UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

41 lines (40 loc) 2.33 kB
import type { $UUIDOptionsV3V5, $UUIDVersion, UUID, UUIDVersion } from './types'; /** Converts a 32-bit number to a 4-byte hex string */ export declare function _numToHex(n: number): string; /** Converts a 64-character string block to an array of 16 numbers */ export declare function _stringToNumbers(s: string): number[]; /** Performs one MD5 cycle on a 4-element state with 16-word block */ export declare function _md5cycle(x: number[], k: number[]): void; /** * Computes UUID timestamp in 100-nanosecond intervals since * 00:00:00.00 15 October 1582 (Gregorian epoch). */ export declare function _uuidTimestamp(): bigint; /** * Generates a random 48-bit node ID. * LSB of first byte must be 1 to indicate a randomly generated node. */ export declare function _randomNode48(): string; /** * Generates random hex string of given byte length using crypto API if available, otherwise falls back to Math.random. * @param bytes Instance of {@link Uint8Array} to fill with random values. * @returns Hex string representation of the random bytes. */ export declare function _bytesToRandomHex(bytes: Uint8Array<ArrayBuffer>): string; /** * Generates a 14-bit clock sequence (2 bytes, but only 14 bits used). */ export declare function _clockSeq14(): string; /** Convert a hex string to UUID format */ export declare function _formatUUID<V extends UUIDVersion>(h: string, v: number, up: boolean): UUID<V>; /** Check if the uuid `options` is compatible for `v3` and `v5` */ export declare function _isOptionV3V5(opt: unknown): opt is $UUIDOptionsV3V5<'v3' | 'v5'>; /** Check UUID version after checking for valid UUID from `v1-v8` */ export declare function _checkUUIDVersion(value: unknown, v: `${$UUIDVersion}`): boolean; /** * Compares two encrypted strings or byte arrays in constant time. * Prevents timing attacks by ensuring equal-time checks regardless of data differences. */ export declare function _constantTimeEquals(a: string | Uint8Array, b: string | Uint8Array): boolean; /** Split string by substring length, intended to be used internally for hex and binary converters only */ export declare function _splitByCharLength(str: string, splitByChars?: number): string[]; /** Pad start of a byte with 0 for `hex` or `binary` */ export declare function _padStartWith0(byte: number, type: 'hex' | 'binary'): string;