TypeScript 55.4%
Python 43.2%
SQL 1.2%
1import { randomBytes } from "node:crypto";23const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";45/** Sortable-ish, URL-safe id: `<prefix>_<base36 time><random>`. */6export function newId(prefix: string, randomLen = 12): string {7 const t = Date.now().toString(36);8 const bytes = randomBytes(randomLen);9 let r = "";10 for (let i = 0; i < randomLen; i++) r += ALPHABET[bytes[i]! % 36];11 return `${prefix}_${t}${r}`;12}1314export const ID_PREFIX = {15 source: "src",16 sensor: "sen",17 run: "run",18 snapshot: "snap",19 change: "chg",20 event: "evt",21 cluster: "clu",22 entity: "ent",23 request: "req",24 watchlist: "wl",25 alert: "alr",26} as const;2728export function slugify(input: string): string {29 return input30 .normalize("NFKD")31 .replace(/[̀-ͯ]/g, "")32 .toLowerCase()33 .replace(/[^a-z0-9]+/g, "-")34 .replace(/^-+|-+$/g, "")35 .slice(0, 80);36}37