everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
19 lines (18 loc) • 611 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomStringFromCharset = void 0;
/**
* Generates a random string from a given charset.
* @author @dailker
* @param {number} length - Length of the string.
* @param {string} charset - Characters to use.
* @returns {string}
*/
function randomStringFromCharset(length, charset) {
let result = '';
for (let i = 0; i < length; i++) {
result += charset.charAt(Math.floor(Math.random() * charset.length));
}
return result;
}
exports.randomStringFromCharset = randomStringFromCharset;