@jmondi/route-strings

Deno Version Npmjs.org Version GitHub Workflow Status Test Coverage NPM Downloads

A typed route string generator to help keep urls under control.

Install

pnpm add @jmondi/route-strings

Deno

import { route } from "https://deno.land/x/route_strings/mod.ts";

Usage

import { Route } from "@jmondi/route-strings";
const r = route("/posts/:slug");
r.template;
// /posts/:slug
const r = route("/posts/:slug/random/:id");
r.create({ slug: "hello", id: 5 });
// /posts/hello/random/5
const g = routeGroup({ prefix: "/api/v1" });
const route = g.add("/posts/:slug/random/:id");
route.template;
// /api/v1/posts/:slug/random/:id
route.create({ slug: "hello", id: 5 });
// /api/v1/posts/hello/random/5