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 Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Prefix extends string |
string |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
IdGeneratorOptions<Prefix> |
Returns
Section titled “Returns”IdGenerator<Prefix>
Example
Section titled “Example”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