mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-18 05:47:31 -04:00
8 lines
279 B
TypeScript
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;
|
|
};
|