Files
zerobyte/app/server/utils/id.ts
Nico a0a813ed09 refactor: short id branded type (#552)
* refactor: short id branded type

* chore: pr feedbacks
2026-02-21 11:16:15 +01:00

8 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;
};