find-node-modules
Version:
Return an array of all parent node_modules directories
1,567 lines (1,360 loc) • 1.03 MB
JavaScript
// This is an `every` implementation that works for all iterables
var every = function every(obj, fn) {
var pass = true;
try {
/* eslint-disable-next-line local-rules/no-prototype-methods */
obj.forEach(function() {
if (!fn.apply(this, arguments)) {
// Throwing an error is the only way to break `forEach`
throw new Error();
}
});
} catch (e) {
pass = false;
}
return pass;
};
var functionName = function functionName(func) {
return (
func.displayName ||
func.name ||
// Use function decomposition as a last resort to get function
// name. Does not rely on function decomposition to work - if it
// doesn't debugging will be slightly less informative
// (i.e. toString will say 'spy' rather than 'myFunc').
(String(func).match(/function ([^\s\(]+)/) || [])[1]
);
};
var call = Function.call;
var copyPrototype = function copyPrototypeMethods(prototype) {
/* eslint-disable local-rules/no-prototype-methods */
return Object.getOwnPropertyNames(prototype).reduce(function(result, name) {
// ignore size because it throws from Map
if (
name !== "size" &&
name !== "caller" &&
name !== "callee" &&
name !== "arguments" &&
typeof prototype[name] === "function"
) {
result[name] = call.bind(prototype[name]);
}
return result;
}, Object.create(null));
};
var array = copyPrototype(Array.prototype);
var _function = copyPrototype(Function.prototype);
var object = copyPrototype(Object.prototype);
var string = copyPrototype(String.prototype);
var prototypes = {
array: array,
function: _function,
object: object,
string: string
};
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
}
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var typeDetect = createCommonjsModule(function (module, exports) {
(function (global, factory) {
module.exports = factory();
}(commonjsGlobal, (function () {
/* !
* type-detect
* Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
* MIT Licensed
*/
var promiseExists = typeof Promise === 'function';
/* eslint-disable no-undef */
var globalObject = typeof self === 'object' ? self : commonjsGlobal; // eslint-disable-line id-blacklist
var symbolExists = typeof Symbol !== 'undefined';
var mapExists = typeof Map !== 'undefined';
var setExists = typeof Set !== 'undefined';
var weakMapExists = typeof WeakMap !== 'undefined';
var weakSetExists = typeof WeakSet !== 'undefined';
var dataViewExists = typeof DataView !== 'undefined';
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
var toStringLeftSliceLength = 8;
var toStringRightSliceLength = -1;
/**
* ### typeOf (obj)
*
* Uses `Object.prototype.toString` to determine the type of an object,
* normalising behaviour across engine versions & well optimised.
*
* @param {Mixed} object
* @return {String} object type
* @api public
*/
function typeDetect(obj) {
/* ! Speed optimisation
* Pre:
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
* boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
* number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
* undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
* function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
* Post:
* string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
* boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
* number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
*/
var typeofObj = typeof obj;
if (typeofObj !== 'object') {
return typeofObj;
}
/* ! Speed optimisation
* Pre:
* null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
* Post:
* null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
*/
if (obj === null) {
return 'null';
}
/* ! Spec Conformance
* Test: `Object.prototype.toString.call(window)``
* - Node === "[object global]"
* - Chrome === "[object global]"
* - Firefox === "[object Window]"
* - PhantomJS === "[object Window]"
* - Safari === "[object Window]"
* - IE 11 === "[object Window]"
* - IE Edge === "[object Window]"
* Test: `Object.prototype.toString.call(this)``
* - Chrome Worker === "[object global]"
* - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
* - Safari Worker === "[object DedicatedWorkerGlobalScope]"
* - IE 11 Worker === "[object WorkerGlobalScope]"
* - IE Edge Worker === "[object WorkerGlobalScope]"
*/
if (obj === globalObject) {
return 'global';
}
/* ! Speed optimisation
* Pre:
* array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
* Post:
* array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
*/
if (
Array.isArray(obj) &&
(symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
) {
return 'Array';
}
// Not caching existence of `window` and related properties due to potential
// for `window` to be unset before tests in quasi-browser environments.
if (typeof window === 'object' && window !== null) {
/* ! Spec Conformance
* (https://html.spec.whatwg.org/multipage/browsers.html#location)
* WhatWG HTML$7.7.3 - The `Location` interface
* Test: `Object.prototype.toString.call(window.location)``
* - IE <=11 === "[object Object]"
* - IE Edge <=13 === "[object Object]"
*/
if (typeof window.location === 'object' && obj === window.location) {
return 'Location';
}
/* ! Spec Conformance
* (https://html.spec.whatwg.org/#document)
* WhatWG HTML$3.1.1 - The `Document` object
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
* which suggests that browsers should use HTMLTableCellElement for
* both TD and TH elements. WhatWG separates these.
* WhatWG HTML states:
* > For historical reasons, Window objects must also have a
* > writable, configurable, non-enumerable property named
* > HTMLDocument whose value is the Document interface object.
* Test: `Object.prototype.toString.call(document)``
* - Chrome === "[object HTMLDocument]"
* - Firefox === "[object HTMLDocument]"
* - Safari === "[object HTMLDocument]"
* - IE <=10 === "[object Document]"
* - IE 11 === "[object HTMLDocument]"
* - IE Edge <=13 === "[object HTMLDocument]"
*/
if (typeof window.document === 'object' && obj === window.document) {
return 'Document';
}
if (typeof window.navigator === 'object') {
/* ! Spec Conformance
* (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
* WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
* Test: `Object.prototype.toString.call(navigator.mimeTypes)``
* - IE <=10 === "[object MSMimeTypesCollection]"
*/
if (typeof window.navigator.mimeTypes === 'object' &&
obj === window.navigator.mimeTypes) {
return 'MimeTypeArray';
}
/* ! Spec Conformance
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
* WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
* Test: `Object.prototype.toString.call(navigator.plugins)``
* - IE <=10 === "[object MSPluginsCollection]"
*/
if (typeof window.navigator.plugins === 'object' &&
obj === window.navigator.plugins) {
return 'PluginArray';
}
}
if ((typeof window.HTMLElement === 'function' ||
typeof window.HTMLElement === 'object') &&
obj instanceof window.HTMLElement) {
/* ! Spec Conformance
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
* WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
* - IE <=10 === "[object HTMLBlockElement]"
*/
if (obj.tagName === 'BLOCKQUOTE') {
return 'HTMLQuoteElement';
}
/* ! Spec Conformance
* (https://html.spec.whatwg.org/#htmltabledatacellelement)
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
* which suggests that browsers should use HTMLTableCellElement for
* both TD and TH elements. WhatWG separates these.
* Test: Object.prototype.toString.call(document.createElement('td'))
* - Chrome === "[object HTMLTableCellElement]"
* - Firefox === "[object HTMLTableCellElement]"
* - Safari === "[object HTMLTableCellElement]"
*/
if (obj.tagName === 'TD') {
return 'HTMLTableDataCellElement';
}
/* ! Spec Conformance
* (https://html.spec.whatwg.org/#htmltableheadercellelement)
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
* which suggests that browsers should use HTMLTableCellElement for
* both TD and TH elements. WhatWG separates these.
* Test: Object.prototype.toString.call(document.createElement('th'))
* - Chrome === "[object HTMLTableCellElement]"
* - Firefox === "[object HTMLTableCellElement]"
* - Safari === "[object HTMLTableCellElement]"
*/
if (obj.tagName === 'TH') {
return 'HTMLTableHeaderCellElement';
}
}
}
/* ! Speed optimisation
* Pre:
* Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
* Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
* Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
* Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
* Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
* Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
* Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
* Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
* Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
* Post:
* Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
* Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
* Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
* Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
* Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
* Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
* Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
*/
var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
if (typeof stringTag === 'string') {
return stringTag;
}
var objPrototype = Object.getPrototypeOf(obj);
/* ! Speed optimisation
* Pre:
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
* regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
* Post:
* regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
* regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
*/
if (objPrototype === RegExp.prototype) {
return 'RegExp';
}
/* ! Speed optimisation
* Pre:
* date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
* Post:
* date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
*/
if (objPrototype === Date.prototype) {
return 'Date';
}
/* ! Spec Conformance
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
* ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
* Test: `Object.prototype.toString.call(Promise.resolve())``
* - Chrome <=47 === "[object Object]"
* - Edge <=20 === "[object Object]"
* - Firefox 29-Latest === "[object Promise]"
* - Safari 7.1-Latest === "[object Promise]"
*/
if (promiseExists && objPrototype === Promise.prototype) {
return 'Promise';
}
/* ! Speed optimisation
* Pre:
* set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
* Post:
* set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
*/
if (setExists && objPrototype === Set.prototype) {
return 'Set';
}
/* ! Speed optimisation
* Pre:
* map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
* Post:
* map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
*/
if (mapExists && objPrototype === Map.prototype) {
return 'Map';
}
/* ! Speed optimisation
* Pre:
* weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
* Post:
* weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
*/
if (weakSetExists && objPrototype === WeakSet.prototype) {
return 'WeakSet';
}
/* ! Speed optimisation
* Pre:
* weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
* Post:
* weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
*/
if (weakMapExists && objPrototype === WeakMap.prototype) {
return 'WeakMap';
}
/* ! Spec Conformance
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
* ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
* Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
* - Edge <=13 === "[object Object]"
*/
if (dataViewExists && objPrototype === DataView.prototype) {
return 'DataView';
}
/* ! Spec Conformance
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
* ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
* Test: `Object.prototype.toString.call(new Map().entries())``
* - Edge <=13 === "[object Object]"
*/
if (mapExists && objPrototype === mapIteratorPrototype) {
return 'Map Iterator';
}
/* ! Spec Conformance
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
* ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
* Test: `Object.prototype.toString.call(new Set().entries())``
* - Edge <=13 === "[object Object]"
*/
if (setExists && objPrototype === setIteratorPrototype) {
return 'Set Iterator';
}
/* ! Spec Conformance
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
* ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
* Test: `Object.prototype.toString.call([][Symbol.iterator]())``
* - Edge <=13 === "[object Object]"
*/
if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
return 'Array Iterator';
}
/* ! Spec Conformance
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
* ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
* Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
* - Edge <=13 === "[object Object]"
*/
if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
return 'String Iterator';
}
/* ! Speed optimisation
* Pre:
* object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
* Post:
* object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
*/
if (objPrototype === null) {
return 'Object';
}
return Object
.prototype
.toString
.call(obj)
.slice(toStringLeftSliceLength, toStringRightSliceLength);
}
return typeDetect;
})));
});
var typeOf = function typeOf(value) {
return typeDetect(value).toLowerCase();
};
function valueToString(value) {
if (value && value.toString) {
/* eslint-disable-next-line local-rules/no-prototype-methods */
return value.toString();
}
return String(value);
}
var valueToString_1 = valueToString;
var lib = {
every: every,
functionName: functionName,
prototypes: prototypes,
typeOf: typeOf,
valueToString: valueToString_1
};
var arrayProto = lib.prototypes.array;
var hasOwnProperty = lib.prototypes.object.hasOwnProperty;
var join = arrayProto.join;
var push = arrayProto.push;
var slice = arrayProto.slice;
// Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
var hasDontEnumBug = (function () {
var obj = {
constructor: function () {
return "0";
},
toString: function () {
return "1";
},
valueOf: function () {
return "2";
},
toLocaleString: function () {
return "3";
},
prototype: function () {
return "4";
},
isPrototypeOf: function () {
return "5";
},
propertyIsEnumerable: function () {
return "6";
},
hasOwnProperty: function () {
return "7";
},
length: function () {
return "8";
},
unique: function () {
return "9";
}
};
var result = [];
for (var prop in obj) {
if (hasOwnProperty(obj, prop)) {
push(result, obj[prop]());
}
}
return join(result, "") !== "0123456789";
})();
/* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
* override properties in previous sources.
*
* target - The Object to extend
* sources - Objects to copy properties from.
*
* Returns the extended target
*/
var extend = function extend(target /*, sources */) {
var sources = slice(arguments, 1);
var source, i, prop;
for (i = 0; i < sources.length; i++) {
source = sources[i];
for (prop in source) {
if (hasOwnProperty(source, prop)) {
target[prop] = source[prop];
}
}
// Make sure we copy (own) toString method even when in JScript with DontEnum bug
// See https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
if (hasDontEnumBug && hasOwnProperty(source, "toString") && source.toString !== target.toString) {
target.toString = source.toString;
}
}
return target;
};
/* istanbul ignore next : not testing that setTimeout works */
function nextTick(callback) {
setTimeout(callback, 0);
}
var getNextTick = function getNextTick(process, setImmediate) {
if (typeof process === "object" && typeof process.nextTick === "function") {
return process.nextTick;
}
if (typeof setImmediate === "function") {
return setImmediate;
}
return nextTick;
};
/* istanbul ignore next */
var root = typeof window !== "undefined" ? window : commonjsGlobal;
var nextTick$1 = getNextTick(root.process, root.setImmediate);
var arrayProto$1 = lib.prototypes.array;
var functionName$1 = lib.functionName;
var valueToString$1 = lib.valueToString;
var concat = arrayProto$1.concat;
var forEach = arrayProto$1.forEach;
var join$1 = arrayProto$1.join;
var reverse = arrayProto$1.reverse;
var slice$1 = arrayProto$1.slice;
var useLeftMostCallback = -1;
var useRightMostCallback = -2;
function getCallback(behavior, args) {
var callArgAt = behavior.callArgAt;
if (callArgAt >= 0) {
return args[callArgAt];
}
var argumentList;
if (callArgAt === useLeftMostCallback) {
argumentList = args;
}
if (callArgAt === useRightMostCallback) {
argumentList = reverse(slice$1(args));
}
var callArgProp = behavior.callArgProp;
for (var i = 0, l = argumentList.length; i < l; ++i) {
if (!callArgProp && typeof argumentList[i] === "function") {
return argumentList[i];
}
if (callArgProp && argumentList[i] &&
typeof argumentList[i][callArgProp] === "function") {
return argumentList[i][callArgProp];
}
}
return null;
}
function getCallbackError(behavior, func, args) {
if (behavior.callArgAt < 0) {
var msg;
if (behavior.callArgProp) {
msg = functionName$1(behavior.stub) +
" expected to yield to '" + valueToString$1(behavior.callArgProp) +
"', but no object with such a property was passed.";
} else {
msg = functionName$1(behavior.stub) +
" expected to yield, but no callback was passed.";
}
if (args.length > 0) {
msg += " Received [" + join$1(args, ", ") + "]";
}
return msg;
}
return "argument at index " + behavior.callArgAt + " is not a function: " + func;
}
function ensureArgs(name, behavior, args) {
// map function name to internal property
// callsArg => callArgAt
var property = name.replace(/sArg/, "ArgAt");
var index = behavior[property];
if (index >= args.length) {
throw new TypeError(
name + " failed: " + (index + 1)
+ " arguments required but only " + args.length
+ " present"
);
}
}
function callCallback(behavior, args) {
if (typeof behavior.callArgAt === "number") {
ensureArgs("callsArg", behavior, args);
var func = getCallback(behavior, args);
if (typeof func !== "function") {
throw new TypeError(getCallbackError(behavior, func, args));
}
if (behavior.callbackAsync) {
nextTick$1(function () {
func.apply(behavior.callbackContext, behavior.callbackArguments);
});
} else {
return func.apply(behavior.callbackContext, behavior.callbackArguments);
}
}
return undefined;
}
var proto = {
create: function create(stub) {
var behavior = extend({}, proto);
delete behavior.create;
delete behavior.addBehavior;
delete behavior.createBehavior;
behavior.stub = stub;
if (stub.defaultBehavior && stub.defaultBehavior.promiseLibrary) {
behavior.promiseLibrary = stub.defaultBehavior.promiseLibrary;
}
return behavior;
},
isPresent: function isPresent() {
return (typeof this.callArgAt === "number" ||
this.exception ||
this.exceptionCreator ||
typeof this.returnArgAt === "number" ||
this.returnThis ||
typeof this.resolveArgAt === "number" ||
this.resolveThis ||
typeof this.throwArgAt === "number" ||
this.fakeFn ||
this.returnValueDefined);
},
invoke: function invoke(context, args) {
/*
* callCallback (conditionally) calls ensureArgs
*
* Note: callCallback intentionally happens before
* everything else and cannot be moved lower
*/
var returnValue = callCallback(this, args);
if (this.exception) {
throw this.exception;
} else if (this.exceptionCreator) {
this.exception = this.exceptionCreator();
this.exceptionCreator = undefined;
throw this.exception;
} else if (typeof this.returnArgAt === "number") {
ensureArgs("returnsArg", this, args);
return args[this.returnArgAt];
} else if (this.returnThis) {
return context;
} else if (typeof this.throwArgAt === "number") {
ensureArgs("throwsArg", this, args);
throw args[this.throwArgAt];
} else if (this.fakeFn) {
return this.fakeFn.apply(context, args);
} else if (typeof this.resolveArgAt === "number") {
ensureArgs("resolvesArg", this, args);
return (this.promiseLibrary || Promise).resolve(args[this.resolveArgAt]);
} else if (this.resolveThis) {
return (this.promiseLibrary || Promise).resolve(context);
} else if (this.resolve) {
return (this.promiseLibrary || Promise).resolve(this.returnValue);
} else if (this.reject) {
return (this.promiseLibrary || Promise).reject(this.returnValue);
} else if (this.callsThrough) {
return this.stub.wrappedMethod.apply(context, args);
} else if (typeof this.returnValue !== "undefined") {
return this.returnValue;
} else if (typeof this.callArgAt === "number") {
return returnValue;
}
return this.returnValue;
},
onCall: function onCall(index) {
return this.stub.onCall(index);
},
onFirstCall: function onFirstCall() {
return this.stub.onFirstCall();
},
onSecondCall: function onSecondCall() {
return this.stub.onSecondCall();
},
onThirdCall: function onThirdCall() {
return this.stub.onThirdCall();
},
withArgs: function withArgs(/* arguments */) {
throw new Error(
"Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " +
"is not supported. Use \"stub.withArgs(...).onCall(...)\" " +
"to define sequential behavior for calls with certain arguments."
);
}
};
function createAsyncVersion(syncFnName) {
return function () {
var result = this[syncFnName].apply(this, arguments);
this.callbackAsync = true;
return result;
};
}
// create asynchronous versions of callsArg* and yields* methods
forEach(Object.keys(proto), function (method) {
// need to avoid creating anotherasync versions of the newly added async methods
if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
proto[method + "Async"] = createAsyncVersion(method);
}
});
function createBehavior(behaviorMethod) {
return function () {
this.defaultBehavior = this.defaultBehavior || proto.create(this);
this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
return this;
};
}
function addBehavior(stub, name, fn) {
proto[name] = function () {
fn.apply(this, concat([this], slice$1(arguments)));
return this.stub || this;
};
stub[name] = createBehavior(name);
}
proto.addBehavior = addBehavior;
proto.createBehavior = createBehavior;
var behavior = proto;
var forEach$1 = lib.prototypes.array.forEach;
function walkInternal(obj, iterator, context, originalObj, seen) {
var proto, prop;
if (typeof Object.getOwnPropertyNames !== "function") {
// We explicitly want to enumerate through all of the prototype's properties
// in this case, therefore we deliberately leave out an own property check.
/* eslint-disable-next-line guard-for-in */
for (prop in obj) {
iterator.call(context, obj[prop], prop, obj);
}
return;
}
forEach$1(Object.getOwnPropertyNames(obj), function (k) {
if (seen[k] !== true) {
seen[k] = true;
var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ?
originalObj : obj;
iterator.call(context, k, target);
}
});
proto = Object.getPrototypeOf(obj);
if (proto) {
walkInternal(proto, iterator, context, originalObj, seen);
}
}
/* Walks the prototype chain of an object and iterates over every own property
* name encountered. The iterator is called in the same fashion that Array.prototype.forEach
* works, where it is passed the value, key, and own object as the 1st, 2nd, and 3rd positional
* argument, respectively. In cases where Object.getOwnPropertyNames is not available, walk will
* default to using a simple for..in loop.
*
* obj - The object to walk the prototype chain for.
* iterator - The function to be called on each pass of the walk.
* context - (Optional) When given, the iterator will be called with this object as the receiver.
*/
var walk = function walk(obj, iterator, context) {
return walkInternal(obj, iterator, context, obj, {});
};
var getPropertyDescriptor = function getPropertyDescriptor(object, property) {
var proto = object;
var descriptor;
while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
proto = Object.getPrototypeOf(proto);
}
return descriptor;
};
var hasOwnProperty$1 = lib.prototypes.object.hasOwnProperty;
var push$1 = lib.prototypes.array.push;
function collectMethod(methods, object, prop, propOwner) {
if (
typeof getPropertyDescriptor(propOwner, prop).value === "function" &&
hasOwnProperty$1(object, prop)
) {
push$1(methods, object[prop]);
}
}
// This function returns an array of all the own methods on the passed object
function collectOwnMethods(object) {
var methods = [];
walk(object, collectMethod.bind(null, methods, object));
return methods;
}
var collectOwnMethods_1 = collectOwnMethods;
/**
* Verify if an object is a ECMAScript Module
*
* As the exports from a module is immutable we cannot alter the exports
* using spies or stubs. Let the consumer know this to avoid bug reports
* on weird error messages.
*/
var isEsModule = function (object) {
return (
object &&
typeof Symbol !== "undefined" &&
object[Symbol.toStringTag] === "Module" &&
Object.isSealed(object)
);
};
function isPropertyConfigurable(obj, propName) {
var propertyDescriptor = getPropertyDescriptor(obj, propName);
return propertyDescriptor ? propertyDescriptor.configurable : true;
}
var isPropertyConfigurable_1 = isPropertyConfigurable;
function isNonExistentOwnProperty(object, property) {
return object && typeof property !== "undefined" && !(property in object);
}
var isNonExistentOwnProperty_1 = isNonExistentOwnProperty;
var o = Object.prototype;
function getClass(value) {
// Returns the internal [[Class]] by calling Object.prototype.toString
// with the provided value as this. Return value is a string, naming the
// internal class, e.g. "Array"
return o.toString.call(value).split(/[ \]]/)[1];
}
var getClass_1 = getClass;
function isNaN$1(value) {
// Unlike global isNaN, this avoids type coercion
// typeof check avoids IE host object issues, hat tip to
// lodash
var val = value; // JsLint thinks value !== value is "weird"
return typeof value === "number" && value !== val;
}
var isNan = isNaN$1;
/**
* @name samsam.isNegZero
* @param Object value
*
* Returns ``true`` if ``value`` is ``-0``.
*/
function isNegZero(value) {
return value === 0 && 1 / value === -Infinity;
}
var isNegZero_1 = isNegZero;
/**
* @name samsam.equal
* @param Object obj1
* @param Object obj2
*
* Returns ``true`` if two objects are strictly equal. Compared to
* ``===`` there are two exceptions:
*
* - NaN is considered equal to NaN
* - -0 and +0 are not considered equal
*/
function identical(obj1, obj2) {
if (obj1 === obj2 || (isNan(obj1) && isNan(obj2))) {
return obj1 !== 0 || isNegZero_1(obj1) === isNegZero_1(obj2);
}
return false;
}
var identical_1 = identical;
/**
* @name samsam.isArguments
* @param Object object
*
* Returns ``true`` if ``object`` is an ``arguments`` object,
* ``false`` otherwise.
*/
function isArguments(object) {
if (getClass_1(object) === "Arguments") {
return true;
}
if (
typeof object !== "object" ||
typeof object.length !== "number" ||
getClass_1(object) === "Array"
) {
return false;
}
if (typeof object.callee === "function") {
return true;
}
try {
object[object.length] = 6;
delete object[object.length];
} catch (e) {
return true;
}
return false;
}
var isArguments_1 = isArguments;
function isDate(value) {
return value instanceof Date;
}
var isDate_1 = isDate;
var div = typeof document !== "undefined" && document.createElement("div");
/**
* @name samsam.isElement
* @param Object object
*
* Returns ``true`` if ``object`` is a DOM element node. Unlike
* Underscore.js/lodash, this function will return ``false`` if ``object``
* is an *element-like* object, i.e. a regular object with a ``nodeType``
* property that holds the value ``1``.
*/
function isElement(object) {
if (!object || object.nodeType !== 1 || !div) {
return false;
}
try {
object.appendChild(div);
object.removeChild(div);
} catch (e) {
return false;
}
return true;
}
var isElement_1 = isElement;
// Returns true when the value is a regular Object and not a specialized Object
//
// This helps speeding up deepEqual cyclic checks
// The premise is that only Objects are stored in the visited array.
// So if this function returns false, we don't have to do the
// expensive operation of searching for the value in the the array of already
// visited objects
function isObject(value) {
return (
typeof value === "object" &&
value !== null &&
// none of these are collection objects, so we can return false
!(value instanceof Boolean) &&
!(value instanceof Date) &&
!(value instanceof Error) &&
!(value instanceof Number) &&
!(value instanceof RegExp) &&
!(value instanceof String)
);
}
var isObject_1 = isObject;
function isSet(val) {
return (typeof Set !== "undefined" && val instanceof Set) || false;
}
var isSet_1 = isSet;
// Production steps of ECMA-262, Edition 6, 22.1.2.1
// Reference: http://www.ecma-international.org/ecma-262/6.0/#sec-array.from
var polyfill = (function() {
var isCallable = function(fn) {
return typeof fn === 'function';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === 0 || !isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function (value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};
var iteratorProp = function(value) {
if(value != null) {
if(['string','number','boolean','symbol'].indexOf(typeof value) > -1){
return Symbol.iterator;
} else if (
(typeof Symbol !== 'undefined') &&
('iterator' in Symbol) &&
(Symbol.iterator in value)
) {
return Symbol.iterator;
}
// Support "@@iterator" placeholder, Gecko 27 to Gecko 35
else if ('@@iterator' in value) {
return '@@iterator';
}
}
};
var getMethod = function(O, P) {
// Assert: IsPropertyKey(P) is true.
if (O != null && P != null) {
// Let func be GetV(O, P).
var func = O[P];
// ReturnIfAbrupt(func).
// If func is either undefined or null, return undefined.
if(func == null) {
return void 0;
}
// If IsCallable(func) is false, throw a TypeError exception.
if (!isCallable(func)) {
throw new TypeError(func + ' is not a function');
}
return func;
}
};
var iteratorStep = function(iterator) {
// Let result be IteratorNext(iterator).
// ReturnIfAbrupt(result).
var result = iterator.next();
// Let done be IteratorComplete(result).
// ReturnIfAbrupt(done).
var done = Boolean(result.done);
// If done is true, return false.
if(done) {
return false;
}
// Return result.
return result;
};
// The length property of the from method is 1.
return function from(items /*, mapFn, thisArg */ ) {
// 1. Let C be the this value.
var C = this;
// 2. If mapfn is undefined, let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void 0;
var T;
if (typeof mapFn !== 'undefined') {
// 3. else
// a. If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError(
'Array.from: when provided, the second argument must be a function'
);
}
// b. If thisArg was supplied, let T be thisArg; else let T
// be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
// c. Let mapping be true (implied by mapFn)
}
var A, k;
// 4. Let usingIterator be GetMethod(items, @@iterator).
// 5. ReturnIfAbrupt(usingIterator).
var usingIterator = getMethod(items, iteratorProp(items));
// 6. If usingIterator is not undefined, then
if (usingIterator !== void 0) {
// a. If IsConstructor(C) is true, then
// i. Let A be the result of calling the [[Construct]]
// internal method of C with an empty argument list.
// b. Else,
// i. Let A be the result of the abstract operation ArrayCreate
// with argument 0.
// c. ReturnIfAbrupt(A).
A = isCallable(C) ? Object(new C()) : [];
// d. Let iterator be GetIterator(items, usingIterator).
var iterator = usingIterator.call(items);
// e. ReturnIfAbrupt(iterator).
if (iterator == null) {
throw new TypeError(
'Array.from requires an array-like or iterable object'
);
}
// f. Let k be 0.
k = 0;
// g. Repeat
var next, nextValue;
while (true) {
// i. Let Pk be ToString(k).
// ii. Let next be IteratorStep(iterator).
// iii. ReturnIfAbrupt(next).
next = iteratorStep(iterator);
// iv. If next is false, then
if (!next) {
// 1. Let setStatus be Set(A, "length", k, true).
// 2. ReturnIfAbrupt(setStatus).
A.length = k;
// 3. Return A.
return A;
}
// v. Let nextValue be IteratorValue(next).
// vi. ReturnIfAbrupt(nextValue)
nextValue = next.value;
// vii. If mapping is true, then
// 1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
// 2. If mappedValue is an abrupt completion, return
// IteratorClose(iterator, mappedValue).
// 3. Let mappedValue be mappedValue.[[value]].
// viii. Else, let mappedValue be nextValue.
// ix. Let defineStatus be the result of
// CreateDataPropertyOrThrow(A, Pk, mappedValue).
// x. [TODO] If defineStatus is an abrupt completion, return
// IteratorClose(iterator, defineStatus).
if (mapFn) {
A[k] = mapFn.call(T, nextValue, k);
}
else {
A[k] = nextValue;
}
// xi. Increase k by 1.
k++;
}
// 7. Assert: items is not an Iterable so assume it is
// an array-like object.
} else {
// 8. Let arrayLike be ToObject(items).
var arrayLike = Object(items);
// 9. ReturnIfAbrupt(items).
if (items == null) {
throw new TypeError(
'Array.from requires an array-like object - not null or undefined'
);
}
// 10. Let len be ToLength(Get(arrayLike, "length")).
// 11. ReturnIfAbrupt(len).
var len = toLength(arrayLike.length);
// 12. If IsConstructor(C) is true, then
// a. Let A be Construct(C, «len»).
// 13. Else
// a. Let A be ArrayCreate(len).
// 14. ReturnIfAbrupt(A).
A = isCallable(C) ? Object(new C(len)) : new Array(len);
// 15. Let k be 0.
k = 0;
// 16. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = arrayLike[k];
if (mapFn) {
A[k] = mapFn.call(T, kValue, k);
}
else {
A[k] = kValue;
}
k++;
}
// 17. Let setStatus be Set(A, "length", len, true).
// 18. ReturnIfAbrupt(setStatus).
A.length = len;
// 19. Return A.
}
return A;
};
})();
var arrayFrom = (typeof Array.from === 'function' ?
Array.from :
polyfill
);
function isSubset(s1, s2, compare) {
// FIXME: IE11 doesn't support Array.from
// Potential solutions:
// - contribute a patch to https://github.com/Volox/eslint-plugin-ie11#readme
// - https://github.com/mathiasbynens/Array.from (doesn't work with matchers)
var values1 = arrayFrom(s1);
var values2 = arrayFrom(s2);
for (var i = 0; i < values1.length; i++) {
var includes = false;
for (var j = 0; j < values2.length; j++) {
if (compare(values2[j], values1[i])) {
includes = true;
break;
}
}
if (!includes) {
return false;
}
}
return true;
}
var isSubset_1 = isSubset;
function getClassName(value) {
return value.constructor ? value.constructor.name : null;
}
var getClassName_1 = getClassName;
var every$1 = Array.prototype.every;
var getTime = Date.prototype.getTime;
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
var indexOf = Array.prototype.indexOf;
var keys = Object.keys;
/**
* @name samsam.deepEqual
* @param Object first
* @param Object second
*
* Deep equal comparison. Two values are "deep equal" if:
*
* - They are equal, according to samsam.identical
* - They are both date objects representing the same time
* - They are both arrays containing elements that are all deepEqual
* - They are objects with the same set of properties, and each property
* in ``first`` is deepEqual to the corresponding property in ``second``
*
* Supports cyclic objects.
*/
function deepEqualCyclic(first, second) {
// used for cyclic comparison
// contain already visited objects
var objects1 = [];
var objects2 = [];
// contain pathes (position in the object structure)
// of the already visited objects
// indexes same as in objects arrays
var paths1 = [];
var paths2 = [];
// contains combinations of already compared objects
// in the manner: { "$1['ref']$2['ref']": true }
var compared = {};
// does the recursion for the deep equal check
return (function deepEqual(obj1, obj2, path1, path2) {
var type1 = typeof obj1;
var type2 = typeof obj2;
// == null also matches undefined
if (
obj1 === obj2 ||
isNan(obj1) ||
isNan(obj2) ||
obj1 == null ||
obj2 == null ||
type1 !== "object" ||
type2 !== "object"
) {
return identical_1(obj1, obj2);
}
// Elements are only equal if identical(expected, actual)
if (isElement_1(obj1) || isElement_1(obj2)) {
return false;
}
var isDate1 = isDate_1(obj1);
var isDate2 = isDate_1(obj2);
if (isDate1 || isDate2) {
if (
!isDate1 ||
!isDate2 ||
getTime.call(obj1) !== getTime.call(obj2)
) {
return false;
}
}
if (obj1 instanceof RegExp && obj2 instanceof RegExp) {
if (obj1.toString() !== obj2.toString()) {
return false;
}
}
if (obj1 instanceof Error && obj2 instanceof Error) {
if (obj1.stack !== obj2.stack) {
return false;
}
}
var class1 = getClass_1(obj1);
var class2 = getClass_1(obj2);
var keys1 = keys(obj1);
var keys2 = keys(obj2);
var name1 = getClassName_1(obj1);
var name2 = getClassName_1(obj2);
if (isArguments_1(obj1) || isArguments_1(obj2)) {
if (obj1.length !== obj2.length) {
return false;
}
} else {
if (
type1 !== type2 ||
class1 !== class2 ||
keys1.length !== keys2.length ||
(name1 && name2 && name1 !== name2)
) {
return false;
}
}
if (isSet_1(obj1) || isSet_1(obj2)) {
if (!isSet_1(obj1) || !isSet_1(obj2) || obj1.size !== obj2.size) {
return false;
}
return isSubset_1(obj1, obj2, deepEqual);
}
return every$1.call(keys1, function(key) {
if (!hasOwnProperty$2.call(obj2, key)) {
return false;
}
var value1 = obj1[key];
var value2 = obj2[key];
var isObject1 = isObject_1(value1);
var isObject2 = isObject_1(value2);
// determines, if the objects were already visited
// (it's faster to check for isObject first, than to
// get -1 from getIndex for non objects)
var index1 = isObject1 ? indexOf.call(objects1, value1) : -1;
var index2 = isObject2 ? indexOf.call(objects2, value2) : -1;
// determines the new paths of the objects
// - for non cyclic objects the current path will be extended
// by current property name
// - for cyclic objects the stored path is taken
var newPath1 =
index1 !== -1
? paths1[index1]
: path1 + "[" + JSON.stringify(key) + "]";
var newPath2 =
index2 !== -1
? paths2[index2]
: path2 + "[" + JSON.stringify(key) + "]";
var combinedPath = newPath1 + newPath2;
// stop recursion if current objects are already compared
if (compared[combinedPath]) {
return true;
}
// remember the current objects and their paths
if (index1 === -1 && isObject1) {
objects1.push(value1);
paths1.push(newPath1);
}
if (index2 === -1 && isObject2) {
objects2.push(value2);
paths2.push(newPath2);
}
// remember that the current objects are already compared
if (isObject1 && isObject2) {
compared[combinedPath] = true;
}
// End of cyclic logic
// neither value1 nor value2 is a cycle
// continue with next level
return deepEqual(value1, value2, newPath1, newPath2);
});
})(first, second, "$1", "$2");
}
var deepEqual = deepEqualCyclic;
function arrayContains(array, subset, compare) {
if (subset.length === 0) {
return true;
}
var i, l, j, k;
for (i = 0, l = array.length; i < l; ++i) {
if (compare(array[i], subset[0])) {
for (j = 0, k = subset.length; j < k; ++j) {
if (i + j >= l) {
return false;
}
if (!compare(array[i + j], subset[j])) {
return false;
}
}
return true;
}
}
return false;
}
/**
* @name samsam.match
* @param Object object
* @param Object matcher
*
* Compare arbitrary value ``object`` with matcher.
*/
function match(object, matcher) {
if (matcher && typeof matcher.test === "function") {
return matcher.test(object);
}
if (typeof matcher === "function") {
return matcher(object) === true;
}
if (typeof matcher === "string") {
matcher = matcher.toLowerCase();
var notNull = typeof object === "string" || !!object;
return (
notNull &&
String(object)
.toLowerCase()
.indexOf(matcher) >= 0
);
}
if (typeof matcher === "number") {
return matcher === object;
}
if (typeof matcher === "boolean") {