diginext-utils
Version:
README.md
23 lines • 767 B
JavaScript
import { numeric, punctuation, randomStringByLength, textLowCase } from "./random.js";
/**
* random password
* - if hard = true -> random punctuation inside
* @param {*} length
* @param {Boolean} hard
* @returns
*/
export function generatePassword(length = 6, hard = true) {
if (!Number.isFinite(length))
length = 6;
if (length <= 0)
length = 6;
let pass = randomStringByLength(length, textLowCase + textLowCase.toUpperCase() + numeric);
if (hard) {
const midIndex = Math.floor(pass.length / 2);
const midChar = pass.charAt(midIndex);
pass = pass.replace(midChar, randomStringByLength(1, punctuation));
}
return pass;
}
export default generatePassword;
//# sourceMappingURL=generatePassword.js.map