aboutsummaryrefslogtreecommitdiff
path: root/node_modules/randomatic/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
commitabd94a7f5a50f43c797a11b53549ae48fff667c3 (patch)
treeab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/randomatic/index.js
parenta0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff)
downloadwallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz
add node_modules to address #4364
Diffstat (limited to 'node_modules/randomatic/index.js')
-rw-r--r--node_modules/randomatic/index.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/node_modules/randomatic/index.js b/node_modules/randomatic/index.js
new file mode 100644
index 000000000..85dbe21ca
--- /dev/null
+++ b/node_modules/randomatic/index.js
@@ -0,0 +1,83 @@
+/*!
+ * randomatic <https://github.com/jonschlinkert/randomatic>
+ *
+ * This was originally inspired by <http://stackoverflow.com/a/10727155/1267639>
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License (MIT)
+ */
+
+'use strict';
+
+var isNumber = require('is-number');
+var typeOf = require('kind-of');
+
+/**
+ * Expose `randomatic`
+ */
+
+module.exports = randomatic;
+
+/**
+ * Available mask characters
+ */
+
+var type = {
+ lower: 'abcdefghijklmnopqrstuvwxyz',
+ upper: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
+ number: '0123456789',
+ special: '~!@#$%^&()_+-={}[];\',.'
+};
+
+type.all = type.lower + type.upper + type.number;
+
+/**
+ * Generate random character sequences of a specified `length`,
+ * based on the given `pattern`.
+ *
+ * @param {String} `pattern` The pattern to use for generating the random string.
+ * @param {String} `length` The length of the string to generate.
+ * @param {String} `options`
+ * @return {String}
+ * @api public
+ */
+
+function randomatic(pattern, length, options) {
+ if (typeof pattern === 'undefined') {
+ throw new Error('randomatic expects a string or number.');
+ }
+
+ var custom = false;
+ if (arguments.length === 1) {
+ if (typeof pattern === 'string') {
+ length = pattern.length;
+
+ } else if (isNumber(pattern)) {
+ options = {}; length = pattern; pattern = '*';
+ }
+ }
+
+ if (typeOf(length) === 'object' && length.hasOwnProperty('chars')) {
+ options = length;
+ pattern = options.chars;
+ length = pattern.length;
+ custom = true;
+ }
+
+ var opts = options || {};
+ var mask = '';
+ var res = '';
+
+ // Characters to be used
+ if (pattern.indexOf('?') !== -1) mask += opts.chars;
+ if (pattern.indexOf('a') !== -1) mask += type.lower;
+ if (pattern.indexOf('A') !== -1) mask += type.upper;
+ if (pattern.indexOf('0') !== -1) mask += type.number;
+ if (pattern.indexOf('!') !== -1) mask += type.special;
+ if (pattern.indexOf('*') !== -1) mask += type.all;
+ if (custom) mask += pattern;
+
+ while (length--) {
+ res += mask.charAt(parseInt(Math.random() * mask.length, 10));
+ }
+ return res;
+};