UNPKG

node-password-generator

Version:

A simple lightweight npm library for password generator. It allows you to create random unqiue password on the fly.

34 lines (33 loc) 1.07 kB
import passwordRandomizer from './password-randomizer'; const uppercase_characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; const lowercase_characters = 'abcdefghijklmnopqrstuvwxyz'; const numeric_characters = '0123456789'; const special_characters = '#?!@$%)^&*-'; const default_length = 10; /** * @param {} {uppercase * @param {} lowercase * @param {} numbers * @param {} symbols * @param {} length * @param {Options} } * @returns string */ export default function generate({ uppercase, lowercase, numbers, symbols, length, }) { /** * Building Character List */ let characterList = ''; if (uppercase === true) characterList += uppercase_characters; if (lowercase === true) characterList += lowercase_characters; if (numbers === true) characterList += numeric_characters; if (symbols === true) characterList += special_characters; if (!characterList) { throw new Error('No `character` sets selected'); } return passwordRandomizer(characterList, length ? length : default_length); }