@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
22 lines • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ALPHABET = exports.ALPHABET_UPPERCASE = exports.ALPHABET_LOWERCASE = void 0;
exports.randomString = randomString;
const assert_1 = require("./assert");
exports.ALPHABET_LOWERCASE = [...'abcdefghijklmnopqrstuvwxyz'];
exports.ALPHABET_UPPERCASE = [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'];
exports.ALPHABET = [...exports.ALPHABET_LOWERCASE, ...exports.ALPHABET_UPPERCASE];
// we could do this with type guards etc. but this way it is easier to read I guess
function isPositiveFiniteInteger(length) {
return isFinite(length) && length >= 0 && length === Math.floor(length);
}
function randomString(length, symbols = exports.ALPHABET) {
(0, assert_1.guard)(isPositiveFiniteInteger(length), `length must be a positive, finite integer (${length} >= 0)`);
(0, assert_1.guard)(symbols.length > 0, 'there must be at least one symbol to use');
let result = '';
for (let i = 0; i < length; i++) {
result += symbols[Math.floor(Math.random() * symbols.length)];
}
return result;
}
//# sourceMappingURL=random.js.map