zerobyte/app/server/utils/id.ts
2026-02-21 10:53:16 +01:00

7 lines
279 B
TypeScript

import crypto from "node:crypto";
import type { ShortId } from "./branded";
export const generateShortId = (length = 8): ShortId => {
const bytesNeeded = Math.ceil((length * 3) / 4);
return crypto.randomBytes(bytesNeeded).toString("base64url").slice(0, length) as ShortId;
};