diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/randomatic/index.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
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; }; |