diff options
Diffstat (limited to 'node_modules/randomatic/index.js')
-rw-r--r-- | node_modules/randomatic/index.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/node_modules/randomatic/index.js b/node_modules/randomatic/index.js index 4681b03e7..64e4f5487 100644 --- a/node_modules/randomatic/index.js +++ b/node_modules/randomatic/index.js @@ -9,12 +9,14 @@ var isNumber = require('is-number'); var typeOf = require('kind-of'); +var mathRandom = require('math-random'); /** * Expose `randomatic` */ module.exports = randomatic; +module.exports.isCrypto = !!mathRandom.cryptographic; /** * Available mask characters @@ -51,7 +53,9 @@ function randomatic(pattern, length, options) { length = pattern.length; } else if (isNumber(pattern)) { - options = {}; length = pattern; pattern = '*'; + options = {}; + length = pattern; + pattern = '*'; } } @@ -75,8 +79,14 @@ function randomatic(pattern, length, options) { if (pattern.indexOf('*') !== -1) mask += type.all; if (custom) mask += pattern; + // Characters to exclude + if (opts.exclude) { + var exclude = typeOf(opts.exclude) === 'string' ? opts.exclude : opts.exclude.join(''); + mask = mask.replace(new RegExp('[' + exclude + ']+', 'g'), ''); + } + while (length--) { - res += mask.charAt(parseInt(Math.random() * mask.length, 10)); + res += mask.charAt(parseInt(mathRandom() * mask.length, 10)); } return res; }; |