Skip to content

Cairn

Typed, opaque IDs and short-lived keys for TypeScript services, so you never hand-roll an ID format or its parser again.

  • @fungi.computer/cairn
  • v0.1.0
  • MIT

Fastest path

  1. Install

    Add it to your project with npm, pnpm, Yarn or Bun.

    TERMINAL
    npm install @fungi.computer/cairn
  2. Mint and check an ID

    Declare an ID family once, then generate IDs and parse untrusted strings with the same codec.

    home.ts
    import { defineIdFamily } from "@fungi.computer/cairn/id";
    import { words } from "@fungi.computer/cairn/words";
    const ids = defineIdFamily({
    family: "jobs",
    version: 1,
    kinds: { job: { prefix: "job" } },
    });
    const id = ids.job.generate();
    console.log(id); // job_ and 21 base36 characters
    console.log(ids.job.parse(id).ok); // true
    console.log(ids.job.parse("job_TOO-SHORT").ok); // false
    console.log(words()); // a candidate name such as "quiet-fern"