Readme

Helper functions/types for Val Town JSON Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { z } from "https://deno.land/x/zod@v3.22.4/mod.ts";
import type { FC } from "npm:hono/jsx";
export interface Options {
homepage?: FC;
routes?: Record<string, string>;
}
export const getResources = (db) => {
return Object.entries(db.data).map(([name, value]) => {
const type = Array.isArray(value) ? "plural" : "singular";
const label = type === "singular" ? "object" : `${(value as Array<any>).length}x`;
return { name, type, label };
});
};
export const validate = (db) => {
if (!("data" in db)) {
return false;
}
return z.object({}).safeParse(db.data).success;
};
export const checkResource = (resource, resources) => {
return resources.some(r => r.name === resource);
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
February 1, 2024