Skip to content

createIdGenerator

function createIdGenerator<Prefix>(options): IdGenerator<Prefix>;

Defined in: src/util/id.ts:127

Create an id generator for one product. The prefix union is a type parameter, so newId("typo") fails to compile.

Type Parameter Default type
Prefix extends string string
Parameter Type
options IdGeneratorOptions<Prefix>

IdGenerator<Prefix>

import { createIdGenerator } from "@xtandard/kit/util";
export const { newId, idPattern, idTime } = createIdGenerator({
format: "ulid",
prefixes: ["evt", "chk"],
});
newId("evt"); // "evt_01JD3Z…" — sorts by creation time