UNPKG

@globalart/text-utils

Version:

A collection of modules, helpers and utils for working with text.

19 lines (18 loc) 748 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateRandomString = void 0; /** * Generates a random word of the specified length using the provided characters. * @param length - The length of the word to generate. * @param chars - The characters to use for generating the word. Defaults to lowercase English letters. * @returns A randomly generated word. */ const generateRandomString = (length, chars = 'abcdefghijklmnopqrstuvwxyz01234567890') => { const array = crypto.getRandomValues(new Uint32Array(length)); let word = ''; for (let i = 0; i < length; i++) { word += chars[array[i] % chars.length]; } return word; }; exports.generateRandomString = generateRandomString;