forked from Mike/freno-dev
22 lines
620 B
TypeScript
22 lines
620 B
TypeScript
/**
|
|
* Shared JSON response helpers for the The Nook license API routes.
|
|
* Underscore-prefixed file — not a route.
|
|
*/
|
|
|
|
export function json(data: unknown, status = 200): Response {
|
|
return new Response(JSON.stringify(data), {
|
|
status,
|
|
headers: { "Content-Type": "application/json" }
|
|
});
|
|
}
|
|
|
|
export function error(message: string, status: number): Response {
|
|
return json({ error: message }, status);
|
|
}
|
|
|
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
|
export function isUuid(value: unknown): value is string {
|
|
return typeof value === "string" && UUID_RE.test(value);
|
|
}
|