UNPKG

jsfakeit

Version:

![alt text](https://raw.githubusercontent.com/Anirban20001962/jsfakeit/main/logo.png)

76 lines (75 loc) 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.password = exports.userName = void 0; const person_1 = require("../data/person"); const chooseRand_1 = require("../helper/chooseRand"); const replaceWithNumber_1 = require("../helper/replaceWithNumber"); const strings_1 = require("../helper/strings"); /** Generate random username*/ const userName = () => { //random select a lastname, // a random number to it and return return ((0, chooseRand_1.chooseRand)('last', person_1.person) + (0, replaceWithNumber_1.replaceWithNumber)('####')); }; exports.userName = userName; /**Generate random password Minimum length of 5 if num < 5 */ const password = (num = 5, lower = true, upper = true, numeric = true, special = true, space = false) => { if (num < 5) { num = 5; } const res = []; //get all the type od characters const lStr = (0, strings_1.lowerChars)(); const uStr = (0, strings_1.upperChars)(); const sStr = (0, strings_1.specialChars)(); const nStr = (0, strings_1.numChars)(); //pass phrase let passphrase = []; let i = 0; //If lower add lower case chars to passphrase if (lower) { passphrase = [...passphrase, ...lStr]; const p = (0, chooseRand_1.getRandomArbitrary)(0, lStr.length); res.push(lStr[p]); i += 1; } //If upper add upper case chars to passphrase if (upper) { passphrase = [...passphrase, ...uStr]; const p = (0, chooseRand_1.getRandomArbitrary)(0, uStr.length); res.push(uStr[p]); i += 1; } //If numeric add numeric case chars to passphrase if (numeric) { passphrase = [...passphrase, ...nStr]; const p = (0, chooseRand_1.getRandomArbitrary)(0, nStr.length); res.push(nStr[p]); i += 1; } //If special add special case chars to passphrase if (special) { passphrase = [...passphrase, ...sStr]; const p = (0, chooseRand_1.getRandomArbitrary)(0, sStr.length); res.push(sStr[p]); i += 1; } //If space add space case chars to passphrase if (space) { passphrase = [...passphrase, ' ']; res.push(' '); i += 1; } if (passphrase.length == 0) { passphrase = [...passphrase, ...lStr, ...nStr]; } while (i < num) { const p = (0, chooseRand_1.getRandomArbitrary)(0, passphrase.length); res.push(passphrase[p]); i += 1; } return res.join(''); }; exports.password = password;