UNPKG

hybrid-id-generator

Version:

A powerful hybrid ID generator that combines timestamps, machine IDs, random bits, and sequence numbers to create globally unique identifiers. Features collision prevention, Base62 encoding, and optional ID expiry tracking, ideal for distributed systems a

124 lines (123 loc) 4.19 kB
export declare class HybridID { private id; /** * Creates an instance of HybridID. * @param id - The ID value as a bigint or string. */ constructor(id: bigint | string); /** * Converts the ID to a Base62 encoded string. * @returns The Base62 encoded string representation of the ID. */ toBase62(): string; /** * Converts the ID to a Base32 encoded string. * @returns The Base32 encoded string representation of the ID. */ toBase32(): string; /** * Converts the ID to a Base64 encoded string. * @returns The Base64 encoded string representation of the ID. */ toBase64(): string; /** * Creates a HybridID instance from a Base62 encoded string. * @param encoded - The Base62 encoded string. * @returns A new HybridID instance. * @throws Error if the encoded string is invalid. */ static fromBase62(encoded: string): HybridID; /** * Creates a HybridID instance from a Base32 encoded string. * @param encoded - The Base32 encoded string. * @returns A new HybridID instance. * @throws Error if the encoded string is invalid. */ static fromBase32(encoded: string): HybridID; /** * Creates a HybridID instance from a Base64 encoded string. * @param encoded - The Base64 encoded string. * @returns A new HybridID instance. * @throws Error if the encoded string is invalid. */ static fromBase64(encoded: string): HybridID; /** * Converts the ID to a hexadecimal string. * @returns The hexadecimal representation of the ID. */ toHex(): string; /** * Creates a HybridID instance from a hexadecimal string. * @param hex - The hexadecimal string. * @returns A new HybridID instance. */ static fromHex(hex: string): HybridID; /** * Converts the ID to a string. * @returns The string representation of the ID. */ toString(): string; /** * Converts the ID to a bigint. * @returns The ID as a bigint. */ toBigInt(): bigint; /** * Returns the ID value as a bigint or string. * @returns The ID value. */ valueOf(): bigint | string; /** * Checks if the current HybridID is equal to another. * @param other - The other HybridID to compare with. * @returns True if equal, false otherwise. */ isEqual(other: HybridID): boolean; /** * Checks if the current HybridID is greater than another. * @param other - The other HybridID to compare with. * @returns True if greater, false otherwise. */ isGreaterThan(other: HybridID): boolean; /** * Checks if the current HybridID is less than another. * @param other - The other HybridID to compare with. * @returns True if less, false otherwise. */ isLessThan(other: HybridID): boolean; /** * Validates if a Base62 encoded string is valid. * @param encoded - The Base62 encoded string to validate. * @returns True if valid, false otherwise. */ static isValidBase62(encoded: string): boolean; /** * Validates if a Base32 encoded string is valid. * @param encoded - The Base32 encoded string to validate. * @returns True if valid, false otherwise. */ static isValidBase32(encoded: string): boolean; /** * Validates if a Base64 encoded string is valid. * @param encoded - The Base64 encoded string to validate. * @returns True if valid, false otherwise. */ static isValidBase64(encoded: string): boolean; /** * Serializes the HybridID instance to a JSON string. * @returns The serialized JSON string representation of the HybridID. */ serialize(): string; /** * Deserializes a JSON string to create a HybridID instance. * @param serialized - The serialized JSON string. * @returns A new HybridID instance. */ static deserialize(serialized: string): HybridID; /** * Generates a random HybridID instance. * @returns A new HybridID instance with a random ID. */ static generateRandom(): HybridID; } export default HybridID;