treetrunks
v0.1.5
Published
<a aria-label="NPM version" href="https://www.npmjs.com/package/treetrunks"> <img alt="NPM Version" src="https://img.shields.io/npm/v/treetrunks?style=for-the-badge"> </a> <a aria-label="Dependencies 0" href="https://www.npmjs.com/package/treetrunks">
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
