UNPKG

@kikiutils/node

Version:

A modular utility library for Node.js offering secure hashing, flexible logging, datetime manipulation, and more.

21 lines 955 B
export type RandomStringMode = 'alphabetic' | 'alphanumeric' | 'lowercase' | 'lowercase-numeric' | 'numeric' | 'uppercase' | 'uppercase-numeric'; /** * Generates a random string of a given length using a specified character set. * * @param {number} length - The length of the string to generate. Must be a positive integer. * @param {RandomStringMode} [mode] - The character set to use. * @returns {string} The generated random string. * * @throws {Error} If the length is not a positive integer or the mode is unsupported. * * @example * ```typescript * import { randomString } from '@kikiutils/node/string'; * * console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic) * console.log(randomString(6, 'numeric')); // e.g. '402398' * console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2' * ``` */ export declare function randomString(length: number, mode?: RandomStringMode): string; //# sourceMappingURL=string.d.ts.map