jsfakeit
Version:

70 lines (69 loc) • 2.16 kB
JavaScript
;
// Refer to ASCII table: https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomString = exports.randCharacter = exports.specialChars = exports.numChars = exports.upperChars = exports.lowerChars = void 0;
const chooseRand_1 = require("./chooseRand");
//array of lower characters
const lowerChars = () => {
let a = [];
for (let i = 97; i <= 122; i++) {
a.push(String.fromCharCode(i));
}
return a;
};
exports.lowerChars = lowerChars;
//array of upper characters
const upperChars = () => {
let a = [];
for (let i = 65; i <= 90; i++) {
a.push(String.fromCharCode(i));
}
return a;
};
exports.upperChars = upperChars;
//array of numbers 0-9
const numChars = () => {
return Array.from({ length: 10 }, (_, k) => String(k));
};
exports.numChars = numChars;
//array of special characters
const specialChars = () => {
let a = [];
for (let i = 33; i <= 47; i++) {
a.push(String.fromCharCode(i));
}
for (let i = 58; i <= 64; i++) {
a.push(String.fromCharCode(i));
}
for (let i = 91; i <= 96; i++) {
a.push(String.fromCharCode(i));
}
for (let i = 123; i <= 126; i++) {
a.push(String.fromCharCode(i));
}
return a;
};
exports.specialChars = specialChars;
//Generate random character
const randCharacter = () => {
const passphrase = [...(0, exports.numChars)(), ...(0, exports.lowerChars)(), ...(0, exports.upperChars)()];
const i = (0, chooseRand_1.getRandomArbitrary)(0, passphrase.length);
return passphrase[i];
};
exports.randCharacter = randCharacter;
// RandomString will take in a slice of string and return a randomly selected value
const randomString = (a) => {
if (Array.isArray(a)) {
if (a.length == 1) {
return a[0];
}
return a[(0, chooseRand_1.getRandomArbitrary)(0, a.length)];
}
else {
if (a.length == 1) {
return a;
}
return a.split('')[(0, chooseRand_1.getRandomArbitrary)(0, a.length)];
}
};
exports.randomString = randomString;