CARVIEW |
Select Language
HTTP/2 302
date: Wed, 23 Jul 2025 10:15:02 GMT
content-type: text/html; charset=utf-8
content-length: 0
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
location: https://release-assets.githubusercontent.com/github-production-release-asset/3360944/82f4a452-6464-11e5-8b31-203d32e1c920?sp=r&sv=2018-11-09&sr=b&spr=https&se=2025-07-23T10%3A49%3A54Z&rscd=attachment%3B+filename%3Dstochator.js&rsct=application%2Foctet-stream&skoid=96c2d410-5711-43a1-aedd-ab1947aa7ab0&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skt=2025-07-23T09%3A49%3A48Z&ske=2025-07-23T10%3A49%3A54Z&sks=b&skv=2018-11-09&sig=Q9H92KLnsRVi%2ByNl56qaGnmA1WK0k6GDc4w6XREyloI%3D&jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmVsZWFzZS1hc3NldHMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwia2V5Ijoia2V5MSIsImV4cCI6MTc1MzI2NjAwMiwibmJmIjoxNzUzMjY1NzAyLCJwYXRoIjoicmVsZWFzZWFzc2V0cHJvZHVjdGlvbi5ibG9iLmNvcmUud2luZG93cy5uZXQifQ.sJNCM3_YNwck_gNPV_BnIfGq3VIxKcZ2pg6tjIwYKdw&response-content-disposition=attachment%3B%20filename%3Dstochator.js&response-content-type=application%2Foctet-stream
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
x-github-request-id: EB82:39062F:8FF177:AECDBA:6880B626
HTTP/2 200
last-modified: Tue, 07 Dec 2021 20:19:06 GMT
etag: "0x8D9B9BED1EDB037"
server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 8784b72d-201e-004f-38ba-fb9001000000
x-ms-version: 2018-11-09
x-ms-creation-time: Tue, 17 Aug 2021 18:47:14 GMT
x-ms-blob-content-md5: K9zjJJ6XjnkP7FnT/uijBw==
x-ms-lease-status: unlocked
x-ms-lease-state: available
x-ms-blob-type: BlockBlob
x-ms-server-encrypted: true
via: 1.1 varnish, 1.1 varnish
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 10:15:03 GMT
x-served-by: cache-iad-kjyo7100114-IAD, cache-bom-vanm7210044-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753265703.793272,VS0,VE270
content-disposition: attachment; filename=stochator.js
content-type: application/octet-stream
content-length: 91513
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o range.high);
};
_SubRange.prototype.touches = function (range) {
return !(this.high + 1 < range.low || this.low - 1 > range.high);
};
//returns inclusive combination of _SubRanges as a _SubRange
_SubRange.prototype.add = function (range) {
return this.touches(range) && new _SubRange(Math.min(this.low, range.low), Math.max(this.high, range.high));
};
//returns subtraction of _SubRanges as an array of _SubRanges (there's a case where subtraction divides it in 2)
_SubRange.prototype.subtract = function (range) {
if (!this.overlaps(range)) return false;
if (range.low <= this.low && range.high >= this.high) return [];
if (range.low > this.low && range.high < this.high) return [new _SubRange(this.low, range.low - 1), new _SubRange(range.high + 1, this.high)];
if (range.low <= this.low) return [new _SubRange(range.high + 1, this.high)];
return [new _SubRange(this.low, range.low - 1)];
};
_SubRange.prototype.toString = function () {
if (this.low == this.high) return this.low.toString();
return this.low + '-' + this.high;
};
_SubRange.prototype.clone = function () {
return new _SubRange(this.low, this.high);
};
function DiscontinuousRange(a, b) {
if (this instanceof DiscontinuousRange) {
this.ranges = [];
this.length = 0;
if (a !== undefined) this.add(a, b);
} else {
return new DiscontinuousRange(a, b);
}
}
function _update_length(self) {
self.length = self.ranges.reduce(function (previous, range) {return previous + range.length}, 0);
}
DiscontinuousRange.prototype.add = function (a, b) {
var self = this;
function _add(subrange) {
var new_ranges = [];
var i = 0;
while (i < self.ranges.length && !subrange.touches(self.ranges[i])) {
new_ranges.push(self.ranges[i].clone());
i++;
}
while (i < self.ranges.length && subrange.touches(self.ranges[i])) {
subrange = subrange.add(self.ranges[i]);
i++;
}
new_ranges.push(subrange);
while (i < self.ranges.length) {
new_ranges.push(self.ranges[i].clone());
i++;
}
self.ranges = new_ranges;
_update_length(self);
}
if (a instanceof DiscontinuousRange) {
a.ranges.forEach(_add);
} else {
if (a instanceof _SubRange) {
_add(a);
} else {
if (b === undefined) b = a;
_add(new _SubRange(a, b));
}
}
return this;
};
DiscontinuousRange.prototype.subtract = function (a, b) {
var self = this;
function _subtract(subrange) {
var new_ranges = [];
var i = 0;
while (i < self.ranges.length && !subrange.overlaps(self.ranges[i])) {
new_ranges.push(self.ranges[i].clone());
i++;
}
while (i < self.ranges.length && subrange.overlaps(self.ranges[i])) {
new_ranges = new_ranges.concat(self.ranges[i].subtract(subrange));
i++;
}
while (i < self.ranges.length) {
new_ranges.push(self.ranges[i].clone());
i++;
}
self.ranges = new_ranges;
_update_length(self);
}
if (a instanceof DiscontinuousRange) {
a.ranges.forEach(_subtract);
} else {
if (a instanceof _SubRange) {
_subtract(a);
} else {
if (b === undefined) b = a;
_subtract(new _SubRange(a, b));
}
}
return this;
};
DiscontinuousRange.prototype.index = function (index) {
var i = 0;
while (i < this.ranges.length && this.ranges[i].length <= index) {
index -= this.ranges[i].length;
i++;
}
if (i >= this.ranges.length) return null;
return this.ranges[i].low + index;
};
DiscontinuousRange.prototype.toString = function () {
return '[ ' + this.ranges.join(', ') + ' ]'
};
DiscontinuousRange.prototype.clone = function () {
return new DiscontinuousRange(this);
};
module.exports = DiscontinuousRange;
},{}],2:[function(require,module,exports){
/**
* lodash 3.0.0 (Custom Build)
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.7.0
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license
*/
/**
* This method returns the first argument provided to it.
*
* @static
* @memberOf _
* @category Utility
* @param {*} value Any value.
* @returns {*} Returns `value`.
* @example
*
* var object = { 'user': 'fred' };
* _.identity(object) === object;
* // => true
*/
function identity(value) {
return value;
}
module.exports = identity;
},{}],3:[function(require,module,exports){
/**
* lodash 3.0.6 (Custom Build)
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.8.3
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license
*/
/** `Object#toString` result references. */
var funcTag = '[object Function]';
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](https://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in older versions of Chrome and Safari which return 'function' for regexes
// and Safari 8 equivalents which return 'object' for typed array constructors.
return isObject(value) && objToString.call(value) == funcTag;
}
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(1);
* // => false
*/
function isObject(value) {
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
module.exports = isFunction;
},{}],4:[function(require,module,exports){
/**
* lodash 3.0.1 (Custom Build)
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.8.2
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license
*/
/** `Object#toString` result references. */
var stringTag = '[object String]';
/**
* Checks if `value` is object-like.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
}
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isString('abc');
* // => true
*
* _.isString(1);
* // => false
*/
function isString(value) {
return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
}
module.exports = isString;
},{}],5:[function(require,module,exports){
/**
* lodash 3.0.3 (Custom Build)
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.8.3
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license
*/
/** `Object#toString` result references. */
var regexpTag = '[object RegExp]';
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](https://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(1);
* // => false
*/
function isObject(value) {
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
/**
* Checks if `value` is classified as a `RegExp` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isRegExp(/abc/);
* // => true
*
* _.isRegExp('/abc/');
* // => false
*/
function isRegExp(value) {
return isObject(value) && objToString.call(value) == regexpTag;
}
module.exports = isRegExp;
},{}],6:[function(require,module,exports){
/**
* lodash 3.0.1 (Custom Build)
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.8.3
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license
*/
var isIterateeCall = require('lodash._isiterateecall');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCeil = Math.ceil,
nativeMax = Math.max;
/**
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to, but not including, `end`. If `end` is not specified it is
* set to `start` with `start` then set to `0`. If `end` is less than `start`
* a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
* @category Utility
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @param {number} [step=1] The value to increment or decrement by.
* @returns {Array} Returns the new array of numbers.
* @example
*
* _.range(4);
* // => [0, 1, 2, 3]
*
* _.range(1, 5);
* // => [1, 2, 3, 4]
*
* _.range(0, 20, 5);
* // => [0, 5, 10, 15]
*
* _.range(0, -4, -1);
* // => [0, -1, -2, -3]
*
* _.range(1, 4, 0);
* // => [1, 1, 1]
*
* _.range(0);
* // => []
*/
function range(start, end, step) {
if (step && isIterateeCall(start, end, step)) {
end = step = undefined;
}
start = +start || 0;
step = step == null ? 1 : (+step || 0);
if (end == null) {
end = start;
start = 0;
} else {
end = +end || 0;
}
// Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
// See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
var index = -1,
length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
result = Array(length);
while (++index < length) {
result[index] = start;
start += step;
}
return result;
}
module.exports = range;
},{"lodash._isiterateecall":7}],7:[function(require,module,exports){
/**
* lodash 3.0.9 (Custom Build)
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.8.3
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license
*/
/** Used to detect unsigned integer values. */
var reIsUint = /^\d+$/;
/**
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
* of an array-like value.
*/
var MAX_SAFE_INTEGER = 9007199254740991;
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new function.
*/
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
/**
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
* that affects Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
var getLength = baseProperty('length');
/**
* Checks if `value` is array-like.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
*/
function isArrayLike(value) {
return value != null && isLength(getLength(value));
}
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
length = length == null ? MAX_SAFE_INTEGER : length;
return value > -1 && value % 1 == 0 && value < length;
}
/**
* Checks if the provided arguments are from an iteratee call.
*
* @private
* @param {*} value The potential iteratee value argument.
* @param {*} index The potential iteratee index or key argument.
* @param {*} object The potential iteratee object argument.
* @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
*/
function isIterateeCall(value, index, object) {
if (!isObject(object)) {
return false;
}
var type = typeof index;
if (type == 'number'
? (isArrayLike(object) && isIndex(index, object.length))
: (type == 'string' && index in object)) {
var other = object[index];
return value === value ? (value === other) : (other !== other);
}
return false;
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
*/
function isLength(value) {
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(1);
* // => false
*/
function isObject(value) {
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
module.exports = isIterateeCall;
},{}],8:[function(require,module,exports){
var util = require('./util');
var types = require('./types');
var sets = require('./sets');
var positions = require('./positions');
module.exports = function(regexpStr) {
var i = 0, l, c,
start = { type: types.ROOT, stack: []},
// Keep track of last clause/group and stack.
lastGroup = start,
last = start.stack,
groupStack = [];
var repeatErr = function(i) {
util.error(regexpStr, 'Nothing to repeat at column ' + (i - 1));
};
// Decode a few escaped characters.
var str = util.strToChars(regexpStr);
l = str.length;
// Iterate through each character in string.
while (i < l) {
c = str[i++];
switch (c) {
// Handle escaped characters, inclues a few sets.
case '\\':
c = str[i++];
switch (c) {
case 'b':
last.push(positions.wordBoundary());
break;
case 'B':
last.push(positions.nonWordBoundary());
break;
case 'w':
last.push(sets.words());
break;
case 'W':
last.push(sets.notWords());
break;
case 'd':
last.push(sets.ints());
break;
case 'D':
last.push(sets.notInts());
break;
case 's':
last.push(sets.whitespace());
break;
case 'S':
last.push(sets.notWhitespace());
break;
default:
// Check if c is integer.
// In which case it's a reference.
if (/\d/.test(c)) {
last.push({ type: types.REFERENCE, value: parseInt(c, 10) });
// Escaped character.
} else {
last.push({ type: types.CHAR, value: c.charCodeAt(0) });
}
}
break;
// Positionals.
case '^':
last.push(positions.begin());
break;
case '$':
last.push(positions.end());
break;
// Handle custom sets.
case '[':
// Check if this class is 'anti' i.e. [^abc].
var not;
if (str[i] === '^') {
not = true;
i++;
} else {
not = false;
}
// Get all the characters in class.
var classTokens = util.tokenizeClass(str.slice(i), regexpStr);
// Increase index by length of class.
i += classTokens[1];
last.push({
type: types.SET
, set: classTokens[0]
, not: not
});
break;
// Class of any character except \n.
case '.':
last.push(sets.anyChar());
break;
// Push group onto stack.
case '(':
// Create group.
var group = {
type: types.GROUP
, stack: []
, remember: true
};
c = str[i];
// if if this is a special kind of group.
if (c === '?') {
c = str[i + 1];
i += 2;
// Match if followed by.
if (c === '=') {
group.followedBy = true;
// Match if not followed by.
} else if (c === '!') {
group.notFollowedBy = true;
} else if (c !== ':') {
util.error(regexpStr,
'Invalid group, character \'' + c + '\' after \'?\' at column ' +
(i - 1));
}
group.remember = false;
}
// Insert subgroup into current group stack.
last.push(group);
// Remember the current group for when the group closes.
groupStack.push(lastGroup);
// Make this new group the current group.
lastGroup = group;
last = group.stack;
break;
// Pop group out of stack.
case ')':
if (groupStack.length === 0) {
util.error(regexpStr, 'Unmatched ) at column ' + (i - 1));
}
lastGroup = groupStack.pop();
// Check if this group has a PIPE.
// To get back the correct last stack.
last = lastGroup.options ? lastGroup.options[lastGroup.options.length - 1] : lastGroup.stack;
break;
// Use pipe character to give more choices.
case '|':
// Create array where options are if this is the first PIPE
// in this clause.
if (!lastGroup.options) {
lastGroup.options = [lastGroup.stack];
delete lastGroup.stack;
}
// Create a new stack and add to options for rest of clause.
var stack = [];
lastGroup.options.push(stack);
last = stack;
break;
// Repetition.
// For every repetition, remove last element from last stack
// then insert back a RANGE object.
// This design is chosen because there could be more than
// one repetition symbols in a regex i.e. `a?+{2,3}`.
case '{':
var rs = /^(\d+)(,(\d+)?)?\}/.exec(str.slice(i)), min, max;
if (rs !== null) {
min = parseInt(rs[1], 10);
max = rs[2] ? rs[3] ? parseInt(rs[3], 10) : Infinity : min;
i += rs[0].length;
last.push({
type: types.REPETITION
, min: min
, max: max
, value: last.pop()
});
} else {
last.push({
type: types.CHAR
, value: 123
});
}
break;
case '?':
if (last.length === 0) {
repeatErr(i);
}
last.push({
type: types.REPETITION
, min: 0
, max: 1
, value: last.pop()
});
break;
case '+':
if (last.length === 0) {
repeatErr(i);
}
last.push({
type: types.REPETITION
, min: 1
, max: Infinity
, value: last.pop()
});
break;
case '*':
if (last.length === 0) {
repeatErr(i);
}
last.push({
type: types.REPETITION
, min: 0
, max: Infinity
, value: last.pop()
});
break;
// Default is a character that is not `\[](){}?+*^$`.
default:
last.push({
type: types.CHAR
, value: c.charCodeAt(0)
});
}
}
// Check if any groups have not been closed.
if (groupStack.length !== 0) {
util.error(regexpStr, 'Unterminated group');
}
return start;
};
module.exports.types = types;
},{"./positions":9,"./sets":10,"./types":11,"./util":12}],9:[function(require,module,exports){
var types = require('./types');
exports.wordBoundary = function() {
return { type: types.POSITION, value: 'b' };
};
exports.nonWordBoundary = function() {
return { type: types.POSITION, value: 'B' };
};
exports.begin = function() {
return { type: types.POSITION, value: '^' };
};
exports.end = function() {
return { type: types.POSITION, value: '$' };
};
},{"./types":11}],10:[function(require,module,exports){
var types = require('./types');
var INTS = function() {
return [{ type: types.RANGE , from: 48, to: 57 }];
};
var WORDS = function() {
return [
{ type: types.CHAR, value: 95 }
, { type: types.RANGE, from: 97, to: 122 }
, { type: types.RANGE, from: 65, to: 90 }
].concat(INTS());
};
var WHITESPACE = function() {
return [
{ type: types.CHAR, value: 9 }
, { type: types.CHAR, value: 10 }
, { type: types.CHAR, value: 11 }
, { type: types.CHAR, value: 12 }
, { type: types.CHAR, value: 13 }
, { type: types.CHAR, value: 32 }
, { type: types.CHAR, value: 160 }
, { type: types.CHAR, value: 5760 }
, { type: types.CHAR, value: 6158 }
, { type: types.CHAR, value: 8192 }
, { type: types.CHAR, value: 8193 }
, { type: types.CHAR, value: 8194 }
, { type: types.CHAR, value: 8195 }
, { type: types.CHAR, value: 8196 }
, { type: types.CHAR, value: 8197 }
, { type: types.CHAR, value: 8198 }
, { type: types.CHAR, value: 8199 }
, { type: types.CHAR, value: 8200 }
, { type: types.CHAR, value: 8201 }
, { type: types.CHAR, value: 8202 }
, { type: types.CHAR, value: 8232 }
, { type: types.CHAR, value: 8233 }
, { type: types.CHAR, value: 8239 }
, { type: types.CHAR, value: 8287 }
, { type: types.CHAR, value: 12288 }
, { type: types.CHAR, value: 65279 }
];
};
var NOTANYCHAR = function() {
return [
{ type: types.CHAR, value: 10 }
, { type: types.CHAR, value: 13 }
, { type: types.CHAR, value: 8232 }
, { type: types.CHAR, value: 8233 }
];
};
// predefined class objects
exports.words = function() {
return { type: types.SET, set: WORDS(), not: false };
};
exports.notWords = function() {
return { type: types.SET, set: WORDS(), not: true };
};
exports.ints = function() {
return { type: types.SET, set: INTS(), not: false };
};
exports.notInts = function() {
return { type: types.SET, set: INTS(), not: true };
};
exports.whitespace = function() {
return { type: types.SET, set: WHITESPACE(), not: false };
};
exports.notWhitespace = function() {
return { type: types.SET, set: WHITESPACE(), not: true };
};
exports.anyChar = function() {
return { type: types.SET, set: NOTANYCHAR(), not: true };
};
},{"./types":11}],11:[function(require,module,exports){
module.exports = {
ROOT : 0
, GROUP : 1
, POSITION : 2
, SET : 3
, RANGE : 4
, REPETITION : 5
, REFERENCE : 6
, CHAR : 7
};
},{}],12:[function(require,module,exports){
var types = require('./types');
var sets = require('./sets');
// All of these are private and only used by randexp.
// It's assumed that they will always be called with the correct input.
var CTRL = '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?';
var SLSH = { '0': 0, 't': 9, 'n': 10, 'v': 11, 'f': 12, 'r': 13 };
/**
* Finds character representations in str and convert all to
* their respective characters
*
* @param {String} str
* @return {String}
*/
exports.strToChars = function(str) {
var chars_regex = /(\[\\b\])|\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z\[\\\]\^?])|([0tnvfr]))/g;
str = str.replace(chars_regex, function(s, b, a16, b16, c8, dctrl, eslsh) {
var code = b ? 8 :
a16 ? parseInt(a16, 16) :
b16 ? parseInt(b16, 16) :
c8 ? parseInt(c8, 8) :
dctrl ? CTRL.indexOf(dctrl) :
eslsh ? SLSH[eslsh] : undefined;
var c = String.fromCharCode(code);
// Escape special regex characters.
if (/[\[\]{}\^$.|?*+()]/.test(c)) {
c = '\\' + c;
}
return c;
});
return str;
};
/**
* turns class into tokens
* reads str until it encounters a ] not preceeded by a \
*
* @param {String} str
* @param {String} regexpStr
* @return {Array., Number>}
*/
exports.tokenizeClass = function(str, regexpStr) {
var tokens = []
, regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?(.)/g
, rs, c
;
while ((rs = regexp.exec(str)) != null) {
if (rs[1]) {
tokens.push(sets.words());
} else if (rs[2]) {
tokens.push(sets.ints());
} else if (rs[3]) {
tokens.push(sets.whitespace());
} else if (rs[4]) {
tokens.push(sets.notWords());
} else if (rs[5]) {
tokens.push(sets.notInts());
} else if (rs[6]) {
tokens.push(sets.notWhitespace());
} else if (rs[7]) {
tokens.push({
type: types.RANGE
, from: (rs[8] || rs[9]).charCodeAt(0)
, to: rs[10].charCodeAt(0)
});
} else if (c = rs[12]) {
tokens.push({
type: types.CHAR
, value: c.charCodeAt(0)
});
} else {
return [tokens, regexp.lastIndex];
}
}
exports.error(regexpStr, 'Unterminated character class');
};
/**
* Shortcut to throw errors.
*
* @param {String} regexp
* @param {String} msg
*/
exports.error = function(regexp, msg) {
throw new SyntaxError('Invalid regular expression: /' + regexp + '/: ' + msg);
};
},{"./sets":10,"./types":11}],13:[function(require,module,exports){
// A library of seedable RNGs implemented in Javascript.
//
// Usage:
//
// var seedrandom = require('seedrandom');
// var random = seedrandom(1); // or any seed.
// var x = random(); // 0 <= x < 1. Every bit is random.
// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness.
// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe.
// Period: ~2^116
// Reported to pass all BigCrush tests.
var alea = require('./lib/alea');
// xor128, a pure xor-shift generator by George Marsaglia.
// Period: 2^128-1.
// Reported to fail: MatrixRank and LinearComp.
var xor128 = require('./lib/xor128');
// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl.
// Period: 2^192-2^32
// Reported to fail: CollisionOver, SimpPoker, and LinearComp.
var xorwow = require('./lib/xorwow');
// xorshift7, by François Panneton and Pierre L'ecuyer, takes
// a different approach: it adds robustness by allowing more shifts
// than Marsaglia's original three. It is a 7-shift generator
// with 256 bits, that passes BigCrush with no systmatic failures.
// Period 2^256-1.
// No systematic BigCrush failures reported.
var xorshift7 = require('./lib/xorshift7');
// xor4096, by Richard Brent, is a 4096-bit xor-shift with a
// very long period that also adds a Weyl generator. It also passes
// BigCrush with no systematic failures. Its long period may
// be useful if you have many generators and need to avoid
// collisions.
// Period: 2^4128-2^32.
// No systematic BigCrush failures reported.
var xor4096 = require('./lib/xor4096');
// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random
// number generator derived from ChaCha, a modern stream cipher.
// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
// Period: ~2^127
// No systematic BigCrush failures reported.
var tychei = require('./lib/tychei');
// The original ARC4-based prng included in this library.
// Period: ~2^1600
var sr = require('./seedrandom');
sr.alea = alea;
sr.xor128 = xor128;
sr.xorwow = xorwow;
sr.xorshift7 = xorshift7;
sr.xor4096 = xor4096;
sr.tychei = tychei;
module.exports = sr;
},{"./lib/alea":14,"./lib/tychei":15,"./lib/xor128":16,"./lib/xor4096":17,"./lib/xorshift7":18,"./lib/xorwow":19,"./seedrandom":20}],14:[function(require,module,exports){
// A port of an algorithm by Johannes Baagøe , 2010
// https://baagoe.com/en/RandomMusings/javascript/
// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
// Original work is under MIT license -
// Copyright (C) 2010 by Johannes Baagøe
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
(function(global, module, define) {
function Alea(seed) {
var me = this, mash = Mash();
me.next = function() {
var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32
me.s0 = me.s1;
me.s1 = me.s2;
return me.s2 = t - (me.c = t | 0);
};
// Apply the seeding algorithm from Baagoe.
me.c = 1;
me.s0 = mash(' ');
me.s1 = mash(' ');
me.s2 = mash(' ');
me.s0 -= mash(seed);
if (me.s0 < 0) { me.s0 += 1; }
me.s1 -= mash(seed);
if (me.s1 < 0) { me.s1 += 1; }
me.s2 -= mash(seed);
if (me.s2 < 0) { me.s2 += 1; }
mash = null;
}
function copy(f, t) {
t.c = f.c;
t.s0 = f.s0;
t.s1 = f.s1;
t.s2 = f.s2;
return t;
}
function impl(seed, opts) {
var xg = new Alea(seed),
state = opts && opts.state,
prng = xg.next;
prng.int32 = function() { return (xg.next() * 0x100000000) | 0; }
prng.double = function() {
return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
};
prng.quick = prng;
if (state) {
if (typeof(state) == 'object') copy(state, xg);
prng.state = function() { return copy(xg, {}); }
}
return prng;
}
function Mash() {
var n = 0xefc8249d;
var mash = function(data) {
data = data.toString();
for (var i = 0; i < data.length; i++) {
n += data.charCodeAt(i);
var h = 0.02519603282416938 * n;
n = h >>> 0;
h -= n;
h *= n;
n = h >>> 0;
h -= n;
n += h * 0x100000000; // 2^32
}
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
};
return mash;
}
if (module && module.exports) {
module.exports = impl;
} else if (define && define.amd) {
define(function() { return impl; });
} else {
this.alea = impl;
}
})(
this,
(typeof module) == 'object' && module, // present in node.js
(typeof define) == 'function' && define // present with an AMD loader
);
},{}],15:[function(require,module,exports){
// A Javascript implementaion of the "Tyche-i" prng algorithm by
// Samuel Neves and Filipe Araujo.
// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
(function(global, module, define) {
function XorGen(seed) {
var me = this, strseed = '';
// Set up generator function.
me.next = function() {
var b = me.b, c = me.c, d = me.d, a = me.a;
b = (b << 25) ^ (b >>> 7) ^ c;
c = (c - d) | 0;
d = (d << 24) ^ (d >>> 8) ^ a;
a = (a - b) | 0;
me.b = b = (b << 20) ^ (b >>> 12) ^ c;
me.c = c = (c - d) | 0;
me.d = (d << 16) ^ (c >>> 16) ^ a;
return me.a = (a - b) | 0;
};
/* The following is non-inverted tyche, which has better internal
* bit diffusion, but which is about 25% slower than tyche-i in JS.
me.next = function() {
var a = me.a, b = me.b, c = me.c, d = me.d;
a = (me.a + me.b | 0) >>> 0;
d = me.d ^ a; d = d << 16 ^ d >>> 16;
c = me.c + d | 0;
b = me.b ^ c; b = b << 12 ^ d >>> 20;
me.a = a = a + b | 0;
d = d ^ a; me.d = d = d << 8 ^ d >>> 24;
me.c = c = c + d | 0;
b = b ^ c;
return me.b = (b << 7 ^ b >>> 25);
}
*/
me.a = 0;
me.b = 0;
me.c = 2654435769 | 0;
me.d = 1367130551;
if (seed === Math.floor(seed)) {
// Integer seed.
me.a = (seed / 0x100000000) | 0;
me.b = seed | 0;
} else {
// String seed.
strseed += seed;
}
// Mix in string seed, then discard an initial batch of 64 values.
for (var k = 0; k < strseed.length + 20; k++) {
me.b ^= strseed.charCodeAt(k) | 0;
me.next();
}
}
function copy(f, t) {
t.a = f.a;
t.b = f.b;
t.c = f.c;
t.d = f.d;
return t;
};
function impl(seed, opts) {
var xg = new XorGen(seed),
state = opts && opts.state,
prng = function() { return (xg.next() >>> 0) / 0x100000000; };
prng.double = function() {
do {
var top = xg.next() >>> 11,
bot = (xg.next() >>> 0) / 0x100000000,
result = (top + bot) / (1 << 21);
} while (result === 0);
return result;
};
prng.int32 = xg.next;
prng.quick = prng;
if (state) {
if (typeof(state) == 'object') copy(state, xg);
prng.state = function() { return copy(xg, {}); }
}
return prng;
}
if (module && module.exports) {
module.exports = impl;
} else if (define && define.amd) {
define(function() { return impl; });
} else {
this.tychei = impl;
}
})(
this,
(typeof module) == 'object' && module, // present in node.js
(typeof define) == 'function' && define // present with an AMD loader
);
},{}],16:[function(require,module,exports){
// A Javascript implementaion of the "xor128" prng algorithm by
// George Marsaglia. See https://www.jstatsoft.org/v08/i14/paper
(function(global, module, define) {
function XorGen(seed) {
var me = this, strseed = '';
me.x = 0;
me.y = 0;
me.z = 0;
me.w = 0;
// Set up generator function.
me.next = function() {
var t = me.x ^ (me.x << 11);
me.x = me.y;
me.y = me.z;
me.z = me.w;
return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8);
};
if (seed === (seed | 0)) {
// Integer seed.
me.x = seed;
} else {
// String seed.
strseed += seed;
}
// Mix in string seed, then discard an initial batch of 64 values.
for (var k = 0; k < strseed.length + 64; k++) {
me.x ^= strseed.charCodeAt(k) | 0;
me.next();
}
}
function copy(f, t) {
t.x = f.x;
t.y = f.y;
t.z = f.z;
t.w = f.w;
return t;
}
function impl(seed, opts) {
var xg = new XorGen(seed),
state = opts && opts.state,
prng = function() { return (xg.next() >>> 0) / 0x100000000; };
prng.double = function() {
do {
var top = xg.next() >>> 11,
bot = (xg.next() >>> 0) / 0x100000000,
result = (top + bot) / (1 << 21);
} while (result === 0);
return result;
};
prng.int32 = xg.next;
prng.quick = prng;
if (state) {
if (typeof(state) == 'object') copy(state, xg);
prng.state = function() { return copy(xg, {}); }
}
return prng;
}
if (module && module.exports) {
module.exports = impl;
} else if (define && define.amd) {
define(function() { return impl; });
} else {
this.xor128 = impl;
}
})(
this,
(typeof module) == 'object' && module, // present in node.js
(typeof define) == 'function' && define // present with an AMD loader
);
},{}],17:[function(require,module,exports){
// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm.
//
// This fast non-cryptographic random number generator is designed for
// use in Monte-Carlo algorithms. It combines a long-period xorshift
// generator with a Weyl generator, and it passes all common batteries
// of stasticial tests for randomness while consuming only a few nanoseconds
// for each prng generated. For background on the generator, see Brent's
// paper: "Some long-period random number generators using shifts and xors."
// https://arxiv.org/pdf/1104.3115.pdf
//
// Usage:
//
// var xor4096 = require('xor4096');
// random = xor4096(1); // Seed with int32 or string.
// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits.
// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits.
//
// For nonzero numeric keys, this impelementation provides a sequence
// identical to that by Brent's xorgens 3 implementaion in C. This
// implementation also provides for initalizing the generator with
// string seeds, or for saving and restoring the state of the generator.
//
// On Chrome, this prng benchmarks about 2.1 times slower than
// Javascript's built-in Math.random().
(function(global, module, define) {
function XorGen(seed) {
var me = this;
// Set up generator function.
me.next = function() {
var w = me.w,
X = me.X, i = me.i, t, v;
// Update Weyl generator.
me.w = w = (w + 0x61c88647) | 0;
// Update xor generator.
v = X[(i + 34) & 127];
t = X[i = ((i + 1) & 127)];
v ^= v << 13;
t ^= t << 17;
v ^= v >>> 15;
t ^= t >>> 12;
// Update Xor generator array state.
v = X[i] = v ^ t;
me.i = i;
// Result is the combination.
return (v + (w ^ (w >>> 16))) | 0;
};
function init(me, seed) {
var t, v, i, j, w, X = [], limit = 128;
if (seed === (seed | 0)) {
// Numeric seeds initialize v, which is used to generates X.
v = seed;
seed = null;
} else {
// String seeds are mixed into v and X one character at a time.
seed = seed + '\0';
v = 0;
limit = Math.max(limit, seed.length);
}
// Initialize circular array and weyl value.
for (i = 0, j = -32; j < limit; ++j) {
// Put the unicode characters into the array, and shuffle them.
if (seed) v ^= seed.charCodeAt((j + 32) % seed.length);
// After 32 shuffles, take v as the starting w value.
if (j === 0) w = v;
v ^= v << 10;
v ^= v >>> 15;
v ^= v << 4;
v ^= v >>> 13;
if (j >= 0) {
w = (w + 0x61c88647) | 0; // Weyl.
t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array.
i = (0 == t) ? i + 1 : 0; // Count zeroes.
}
}
// We have detected all zeroes; make the key nonzero.
if (i >= 128) {
X[(seed && seed.length || 0) & 127] = -1;
}
// Run the generator 512 times to further mix the state before using it.
// Factoring this as a function slows the main generator, so it is just
// unrolled here. The weyl generator is not advanced while warming up.
i = 127;
for (j = 4 * 128; j > 0; --j) {
v = X[(i + 34) & 127];
t = X[i = ((i + 1) & 127)];
v ^= v << 13;
t ^= t << 17;
v ^= v >>> 15;
t ^= t >>> 12;
X[i] = v ^ t;
}
// Storing state as object members is faster than using closure variables.
me.w = w;
me.X = X;
me.i = i;
}
init(me, seed);
}
function copy(f, t) {
t.i = f.i;
t.w = f.w;
t.X = f.X.slice();
return t;
};
function impl(seed, opts) {
if (seed == null) seed = +(new Date);
var xg = new XorGen(seed),
state = opts && opts.state,
prng = function() { return (xg.next() >>> 0) / 0x100000000; };
prng.double = function() {
do {
var top = xg.next() >>> 11,
bot = (xg.next() >>> 0) / 0x100000000,
result = (top + bot) / (1 << 21);
} while (result === 0);
return result;
};
prng.int32 = xg.next;
prng.quick = prng;
if (state) {
if (state.X) copy(state, xg);
prng.state = function() { return copy(xg, {}); }
}
return prng;
}
if (module && module.exports) {
module.exports = impl;
} else if (define && define.amd) {
define(function() { return impl; });
} else {
this.xor4096 = impl;
}
})(
this, // window object or global
(typeof module) == 'object' && module, // present in node.js
(typeof define) == 'function' && define // present with an AMD loader
);
},{}],18:[function(require,module,exports){
// A Javascript implementaion of the "xorshift7" algorithm by
// François Panneton and Pierre L'ecuyer:
// "On the Xorgshift Random Number Generators"
// https://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf
(function(global, module, define) {
function XorGen(seed) {
var me = this;
// Set up generator function.
me.next = function() {
// Update xor generator.
var X = me.x, i = me.i, t, v, w;
t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24);
t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10);
t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3);
t = X[(i + 4) & 7]; v ^= t ^ (t << 7);
t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9);
X[i] = v;
me.i = (i + 1) & 7;
return v;
};
function init(me, seed) {
var j, w, X = [];
if (seed === (seed | 0)) {
// Seed state array using a 32-bit integer.
w = X[0] = seed;
} else {
// Seed state using a string.
seed = '' + seed;
for (j = 0; j < seed.length; ++j) {
X[j & 7] = (X[j & 7] << 15) ^
(seed.charCodeAt(j) + X[(j + 1) & 7] << 13);
}
}
// Enforce an array length of 8, not all zeroes.
while (X.length < 8) X.push(0);
for (j = 0; j < 8 && X[j] === 0; ++j);
if (j == 8) w = X[7] = -1; else w = X[j];
me.x = X;
me.i = 0;
// Discard an initial 256 values.
for (j = 256; j > 0; --j) {
me.next();
}
}
init(me, seed);
}
function copy(f, t) {
t.x = f.x.slice();
t.i = f.i;
return t;
}
function impl(seed, opts) {
if (seed == null) seed = +(new Date);
var xg = new XorGen(seed),
state = opts && opts.state,
prng = function() { return (xg.next() >>> 0) / 0x100000000; };
prng.double = function() {
do {
var top = xg.next() >>> 11,
bot = (xg.next() >>> 0) / 0x100000000,
result = (top + bot) / (1 << 21);
} while (result === 0);
return result;
};
prng.int32 = xg.next;
prng.quick = prng;
if (state) {
if (state.x) copy(state, xg);
prng.state = function() { return copy(xg, {}); }
}
return prng;
}
if (module && module.exports) {
module.exports = impl;
} else if (define && define.amd) {
define(function() { return impl; });
} else {
this.xorshift7 = impl;
}
})(
this,
(typeof module) == 'object' && module, // present in node.js
(typeof define) == 'function' && define // present with an AMD loader
);
},{}],19:[function(require,module,exports){
// A Javascript implementaion of the "xorwow" prng algorithm by
// George Marsaglia. See https://www.jstatsoft.org/v08/i14/paper
(function(global, module, define) {
function XorGen(seed) {
var me = this, strseed = '';
// Set up generator function.
me.next = function() {
var t = (me.x ^ (me.x >>> 2));
me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v;
return (me.d = (me.d + 362437 | 0)) +
(me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0;
};
me.x = 0;
me.y = 0;
me.z = 0;
me.w = 0;
me.v = 0;
if (seed === (seed | 0)) {
// Integer seed.
me.x = seed;
} else {
// String seed.
strseed += seed;
}
// Mix in string seed, then discard an initial batch of 64 values.
for (var k = 0; k < strseed.length + 64; k++) {
me.x ^= strseed.charCodeAt(k) | 0;
if (k == strseed.length) {
me.d = me.x << 10 ^ me.x >>> 4;
}
me.next();
}
}
function copy(f, t) {
t.x = f.x;
t.y = f.y;
t.z = f.z;
t.w = f.w;
t.v = f.v;
t.d = f.d;
return t;
}
function impl(seed, opts) {
var xg = new XorGen(seed),
state = opts && opts.state,
prng = function() { return (xg.next() >>> 0) / 0x100000000; };
prng.double = function() {
do {
var top = xg.next() >>> 11,
bot = (xg.next() >>> 0) / 0x100000000,
result = (top + bot) / (1 << 21);
} while (result === 0);
return result;
};
prng.int32 = xg.next;
prng.quick = prng;
if (state) {
if (typeof(state) == 'object') copy(state, xg);
prng.state = function() { return copy(xg, {}); }
}
return prng;
}
if (module && module.exports) {
module.exports = impl;
} else if (define && define.amd) {
define(function() { return impl; });
} else {
this.xorwow = impl;
}
})(
this,
(typeof module) == 'object' && module, // present in node.js
(typeof define) == 'function' && define // present with an AMD loader
);
},{}],20:[function(require,module,exports){
/*
Copyright 2014 David Bau.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function (pool, math) {
//
// The following constants are related to IEEE 754 limits.
//
var global = this,
width = 256, // each RC4 output is 0 <= x < 256
chunks = 6, // at least six RC4 outputs for each double
digits = 52, // there are 52 significant digits in a double
rngname = 'random', // rngname: name for Math.random and Math.seedrandom
startdenom = math.pow(width, chunks),
significance = math.pow(2, digits),
overflow = significance * 2,
mask = width - 1,
nodecrypto; // node.js crypto module, initialized at the bottom.
//
// seedrandom()
// This is the seedrandom function described above.
//
function seedrandom(seed, options, callback) {
var key = [];
options = (options == true) ? { entropy: true } : (options || {});
// Flatten the seed string or build one from local entropy if needed.
var shortseed = mixkey(flatten(
options.entropy ? [seed, tostring(pool)] :
(seed == null) ? autoseed() : seed, 3), key);
// Use the seed to initialize an ARC4 generator.
var arc4 = new ARC4(key);
// This function returns a random double in [0, 1) that contains
// randomness in every bit of the mantissa of the IEEE 754 value.
var prng = function() {
var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
d = startdenom, // and denominator d = 2 ^ 48.
x = 0; // and no 'extra last byte'.
while (n < significance) { // Fill up all significant digits by
n = (n + x) * width; // shifting numerator and
d *= width; // denominator and generating a
x = arc4.g(1); // new least-significant-byte.
}
while (n >= overflow) { // To avoid rounding up, before adding
n /= 2; // last byte, shift everything
d /= 2; // right using integer math until
x >>>= 1; // we have exactly the desired bits.
}
return (n + x) / d; // Form the number within [0, 1).
};
prng.int32 = function() { return arc4.g(4) | 0; }
prng.quick = function() { return arc4.g(4) / 0x100000000; }
prng.double = prng;
// Mix the randomness into accumulated entropy.
mixkey(tostring(arc4.S), pool);
// Calling convention: what to return as a function of prng, seed, is_math.
return (options.pass || callback ||
function(prng, seed, is_math_call, state) {
if (state) {
// Load the arc4 state from the given state if it has an S array.
if (state.S) { copy(state, arc4); }
// Only provide the .state method if requested via options.state.
prng.state = function() { return copy(arc4, {}); }
}
// If called as a method of Math (Math.seedrandom()), mutate
// Math.random because that is how seedrandom.js has worked since v1.0.
if (is_math_call) { math[rngname] = prng; return seed; }
// Otherwise, it is a newer calling convention, so return the
// prng directly.
else return prng;
})(
prng,
shortseed,
'global' in options ? options.global : (this == math),
options.state);
}
math['seed' + rngname] = seedrandom;
//
// ARC4
//
// An ARC4 implementation. The constructor takes a key in the form of
// an array of at most (width) integers that should be 0 <= x < (width).
//
// The g(count) method returns a pseudorandom integer that concatenates
// the next (count) outputs from ARC4. Its return value is a number x
// that is in the range 0 <= x < (width ^ count).
//
function ARC4(key) {
var t, keylen = key.length,
me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
// The empty key [] is treated as [0].
if (!keylen) { key = [keylen++]; }
// Set up S using the standard key scheduling algorithm.
while (i < width) {
s[i] = i++;
}
for (i = 0; i < width; i++) {
s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
s[j] = t;
}
// The "g" method returns the next (count) outputs as one number.
(me.g = function(count) {
// Using instance members instead of closure state nearly doubles speed.
var t, r = 0,
i = me.i, j = me.j, s = me.S;
while (count--) {
t = s[i = mask & (i + 1)];
r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
}
me.i = i; me.j = j;
return r;
// For robust unpredictability, the function call below automatically
// discards an initial batch of values. This is called RC4-drop[256].
// See https://google.com/search?q=rsa+fluhrer+response&btnI
})(width);
}
//
// copy()
// Copies internal state of ARC4 to or from a plain object.
//
function copy(f, t) {
t.i = f.i;
t.j = f.j;
t.S = f.S.slice();
return t;
};
//
// flatten()
// Converts an object tree to nested arrays of strings.
//
function flatten(obj, depth) {
var result = [], typ = (typeof obj), prop;
if (depth && typ == 'object') {
for (prop in obj) {
try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
}
}
return (result.length ? result : typ == 'string' ? obj : obj + '\0');
}
//
// mixkey()
// Mixes a string seed into a key that is an array of integers, and
// returns a shortened string seed that is equivalent to the result key.
//
function mixkey(seed, key) {
var stringseed = seed + '', smear, j = 0;
while (j < stringseed.length) {
key[mask & j] =
mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
}
return tostring(key);
}
//
// autoseed()
// Returns an object for autoseeding, using window.crypto and Node crypto
// module if available.
//
function autoseed() {
try {
if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); }
var out = new Uint8Array(width);
(global.crypto || global.msCrypto).getRandomValues(out);
return tostring(out);
} catch (e) {
var browser = global.navigator,
plugins = browser && browser.plugins;
return [+new Date, global, plugins, global.screen, tostring(pool)];
}
}
//
// tostring()
// Converts an array of charcodes to a string
//
function tostring(a) {
return String.fromCharCode.apply(0, a);
}
//
// When seedrandom.js is loaded, we immediately mix a few bits
// from the built-in RNG into the entropy pool. Because we do
// not want to interfere with deterministic PRNG state later,
// seedrandom will not call math.random on its own again after
// initialization.
//
mixkey(math.random(), pool);
//
// Nodejs and AMD support: export the implementation as a module using
// either convention.
//
if ((typeof module) == 'object' && module.exports) {
module.exports = seedrandom;
// When in node.js, try using crypto package for autoseeding.
try {
nodecrypto = require('crypto');
} catch (ex) {}
} else if ((typeof define) == 'function' && define.amd) {
define(function() { return seedrandom; });
}
// End anonymous scope, and pass initial values.
})(
[], // pool: entropy pool starts empty
Math // math: package containing random, pow, and seedrandom
);
},{"crypto":undefined}],21:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _integer = require("./integer");
var _integer2 = _interopRequireDefault(_integer);
var random = function random() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return Boolean(_integer2["default"].boundedRandom(0, 1, prng));
};
exports["default"] = { random: random };
module.exports = exports["default"];
},{"./integer":26}],22:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _integer = require("./integer");
var _integer2 = _interopRequireDefault(_integer);
var randomRgb = function randomRgb() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return {
red: _integer2["default"].randomByte(prng),
green: _integer2["default"].randomByte(prng),
blue: _integer2["default"].randomByte(prng)
};
};
exports["default"] = { randomRgb: randomRgb };
module.exports = exports["default"];
},{"./integer":26}],23:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _float = require("./float");
var _float2 = _interopRequireDefault(_float);
var inverseNormalCumulativeDistribution = function inverseNormalCumulativeDistribution(probability) {
var high = probability > 0.97575;
var low = probability < 0.02425;
var numCoefficients = undefined,
denomCoeffcients = undefined,
numMaxExponent = undefined,
denomMaxExponent = undefined,
coefficient = undefined,
base = undefined;
if (low || high) {
numCoefficients = [-7.784894002430293e-3, -3.223964580411365e-1, -2.400758277161838, -2.549732539343734, 4.374664141464968];
denomCoeffcients = [7.784695709041462e-3, 3.224671290700398e-1, 2.445134137142996, 3.754408661907416];
numMaxExponent = 5;
denomMaxExponent = 4;
coefficient = low ? 1 : -1;
base = Math.sqrt(-2 * Math.log(low ? probability : 1 - probability));
} else {
numCoefficients = [-3.969683028665376e1, 2.209460984245205e2, -2.759285104469687e2, 1.383577518672690e2, -3.066479806614716e1, 2.506628277459239];
denomCoeffcients = [-5.447609879822406e1, 1.615858368580409e2, -1.556989798598866e2, 6.680131188771972e1, -1.328068155288572e1];
numMaxExponent = 5;
denomMaxExponent = 5;
coefficient = probability - 0.5;
base = Math.pow(coefficient, 2);
}
var mapMaxExp = function mapMaxExp(maxExp) {
return function (value, index) {
return value * Math.pow(base, maxExp - index);
};
};
var sum = function sum(arr) {
return arr.reduce(function (result, value) {
return result + value;
}, 0);
};
var numerator = sum(numCoefficients.map(mapMaxExp(numMaxExponent)));
var denominator = sum(denomCoeffcients.map(mapMaxExp(denomMaxExponent))) + 1;
return coefficient * numerator / denominator;
};
var randomNormallyDistributedFloat = function randomNormallyDistributedFloat(mean, stdev, min, max) {
var prng = arguments.length <= 4 || arguments[4] === undefined ? Math.random : arguments[4];
var seed = _float2["default"].boundedRandom(0, 1, prng);
var result = inverseNormalCumulativeDistribution(seed) * stdev + mean;
return min != null && max != null ? Math.min(max, Math.max(min, result)) : result;
};
exports["default"] = { randomNormallyDistributedFloat: randomNormallyDistributedFloat };
module.exports = exports["default"];
},{"./float":24}],24:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var boundedRandom = function boundedRandom() {
var min = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
var max = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
var prng = arguments.length <= 2 || arguments[2] === undefined ? Math.random : arguments[2];
var spread = max - min;
return prng() * spread + min;
};
exports["default"] = { boundedRandom: boundedRandom };
module.exports = exports["default"];
},{}],25:[function(require,module,exports){
(function (global){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _lodashIdentity = require("lodash.identity");
var _lodashIdentity2 = _interopRequireDefault(_lodashIdentity);
var _lodashIsFunction = require("lodash.isFunction");
var _lodashIsFunction2 = _interopRequireDefault(_lodashIsFunction);
var _lodashIsregexp = require("lodash.isregexp");
var _lodashIsregexp2 = _interopRequireDefault(_lodashIsregexp);
var _lodashIsString = require("lodash.isString");
var _lodashIsString2 = _interopRequireDefault(_lodashIsString);
var _lodashRange = require("lodash.range");
var _lodashRange2 = _interopRequireDefault(_lodashRange);
var _boolean = require("./boolean");
var _boolean2 = _interopRequireDefault(_boolean);
var _color = require("./color");
var _color2 = _interopRequireDefault(_color);
var _distribution = require("./distribution");
var _distribution2 = _interopRequireDefault(_distribution);
var _float = require("./float");
var _float2 = _interopRequireDefault(_float);
var _integer = require("./integer");
var _integer2 = _interopRequireDefault(_integer);
var _seedrandom = require("seedrandom");
var _seedrandom2 = _interopRequireDefault(_seedrandom);
var _set = require("./set");
var _set2 = _interopRequireDefault(_set);
var _string = require("./string");
var _string2 = _interopRequireDefault(_string);
var booleanGenerator = function booleanGenerator(_ref2) {
var prng = _ref2.prng;
return function () {
return _boolean2["default"].random(prng);
};
};
var colorGenerator = function colorGenerator(_ref3) {
var prng = _ref3.prng;
return function () {
return _color2["default"].randomRgb(prng);
};
};
var floatGenerator = function floatGenerator(_ref4) {
var min = _ref4.min;
var max = _ref4.max;
var mean = _ref4.mean;
var prng = _ref4.prng;
var stdev = _ref4.stdev;
if (mean && stdev) {
return function () {
return _distribution2["default"].randomNormallyDistributedFloat(mean, stdev, min, max, prng);
};
} else {
return function () {
return _float2["default"].boundedRandom(min, max, prng);
};
}
};
var integerGenerator = function integerGenerator(_ref5) {
var min = _ref5.min;
var max = _ref5.max;
var prng = _ref5.prng;
return function () {
return _integer2["default"].boundedRandom(min, max, prng);
};
};
var setGenerator = function setGenerator(_ref6) {
var values = _ref6.values;
var prng = _ref6.prng;
var _ref6$replacement = _ref6.replacement;
var replacement = _ref6$replacement === undefined ? true : _ref6$replacement;
var _ref6$shuffle = _ref6.shuffle;
var shuffle = _ref6$shuffle === undefined ? false : _ref6$shuffle;
var _ref6$weights = _ref6.weights;
var weights = _ref6$weights === undefined ? null : _ref6$weights;
if (!values || !values.length) {
throw Error("Must provide a 'values' array for a set generator.");
}
if (shuffle) {
return function () {
return _set2["default"].shuffleSet(values, prng);
};
} else if (replacement) {
if (weights) {
return function () {
return _set2["default"].weightedRandomMember(values, weights, prng);
};
} else {
return function () {
return _set2["default"].randomMember(values, prng);
};
}
} else {
return function () {
return _set2["default"].randomMemberWithoutReplacement(values, prng);
};
}
};
var stringGenerator = function stringGenerator(_ref7) {
var kind = _ref7.kind;
var _ref7$expression = _ref7.expression;
var expression = _ref7$expression === undefined ? "[" + kind + "]" : _ref7$expression;
var _ref7$ignoreCase = _ref7.ignoreCase;
var ignoreCase = _ref7$ignoreCase === undefined ? false : _ref7$ignoreCase;
var _ref7$maxWildcard = _ref7.maxWildcard;
var maxWildcard = _ref7$maxWildcard === undefined ? 100 : _ref7$maxWildcard;
var prng = _ref7.prng;
var _ref7$unicode = _ref7.unicode;
var unicode = _ref7$unicode === undefined ? false : _ref7$unicode;
return (function () {
var isRe = (0, _lodashIsregexp2["default"])(expression);
var exprSource = isRe ? expression.source : expression;
var options = {
ignoreCase: ignoreCase || isRe && expression.ignoreCase,
maxWildcard: maxWildcard,
prng: prng
};
return _string2["default"].generateString(unicode, exprSource, options);
})();
};
var KIND_GENERATORS = {
"boolean": booleanGenerator,
"float": floatGenerator,
"integer": integerGenerator,
"set": setGenerator,
"color": colorGenerator,
"rgb": colorGenerator,
"string": stringGenerator,
"a-z": stringGenerator,
"A-Z": stringGenerator
};
var VALID_KINDS = Object.keys(KIND_GENERATORS);
var validateKind = function validateKind(kind) {
if (VALID_KINDS.indexOf(kind) !== -1) {
return true;
}
throw Error(kind + " is in invalid kind. Valid kinds include:\n " + VALID_KINDS.join(', '));
};
var getConfigWithDefaults = function getConfigWithDefaults(rawConfig) {
return _extends({ kind: "float" }, rawConfig, { prng: getPrng(rawConfig) });
};
var createGenerator = function createGenerator(rawConfig) {
var config = getConfigWithDefaults(rawConfig);
validateKind(config.kind);
return KIND_GENERATORS[config.kind](config);
};
var getNextValueGenerator = function getNextValueGenerator(configs) {
configs[0] = configs[0] ? configs[0] : {};
var generators = (function () {
var _generators = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = configs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var config = _step.value;
_generators.push(createGenerator(config));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"]) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return _generators;
})();
if (generators.length === 1) {
return function () {
return generators[0]();
};
} else {
return function () {
return (function () {
var _ref = [];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = generators[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var generator = _step2.value;
_ref.push(generator());
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2["return"]) {
_iterator2["return"]();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return _ref;
})();
};
}
};
var getPrng = function getPrng(_ref8) {
var seed = _ref8.seed;
var prng = _ref8.prng;
var defaultPrng = seed ? _seedrandom2["default"] : Math.random;
var basePrng = prng ? prng : defaultPrng;
return seed ? basePrng(seed) : basePrng;
};
var parseArgs = function parseArgs(args) {
var defaults = { configs: [], mutator: null, name: null };
return args.reduce(function (result, arg) {
if (result.mutator || (0, _lodashIsString2["default"])(arg)) {
result.name = arg;
} else if ((0, _lodashIsFunction2["default"])(arg)) {
result.mutator = arg;
} else {
result.configs.push(arg);
}
return result;
}, defaults);
};
var Stochator = (function () {
_createClass(Stochator, null, [{
key: "fromDistribution",
value: {
normal: _distribution2["default"].randomNormallyDistributedFloat
},
enumerable: true
}, {
key: "randomAsciiCharacter",
value: _string2["default"].randomAsciiCharacter,
enumerable: true
}, {
key: "randomAsciiString",
value: _string2["default"].randomAsciiString,
enumerable: true
}, {
key: "randomBoolean",
value: _boolean2["default"].random,
enumerable: true
}, {
key: "randomByte",
value: _integer2["default"].randomByte,
enumerable: true
}, {
key: "randomCharacterFromRange",
value: _string2["default"].randomCharacterFromRange,
enumerable: true
}, {
key: "randomColor",
value: _color2["default"].randomRgb,
enumerable: true
}, {
key: "randomFloat",
value: _float2["default"].boundedRandom,
enumerable: true
}, {
key: "randomInteger",
value: _integer2["default"].boundedRandom,
enumerable: true
}, {
key: "randomLowercaseCharacter",
value: _string2["default"].randomLowercaseCharacter,
enumerable: true
}, {
key: "randomSetMember",
value: _set2["default"].randomMember,
enumerable: true
}, {
key: "randomSetMemberWithoutReplacement",
value: _set2["default"].randomMemberWithoutReplacement,
enumerable: true
}, {
key: "randomUnicodeCharacter",
value: _string2["default"].randomUnicodeCharacter,
enumerable: true
}, {
key: "randomUnicodeString",
value: _string2["default"].randomUnicodeString,
enumerable: true
}, {
key: "randomUppercaseCharacter",
value: _string2["default"].randomUppercaseCharacter,
enumerable: true
}, {
key: "shuffleSet",
value: _set2["default"].shuffleSet,
enumerable: true
}, {
key: "weightedRandomSetMember",
value: _set2["default"].weightedRandomMember,
enumerable: true
}]);
function Stochator() {
var _this = this;
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_classCallCheck(this, Stochator);
this.VERSION = "0.6";
this._value = 0;
var _parseArgs = parseArgs(args);
var configs = _parseArgs.configs;
var mutator = _parseArgs.mutator;
var name = _parseArgs.name;
// If the mutator is provided, override the default identity func.
this.mutate = mutator ? function (nextValue) {
return mutator(nextValue, _this.getValue());
} : _lodashIdentity2["default"];
// Transform the configs to a func to get the next value.
var getNext = getNextValueGenerator(configs);
// Assign `name` to the next mutated value(s), after `times` iterations.
// If `times` is 1, just return the value, otherwise return an array.
this.next = function () {
var times = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0];
var values = (function () {
var _values = [];
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = (0, _lodashRange2["default"])(1, times + 1)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var time = _step3.value;
_values.push(_this.setValue(_this.mutate(getNext())));
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3["return"]) {
_iterator3["return"]();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
return _values;
})();
return times == 1 ? values[0] : values;
};
if (name) {
this[name] = function () {
return _this.next.apply(_this, arguments);
};
}
}
_createClass(Stochator, [{
key: "getValue",
value: function getValue() {
return this._value;
}
}, {
key: "setValue",
value: function setValue(value) {
this._value = value;
return this._value;
}
}, {
key: "toString",
value: function toString() {
return "[object Stochator]";
}
}]);
return Stochator;
})();
exports["default"] = Stochator;
if (global) {
global.Stochator = Stochator;
}
module.exports = exports["default"];
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./boolean":21,"./color":22,"./distribution":23,"./float":24,"./integer":26,"./set":27,"./string":28,"lodash.identity":2,"lodash.isFunction":3,"lodash.isString":4,"lodash.isregexp":5,"lodash.range":6,"seedrandom":13}],26:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var boundedRandom = function boundedRandom() {
var min = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
var max = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
var prng = arguments.length <= 2 || arguments[2] === undefined ? Math.random : arguments[2];
var spread = 1 + max - min;
return Math.floor(prng() * spread) + min;
};
var randomByte = function randomByte() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return boundedRandom(0, 255, prng);
};
exports["default"] = { boundedRandom: boundedRandom, randomByte: randomByte };
module.exports = exports["default"];
},{}],27:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _float = require("./float");
var _float2 = _interopRequireDefault(_float);
var _integer = require("./integer");
var _integer2 = _interopRequireDefault(_integer);
var randomMember = function randomMember(values) {
var prng = arguments.length <= 1 || arguments[1] === undefined ? Math.random : arguments[1];
var max = values.length - 1;
return values[_integer2["default"].boundedRandom(0, max, prng)];
};
var randomMemberWithoutReplacement = function randomMemberWithoutReplacement(values) {
var prng = arguments.length <= 1 || arguments[1] === undefined ? Math.random : arguments[1];
if (values.length > 0) {
var _index = _integer2["default"].boundedRandom(0, values.length - 1, prng);
var value = values[_index];
values.splice(_index, 1);
return value;
}
};
var weightedRandomMember = function weightedRandomMember(values, weights) {
var prng = arguments.length <= 2 || arguments[2] === undefined ? Math.random : arguments[2];
var member = undefined;
var weightSum = 0;
var threshold = _float2["default"].boundedRandom(0, 1, prng);
values.forEach(function (value, index) {
if (member) {
return;
}
var weight = weights[index];
if (threshold <= weightSum + weight && threshold >= weightSum) {
member = value;
}
weightSum += weight;
});
return member;
};
var shuffle = function shuffle(values) {
var prng = arguments.length <= 1 || arguments[1] === undefined ? Math.random : arguments[1];
var valuesRef = [].concat(_toConsumableArray(values));
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = range(0, valuesRef.length)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
index = _step.value;
randomIndex = _integer2["default"].boundedRandom(0, index, prng);
tmp = valuesRef[index];
valuesRef[index] = valuesRef[randomIndex];
valuesRef[randomIndex] = tmp;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"]) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return valuesRef;
};
exports["default"] = {
randomMember: randomMember,
randomMemberWithoutReplacement: randomMemberWithoutReplacement,
weightedRandomMember: weightedRandomMember,
shuffle: shuffle
};
module.exports = exports["default"];
},{"./float":24,"./integer":26}],28:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _expanders, _generators;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var _boolean = require("./boolean");
var _boolean2 = _interopRequireDefault(_boolean);
var _integer = require("./integer");
var _integer2 = _interopRequireDefault(_integer);
var _set = require("./set");
var _set2 = _interopRequireDefault(_set);
var _ret = require("ret");
var _ret2 = _interopRequireDefault(_ret);
var _discontinuousRange = require("discontinuous-range");
var _discontinuousRange2 = _interopRequireDefault(_discontinuousRange);
var _lodashRange = require("lodash.range");
var _lodashRange2 = _interopRequireDefault(_lodashRange);
var LOWERCASE_RANGE = [97, 122];
var UPPERCASE_RANGE = [65, 90];
var ASCII_RANGE = [32, 126];
var UNICODE_RANGE = [0, 65535];
var AsciiDRange = _discontinuousRange2["default"].apply(undefined, ASCII_RANGE);
var UnicodeDRange = _discontinuousRange2["default"].apply(undefined, UNICODE_RANGE);
var inRange = function inRange(_ref, n) {
var _ref2 = _slicedToArray(_ref, 2);
var min = _ref2[0];
var max = _ref2[1];
return n >= min && n <= max;
};
var changeCase = function changeCase(code) {
var lowercase = inRange(LOWERCASE_RANGE, code);
var uppercase = inRange(UPPERCASE_RANGE, code);
return lowercase || uppercase ? code + (lowercase ? -32 : 32) : code;
};
var createChar = function createChar(code, ignoreCase, prng) {
return code === null ? '' : String.fromCharCode(ignoreCase && _boolean2["default"].random(prng) ? changeCase(code) : code);
};
var expandCharacter = function expandCharacter(_ref3) {
var value = _ref3.value;
return (0, _discontinuousRange2["default"])(value);
};
var expandRange = function expandRange(_ref4) {
var from = _ref4.from;
var to = _ref4.to;
return (0, _discontinuousRange2["default"])(from, to);
};
var expandSet = function expandSet(token, range) {
var drange = (0, _discontinuousRange2["default"])();
var setRanges = token.set.map(function (code) {
return expand(code, range);
});
setRanges.forEach(function (setRange) {
return drange.add(setRange);
});
return token.not ? range.clone().subtract(drange) : drange;
};
var expanders = (_expanders = {}, _defineProperty(_expanders, _ret2["default"].types.SET, expandSet), _defineProperty(_expanders, _ret2["default"].types.RANGE, expandRange), _defineProperty(_expanders, _ret2["default"].types.CHAR, expandCharacter), _expanders);
var expand = function expand(token) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return expanders[token.type].apply(expanders, [token].concat(args));
};
// These generators accept a token and the options object and return a character
// code.
var generateCharFromSet = function generateCharFromSet(token, _ref5) {
var range = _ref5.range;
var prng = _ref5.prng;
var set = expand(token, range);
return set.index(_integer2["default"].boundedRandom(0, set.length - 1, prng));
};
var generateCharFromRange = function generateCharFromRange(_ref6, _ref7) {
var from = _ref6.from;
var to = _ref6.to;
var prng = _ref7.prng;
return _integer2["default"].boundedRandom(from, to, prng);
};
var generateChar = function generateChar(_ref8) {
var value = _ref8.value;
return value;
};
var createCharGenerator = function createCharGenerator(func) {
return function (token, _, _ref9) {
var range = _ref9.range;
var ignoreCase = _ref9.ignoreCase;
var prng = _ref9.prng;
return createChar(func(token, { range: range, ignoreCase: ignoreCase, prng: prng }), ignoreCase, prng);
};
};
// These generators accept a token, the groups and the options and return a
// sequence of tokens, which are then in turn passed to generator functions.
var generateFromGroup = function generateFromGroup(_ref10, _, _ref11) {
var notFollowedBy = _ref10.notFollowedBy;
var options = _ref10.options;
var stack = _ref10.stack;
var prng = _ref11.prng;
return notFollowedBy ? [] : options ? _set2["default"].randomMember(options, prng) : stack;
};
var generateRepeat = function generateRepeat(token, _, options) {
var max = token.max === Infinity ? token.min + options.max : token.max;
return (0, _lodashRange2["default"])(_integer2["default"].boundedRandom(token.min, max, options.prng)).map(function () {
return token.value;
});
};
var createSequenceGenerator = function createSequenceGenerator(func) {
return function (token, groups, options) {
return func(token, groups, options).map(function (value) {
return generateFromToken(value, groups, options);
}).join('');
};
};
// Generator dispatch table based upon the token type.
var generators = (_generators = {}, _defineProperty(_generators, _ret2["default"].types.ROOT, createSequenceGenerator(generateFromGroup)), _defineProperty(_generators, _ret2["default"].types.GROUP, createSequenceGenerator(generateFromGroup)), _defineProperty(_generators, _ret2["default"].types.POSITION, function () {
return '';
}), _defineProperty(_generators, _ret2["default"].types.REPETITION, createSequenceGenerator(generateRepeat)), _defineProperty(_generators, _ret2["default"].types.REFERENCE, function (_ref12, groups) {
var value = _ref12.value;
return groups[value - 1];
}), _defineProperty(_generators, _ret2["default"].types.CHAR, createCharGenerator(generateChar)), _defineProperty(_generators, _ret2["default"].types.SET, createCharGenerator(generateCharFromSet)), _defineProperty(_generators, _ret2["default"].types.RANGE, createCharGenerator(generateCharFromRange)), _generators);
var generateFromToken = function generateFromToken(token, groups, options) {
var result = generators[token.type](token, groups, options);
if (token.type === _ret2["default"].types.GROUP && token.remember) {
groups.push(result);
}
return result;
};
var generateStringFromRange = function generateStringFromRange(range, expression, options) {
return function () {
return generateFromToken((0, _ret2["default"])(expression), [], _extends({ range: range }, options));
};
};
// Exported public functions.
var generateCharacterFromRange = function generateCharacterFromRange(_ref13, _ref14) {
var _ref132 = _slicedToArray(_ref13, 2);
var min = _ref132[0];
var max = _ref132[1];
var prng = _ref14.prng;
return generateStringFromRange((0, _discontinuousRange2["default"])(min, max), '.', { prng: prng });
};
var generateString = function generateString(unicode, expression, options) {
return generateStringFromRange(unicode ? UnicodeDRange : AsciiDRange, expression, options);
};
var randomCharacterFromRange = function randomCharacterFromRange(range) {
var prng = arguments.length <= 1 || arguments[1] === undefined ? Math.random : arguments[1];
return generateCharacterFromRange(range, { prng: prng })();
};
var randomAsciiString = function randomAsciiString(expression, ignoreCase) {
var prng = arguments.length <= 2 || arguments[2] === undefined ? Math.random : arguments[2];
return generateStringFromRange(AsciiDRange, expression, { ignoreCase: ignoreCase, prng: prng });
};
var randomUnicodeString = function randomUnicodeString(expression, ignoreCase) {
var prng = arguments.length <= 2 || arguments[2] === undefined ? Math.random : arguments[2];
return generateStringFromRange(UnicodeDRange, expression, { ignoreCase: ignoreCase, prng: prng });
};
var randomAsciiCharacter = function randomAsciiCharacter() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return generateCharacterFromRange(ASCII_RANGE, { prng: prng })();
};
var randomLowercaseCharacter = function randomLowercaseCharacter() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return generateCharacterFromRange(LOWERCASE_RANGE, { prng: prng })();
};
var randomUnicodeCharacter = function randomUnicodeCharacter() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return generateCharacterFromRange(UNICODE_RANGE, { prng: prng })();
};
var randomUppercaseCharacter = function randomUppercaseCharacter() {
var prng = arguments.length <= 0 || arguments[0] === undefined ? Math.random : arguments[0];
return generateCharacterFromRange(UPPERCASE_RANGE, { prng: prng })();
};
exports["default"] = {
generateString: generateString,
randomCharacterFromRange: randomCharacterFromRange,
randomAsciiString: randomAsciiString,
randomUnicodeString: randomUnicodeString,
randomAsciiCharacter: randomAsciiCharacter,
randomLowercaseCharacter: randomLowercaseCharacter,
randomUnicodeCharacter: randomUnicodeCharacter,
randomUppercaseCharacter: randomUppercaseCharacter
};
module.exports = exports["default"];
},{"./boolean":21,"./integer":26,"./set":27,"discontinuous-range":1,"lodash.range":6,"ret":8}]},{},[25]);