treetrunks
v0.1.7
Published
Type and runtime representations of tree structures.
Downloads
17,951
Readme
treetrunks
npm i treetrunkstreetrunks is a convenient way to define type-safe routers.
overview
a tree structure affords many possible routes through the tree
import type { Tree, TreePath } from "treetrunks";
import { optional, required } from "treetrunks";
const greetingTree = required({
hello: optional({
world: null,
$name: optional({
good: required({
morning: null,
}),
}),
}),
}) satisfies Tree;
const validPaths: TreePath<typeof greetingTree>[] = [
[`hello`],
[`hello`, `world`],
[`hello`, `jeremybanka`],
[`hello`, `treetrunks`, `good`, `morning`],
];the optional and required functions help determine what routes are valid.
note that,
"hello"is required"world", or any$nameis optional"good morning"is optional
