import { randomBytes } from "node:crypto"; const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"; /** Sortable-ish, URL-safe id: `_`. */ export function newId(prefix: string, randomLen = 12): string { const t = Date.now().toString(36); const bytes = randomBytes(randomLen); let r = ""; for (let i = 0; i < randomLen; i++) r += ALPHABET[bytes[i]! % 36]; return `${prefix}_${t}${r}`; } export const ID_PREFIX = { source: "src", sensor: "sen", run: "run", snapshot: "snap", change: "chg", event: "evt", cluster: "clu", entity: "ent", request: "req", watchlist: "wl", alert: "alr", } as const; export function slugify(input: string): string { return input .normalize("NFKD") .replace(/[̀-ͯ]/g, "") .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") .slice(0, 80); }