UNPKG

@thi.ng/idgen

Version:

Generator of opaque numeric identifiers with optional support for ID versioning and efficient re-use

23 lines 912 B
import { type Event, type IIDGen, type INotify, type Listener } from "@thi.ng/api"; import { type IDGenEventType } from "./api.js"; /** * Wrapped ID generator for creating string-based IDs derived from a backing ID gen. */ export declare class PrefixedID implements IIDGen<string>, INotify { readonly prefix: string; readonly gen: IIDGen<number>; constructor(prefix: string, gen: IIDGen<number>); next(): string; free(id: string): boolean; addListener(id: IDGenEventType, fn: Listener<IDGenEventType>, scope?: any): boolean; removeListener(id: IDGenEventType, fn: Listener<IDGenEventType>, scope?: any): boolean; notify(event: Event<IDGenEventType>): boolean; } /** * Syntax sugar for {@link PrefixedID} constructor. * * @param prefix * @param gen */ export declare const prefixed: (prefix: string, gen: IIDGen<number>) => PrefixedID; //# sourceMappingURL=prefixed.d.ts.map