jonschlinkert / randomatic

Easily generate random strings like passwords, with simple options for specifying a length and for using patterns of numeric, alpha-numeric, alphabetical, special or custom characters. (the original "generate-password")
https://github.com/jonschlinkert
MIT License
183 stars 25 forks source link

Add exclude to options #16

Closed kivlor closed 6 years ago

kivlor commented 6 years ago

Fixes #12

doowb commented 6 years ago

@kivlor thanks! Looks good. I just had one syntax comment, then it looks good to me.

From #12:

I wasn't sure the best approach to take to allow passing a function

I think this means to check if exclude is a function just before checking for string or array and calling exclude passing in the current mask.

At first, I thought it meant taking a function that allowed returning the mask, but that can be done by passing a string on options.chars.

I think with this change, a scenario that I thought of will be addressed: I want a random string that contains most of the characters provided here (all - some excluded chars) + some chars that aren't included.

const id = randomatic('?*', 20, { chars: '|', exclude: ['1lL0oO.'] });
kivlor commented 6 years ago

@doowb syntax comment addressed!

Thanks for explaining my 'passing a function' question. Seems with out it this change will still work (and without the complexity).

doowb commented 6 years ago

Thanks @kivlor this has been merged and published as 3.1.0.