UNPKG

diginext-utils

Version:
20 lines (19 loc) 656 B
import { numeric, punctuation, randomStringByLength, textLowCase } from "./random"; /** * 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) pass = pass.replace(pass[Math.floor(pass.length / 2)], randomStringByLength(1, punctuation)); return pass; } export default generatePassword;