forked from Mirrors/doipjs
16509 lines
1,006 KiB
JavaScript
16509 lines
1,006 KiB
JavaScript
|
/* Sinon.JS 9.2.0, 2020-10-06, @license BSD-3 */let sinon;(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
// eslint-disable-next-line no-undef
|
|||
|
sinon = require("./sinon");
|
|||
|
|
|||
|
},{"./sinon":2}],2:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var behavior = require("./sinon/behavior");
|
|||
|
var createSandbox = require("./sinon/create-sandbox");
|
|||
|
var extend = require("./sinon/util/core/extend");
|
|||
|
var fakeTimers = require("./sinon/util/fake-timers");
|
|||
|
var format = require("./sinon/util/core/format");
|
|||
|
var nise = require("nise");
|
|||
|
var Sandbox = require("./sinon/sandbox");
|
|||
|
var stub = require("./sinon/stub");
|
|||
|
|
|||
|
var apiMethods = {
|
|||
|
createSandbox: createSandbox,
|
|||
|
assert: require("./sinon/assert"),
|
|||
|
match: require("@sinonjs/samsam").createMatcher,
|
|||
|
restoreObject: require("./sinon/restore-object"),
|
|||
|
|
|||
|
expectation: require("./sinon/mock-expectation"),
|
|||
|
defaultConfig: require("./sinon/util/core/default-config"),
|
|||
|
|
|||
|
setFormatter: format.setFormatter,
|
|||
|
|
|||
|
// fake timers
|
|||
|
timers: fakeTimers.timers,
|
|||
|
|
|||
|
// fake XHR
|
|||
|
xhr: nise.fakeXhr.xhr,
|
|||
|
FakeXMLHttpRequest: nise.fakeXhr.FakeXMLHttpRequest,
|
|||
|
|
|||
|
// fake server
|
|||
|
fakeServer: nise.fakeServer,
|
|||
|
fakeServerWithClock: nise.fakeServerWithClock,
|
|||
|
createFakeServer: nise.fakeServer.create.bind(nise.fakeServer),
|
|||
|
createFakeServerWithClock: nise.fakeServerWithClock.create.bind(nise.fakeServerWithClock),
|
|||
|
|
|||
|
addBehavior: function(name, fn) {
|
|||
|
behavior.addBehavior(stub, name, fn);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var sandbox = new Sandbox();
|
|||
|
|
|||
|
var api = extend(sandbox, apiMethods);
|
|||
|
|
|||
|
module.exports = api;
|
|||
|
|
|||
|
},{"./sinon/assert":3,"./sinon/behavior":4,"./sinon/create-sandbox":7,"./sinon/mock-expectation":10,"./sinon/restore-object":16,"./sinon/sandbox":17,"./sinon/stub":20,"./sinon/util/core/default-config":22,"./sinon/util/core/extend":24,"./sinon/util/core/format":25,"./sinon/util/fake-timers":38,"@sinonjs/samsam":84,"nise":103}],3:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var calledInOrder = require("@sinonjs/commons").calledInOrder;
|
|||
|
var createMatcher = require("@sinonjs/samsam").createMatcher;
|
|||
|
var orderByFirstCall = require("@sinonjs/commons").orderByFirstCall;
|
|||
|
var timesInWords = require("./util/core/times-in-words");
|
|||
|
var format = require("./util/core/format");
|
|||
|
var stringSlice = require("@sinonjs/commons").prototypes.string.slice;
|
|||
|
var globalObject = require("@sinonjs/commons").global;
|
|||
|
|
|||
|
var arraySlice = arrayProto.slice;
|
|||
|
var concat = arrayProto.concat;
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var join = arrayProto.join;
|
|||
|
var splice = arrayProto.splice;
|
|||
|
|
|||
|
var assert;
|
|||
|
|
|||
|
function verifyIsStub() {
|
|||
|
var args = arraySlice(arguments);
|
|||
|
|
|||
|
forEach(args, function(method) {
|
|||
|
if (!method) {
|
|||
|
assert.fail("fake is not a spy");
|
|||
|
}
|
|||
|
|
|||
|
if (method.proxy && method.proxy.isSinonProxy) {
|
|||
|
verifyIsStub(method.proxy);
|
|||
|
} else {
|
|||
|
if (typeof method !== "function") {
|
|||
|
assert.fail(method + " is not a function");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof method.getCall !== "function") {
|
|||
|
assert.fail(method + " is not stubbed");
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function verifyIsValidAssertion(assertionMethod, assertionArgs) {
|
|||
|
switch (assertionMethod) {
|
|||
|
case "notCalled":
|
|||
|
case "called":
|
|||
|
case "calledOnce":
|
|||
|
case "calledTwice":
|
|||
|
case "calledThrice":
|
|||
|
if (assertionArgs.length !== 0) {
|
|||
|
assert.fail(
|
|||
|
assertionMethod +
|
|||
|
" takes 1 argument but was called with " +
|
|||
|
(assertionArgs.length + 1) +
|
|||
|
" arguments"
|
|||
|
);
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function failAssertion(object, msg) {
|
|||
|
var obj = object || globalObject;
|
|||
|
var failMethod = obj.fail || assert.fail;
|
|||
|
failMethod.call(obj, msg);
|
|||
|
}
|
|||
|
|
|||
|
function mirrorPropAsAssertion(name, method, message) {
|
|||
|
var msg = message;
|
|||
|
var meth = method;
|
|||
|
if (arguments.length === 2) {
|
|||
|
msg = method;
|
|||
|
meth = name;
|
|||
|
}
|
|||
|
|
|||
|
assert[name] = function(fake) {
|
|||
|
verifyIsStub(fake);
|
|||
|
|
|||
|
var args = arraySlice(arguments, 1);
|
|||
|
var failed = false;
|
|||
|
|
|||
|
verifyIsValidAssertion(name, args);
|
|||
|
|
|||
|
if (typeof meth === "function") {
|
|||
|
failed = !meth(fake);
|
|||
|
} else {
|
|||
|
failed = typeof fake[meth] === "function" ? !fake[meth].apply(fake, args) : !fake[meth];
|
|||
|
}
|
|||
|
|
|||
|
if (failed) {
|
|||
|
failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, concat([msg], args)));
|
|||
|
} else {
|
|||
|
assert.pass(name);
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function exposedName(prefix, prop) {
|
|||
|
return !prefix || /^fail/.test(prop) ? prop : prefix + stringSlice(prop, 0, 1).toUpperCase() + stringSlice(prop, 1);
|
|||
|
}
|
|||
|
|
|||
|
assert = {
|
|||
|
failException: "AssertError",
|
|||
|
|
|||
|
fail: function fail(message) {
|
|||
|
var error = new Error(message);
|
|||
|
error.name = this.failException || assert.failException;
|
|||
|
|
|||
|
throw error;
|
|||
|
},
|
|||
|
|
|||
|
pass: function pass() {
|
|||
|
return;
|
|||
|
},
|
|||
|
|
|||
|
callOrder: function assertCallOrder() {
|
|||
|
verifyIsStub.apply(null, arguments);
|
|||
|
var expected = "";
|
|||
|
var actual = "";
|
|||
|
|
|||
|
if (!calledInOrder(arguments)) {
|
|||
|
try {
|
|||
|
expected = join(arguments, ", ");
|
|||
|
var calls = arraySlice(arguments);
|
|||
|
var i = calls.length;
|
|||
|
while (i) {
|
|||
|
if (!calls[--i].called) {
|
|||
|
splice(calls, i, 1);
|
|||
|
}
|
|||
|
}
|
|||
|
actual = join(orderByFirstCall(calls), ", ");
|
|||
|
} catch (e) {
|
|||
|
// If this fails, we'll just fall back to the blank string
|
|||
|
}
|
|||
|
|
|||
|
failAssertion(this, "expected " + expected + " to be called in order but were called as " + actual);
|
|||
|
} else {
|
|||
|
assert.pass("callOrder");
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
callCount: function assertCallCount(method, count) {
|
|||
|
verifyIsStub(method);
|
|||
|
|
|||
|
if (method.callCount !== count) {
|
|||
|
var msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C";
|
|||
|
failAssertion(this, method.printf(msg));
|
|||
|
} else {
|
|||
|
assert.pass("callCount");
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
expose: function expose(target, options) {
|
|||
|
if (!target) {
|
|||
|
throw new TypeError("target is null or undefined");
|
|||
|
}
|
|||
|
|
|||
|
var o = options || {};
|
|||
|
var prefix = (typeof o.prefix === "undefined" && "assert") || o.prefix;
|
|||
|
var includeFail = typeof o.includeFail === "undefined" || Boolean(o.includeFail);
|
|||
|
var instance = this;
|
|||
|
|
|||
|
forEach(Object.keys(instance), function(method) {
|
|||
|
if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) {
|
|||
|
target[exposedName(prefix, method)] = instance[method];
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return target;
|
|||
|
},
|
|||
|
|
|||
|
match: function match(actual, expectation) {
|
|||
|
var matcher = createMatcher(expectation);
|
|||
|
if (matcher.test(actual)) {
|
|||
|
assert.pass("match");
|
|||
|
} else {
|
|||
|
var formatted = [
|
|||
|
"expected value to match",
|
|||
|
" expected = " + format(expectation),
|
|||
|
" actual = " + format(actual)
|
|||
|
];
|
|||
|
|
|||
|
failAssertion(this, join(formatted, "\n"));
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called");
|
|||
|
mirrorPropAsAssertion(
|
|||
|
"notCalled",
|
|||
|
function(spy) {
|
|||
|
return !spy.called;
|
|||
|
},
|
|||
|
"expected %n to not have been called but was called %c%C"
|
|||
|
);
|
|||
|
mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C");
|
|||
|
mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C");
|
|||
|
mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C");
|
|||
|
mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t");
|
|||
|
mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t");
|
|||
|
mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
|
|||
|
mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new");
|
|||
|
mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D");
|
|||
|
mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %D");
|
|||
|
mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %D");
|
|||
|
mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %D");
|
|||
|
mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %D");
|
|||
|
mirrorPropAsAssertion("calledOnceWithExactly", "expected %n to be called once and with exact arguments %D");
|
|||
|
mirrorPropAsAssertion("calledOnceWithMatch", "expected %n to be called once and with match %D");
|
|||
|
mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %D");
|
|||
|
mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C");
|
|||
|
mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C");
|
|||
|
mirrorPropAsAssertion("threw", "%n did not throw exception%C");
|
|||
|
mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C");
|
|||
|
|
|||
|
module.exports = assert;
|
|||
|
|
|||
|
},{"./util/core/format":25,"./util/core/times-in-words":33,"@sinonjs/commons":45,"@sinonjs/samsam":84}],4:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var nextTick = require("./util/core/next-tick");
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
var exportAsyncBehaviors = require("./util/core/export-async-behaviors");
|
|||
|
|
|||
|
var concat = arrayProto.concat;
|
|||
|
var join = arrayProto.join;
|
|||
|
var reverse = arrayProto.reverse;
|
|||
|
var slice = arrayProto.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(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(behavior.stub) +
|
|||
|
" expected to yield to '" +
|
|||
|
valueToString(behavior.callArgProp) +
|
|||
|
"', but no object with such a property was passed.";
|
|||
|
} else {
|
|||
|
msg = functionName(behavior.stub) + " expected to yield, but no callback was passed.";
|
|||
|
}
|
|||
|
|
|||
|
if (args.length > 0) {
|
|||
|
msg += " Received [" + join(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(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
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
/*eslint complexity: ["error", 20]*/
|
|||
|
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) {
|
|||
|
var wrappedMethod = this.effectiveWrappedMethod();
|
|||
|
|
|||
|
return wrappedMethod.apply(context, args);
|
|||
|
} else if (this.callsThroughWithNew) {
|
|||
|
// Get the original method (assumed to be a constructor in this case)
|
|||
|
var WrappedClass = this.effectiveWrappedMethod();
|
|||
|
// Turn the arguments object into a normal array
|
|||
|
var argsArray = slice(args);
|
|||
|
// Call the constructor
|
|||
|
var F = WrappedClass.bind.apply(WrappedClass, concat([null], argsArray));
|
|||
|
return new F();
|
|||
|
} else if (typeof this.returnValue !== "undefined") {
|
|||
|
return this.returnValue;
|
|||
|
} else if (typeof this.callArgAt === "number") {
|
|||
|
return returnValue;
|
|||
|
}
|
|||
|
|
|||
|
return this.returnValue;
|
|||
|
},
|
|||
|
|
|||
|
effectiveWrappedMethod: function effectiveWrappedMethod() {
|
|||
|
for (var stubb = this.stub; stubb; stubb = stubb.parent) {
|
|||
|
if (stubb.wrappedMethod) {
|
|||
|
return stubb.wrappedMethod;
|
|||
|
}
|
|||
|
}
|
|||
|
throw new Error("Unable to find wrapped method");
|
|||
|
},
|
|||
|
|
|||
|
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 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(arguments)));
|
|||
|
return this.stub || this;
|
|||
|
};
|
|||
|
|
|||
|
stub[name] = createBehavior(name);
|
|||
|
}
|
|||
|
|
|||
|
proto.addBehavior = addBehavior;
|
|||
|
proto.createBehavior = createBehavior;
|
|||
|
|
|||
|
var asyncBehaviors = exportAsyncBehaviors(proto);
|
|||
|
|
|||
|
module.exports = extend.nonEnum({}, proto, asyncBehaviors);
|
|||
|
|
|||
|
},{"./util/core/export-async-behaviors":23,"./util/core/extend":24,"./util/core/next-tick":32,"@sinonjs/commons":45}],5:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var walk = require("./util/core/walk");
|
|||
|
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
|
|||
|
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
|||
|
var push = require("@sinonjs/commons").prototypes.array.push;
|
|||
|
|
|||
|
function collectMethod(methods, object, prop, propOwner) {
|
|||
|
if (typeof getPropertyDescriptor(propOwner, prop).value === "function" && hasOwnProperty(object, prop)) {
|
|||
|
push(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;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = collectOwnMethods;
|
|||
|
|
|||
|
},{"./util/core/get-property-descriptor":28,"./util/core/walk":36,"@sinonjs/commons":45}],6:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var supportsColor = require("supports-color");
|
|||
|
|
|||
|
function colorize(str, color) {
|
|||
|
if (supportsColor.stdout === false) {
|
|||
|
return str;
|
|||
|
}
|
|||
|
|
|||
|
return "\x1b[" + color + "m" + str + "\x1b[0m";
|
|||
|
}
|
|||
|
|
|||
|
exports.red = function(str) {
|
|||
|
return colorize(str, 31);
|
|||
|
};
|
|||
|
|
|||
|
exports.green = function(str) {
|
|||
|
return colorize(str, 32);
|
|||
|
};
|
|||
|
|
|||
|
exports.cyan = function(str) {
|
|||
|
return colorize(str, 96);
|
|||
|
};
|
|||
|
|
|||
|
exports.white = function(str) {
|
|||
|
return colorize(str, 39);
|
|||
|
};
|
|||
|
|
|||
|
exports.bold = function(str) {
|
|||
|
return colorize(str, 1);
|
|||
|
};
|
|||
|
|
|||
|
},{"supports-color":105}],7:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var Sandbox = require("./sandbox");
|
|||
|
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var push = arrayProto.push;
|
|||
|
|
|||
|
function prepareSandboxFromConfig(config) {
|
|||
|
var sandbox = new Sandbox();
|
|||
|
|
|||
|
if (config.useFakeServer) {
|
|||
|
if (typeof config.useFakeServer === "object") {
|
|||
|
sandbox.serverPrototype = config.useFakeServer;
|
|||
|
}
|
|||
|
|
|||
|
sandbox.useFakeServer();
|
|||
|
}
|
|||
|
|
|||
|
if (config.useFakeTimers) {
|
|||
|
if (typeof config.useFakeTimers === "object") {
|
|||
|
sandbox.useFakeTimers(config.useFakeTimers);
|
|||
|
} else {
|
|||
|
sandbox.useFakeTimers();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return sandbox;
|
|||
|
}
|
|||
|
|
|||
|
function exposeValue(sandbox, config, key, value) {
|
|||
|
if (!value) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (config.injectInto && !(key in config.injectInto)) {
|
|||
|
config.injectInto[key] = value;
|
|||
|
push(sandbox.injectedKeys, key);
|
|||
|
} else {
|
|||
|
push(sandbox.args, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function createSandbox(config) {
|
|||
|
if (!config) {
|
|||
|
return new Sandbox();
|
|||
|
}
|
|||
|
|
|||
|
var configuredSandbox = prepareSandboxFromConfig(config);
|
|||
|
configuredSandbox.args = configuredSandbox.args || [];
|
|||
|
configuredSandbox.injectedKeys = [];
|
|||
|
configuredSandbox.injectInto = config.injectInto;
|
|||
|
var exposed = configuredSandbox.inject({});
|
|||
|
|
|||
|
if (config.properties) {
|
|||
|
forEach(config.properties, function(prop) {
|
|||
|
var value = exposed[prop] || (prop === "sandbox" && configuredSandbox);
|
|||
|
exposeValue(configuredSandbox, config, prop, value);
|
|||
|
});
|
|||
|
} else {
|
|||
|
exposeValue(configuredSandbox, config, "sandbox");
|
|||
|
}
|
|||
|
|
|||
|
return configuredSandbox;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = createSandbox;
|
|||
|
|
|||
|
},{"./sandbox":17,"@sinonjs/commons":45}],8:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var isPropertyConfigurable = require("./util/core/is-property-configurable");
|
|||
|
var exportAsyncBehaviors = require("./util/core/export-async-behaviors");
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
|
|||
|
var slice = arrayProto.slice;
|
|||
|
|
|||
|
var useLeftMostCallback = -1;
|
|||
|
var useRightMostCallback = -2;
|
|||
|
|
|||
|
function throwsException(fake, error, message) {
|
|||
|
if (typeof error === "function") {
|
|||
|
fake.exceptionCreator = error;
|
|||
|
} else if (typeof error === "string") {
|
|||
|
fake.exceptionCreator = function() {
|
|||
|
var newException = new Error(message || "");
|
|||
|
newException.name = error;
|
|||
|
return newException;
|
|||
|
};
|
|||
|
} else if (!error) {
|
|||
|
fake.exceptionCreator = function() {
|
|||
|
return new Error("Error");
|
|||
|
};
|
|||
|
} else {
|
|||
|
fake.exception = error;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var defaultBehaviors = {
|
|||
|
callsFake: function callsFake(fake, fn) {
|
|||
|
fake.fakeFn = fn;
|
|||
|
},
|
|||
|
|
|||
|
callsArg: function callsArg(fake, index) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
|
|||
|
fake.callArgAt = index;
|
|||
|
fake.callbackArguments = [];
|
|||
|
fake.callbackContext = undefined;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
callsArgOn: function callsArgOn(fake, index, context) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
|
|||
|
fake.callArgAt = index;
|
|||
|
fake.callbackArguments = [];
|
|||
|
fake.callbackContext = context;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
callsArgWith: function callsArgWith(fake, index) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
|
|||
|
fake.callArgAt = index;
|
|||
|
fake.callbackArguments = slice(arguments, 2);
|
|||
|
fake.callbackContext = undefined;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
callsArgOnWith: function callsArgWith(fake, index, context) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
|
|||
|
fake.callArgAt = index;
|
|||
|
fake.callbackArguments = slice(arguments, 3);
|
|||
|
fake.callbackContext = context;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
usingPromise: function usingPromise(fake, promiseLibrary) {
|
|||
|
fake.promiseLibrary = promiseLibrary;
|
|||
|
},
|
|||
|
|
|||
|
yields: function(fake) {
|
|||
|
fake.callArgAt = useLeftMostCallback;
|
|||
|
fake.callbackArguments = slice(arguments, 1);
|
|||
|
fake.callbackContext = undefined;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
yieldsRight: function(fake) {
|
|||
|
fake.callArgAt = useRightMostCallback;
|
|||
|
fake.callbackArguments = slice(arguments, 1);
|
|||
|
fake.callbackContext = undefined;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
yieldsOn: function(fake, context) {
|
|||
|
fake.callArgAt = useLeftMostCallback;
|
|||
|
fake.callbackArguments = slice(arguments, 2);
|
|||
|
fake.callbackContext = context;
|
|||
|
fake.callArgProp = undefined;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
yieldsTo: function(fake, prop) {
|
|||
|
fake.callArgAt = useLeftMostCallback;
|
|||
|
fake.callbackArguments = slice(arguments, 2);
|
|||
|
fake.callbackContext = undefined;
|
|||
|
fake.callArgProp = prop;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
yieldsToOn: function(fake, prop, context) {
|
|||
|
fake.callArgAt = useLeftMostCallback;
|
|||
|
fake.callbackArguments = slice(arguments, 3);
|
|||
|
fake.callbackContext = context;
|
|||
|
fake.callArgProp = prop;
|
|||
|
fake.callbackAsync = false;
|
|||
|
},
|
|||
|
|
|||
|
throws: throwsException,
|
|||
|
throwsException: throwsException,
|
|||
|
|
|||
|
returns: function returns(fake, value) {
|
|||
|
fake.returnValue = value;
|
|||
|
fake.resolve = false;
|
|||
|
fake.reject = false;
|
|||
|
fake.returnValueDefined = true;
|
|||
|
fake.exception = undefined;
|
|||
|
fake.exceptionCreator = undefined;
|
|||
|
fake.fakeFn = undefined;
|
|||
|
},
|
|||
|
|
|||
|
returnsArg: function returnsArg(fake, index) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
|
|||
|
fake.returnArgAt = index;
|
|||
|
},
|
|||
|
|
|||
|
throwsArg: function throwsArg(fake, index) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
|
|||
|
fake.throwArgAt = index;
|
|||
|
},
|
|||
|
|
|||
|
returnsThis: function returnsThis(fake) {
|
|||
|
fake.returnThis = true;
|
|||
|
},
|
|||
|
|
|||
|
resolves: function resolves(fake, value) {
|
|||
|
fake.returnValue = value;
|
|||
|
fake.resolve = true;
|
|||
|
fake.resolveThis = false;
|
|||
|
fake.reject = false;
|
|||
|
fake.returnValueDefined = true;
|
|||
|
fake.exception = undefined;
|
|||
|
fake.exceptionCreator = undefined;
|
|||
|
fake.fakeFn = undefined;
|
|||
|
},
|
|||
|
|
|||
|
resolvesArg: function resolvesArg(fake, index) {
|
|||
|
if (typeof index !== "number") {
|
|||
|
throw new TypeError("argument index is not number");
|
|||
|
}
|
|||
|
fake.resolveArgAt = index;
|
|||
|
fake.returnValue = undefined;
|
|||
|
fake.resolve = true;
|
|||
|
fake.resolveThis = false;
|
|||
|
fake.reject = false;
|
|||
|
fake.returnValueDefined = false;
|
|||
|
fake.exception = undefined;
|
|||
|
fake.exceptionCreator = undefined;
|
|||
|
fake.fakeFn = undefined;
|
|||
|
},
|
|||
|
|
|||
|
rejects: function rejects(fake, error, message) {
|
|||
|
var reason;
|
|||
|
if (typeof error === "string") {
|
|||
|
reason = new Error(message || "");
|
|||
|
reason.name = error;
|
|||
|
} else if (!error) {
|
|||
|
reason = new Error("Error");
|
|||
|
} else {
|
|||
|
reason = error;
|
|||
|
}
|
|||
|
fake.returnValue = reason;
|
|||
|
fake.resolve = false;
|
|||
|
fake.resolveThis = false;
|
|||
|
fake.reject = true;
|
|||
|
fake.returnValueDefined = true;
|
|||
|
fake.exception = undefined;
|
|||
|
fake.exceptionCreator = undefined;
|
|||
|
fake.fakeFn = undefined;
|
|||
|
|
|||
|
return fake;
|
|||
|
},
|
|||
|
|
|||
|
resolvesThis: function resolvesThis(fake) {
|
|||
|
fake.returnValue = undefined;
|
|||
|
fake.resolve = false;
|
|||
|
fake.resolveThis = true;
|
|||
|
fake.reject = false;
|
|||
|
fake.returnValueDefined = false;
|
|||
|
fake.exception = undefined;
|
|||
|
fake.exceptionCreator = undefined;
|
|||
|
fake.fakeFn = undefined;
|
|||
|
},
|
|||
|
|
|||
|
callThrough: function callThrough(fake) {
|
|||
|
fake.callsThrough = true;
|
|||
|
},
|
|||
|
|
|||
|
callThroughWithNew: function callThroughWithNew(fake) {
|
|||
|
fake.callsThroughWithNew = true;
|
|||
|
},
|
|||
|
|
|||
|
get: function get(fake, getterFunction) {
|
|||
|
var rootStub = fake.stub || fake;
|
|||
|
|
|||
|
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
|
|||
|
get: getterFunction,
|
|||
|
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
|
|||
|
});
|
|||
|
|
|||
|
return fake;
|
|||
|
},
|
|||
|
|
|||
|
set: function set(fake, setterFunction) {
|
|||
|
var rootStub = fake.stub || fake;
|
|||
|
|
|||
|
Object.defineProperty(
|
|||
|
rootStub.rootObj,
|
|||
|
rootStub.propName,
|
|||
|
// eslint-disable-next-line accessor-pairs
|
|||
|
{
|
|||
|
set: setterFunction,
|
|||
|
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
|
|||
|
}
|
|||
|
);
|
|||
|
|
|||
|
return fake;
|
|||
|
},
|
|||
|
|
|||
|
value: function value(fake, newVal) {
|
|||
|
var rootStub = fake.stub || fake;
|
|||
|
|
|||
|
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
|
|||
|
value: newVal,
|
|||
|
enumerable: true,
|
|||
|
configurable: rootStub.shadowsPropOnPrototype || isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
|
|||
|
});
|
|||
|
|
|||
|
return fake;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var asyncBehaviors = exportAsyncBehaviors(defaultBehaviors);
|
|||
|
|
|||
|
module.exports = extend({}, defaultBehaviors, asyncBehaviors);
|
|||
|
|
|||
|
},{"./util/core/export-async-behaviors":23,"./util/core/extend":24,"./util/core/is-property-configurable":31,"@sinonjs/commons":45}],9:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var createProxy = require("./proxy");
|
|||
|
var nextTick = require("./util/core/next-tick");
|
|||
|
|
|||
|
var slice = arrayProto.slice;
|
|||
|
|
|||
|
function getError(value) {
|
|||
|
return value instanceof Error ? value : new Error(value);
|
|||
|
}
|
|||
|
|
|||
|
var uuid = 0;
|
|||
|
function wrapFunc(f) {
|
|||
|
var proxy;
|
|||
|
var fakeInstance = function() {
|
|||
|
var firstArg, lastArg;
|
|||
|
|
|||
|
if (arguments.length > 0) {
|
|||
|
firstArg = arguments[0];
|
|||
|
lastArg = arguments[arguments.length - 1];
|
|||
|
}
|
|||
|
|
|||
|
var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined;
|
|||
|
|
|||
|
proxy.firstArg = firstArg;
|
|||
|
proxy.lastArg = lastArg;
|
|||
|
proxy.callback = callback;
|
|||
|
|
|||
|
return f && f.apply(this, arguments);
|
|||
|
};
|
|||
|
proxy = createProxy(fakeInstance, f || fakeInstance);
|
|||
|
|
|||
|
proxy.displayName = "fake";
|
|||
|
proxy.id = "fake#" + uuid++;
|
|||
|
|
|||
|
return proxy;
|
|||
|
}
|
|||
|
|
|||
|
function fake(f) {
|
|||
|
if (arguments.length > 0 && typeof f !== "function") {
|
|||
|
throw new TypeError("Expected f argument to be a Function");
|
|||
|
}
|
|||
|
|
|||
|
return wrapFunc(f);
|
|||
|
}
|
|||
|
|
|||
|
fake.returns = function returns(value) {
|
|||
|
function f() {
|
|||
|
return value;
|
|||
|
}
|
|||
|
|
|||
|
return wrapFunc(f);
|
|||
|
};
|
|||
|
|
|||
|
fake.throws = function throws(value) {
|
|||
|
function f() {
|
|||
|
throw getError(value);
|
|||
|
}
|
|||
|
|
|||
|
return wrapFunc(f);
|
|||
|
};
|
|||
|
|
|||
|
fake.resolves = function resolves(value) {
|
|||
|
function f() {
|
|||
|
return Promise.resolve(value);
|
|||
|
}
|
|||
|
|
|||
|
return wrapFunc(f);
|
|||
|
};
|
|||
|
|
|||
|
fake.rejects = function rejects(value) {
|
|||
|
function f() {
|
|||
|
return Promise.reject(getError(value));
|
|||
|
}
|
|||
|
|
|||
|
return wrapFunc(f);
|
|||
|
};
|
|||
|
|
|||
|
function yieldInternal(async, values) {
|
|||
|
function f() {
|
|||
|
var callback = arguments[arguments.length - 1];
|
|||
|
if (typeof callback !== "function") {
|
|||
|
throw new TypeError("Expected last argument to be a function");
|
|||
|
}
|
|||
|
if (async) {
|
|||
|
nextTick(function() {
|
|||
|
callback.apply(null, values);
|
|||
|
});
|
|||
|
} else {
|
|||
|
callback.apply(null, values);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return wrapFunc(f);
|
|||
|
}
|
|||
|
|
|||
|
fake.yields = function yields() {
|
|||
|
return yieldInternal(false, slice(arguments));
|
|||
|
};
|
|||
|
|
|||
|
fake.yieldsAsync = function yieldsAsync() {
|
|||
|
return yieldInternal(true, slice(arguments));
|
|||
|
};
|
|||
|
|
|||
|
module.exports = fake;
|
|||
|
|
|||
|
},{"./proxy":15,"./util/core/next-tick":32,"@sinonjs/commons":45}],10:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var proxyInvoke = require("./proxy-invoke");
|
|||
|
var proxyCallToString = require("./proxy-call").toString;
|
|||
|
var timesInWords = require("./util/core/times-in-words");
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
var match = require("@sinonjs/samsam").createMatcher;
|
|||
|
var stub = require("./stub");
|
|||
|
var assert = require("./assert");
|
|||
|
var deepEqual = require("@sinonjs/samsam").deepEqual;
|
|||
|
var format = require("./util/core/format");
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
var every = arrayProto.every;
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var push = arrayProto.push;
|
|||
|
var slice = arrayProto.slice;
|
|||
|
|
|||
|
function callCountInWords(callCount) {
|
|||
|
if (callCount === 0) {
|
|||
|
return "never called";
|
|||
|
}
|
|||
|
|
|||
|
return "called " + timesInWords(callCount);
|
|||
|
}
|
|||
|
|
|||
|
function expectedCallCountInWords(expectation) {
|
|||
|
var min = expectation.minCalls;
|
|||
|
var max = expectation.maxCalls;
|
|||
|
|
|||
|
if (typeof min === "number" && typeof max === "number") {
|
|||
|
var str = timesInWords(min);
|
|||
|
|
|||
|
if (min !== max) {
|
|||
|
str = "at least " + str + " and at most " + timesInWords(max);
|
|||
|
}
|
|||
|
|
|||
|
return str;
|
|||
|
}
|
|||
|
|
|||
|
if (typeof min === "number") {
|
|||
|
return "at least " + timesInWords(min);
|
|||
|
}
|
|||
|
|
|||
|
return "at most " + timesInWords(max);
|
|||
|
}
|
|||
|
|
|||
|
function receivedMinCalls(expectation) {
|
|||
|
var hasMinLimit = typeof expectation.minCalls === "number";
|
|||
|
return !hasMinLimit || expectation.callCount >= expectation.minCalls;
|
|||
|
}
|
|||
|
|
|||
|
function receivedMaxCalls(expectation) {
|
|||
|
if (typeof expectation.maxCalls !== "number") {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return expectation.callCount === expectation.maxCalls;
|
|||
|
}
|
|||
|
|
|||
|
function verifyMatcher(possibleMatcher, arg) {
|
|||
|
var isMatcher = match.isMatcher(possibleMatcher);
|
|||
|
|
|||
|
return (isMatcher && possibleMatcher.test(arg)) || true;
|
|||
|
}
|
|||
|
|
|||
|
var mockExpectation = {
|
|||
|
minCalls: 1,
|
|||
|
maxCalls: 1,
|
|||
|
|
|||
|
create: function create(methodName) {
|
|||
|
var expectation = extend.nonEnum(stub(), mockExpectation);
|
|||
|
delete expectation.create;
|
|||
|
expectation.method = methodName;
|
|||
|
|
|||
|
return expectation;
|
|||
|
},
|
|||
|
|
|||
|
invoke: function invoke(func, thisValue, args) {
|
|||
|
this.verifyCallAllowed(thisValue, args);
|
|||
|
|
|||
|
return proxyInvoke.apply(this, arguments);
|
|||
|
},
|
|||
|
|
|||
|
atLeast: function atLeast(num) {
|
|||
|
if (typeof num !== "number") {
|
|||
|
throw new TypeError("'" + valueToString(num) + "' is not number");
|
|||
|
}
|
|||
|
|
|||
|
if (!this.limitsSet) {
|
|||
|
this.maxCalls = null;
|
|||
|
this.limitsSet = true;
|
|||
|
}
|
|||
|
|
|||
|
this.minCalls = num;
|
|||
|
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
atMost: function atMost(num) {
|
|||
|
if (typeof num !== "number") {
|
|||
|
throw new TypeError("'" + valueToString(num) + "' is not number");
|
|||
|
}
|
|||
|
|
|||
|
if (!this.limitsSet) {
|
|||
|
this.minCalls = null;
|
|||
|
this.limitsSet = true;
|
|||
|
}
|
|||
|
|
|||
|
this.maxCalls = num;
|
|||
|
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
never: function never() {
|
|||
|
return this.exactly(0);
|
|||
|
},
|
|||
|
|
|||
|
once: function once() {
|
|||
|
return this.exactly(1);
|
|||
|
},
|
|||
|
|
|||
|
twice: function twice() {
|
|||
|
return this.exactly(2);
|
|||
|
},
|
|||
|
|
|||
|
thrice: function thrice() {
|
|||
|
return this.exactly(3);
|
|||
|
},
|
|||
|
|
|||
|
exactly: function exactly(num) {
|
|||
|
if (typeof num !== "number") {
|
|||
|
throw new TypeError("'" + valueToString(num) + "' is not a number");
|
|||
|
}
|
|||
|
|
|||
|
this.atLeast(num);
|
|||
|
return this.atMost(num);
|
|||
|
},
|
|||
|
|
|||
|
met: function met() {
|
|||
|
return !this.failed && receivedMinCalls(this);
|
|||
|
},
|
|||
|
|
|||
|
verifyCallAllowed: function verifyCallAllowed(thisValue, args) {
|
|||
|
var expectedArguments = this.expectedArguments;
|
|||
|
|
|||
|
if (receivedMaxCalls(this)) {
|
|||
|
this.failed = true;
|
|||
|
mockExpectation.fail(this.method + " already called " + timesInWords(this.maxCalls));
|
|||
|
}
|
|||
|
|
|||
|
if ("expectedThis" in this && this.expectedThis !== thisValue) {
|
|||
|
mockExpectation.fail(
|
|||
|
this.method +
|
|||
|
" called with " +
|
|||
|
valueToString(thisValue) +
|
|||
|
" as thisValue, expected " +
|
|||
|
valueToString(this.expectedThis)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
if (!("expectedArguments" in this)) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (!args) {
|
|||
|
mockExpectation.fail(this.method + " received no arguments, expected " + format(expectedArguments));
|
|||
|
}
|
|||
|
|
|||
|
if (args.length < expectedArguments.length) {
|
|||
|
mockExpectation.fail(
|
|||
|
this.method +
|
|||
|
" received too few arguments (" +
|
|||
|
format(args) +
|
|||
|
"), expected " +
|
|||
|
format(expectedArguments)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
if (this.expectsExactArgCount && args.length !== expectedArguments.length) {
|
|||
|
mockExpectation.fail(
|
|||
|
this.method +
|
|||
|
" received too many arguments (" +
|
|||
|
format(args) +
|
|||
|
"), expected " +
|
|||
|
format(expectedArguments)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
forEach(
|
|||
|
expectedArguments,
|
|||
|
function(expectedArgument, i) {
|
|||
|
if (!verifyMatcher(expectedArgument, args[i])) {
|
|||
|
mockExpectation.fail(
|
|||
|
this.method +
|
|||
|
" received wrong arguments " +
|
|||
|
format(args) +
|
|||
|
", didn't match " +
|
|||
|
String(expectedArguments)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
if (!deepEqual(args[i], expectedArgument)) {
|
|||
|
mockExpectation.fail(
|
|||
|
this.method +
|
|||
|
" received wrong arguments " +
|
|||
|
format(args) +
|
|||
|
", expected " +
|
|||
|
format(expectedArguments)
|
|||
|
);
|
|||
|
}
|
|||
|
},
|
|||
|
this
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
allowsCall: function allowsCall(thisValue, args) {
|
|||
|
var expectedArguments = this.expectedArguments;
|
|||
|
|
|||
|
if (this.met() && receivedMaxCalls(this)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if ("expectedThis" in this && this.expectedThis !== thisValue) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (!("expectedArguments" in this)) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
// eslint-disable-next-line no-underscore-dangle
|
|||
|
var _args = args || [];
|
|||
|
|
|||
|
if (_args.length < expectedArguments.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (this.expectsExactArgCount && _args.length !== expectedArguments.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return every(expectedArguments, function(expectedArgument, i) {
|
|||
|
if (!verifyMatcher(expectedArgument, _args[i])) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (!deepEqual(_args[i], expectedArgument)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
withArgs: function withArgs() {
|
|||
|
this.expectedArguments = slice(arguments);
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
withExactArgs: function withExactArgs() {
|
|||
|
this.withArgs.apply(this, arguments);
|
|||
|
this.expectsExactArgCount = true;
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
on: function on(thisValue) {
|
|||
|
this.expectedThis = thisValue;
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
toString: function() {
|
|||
|
var args = slice(this.expectedArguments || []);
|
|||
|
|
|||
|
if (!this.expectsExactArgCount) {
|
|||
|
push(args, "[...]");
|
|||
|
}
|
|||
|
|
|||
|
var callStr = proxyCallToString.call({
|
|||
|
proxy: this.method || "anonymous mock expectation",
|
|||
|
args: args
|
|||
|
});
|
|||
|
|
|||
|
var message = callStr.replace(", [...", "[, ...") + " " + expectedCallCountInWords(this);
|
|||
|
|
|||
|
if (this.met()) {
|
|||
|
return "Expectation met: " + message;
|
|||
|
}
|
|||
|
|
|||
|
return "Expected " + message + " (" + callCountInWords(this.callCount) + ")";
|
|||
|
},
|
|||
|
|
|||
|
verify: function verify() {
|
|||
|
if (!this.met()) {
|
|||
|
mockExpectation.fail(String(this));
|
|||
|
} else {
|
|||
|
mockExpectation.pass(String(this));
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
},
|
|||
|
|
|||
|
pass: function pass(message) {
|
|||
|
assert.pass(message);
|
|||
|
},
|
|||
|
|
|||
|
fail: function fail(message) {
|
|||
|
var exception = new Error(message);
|
|||
|
exception.name = "ExpectationError";
|
|||
|
|
|||
|
throw exception;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
module.exports = mockExpectation;
|
|||
|
|
|||
|
},{"./assert":3,"./proxy-call":13,"./proxy-invoke":14,"./stub":20,"./util/core/extend":24,"./util/core/format":25,"./util/core/times-in-words":33,"@sinonjs/commons":45,"@sinonjs/samsam":84}],11:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var mockExpectation = require("./mock-expectation");
|
|||
|
var proxyCallToString = require("./proxy-call").toString;
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
var deepEqual = require("@sinonjs/samsam").deepEqual;
|
|||
|
var wrapMethod = require("./util/core/wrap-method");
|
|||
|
var usePromiseLibrary = require("./util/core/use-promise-library");
|
|||
|
|
|||
|
var concat = arrayProto.concat;
|
|||
|
var filter = arrayProto.filter;
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var every = arrayProto.every;
|
|||
|
var join = arrayProto.join;
|
|||
|
var push = arrayProto.push;
|
|||
|
var slice = arrayProto.slice;
|
|||
|
var unshift = arrayProto.unshift;
|
|||
|
|
|||
|
function mock(object) {
|
|||
|
if (!object || typeof object === "string") {
|
|||
|
return mockExpectation.create(object ? object : "Anonymous mock");
|
|||
|
}
|
|||
|
|
|||
|
return mock.create(object);
|
|||
|
}
|
|||
|
|
|||
|
function each(collection, callback) {
|
|||
|
var col = collection || [];
|
|||
|
|
|||
|
forEach(col, callback);
|
|||
|
}
|
|||
|
|
|||
|
function arrayEquals(arr1, arr2, compareLength) {
|
|||
|
if (compareLength && arr1.length !== arr2.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return every(arr1, function(element, i) {
|
|||
|
return deepEqual(arr2[i], element);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
extend(mock, {
|
|||
|
create: function create(object) {
|
|||
|
if (!object) {
|
|||
|
throw new TypeError("object is null");
|
|||
|
}
|
|||
|
|
|||
|
var mockObject = extend.nonEnum({}, mock, { object: object });
|
|||
|
delete mockObject.create;
|
|||
|
|
|||
|
return mockObject;
|
|||
|
},
|
|||
|
|
|||
|
expects: function expects(method) {
|
|||
|
if (!method) {
|
|||
|
throw new TypeError("method is falsy");
|
|||
|
}
|
|||
|
|
|||
|
if (!this.expectations) {
|
|||
|
this.expectations = {};
|
|||
|
this.proxies = [];
|
|||
|
this.failures = [];
|
|||
|
}
|
|||
|
|
|||
|
if (!this.expectations[method]) {
|
|||
|
this.expectations[method] = [];
|
|||
|
var mockObject = this;
|
|||
|
|
|||
|
wrapMethod(this.object, method, function() {
|
|||
|
return mockObject.invokeMethod(method, this, arguments);
|
|||
|
});
|
|||
|
|
|||
|
push(this.proxies, method);
|
|||
|
}
|
|||
|
|
|||
|
var expectation = mockExpectation.create(method);
|
|||
|
expectation.wrappedMethod = this.object[method].wrappedMethod;
|
|||
|
push(this.expectations[method], expectation);
|
|||
|
usePromiseLibrary(this.promiseLibrary, expectation);
|
|||
|
|
|||
|
return expectation;
|
|||
|
},
|
|||
|
|
|||
|
restore: function restore() {
|
|||
|
var object = this.object;
|
|||
|
|
|||
|
each(this.proxies, function(proxy) {
|
|||
|
if (typeof object[proxy].restore === "function") {
|
|||
|
object[proxy].restore();
|
|||
|
}
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
verify: function verify() {
|
|||
|
var expectations = this.expectations || {};
|
|||
|
var messages = this.failures ? slice(this.failures) : [];
|
|||
|
var met = [];
|
|||
|
|
|||
|
each(this.proxies, function(proxy) {
|
|||
|
each(expectations[proxy], function(expectation) {
|
|||
|
if (!expectation.met()) {
|
|||
|
push(messages, String(expectation));
|
|||
|
} else {
|
|||
|
push(met, String(expectation));
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
|
|||
|
this.restore();
|
|||
|
|
|||
|
if (messages.length > 0) {
|
|||
|
mockExpectation.fail(join(concat(messages, met), "\n"));
|
|||
|
} else if (met.length > 0) {
|
|||
|
mockExpectation.pass(join(concat(messages, met), "\n"));
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
},
|
|||
|
|
|||
|
usingPromise: function usingPromise(promiseLibrary) {
|
|||
|
this.promiseLibrary = promiseLibrary;
|
|||
|
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
invokeMethod: function invokeMethod(method, thisValue, args) {
|
|||
|
/* if we cannot find any matching files we will explicitly call mockExpection#fail with error messages */
|
|||
|
/* eslint consistent-return: "off" */
|
|||
|
var expectations = this.expectations && this.expectations[method] ? this.expectations[method] : [];
|
|||
|
var currentArgs = args || [];
|
|||
|
var available;
|
|||
|
|
|||
|
var expectationsWithMatchingArgs = filter(expectations, function(expectation) {
|
|||
|
var expectedArgs = expectation.expectedArguments || [];
|
|||
|
|
|||
|
return arrayEquals(expectedArgs, currentArgs, expectation.expectsExactArgCount);
|
|||
|
});
|
|||
|
|
|||
|
var expectationsToApply = filter(expectationsWithMatchingArgs, function(expectation) {
|
|||
|
return !expectation.met() && expectation.allowsCall(thisValue, args);
|
|||
|
});
|
|||
|
|
|||
|
if (expectationsToApply.length > 0) {
|
|||
|
return expectationsToApply[0].apply(thisValue, args);
|
|||
|
}
|
|||
|
|
|||
|
var messages = [];
|
|||
|
var exhausted = 0;
|
|||
|
|
|||
|
forEach(expectationsWithMatchingArgs, function(expectation) {
|
|||
|
if (expectation.allowsCall(thisValue, args)) {
|
|||
|
available = available || expectation;
|
|||
|
} else {
|
|||
|
exhausted += 1;
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
if (available && exhausted === 0) {
|
|||
|
return available.apply(thisValue, args);
|
|||
|
}
|
|||
|
|
|||
|
forEach(expectations, function(expectation) {
|
|||
|
push(messages, " " + String(expectation));
|
|||
|
});
|
|||
|
|
|||
|
unshift(
|
|||
|
messages,
|
|||
|
"Unexpected call: " +
|
|||
|
proxyCallToString.call({
|
|||
|
proxy: method,
|
|||
|
args: args
|
|||
|
})
|
|||
|
);
|
|||
|
|
|||
|
var err = new Error();
|
|||
|
if (!err.stack) {
|
|||
|
// PhantomJS does not serialize the stack trace until the error has been thrown
|
|||
|
try {
|
|||
|
throw err;
|
|||
|
} catch (e) {
|
|||
|
/* empty */
|
|||
|
}
|
|||
|
}
|
|||
|
push(
|
|||
|
this.failures,
|
|||
|
"Unexpected call: " +
|
|||
|
proxyCallToString.call({
|
|||
|
proxy: method,
|
|||
|
args: args,
|
|||
|
stack: err.stack
|
|||
|
})
|
|||
|
);
|
|||
|
|
|||
|
mockExpectation.fail(join(messages, "\n"));
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
module.exports = mock;
|
|||
|
|
|||
|
},{"./mock-expectation":10,"./proxy-call":13,"./util/core/extend":24,"./util/core/use-promise-library":34,"./util/core/wrap-method":37,"@sinonjs/commons":45,"@sinonjs/samsam":84}],12:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var push = require("@sinonjs/commons").prototypes.array.push;
|
|||
|
|
|||
|
exports.incrementCallCount = function incrementCallCount(proxy) {
|
|||
|
proxy.called = true;
|
|||
|
proxy.callCount += 1;
|
|||
|
proxy.notCalled = false;
|
|||
|
proxy.calledOnce = proxy.callCount === 1;
|
|||
|
proxy.calledTwice = proxy.callCount === 2;
|
|||
|
proxy.calledThrice = proxy.callCount === 3;
|
|||
|
};
|
|||
|
|
|||
|
exports.createCallProperties = function createCallProperties(proxy) {
|
|||
|
proxy.firstCall = proxy.getCall(0);
|
|||
|
proxy.secondCall = proxy.getCall(1);
|
|||
|
proxy.thirdCall = proxy.getCall(2);
|
|||
|
proxy.lastCall = proxy.getCall(proxy.callCount - 1);
|
|||
|
};
|
|||
|
|
|||
|
exports.delegateToCalls = function delegateToCalls(
|
|||
|
proxy,
|
|||
|
method,
|
|||
|
matchAny,
|
|||
|
actual,
|
|||
|
returnsValues,
|
|||
|
notCalled,
|
|||
|
totalCallCount
|
|||
|
) {
|
|||
|
proxy[method] = function() {
|
|||
|
if (!this.called) {
|
|||
|
if (notCalled) {
|
|||
|
return notCalled.apply(this, arguments);
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (totalCallCount !== undefined && this.callCount !== totalCallCount) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
var currentCall;
|
|||
|
var matches = 0;
|
|||
|
var returnValues = [];
|
|||
|
|
|||
|
for (var i = 0, l = this.callCount; i < l; i += 1) {
|
|||
|
currentCall = this.getCall(i);
|
|||
|
var returnValue = currentCall[actual || method].apply(currentCall, arguments);
|
|||
|
push(returnValues, returnValue);
|
|||
|
if (returnValue) {
|
|||
|
matches += 1;
|
|||
|
|
|||
|
if (matchAny) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (returnsValues) {
|
|||
|
return returnValues;
|
|||
|
}
|
|||
|
return matches === this.callCount;
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],13:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var match = require("@sinonjs/samsam").createMatcher;
|
|||
|
var deepEqual = require("@sinonjs/samsam").deepEqual;
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var sinonFormat = require("./util/core/format");
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
var concat = arrayProto.concat;
|
|||
|
var filter = arrayProto.filter;
|
|||
|
var join = arrayProto.join;
|
|||
|
var map = arrayProto.map;
|
|||
|
var reduce = arrayProto.reduce;
|
|||
|
var slice = arrayProto.slice;
|
|||
|
|
|||
|
function throwYieldError(proxy, text, args) {
|
|||
|
var msg = functionName(proxy) + text;
|
|||
|
if (args.length) {
|
|||
|
msg += " Received [" + join(slice(args), ", ") + "]";
|
|||
|
}
|
|||
|
throw new Error(msg);
|
|||
|
}
|
|||
|
|
|||
|
var callProto = {
|
|||
|
calledOn: function calledOn(thisValue) {
|
|||
|
if (match.isMatcher(thisValue)) {
|
|||
|
return thisValue.test(this.thisValue);
|
|||
|
}
|
|||
|
return this.thisValue === thisValue;
|
|||
|
},
|
|||
|
|
|||
|
calledWith: function calledWith() {
|
|||
|
var self = this;
|
|||
|
var calledWithArgs = slice(arguments);
|
|||
|
|
|||
|
if (calledWithArgs.length > self.args.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return reduce(
|
|||
|
calledWithArgs,
|
|||
|
function(prev, arg, i) {
|
|||
|
return prev && deepEqual(self.args[i], arg);
|
|||
|
},
|
|||
|
true
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
calledWithMatch: function calledWithMatch() {
|
|||
|
var self = this;
|
|||
|
var calledWithMatchArgs = slice(arguments);
|
|||
|
|
|||
|
if (calledWithMatchArgs.length > self.args.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return reduce(
|
|||
|
calledWithMatchArgs,
|
|||
|
function(prev, expectation, i) {
|
|||
|
var actual = self.args[i];
|
|||
|
|
|||
|
return prev && match(expectation).test(actual);
|
|||
|
},
|
|||
|
true
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
calledWithExactly: function calledWithExactly() {
|
|||
|
return arguments.length === this.args.length && this.calledWith.apply(this, arguments);
|
|||
|
},
|
|||
|
|
|||
|
notCalledWith: function notCalledWith() {
|
|||
|
return !this.calledWith.apply(this, arguments);
|
|||
|
},
|
|||
|
|
|||
|
notCalledWithMatch: function notCalledWithMatch() {
|
|||
|
return !this.calledWithMatch.apply(this, arguments);
|
|||
|
},
|
|||
|
|
|||
|
returned: function returned(value) {
|
|||
|
return deepEqual(this.returnValue, value);
|
|||
|
},
|
|||
|
|
|||
|
threw: function threw(error) {
|
|||
|
if (typeof error === "undefined" || !this.exception) {
|
|||
|
return Boolean(this.exception);
|
|||
|
}
|
|||
|
|
|||
|
return this.exception === error || this.exception.name === error;
|
|||
|
},
|
|||
|
|
|||
|
calledWithNew: function calledWithNew() {
|
|||
|
return this.proxy.prototype && this.thisValue instanceof this.proxy;
|
|||
|
},
|
|||
|
|
|||
|
calledBefore: function(other) {
|
|||
|
return this.callId < other.callId;
|
|||
|
},
|
|||
|
|
|||
|
calledAfter: function(other) {
|
|||
|
return this.callId > other.callId;
|
|||
|
},
|
|||
|
|
|||
|
calledImmediatelyBefore: function(other) {
|
|||
|
return this.callId === other.callId - 1;
|
|||
|
},
|
|||
|
|
|||
|
calledImmediatelyAfter: function(other) {
|
|||
|
return this.callId === other.callId + 1;
|
|||
|
},
|
|||
|
|
|||
|
callArg: function(pos) {
|
|||
|
this.ensureArgIsAFunction(pos);
|
|||
|
return this.args[pos]();
|
|||
|
},
|
|||
|
|
|||
|
callArgOn: function(pos, thisValue) {
|
|||
|
this.ensureArgIsAFunction(pos);
|
|||
|
return this.args[pos].apply(thisValue);
|
|||
|
},
|
|||
|
|
|||
|
callArgWith: function(pos) {
|
|||
|
return this.callArgOnWith.apply(this, concat([pos, null], slice(arguments, 1)));
|
|||
|
},
|
|||
|
|
|||
|
callArgOnWith: function(pos, thisValue) {
|
|||
|
this.ensureArgIsAFunction(pos);
|
|||
|
var args = slice(arguments, 2);
|
|||
|
return this.args[pos].apply(thisValue, args);
|
|||
|
},
|
|||
|
|
|||
|
throwArg: function(pos) {
|
|||
|
if (pos > this.args.length) {
|
|||
|
throw new TypeError("Not enough arguments: " + pos + " required but only " + this.args.length + " present");
|
|||
|
}
|
|||
|
|
|||
|
throw this.args[pos];
|
|||
|
},
|
|||
|
|
|||
|
yield: function() {
|
|||
|
return this.yieldOn.apply(this, concat([null], slice(arguments, 0)));
|
|||
|
},
|
|||
|
|
|||
|
yieldOn: function(thisValue) {
|
|||
|
var args = slice(this.args);
|
|||
|
var yieldFn = filter(args, function(arg) {
|
|||
|
return typeof arg === "function";
|
|||
|
})[0];
|
|||
|
|
|||
|
if (!yieldFn) {
|
|||
|
throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
|
|||
|
}
|
|||
|
|
|||
|
return yieldFn.apply(thisValue, slice(arguments, 1));
|
|||
|
},
|
|||
|
|
|||
|
yieldTo: function(prop) {
|
|||
|
return this.yieldToOn.apply(this, concat([prop, null], slice(arguments, 1)));
|
|||
|
},
|
|||
|
|
|||
|
yieldToOn: function(prop, thisValue) {
|
|||
|
var args = slice(this.args);
|
|||
|
var yieldArg = filter(args, function(arg) {
|
|||
|
return arg && typeof arg[prop] === "function";
|
|||
|
})[0];
|
|||
|
var yieldFn = yieldArg && yieldArg[prop];
|
|||
|
|
|||
|
if (!yieldFn) {
|
|||
|
throwYieldError(
|
|||
|
this.proxy,
|
|||
|
" cannot yield to '" + valueToString(prop) + "' since no callback was passed.",
|
|||
|
args
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
return yieldFn.apply(thisValue, slice(arguments, 2));
|
|||
|
},
|
|||
|
|
|||
|
toString: function() {
|
|||
|
var callStr = this.proxy ? String(this.proxy) + "(" : "";
|
|||
|
var formattedArgs;
|
|||
|
|
|||
|
if (!this.args) {
|
|||
|
return ":(";
|
|||
|
}
|
|||
|
|
|||
|
formattedArgs = map(this.args, function(arg) {
|
|||
|
return sinonFormat(arg);
|
|||
|
});
|
|||
|
|
|||
|
callStr = callStr + join(formattedArgs, ", ") + ")";
|
|||
|
|
|||
|
if (typeof this.returnValue !== "undefined") {
|
|||
|
callStr += " => " + sinonFormat(this.returnValue);
|
|||
|
}
|
|||
|
|
|||
|
if (this.exception) {
|
|||
|
callStr += " !" + this.exception.name;
|
|||
|
|
|||
|
if (this.exception.message) {
|
|||
|
callStr += "(" + this.exception.message + ")";
|
|||
|
}
|
|||
|
}
|
|||
|
if (this.stack) {
|
|||
|
// Omit the error message and the two top stack frames in sinon itself:
|
|||
|
callStr += (this.stack.split("\n")[3] || "unknown").replace(/^\s*(?:at\s+|@)?/, " at ");
|
|||
|
}
|
|||
|
|
|||
|
return callStr;
|
|||
|
},
|
|||
|
|
|||
|
ensureArgIsAFunction: function(pos) {
|
|||
|
if (typeof this.args[pos] !== "function") {
|
|||
|
throw new TypeError(
|
|||
|
"Expected argument at position " + pos + " to be a Function, but was " + typeof this.args[pos]
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
Object.defineProperty(callProto, "stack", {
|
|||
|
enumerable: true,
|
|||
|
configurable: true,
|
|||
|
get: function() {
|
|||
|
return (this.errorWithCallStack && this.errorWithCallStack.stack) || "";
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
callProto.invokeCallback = callProto.yield;
|
|||
|
|
|||
|
function createProxyCall(proxy, thisValue, args, returnValue, exception, id, errorWithCallStack) {
|
|||
|
if (typeof id !== "number") {
|
|||
|
throw new TypeError("Call id is not a number");
|
|||
|
}
|
|||
|
|
|||
|
var firstArg, lastArg;
|
|||
|
|
|||
|
if (args.length > 0) {
|
|||
|
firstArg = args[0];
|
|||
|
lastArg = args[args.length - 1];
|
|||
|
}
|
|||
|
|
|||
|
var proxyCall = Object.create(callProto);
|
|||
|
var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined;
|
|||
|
|
|||
|
proxyCall.proxy = proxy;
|
|||
|
proxyCall.thisValue = thisValue;
|
|||
|
proxyCall.args = args;
|
|||
|
proxyCall.firstArg = firstArg;
|
|||
|
proxyCall.lastArg = lastArg;
|
|||
|
proxyCall.callback = callback;
|
|||
|
proxyCall.returnValue = returnValue;
|
|||
|
proxyCall.exception = exception;
|
|||
|
proxyCall.callId = id;
|
|||
|
proxyCall.errorWithCallStack = errorWithCallStack;
|
|||
|
|
|||
|
return proxyCall;
|
|||
|
}
|
|||
|
createProxyCall.toString = callProto.toString; // used by mocks
|
|||
|
|
|||
|
module.exports = createProxyCall;
|
|||
|
|
|||
|
},{"./util/core/format":25,"@sinonjs/commons":45,"@sinonjs/samsam":84}],14:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var proxyCallUtil = require("./proxy-call-util");
|
|||
|
|
|||
|
var push = arrayProto.push;
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var concat = arrayProto.concat;
|
|||
|
var ErrorConstructor = Error.prototype.constructor;
|
|||
|
var bind = Function.prototype.bind;
|
|||
|
|
|||
|
var callId = 0;
|
|||
|
|
|||
|
module.exports = function invoke(func, thisValue, args) {
|
|||
|
var matchings = this.matchingFakes(args);
|
|||
|
var currentCallId = callId++;
|
|||
|
var exception, returnValue;
|
|||
|
|
|||
|
proxyCallUtil.incrementCallCount(this);
|
|||
|
push(this.thisValues, thisValue);
|
|||
|
push(this.args, args);
|
|||
|
push(this.callIds, currentCallId);
|
|||
|
forEach(matchings, function(matching) {
|
|||
|
proxyCallUtil.incrementCallCount(matching);
|
|||
|
push(matching.thisValues, thisValue);
|
|||
|
push(matching.args, args);
|
|||
|
push(matching.callIds, currentCallId);
|
|||
|
});
|
|||
|
|
|||
|
// Make call properties available from within the spied function:
|
|||
|
proxyCallUtil.createCallProperties(this);
|
|||
|
forEach(matchings, proxyCallUtil.createCallProperties);
|
|||
|
|
|||
|
try {
|
|||
|
this.invoking = true;
|
|||
|
|
|||
|
var thisCall = this.getCall(this.callCount - 1);
|
|||
|
|
|||
|
if (thisCall.calledWithNew()) {
|
|||
|
// Call through with `new`
|
|||
|
returnValue = new (bind.apply(this.func || func, concat([thisValue], args)))();
|
|||
|
|
|||
|
if (typeof returnValue !== "object") {
|
|||
|
returnValue = thisValue;
|
|||
|
}
|
|||
|
} else {
|
|||
|
returnValue = (this.func || func).apply(thisValue, args);
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
exception = e;
|
|||
|
} finally {
|
|||
|
delete this.invoking;
|
|||
|
}
|
|||
|
|
|||
|
push(this.exceptions, exception);
|
|||
|
push(this.returnValues, returnValue);
|
|||
|
forEach(matchings, function(matching) {
|
|||
|
push(matching.exceptions, exception);
|
|||
|
push(matching.returnValues, returnValue);
|
|||
|
});
|
|||
|
|
|||
|
var err = new ErrorConstructor();
|
|||
|
// 1. Please do not get stack at this point. It may be so very slow, and not actually used
|
|||
|
// 2. PhantomJS does not serialize the stack trace until the error has been thrown:
|
|||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
|
|||
|
try {
|
|||
|
throw err;
|
|||
|
} catch (e) {
|
|||
|
/* empty */
|
|||
|
}
|
|||
|
push(this.errorsWithCallStack, err);
|
|||
|
forEach(matchings, function(matching) {
|
|||
|
push(matching.errorsWithCallStack, err);
|
|||
|
});
|
|||
|
|
|||
|
// Make return value and exception available in the calls:
|
|||
|
proxyCallUtil.createCallProperties(this);
|
|||
|
forEach(matchings, proxyCallUtil.createCallProperties);
|
|||
|
|
|||
|
if (exception !== undefined) {
|
|||
|
throw exception;
|
|||
|
}
|
|||
|
|
|||
|
return returnValue;
|
|||
|
};
|
|||
|
|
|||
|
},{"./proxy-call-util":12,"@sinonjs/commons":45}],15:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
var functionToString = require("./util/core/function-to-string");
|
|||
|
var proxyCall = require("./proxy-call");
|
|||
|
var proxyCallUtil = require("./proxy-call-util");
|
|||
|
var proxyInvoke = require("./proxy-invoke");
|
|||
|
var sinonFormat = require("./util/core/format");
|
|||
|
|
|||
|
var push = arrayProto.push;
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var slice = arrayProto.slice;
|
|||
|
|
|||
|
var emptyFakes = Object.freeze([]);
|
|||
|
|
|||
|
// Public API
|
|||
|
var proxyApi = {
|
|||
|
toString: functionToString,
|
|||
|
|
|||
|
named: function named(name) {
|
|||
|
this.displayName = name;
|
|||
|
var nameDescriptor = Object.getOwnPropertyDescriptor(this, "name");
|
|||
|
if (nameDescriptor && nameDescriptor.configurable) {
|
|||
|
// IE 11 functions don't have a name.
|
|||
|
// Safari 9 has names that are not configurable.
|
|||
|
nameDescriptor.value = name;
|
|||
|
Object.defineProperty(this, "name", nameDescriptor);
|
|||
|
}
|
|||
|
return this;
|
|||
|
},
|
|||
|
|
|||
|
invoke: proxyInvoke,
|
|||
|
|
|||
|
/*
|
|||
|
* Hook for derived implementation to return fake instances matching the
|
|||
|
* given arguments.
|
|||
|
*/
|
|||
|
matchingFakes: function(/*args, strict*/) {
|
|||
|
return emptyFakes;
|
|||
|
},
|
|||
|
|
|||
|
getCall: function getCall(index) {
|
|||
|
var i = index;
|
|||
|
if (i < 0) {
|
|||
|
// Negative indices means counting backwards from the last call
|
|||
|
i += this.callCount;
|
|||
|
}
|
|||
|
if (i < 0 || i >= this.callCount) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return proxyCall(
|
|||
|
this,
|
|||
|
this.thisValues[i],
|
|||
|
this.args[i],
|
|||
|
this.returnValues[i],
|
|||
|
this.exceptions[i],
|
|||
|
this.callIds[i],
|
|||
|
this.errorsWithCallStack[i]
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
getCalls: function() {
|
|||
|
var calls = [];
|
|||
|
var i;
|
|||
|
|
|||
|
for (i = 0; i < this.callCount; i++) {
|
|||
|
push(calls, this.getCall(i));
|
|||
|
}
|
|||
|
|
|||
|
return calls;
|
|||
|
},
|
|||
|
|
|||
|
calledBefore: function calledBefore(proxy) {
|
|||
|
if (!this.called) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (!proxy.called) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return this.callIds[0] < proxy.callIds[proxy.callIds.length - 1];
|
|||
|
},
|
|||
|
|
|||
|
calledAfter: function calledAfter(proxy) {
|
|||
|
if (!this.called || !proxy.called) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return this.callIds[this.callCount - 1] > proxy.callIds[0];
|
|||
|
},
|
|||
|
|
|||
|
calledImmediatelyBefore: function calledImmediatelyBefore(proxy) {
|
|||
|
if (!this.called || !proxy.called) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return this.callIds[this.callCount - 1] === proxy.callIds[proxy.callCount - 1] - 1;
|
|||
|
},
|
|||
|
|
|||
|
calledImmediatelyAfter: function calledImmediatelyAfter(proxy) {
|
|||
|
if (!this.called || !proxy.called) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return this.callIds[this.callCount - 1] === proxy.callIds[proxy.callCount - 1] + 1;
|
|||
|
},
|
|||
|
|
|||
|
formatters: require("./spy-formatters"),
|
|||
|
printf: function(format) {
|
|||
|
var spyInstance = this;
|
|||
|
var args = slice(arguments, 1);
|
|||
|
var formatter;
|
|||
|
|
|||
|
return (format || "").replace(/%(.)/g, function(match, specifyer) {
|
|||
|
formatter = proxyApi.formatters[specifyer];
|
|||
|
|
|||
|
if (typeof formatter === "function") {
|
|||
|
return String(formatter(spyInstance, args));
|
|||
|
} else if (!isNaN(parseInt(specifyer, 10))) {
|
|||
|
return sinonFormat(args[specifyer - 1]);
|
|||
|
}
|
|||
|
|
|||
|
return "%" + specifyer;
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
resetHistory: function() {
|
|||
|
if (this.invoking) {
|
|||
|
var err = new Error(
|
|||
|
"Cannot reset Sinon function while invoking it. " +
|
|||
|
"Move the call to .resetHistory outside of the callback."
|
|||
|
);
|
|||
|
err.name = "InvalidResetException";
|
|||
|
throw err;
|
|||
|
}
|
|||
|
|
|||
|
this.called = false;
|
|||
|
this.notCalled = true;
|
|||
|
this.calledOnce = false;
|
|||
|
this.calledTwice = false;
|
|||
|
this.calledThrice = false;
|
|||
|
this.callCount = 0;
|
|||
|
this.firstCall = null;
|
|||
|
this.secondCall = null;
|
|||
|
this.thirdCall = null;
|
|||
|
this.lastCall = null;
|
|||
|
this.args = [];
|
|||
|
this.firstArg = null;
|
|||
|
this.lastArg = null;
|
|||
|
this.returnValues = [];
|
|||
|
this.thisValues = [];
|
|||
|
this.exceptions = [];
|
|||
|
this.callIds = [];
|
|||
|
this.errorsWithCallStack = [];
|
|||
|
|
|||
|
if (this.fakes) {
|
|||
|
forEach(this.fakes, function(fake) {
|
|||
|
fake.resetHistory();
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
return this;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var delegateToCalls = proxyCallUtil.delegateToCalls;
|
|||
|
delegateToCalls(proxyApi, "calledOn", true);
|
|||
|
delegateToCalls(proxyApi, "alwaysCalledOn", false, "calledOn");
|
|||
|
delegateToCalls(proxyApi, "calledWith", true);
|
|||
|
delegateToCalls(proxyApi, "calledOnceWith", true, "calledWith", false, undefined, 1);
|
|||
|
delegateToCalls(proxyApi, "calledWithMatch", true);
|
|||
|
delegateToCalls(proxyApi, "alwaysCalledWith", false, "calledWith");
|
|||
|
delegateToCalls(proxyApi, "alwaysCalledWithMatch", false, "calledWithMatch");
|
|||
|
delegateToCalls(proxyApi, "calledWithExactly", true);
|
|||
|
delegateToCalls(proxyApi, "calledOnceWithExactly", true, "calledWithExactly", false, undefined, 1);
|
|||
|
delegateToCalls(proxyApi, "calledOnceWithMatch", true, "calledWithMatch", false, undefined, 1);
|
|||
|
delegateToCalls(proxyApi, "alwaysCalledWithExactly", false, "calledWithExactly");
|
|||
|
delegateToCalls(proxyApi, "neverCalledWith", false, "notCalledWith", false, function() {
|
|||
|
return true;
|
|||
|
});
|
|||
|
delegateToCalls(proxyApi, "neverCalledWithMatch", false, "notCalledWithMatch", false, function() {
|
|||
|
return true;
|
|||
|
});
|
|||
|
delegateToCalls(proxyApi, "threw", true);
|
|||
|
delegateToCalls(proxyApi, "alwaysThrew", false, "threw");
|
|||
|
delegateToCalls(proxyApi, "returned", true);
|
|||
|
delegateToCalls(proxyApi, "alwaysReturned", false, "returned");
|
|||
|
delegateToCalls(proxyApi, "calledWithNew", true);
|
|||
|
delegateToCalls(proxyApi, "alwaysCalledWithNew", false, "calledWithNew");
|
|||
|
|
|||
|
function createProxy(func, originalFunc) {
|
|||
|
var proxy = wrapFunction(func, originalFunc);
|
|||
|
|
|||
|
// Inherit function properties:
|
|||
|
extend(proxy, func);
|
|||
|
|
|||
|
proxy.prototype = func.prototype;
|
|||
|
|
|||
|
extend.nonEnum(proxy, proxyApi);
|
|||
|
|
|||
|
return proxy;
|
|||
|
}
|
|||
|
|
|||
|
function wrapFunction(func, originalFunc) {
|
|||
|
var arity = originalFunc.length;
|
|||
|
var p;
|
|||
|
// Do not change this to use an eval. Projects that depend on sinon block the use of eval.
|
|||
|
// ref: https://github.com/sinonjs/sinon/issues/710
|
|||
|
switch (arity) {
|
|||
|
/*eslint-disable no-unused-vars, max-len*/
|
|||
|
case 0:
|
|||
|
p = function proxy() {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
p = function proxy(a) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
p = function proxy(a, b) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
p = function proxy(a, b, c) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
p = function proxy(a, b, c, d) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
p = function proxy(a, b, c, d, e) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
p = function proxy(a, b, c, d, e, f) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
p = function proxy(a, b, c, d, e, f, g) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 8:
|
|||
|
p = function proxy(a, b, c, d, e, f, g, h) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 9:
|
|||
|
p = function proxy(a, b, c, d, e, f, g, h, i) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 10:
|
|||
|
p = function proxy(a, b, c, d, e, f, g, h, i, j) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 11:
|
|||
|
p = function proxy(a, b, c, d, e, f, g, h, i, j, k) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
case 12:
|
|||
|
p = function proxy(a, b, c, d, e, f, g, h, i, j, k, l) {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
default:
|
|||
|
p = function proxy() {
|
|||
|
return p.invoke(func, this, slice(arguments));
|
|||
|
};
|
|||
|
break;
|
|||
|
/*eslint-enable*/
|
|||
|
}
|
|||
|
var nameDescriptor = Object.getOwnPropertyDescriptor(originalFunc, "name");
|
|||
|
if (nameDescriptor && nameDescriptor.configurable) {
|
|||
|
// IE 11 functions don't have a name.
|
|||
|
// Safari 9 has names that are not configurable.
|
|||
|
Object.defineProperty(p, "name", nameDescriptor);
|
|||
|
}
|
|||
|
extend.nonEnum(p, {
|
|||
|
isSinonProxy: true,
|
|||
|
|
|||
|
called: false,
|
|||
|
notCalled: true,
|
|||
|
calledOnce: false,
|
|||
|
calledTwice: false,
|
|||
|
calledThrice: false,
|
|||
|
callCount: 0,
|
|||
|
firstCall: null,
|
|||
|
firstArg: null,
|
|||
|
secondCall: null,
|
|||
|
thirdCall: null,
|
|||
|
lastCall: null,
|
|||
|
lastArg: null,
|
|||
|
args: [],
|
|||
|
returnValues: [],
|
|||
|
thisValues: [],
|
|||
|
exceptions: [],
|
|||
|
callIds: [],
|
|||
|
errorsWithCallStack: []
|
|||
|
});
|
|||
|
return p;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = createProxy;
|
|||
|
|
|||
|
},{"./proxy-call":13,"./proxy-call-util":12,"./proxy-invoke":14,"./spy-formatters":18,"./util/core/extend":24,"./util/core/format":25,"./util/core/function-to-string":26,"@sinonjs/commons":45}],16:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var walkObject = require("./util/core/walk-object");
|
|||
|
|
|||
|
function filter(object, property) {
|
|||
|
return object[property].restore && object[property].restore.sinon;
|
|||
|
}
|
|||
|
|
|||
|
function restore(object, property) {
|
|||
|
object[property].restore();
|
|||
|
}
|
|||
|
|
|||
|
function restoreObject(object) {
|
|||
|
return walkObject(restore, object, filter);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = restoreObject;
|
|||
|
|
|||
|
},{"./util/core/walk-object":35}],17:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var collectOwnMethods = require("./collect-own-methods");
|
|||
|
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
|
|||
|
var isPropertyConfigurable = require("./util/core/is-property-configurable");
|
|||
|
var match = require("@sinonjs/samsam").createMatcher;
|
|||
|
var sinonAssert = require("./assert");
|
|||
|
var sinonClock = require("./util/fake-timers");
|
|||
|
var sinonMock = require("./mock");
|
|||
|
var sinonSpy = require("./spy");
|
|||
|
var sinonStub = require("./stub");
|
|||
|
var sinonFake = require("./fake");
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
var fakeServer = require("nise").fakeServer;
|
|||
|
var fakeXhr = require("nise").fakeXhr;
|
|||
|
var usePromiseLibrary = require("./util/core/use-promise-library");
|
|||
|
|
|||
|
var filter = arrayProto.filter;
|
|||
|
var forEach = arrayProto.filter;
|
|||
|
var push = arrayProto.push;
|
|||
|
var reverse = arrayProto.reverse;
|
|||
|
|
|||
|
function applyOnEach(fakes, method) {
|
|||
|
var matchingFakes = filter(fakes, function(fake) {
|
|||
|
return typeof fake[method] === "function";
|
|||
|
});
|
|||
|
|
|||
|
forEach(matchingFakes, function(fake) {
|
|||
|
fake[method]();
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function Sandbox() {
|
|||
|
var sandbox = this;
|
|||
|
var collection = [];
|
|||
|
var fakeRestorers = [];
|
|||
|
var promiseLib;
|
|||
|
|
|||
|
sandbox.serverPrototype = fakeServer;
|
|||
|
|
|||
|
// this is for testing only
|
|||
|
sandbox.getFakes = function getFakes() {
|
|||
|
return collection;
|
|||
|
};
|
|||
|
|
|||
|
// this is for testing only
|
|||
|
sandbox.getRestorers = function() {
|
|||
|
return fakeRestorers;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.createStubInstance = function createStubInstance() {
|
|||
|
var stubbed = sinonStub.createStubInstance.apply(null, arguments);
|
|||
|
|
|||
|
var ownMethods = collectOwnMethods(stubbed);
|
|||
|
|
|||
|
forEach(ownMethods, function(method) {
|
|||
|
push(collection, method);
|
|||
|
});
|
|||
|
|
|||
|
usePromiseLibrary(promiseLib, ownMethods);
|
|||
|
|
|||
|
return stubbed;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.inject = function inject(obj) {
|
|||
|
obj.spy = function() {
|
|||
|
return sandbox.spy.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.stub = function() {
|
|||
|
return sandbox.stub.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.mock = function() {
|
|||
|
return sandbox.mock.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.createStubInstance = function() {
|
|||
|
return sandbox.createStubInstance.apply(sandbox, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.fake = function() {
|
|||
|
return sandbox.fake.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.replace = function() {
|
|||
|
return sandbox.replace.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.replaceSetter = function() {
|
|||
|
return sandbox.replaceSetter.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
obj.replaceGetter = function() {
|
|||
|
return sandbox.replaceGetter.apply(null, arguments);
|
|||
|
};
|
|||
|
|
|||
|
if (sandbox.clock) {
|
|||
|
obj.clock = sandbox.clock;
|
|||
|
}
|
|||
|
|
|||
|
if (sandbox.server) {
|
|||
|
obj.server = sandbox.server;
|
|||
|
obj.requests = sandbox.server.requests;
|
|||
|
}
|
|||
|
|
|||
|
obj.match = match;
|
|||
|
|
|||
|
return obj;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.mock = function mock() {
|
|||
|
var m = sinonMock.apply(null, arguments);
|
|||
|
|
|||
|
push(collection, m);
|
|||
|
usePromiseLibrary(promiseLib, m);
|
|||
|
|
|||
|
return m;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.reset = function reset() {
|
|||
|
applyOnEach(collection, "reset");
|
|||
|
applyOnEach(collection, "resetHistory");
|
|||
|
};
|
|||
|
|
|||
|
sandbox.resetBehavior = function resetBehavior() {
|
|||
|
applyOnEach(collection, "resetBehavior");
|
|||
|
};
|
|||
|
|
|||
|
sandbox.resetHistory = function resetHistory() {
|
|||
|
function privateResetHistory(f) {
|
|||
|
var method = f.resetHistory || f.reset;
|
|||
|
if (method) {
|
|||
|
method.call(f);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
forEach(collection, function(fake) {
|
|||
|
if (typeof fake === "function") {
|
|||
|
privateResetHistory(fake);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var methods = [];
|
|||
|
if (fake.get) {
|
|||
|
push(methods, fake.get);
|
|||
|
}
|
|||
|
|
|||
|
if (fake.set) {
|
|||
|
push(methods, fake.set);
|
|||
|
}
|
|||
|
|
|||
|
forEach(methods, privateResetHistory);
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
sandbox.restore = function restore() {
|
|||
|
if (arguments.length) {
|
|||
|
throw new Error("sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()");
|
|||
|
}
|
|||
|
|
|||
|
reverse(collection);
|
|||
|
applyOnEach(collection, "restore");
|
|||
|
collection = [];
|
|||
|
|
|||
|
forEach(fakeRestorers, function(restorer) {
|
|||
|
restorer();
|
|||
|
});
|
|||
|
fakeRestorers = [];
|
|||
|
|
|||
|
sandbox.restoreContext();
|
|||
|
};
|
|||
|
|
|||
|
sandbox.restoreContext = function restoreContext() {
|
|||
|
var injectedKeys = sandbox.injectedKeys;
|
|||
|
var injectInto = sandbox.injectInto;
|
|||
|
|
|||
|
if (!injectedKeys) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
forEach(injectedKeys, function(injectedKey) {
|
|||
|
delete injectInto[injectedKey];
|
|||
|
});
|
|||
|
|
|||
|
injectedKeys = [];
|
|||
|
};
|
|||
|
|
|||
|
function getFakeRestorer(object, property) {
|
|||
|
var descriptor = getPropertyDescriptor(object, property);
|
|||
|
|
|||
|
function restorer() {
|
|||
|
if (descriptor.isOwn) {
|
|||
|
Object.defineProperty(object, property, descriptor);
|
|||
|
} else {
|
|||
|
delete object[property];
|
|||
|
}
|
|||
|
}
|
|||
|
restorer.object = object;
|
|||
|
restorer.property = property;
|
|||
|
return restorer;
|
|||
|
}
|
|||
|
|
|||
|
function verifyNotReplaced(object, property) {
|
|||
|
forEach(fakeRestorers, function(fakeRestorer) {
|
|||
|
if (fakeRestorer.object === object && fakeRestorer.property === property) {
|
|||
|
throw new TypeError("Attempted to replace " + property + " which is already replaced");
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
sandbox.replace = function replace(object, property, replacement) {
|
|||
|
var descriptor = getPropertyDescriptor(object, property);
|
|||
|
|
|||
|
if (typeof descriptor === "undefined") {
|
|||
|
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
|
|||
|
}
|
|||
|
|
|||
|
if (typeof replacement === "undefined") {
|
|||
|
throw new TypeError("Expected replacement argument to be defined");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof descriptor.get === "function") {
|
|||
|
throw new Error("Use sandbox.replaceGetter for replacing getters");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof descriptor.set === "function") {
|
|||
|
throw new Error("Use sandbox.replaceSetter for replacing setters");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof object[property] !== typeof replacement) {
|
|||
|
throw new TypeError("Cannot replace " + typeof object[property] + " with " + typeof replacement);
|
|||
|
}
|
|||
|
|
|||
|
verifyNotReplaced(object, property);
|
|||
|
|
|||
|
// store a function for restoring the replaced property
|
|||
|
push(fakeRestorers, getFakeRestorer(object, property));
|
|||
|
|
|||
|
object[property] = replacement;
|
|||
|
|
|||
|
return replacement;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.replaceGetter = function replaceGetter(object, property, replacement) {
|
|||
|
var descriptor = getPropertyDescriptor(object, property);
|
|||
|
|
|||
|
if (typeof descriptor === "undefined") {
|
|||
|
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
|
|||
|
}
|
|||
|
|
|||
|
if (typeof replacement !== "function") {
|
|||
|
throw new TypeError("Expected replacement argument to be a function");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof descriptor.get !== "function") {
|
|||
|
throw new Error("`object.property` is not a getter");
|
|||
|
}
|
|||
|
|
|||
|
verifyNotReplaced(object, property);
|
|||
|
|
|||
|
// store a function for restoring the replaced property
|
|||
|
push(fakeRestorers, getFakeRestorer(object, property));
|
|||
|
|
|||
|
Object.defineProperty(object, property, {
|
|||
|
get: replacement,
|
|||
|
configurable: isPropertyConfigurable(object, property)
|
|||
|
});
|
|||
|
|
|||
|
return replacement;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.replaceSetter = function replaceSetter(object, property, replacement) {
|
|||
|
var descriptor = getPropertyDescriptor(object, property);
|
|||
|
|
|||
|
if (typeof descriptor === "undefined") {
|
|||
|
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
|
|||
|
}
|
|||
|
|
|||
|
if (typeof replacement !== "function") {
|
|||
|
throw new TypeError("Expected replacement argument to be a function");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof descriptor.set !== "function") {
|
|||
|
throw new Error("`object.property` is not a setter");
|
|||
|
}
|
|||
|
|
|||
|
verifyNotReplaced(object, property);
|
|||
|
|
|||
|
// store a function for restoring the replaced property
|
|||
|
push(fakeRestorers, getFakeRestorer(object, property));
|
|||
|
|
|||
|
// eslint-disable-next-line accessor-pairs
|
|||
|
Object.defineProperty(object, property, {
|
|||
|
set: replacement,
|
|||
|
configurable: isPropertyConfigurable(object, property)
|
|||
|
});
|
|||
|
|
|||
|
return replacement;
|
|||
|
};
|
|||
|
|
|||
|
function commonPostInitSetup(args, spy) {
|
|||
|
var object = args[0];
|
|||
|
var property = args[1];
|
|||
|
|
|||
|
var isSpyingOnEntireObject = typeof property === "undefined" && typeof object === "object";
|
|||
|
|
|||
|
if (isSpyingOnEntireObject) {
|
|||
|
var ownMethods = collectOwnMethods(spy);
|
|||
|
|
|||
|
forEach(ownMethods, function(method) {
|
|||
|
push(collection, method);
|
|||
|
});
|
|||
|
|
|||
|
usePromiseLibrary(promiseLib, ownMethods);
|
|||
|
} else {
|
|||
|
push(collection, spy);
|
|||
|
usePromiseLibrary(promiseLib, spy);
|
|||
|
}
|
|||
|
|
|||
|
return spy;
|
|||
|
}
|
|||
|
|
|||
|
sandbox.spy = function spy() {
|
|||
|
var createdSpy = sinonSpy.apply(sinonSpy, arguments);
|
|||
|
return commonPostInitSetup(arguments, createdSpy);
|
|||
|
};
|
|||
|
|
|||
|
sandbox.stub = function stub() {
|
|||
|
var createdStub = sinonStub.apply(sinonStub, arguments);
|
|||
|
return commonPostInitSetup(arguments, createdStub);
|
|||
|
};
|
|||
|
|
|||
|
// eslint-disable-next-line no-unused-vars
|
|||
|
sandbox.fake = function fake(f) {
|
|||
|
var s = sinonFake.apply(sinonFake, arguments);
|
|||
|
|
|||
|
push(collection, s);
|
|||
|
|
|||
|
return s;
|
|||
|
};
|
|||
|
|
|||
|
forEach(Object.keys(sinonFake), function(key) {
|
|||
|
var fakeBehavior = sinonFake[key];
|
|||
|
if (typeof fakeBehavior === "function") {
|
|||
|
sandbox.fake[key] = function() {
|
|||
|
var s = fakeBehavior.apply(fakeBehavior, arguments);
|
|||
|
|
|||
|
push(collection, s);
|
|||
|
|
|||
|
return s;
|
|||
|
};
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
sandbox.useFakeTimers = function useFakeTimers(args) {
|
|||
|
var clock = sinonClock.useFakeTimers.call(null, args);
|
|||
|
|
|||
|
sandbox.clock = clock;
|
|||
|
push(collection, clock);
|
|||
|
|
|||
|
return clock;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.verify = function verify() {
|
|||
|
applyOnEach(collection, "verify");
|
|||
|
};
|
|||
|
|
|||
|
sandbox.verifyAndRestore = function verifyAndRestore() {
|
|||
|
var exception;
|
|||
|
|
|||
|
try {
|
|||
|
sandbox.verify();
|
|||
|
} catch (e) {
|
|||
|
exception = e;
|
|||
|
}
|
|||
|
|
|||
|
sandbox.restore();
|
|||
|
|
|||
|
if (exception) {
|
|||
|
throw exception;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
sandbox.useFakeServer = function useFakeServer() {
|
|||
|
var proto = sandbox.serverPrototype || fakeServer;
|
|||
|
|
|||
|
if (!proto || !proto.create) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
sandbox.server = proto.create();
|
|||
|
push(collection, sandbox.server);
|
|||
|
|
|||
|
return sandbox.server;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.useFakeXMLHttpRequest = function useFakeXMLHttpRequest() {
|
|||
|
var xhr = fakeXhr.useFakeXMLHttpRequest();
|
|||
|
push(collection, xhr);
|
|||
|
return xhr;
|
|||
|
};
|
|||
|
|
|||
|
sandbox.usingPromise = function usingPromise(promiseLibrary) {
|
|||
|
promiseLib = promiseLibrary;
|
|||
|
collection.promiseLibrary = promiseLibrary;
|
|||
|
|
|||
|
return sandbox;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
Sandbox.prototype.assert = sinonAssert;
|
|||
|
Sandbox.prototype.match = match;
|
|||
|
|
|||
|
module.exports = Sandbox;
|
|||
|
|
|||
|
},{"./assert":3,"./collect-own-methods":5,"./fake":9,"./mock":11,"./spy":19,"./stub":20,"./util/core/get-property-descriptor":28,"./util/core/is-property-configurable":31,"./util/core/use-promise-library":34,"./util/fake-timers":38,"@sinonjs/commons":45,"@sinonjs/samsam":84,"nise":103}],18:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var color = require("./color");
|
|||
|
var match = require("@sinonjs/samsam").createMatcher;
|
|||
|
var timesInWords = require("./util/core/times-in-words");
|
|||
|
var sinonFormat = require("./util/core/format");
|
|||
|
var jsDiff = require("diff");
|
|||
|
|
|||
|
var join = arrayProto.join;
|
|||
|
var map = arrayProto.map;
|
|||
|
var push = arrayProto.push;
|
|||
|
|
|||
|
function colorSinonMatchText(matcher, calledArg, calledArgMessage) {
|
|||
|
var calledArgumentMessage = calledArgMessage;
|
|||
|
if (!matcher.test(calledArg)) {
|
|||
|
matcher.message = color.red(matcher.message);
|
|||
|
if (calledArgumentMessage) {
|
|||
|
calledArgumentMessage = color.green(calledArgumentMessage);
|
|||
|
}
|
|||
|
}
|
|||
|
return calledArgumentMessage + " " + matcher.message;
|
|||
|
}
|
|||
|
|
|||
|
function colorDiffText(diff) {
|
|||
|
var objects = map(diff, function(part) {
|
|||
|
var text = part.value;
|
|||
|
if (part.added) {
|
|||
|
text = color.green(text);
|
|||
|
} else if (part.removed) {
|
|||
|
text = color.red(text);
|
|||
|
}
|
|||
|
if (diff.length === 2) {
|
|||
|
text += " "; // format simple diffs
|
|||
|
}
|
|||
|
return text;
|
|||
|
});
|
|||
|
return join(objects, "");
|
|||
|
}
|
|||
|
|
|||
|
module.exports = {
|
|||
|
c: function(spyInstance) {
|
|||
|
return timesInWords(spyInstance.callCount);
|
|||
|
},
|
|||
|
|
|||
|
n: function(spyInstance) {
|
|||
|
// eslint-disable-next-line local-rules/no-prototype-methods
|
|||
|
return spyInstance.toString();
|
|||
|
},
|
|||
|
|
|||
|
D: function(spyInstance, args) {
|
|||
|
var message = "";
|
|||
|
|
|||
|
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
|
|||
|
// describe multiple calls
|
|||
|
if (l > 1) {
|
|||
|
message += "\nCall " + (i + 1) + ":";
|
|||
|
}
|
|||
|
var calledArgs = spyInstance.getCall(i).args;
|
|||
|
for (var j = 0; j < calledArgs.length || j < args.length; ++j) {
|
|||
|
message += "\n";
|
|||
|
var calledArgMessage = j < calledArgs.length ? sinonFormat(calledArgs[j]) : "";
|
|||
|
if (match.isMatcher(args[j])) {
|
|||
|
message += colorSinonMatchText(args[j], calledArgs[j], calledArgMessage);
|
|||
|
} else {
|
|||
|
var expectedArgMessage = j < args.length ? sinonFormat(args[j]) : "";
|
|||
|
var diff = jsDiff.diffJson(calledArgMessage, expectedArgMessage);
|
|||
|
message += colorDiffText(diff);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return message;
|
|||
|
},
|
|||
|
|
|||
|
C: function(spyInstance) {
|
|||
|
var calls = [];
|
|||
|
|
|||
|
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
|
|||
|
// eslint-disable-next-line local-rules/no-prototype-methods
|
|||
|
var stringifiedCall = " " + spyInstance.getCall(i).toString();
|
|||
|
if (/\n/.test(calls[i - 1])) {
|
|||
|
stringifiedCall = "\n" + stringifiedCall;
|
|||
|
}
|
|||
|
push(calls, stringifiedCall);
|
|||
|
}
|
|||
|
|
|||
|
return calls.length > 0 ? "\n" + join(calls, "\n") : "";
|
|||
|
},
|
|||
|
|
|||
|
t: function(spyInstance) {
|
|||
|
var objects = [];
|
|||
|
|
|||
|
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
|
|||
|
push(objects, sinonFormat(spyInstance.thisValues[i]));
|
|||
|
}
|
|||
|
|
|||
|
return join(objects, ", ");
|
|||
|
},
|
|||
|
|
|||
|
"*": function(spyInstance, args) {
|
|||
|
return join(
|
|||
|
map(args, function(arg) {
|
|||
|
return sinonFormat(arg);
|
|||
|
}),
|
|||
|
", "
|
|||
|
);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
},{"./color":6,"./util/core/format":25,"./util/core/times-in-words":33,"@sinonjs/commons":45,"@sinonjs/samsam":84,"diff":88}],19:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var createProxy = require("./proxy");
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
|
|||
|
var deepEqual = require("@sinonjs/samsam").deepEqual;
|
|||
|
var isEsModule = require("./util/core/is-es-module");
|
|||
|
var proxyCallUtil = require("./proxy-call-util");
|
|||
|
var walkObject = require("./util/core/walk-object");
|
|||
|
var wrapMethod = require("./util/core/wrap-method");
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
/* cache references to library methods so that they also can be stubbed without problems */
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var pop = arrayProto.pop;
|
|||
|
var push = arrayProto.push;
|
|||
|
var slice = arrayProto.slice;
|
|||
|
var filter = Array.prototype.filter;
|
|||
|
|
|||
|
var uuid = 0;
|
|||
|
|
|||
|
function matches(fake, args, strict) {
|
|||
|
var margs = fake.matchingArguments;
|
|||
|
if (margs.length <= args.length && deepEqual(slice(args, 0, margs.length), margs)) {
|
|||
|
return !strict || margs.length === args.length;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
// Public API
|
|||
|
var spyApi = {
|
|||
|
withArgs: function() {
|
|||
|
var args = slice(arguments);
|
|||
|
var matching = pop(this.matchingFakes(args, true));
|
|||
|
if (matching) {
|
|||
|
return matching;
|
|||
|
}
|
|||
|
|
|||
|
var original = this;
|
|||
|
var fake = this.instantiateFake();
|
|||
|
fake.matchingArguments = args;
|
|||
|
fake.parent = this;
|
|||
|
push(this.fakes, fake);
|
|||
|
|
|||
|
fake.withArgs = function() {
|
|||
|
return original.withArgs.apply(original, arguments);
|
|||
|
};
|
|||
|
|
|||
|
forEach(original.args, function(arg, i) {
|
|||
|
if (!matches(fake, arg)) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
proxyCallUtil.incrementCallCount(fake);
|
|||
|
push(fake.thisValues, original.thisValues[i]);
|
|||
|
push(fake.args, arg);
|
|||
|
push(fake.returnValues, original.returnValues[i]);
|
|||
|
push(fake.exceptions, original.exceptions[i]);
|
|||
|
push(fake.callIds, original.callIds[i]);
|
|||
|
});
|
|||
|
|
|||
|
proxyCallUtil.createCallProperties(fake);
|
|||
|
|
|||
|
return fake;
|
|||
|
},
|
|||
|
|
|||
|
// Override proxy default implementation
|
|||
|
matchingFakes: function(args, strict) {
|
|||
|
return filter.call(this.fakes, function(fake) {
|
|||
|
return matches(fake, args, strict);
|
|||
|
});
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
/* eslint-disable local-rules/no-prototype-methods */
|
|||
|
var delegateToCalls = proxyCallUtil.delegateToCalls;
|
|||
|
delegateToCalls(spyApi, "callArg", false, "callArgWith", true, function() {
|
|||
|
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
|
|||
|
});
|
|||
|
spyApi.callArgWith = spyApi.callArg;
|
|||
|
delegateToCalls(spyApi, "callArgOn", false, "callArgOnWith", true, function() {
|
|||
|
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
|
|||
|
});
|
|||
|
spyApi.callArgOnWith = spyApi.callArgOn;
|
|||
|
delegateToCalls(spyApi, "throwArg", false, "throwArg", false, function() {
|
|||
|
throw new Error(this.toString() + " cannot throw arg since it was not yet invoked.");
|
|||
|
});
|
|||
|
delegateToCalls(spyApi, "yield", false, "yield", true, function() {
|
|||
|
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
|
|||
|
});
|
|||
|
// "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
|
|||
|
spyApi.invokeCallback = spyApi.yield;
|
|||
|
delegateToCalls(spyApi, "yieldOn", false, "yieldOn", true, function() {
|
|||
|
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
|
|||
|
});
|
|||
|
delegateToCalls(spyApi, "yieldTo", false, "yieldTo", true, function(property) {
|
|||
|
throw new Error(
|
|||
|
this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked."
|
|||
|
);
|
|||
|
});
|
|||
|
delegateToCalls(spyApi, "yieldToOn", false, "yieldToOn", true, function(property) {
|
|||
|
throw new Error(
|
|||
|
this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked."
|
|||
|
);
|
|||
|
});
|
|||
|
/* eslint-enable local-rules/no-prototype-methods */
|
|||
|
|
|||
|
function createSpy(func) {
|
|||
|
var name;
|
|||
|
var funk = func;
|
|||
|
|
|||
|
if (typeof funk !== "function") {
|
|||
|
funk = function() {
|
|||
|
return;
|
|||
|
};
|
|||
|
} else {
|
|||
|
name = functionName(funk);
|
|||
|
}
|
|||
|
|
|||
|
var proxy = createProxy(funk, funk);
|
|||
|
|
|||
|
// Inherit spy API:
|
|||
|
extend.nonEnum(proxy, spyApi);
|
|||
|
extend.nonEnum(proxy, {
|
|||
|
displayName: name || "spy",
|
|||
|
fakes: [],
|
|||
|
instantiateFake: createSpy,
|
|||
|
id: "spy#" + uuid++
|
|||
|
});
|
|||
|
return proxy;
|
|||
|
}
|
|||
|
|
|||
|
function spy(object, property, types) {
|
|||
|
var descriptor, methodDesc;
|
|||
|
|
|||
|
if (isEsModule(object)) {
|
|||
|
throw new TypeError("ES Modules cannot be spied");
|
|||
|
}
|
|||
|
|
|||
|
if (!property && typeof object === "function") {
|
|||
|
return createSpy(object);
|
|||
|
}
|
|||
|
|
|||
|
if (!property && typeof object === "object") {
|
|||
|
return walkObject(spy, object);
|
|||
|
}
|
|||
|
|
|||
|
if (!object && !property) {
|
|||
|
return createSpy(function() {
|
|||
|
return;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
if (!types) {
|
|||
|
return wrapMethod(object, property, createSpy(object[property]));
|
|||
|
}
|
|||
|
|
|||
|
descriptor = {};
|
|||
|
methodDesc = getPropertyDescriptor(object, property);
|
|||
|
|
|||
|
forEach(types, function(type) {
|
|||
|
descriptor[type] = createSpy(methodDesc[type]);
|
|||
|
});
|
|||
|
|
|||
|
return wrapMethod(object, property, descriptor);
|
|||
|
}
|
|||
|
|
|||
|
extend(spy, spyApi);
|
|||
|
module.exports = spy;
|
|||
|
|
|||
|
},{"./proxy":15,"./proxy-call-util":12,"./util/core/extend":24,"./util/core/get-property-descriptor":28,"./util/core/is-es-module":29,"./util/core/walk-object":35,"./util/core/wrap-method":37,"@sinonjs/commons":45,"@sinonjs/samsam":84}],20:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var behavior = require("./behavior");
|
|||
|
var behaviors = require("./default-behaviors");
|
|||
|
var createProxy = require("./proxy");
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
|||
|
var isNonExistentProperty = require("./util/core/is-non-existent-property");
|
|||
|
var spy = require("./spy");
|
|||
|
var extend = require("./util/core/extend");
|
|||
|
var getPropertyDescriptor = require("./util/core/get-property-descriptor");
|
|||
|
var isEsModule = require("./util/core/is-es-module");
|
|||
|
var wrapMethod = require("./util/core/wrap-method");
|
|||
|
var throwOnFalsyObject = require("./throw-on-falsy-object");
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
var walkObject = require("./util/core/walk-object");
|
|||
|
|
|||
|
var forEach = arrayProto.forEach;
|
|||
|
var pop = arrayProto.pop;
|
|||
|
var slice = arrayProto.slice;
|
|||
|
var sort = arrayProto.sort;
|
|||
|
|
|||
|
var uuid = 0;
|
|||
|
|
|||
|
function createStub(originalFunc) {
|
|||
|
var proxy;
|
|||
|
|
|||
|
function functionStub() {
|
|||
|
var args = slice(arguments);
|
|||
|
var matchings = proxy.matchingFakes(args);
|
|||
|
|
|||
|
var fnStub =
|
|||
|
pop(
|
|||
|
sort(matchings, function(a, b) {
|
|||
|
return a.matchingArguments.length - b.matchingArguments.length;
|
|||
|
})
|
|||
|
) || proxy;
|
|||
|
return getCurrentBehavior(fnStub).invoke(this, arguments);
|
|||
|
}
|
|||
|
|
|||
|
proxy = createProxy(functionStub, originalFunc || functionStub);
|
|||
|
// Inherit spy API:
|
|||
|
extend.nonEnum(proxy, spy);
|
|||
|
// Inherit stub API:
|
|||
|
extend.nonEnum(proxy, stub);
|
|||
|
|
|||
|
var name = originalFunc ? functionName(originalFunc) : null;
|
|||
|
extend.nonEnum(proxy, {
|
|||
|
fakes: [],
|
|||
|
instantiateFake: createStub,
|
|||
|
displayName: name || "stub",
|
|||
|
defaultBehavior: null,
|
|||
|
behaviors: [],
|
|||
|
id: "stub#" + uuid++
|
|||
|
});
|
|||
|
|
|||
|
return proxy;
|
|||
|
}
|
|||
|
|
|||
|
function stub(object, property) {
|
|||
|
if (arguments.length > 2) {
|
|||
|
throw new TypeError("stub(obj, 'meth', fn) has been removed, see documentation");
|
|||
|
}
|
|||
|
|
|||
|
if (isEsModule(object)) {
|
|||
|
throw new TypeError("ES Modules cannot be stubbed");
|
|||
|
}
|
|||
|
|
|||
|
throwOnFalsyObject.apply(null, arguments);
|
|||
|
|
|||
|
if (isNonExistentProperty(object, property)) {
|
|||
|
throw new TypeError("Cannot stub non-existent property " + valueToString(property));
|
|||
|
}
|
|||
|
|
|||
|
var actualDescriptor = getPropertyDescriptor(object, property);
|
|||
|
var isObjectOrFunction = typeof object === "object" || typeof object === "function";
|
|||
|
var isStubbingEntireObject = typeof property === "undefined" && isObjectOrFunction;
|
|||
|
var isCreatingNewStub = !object && typeof property === "undefined";
|
|||
|
var isStubbingNonFuncProperty =
|
|||
|
isObjectOrFunction &&
|
|||
|
typeof property !== "undefined" &&
|
|||
|
(typeof actualDescriptor === "undefined" || typeof actualDescriptor.value !== "function");
|
|||
|
|
|||
|
if (isStubbingEntireObject) {
|
|||
|
return walkObject(stub, object);
|
|||
|
}
|
|||
|
|
|||
|
if (isCreatingNewStub) {
|
|||
|
return createStub();
|
|||
|
}
|
|||
|
|
|||
|
var func = typeof actualDescriptor.value === "function" ? actualDescriptor.value : null;
|
|||
|
var s = createStub(func);
|
|||
|
|
|||
|
extend.nonEnum(s, {
|
|||
|
rootObj: object,
|
|||
|
propName: property,
|
|||
|
shadowsPropOnPrototype: !actualDescriptor.isOwn,
|
|||
|
restore: function restore() {
|
|||
|
if (actualDescriptor !== undefined && actualDescriptor.isOwn) {
|
|||
|
Object.defineProperty(object, property, actualDescriptor);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
delete object[property];
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return isStubbingNonFuncProperty ? s : wrapMethod(object, property, s);
|
|||
|
}
|
|||
|
|
|||
|
stub.createStubInstance = function(constructor, overrides) {
|
|||
|
if (typeof constructor !== "function") {
|
|||
|
throw new TypeError("The constructor should be a function.");
|
|||
|
}
|
|||
|
|
|||
|
var stubbedObject = stub(Object.create(constructor.prototype));
|
|||
|
|
|||
|
forEach(Object.keys(overrides || {}), function(propertyName) {
|
|||
|
if (propertyName in stubbedObject) {
|
|||
|
var value = overrides[propertyName];
|
|||
|
if (value && value.createStubInstance) {
|
|||
|
stubbedObject[propertyName] = value;
|
|||
|
} else {
|
|||
|
stubbedObject[propertyName].returns(value);
|
|||
|
}
|
|||
|
} else {
|
|||
|
throw new Error("Cannot stub " + propertyName + ". Property does not exist!");
|
|||
|
}
|
|||
|
});
|
|||
|
return stubbedObject;
|
|||
|
};
|
|||
|
|
|||
|
/*eslint-disable no-use-before-define*/
|
|||
|
function getParentBehaviour(stubInstance) {
|
|||
|
return stubInstance.parent && getCurrentBehavior(stubInstance.parent);
|
|||
|
}
|
|||
|
|
|||
|
function getDefaultBehavior(stubInstance) {
|
|||
|
return stubInstance.defaultBehavior || getParentBehaviour(stubInstance) || behavior.create(stubInstance);
|
|||
|
}
|
|||
|
|
|||
|
function getCurrentBehavior(stubInstance) {
|
|||
|
var currentBehavior = stubInstance.behaviors[stubInstance.callCount - 1];
|
|||
|
return currentBehavior && currentBehavior.isPresent() ? currentBehavior : getDefaultBehavior(stubInstance);
|
|||
|
}
|
|||
|
/*eslint-enable no-use-before-define*/
|
|||
|
|
|||
|
var proto = {
|
|||
|
resetBehavior: function() {
|
|||
|
this.defaultBehavior = null;
|
|||
|
this.behaviors = [];
|
|||
|
|
|||
|
delete this.returnValue;
|
|||
|
delete this.returnArgAt;
|
|||
|
delete this.throwArgAt;
|
|||
|
delete this.resolveArgAt;
|
|||
|
delete this.fakeFn;
|
|||
|
this.returnThis = false;
|
|||
|
this.resolveThis = false;
|
|||
|
|
|||
|
forEach(this.fakes, function(fake) {
|
|||
|
fake.resetBehavior();
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
reset: function() {
|
|||
|
this.resetHistory();
|
|||
|
this.resetBehavior();
|
|||
|
},
|
|||
|
|
|||
|
onCall: function onCall(index) {
|
|||
|
if (!this.behaviors[index]) {
|
|||
|
this.behaviors[index] = behavior.create(this);
|
|||
|
}
|
|||
|
|
|||
|
return this.behaviors[index];
|
|||
|
},
|
|||
|
|
|||
|
onFirstCall: function onFirstCall() {
|
|||
|
return this.onCall(0);
|
|||
|
},
|
|||
|
|
|||
|
onSecondCall: function onSecondCall() {
|
|||
|
return this.onCall(1);
|
|||
|
},
|
|||
|
|
|||
|
onThirdCall: function onThirdCall() {
|
|||
|
return this.onCall(2);
|
|||
|
},
|
|||
|
|
|||
|
withArgs: function withArgs() {
|
|||
|
var fake = spy.withArgs.apply(this, arguments);
|
|||
|
if (this.defaultBehavior && this.defaultBehavior.promiseLibrary) {
|
|||
|
fake.defaultBehavior = fake.defaultBehavior || behavior.create(fake);
|
|||
|
fake.defaultBehavior.promiseLibrary = this.defaultBehavior.promiseLibrary;
|
|||
|
}
|
|||
|
return fake;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
forEach(Object.keys(behavior), function(method) {
|
|||
|
if (
|
|||
|
hasOwnProperty(behavior, method) &&
|
|||
|
!hasOwnProperty(proto, method) &&
|
|||
|
method !== "create" &&
|
|||
|
method !== "invoke"
|
|||
|
) {
|
|||
|
proto[method] = behavior.createBehavior(method);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
forEach(Object.keys(behaviors), function(method) {
|
|||
|
if (hasOwnProperty(behaviors, method) && !hasOwnProperty(proto, method)) {
|
|||
|
behavior.addBehavior(stub, method, behaviors[method]);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
extend(stub, proto);
|
|||
|
module.exports = stub;
|
|||
|
|
|||
|
},{"./behavior":4,"./default-behaviors":8,"./proxy":15,"./spy":19,"./throw-on-falsy-object":21,"./util/core/extend":24,"./util/core/get-property-descriptor":28,"./util/core/is-es-module":29,"./util/core/is-non-existent-property":30,"./util/core/walk-object":35,"./util/core/wrap-method":37,"@sinonjs/commons":45}],21:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
function throwOnFalsyObject(object, property) {
|
|||
|
if (property && !object) {
|
|||
|
var type = object === null ? "null" : "undefined";
|
|||
|
throw new Error("Trying to stub property '" + valueToString(property) + "' of " + type);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = throwOnFalsyObject;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],22:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = {
|
|||
|
injectInto: null,
|
|||
|
properties: [
|
|||
|
"spy",
|
|||
|
"stub",
|
|||
|
"mock",
|
|||
|
"clock",
|
|||
|
"server",
|
|||
|
"requests",
|
|||
|
"fake",
|
|||
|
"replace",
|
|||
|
"replaceSetter",
|
|||
|
"replaceGetter",
|
|||
|
"createStubInstance"
|
|||
|
],
|
|||
|
useFakeTimers: true,
|
|||
|
useFakeServer: true
|
|||
|
};
|
|||
|
|
|||
|
},{}],23:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var reduce = arrayProto.reduce;
|
|||
|
|
|||
|
module.exports = function exportAsyncBehaviors(behaviorMethods) {
|
|||
|
return reduce(
|
|||
|
Object.keys(behaviorMethods),
|
|||
|
function(acc, method) {
|
|||
|
// need to avoid creating another async versions of the newly added async methods
|
|||
|
if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
|
|||
|
acc[method + "Async"] = function() {
|
|||
|
var result = behaviorMethods[method].apply(this, arguments);
|
|||
|
this.callbackAsync = true;
|
|||
|
return result;
|
|||
|
};
|
|||
|
}
|
|||
|
return acc;
|
|||
|
},
|
|||
|
{}
|
|||
|
);
|
|||
|
};
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],24:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var hasOwnProperty = require("@sinonjs/commons").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";
|
|||
|
})();
|
|||
|
|
|||
|
function extendCommon(target, sources, doCopy) {
|
|||
|
var source, i, prop;
|
|||
|
|
|||
|
for (i = 0; i < sources.length; i++) {
|
|||
|
source = sources[i];
|
|||
|
|
|||
|
for (prop in source) {
|
|||
|
if (hasOwnProperty(source, prop)) {
|
|||
|
doCopy(target, 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;
|
|||
|
}
|
|||
|
|
|||
|
/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
|
|||
|
* override properties in previous sources.
|
|||
|
*
|
|||
|
* @arg {Object} target - The Object to extend
|
|||
|
* @arg {Object[]} sources - Objects to copy properties from.
|
|||
|
*
|
|||
|
* @returns {Object} the extended target
|
|||
|
*/
|
|||
|
module.exports = function extend(target /*, sources */) {
|
|||
|
var sources = slice(arguments, 1);
|
|||
|
|
|||
|
return extendCommon(target, sources, function copyValue(dest, source, prop) {
|
|||
|
dest[prop] = source[prop];
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
|
|||
|
* override properties in previous sources. Define the properties as non enumerable.
|
|||
|
*
|
|||
|
* @arg {Object} target - The Object to extend
|
|||
|
* @arg {Object[]} sources - Objects to copy properties from.
|
|||
|
*
|
|||
|
* @returns {Object} the extended target
|
|||
|
*/
|
|||
|
module.exports.nonEnum = function extendNonEnum(target /*, sources */) {
|
|||
|
var sources = slice(arguments, 1);
|
|||
|
|
|||
|
return extendCommon(target, sources, function copyProperty(dest, source, prop) {
|
|||
|
Object.defineProperty(dest, prop, {
|
|||
|
value: source[prop],
|
|||
|
enumerable: false,
|
|||
|
configurable: true,
|
|||
|
writable: true
|
|||
|
});
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],25:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var formatio = require("@sinonjs/formatio");
|
|||
|
|
|||
|
var formatter = formatio.configure({
|
|||
|
quoteStrings: false,
|
|||
|
limitChildrenCount: 250
|
|||
|
});
|
|||
|
|
|||
|
var customFormatter;
|
|||
|
|
|||
|
function format() {
|
|||
|
if (customFormatter) {
|
|||
|
return customFormatter.apply(null, arguments);
|
|||
|
}
|
|||
|
|
|||
|
return formatter.ascii.apply(formatter, arguments);
|
|||
|
}
|
|||
|
|
|||
|
format.setFormatter = function(aCustomFormatter) {
|
|||
|
if (typeof aCustomFormatter !== "function") {
|
|||
|
throw new Error("format.setFormatter must be called with a function");
|
|||
|
}
|
|||
|
|
|||
|
customFormatter = aCustomFormatter;
|
|||
|
};
|
|||
|
|
|||
|
module.exports = format;
|
|||
|
|
|||
|
},{"@sinonjs/formatio":58}],26:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = function toString() {
|
|||
|
var i, prop, thisValue;
|
|||
|
if (this.getCall && this.callCount) {
|
|||
|
i = this.callCount;
|
|||
|
|
|||
|
while (i--) {
|
|||
|
thisValue = this.getCall(i).thisValue;
|
|||
|
|
|||
|
// eslint-disable-next-line guard-for-in
|
|||
|
for (prop in thisValue) {
|
|||
|
try {
|
|||
|
if (thisValue[prop] === this) {
|
|||
|
return prop;
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
// no-op - accessing props can throw an error, nothing to do here
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return this.displayName || "sinon fake";
|
|||
|
};
|
|||
|
|
|||
|
},{}],27:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/* istanbul ignore next : not testing that setTimeout works */
|
|||
|
function nextTick(callback) {
|
|||
|
setTimeout(callback, 0);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = function getNextTick(process, setImmediate) {
|
|||
|
if (typeof process === "object" && typeof process.nextTick === "function") {
|
|||
|
return process.nextTick;
|
|||
|
}
|
|||
|
|
|||
|
if (typeof setImmediate === "function") {
|
|||
|
return setImmediate;
|
|||
|
}
|
|||
|
|
|||
|
return nextTick;
|
|||
|
};
|
|||
|
|
|||
|
},{}],28:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = function getPropertyDescriptor(object, property) {
|
|||
|
var proto = object;
|
|||
|
var descriptor;
|
|||
|
var isOwn = Boolean(object && Object.getOwnPropertyDescriptor(object, property));
|
|||
|
|
|||
|
while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
|
|||
|
proto = Object.getPrototypeOf(proto);
|
|||
|
}
|
|||
|
|
|||
|
if (descriptor) {
|
|||
|
descriptor.isOwn = isOwn;
|
|||
|
}
|
|||
|
|
|||
|
return descriptor;
|
|||
|
};
|
|||
|
|
|||
|
},{}],29:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* 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.
|
|||
|
*
|
|||
|
* @param {Object} object The object to examine
|
|||
|
*
|
|||
|
* @returns {Boolean} true when the object is a module
|
|||
|
*/
|
|||
|
module.exports = function(object) {
|
|||
|
return (
|
|||
|
object && typeof Symbol !== "undefined" && object[Symbol.toStringTag] === "Module" && Object.isSealed(object)
|
|||
|
);
|
|||
|
};
|
|||
|
|
|||
|
},{}],30:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* @param {*} object
|
|||
|
* @param {String} property
|
|||
|
* @returns whether a prop exists in the prototype chain
|
|||
|
*/
|
|||
|
function isNonExistentProperty(object, property) {
|
|||
|
return object && typeof property !== "undefined" && !(property in object);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isNonExistentProperty;
|
|||
|
|
|||
|
},{}],31:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var getPropertyDescriptor = require("./get-property-descriptor");
|
|||
|
|
|||
|
function isPropertyConfigurable(obj, propName) {
|
|||
|
var propertyDescriptor = getPropertyDescriptor(obj, propName);
|
|||
|
|
|||
|
return propertyDescriptor ? propertyDescriptor.configurable : true;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isPropertyConfigurable;
|
|||
|
|
|||
|
},{"./get-property-descriptor":28}],32:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var globalObject = require("@sinonjs/commons").global;
|
|||
|
var getNextTick = require("./get-next-tick");
|
|||
|
|
|||
|
module.exports = getNextTick(globalObject.process, globalObject.setImmediate);
|
|||
|
|
|||
|
},{"./get-next-tick":27,"@sinonjs/commons":45}],33:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var array = [null, "once", "twice", "thrice"];
|
|||
|
|
|||
|
module.exports = function timesInWords(count) {
|
|||
|
return array[count] || (count || 0) + " times";
|
|||
|
};
|
|||
|
|
|||
|
},{}],34:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var forEach = Array.prototype.forEach;
|
|||
|
|
|||
|
function usePromiseLibrary(library, fakes) {
|
|||
|
if (typeof library === "undefined") {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (Array.isArray(fakes)) {
|
|||
|
forEach.call(fakes, usePromiseLibrary.bind(null, library));
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (typeof fakes.usingPromise === "function") {
|
|||
|
fakes.usingPromise(library);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = usePromiseLibrary;
|
|||
|
|
|||
|
},{}],35:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
|
|||
|
var getPropertyDescriptor = require("./get-property-descriptor");
|
|||
|
var walk = require("./walk");
|
|||
|
|
|||
|
function walkObject(predicate, object, filter) {
|
|||
|
var called = false;
|
|||
|
var name = functionName(predicate);
|
|||
|
|
|||
|
if (!object) {
|
|||
|
throw new Error("Trying to " + name + " object but received " + String(object));
|
|||
|
}
|
|||
|
|
|||
|
walk(object, function(prop, propOwner) {
|
|||
|
// we don't want to stub things like toString(), valueOf(), etc. so we only stub if the object
|
|||
|
// is not Object.prototype
|
|||
|
if (
|
|||
|
propOwner !== Object.prototype &&
|
|||
|
prop !== "constructor" &&
|
|||
|
typeof getPropertyDescriptor(propOwner, prop).value === "function"
|
|||
|
) {
|
|||
|
if (filter) {
|
|||
|
if (filter(object, prop)) {
|
|||
|
called = true;
|
|||
|
predicate(object, prop);
|
|||
|
}
|
|||
|
} else {
|
|||
|
called = true;
|
|||
|
predicate(object, prop);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
if (!called) {
|
|||
|
throw new Error("Expected to " + name + " methods on object but found none");
|
|||
|
}
|
|||
|
|
|||
|
return object;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = walkObject;
|
|||
|
|
|||
|
},{"./get-property-descriptor":28,"./walk":36,"@sinonjs/commons":45}],36:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var forEach = require("@sinonjs/commons").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(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.
|
|||
|
*/
|
|||
|
module.exports = function walk(obj, iterator, context) {
|
|||
|
return walkInternal(obj, iterator, context, obj, {});
|
|||
|
};
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],37:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var getPropertyDescriptor = require("./get-property-descriptor");
|
|||
|
var extend = require("./extend");
|
|||
|
var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty;
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
function isFunction(obj) {
|
|||
|
return typeof obj === "function" || Boolean(obj && obj.constructor && obj.call && obj.apply);
|
|||
|
}
|
|||
|
|
|||
|
function mirrorProperties(target, source) {
|
|||
|
for (var prop in source) {
|
|||
|
if (!hasOwnProperty(target, prop)) {
|
|||
|
target[prop] = source[prop];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Cheap way to detect if we have ES5 support.
|
|||
|
var hasES5Support = "keys" in Object;
|
|||
|
|
|||
|
module.exports = function wrapMethod(object, property, method) {
|
|||
|
if (!object) {
|
|||
|
throw new TypeError("Should wrap property of object");
|
|||
|
}
|
|||
|
|
|||
|
if (typeof method !== "function" && typeof method !== "object") {
|
|||
|
throw new TypeError("Method wrapper should be a function or a property descriptor");
|
|||
|
}
|
|||
|
|
|||
|
function checkWrappedMethod(wrappedMethod) {
|
|||
|
var error;
|
|||
|
|
|||
|
if (!isFunction(wrappedMethod)) {
|
|||
|
error = new TypeError(
|
|||
|
"Attempted to wrap " + typeof wrappedMethod + " property " + valueToString(property) + " as function"
|
|||
|
);
|
|||
|
} else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
|
|||
|
error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already wrapped");
|
|||
|
} else if (wrappedMethod.calledBefore) {
|
|||
|
var verb = wrappedMethod.returns ? "stubbed" : "spied on";
|
|||
|
error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already " + verb);
|
|||
|
}
|
|||
|
|
|||
|
if (error) {
|
|||
|
if (wrappedMethod && wrappedMethod.stackTraceError) {
|
|||
|
error.stack += "\n--------------\n" + wrappedMethod.stackTraceError.stack;
|
|||
|
}
|
|||
|
throw error;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var error, wrappedMethod, i, wrappedMethodDesc;
|
|||
|
|
|||
|
function simplePropertyAssignment() {
|
|||
|
wrappedMethod = object[property];
|
|||
|
checkWrappedMethod(wrappedMethod);
|
|||
|
object[property] = method;
|
|||
|
method.displayName = property;
|
|||
|
}
|
|||
|
|
|||
|
// Firefox has a problem when using hasOwn.call on objects from other frames.
|
|||
|
/* eslint-disable-next-line local-rules/no-prototype-methods */
|
|||
|
var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwnProperty(object, property);
|
|||
|
|
|||
|
if (hasES5Support) {
|
|||
|
var methodDesc = typeof method === "function" ? { value: method } : method;
|
|||
|
wrappedMethodDesc = getPropertyDescriptor(object, property);
|
|||
|
|
|||
|
if (!wrappedMethodDesc) {
|
|||
|
error = new TypeError(
|
|||
|
"Attempted to wrap " + typeof wrappedMethod + " property " + property + " as function"
|
|||
|
);
|
|||
|
} else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) {
|
|||
|
error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
|
|||
|
}
|
|||
|
if (error) {
|
|||
|
if (wrappedMethodDesc && wrappedMethodDesc.stackTraceError) {
|
|||
|
error.stack += "\n--------------\n" + wrappedMethodDesc.stackTraceError.stack;
|
|||
|
}
|
|||
|
throw error;
|
|||
|
}
|
|||
|
|
|||
|
var types = Object.keys(methodDesc);
|
|||
|
for (i = 0; i < types.length; i++) {
|
|||
|
wrappedMethod = wrappedMethodDesc[types[i]];
|
|||
|
checkWrappedMethod(wrappedMethod);
|
|||
|
}
|
|||
|
|
|||
|
mirrorProperties(methodDesc, wrappedMethodDesc);
|
|||
|
for (i = 0; i < types.length; i++) {
|
|||
|
mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]);
|
|||
|
}
|
|||
|
Object.defineProperty(object, property, methodDesc);
|
|||
|
|
|||
|
// catch failing assignment
|
|||
|
// this is the converse of the check in `.restore` below
|
|||
|
if (typeof method === "function" && object[property] !== method) {
|
|||
|
// correct any wrongdoings caused by the defineProperty call above,
|
|||
|
// such as adding new items (if object was a Storage object)
|
|||
|
delete object[property];
|
|||
|
simplePropertyAssignment();
|
|||
|
}
|
|||
|
} else {
|
|||
|
simplePropertyAssignment();
|
|||
|
}
|
|||
|
|
|||
|
extend.nonEnum(method, {
|
|||
|
displayName: property,
|
|||
|
|
|||
|
wrappedMethod: wrappedMethod,
|
|||
|
|
|||
|
// Set up an Error object for a stack trace which can be used later to find what line of
|
|||
|
// code the original method was created on.
|
|||
|
stackTraceError: new Error("Stack Trace for original"),
|
|||
|
|
|||
|
restore: function() {
|
|||
|
// For prototype properties try to reset by delete first.
|
|||
|
// If this fails (ex: localStorage on mobile safari) then force a reset
|
|||
|
// via direct assignment.
|
|||
|
if (!owned) {
|
|||
|
// In some cases `delete` may throw an error
|
|||
|
try {
|
|||
|
delete object[property];
|
|||
|
} catch (e) {} // eslint-disable-line no-empty
|
|||
|
// For native code functions `delete` fails without throwing an error
|
|||
|
// on Chrome < 43, PhantomJS, etc.
|
|||
|
} else if (hasES5Support) {
|
|||
|
Object.defineProperty(object, property, wrappedMethodDesc);
|
|||
|
}
|
|||
|
|
|||
|
if (hasES5Support) {
|
|||
|
var descriptor = getPropertyDescriptor(object, property);
|
|||
|
if (descriptor && descriptor.value === method) {
|
|||
|
object[property] = wrappedMethod;
|
|||
|
}
|
|||
|
} else {
|
|||
|
// Use strict equality comparison to check failures then force a reset
|
|||
|
// via direct assignment.
|
|||
|
if (object[property] === method) {
|
|||
|
object[property] = wrappedMethod;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
method.restore.sinon = true;
|
|||
|
|
|||
|
if (!hasES5Support) {
|
|||
|
mirrorProperties(method, wrappedMethod);
|
|||
|
}
|
|||
|
|
|||
|
return method;
|
|||
|
};
|
|||
|
|
|||
|
},{"./extend":24,"./get-property-descriptor":28,"@sinonjs/commons":45}],38:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var extend = require("./core/extend");
|
|||
|
var FakeTimers = require("@sinonjs/fake-timers");
|
|||
|
var globalObject = require("@sinonjs/commons").global;
|
|||
|
|
|||
|
function createClock(config, globalCtx) {
|
|||
|
var FakeTimersCtx = FakeTimers;
|
|||
|
if (globalCtx !== null && typeof globalCtx === "object") {
|
|||
|
FakeTimersCtx = FakeTimers.withGlobal(globalCtx);
|
|||
|
}
|
|||
|
var clock = FakeTimersCtx.install(config);
|
|||
|
clock.restore = clock.uninstall;
|
|||
|
return clock;
|
|||
|
}
|
|||
|
|
|||
|
function addIfDefined(obj, globalPropName) {
|
|||
|
var globalProp = globalObject[globalPropName];
|
|||
|
if (typeof globalProp !== "undefined") {
|
|||
|
obj[globalPropName] = globalProp;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number|Date|Object} dateOrConfig The unix epoch value to install with (default 0)
|
|||
|
* @returns {Object} Returns a lolex clock instance
|
|||
|
*/
|
|||
|
exports.useFakeTimers = function(dateOrConfig) {
|
|||
|
var hasArguments = typeof dateOrConfig !== "undefined";
|
|||
|
var argumentIsDateLike =
|
|||
|
(typeof dateOrConfig === "number" || dateOrConfig instanceof Date) && arguments.length === 1;
|
|||
|
var argumentIsObject = dateOrConfig !== null && typeof dateOrConfig === "object" && arguments.length === 1;
|
|||
|
|
|||
|
if (!hasArguments) {
|
|||
|
return createClock({
|
|||
|
now: 0
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
if (argumentIsDateLike) {
|
|||
|
return createClock({
|
|||
|
now: dateOrConfig
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
if (argumentIsObject) {
|
|||
|
var config = extend.nonEnum({}, dateOrConfig);
|
|||
|
var globalCtx = config.global;
|
|||
|
delete config.global;
|
|||
|
return createClock(config, globalCtx);
|
|||
|
}
|
|||
|
|
|||
|
throw new TypeError("useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon");
|
|||
|
};
|
|||
|
|
|||
|
exports.clock = {
|
|||
|
create: function(now) {
|
|||
|
return FakeTimers.createClock(now);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var timers = {
|
|||
|
setTimeout: setTimeout,
|
|||
|
clearTimeout: clearTimeout,
|
|||
|
setInterval: setInterval,
|
|||
|
clearInterval: clearInterval,
|
|||
|
Date: Date
|
|||
|
};
|
|||
|
addIfDefined(timers, "setImmediate");
|
|||
|
addIfDefined(timers, "clearImmediate");
|
|||
|
|
|||
|
exports.timers = timers;
|
|||
|
|
|||
|
},{"./core/extend":24,"@sinonjs/commons":45,"@sinonjs/fake-timers":57}],39:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var every = require("./prototypes/array").every;
|
|||
|
|
|||
|
/**
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function hasCallsLeft(callMap, spy) {
|
|||
|
if (callMap[spy.id] === undefined) {
|
|||
|
callMap[spy.id] = 0;
|
|||
|
}
|
|||
|
|
|||
|
return callMap[spy.id] < spy.callCount;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function checkAdjacentCalls(callMap, spy, index, spies) {
|
|||
|
var calledBeforeNext = true;
|
|||
|
|
|||
|
if (index !== spies.length - 1) {
|
|||
|
calledBeforeNext = spy.calledBefore(spies[index + 1]);
|
|||
|
}
|
|||
|
|
|||
|
if (hasCallsLeft(callMap, spy) && calledBeforeNext) {
|
|||
|
callMap[spy.id] += 1;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* A Sinon proxy object (fake, spy, stub)
|
|||
|
*
|
|||
|
* @typedef {object} SinonProxy
|
|||
|
* @property {Function} calledBefore - A method that determines if this proxy was called before another one
|
|||
|
* @property {string} id - Some id
|
|||
|
* @property {number} callCount - Number of times this proxy has been called
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* Returns true when the spies have been called in the order they were supplied in
|
|||
|
*
|
|||
|
* @param {SinonProxy[] | SinonProxy} spies An array of proxies, or several proxies as arguments
|
|||
|
* @returns {boolean} true when spies are called in order, false otherwise
|
|||
|
*/
|
|||
|
function calledInOrder(spies) {
|
|||
|
var callMap = {};
|
|||
|
// eslint-disable-next-line no-underscore-dangle
|
|||
|
var _spies = arguments.length > 1 ? arguments : spies;
|
|||
|
|
|||
|
return every(_spies, checkAdjacentCalls.bind(null, callMap));
|
|||
|
}
|
|||
|
|
|||
|
module.exports = calledInOrder;
|
|||
|
|
|||
|
},{"./prototypes/array":47}],40:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var functionName = require("./function-name");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns a display name for a value from a constructor
|
|||
|
*
|
|||
|
* @param {object} value A value to examine
|
|||
|
* @returns {(string|null)} A string or null
|
|||
|
*/
|
|||
|
function className(value) {
|
|||
|
return (
|
|||
|
(value.constructor && value.constructor.name) ||
|
|||
|
// The next branch is for IE11 support only:
|
|||
|
// Because the name property is not set on the prototype
|
|||
|
// of the Function object, we finally try to grab the
|
|||
|
// name from its definition. This will never be reached
|
|||
|
// in node, so we are not able to test this properly.
|
|||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
|
|||
|
(typeof value.constructor === "function" &&
|
|||
|
/* istanbul ignore next */
|
|||
|
functionName(value.constructor)) ||
|
|||
|
null
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = className;
|
|||
|
|
|||
|
},{"./function-name":43}],41:[function(require,module,exports){
|
|||
|
/* eslint-disable no-console */
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns a function that will invoke the supplied function and print a
|
|||
|
* deprecation warning to the console each time it is called.
|
|||
|
*
|
|||
|
* @param {Function} func
|
|||
|
* @param {string} msg
|
|||
|
* @returns {Function}
|
|||
|
*/
|
|||
|
exports.wrap = function(func, msg) {
|
|||
|
var wrapped = function() {
|
|||
|
exports.printWarning(msg);
|
|||
|
return func.apply(this, arguments);
|
|||
|
};
|
|||
|
if (func.prototype) {
|
|||
|
wrapped.prototype = func.prototype;
|
|||
|
}
|
|||
|
return wrapped;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Returns a string which can be supplied to `wrap()` to notify the user that a
|
|||
|
* particular part of the sinon API has been deprecated.
|
|||
|
*
|
|||
|
* @param {string} packageName
|
|||
|
* @param {string} funcName
|
|||
|
* @returns {string}
|
|||
|
*/
|
|||
|
exports.defaultMsg = function(packageName, funcName) {
|
|||
|
return (
|
|||
|
packageName +
|
|||
|
"." +
|
|||
|
funcName +
|
|||
|
" is deprecated and will be removed from the public API in a future version of " +
|
|||
|
packageName +
|
|||
|
"."
|
|||
|
);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Prints a warning on the console, when it exists
|
|||
|
*
|
|||
|
* @param {string} msg
|
|||
|
* @returns {undefined}
|
|||
|
*/
|
|||
|
exports.printWarning = function(msg) {
|
|||
|
/* istanbul ignore next */
|
|||
|
if (typeof process === "object" && process.emitWarning) {
|
|||
|
// Emit Warnings in Node
|
|||
|
process.emitWarning(msg);
|
|||
|
} else if (console.info) {
|
|||
|
console.info(msg);
|
|||
|
} else {
|
|||
|
console.log(msg);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
},{}],42:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns true when fn returns true for all members of obj.
|
|||
|
* This is an every implementation that works for all iterables
|
|||
|
*
|
|||
|
* @param {object} obj
|
|||
|
* @param {Function} fn
|
|||
|
* @returns {boolean}
|
|||
|
*/
|
|||
|
module.exports = 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;
|
|||
|
};
|
|||
|
|
|||
|
},{}],43:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns a display name for a function
|
|||
|
*
|
|||
|
* @param {Function} func
|
|||
|
* @returns {string}
|
|||
|
*/
|
|||
|
module.exports = function functionName(func) {
|
|||
|
if (!func) {
|
|||
|
return "";
|
|||
|
}
|
|||
|
|
|||
|
try {
|
|||
|
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]
|
|||
|
);
|
|||
|
} catch (e) {
|
|||
|
// Stringify may fail and we might get an exception, as a last-last
|
|||
|
// resort fall back to empty string.
|
|||
|
return "";
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
},{}],44:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* A reference to the global object
|
|||
|
*
|
|||
|
* @type {object} globalObject
|
|||
|
*/
|
|||
|
var globalObject;
|
|||
|
|
|||
|
/* istanbul ignore else */
|
|||
|
if (typeof global !== "undefined") {
|
|||
|
// Node
|
|||
|
globalObject = global;
|
|||
|
} else if (typeof window !== "undefined") {
|
|||
|
// Browser
|
|||
|
globalObject = window;
|
|||
|
} else {
|
|||
|
// WebWorker
|
|||
|
globalObject = self;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = globalObject;
|
|||
|
|
|||
|
},{}],45:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = {
|
|||
|
global: require("./global"),
|
|||
|
calledInOrder: require("./called-in-order"),
|
|||
|
className: require("./class-name"),
|
|||
|
deprecated: require("./deprecated"),
|
|||
|
every: require("./every"),
|
|||
|
functionName: require("./function-name"),
|
|||
|
orderByFirstCall: require("./order-by-first-call"),
|
|||
|
prototypes: require("./prototypes"),
|
|||
|
typeOf: require("./type-of"),
|
|||
|
valueToString: require("./value-to-string")
|
|||
|
};
|
|||
|
|
|||
|
},{"./called-in-order":39,"./class-name":40,"./deprecated":41,"./every":42,"./function-name":43,"./global":44,"./order-by-first-call":46,"./prototypes":50,"./type-of":55,"./value-to-string":56}],46:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var sort = require("./prototypes/array").sort;
|
|||
|
var slice = require("./prototypes/array").slice;
|
|||
|
|
|||
|
/**
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function comparator(a, b) {
|
|||
|
// uuid, won't ever be equal
|
|||
|
var aCall = a.getCall(0);
|
|||
|
var bCall = b.getCall(0);
|
|||
|
var aId = (aCall && aCall.callId) || -1;
|
|||
|
var bId = (bCall && bCall.callId) || -1;
|
|||
|
|
|||
|
return aId < bId ? -1 : 1;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* A Sinon proxy object (fake, spy, stub)
|
|||
|
*
|
|||
|
* @typedef {object} SinonProxy
|
|||
|
* @property {Function} getCall - A method that can return the first call
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* Sorts an array of SinonProxy instances (fake, spy, stub) by their first call
|
|||
|
*
|
|||
|
* @param {SinonProxy[] | SinonProxy} spies
|
|||
|
* @returns {SinonProxy[]}
|
|||
|
*/
|
|||
|
function orderByFirstCall(spies) {
|
|||
|
return sort(slice(spies), comparator);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = orderByFirstCall;
|
|||
|
|
|||
|
},{"./prototypes/array":47}],47:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var copyPrototype = require("./copy-prototype");
|
|||
|
|
|||
|
module.exports = copyPrototype(Array.prototype);
|
|||
|
|
|||
|
},{"./copy-prototype":48}],48:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var call = Function.call;
|
|||
|
|
|||
|
module.exports = 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));
|
|||
|
};
|
|||
|
|
|||
|
},{}],49:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var copyPrototype = require("./copy-prototype");
|
|||
|
|
|||
|
module.exports = copyPrototype(Function.prototype);
|
|||
|
|
|||
|
},{"./copy-prototype":48}],50:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = {
|
|||
|
array: require("./array"),
|
|||
|
function: require("./function"),
|
|||
|
map: require("./map"),
|
|||
|
object: require("./object"),
|
|||
|
set: require("./set"),
|
|||
|
string: require("./string")
|
|||
|
};
|
|||
|
|
|||
|
},{"./array":47,"./function":49,"./map":51,"./object":52,"./set":53,"./string":54}],51:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var copyPrototype = require("./copy-prototype");
|
|||
|
|
|||
|
module.exports = copyPrototype(Map.prototype);
|
|||
|
|
|||
|
},{"./copy-prototype":48}],52:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var copyPrototype = require("./copy-prototype");
|
|||
|
|
|||
|
module.exports = copyPrototype(Object.prototype);
|
|||
|
|
|||
|
},{"./copy-prototype":48}],53:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var copyPrototype = require("./copy-prototype");
|
|||
|
|
|||
|
module.exports = copyPrototype(Set.prototype);
|
|||
|
|
|||
|
},{"./copy-prototype":48}],54:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var copyPrototype = require("./copy-prototype");
|
|||
|
|
|||
|
module.exports = copyPrototype(String.prototype);
|
|||
|
|
|||
|
},{"./copy-prototype":48}],55:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var type = require("type-detect");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the lower-case result of running type from type-detect on the value
|
|||
|
*
|
|||
|
* @param {*} value
|
|||
|
* @returns {string}
|
|||
|
*/
|
|||
|
module.exports = function typeOf(value) {
|
|||
|
return type(value).toLowerCase();
|
|||
|
};
|
|||
|
|
|||
|
},{"type-detect":106}],56:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns a string representation of the value
|
|||
|
*
|
|||
|
* @param {*} value
|
|||
|
* @returns {string}
|
|||
|
*/
|
|||
|
function valueToString(value) {
|
|||
|
if (value && value.toString) {
|
|||
|
/* eslint-disable-next-line local-rules/no-prototype-methods */
|
|||
|
return value.toString();
|
|||
|
}
|
|||
|
return String(value);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = valueToString;
|
|||
|
|
|||
|
},{}],57:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var globalObject = require("@sinonjs/commons").global;
|
|||
|
|
|||
|
// eslint-disable-next-line complexity
|
|||
|
function withGlobal(_global) {
|
|||
|
var userAgent = _global.navigator && _global.navigator.userAgent;
|
|||
|
var isRunningInIE = userAgent && userAgent.indexOf("MSIE ") > -1;
|
|||
|
var maxTimeout = Math.pow(2, 31) - 1; //see https://heycam.github.io/webidl/#abstract-opdef-converttoint
|
|||
|
var NOOP = function() {
|
|||
|
return undefined;
|
|||
|
};
|
|||
|
var NOOP_ARRAY = function() {
|
|||
|
return [];
|
|||
|
};
|
|||
|
var timeoutResult = _global.setTimeout(NOOP, 0);
|
|||
|
var addTimerReturnsObject = typeof timeoutResult === "object";
|
|||
|
var hrtimePresent =
|
|||
|
_global.process && typeof _global.process.hrtime === "function";
|
|||
|
var hrtimeBigintPresent =
|
|||
|
hrtimePresent && typeof _global.process.hrtime.bigint === "function";
|
|||
|
var nextTickPresent =
|
|||
|
_global.process && typeof _global.process.nextTick === "function";
|
|||
|
var utilPromisify = _global.process && require("util").promisify;
|
|||
|
var performancePresent =
|
|||
|
_global.performance && typeof _global.performance.now === "function";
|
|||
|
var hasPerformancePrototype =
|
|||
|
_global.Performance &&
|
|||
|
(typeof _global.Performance).match(/^(function|object)$/);
|
|||
|
var queueMicrotaskPresent = _global.hasOwnProperty("queueMicrotask");
|
|||
|
var requestAnimationFramePresent =
|
|||
|
_global.requestAnimationFrame &&
|
|||
|
typeof _global.requestAnimationFrame === "function";
|
|||
|
var cancelAnimationFramePresent =
|
|||
|
_global.cancelAnimationFrame &&
|
|||
|
typeof _global.cancelAnimationFrame === "function";
|
|||
|
var requestIdleCallbackPresent =
|
|||
|
_global.requestIdleCallback &&
|
|||
|
typeof _global.requestIdleCallback === "function";
|
|||
|
var cancelIdleCallbackPresent =
|
|||
|
_global.cancelIdleCallback &&
|
|||
|
typeof _global.cancelIdleCallback === "function";
|
|||
|
var setImmediatePresent =
|
|||
|
_global.setImmediate && typeof _global.setImmediate === "function";
|
|||
|
|
|||
|
// Make properties writable in IE, as per
|
|||
|
// http://www.adequatelygood.com/Replacing-setTimeout-Globally.html
|
|||
|
/* eslint-disable no-self-assign */
|
|||
|
if (isRunningInIE) {
|
|||
|
_global.setTimeout = _global.setTimeout;
|
|||
|
_global.clearTimeout = _global.clearTimeout;
|
|||
|
_global.setInterval = _global.setInterval;
|
|||
|
_global.clearInterval = _global.clearInterval;
|
|||
|
_global.Date = _global.Date;
|
|||
|
}
|
|||
|
|
|||
|
// setImmediate is not a standard function
|
|||
|
// avoid adding the prop to the window object if not present
|
|||
|
if (setImmediatePresent) {
|
|||
|
_global.setImmediate = _global.setImmediate;
|
|||
|
_global.clearImmediate = _global.clearImmediate;
|
|||
|
}
|
|||
|
/* eslint-enable no-self-assign */
|
|||
|
|
|||
|
_global.clearTimeout(timeoutResult);
|
|||
|
|
|||
|
var NativeDate = _global.Date;
|
|||
|
var uniqueTimerId = 1;
|
|||
|
|
|||
|
function isNumberFinite(num) {
|
|||
|
if (Number.isFinite) {
|
|||
|
return Number.isFinite(num);
|
|||
|
}
|
|||
|
|
|||
|
if (typeof num !== "number") {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return isFinite(num);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Parse strings like "01:10:00" (meaning 1 hour, 10 minutes, 0 seconds) into
|
|||
|
* number of milliseconds. This is used to support human-readable strings passed
|
|||
|
* to clock.tick()
|
|||
|
*/
|
|||
|
function parseTime(str) {
|
|||
|
if (!str) {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
var strings = str.split(":");
|
|||
|
var l = strings.length;
|
|||
|
var i = l;
|
|||
|
var ms = 0;
|
|||
|
var parsed;
|
|||
|
|
|||
|
if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
|
|||
|
throw new Error(
|
|||
|
"tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
while (i--) {
|
|||
|
parsed = parseInt(strings[i], 10);
|
|||
|
|
|||
|
if (parsed >= 60) {
|
|||
|
throw new Error("Invalid time " + str);
|
|||
|
}
|
|||
|
|
|||
|
ms += parsed * Math.pow(60, l - i - 1);
|
|||
|
}
|
|||
|
|
|||
|
return ms * 1000;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Get the decimal part of the millisecond value as nanoseconds
|
|||
|
*
|
|||
|
* @param {Number} msFloat the number of milliseconds
|
|||
|
* @returns {Number} an integer number of nanoseconds in the range [0,1e6)
|
|||
|
*
|
|||
|
* Example: nanoRemainer(123.456789) -> 456789
|
|||
|
*/
|
|||
|
function nanoRemainder(msFloat) {
|
|||
|
var modulo = 1e6;
|
|||
|
var remainder = (msFloat * 1e6) % modulo;
|
|||
|
var positiveRemainder = remainder < 0 ? remainder + modulo : remainder;
|
|||
|
|
|||
|
return Math.floor(positiveRemainder);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Used to grok the `now` parameter to createClock.
|
|||
|
* @param epoch {Date|number} the system time
|
|||
|
*/
|
|||
|
function getEpoch(epoch) {
|
|||
|
if (!epoch) {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
if (typeof epoch.getTime === "function") {
|
|||
|
return epoch.getTime();
|
|||
|
}
|
|||
|
if (typeof epoch === "number") {
|
|||
|
return epoch;
|
|||
|
}
|
|||
|
throw new TypeError("now should be milliseconds since UNIX epoch");
|
|||
|
}
|
|||
|
|
|||
|
function inRange(from, to, timer) {
|
|||
|
return timer && timer.callAt >= from && timer.callAt <= to;
|
|||
|
}
|
|||
|
|
|||
|
function mirrorDateProperties(target, source) {
|
|||
|
var prop;
|
|||
|
for (prop in source) {
|
|||
|
if (source.hasOwnProperty(prop)) {
|
|||
|
target[prop] = source[prop];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// set special now implementation
|
|||
|
if (source.now) {
|
|||
|
target.now = function now() {
|
|||
|
return target.clock.now;
|
|||
|
};
|
|||
|
} else {
|
|||
|
delete target.now;
|
|||
|
}
|
|||
|
|
|||
|
// set special toSource implementation
|
|||
|
if (source.toSource) {
|
|||
|
target.toSource = function toSource() {
|
|||
|
return source.toSource();
|
|||
|
};
|
|||
|
} else {
|
|||
|
delete target.toSource;
|
|||
|
}
|
|||
|
|
|||
|
// set special toString implementation
|
|||
|
target.toString = function toString() {
|
|||
|
return source.toString();
|
|||
|
};
|
|||
|
|
|||
|
target.prototype = source.prototype;
|
|||
|
target.parse = source.parse;
|
|||
|
target.UTC = source.UTC;
|
|||
|
target.prototype.toUTCString = source.prototype.toUTCString;
|
|||
|
|
|||
|
return target;
|
|||
|
}
|
|||
|
|
|||
|
function createDate() {
|
|||
|
function ClockDate(year, month, date, hour, minute, second, ms) {
|
|||
|
// the Date constructor called as a function, ref Ecma-262 Edition 5.1, section 15.9.2.
|
|||
|
// This remains so in the 10th edition of 2019 as well.
|
|||
|
if (!(this instanceof ClockDate)) {
|
|||
|
return new NativeDate(ClockDate.clock.now).toString();
|
|||
|
}
|
|||
|
|
|||
|
// if Date is called as a constructor with 'new' keyword
|
|||
|
// Defensive and verbose to avoid potential harm in passing
|
|||
|
// explicit undefined when user does not pass argument
|
|||
|
switch (arguments.length) {
|
|||
|
case 0:
|
|||
|
return new NativeDate(ClockDate.clock.now);
|
|||
|
case 1:
|
|||
|
return new NativeDate(year);
|
|||
|
case 2:
|
|||
|
return new NativeDate(year, month);
|
|||
|
case 3:
|
|||
|
return new NativeDate(year, month, date);
|
|||
|
case 4:
|
|||
|
return new NativeDate(year, month, date, hour);
|
|||
|
case 5:
|
|||
|
return new NativeDate(year, month, date, hour, minute);
|
|||
|
case 6:
|
|||
|
return new NativeDate(
|
|||
|
year,
|
|||
|
month,
|
|||
|
date,
|
|||
|
hour,
|
|||
|
minute,
|
|||
|
second
|
|||
|
);
|
|||
|
default:
|
|||
|
return new NativeDate(
|
|||
|
year,
|
|||
|
month,
|
|||
|
date,
|
|||
|
hour,
|
|||
|
minute,
|
|||
|
second,
|
|||
|
ms
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return mirrorDateProperties(ClockDate, NativeDate);
|
|||
|
}
|
|||
|
|
|||
|
function enqueueJob(clock, job) {
|
|||
|
// enqueues a microtick-deferred task - ecma262/#sec-enqueuejob
|
|||
|
if (!clock.jobs) {
|
|||
|
clock.jobs = [];
|
|||
|
}
|
|||
|
clock.jobs.push(job);
|
|||
|
}
|
|||
|
|
|||
|
function runJobs(clock) {
|
|||
|
// runs all microtick-deferred tasks - ecma262/#sec-runjobs
|
|||
|
if (!clock.jobs) {
|
|||
|
return;
|
|||
|
}
|
|||
|
for (var i = 0; i < clock.jobs.length; i++) {
|
|||
|
var job = clock.jobs[i];
|
|||
|
job.func.apply(null, job.args);
|
|||
|
if (clock.loopLimit && i > clock.loopLimit) {
|
|||
|
throw new Error(
|
|||
|
"Aborting after running " +
|
|||
|
clock.loopLimit +
|
|||
|
" timers, assuming an infinite loop!"
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
clock.jobs = [];
|
|||
|
}
|
|||
|
|
|||
|
function addTimer(clock, timer) {
|
|||
|
if (timer.func === undefined) {
|
|||
|
throw new Error("Callback must be provided to timer calls");
|
|||
|
}
|
|||
|
|
|||
|
timer.type = timer.immediate ? "Immediate" : "Timeout";
|
|||
|
|
|||
|
if (timer.hasOwnProperty("delay")) {
|
|||
|
if (!isNumberFinite(timer.delay)) {
|
|||
|
timer.delay = 0;
|
|||
|
}
|
|||
|
timer.delay = timer.delay > maxTimeout ? 1 : timer.delay;
|
|||
|
timer.delay = Math.max(0, timer.delay);
|
|||
|
}
|
|||
|
|
|||
|
if (timer.hasOwnProperty("interval")) {
|
|||
|
timer.type = "Interval";
|
|||
|
timer.interval = timer.interval > maxTimeout ? 1 : timer.interval;
|
|||
|
}
|
|||
|
|
|||
|
if (timer.hasOwnProperty("animation")) {
|
|||
|
timer.type = "AnimationFrame";
|
|||
|
timer.animation = true;
|
|||
|
}
|
|||
|
|
|||
|
if (!clock.timers) {
|
|||
|
clock.timers = {};
|
|||
|
}
|
|||
|
|
|||
|
timer.id = uniqueTimerId++;
|
|||
|
timer.createdAt = clock.now;
|
|||
|
timer.callAt =
|
|||
|
clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
|
|||
|
|
|||
|
clock.timers[timer.id] = timer;
|
|||
|
|
|||
|
if (addTimerReturnsObject) {
|
|||
|
var res = {
|
|||
|
id: timer.id,
|
|||
|
ref: function() {
|
|||
|
return res;
|
|||
|
},
|
|||
|
unref: function() {
|
|||
|
return res;
|
|||
|
},
|
|||
|
refresh: function() {
|
|||
|
return res;
|
|||
|
}
|
|||
|
};
|
|||
|
return res;
|
|||
|
}
|
|||
|
|
|||
|
return timer.id;
|
|||
|
}
|
|||
|
|
|||
|
/* eslint consistent-return: "off" */
|
|||
|
function compareTimers(a, b) {
|
|||
|
// Sort first by absolute timing
|
|||
|
if (a.callAt < b.callAt) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
if (a.callAt > b.callAt) {
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
// Sort next by immediate, immediate timers take precedence
|
|||
|
if (a.immediate && !b.immediate) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
if (!a.immediate && b.immediate) {
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
// Sort next by creation time, earlier-created timers take precedence
|
|||
|
if (a.createdAt < b.createdAt) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
if (a.createdAt > b.createdAt) {
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
// Sort next by id, lower-id timers take precedence
|
|||
|
if (a.id < b.id) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
if (a.id > b.id) {
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
// As timer ids are unique, no fallback `0` is necessary
|
|||
|
}
|
|||
|
|
|||
|
function firstTimerInRange(clock, from, to) {
|
|||
|
var timers = clock.timers;
|
|||
|
var timer = null;
|
|||
|
var id, isInRange;
|
|||
|
|
|||
|
for (id in timers) {
|
|||
|
if (timers.hasOwnProperty(id)) {
|
|||
|
isInRange = inRange(from, to, timers[id]);
|
|||
|
|
|||
|
if (
|
|||
|
isInRange &&
|
|||
|
(!timer || compareTimers(timer, timers[id]) === 1)
|
|||
|
) {
|
|||
|
timer = timers[id];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return timer;
|
|||
|
}
|
|||
|
|
|||
|
function firstTimer(clock) {
|
|||
|
var timers = clock.timers;
|
|||
|
var timer = null;
|
|||
|
var id;
|
|||
|
|
|||
|
for (id in timers) {
|
|||
|
if (timers.hasOwnProperty(id)) {
|
|||
|
if (!timer || compareTimers(timer, timers[id]) === 1) {
|
|||
|
timer = timers[id];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return timer;
|
|||
|
}
|
|||
|
|
|||
|
function lastTimer(clock) {
|
|||
|
var timers = clock.timers;
|
|||
|
var timer = null;
|
|||
|
var id;
|
|||
|
|
|||
|
for (id in timers) {
|
|||
|
if (timers.hasOwnProperty(id)) {
|
|||
|
if (!timer || compareTimers(timer, timers[id]) === -1) {
|
|||
|
timer = timers[id];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return timer;
|
|||
|
}
|
|||
|
|
|||
|
function callTimer(clock, timer) {
|
|||
|
if (typeof timer.interval === "number") {
|
|||
|
clock.timers[timer.id].callAt += timer.interval;
|
|||
|
} else {
|
|||
|
delete clock.timers[timer.id];
|
|||
|
}
|
|||
|
|
|||
|
if (typeof timer.func === "function") {
|
|||
|
timer.func.apply(null, timer.args);
|
|||
|
} else {
|
|||
|
/* eslint no-eval: "off" */
|
|||
|
eval(timer.func);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function clearTimer(clock, timerId, ttype) {
|
|||
|
if (!timerId) {
|
|||
|
// null appears to be allowed in most browsers, and appears to be
|
|||
|
// relied upon by some libraries, like Bootstrap carousel
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (!clock.timers) {
|
|||
|
clock.timers = {};
|
|||
|
}
|
|||
|
|
|||
|
// in Node, timerId is an object with .ref()/.unref(), and
|
|||
|
// its .id field is the actual timer id.
|
|||
|
var id = typeof timerId === "object" ? timerId.id : timerId;
|
|||
|
|
|||
|
if (clock.timers.hasOwnProperty(id)) {
|
|||
|
// check that the ID matches a timer of the correct type
|
|||
|
var timer = clock.timers[id];
|
|||
|
if (timer.type === ttype) {
|
|||
|
delete clock.timers[id];
|
|||
|
} else {
|
|||
|
var clear =
|
|||
|
ttype === "AnimationFrame"
|
|||
|
? "cancelAnimationFrame"
|
|||
|
: "clear" + ttype;
|
|||
|
var schedule =
|
|||
|
timer.type === "AnimationFrame"
|
|||
|
? "requestAnimationFrame"
|
|||
|
: "set" + timer.type;
|
|||
|
throw new Error(
|
|||
|
"Cannot clear timer: timer created with " +
|
|||
|
schedule +
|
|||
|
"() but cleared with " +
|
|||
|
clear +
|
|||
|
"()"
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function uninstall(clock, target, config) {
|
|||
|
var method, i, l;
|
|||
|
var installedHrTime = "_hrtime";
|
|||
|
var installedNextTick = "_nextTick";
|
|||
|
|
|||
|
for (i = 0, l = clock.methods.length; i < l; i++) {
|
|||
|
method = clock.methods[i];
|
|||
|
if (method === "hrtime" && target.process) {
|
|||
|
target.process.hrtime = clock[installedHrTime];
|
|||
|
} else if (method === "nextTick" && target.process) {
|
|||
|
target.process.nextTick = clock[installedNextTick];
|
|||
|
} else if (method === "performance") {
|
|||
|
var originalPerfDescriptor = Object.getOwnPropertyDescriptor(
|
|||
|
clock,
|
|||
|
"_" + method
|
|||
|
);
|
|||
|
if (
|
|||
|
originalPerfDescriptor &&
|
|||
|
originalPerfDescriptor.get &&
|
|||
|
!originalPerfDescriptor.set
|
|||
|
) {
|
|||
|
Object.defineProperty(
|
|||
|
target,
|
|||
|
method,
|
|||
|
originalPerfDescriptor
|
|||
|
);
|
|||
|
} else if (originalPerfDescriptor.configurable) {
|
|||
|
target[method] = clock["_" + method];
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (target[method] && target[method].hadOwnProperty) {
|
|||
|
target[method] = clock["_" + method];
|
|||
|
if (
|
|||
|
method === "clearInterval" &&
|
|||
|
config.shouldAdvanceTime === true
|
|||
|
) {
|
|||
|
target[method](clock.attachedInterval);
|
|||
|
}
|
|||
|
} else {
|
|||
|
try {
|
|||
|
delete target[method];
|
|||
|
} catch (ignore) {
|
|||
|
/* eslint no-empty: "off" */
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Prevent multiple executions which will completely remove these props
|
|||
|
clock.methods = [];
|
|||
|
|
|||
|
// return pending timers, to enable checking what timers remained on uninstall
|
|||
|
if (!clock.timers) {
|
|||
|
return [];
|
|||
|
}
|
|||
|
return Object.keys(clock.timers).map(function mapper(key) {
|
|||
|
return clock.timers[key];
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function hijackMethod(target, method, clock) {
|
|||
|
var prop;
|
|||
|
clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(
|
|||
|
target,
|
|||
|
method
|
|||
|
);
|
|||
|
clock["_" + method] = target[method];
|
|||
|
|
|||
|
if (method === "Date") {
|
|||
|
var date = mirrorDateProperties(clock[method], target[method]);
|
|||
|
target[method] = date;
|
|||
|
} else if (method === "performance") {
|
|||
|
var originalPerfDescriptor = Object.getOwnPropertyDescriptor(
|
|||
|
target,
|
|||
|
method
|
|||
|
);
|
|||
|
// JSDOM has a read only performance field so we have to save/copy it differently
|
|||
|
if (
|
|||
|
originalPerfDescriptor &&
|
|||
|
originalPerfDescriptor.get &&
|
|||
|
!originalPerfDescriptor.set
|
|||
|
) {
|
|||
|
Object.defineProperty(
|
|||
|
clock,
|
|||
|
"_" + method,
|
|||
|
originalPerfDescriptor
|
|||
|
);
|
|||
|
|
|||
|
var perfDescriptor = Object.getOwnPropertyDescriptor(
|
|||
|
clock,
|
|||
|
method
|
|||
|
);
|
|||
|
Object.defineProperty(target, method, perfDescriptor);
|
|||
|
} else {
|
|||
|
target[method] = clock[method];
|
|||
|
}
|
|||
|
} else {
|
|||
|
target[method] = function() {
|
|||
|
return clock[method].apply(clock, arguments);
|
|||
|
};
|
|||
|
|
|||
|
for (prop in clock[method]) {
|
|||
|
if (clock[method].hasOwnProperty(prop)) {
|
|||
|
target[method][prop] = clock[method][prop];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
target[method].clock = clock;
|
|||
|
}
|
|||
|
|
|||
|
function doIntervalTick(clock, advanceTimeDelta) {
|
|||
|
clock.tick(advanceTimeDelta);
|
|||
|
}
|
|||
|
|
|||
|
var timers = {
|
|||
|
setTimeout: _global.setTimeout,
|
|||
|
clearTimeout: _global.clearTimeout,
|
|||
|
setInterval: _global.setInterval,
|
|||
|
clearInterval: _global.clearInterval,
|
|||
|
Date: _global.Date
|
|||
|
};
|
|||
|
|
|||
|
if (setImmediatePresent) {
|
|||
|
timers.setImmediate = _global.setImmediate;
|
|||
|
timers.clearImmediate = _global.clearImmediate;
|
|||
|
}
|
|||
|
|
|||
|
if (hrtimePresent) {
|
|||
|
timers.hrtime = _global.process.hrtime;
|
|||
|
}
|
|||
|
|
|||
|
if (nextTickPresent) {
|
|||
|
timers.nextTick = _global.process.nextTick;
|
|||
|
}
|
|||
|
|
|||
|
if (performancePresent) {
|
|||
|
timers.performance = _global.performance;
|
|||
|
}
|
|||
|
|
|||
|
if (requestAnimationFramePresent) {
|
|||
|
timers.requestAnimationFrame = _global.requestAnimationFrame;
|
|||
|
}
|
|||
|
|
|||
|
if (queueMicrotaskPresent) {
|
|||
|
timers.queueMicrotask = true;
|
|||
|
}
|
|||
|
|
|||
|
if (cancelAnimationFramePresent) {
|
|||
|
timers.cancelAnimationFrame = _global.cancelAnimationFrame;
|
|||
|
}
|
|||
|
|
|||
|
if (requestIdleCallbackPresent) {
|
|||
|
timers.requestIdleCallback = _global.requestIdleCallback;
|
|||
|
}
|
|||
|
|
|||
|
if (cancelIdleCallbackPresent) {
|
|||
|
timers.cancelIdleCallback = _global.cancelIdleCallback;
|
|||
|
}
|
|||
|
|
|||
|
var keys =
|
|||
|
Object.keys ||
|
|||
|
function(obj) {
|
|||
|
var ks = [];
|
|||
|
var key;
|
|||
|
|
|||
|
for (key in obj) {
|
|||
|
if (obj.hasOwnProperty(key)) {
|
|||
|
ks.push(key);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return ks;
|
|||
|
};
|
|||
|
|
|||
|
var originalSetTimeout = _global.setImmediate || _global.setTimeout;
|
|||
|
|
|||
|
/**
|
|||
|
* @param start {Date|number} the system time - non-integer values are floored
|
|||
|
* @param loopLimit {number} maximum number of timers that will be run when calling runAll()
|
|||
|
*/
|
|||
|
function createClock(start, loopLimit) {
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
start = Math.floor(getEpoch(start));
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
loopLimit = loopLimit || 1000;
|
|||
|
var nanos = 0;
|
|||
|
var adjustedSystemTime = [0, 0]; // [millis, nanoremainder]
|
|||
|
|
|||
|
if (NativeDate === undefined) {
|
|||
|
throw new Error(
|
|||
|
"The global scope doesn't have a `Date` object" +
|
|||
|
" (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
var clock = {
|
|||
|
now: start,
|
|||
|
timeouts: {},
|
|||
|
Date: createDate(),
|
|||
|
loopLimit: loopLimit
|
|||
|
};
|
|||
|
|
|||
|
clock.Date.clock = clock;
|
|||
|
|
|||
|
function getTimeToNextFrame() {
|
|||
|
return 16 - ((clock.now - start) % 16);
|
|||
|
}
|
|||
|
|
|||
|
function hrtime(prev) {
|
|||
|
var millisSinceStart = clock.now - adjustedSystemTime[0] - start;
|
|||
|
var secsSinceStart = Math.floor(millisSinceStart / 1000);
|
|||
|
var remainderInNanos =
|
|||
|
(millisSinceStart - secsSinceStart * 1e3) * 1e6 +
|
|||
|
nanos -
|
|||
|
adjustedSystemTime[1];
|
|||
|
|
|||
|
if (Array.isArray(prev)) {
|
|||
|
if (prev[1] > 1e9) {
|
|||
|
throw new TypeError(
|
|||
|
"Number of nanoseconds can't exceed a billion"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
var oldSecs = prev[0];
|
|||
|
var nanoDiff = remainderInNanos - prev[1];
|
|||
|
var secDiff = secsSinceStart - oldSecs;
|
|||
|
|
|||
|
if (nanoDiff < 0) {
|
|||
|
nanoDiff += 1e9;
|
|||
|
secDiff -= 1;
|
|||
|
}
|
|||
|
|
|||
|
return [secDiff, nanoDiff];
|
|||
|
}
|
|||
|
return [secsSinceStart, remainderInNanos];
|
|||
|
}
|
|||
|
|
|||
|
if (hrtimeBigintPresent) {
|
|||
|
hrtime.bigint = function() {
|
|||
|
var parts = hrtime();
|
|||
|
return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]); // eslint-disable-line
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.requestIdleCallback = function requestIdleCallback(
|
|||
|
func,
|
|||
|
timeout
|
|||
|
) {
|
|||
|
var timeToNextIdlePeriod = 0;
|
|||
|
|
|||
|
if (clock.countTimers() > 0) {
|
|||
|
timeToNextIdlePeriod = 50; // const for now
|
|||
|
}
|
|||
|
|
|||
|
var result = addTimer(clock, {
|
|||
|
func: func,
|
|||
|
args: Array.prototype.slice.call(arguments, 2),
|
|||
|
delay:
|
|||
|
typeof timeout === "undefined"
|
|||
|
? timeToNextIdlePeriod
|
|||
|
: Math.min(timeout, timeToNextIdlePeriod)
|
|||
|
});
|
|||
|
|
|||
|
return result.id || result;
|
|||
|
};
|
|||
|
|
|||
|
clock.cancelIdleCallback = function cancelIdleCallback(timerId) {
|
|||
|
return clearTimer(clock, timerId, "Timeout");
|
|||
|
};
|
|||
|
|
|||
|
clock.setTimeout = function setTimeout(func, timeout) {
|
|||
|
return addTimer(clock, {
|
|||
|
func: func,
|
|||
|
args: Array.prototype.slice.call(arguments, 2),
|
|||
|
delay: timeout
|
|||
|
});
|
|||
|
};
|
|||
|
if (typeof _global.Promise !== "undefined" && utilPromisify) {
|
|||
|
clock.setTimeout[
|
|||
|
utilPromisify.custom
|
|||
|
] = function promisifiedSetTimeout(timeout, arg) {
|
|||
|
return new _global.Promise(function setTimeoutExecutor(
|
|||
|
resolve
|
|||
|
) {
|
|||
|
addTimer(clock, {
|
|||
|
func: resolve,
|
|||
|
args: [arg],
|
|||
|
delay: timeout
|
|||
|
});
|
|||
|
});
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.clearTimeout = function clearTimeout(timerId) {
|
|||
|
return clearTimer(clock, timerId, "Timeout");
|
|||
|
};
|
|||
|
|
|||
|
clock.nextTick = function nextTick(func) {
|
|||
|
return enqueueJob(clock, {
|
|||
|
func: func,
|
|||
|
args: Array.prototype.slice.call(arguments, 1)
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
clock.queueMicrotask = function queueMicrotask(func) {
|
|||
|
return clock.nextTick(func); // explicitly drop additional arguments
|
|||
|
};
|
|||
|
|
|||
|
clock.setInterval = function setInterval(func, timeout) {
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
timeout = parseInt(timeout, 10);
|
|||
|
return addTimer(clock, {
|
|||
|
func: func,
|
|||
|
args: Array.prototype.slice.call(arguments, 2),
|
|||
|
delay: timeout,
|
|||
|
interval: timeout
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
clock.clearInterval = function clearInterval(timerId) {
|
|||
|
return clearTimer(clock, timerId, "Interval");
|
|||
|
};
|
|||
|
|
|||
|
if (setImmediatePresent) {
|
|||
|
clock.setImmediate = function setImmediate(func) {
|
|||
|
return addTimer(clock, {
|
|||
|
func: func,
|
|||
|
args: Array.prototype.slice.call(arguments, 1),
|
|||
|
immediate: true
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
if (typeof _global.Promise !== "undefined" && utilPromisify) {
|
|||
|
clock.setImmediate[
|
|||
|
utilPromisify.custom
|
|||
|
] = function promisifiedSetImmediate(arg) {
|
|||
|
return new _global.Promise(function setImmediateExecutor(
|
|||
|
resolve
|
|||
|
) {
|
|||
|
addTimer(clock, {
|
|||
|
func: resolve,
|
|||
|
args: [arg],
|
|||
|
immediate: true
|
|||
|
});
|
|||
|
});
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.clearImmediate = function clearImmediate(timerId) {
|
|||
|
return clearTimer(clock, timerId, "Immediate");
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.countTimers = function countTimers() {
|
|||
|
return (
|
|||
|
Object.keys(clock.timers || {}).length +
|
|||
|
(clock.jobs || []).length
|
|||
|
);
|
|||
|
};
|
|||
|
|
|||
|
clock.requestAnimationFrame = function requestAnimationFrame(func) {
|
|||
|
var result = addTimer(clock, {
|
|||
|
func: func,
|
|||
|
delay: getTimeToNextFrame(),
|
|||
|
args: [clock.now + getTimeToNextFrame()],
|
|||
|
animation: true
|
|||
|
});
|
|||
|
|
|||
|
return result.id || result;
|
|||
|
};
|
|||
|
|
|||
|
clock.cancelAnimationFrame = function cancelAnimationFrame(timerId) {
|
|||
|
return clearTimer(clock, timerId, "AnimationFrame");
|
|||
|
};
|
|||
|
|
|||
|
clock.runMicrotasks = function runMicrotasks() {
|
|||
|
runJobs(clock);
|
|||
|
};
|
|||
|
|
|||
|
function doTick(tickValue, isAsync, resolve, reject) {
|
|||
|
var msFloat =
|
|||
|
typeof tickValue === "number"
|
|||
|
? tickValue
|
|||
|
: parseTime(tickValue);
|
|||
|
var ms = Math.floor(msFloat);
|
|||
|
var remainder = nanoRemainder(msFloat);
|
|||
|
var nanosTotal = nanos + remainder;
|
|||
|
var tickTo = clock.now + ms;
|
|||
|
|
|||
|
if (msFloat < 0) {
|
|||
|
throw new TypeError("Negative ticks are not supported");
|
|||
|
}
|
|||
|
|
|||
|
// adjust for positive overflow
|
|||
|
if (nanosTotal >= 1e6) {
|
|||
|
tickTo += 1;
|
|||
|
nanosTotal -= 1e6;
|
|||
|
}
|
|||
|
|
|||
|
nanos = nanosTotal;
|
|||
|
var tickFrom = clock.now;
|
|||
|
var previous = clock.now;
|
|||
|
var timer,
|
|||
|
firstException,
|
|||
|
oldNow,
|
|||
|
nextPromiseTick,
|
|||
|
compensationCheck,
|
|||
|
postTimerCall;
|
|||
|
|
|||
|
clock.duringTick = true;
|
|||
|
|
|||
|
// perform microtasks
|
|||
|
oldNow = clock.now;
|
|||
|
runJobs(clock);
|
|||
|
if (oldNow !== clock.now) {
|
|||
|
// compensate for any setSystemTime() call during microtask callback
|
|||
|
tickFrom += clock.now - oldNow;
|
|||
|
tickTo += clock.now - oldNow;
|
|||
|
}
|
|||
|
|
|||
|
function doTickInner() {
|
|||
|
// perform each timer in the requested range
|
|||
|
timer = firstTimerInRange(clock, tickFrom, tickTo);
|
|||
|
// eslint-disable-next-line no-unmodified-loop-condition
|
|||
|
while (timer && tickFrom <= tickTo) {
|
|||
|
if (clock.timers[timer.id]) {
|
|||
|
tickFrom = timer.callAt;
|
|||
|
clock.now = timer.callAt;
|
|||
|
oldNow = clock.now;
|
|||
|
try {
|
|||
|
runJobs(clock);
|
|||
|
callTimer(clock, timer);
|
|||
|
} catch (e) {
|
|||
|
firstException = firstException || e;
|
|||
|
}
|
|||
|
|
|||
|
if (isAsync) {
|
|||
|
// finish up after native setImmediate callback to allow
|
|||
|
// all native es6 promises to process their callbacks after
|
|||
|
// each timer fires.
|
|||
|
originalSetTimeout(nextPromiseTick);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
compensationCheck();
|
|||
|
}
|
|||
|
|
|||
|
postTimerCall();
|
|||
|
}
|
|||
|
|
|||
|
// perform process.nextTick()s again
|
|||
|
oldNow = clock.now;
|
|||
|
runJobs(clock);
|
|||
|
if (oldNow !== clock.now) {
|
|||
|
// compensate for any setSystemTime() call during process.nextTick() callback
|
|||
|
tickFrom += clock.now - oldNow;
|
|||
|
tickTo += clock.now - oldNow;
|
|||
|
}
|
|||
|
clock.duringTick = false;
|
|||
|
|
|||
|
// corner case: during runJobs new timers were scheduled which could be in the range [clock.now, tickTo]
|
|||
|
timer = firstTimerInRange(clock, tickFrom, tickTo);
|
|||
|
if (timer) {
|
|||
|
try {
|
|||
|
clock.tick(tickTo - clock.now); // do it all again - for the remainder of the requested range
|
|||
|
} catch (e) {
|
|||
|
firstException = firstException || e;
|
|||
|
}
|
|||
|
} else {
|
|||
|
// no timers remaining in the requested range: move the clock all the way to the end
|
|||
|
clock.now = tickTo;
|
|||
|
|
|||
|
// update nanos
|
|||
|
nanos = nanosTotal;
|
|||
|
}
|
|||
|
if (firstException) {
|
|||
|
throw firstException;
|
|||
|
}
|
|||
|
|
|||
|
if (isAsync) {
|
|||
|
resolve(clock.now);
|
|||
|
} else {
|
|||
|
return clock.now;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
nextPromiseTick =
|
|||
|
isAsync &&
|
|||
|
function() {
|
|||
|
try {
|
|||
|
compensationCheck();
|
|||
|
postTimerCall();
|
|||
|
doTickInner();
|
|||
|
} catch (e) {
|
|||
|
reject(e);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
compensationCheck = function() {
|
|||
|
// compensate for any setSystemTime() call during timer callback
|
|||
|
if (oldNow !== clock.now) {
|
|||
|
tickFrom += clock.now - oldNow;
|
|||
|
tickTo += clock.now - oldNow;
|
|||
|
previous += clock.now - oldNow;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
postTimerCall = function() {
|
|||
|
timer = firstTimerInRange(clock, previous, tickTo);
|
|||
|
previous = tickFrom;
|
|||
|
};
|
|||
|
|
|||
|
return doTickInner();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {tickValue} {String|Number} number of milliseconds or a human-readable value like "01:11:15"
|
|||
|
*/
|
|||
|
clock.tick = function tick(tickValue) {
|
|||
|
return doTick(tickValue, false);
|
|||
|
};
|
|||
|
|
|||
|
if (typeof _global.Promise !== "undefined") {
|
|||
|
clock.tickAsync = function tickAsync(ms) {
|
|||
|
return new _global.Promise(function(resolve, reject) {
|
|||
|
originalSetTimeout(function() {
|
|||
|
try {
|
|||
|
doTick(ms, true, resolve, reject);
|
|||
|
} catch (e) {
|
|||
|
reject(e);
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.next = function next() {
|
|||
|
runJobs(clock);
|
|||
|
var timer = firstTimer(clock);
|
|||
|
if (!timer) {
|
|||
|
return clock.now;
|
|||
|
}
|
|||
|
|
|||
|
clock.duringTick = true;
|
|||
|
try {
|
|||
|
clock.now = timer.callAt;
|
|||
|
callTimer(clock, timer);
|
|||
|
runJobs(clock);
|
|||
|
return clock.now;
|
|||
|
} finally {
|
|||
|
clock.duringTick = false;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
if (typeof _global.Promise !== "undefined") {
|
|||
|
clock.nextAsync = function nextAsync() {
|
|||
|
return new _global.Promise(function(resolve, reject) {
|
|||
|
originalSetTimeout(function() {
|
|||
|
try {
|
|||
|
var timer = firstTimer(clock);
|
|||
|
if (!timer) {
|
|||
|
resolve(clock.now);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var err;
|
|||
|
clock.duringTick = true;
|
|||
|
clock.now = timer.callAt;
|
|||
|
try {
|
|||
|
callTimer(clock, timer);
|
|||
|
} catch (e) {
|
|||
|
err = e;
|
|||
|
}
|
|||
|
clock.duringTick = false;
|
|||
|
|
|||
|
originalSetTimeout(function() {
|
|||
|
if (err) {
|
|||
|
reject(err);
|
|||
|
} else {
|
|||
|
resolve(clock.now);
|
|||
|
}
|
|||
|
});
|
|||
|
} catch (e) {
|
|||
|
reject(e);
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.runAll = function runAll() {
|
|||
|
var numTimers, i;
|
|||
|
runJobs(clock);
|
|||
|
for (i = 0; i < clock.loopLimit; i++) {
|
|||
|
if (!clock.timers) {
|
|||
|
return clock.now;
|
|||
|
}
|
|||
|
|
|||
|
numTimers = keys(clock.timers).length;
|
|||
|
if (numTimers === 0) {
|
|||
|
return clock.now;
|
|||
|
}
|
|||
|
|
|||
|
clock.next();
|
|||
|
}
|
|||
|
|
|||
|
throw new Error(
|
|||
|
"Aborting after running " +
|
|||
|
clock.loopLimit +
|
|||
|
" timers, assuming an infinite loop!"
|
|||
|
);
|
|||
|
};
|
|||
|
|
|||
|
clock.runToFrame = function runToFrame() {
|
|||
|
return clock.tick(getTimeToNextFrame());
|
|||
|
};
|
|||
|
|
|||
|
if (typeof _global.Promise !== "undefined") {
|
|||
|
clock.runAllAsync = function runAllAsync() {
|
|||
|
return new _global.Promise(function(resolve, reject) {
|
|||
|
var i = 0;
|
|||
|
function doRun() {
|
|||
|
originalSetTimeout(function() {
|
|||
|
try {
|
|||
|
var numTimers;
|
|||
|
if (i < clock.loopLimit) {
|
|||
|
if (!clock.timers) {
|
|||
|
resolve(clock.now);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
numTimers = Object.keys(clock.timers)
|
|||
|
.length;
|
|||
|
if (numTimers === 0) {
|
|||
|
resolve(clock.now);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
clock.next();
|
|||
|
|
|||
|
i++;
|
|||
|
|
|||
|
doRun();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
reject(
|
|||
|
new Error(
|
|||
|
"Aborting after running " +
|
|||
|
clock.loopLimit +
|
|||
|
" timers, assuming an infinite loop!"
|
|||
|
)
|
|||
|
);
|
|||
|
} catch (e) {
|
|||
|
reject(e);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
doRun();
|
|||
|
});
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.runToLast = function runToLast() {
|
|||
|
var timer = lastTimer(clock);
|
|||
|
if (!timer) {
|
|||
|
runJobs(clock);
|
|||
|
return clock.now;
|
|||
|
}
|
|||
|
|
|||
|
return clock.tick(timer.callAt - clock.now);
|
|||
|
};
|
|||
|
|
|||
|
if (typeof _global.Promise !== "undefined") {
|
|||
|
clock.runToLastAsync = function runToLastAsync() {
|
|||
|
return new _global.Promise(function(resolve, reject) {
|
|||
|
originalSetTimeout(function() {
|
|||
|
try {
|
|||
|
var timer = lastTimer(clock);
|
|||
|
if (!timer) {
|
|||
|
resolve(clock.now);
|
|||
|
}
|
|||
|
|
|||
|
resolve(clock.tickAsync(timer.callAt));
|
|||
|
} catch (e) {
|
|||
|
reject(e);
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
clock.reset = function reset() {
|
|||
|
nanos = 0;
|
|||
|
clock.timers = {};
|
|||
|
clock.jobs = [];
|
|||
|
clock.now = start;
|
|||
|
};
|
|||
|
|
|||
|
clock.setSystemTime = function setSystemTime(systemTime) {
|
|||
|
// determine time difference
|
|||
|
var newNow = getEpoch(systemTime);
|
|||
|
var difference = newNow - clock.now;
|
|||
|
var id, timer;
|
|||
|
|
|||
|
adjustedSystemTime[0] = adjustedSystemTime[0] + difference;
|
|||
|
adjustedSystemTime[1] = adjustedSystemTime[1] + nanos;
|
|||
|
// update 'system clock'
|
|||
|
clock.now = newNow;
|
|||
|
nanos = 0;
|
|||
|
|
|||
|
// update timers and intervals to keep them stable
|
|||
|
for (id in clock.timers) {
|
|||
|
if (clock.timers.hasOwnProperty(id)) {
|
|||
|
timer = clock.timers[id];
|
|||
|
timer.createdAt += difference;
|
|||
|
timer.callAt += difference;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
if (performancePresent) {
|
|||
|
clock.performance = Object.create(null);
|
|||
|
|
|||
|
if (hasPerformancePrototype) {
|
|||
|
var proto = _global.Performance.prototype;
|
|||
|
|
|||
|
Object.getOwnPropertyNames(proto).forEach(function(name) {
|
|||
|
if (name.indexOf("getEntries") === 0) {
|
|||
|
// match expected return type for getEntries functions
|
|||
|
clock.performance[name] = NOOP_ARRAY;
|
|||
|
} else {
|
|||
|
clock.performance[name] = NOOP;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
clock.performance.now = function FakeTimersNow() {
|
|||
|
var hrt = hrtime();
|
|||
|
var millis = hrt[0] * 1000 + hrt[1] / 1e6;
|
|||
|
return millis;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
if (hrtimePresent) {
|
|||
|
clock.hrtime = hrtime;
|
|||
|
}
|
|||
|
|
|||
|
return clock;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param config {Object} optional config
|
|||
|
* @param config.target {Object} the target to install timers in (default `window`)
|
|||
|
* @param config.now {number|Date} a number (in milliseconds) or a Date object (default epoch)
|
|||
|
* @param config.toFake {string[]} names of the methods that should be faked.
|
|||
|
* @param config.loopLimit {number} the maximum number of timers that will be run when calling runAll()
|
|||
|
* @param config.shouldAdvanceTime {Boolean} tells FakeTimers to increment mocked time automatically (default false)
|
|||
|
* @param config.advanceTimeDelta {Number} increment mocked time every <<advanceTimeDelta>> ms (default: 20ms)
|
|||
|
*/
|
|||
|
// eslint-disable-next-line complexity
|
|||
|
function install(config) {
|
|||
|
if (
|
|||
|
arguments.length > 1 ||
|
|||
|
config instanceof Date ||
|
|||
|
Array.isArray(config) ||
|
|||
|
typeof config === "number"
|
|||
|
) {
|
|||
|
throw new TypeError(
|
|||
|
"FakeTimers.install called with " +
|
|||
|
String(config) +
|
|||
|
" install requires an object parameter"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
config = typeof config !== "undefined" ? config : {};
|
|||
|
config.shouldAdvanceTime = config.shouldAdvanceTime || false;
|
|||
|
config.advanceTimeDelta = config.advanceTimeDelta || 20;
|
|||
|
|
|||
|
var i, l;
|
|||
|
var target = config.target || _global;
|
|||
|
var clock = createClock(config.now, config.loopLimit);
|
|||
|
|
|||
|
clock.uninstall = function() {
|
|||
|
return uninstall(clock, target, config);
|
|||
|
};
|
|||
|
|
|||
|
clock.methods = config.toFake || [];
|
|||
|
|
|||
|
if (clock.methods.length === 0) {
|
|||
|
// do not fake nextTick by default - GitHub#126
|
|||
|
clock.methods = keys(timers).filter(function(key) {
|
|||
|
return key !== "nextTick" && key !== "queueMicrotask";
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
for (i = 0, l = clock.methods.length; i < l; i++) {
|
|||
|
if (clock.methods[i] === "hrtime") {
|
|||
|
if (
|
|||
|
target.process &&
|
|||
|
typeof target.process.hrtime === "function"
|
|||
|
) {
|
|||
|
hijackMethod(target.process, clock.methods[i], clock);
|
|||
|
}
|
|||
|
} else if (clock.methods[i] === "nextTick") {
|
|||
|
if (
|
|||
|
target.process &&
|
|||
|
typeof target.process.nextTick === "function"
|
|||
|
) {
|
|||
|
hijackMethod(target.process, clock.methods[i], clock);
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (
|
|||
|
clock.methods[i] === "setInterval" &&
|
|||
|
config.shouldAdvanceTime === true
|
|||
|
) {
|
|||
|
var intervalTick = doIntervalTick.bind(
|
|||
|
null,
|
|||
|
clock,
|
|||
|
config.advanceTimeDelta
|
|||
|
);
|
|||
|
var intervalId = target[clock.methods[i]](
|
|||
|
intervalTick,
|
|||
|
config.advanceTimeDelta
|
|||
|
);
|
|||
|
clock.attachedInterval = intervalId;
|
|||
|
}
|
|||
|
hijackMethod(target, clock.methods[i], clock);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return clock;
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
timers: timers,
|
|||
|
createClock: createClock,
|
|||
|
install: install,
|
|||
|
withGlobal: withGlobal
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
var defaultImplementation = withGlobal(globalObject);
|
|||
|
|
|||
|
exports.timers = defaultImplementation.timers;
|
|||
|
exports.createClock = defaultImplementation.createClock;
|
|||
|
exports.install = defaultImplementation.install;
|
|||
|
exports.withGlobal = withGlobal;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45,"util":109}],58:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var samsam = require("@sinonjs/samsam");
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
|
|||
|
var formatio = {
|
|||
|
excludeConstructors: ["Object", /^.$/],
|
|||
|
quoteStrings: true,
|
|||
|
limitChildrenCount: 0
|
|||
|
};
|
|||
|
|
|||
|
var specialObjects = [];
|
|||
|
/* istanbul ignore else */
|
|||
|
if (typeof global !== "undefined") {
|
|||
|
specialObjects.push({ object: global, value: "[object global]" });
|
|||
|
}
|
|||
|
if (typeof document !== "undefined") {
|
|||
|
specialObjects.push({
|
|||
|
object: document,
|
|||
|
value: "[object HTMLDocument]"
|
|||
|
});
|
|||
|
}
|
|||
|
if (typeof window !== "undefined") {
|
|||
|
specialObjects.push({ object: window, value: "[object Window]" });
|
|||
|
}
|
|||
|
|
|||
|
function constructorName(f, object) {
|
|||
|
var name = functionName(object && object.constructor);
|
|||
|
var excludes = f.excludeConstructors || formatio.excludeConstructors;
|
|||
|
|
|||
|
var i, l;
|
|||
|
for (i = 0, l = excludes.length; i < l; ++i) {
|
|||
|
if (typeof excludes[i] === "string" && excludes[i] === name) {
|
|||
|
return "";
|
|||
|
} else if (excludes[i].test && excludes[i].test(name)) {
|
|||
|
return "";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return name;
|
|||
|
}
|
|||
|
|
|||
|
function isCircular(object, objects) {
|
|||
|
if (typeof object !== "object") {
|
|||
|
return false;
|
|||
|
}
|
|||
|
var i, l;
|
|||
|
for (i = 0, l = objects.length; i < l; ++i) {
|
|||
|
if (objects[i] === object) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
// eslint-disable-next-line complexity
|
|||
|
function ascii(f, object, processed, indent) {
|
|||
|
if (typeof object === "string") {
|
|||
|
if (object.length === 0) {
|
|||
|
return "(empty string)";
|
|||
|
}
|
|||
|
var qs = f.quoteStrings;
|
|||
|
var quote = typeof qs !== "boolean" || qs;
|
|||
|
// eslint-disable-next-line quotes
|
|||
|
return processed || quote ? '"' + object + '"' : object;
|
|||
|
}
|
|||
|
|
|||
|
if (typeof object === "symbol") {
|
|||
|
return object.toString();
|
|||
|
}
|
|||
|
|
|||
|
if (typeof object === "function" && !(object instanceof RegExp)) {
|
|||
|
return ascii.func(object);
|
|||
|
}
|
|||
|
|
|||
|
// eslint supports bigint as of version 6.0.0
|
|||
|
// https://github.com/eslint/eslint/commit/e4ab0531c4e44c23494c6a802aa2329d15ac90e5
|
|||
|
// eslint-disable-next-line
|
|||
|
if (typeOf(object) === "bigint") {
|
|||
|
return object.toString();
|
|||
|
}
|
|||
|
|
|||
|
var internalProcessed = processed || [];
|
|||
|
|
|||
|
if (isCircular(object, internalProcessed)) {
|
|||
|
return "[Circular]";
|
|||
|
}
|
|||
|
|
|||
|
if (typeOf(object) === "array") {
|
|||
|
return ascii.array.call(f, object, internalProcessed);
|
|||
|
}
|
|||
|
|
|||
|
if (!object) {
|
|||
|
return String(1 / object === -Infinity ? "-0" : object);
|
|||
|
}
|
|||
|
if (samsam.isElement(object)) {
|
|||
|
return ascii.element(object);
|
|||
|
}
|
|||
|
|
|||
|
if (
|
|||
|
typeof object.toString === "function" &&
|
|||
|
object.toString !== Object.prototype.toString
|
|||
|
) {
|
|||
|
return object.toString();
|
|||
|
}
|
|||
|
|
|||
|
var i, l;
|
|||
|
for (i = 0, l = specialObjects.length; i < l; i++) {
|
|||
|
if (object === specialObjects[i].object) {
|
|||
|
return specialObjects[i].value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (samsam.isSet(object)) {
|
|||
|
return ascii.set.call(f, object, internalProcessed);
|
|||
|
}
|
|||
|
|
|||
|
if (object instanceof Map) {
|
|||
|
return ascii.map.call(f, object, internalProcessed);
|
|||
|
}
|
|||
|
|
|||
|
return ascii.object.call(f, object, internalProcessed, indent);
|
|||
|
}
|
|||
|
|
|||
|
ascii.func = function(func) {
|
|||
|
var funcName = functionName(func) || "";
|
|||
|
return "function " + funcName + "() {}";
|
|||
|
};
|
|||
|
|
|||
|
function delimit(str, delimiters) {
|
|||
|
var delims = delimiters || ["[", "]"];
|
|||
|
return delims[0] + str + delims[1];
|
|||
|
}
|
|||
|
|
|||
|
ascii.array = function(array, processed, delimiters) {
|
|||
|
processed.push(array);
|
|||
|
var pieces = [];
|
|||
|
var i, l;
|
|||
|
l =
|
|||
|
this.limitChildrenCount > 0
|
|||
|
? Math.min(this.limitChildrenCount, array.length)
|
|||
|
: array.length;
|
|||
|
|
|||
|
for (i = 0; i < l; ++i) {
|
|||
|
pieces.push(ascii(this, array[i], processed));
|
|||
|
}
|
|||
|
|
|||
|
if (l < array.length) {
|
|||
|
pieces.push("[... " + (array.length - l) + " more elements]");
|
|||
|
}
|
|||
|
|
|||
|
return delimit(pieces.join(", "), delimiters);
|
|||
|
};
|
|||
|
|
|||
|
ascii.set = function(set, processed) {
|
|||
|
return ascii.array.call(this, Array.from(set), processed, ["Set {", "}"]);
|
|||
|
};
|
|||
|
|
|||
|
ascii.map = function(map, processed) {
|
|||
|
return ascii.array.call(this, Array.from(map), processed, ["Map [", "]"]);
|
|||
|
};
|
|||
|
|
|||
|
function getSymbols(object) {
|
|||
|
if (samsam.isArguments(object)) {
|
|||
|
return [];
|
|||
|
}
|
|||
|
|
|||
|
/* istanbul ignore else */
|
|||
|
if (typeof Object.getOwnPropertySymbols === "function") {
|
|||
|
return Object.getOwnPropertySymbols(object);
|
|||
|
}
|
|||
|
|
|||
|
/* istanbul ignore next: This is only for IE, since getOwnPropertySymbols
|
|||
|
* does not exist on Object there
|
|||
|
*/
|
|||
|
return [];
|
|||
|
}
|
|||
|
|
|||
|
ascii.object = function(object, processed, indent) {
|
|||
|
processed.push(object);
|
|||
|
var internalIndent = indent || 0;
|
|||
|
var pieces = [];
|
|||
|
var properties = Object.keys(object)
|
|||
|
.sort()
|
|||
|
.concat(getSymbols(object));
|
|||
|
var length = 3;
|
|||
|
var prop, str, obj, i, k, l;
|
|||
|
l =
|
|||
|
this.limitChildrenCount > 0
|
|||
|
? Math.min(this.limitChildrenCount, properties.length)
|
|||
|
: properties.length;
|
|||
|
|
|||
|
for (i = 0; i < l; ++i) {
|
|||
|
prop = properties[i];
|
|||
|
obj = object[prop];
|
|||
|
|
|||
|
if (isCircular(obj, processed)) {
|
|||
|
str = "[Circular]";
|
|||
|
} else {
|
|||
|
str = ascii(this, obj, processed, internalIndent + 2);
|
|||
|
}
|
|||
|
|
|||
|
str =
|
|||
|
(typeof prop === "string" && /\s/.test(prop)
|
|||
|
? // eslint-disable-next-line quotes
|
|||
|
'"' + prop + '"'
|
|||
|
: prop.toString()) +
|
|||
|
": " +
|
|||
|
str;
|
|||
|
length += str.length;
|
|||
|
pieces.push(str);
|
|||
|
}
|
|||
|
|
|||
|
var cons = constructorName(this, object);
|
|||
|
var prefix = cons ? "[" + cons + "] " : "";
|
|||
|
var is = "";
|
|||
|
for (i = 0, k = internalIndent; i < k; ++i) {
|
|||
|
is += " ";
|
|||
|
}
|
|||
|
|
|||
|
if (l < properties.length) {
|
|||
|
pieces.push("[... " + (properties.length - l) + " more elements]");
|
|||
|
}
|
|||
|
|
|||
|
if (length + internalIndent > 80) {
|
|||
|
return (
|
|||
|
prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + is + "}"
|
|||
|
);
|
|||
|
}
|
|||
|
return prefix + "{ " + pieces.join(", ") + " }";
|
|||
|
};
|
|||
|
|
|||
|
ascii.element = function(element) {
|
|||
|
var tagName = element.tagName.toLowerCase();
|
|||
|
var attrs = element.attributes;
|
|||
|
var pairs = [];
|
|||
|
var attr, attrName, i, l, val;
|
|||
|
|
|||
|
for (i = 0, l = attrs.length; i < l; ++i) {
|
|||
|
attr = attrs.item(i);
|
|||
|
attrName = attr.nodeName.toLowerCase().replace("html:", "");
|
|||
|
val = attr.nodeValue;
|
|||
|
if (attrName !== "contenteditable" || val !== "inherit") {
|
|||
|
if (val) {
|
|||
|
// eslint-disable-next-line quotes
|
|||
|
pairs.push(attrName + '="' + val + '"');
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
|
|||
|
// SVG elements have undefined innerHTML
|
|||
|
var content = element.innerHTML || "";
|
|||
|
|
|||
|
if (content.length > 20) {
|
|||
|
content = content.substr(0, 20) + "[...]";
|
|||
|
}
|
|||
|
|
|||
|
var res =
|
|||
|
formatted + pairs.join(" ") + ">" + content + "</" + tagName + ">";
|
|||
|
|
|||
|
return res.replace(/ contentEditable="inherit"/, "");
|
|||
|
};
|
|||
|
|
|||
|
function Formatio(options) {
|
|||
|
// eslint-disable-next-line guard-for-in
|
|||
|
for (var opt in options) {
|
|||
|
this[opt] = options[opt];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Formatio.prototype = {
|
|||
|
functionName: functionName,
|
|||
|
|
|||
|
configure: function(options) {
|
|||
|
return new Formatio(options);
|
|||
|
},
|
|||
|
|
|||
|
constructorName: function(object) {
|
|||
|
return constructorName(this, object);
|
|||
|
},
|
|||
|
|
|||
|
ascii: function(object, processed, indent) {
|
|||
|
return ascii(this, object, processed, indent);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
module.exports = Formatio.prototype;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45,"@sinonjs/samsam":84}],59:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var ARRAY_TYPES = [
|
|||
|
Array,
|
|||
|
Int8Array,
|
|||
|
Uint8Array,
|
|||
|
Uint8ClampedArray,
|
|||
|
Int16Array,
|
|||
|
Uint16Array,
|
|||
|
Int32Array,
|
|||
|
Uint32Array,
|
|||
|
Float32Array,
|
|||
|
Float64Array
|
|||
|
];
|
|||
|
|
|||
|
module.exports = ARRAY_TYPES;
|
|||
|
|
|||
|
},{}],60:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var deepEqual = require("./deep-equal").use(createMatcher); // eslint-disable-line no-use-before-define
|
|||
|
var every = require("@sinonjs/commons").every;
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var get = require("lodash.get");
|
|||
|
var iterableToString = require("./iterable-to-string");
|
|||
|
var objectProto = require("@sinonjs/commons").prototypes.object;
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
var assertMatcher = require("./create-matcher/assert-matcher");
|
|||
|
var assertMethodExists = require("./create-matcher/assert-method-exists");
|
|||
|
var assertType = require("./create-matcher/assert-type");
|
|||
|
var isIterable = require("./create-matcher/is-iterable");
|
|||
|
var isMatcher = require("./create-matcher/is-matcher");
|
|||
|
|
|||
|
var matcherPrototype = require("./create-matcher/matcher-prototype");
|
|||
|
|
|||
|
var arrayIndexOf = arrayProto.indexOf;
|
|||
|
var some = arrayProto.some;
|
|||
|
|
|||
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|||
|
var objectToString = objectProto.toString;
|
|||
|
|
|||
|
var TYPE_MAP = require("./create-matcher/type-map")(createMatcher); // eslint-disable-line no-use-before-define
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a matcher object for the passed expectation
|
|||
|
*
|
|||
|
* @alias module:samsam.createMatcher
|
|||
|
* @param {*} expectation An expecttation
|
|||
|
* @param {string} message A message for the expectation
|
|||
|
* @returns {object} A matcher object
|
|||
|
*/
|
|||
|
function createMatcher(expectation, message) {
|
|||
|
var m = Object.create(matcherPrototype);
|
|||
|
var type = typeOf(expectation);
|
|||
|
|
|||
|
if (message !== undefined && typeof message !== "string") {
|
|||
|
throw new TypeError("Message should be a string");
|
|||
|
}
|
|||
|
|
|||
|
if (arguments.length > 2) {
|
|||
|
throw new TypeError(
|
|||
|
"Expected 1 or 2 arguments, received " + arguments.length
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
if (type in TYPE_MAP) {
|
|||
|
TYPE_MAP[type](m, expectation, message);
|
|||
|
} else {
|
|||
|
m.test = function(actual) {
|
|||
|
return deepEqual(actual, expectation);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
if (!m.message) {
|
|||
|
m.message = "match(" + valueToString(expectation) + ")";
|
|||
|
}
|
|||
|
|
|||
|
return m;
|
|||
|
}
|
|||
|
|
|||
|
createMatcher.isMatcher = isMatcher;
|
|||
|
|
|||
|
createMatcher.any = createMatcher(function() {
|
|||
|
return true;
|
|||
|
}, "any");
|
|||
|
|
|||
|
createMatcher.defined = createMatcher(function(actual) {
|
|||
|
return actual !== null && actual !== undefined;
|
|||
|
}, "defined");
|
|||
|
|
|||
|
createMatcher.truthy = createMatcher(function(actual) {
|
|||
|
return Boolean(actual);
|
|||
|
}, "truthy");
|
|||
|
|
|||
|
createMatcher.falsy = createMatcher(function(actual) {
|
|||
|
return !actual;
|
|||
|
}, "falsy");
|
|||
|
|
|||
|
createMatcher.same = function(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return expectation === actual;
|
|||
|
}, "same(" + valueToString(expectation) + ")");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.in = function(arrayOfExpectations) {
|
|||
|
if (typeOf(arrayOfExpectations) !== "array") {
|
|||
|
throw new TypeError("array expected");
|
|||
|
}
|
|||
|
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return some(arrayOfExpectations, function(expectation) {
|
|||
|
return expectation === actual;
|
|||
|
});
|
|||
|
}, "in(" + valueToString(arrayOfExpectations) + ")");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.typeOf = function(type) {
|
|||
|
assertType(type, "string", "type");
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return typeOf(actual) === type;
|
|||
|
}, 'typeOf("' + type + '")');
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.instanceOf = function(type) {
|
|||
|
/* istanbul ignore if */
|
|||
|
if (
|
|||
|
typeof Symbol === "undefined" ||
|
|||
|
typeof Symbol.hasInstance === "undefined"
|
|||
|
) {
|
|||
|
assertType(type, "function", "type");
|
|||
|
} else {
|
|||
|
assertMethodExists(
|
|||
|
type,
|
|||
|
Symbol.hasInstance,
|
|||
|
"type",
|
|||
|
"[Symbol.hasInstance]"
|
|||
|
);
|
|||
|
}
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return actual instanceof type;
|
|||
|
}, "instanceOf(" + (functionName(type) || objectToString(type)) + ")");
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a property matcher
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Function} propertyTest A function to test the property against a value
|
|||
|
* @param {string} messagePrefix A prefix to use for messages generated by the matcher
|
|||
|
* @returns {object} A matcher
|
|||
|
*/
|
|||
|
function createPropertyMatcher(propertyTest, messagePrefix) {
|
|||
|
return function(property, value) {
|
|||
|
assertType(property, "string", "property");
|
|||
|
var onlyProperty = arguments.length === 1;
|
|||
|
var message = messagePrefix + '("' + property + '"';
|
|||
|
if (!onlyProperty) {
|
|||
|
message += ", " + valueToString(value);
|
|||
|
}
|
|||
|
message += ")";
|
|||
|
return createMatcher(function(actual) {
|
|||
|
if (
|
|||
|
actual === undefined ||
|
|||
|
actual === null ||
|
|||
|
!propertyTest(actual, property)
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
return onlyProperty || deepEqual(actual[property], value);
|
|||
|
}, message);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
createMatcher.has = createPropertyMatcher(function(actual, property) {
|
|||
|
if (typeof actual === "object") {
|
|||
|
return property in actual;
|
|||
|
}
|
|||
|
return actual[property] !== undefined;
|
|||
|
}, "has");
|
|||
|
|
|||
|
createMatcher.hasOwn = createPropertyMatcher(function(actual, property) {
|
|||
|
return hasOwnProperty(actual, property);
|
|||
|
}, "hasOwn");
|
|||
|
|
|||
|
createMatcher.hasNested = function(property, value) {
|
|||
|
assertType(property, "string", "property");
|
|||
|
var onlyProperty = arguments.length === 1;
|
|||
|
var message = 'hasNested("' + property + '"';
|
|||
|
if (!onlyProperty) {
|
|||
|
message += ", " + valueToString(value);
|
|||
|
}
|
|||
|
message += ")";
|
|||
|
return createMatcher(function(actual) {
|
|||
|
if (
|
|||
|
actual === undefined ||
|
|||
|
actual === null ||
|
|||
|
get(actual, property) === undefined
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
return onlyProperty || deepEqual(get(actual, property), value);
|
|||
|
}, message);
|
|||
|
};
|
|||
|
|
|||
|
var jsonParseResultTypes = {
|
|||
|
null: true,
|
|||
|
boolean: true,
|
|||
|
number: true,
|
|||
|
string: true,
|
|||
|
object: true,
|
|||
|
array: true
|
|||
|
};
|
|||
|
createMatcher.json = function(value) {
|
|||
|
if (!jsonParseResultTypes[typeOf(value)]) {
|
|||
|
throw new TypeError("Value cannot be the result of JSON.parse");
|
|||
|
}
|
|||
|
var message = "json(" + JSON.stringify(value, null, " ") + ")";
|
|||
|
return createMatcher(function(actual) {
|
|||
|
var parsed;
|
|||
|
try {
|
|||
|
parsed = JSON.parse(actual);
|
|||
|
} catch (e) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
return deepEqual(parsed, value);
|
|||
|
}, message);
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.every = function(predicate) {
|
|||
|
assertMatcher(predicate);
|
|||
|
|
|||
|
return createMatcher(function(actual) {
|
|||
|
if (typeOf(actual) === "object") {
|
|||
|
return every(Object.keys(actual), function(key) {
|
|||
|
return predicate.test(actual[key]);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
return (
|
|||
|
isIterable(actual) &&
|
|||
|
every(actual, function(element) {
|
|||
|
return predicate.test(element);
|
|||
|
})
|
|||
|
);
|
|||
|
}, "every(" + predicate.message + ")");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.some = function(predicate) {
|
|||
|
assertMatcher(predicate);
|
|||
|
|
|||
|
return createMatcher(function(actual) {
|
|||
|
if (typeOf(actual) === "object") {
|
|||
|
return !every(Object.keys(actual), function(key) {
|
|||
|
return !predicate.test(actual[key]);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
return (
|
|||
|
isIterable(actual) &&
|
|||
|
!every(actual, function(element) {
|
|||
|
return !predicate.test(element);
|
|||
|
})
|
|||
|
);
|
|||
|
}, "some(" + predicate.message + ")");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.array = createMatcher.typeOf("array");
|
|||
|
|
|||
|
createMatcher.array.deepEquals = function(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
|||
|
var sameLength = actual.length === expectation.length;
|
|||
|
return (
|
|||
|
typeOf(actual) === "array" &&
|
|||
|
sameLength &&
|
|||
|
every(actual, function(element, index) {
|
|||
|
var expected = expectation[index];
|
|||
|
return typeOf(expected) === "array" &&
|
|||
|
typeOf(element) === "array"
|
|||
|
? createMatcher.array.deepEquals(expected).test(element)
|
|||
|
: deepEqual(expected, element);
|
|||
|
})
|
|||
|
);
|
|||
|
}, "deepEquals([" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.array.startsWith = function(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return (
|
|||
|
typeOf(actual) === "array" &&
|
|||
|
every(expectation, function(expectedElement, index) {
|
|||
|
return actual[index] === expectedElement;
|
|||
|
})
|
|||
|
);
|
|||
|
}, "startsWith([" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.array.endsWith = function(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
// This indicates the index in which we should start matching
|
|||
|
var offset = actual.length - expectation.length;
|
|||
|
|
|||
|
return (
|
|||
|
typeOf(actual) === "array" &&
|
|||
|
every(expectation, function(expectedElement, index) {
|
|||
|
return actual[offset + index] === expectedElement;
|
|||
|
})
|
|||
|
);
|
|||
|
}, "endsWith([" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.array.contains = function(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return (
|
|||
|
typeOf(actual) === "array" &&
|
|||
|
every(expectation, function(expectedElement) {
|
|||
|
return arrayIndexOf(actual, expectedElement) !== -1;
|
|||
|
})
|
|||
|
);
|
|||
|
}, "contains([" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.map = createMatcher.typeOf("map");
|
|||
|
|
|||
|
createMatcher.map.deepEquals = function mapDeepEquals(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
|||
|
var sameLength = actual.size === expectation.size;
|
|||
|
return (
|
|||
|
typeOf(actual) === "map" &&
|
|||
|
sameLength &&
|
|||
|
every(actual, function(element, key) {
|
|||
|
return expectation.has(key) && expectation.get(key) === element;
|
|||
|
})
|
|||
|
);
|
|||
|
}, "deepEquals(Map[" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.map.contains = function mapContains(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return (
|
|||
|
typeOf(actual) === "map" &&
|
|||
|
every(expectation, function(element, key) {
|
|||
|
return actual.has(key) && actual.get(key) === element;
|
|||
|
})
|
|||
|
);
|
|||
|
}, "contains(Map[" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.set = createMatcher.typeOf("set");
|
|||
|
|
|||
|
createMatcher.set.deepEquals = function setDeepEquals(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
// Comparing lengths is the fastest way to spot a difference before iterating through every item
|
|||
|
var sameLength = actual.size === expectation.size;
|
|||
|
return (
|
|||
|
typeOf(actual) === "set" &&
|
|||
|
sameLength &&
|
|||
|
every(actual, function(element) {
|
|||
|
return expectation.has(element);
|
|||
|
})
|
|||
|
);
|
|||
|
}, "deepEquals(Set[" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.set.contains = function setContains(expectation) {
|
|||
|
return createMatcher(function(actual) {
|
|||
|
return (
|
|||
|
typeOf(actual) === "set" &&
|
|||
|
every(expectation, function(element) {
|
|||
|
return actual.has(element);
|
|||
|
})
|
|||
|
);
|
|||
|
}, "contains(Set[" + iterableToString(expectation) + "])");
|
|||
|
};
|
|||
|
|
|||
|
createMatcher.bool = createMatcher.typeOf("boolean");
|
|||
|
createMatcher.number = createMatcher.typeOf("number");
|
|||
|
createMatcher.string = createMatcher.typeOf("string");
|
|||
|
createMatcher.object = createMatcher.typeOf("object");
|
|||
|
createMatcher.func = createMatcher.typeOf("function");
|
|||
|
createMatcher.regexp = createMatcher.typeOf("regexp");
|
|||
|
createMatcher.date = createMatcher.typeOf("date");
|
|||
|
createMatcher.symbol = createMatcher.typeOf("symbol");
|
|||
|
|
|||
|
module.exports = createMatcher;
|
|||
|
|
|||
|
},{"./create-matcher/assert-matcher":61,"./create-matcher/assert-method-exists":62,"./create-matcher/assert-type":63,"./create-matcher/is-iterable":64,"./create-matcher/is-matcher":65,"./create-matcher/matcher-prototype":67,"./create-matcher/type-map":68,"./deep-equal":69,"./iterable-to-string":82,"@sinonjs/commons":45,"lodash.get":91}],61:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var isMatcher = require("./is-matcher");
|
|||
|
|
|||
|
/**
|
|||
|
* Throws a TypeError when `value` is not a matcher
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to examine
|
|||
|
*/
|
|||
|
function assertMatcher(value) {
|
|||
|
if (!isMatcher(value)) {
|
|||
|
throw new TypeError("Matcher expected");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = assertMatcher;
|
|||
|
|
|||
|
},{"./is-matcher":65}],62:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Throws a TypeError when expected method doesn't exist
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value A value to examine
|
|||
|
* @param {string} method The name of the method to look for
|
|||
|
* @param {name} name A name to use for the error message
|
|||
|
* @param {string} methodPath The name of the method to use for error messages
|
|||
|
* @throws {TypeError} When the method doesn't exist
|
|||
|
*/
|
|||
|
function assertMethodExists(value, method, name, methodPath) {
|
|||
|
if (value[method] === null || value[method] === undefined) {
|
|||
|
throw new TypeError(
|
|||
|
"Expected " + name + " to have method " + methodPath
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = assertMethodExists;
|
|||
|
|
|||
|
},{}],63:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
|
|||
|
/**
|
|||
|
* Ensures that value is of type
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value A value to examine
|
|||
|
* @param {string} type A basic JavaScript type to compare to, e.g. "object", "string"
|
|||
|
* @param {string} name A string to use for the error message
|
|||
|
* @throws {TypeError} If value is not of the expected type
|
|||
|
* @returns {undefined}
|
|||
|
*/
|
|||
|
function assertType(value, type, name) {
|
|||
|
var actual = typeOf(value);
|
|||
|
if (actual !== type) {
|
|||
|
throw new TypeError(
|
|||
|
"Expected type of " +
|
|||
|
name +
|
|||
|
" to be " +
|
|||
|
type +
|
|||
|
", but was " +
|
|||
|
actual
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = assertType;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],64:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` for iterables
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value A value to examine
|
|||
|
* @returns {boolean} Returns `true` when `value` looks like an iterable
|
|||
|
*/
|
|||
|
function isIterable(value) {
|
|||
|
return Boolean(value) && typeOf(value.forEach) === "function";
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isIterable;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],65:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var isPrototypeOf = require("@sinonjs/commons").prototypes.object.isPrototypeOf;
|
|||
|
|
|||
|
var matcherPrototype = require("./matcher-prototype");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `object` is a matcher
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} object A value to examine
|
|||
|
* @returns {boolean} Returns `true` when `object` is a matcher
|
|||
|
*/
|
|||
|
function isMatcher(object) {
|
|||
|
return isPrototypeOf(matcherPrototype, object);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isMatcher;
|
|||
|
|
|||
|
},{"./matcher-prototype":67,"@sinonjs/commons":45}],66:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var every = require("@sinonjs/commons").prototypes.array.every;
|
|||
|
var concat = require("@sinonjs/commons").prototypes.array.concat;
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
|
|||
|
var deepEqualFactory = require("../deep-equal").use;
|
|||
|
|
|||
|
var isMatcher = require("./is-matcher");
|
|||
|
|
|||
|
var keys = Object.keys;
|
|||
|
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|||
|
|
|||
|
/**
|
|||
|
* Matches `actual` with `expectation`
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} actual A value to examine
|
|||
|
* @param {object} expectation An object with properties to match on
|
|||
|
* @param {object} matcher A matcher to use for comparison
|
|||
|
* @returns {boolean} Returns true when `actual` matches all properties in `expectation`
|
|||
|
*/
|
|||
|
function matchObject(actual, expectation, matcher) {
|
|||
|
var deepEqual = deepEqualFactory(matcher);
|
|||
|
if (actual === null || actual === undefined) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
var expectedKeys = keys(expectation);
|
|||
|
/* istanbul ignore else: cannot collect coverage for engine that doesn't support Symbol */
|
|||
|
if (typeOf(getOwnPropertySymbols) === "function") {
|
|||
|
expectedKeys = concat(expectedKeys, getOwnPropertySymbols(expectation));
|
|||
|
}
|
|||
|
|
|||
|
return every(expectedKeys, function(key) {
|
|||
|
var exp = expectation[key];
|
|||
|
var act = actual[key];
|
|||
|
|
|||
|
if (isMatcher(exp)) {
|
|||
|
if (!exp.test(act)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
} else if (typeOf(exp) === "object") {
|
|||
|
if (!matchObject(act, exp, matcher)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
} else if (!deepEqual(act, exp)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
module.exports = matchObject;
|
|||
|
|
|||
|
},{"../deep-equal":69,"./is-matcher":65,"@sinonjs/commons":45}],67:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var matcherPrototype = {
|
|||
|
toString: function() {
|
|||
|
return this.message;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
matcherPrototype.or = function(valueOrMatcher) {
|
|||
|
var createMatcher = require("../create-matcher");
|
|||
|
var isMatcher = createMatcher.isMatcher;
|
|||
|
|
|||
|
if (!arguments.length) {
|
|||
|
throw new TypeError("Matcher expected");
|
|||
|
}
|
|||
|
|
|||
|
var m2 = isMatcher(valueOrMatcher)
|
|||
|
? valueOrMatcher
|
|||
|
: createMatcher(valueOrMatcher);
|
|||
|
var m1 = this;
|
|||
|
var or = Object.create(matcherPrototype);
|
|||
|
or.test = function(actual) {
|
|||
|
return m1.test(actual) || m2.test(actual);
|
|||
|
};
|
|||
|
or.message = m1.message + ".or(" + m2.message + ")";
|
|||
|
return or;
|
|||
|
};
|
|||
|
|
|||
|
matcherPrototype.and = function(valueOrMatcher) {
|
|||
|
var createMatcher = require("../create-matcher");
|
|||
|
var isMatcher = createMatcher.isMatcher;
|
|||
|
|
|||
|
if (!arguments.length) {
|
|||
|
throw new TypeError("Matcher expected");
|
|||
|
}
|
|||
|
|
|||
|
var m2 = isMatcher(valueOrMatcher)
|
|||
|
? valueOrMatcher
|
|||
|
: createMatcher(valueOrMatcher);
|
|||
|
var m1 = this;
|
|||
|
var and = Object.create(matcherPrototype);
|
|||
|
and.test = function(actual) {
|
|||
|
return m1.test(actual) && m2.test(actual);
|
|||
|
};
|
|||
|
and.message = m1.message + ".and(" + m2.message + ")";
|
|||
|
return and;
|
|||
|
};
|
|||
|
|
|||
|
module.exports = matcherPrototype;
|
|||
|
|
|||
|
},{"../create-matcher":60}],68:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var join = require("@sinonjs/commons").prototypes.array.join;
|
|||
|
var map = require("@sinonjs/commons").prototypes.array.map;
|
|||
|
var stringIndexOf = require("@sinonjs/commons").prototypes.string.indexOf;
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
var matchObject = require("./match-object");
|
|||
|
|
|||
|
var createTypeMap = function(match) {
|
|||
|
return {
|
|||
|
function: function(m, expectation, message) {
|
|||
|
m.test = expectation;
|
|||
|
m.message = message || "match(" + functionName(expectation) + ")";
|
|||
|
},
|
|||
|
number: function(m, expectation) {
|
|||
|
m.test = function(actual) {
|
|||
|
// we need type coercion here
|
|||
|
return expectation == actual; // eslint-disable-line eqeqeq
|
|||
|
};
|
|||
|
},
|
|||
|
object: function(m, expectation) {
|
|||
|
var array = [];
|
|||
|
|
|||
|
if (typeof expectation.test === "function") {
|
|||
|
m.test = function(actual) {
|
|||
|
return expectation.test(actual) === true;
|
|||
|
};
|
|||
|
m.message = "match(" + functionName(expectation.test) + ")";
|
|||
|
return m;
|
|||
|
}
|
|||
|
|
|||
|
array = map(Object.keys(expectation), function(key) {
|
|||
|
return key + ": " + valueToString(expectation[key]);
|
|||
|
});
|
|||
|
|
|||
|
m.test = function(actual) {
|
|||
|
return matchObject(actual, expectation, match);
|
|||
|
};
|
|||
|
m.message = "match(" + join(array, ", ") + ")";
|
|||
|
|
|||
|
return m;
|
|||
|
},
|
|||
|
regexp: function(m, expectation) {
|
|||
|
m.test = function(actual) {
|
|||
|
return typeof actual === "string" && expectation.test(actual);
|
|||
|
};
|
|||
|
},
|
|||
|
string: function(m, expectation) {
|
|||
|
m.test = function(actual) {
|
|||
|
return (
|
|||
|
typeof actual === "string" &&
|
|||
|
stringIndexOf(actual, expectation) !== -1
|
|||
|
);
|
|||
|
};
|
|||
|
m.message = 'match("' + expectation + '")';
|
|||
|
}
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
module.exports = createTypeMap;
|
|||
|
|
|||
|
},{"./match-object":66,"@sinonjs/commons":45}],69:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
var className = require("@sinonjs/commons").className;
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
var arrayProto = require("@sinonjs/commons").prototypes.array;
|
|||
|
var objectProto = require("@sinonjs/commons").prototypes.object;
|
|||
|
var mapForEach = require("@sinonjs/commons").prototypes.map.forEach;
|
|||
|
|
|||
|
var getClass = require("./get-class");
|
|||
|
var identical = require("./identical");
|
|||
|
var isArguments = require("./is-arguments");
|
|||
|
var isDate = require("./is-date");
|
|||
|
var isElement = require("./is-element");
|
|||
|
var isMap = require("./is-map");
|
|||
|
var isNaN = require("./is-nan");
|
|||
|
var isObject = require("./is-object");
|
|||
|
var isSet = require("./is-set");
|
|||
|
var isSubset = require("./is-subset");
|
|||
|
|
|||
|
var concat = arrayProto.concat;
|
|||
|
var every = arrayProto.every;
|
|||
|
var push = arrayProto.push;
|
|||
|
|
|||
|
var getTime = Date.prototype.getTime;
|
|||
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|||
|
var indexOf = arrayProto.indexOf;
|
|||
|
var keys = Object.keys;
|
|||
|
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|||
|
|
|||
|
/**
|
|||
|
* Deep equal comparison. Two values are "deep equal" when:
|
|||
|
*
|
|||
|
* - 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 ``actual`` is deepEqual to the corresponding property in ``expectation``
|
|||
|
*
|
|||
|
* Supports cyclic objects.
|
|||
|
*
|
|||
|
* @alias module:samsam.deepEqual
|
|||
|
* @param {*} actual The object to examine
|
|||
|
* @param {*} expectation The object actual is expected to be equal to
|
|||
|
* @param {object} match A value to match on
|
|||
|
* @returns {boolean} Returns true when actual and expectation are considered equal
|
|||
|
*/
|
|||
|
function deepEqualCyclic(actual, expectation, match) {
|
|||
|
// used for cyclic comparison
|
|||
|
// contain already visited objects
|
|||
|
var actualObjects = [];
|
|||
|
var expectationObjects = [];
|
|||
|
// contain pathes (position in the object structure)
|
|||
|
// of the already visited objects
|
|||
|
// indexes same as in objects arrays
|
|||
|
var actualPaths = [];
|
|||
|
var expectationPaths = [];
|
|||
|
// contains combinations of already compared objects
|
|||
|
// in the manner: { "$1['ref']$2['ref']": true }
|
|||
|
var compared = {};
|
|||
|
|
|||
|
// does the recursion for the deep equal check
|
|||
|
// eslint-disable-next-line complexity
|
|||
|
return (function deepEqual(
|
|||
|
actualObj,
|
|||
|
expectationObj,
|
|||
|
actualPath,
|
|||
|
expectationPath
|
|||
|
) {
|
|||
|
// If both are matchers they must be the same instance in order to be
|
|||
|
// considered equal If we didn't do that we would end up running one
|
|||
|
// matcher against the other
|
|||
|
if (match && match.isMatcher(expectationObj)) {
|
|||
|
if (match.isMatcher(actualObj)) {
|
|||
|
return actualObj === expectationObj;
|
|||
|
}
|
|||
|
return expectationObj.test(actualObj);
|
|||
|
}
|
|||
|
|
|||
|
var actualType = typeof actualObj;
|
|||
|
var expectationType = typeof expectationObj;
|
|||
|
|
|||
|
if (
|
|||
|
actualObj === expectationObj ||
|
|||
|
isNaN(actualObj) ||
|
|||
|
isNaN(expectationObj) ||
|
|||
|
actualObj === null ||
|
|||
|
expectationObj === null ||
|
|||
|
actualObj === undefined ||
|
|||
|
expectationObj === undefined ||
|
|||
|
actualType !== "object" ||
|
|||
|
expectationType !== "object"
|
|||
|
) {
|
|||
|
return identical(actualObj, expectationObj);
|
|||
|
}
|
|||
|
|
|||
|
// Elements are only equal if identical(expected, actual)
|
|||
|
if (isElement(actualObj) || isElement(expectationObj)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
var isActualDate = isDate(actualObj);
|
|||
|
var isExpectationDate = isDate(expectationObj);
|
|||
|
if (isActualDate || isExpectationDate) {
|
|||
|
if (
|
|||
|
!isActualDate ||
|
|||
|
!isExpectationDate ||
|
|||
|
getTime.call(actualObj) !== getTime.call(expectationObj)
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (actualObj instanceof RegExp && expectationObj instanceof RegExp) {
|
|||
|
if (valueToString(actualObj) !== valueToString(expectationObj)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (actualObj instanceof Error && expectationObj instanceof Error) {
|
|||
|
return actualObj === expectationObj;
|
|||
|
}
|
|||
|
|
|||
|
var actualClass = getClass(actualObj);
|
|||
|
var expectationClass = getClass(expectationObj);
|
|||
|
var actualKeys = keys(actualObj);
|
|||
|
var expectationKeys = keys(expectationObj);
|
|||
|
var actualName = className(actualObj);
|
|||
|
var expectationName = className(expectationObj);
|
|||
|
var expectationSymbols =
|
|||
|
typeOf(getOwnPropertySymbols) === "function"
|
|||
|
? getOwnPropertySymbols(expectationObj)
|
|||
|
: /* istanbul ignore next: cannot collect coverage for engine that doesn't support Symbol */
|
|||
|
[];
|
|||
|
var expectationKeysAndSymbols = concat(
|
|||
|
expectationKeys,
|
|||
|
expectationSymbols
|
|||
|
);
|
|||
|
|
|||
|
if (isArguments(actualObj) || isArguments(expectationObj)) {
|
|||
|
if (actualObj.length !== expectationObj.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (
|
|||
|
actualType !== expectationType ||
|
|||
|
actualClass !== expectationClass ||
|
|||
|
actualKeys.length !== expectationKeys.length ||
|
|||
|
(actualName &&
|
|||
|
expectationName &&
|
|||
|
actualName !== expectationName)
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (isSet(actualObj) || isSet(expectationObj)) {
|
|||
|
if (
|
|||
|
!isSet(actualObj) ||
|
|||
|
!isSet(expectationObj) ||
|
|||
|
actualObj.size !== expectationObj.size
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return isSubset(actualObj, expectationObj, deepEqual);
|
|||
|
}
|
|||
|
|
|||
|
if (isMap(actualObj) || isMap(expectationObj)) {
|
|||
|
if (
|
|||
|
!isMap(actualObj) ||
|
|||
|
!isMap(expectationObj) ||
|
|||
|
actualObj.size !== expectationObj.size
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
var mapsDeeplyEqual = true;
|
|||
|
mapForEach(actualObj, function(value, key) {
|
|||
|
mapsDeeplyEqual =
|
|||
|
mapsDeeplyEqual &&
|
|||
|
deepEqualCyclic(value, expectationObj.get(key));
|
|||
|
});
|
|||
|
|
|||
|
return mapsDeeplyEqual;
|
|||
|
}
|
|||
|
|
|||
|
return every(expectationKeysAndSymbols, function(key) {
|
|||
|
if (!hasOwnProperty(actualObj, key)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
var actualValue = actualObj[key];
|
|||
|
var expectationValue = expectationObj[key];
|
|||
|
var actualObject = isObject(actualValue);
|
|||
|
var expectationObject = isObject(expectationValue);
|
|||
|
// 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 actualIndex = actualObject
|
|||
|
? indexOf(actualObjects, actualValue)
|
|||
|
: -1;
|
|||
|
var expectationIndex = expectationObject
|
|||
|
? indexOf(expectationObjects, expectationValue)
|
|||
|
: -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 newActualPath =
|
|||
|
actualIndex !== -1
|
|||
|
? actualPaths[actualIndex]
|
|||
|
: actualPath + "[" + JSON.stringify(key) + "]";
|
|||
|
var newExpectationPath =
|
|||
|
expectationIndex !== -1
|
|||
|
? expectationPaths[expectationIndex]
|
|||
|
: expectationPath + "[" + JSON.stringify(key) + "]";
|
|||
|
var combinedPath = newActualPath + newExpectationPath;
|
|||
|
|
|||
|
// stop recursion if current objects are already compared
|
|||
|
if (compared[combinedPath]) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
// remember the current objects and their paths
|
|||
|
if (actualIndex === -1 && actualObject) {
|
|||
|
push(actualObjects, actualValue);
|
|||
|
push(actualPaths, newActualPath);
|
|||
|
}
|
|||
|
if (expectationIndex === -1 && expectationObject) {
|
|||
|
push(expectationObjects, expectationValue);
|
|||
|
push(expectationPaths, newExpectationPath);
|
|||
|
}
|
|||
|
|
|||
|
// remember that the current objects are already compared
|
|||
|
if (actualObject && expectationObject) {
|
|||
|
compared[combinedPath] = true;
|
|||
|
}
|
|||
|
|
|||
|
// End of cyclic logic
|
|||
|
|
|||
|
// neither actualValue nor expectationValue is a cycle
|
|||
|
// continue with next level
|
|||
|
return deepEqual(
|
|||
|
actualValue,
|
|||
|
expectationValue,
|
|||
|
newActualPath,
|
|||
|
newExpectationPath
|
|||
|
);
|
|||
|
});
|
|||
|
})(actual, expectation, "$1", "$2");
|
|||
|
}
|
|||
|
|
|||
|
deepEqualCyclic.use = function(match) {
|
|||
|
return function deepEqual(a, b) {
|
|||
|
return deepEqualCyclic(a, b, match);
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
module.exports = deepEqualCyclic;
|
|||
|
|
|||
|
},{"./get-class":70,"./identical":71,"./is-arguments":72,"./is-date":74,"./is-element":75,"./is-map":76,"./is-nan":77,"./is-object":79,"./is-set":80,"./is-subset":81,"@sinonjs/commons":45}],70:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var toString = require("@sinonjs/commons").prototypes.object.toString;
|
|||
|
|
|||
|
/**
|
|||
|
* 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"
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value - Any value
|
|||
|
* @returns {string} - A string representation of the `Class` of `value`
|
|||
|
*/
|
|||
|
function getClass(value) {
|
|||
|
return toString(value).split(/[ \]]/)[1];
|
|||
|
}
|
|||
|
|
|||
|
module.exports = getClass;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],71:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var isNaN = require("./is-nan");
|
|||
|
var isNegZero = require("./is-neg-zero");
|
|||
|
|
|||
|
/**
|
|||
|
* Strict equality check according to EcmaScript Harmony's `egal`.
|
|||
|
*
|
|||
|
* **From the Harmony wiki:**
|
|||
|
* > An `egal` function simply makes available the internal `SameValue` function
|
|||
|
* > from section 9.12 of the ES5 spec. If two values are egal, then they are not
|
|||
|
* > observably distinguishable.
|
|||
|
*
|
|||
|
* `identical` returns `true` when `===` is `true`, except for `-0` and
|
|||
|
* `+0`, where it returns `false`. Additionally, it returns `true` when
|
|||
|
* `NaN` is compared to itself.
|
|||
|
*
|
|||
|
* @alias module:samsam.identical
|
|||
|
* @param {*} obj1 The first value to compare
|
|||
|
* @param {*} obj2 The second value to compare
|
|||
|
* @returns {boolean} Returns `true` when the objects are *egal*, `false` otherwise
|
|||
|
*/
|
|||
|
function identical(obj1, obj2) {
|
|||
|
if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) {
|
|||
|
return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2);
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = identical;
|
|||
|
|
|||
|
},{"./is-nan":77,"./is-neg-zero":78}],72:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var getClass = require("./get-class");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `object` is an `arguments` object, `false` otherwise
|
|||
|
*
|
|||
|
* @alias module:samsam.isArguments
|
|||
|
* @param {*} object - The object to examine
|
|||
|
* @returns {boolean} `true` when `object` is an `arguments` object
|
|||
|
*/
|
|||
|
function isArguments(object) {
|
|||
|
return getClass(object) === "Arguments";
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isArguments;
|
|||
|
|
|||
|
},{"./get-class":70}],73:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var functionName = require("@sinonjs/commons").functionName;
|
|||
|
var indexOf = require("@sinonjs/commons").prototypes.array.indexOf;
|
|||
|
var map = require("@sinonjs/commons").prototypes.array.map;
|
|||
|
var ARRAY_TYPES = require("./array-types");
|
|||
|
var type = require("type-detect");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `object` is an array type, `false` otherwise
|
|||
|
*
|
|||
|
* @param {*} object - The object to examine
|
|||
|
* @returns {boolean} `true` when `object` is an array type
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function isArrayType(object) {
|
|||
|
return indexOf(map(ARRAY_TYPES, functionName), type(object)) !== -1;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isArrayType;
|
|||
|
|
|||
|
},{"./array-types":59,"@sinonjs/commons":45,"type-detect":106}],74:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `value` is an instance of Date
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Date} value The value to examine
|
|||
|
* @returns {boolean} `true` when `value` is an instance of Date
|
|||
|
*/
|
|||
|
function isDate(value) {
|
|||
|
return value instanceof Date;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isDate;
|
|||
|
|
|||
|
},{}],75:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var div = typeof document !== "undefined" && document.createElement("div");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `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`.
|
|||
|
*
|
|||
|
* @alias module:samsam.isElement
|
|||
|
* @param {object} object The object to examine
|
|||
|
* @returns {boolean} Returns `true` for DOM element nodes
|
|||
|
*/
|
|||
|
function isElement(object) {
|
|||
|
if (!object || object.nodeType !== 1 || !div) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
try {
|
|||
|
object.appendChild(div);
|
|||
|
object.removeChild(div);
|
|||
|
} catch (e) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isElement;
|
|||
|
|
|||
|
},{}],76:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `value` is a Map
|
|||
|
*
|
|||
|
* @param {*} value A value to examine
|
|||
|
* @returns {boolean} `true` when `value` is an instance of `Map`, `false` otherwise
|
|||
|
* @private
|
|||
|
*/
|
|||
|
function isMap(value) {
|
|||
|
return typeof Map !== "undefined" && value instanceof Map;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isMap;
|
|||
|
|
|||
|
},{}],77:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Compares a `value` to `NaN`
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value A value to examine
|
|||
|
* @returns {boolean} Returns `true` when `value` is `NaN`
|
|||
|
*/
|
|||
|
function isNaN(value) {
|
|||
|
// Unlike global `isNaN`, this function avoids type coercion
|
|||
|
// `typeof` check avoids IE host object issues, hat tip to
|
|||
|
// lodash
|
|||
|
|
|||
|
// eslint-disable-next-line no-self-compare
|
|||
|
return typeof value === "number" && value !== value;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isNaN;
|
|||
|
|
|||
|
},{}],78:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `value` is `-0`
|
|||
|
*
|
|||
|
* @alias module:samsam.isNegZero
|
|||
|
* @param {*} value A value to examine
|
|||
|
* @returns {boolean} Returns `true` when `value` is `-0`
|
|||
|
*/
|
|||
|
function isNegZero(value) {
|
|||
|
return value === 0 && 1 / value === -Infinity;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isNegZero;
|
|||
|
|
|||
|
},{}],79:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when the value is a regular Object and not a specialized Object
|
|||
|
*
|
|||
|
* This helps speed 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
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {object} value The object to examine
|
|||
|
* @returns {boolean} `true` when the object is a non-specialised object
|
|||
|
*/
|
|||
|
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)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isObject;
|
|||
|
|
|||
|
},{}],80:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when the argument is an instance of Set, `false` otherwise
|
|||
|
*
|
|||
|
* @alias module:samsam.isSet
|
|||
|
* @param {*} val - A value to examine
|
|||
|
* @returns {boolean} Returns `true` when the argument is an instance of Set, `false` otherwise
|
|||
|
*/
|
|||
|
function isSet(val) {
|
|||
|
return (typeof Set !== "undefined" && val instanceof Set) || false;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isSet;
|
|||
|
|
|||
|
},{}],81:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var forEach = require("@sinonjs/commons").prototypes.set.forEach;
|
|||
|
|
|||
|
/**
|
|||
|
* Returns `true` when `s1` is a subset of `s2`, `false` otherwise
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Array|Set} s1 The target value
|
|||
|
* @param {Array|Set} s2 The containing value
|
|||
|
* @param {Function} compare A comparison function, should return `true` when
|
|||
|
* values are considered equal
|
|||
|
* @returns {boolean} Returns `true` when `s1` is a subset of `s2`, `false`` otherwise
|
|||
|
*/
|
|||
|
function isSubset(s1, s2, compare) {
|
|||
|
var allContained = true;
|
|||
|
forEach(s1, function(v1) {
|
|||
|
var includes = false;
|
|||
|
forEach(s2, function(v2) {
|
|||
|
if (compare(v2, v1)) {
|
|||
|
includes = true;
|
|||
|
}
|
|||
|
});
|
|||
|
allContained = allContained && includes;
|
|||
|
});
|
|||
|
|
|||
|
return allContained;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = isSubset;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],82:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var slice = require("@sinonjs/commons").prototypes.string.slice;
|
|||
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a string represenation of an iterable object
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {object} obj The iterable object to stringify
|
|||
|
* @returns {string} A string representation
|
|||
|
*/
|
|||
|
function iterableToString(obj) {
|
|||
|
if (typeOf(obj) === "map") {
|
|||
|
return mapToString(obj);
|
|||
|
}
|
|||
|
|
|||
|
return genericIterableToString(obj);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a string representation of a Map
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Map} map The map to stringify
|
|||
|
* @returns {string} A string representation
|
|||
|
*/
|
|||
|
function mapToString(map) {
|
|||
|
var representation = "";
|
|||
|
|
|||
|
/* eslint-disable-next-line local-rules/no-prototype-methods */
|
|||
|
map.forEach(function(value, key) {
|
|||
|
representation += "[" + stringify(key) + "," + stringify(value) + "],";
|
|||
|
});
|
|||
|
|
|||
|
representation = slice(representation, 0, -1);
|
|||
|
return representation;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Create a string represenation for an iterable
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {object} iterable The iterable to stringify
|
|||
|
* @returns {string} A string representation
|
|||
|
*/
|
|||
|
function genericIterableToString(iterable) {
|
|||
|
var representation = "";
|
|||
|
|
|||
|
/* eslint-disable-next-line local-rules/no-prototype-methods */
|
|||
|
iterable.forEach(function(value) {
|
|||
|
representation += stringify(value) + ",";
|
|||
|
});
|
|||
|
|
|||
|
representation = slice(representation, 0, -1);
|
|||
|
return representation;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a string representation of the passed `item`
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {object} item The item to stringify
|
|||
|
* @returns {string} A string representation of `item`
|
|||
|
*/
|
|||
|
function stringify(item) {
|
|||
|
return typeof item === "string" ? "'" + item + "'" : valueToString(item);
|
|||
|
}
|
|||
|
|
|||
|
module.exports = iterableToString;
|
|||
|
|
|||
|
},{"@sinonjs/commons":45}],83:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|||
|
var indexOf = require("@sinonjs/commons").prototypes.string.indexOf;
|
|||
|
var forEach = require("@sinonjs/commons").prototypes.array.forEach;
|
|||
|
var type = require("type-detect");
|
|||
|
|
|||
|
var engineCanCompareMaps = typeof Array.from === "function";
|
|||
|
var deepEqual = require("./deep-equal").use(match); // eslint-disable-line no-use-before-define
|
|||
|
var isArrayType = require("./is-array-type");
|
|||
|
var isSubset = require("./is-subset");
|
|||
|
var createMatcher = require("./create-matcher");
|
|||
|
|
|||
|
/**
|
|||
|
* Returns true when `array` contains all of `subset` as defined by the `compare`
|
|||
|
* argument
|
|||
|
*
|
|||
|
* @param {Array} array An array to search for a subset
|
|||
|
* @param {Array} subset The subset to find in the array
|
|||
|
* @param {Function} compare A comparison function
|
|||
|
* @returns {boolean} [description]
|
|||
|
* @private
|
|||
|
*/
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
/* eslint-disable complexity */
|
|||
|
/**
|
|||
|
* Matches an object with a matcher (or value)
|
|||
|
*
|
|||
|
* @alias module:samsam.match
|
|||
|
* @param {object} object The object candidate to match
|
|||
|
* @param {object} matcherOrValue A matcher or value to match against
|
|||
|
* @returns {boolean} true when `object` matches `matcherOrValue`
|
|||
|
*/
|
|||
|
function match(object, matcherOrValue) {
|
|||
|
if (matcherOrValue && typeof matcherOrValue.test === "function") {
|
|||
|
return matcherOrValue.test(object);
|
|||
|
}
|
|||
|
|
|||
|
switch (type(matcherOrValue)) {
|
|||
|
case "bigint":
|
|||
|
case "boolean":
|
|||
|
case "number":
|
|||
|
case "symbol":
|
|||
|
return matcherOrValue === object;
|
|||
|
case "function":
|
|||
|
return matcherOrValue(object) === true;
|
|||
|
case "string":
|
|||
|
var notNull = typeof object === "string" || Boolean(object);
|
|||
|
return (
|
|||
|
notNull &&
|
|||
|
indexOf(
|
|||
|
valueToString(object).toLowerCase(),
|
|||
|
matcherOrValue.toLowerCase()
|
|||
|
) >= 0
|
|||
|
);
|
|||
|
case "null":
|
|||
|
return object === null;
|
|||
|
case "undefined":
|
|||
|
return typeof object === "undefined";
|
|||
|
case "Date":
|
|||
|
/* istanbul ignore else */
|
|||
|
if (type(object) === "Date") {
|
|||
|
return object.getTime() === matcherOrValue.getTime();
|
|||
|
}
|
|||
|
/* istanbul ignore next: this is basically the rest of the function, which is covered */
|
|||
|
break;
|
|||
|
case "Array":
|
|||
|
case "Int8Array":
|
|||
|
case "Uint8Array":
|
|||
|
case "Uint8ClampedArray":
|
|||
|
case "Int16Array":
|
|||
|
case "Uint16Array":
|
|||
|
case "Int32Array":
|
|||
|
case "Uint32Array":
|
|||
|
case "Float32Array":
|
|||
|
case "Float64Array":
|
|||
|
return (
|
|||
|
isArrayType(matcherOrValue) &&
|
|||
|
arrayContains(object, matcherOrValue, match)
|
|||
|
);
|
|||
|
case "Map":
|
|||
|
/* istanbul ignore next: this is covered by a test, that is only run in IE, but we collect coverage information in node*/
|
|||
|
if (!engineCanCompareMaps) {
|
|||
|
throw new Error(
|
|||
|
"The JavaScript engine does not support Array.from and cannot reliably do value comparison of Map instances"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
return (
|
|||
|
type(object) === "Map" &&
|
|||
|
arrayContains(
|
|||
|
Array.from(object),
|
|||
|
Array.from(matcherOrValue),
|
|||
|
match
|
|||
|
)
|
|||
|
);
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
switch (type(object)) {
|
|||
|
case "null":
|
|||
|
return false;
|
|||
|
case "Set":
|
|||
|
return isSubset(matcherOrValue, object, match);
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
/* istanbul ignore else */
|
|||
|
if (matcherOrValue && typeof matcherOrValue === "object") {
|
|||
|
if (matcherOrValue === object) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
if (typeof object !== "object") {
|
|||
|
return false;
|
|||
|
}
|
|||
|
var prop;
|
|||
|
// eslint-disable-next-line guard-for-in
|
|||
|
for (prop in matcherOrValue) {
|
|||
|
var value = object[prop];
|
|||
|
if (
|
|||
|
typeof value === "undefined" &&
|
|||
|
typeof object.getAttribute === "function"
|
|||
|
) {
|
|||
|
value = object.getAttribute(prop);
|
|||
|
}
|
|||
|
if (
|
|||
|
matcherOrValue[prop] === null ||
|
|||
|
typeof matcherOrValue[prop] === "undefined"
|
|||
|
) {
|
|||
|
if (value !== matcherOrValue[prop]) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
} else if (
|
|||
|
typeof value === "undefined" ||
|
|||
|
!deepEqual(value, matcherOrValue[prop])
|
|||
|
) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
/* istanbul ignore next */
|
|||
|
throw new Error("Matcher was an unknown or unsupported type");
|
|||
|
}
|
|||
|
/* eslint-enable complexity */
|
|||
|
|
|||
|
forEach(Object.keys(createMatcher), function(key) {
|
|||
|
match[key] = createMatcher[key];
|
|||
|
});
|
|||
|
|
|||
|
module.exports = match;
|
|||
|
|
|||
|
},{"./create-matcher":60,"./deep-equal":69,"./is-array-type":73,"./is-subset":81,"@sinonjs/commons":45,"type-detect":106}],84:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
/**
|
|||
|
* @module samsam
|
|||
|
*/
|
|||
|
var identical = require("./identical");
|
|||
|
var isArguments = require("./is-arguments");
|
|||
|
var isElement = require("./is-element");
|
|||
|
var isNegZero = require("./is-neg-zero");
|
|||
|
var isSet = require("./is-set");
|
|||
|
var isMap = require("./is-map");
|
|||
|
var match = require("./match");
|
|||
|
var deepEqualCyclic = require("./deep-equal").use(match);
|
|||
|
var createMatcher = require("./create-matcher");
|
|||
|
|
|||
|
module.exports = {
|
|||
|
createMatcher: createMatcher,
|
|||
|
deepEqual: deepEqualCyclic,
|
|||
|
identical: identical,
|
|||
|
isArguments: isArguments,
|
|||
|
isElement: isElement,
|
|||
|
isMap: isMap,
|
|||
|
isNegZero: isNegZero,
|
|||
|
isSet: isSet,
|
|||
|
match: match
|
|||
|
};
|
|||
|
|
|||
|
},{"./create-matcher":60,"./deep-equal":69,"./identical":71,"./is-arguments":72,"./is-element":75,"./is-map":76,"./is-neg-zero":78,"./is-set":80,"./match":83}],85:[function(require,module,exports){
|
|||
|
// This is free and unencumbered software released into the public domain.
|
|||
|
// See LICENSE.md for more information.
|
|||
|
|
|||
|
var encoding = require("./lib/encoding.js");
|
|||
|
|
|||
|
module.exports = {
|
|||
|
TextEncoder: encoding.TextEncoder,
|
|||
|
TextDecoder: encoding.TextDecoder,
|
|||
|
};
|
|||
|
|
|||
|
},{"./lib/encoding.js":87}],86:[function(require,module,exports){
|
|||
|
(function(global) {
|
|||
|
'use strict';
|
|||
|
|
|||
|
if (typeof module !== "undefined" && module.exports) {
|
|||
|
module.exports = global;
|
|||
|
}
|
|||
|
|
|||
|
global["encoding-indexes"] =
|
|||
|
{
|
|||
|
"big5":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
|
|||
|
"euc-kr":[44034,44035,44037,44038,44043,44044,44045,44046,44047,44056,44062,44063,44065,44066,44067,44069,44070,44071,44072,44073,44074,44075,44078,44082,44083,44084,null,null,null,null,null,null,44085,44086,44087,44090,44091,44093,44094,44095,44097,44098,44099,44100,44101,44102,44103,44104,44105,44106,44108,44110,44111,44112,44113,44114,44115,44117,null,null,null,null,null,null,44118,44119,44121,44122,44123,44125,44126,44127,44128,44129,44130,44131,44132,44133,44134,44135,44136,44137,44138,44139,44140,44141,44142,44143,44146,44147,44149,44150,44153,44155,44156,44157,44158,44159,44162,44167,44168,44173,44174,44175,44177,44178,44179,44181,44182,44183,44184,44185,44186,44187,44190,44194,44195,44196,44197,44198,44199,44203,44205,44206,44209,44210,44211,44212,44213,44214,44215,44218,44222,44223,44224,44226,44227,44229,44230,44231,44233,44234,44235,44237,44238,44239,44240,44241,44242,44243,44244,44246,44248,44249,44250,44251,44252,44253,44254,44255,44258,44259,44261,44262,44265,44267,44269,44270,44274,44276,44279,44280,44281,44282,44283,44286,44287,44289,44290,44291,44293,44295,44296,44297,44298,44299,44302,44304,44306,44307,44308,44309,44310,44311,44313,44314,44315,44317,44318,44319,44321,44322,44323,44324,44325,44326,44327,44328,44330,44331,44334,44335,44336,44337,44338,44339,null,null,null,null,null,null,44342,44343,44345,44346,44347,44349,44350,44351,44352,44353,44354,44355,44358,44360,44362,44363,44364,44365,44366,44367,44369,44370,44371,44373,44374,44375,null,null,null,null,null,null,44377,44378,44379,44380,44381,44382,44383,44384,44386,44388,44389,44390,44391,44392,44393,44394,44395,44398,44399,44401,44402,44407,44408,44409,44410,44414,44416,44419,44420,44421,44422,44423,44426,44427,44429,44430,44431,44433,44434,44435,44436,44437,44438,44439,44440,44441,44442,44443,44446,44447,44448,44449,44450,44451,44453,44454,44455,44456,44457,44458,44459,44460,44461,44462,44463,44464,44465,44466,44467,44468,44469,44470,44472,44473,44474,44475,44476,44477,44478,44479,44482,44483,44485,44486,44487,44489,44490,44491,44492,44493,44494,44495,44498,44500,44501,44502,44503,44504,44505,44506,44507,44509,44510,44511,44513,44514,44515,44517,44518,44519,44520,44521,44522,44523,44524,44525,44526,44527,44528,44529,44530,44531,44532,44533,44534,44535,44538,44539,44541,44542,44546,44547,44548,44549,44550,44551,44554,44556,44558,44559,44560,44561,44562,44563,44565,44566,44567,44568,44569,44570,44571,44572,null,null,null,null,null,null,44573,44574,44575,44576,44577,44578,44579,44580,44581,44582,44583,44584,44585,44586,44587,44588,44589,44590,44591,44594,44595,44597,44598,44601,44603,44604,null,null,null,null,null,null,44605,44606,44607,44610,44612,44615,44616,44617,44619,44623,44625,44626,44627,44629,44631,44632,44633,44634,44635,44638,44642,44643,44644,44646,44647,44650,44651,44653,44654,44655,44657,44658,44659,44660,44661,44662,44663,44666,44670,44671,44672,44673,44674,44675,44678,44679,44680,44681,44682,44683,44685,44686,44687,44688,44689,44690,44691,44692,44693,44694,44695,44696,44697,44698,44699,44700,44701,44702,44703,44704,44705,44706,44707,44708,44709,44710,44711,44712,44713,44714,44715,44716,44717,44718,44719,44720,44721,44722,44723,44724,44725,44726,44727,44728,44729,44730,44731,44735,44737,44738,44739,44741,44742,44743,44744,44745,44746,44747,44750,44754,44755,44756,44757,44758,44759,44762,44763,44765,44766,44767,44768,44769,44770,44771,44772,44773,44774,44775,44777,44778,44780,44782,44783,44784,44785,44786,44787,44789,44790,44791,44793,44794,44795,44797,44798,44799,44800,44801,44802,44803,44804,44805,null,null,null,null,null,null,44806,44809,44810,44811,44812,44814,44815,44817,44818,44819,44820,44821,44822,44823,44824,44825,44826,44827,44828,44829,44830,44831,44832,44833,44834,44835,null,null,null,null,null,null,44836,44837,44838,44839,44840,44841,44842,44843,44846,44847,44849,44851,44853,44854,44855,44856,44857,44858,44859,44862,44864,44868,44869,44870,44871,44874,44875,44876,44877,44878,44879,44881,44882,44883,44884,44885,44886,44887,44888,44889,44890,44891,44894,44895,44896,44897,44898,44899,44902,44903,44904,44905,44906,44907,449
|
|||
|
"gb18030":[19970,19972,19973,19974,19983,19986,19991,19999,20000,20001,20003,20006,20009,20014,20015,20017,20019,20021,20023,20028,20032,20033,20034,20036,20038,20042,20049,20053,20055,20058,20059,20066,20067,20068,20069,20071,20072,20074,20075,20076,20077,20078,20079,20082,20084,20085,20086,20087,20088,20089,20090,20091,20092,20093,20095,20096,20097,20098,20099,20100,20101,20103,20106,20112,20118,20119,20121,20124,20125,20126,20131,20138,20143,20144,20145,20148,20150,20151,20152,20153,20156,20157,20158,20168,20172,20175,20176,20178,20186,20187,20188,20192,20194,20198,20199,20201,20205,20206,20207,20209,20212,20216,20217,20218,20220,20222,20224,20226,20227,20228,20229,20230,20231,20232,20235,20236,20242,20243,20244,20245,20246,20252,20253,20257,20259,20264,20265,20268,20269,20270,20273,20275,20277,20279,20281,20283,20286,20287,20288,20289,20290,20292,20293,20295,20296,20297,20298,20299,20300,20306,20308,20310,20321,20322,20326,20328,20330,20331,20333,20334,20337,20338,20341,20343,20344,20345,20346,20349,20352,20353,20354,20357,20358,20359,20362,20364,20366,20368,20370,20371,20373,20374,20376,20377,20378,20380,20382,20383,20385,20386,20388,20395,20397,20400,20401,20402,20403,20404,20406,20407,20408,20409,20410,20411,20412,20413,20414,20416,20417,20418,20422,20423,20424,20425,20427,20428,20429,20434,20435,20436,20437,20438,20441,20443,20448,20450,20452,20453,20455,20459,20460,20464,20466,20468,20469,20470,20471,20473,20475,20476,20477,20479,20480,20481,20482,20483,20484,20485,20486,20487,20488,20489,20490,20491,20494,20496,20497,20499,20501,20502,20503,20507,20509,20510,20512,20514,20515,20516,20519,20523,20527,20528,20529,20530,20531,20532,20533,20534,20535,20536,20537,20539,20541,20543,20544,20545,20546,20548,20549,20550,20553,20554,20555,20557,20560,20561,20562,20563,20564,20566,20567,20568,20569,20571,20573,20574,20575,20576,20577,20578,20579,20580,20582,20583,20584,20585,20586,20587,20589,20590,20591,20592,20593,20594,20595,20596,20597,20600,20601,20602,20604,20605,20609,20610,20611,20612,20614,20615,20617,20618,20619,20620,20622,20623,20624,20625,20626,20627,20628,20629,20630,20631,20632,20633,20634,20635,20636,20637,20638,20639,20640,20641,20642,20644,20646,20650,20651,20653,20654,20655,20656,20657,20659,20660,20661,20662,20663,20664,20665,20668,20669,20670,20671,20672,20673,20674,20675,20676,20677,20678,20679,20680,20681,20682,20683,20684,20685,20686,20688,20689,20690,20691,20692,20693,20695,20696,20697,20699,20700,20701,20702,20703,20704,20705,20706,20707,20708,20709,20712,20713,20714,20715,20719,20720,20721,20722,20724,20726,20727,20728,20729,20730,20732,20733,20734,20735,20736,20737,20738,20739,20740,20741,20744,20745,20746,20748,20749,20750,20751,20752,20753,20755,20756,20757,20758,20759,20760,20761,20762,20763,20764,20765,20766,20767,20768,20770,20771,20772,20773,20774,20775,20776,20777,20778,20779,20780,20781,20782,20783,20784,20785,20786,20787,20788,20789,20790,20791,20792,20793,20794,20795,20796,20797,20798,20802,20807,20810,20812,20814,20815,20816,20818,20819,20823,20824,20825,20827,20829,20830,20831,20832,20833,20835,20836,20838,20839,20841,20842,20847,20850,20858,20862,20863,20867,20868,20870,20871,20874,20875,20878,20879,20880,20881,20883,20884,20888,20890,20893,20894,20895,20897,20899,20902,20903,20904,20905,20906,20909,20910,20916,20920,20921,20922,20926,20927,20929,20930,20931,20933,20936,20938,20941,20942,20944,20946,20947,20948,20949,20950,20951,20952,20953,20954,20956,20958,20959,20962,20963,20965,20966,20967,20968,20969,20970,20972,20974,20977,20978,20980,20983,20990,20996,20997,21001,21003,21004,21007,21008,21011,21012,21013,21020,21022,21023,21025,21026,21027,21029,21030,21031,21034,21036,21039,21041,21042,21044,21045,21052,21054,21060,21061,21062,21063,21064,21065,21067,21070,21071,21074,21075,21077,21079,21080,21081,21082,21083,21085,21087,21088,21090,21091,21092,21094,21096,21099,21100,21101,21102,21104,21105,21107,21108,21109,21110,21111,21112,21113,21114,21115,21116,21118,21120,21123,21124,21125,21126,21127,21129,21130,21131,21132,21133,21134,21135,21137,21138,21140,21141,21142,21143,21
|
|||
|
"gb18030-ranges":[[0,128],[36,165],[38,169],[45,178],[50,184],[81,216],[89,226],[95,235],[96,238],[100,244],[103,248],[104,251],[105,253],[109,258],[126,276],[133,284],[148,300],[172,325],[175,329],[179,334],[208,364],[306,463],[307,465],[308,467],[309,469],[310,471],[311,473],[312,475],[313,477],[341,506],[428,594],[443,610],[544,712],[545,716],[558,730],[741,930],[742,938],[749,962],[750,970],[805,1026],[819,1104],[820,1106],[7922,8209],[7924,8215],[7925,8218],[7927,8222],[7934,8231],[7943,8241],[7944,8244],[7945,8246],[7950,8252],[8062,8365],[8148,8452],[8149,8454],[8152,8458],[8164,8471],[8174,8482],[8236,8556],[8240,8570],[8262,8596],[8264,8602],[8374,8713],[8380,8720],[8381,8722],[8384,8726],[8388,8731],[8390,8737],[8392,8740],[8393,8742],[8394,8748],[8396,8751],[8401,8760],[8406,8766],[8416,8777],[8419,8781],[8424,8787],[8437,8802],[8439,8808],[8445,8816],[8482,8854],[8485,8858],[8496,8870],[8521,8896],[8603,8979],[8936,9322],[8946,9372],[9046,9548],[9050,9588],[9063,9616],[9066,9622],[9076,9634],[9092,9652],[9100,9662],[9108,9672],[9111,9676],[9113,9680],[9131,9702],[9162,9735],[9164,9738],[9218,9793],[9219,9795],[11329,11906],[11331,11909],[11334,11913],[11336,11917],[11346,11928],[11361,11944],[11363,11947],[11366,11951],[11370,11956],[11372,11960],[11375,11964],[11389,11979],[11682,12284],[11686,12292],[11687,12312],[11692,12319],[11694,12330],[11714,12351],[11716,12436],[11723,12447],[11725,12535],[11730,12543],[11736,12586],[11982,12842],[11989,12850],[12102,12964],[12336,13200],[12348,13215],[12350,13218],[12384,13253],[12393,13263],[12395,13267],[12397,13270],[12510,13384],[12553,13428],[12851,13727],[12962,13839],[12973,13851],[13738,14617],[13823,14703],[13919,14801],[13933,14816],[14080,14964],[14298,15183],[14585,15471],[14698,15585],[15583,16471],[15847,16736],[16318,17208],[16434,17325],[16438,17330],[16481,17374],[16729,17623],[17102,17997],[17122,18018],[17315,18212],[17320,18218],[17402,18301],[17418,18318],[17859,18760],[17909,18811],[17911,18814],[17915,18820],[17916,18823],[17936,18844],[17939,18848],[17961,18872],[18664,19576],[18703,19620],[18814,19738],[18962,19887],[19043,40870],[33469,59244],[33470,59336],[33471,59367],[33484,59413],[33485,59417],[33490,59423],[33497,59431],[33501,59437],[33505,59443],[33513,59452],[33520,59460],[33536,59478],[33550,59493],[37845,63789],[37921,63866],[37948,63894],[38029,63976],[38038,63986],[38064,64016],[38065,64018],[38066,64021],[38069,64025],[38075,64034],[38076,64037],[38078,64042],[39108,65074],[39109,65093],[39113,65107],[39114,65112],[39115,65127],[39116,65132],[39265,65375],[39394,65510],[189000,65536]],
|
|||
|
"jis0208":[12288,12289,12290,65292,65294,12539,65306,65307,65311,65281,12443,12444,180,65344,168,65342,65507,65343,12541,12542,12445,12446,12291,20189,12293,12294,12295,12540,8213,8208,65295,65340,65374,8741,65372,8230,8229,8216,8217,8220,8221,65288,65289,12308,12309,65339,65341,65371,65373,12296,12297,12298,12299,12300,12301,12302,12303,12304,12305,65291,65293,177,215,247,65309,8800,65308,65310,8806,8807,8734,8756,9794,9792,176,8242,8243,8451,65509,65284,65504,65505,65285,65283,65286,65290,65312,167,9734,9733,9675,9679,9678,9671,9670,9633,9632,9651,9650,9661,9660,8251,12306,8594,8592,8593,8595,12307,null,null,null,null,null,null,null,null,null,null,null,8712,8715,8838,8839,8834,8835,8746,8745,null,null,null,null,null,null,null,null,8743,8744,65506,8658,8660,8704,8707,null,null,null,null,null,null,null,null,null,null,null,8736,8869,8978,8706,8711,8801,8786,8810,8811,8730,8765,8733,8757,8747,8748,null,null,null,null,null,null,null,8491,8240,9839,9837,9834,8224,8225,182,null,null,null,null,9711,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,65296,65297,65298,65299,65300,65301,65302,65303,65304,65305,null,null,null,null,null,null,null,65313,65314,65315,65316,65317,65318,65319,65320,65321,65322,65323,65324,65325,65326,65327,65328,65329,65330,65331,65332,65333,65334,65335,65336,65337,65338,null,null,null,null,null,null,65345,65346,65347,65348,65349,65350,65351,65352,65353,65354,65355,65356,65357,65358,65359,65360,65361,65362,65363,65364,65365,65366,65367,65368,65369,65370,null,null,null,null,12353,12354,12355,12356,12357,12358,12359,12360,12361,12362,12363,12364,12365,12366,12367,12368,12369,12370,12371,12372,12373,12374,12375,12376,12377,12378,12379,12380,12381,12382,12383,12384,12385,12386,12387,12388,12389,12390,12391,12392,12393,12394,12395,12396,12397,12398,12399,12400,12401,12402,12403,12404,12405,12406,12407,12408,12409,12410,12411,12412,12413,12414,12415,12416,12417,12418,12419,12420,12421,12422,12423,12424,12425,12426,12427,12428,12429,12430,12431,12432,12433,12434,12435,null,null,null,null,null,null,null,null,null,null,null,12449,12450,12451,12452,12453,12454,12455,12456,12457,12458,12459,12460,12461,12462,12463,12464,12465,12466,12467,12468,12469,12470,12471,12472,12473,12474,12475,12476,12477,12478,12479,12480,12481,12482,12483,12484,12485,12486,12487,12488,12489,12490,12491,12492,12493,12494,12495,12496,12497,12498,12499,12500,12501,12502,12503,12504,12505,12506,12507,12508,12509,12510,12511,12512,12513,12514,12515,12516,12517,12518,12519,12520,12521,12522,12523,12524,12525,12526,12527,12528,12529,12530,12531,12532,12533,12534,null,null,null,null,null,null,null,null,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936,937,null,null,null,null,null,null,null,null,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,963,964,965,966,967,968,969,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1040,1041,1042,1043,1044,1045,1025,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1072,1073,1074,1075,1076,1077,1105,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,null,null,null,null,null,null,null,null,null,null,null,null,null,9472,9474,9484,9488,9496,9492,9500,9516,9508,9524,9532,9473,9475,9487,9491,9499,9495,9507,9523,9515,9531,9547,9504,9519,9512,9527,9535,9501,9520,9509,9528,9538,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,nu
|
|||
|
"jis0212":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,728,711,184,729,733,175,731,730,65374,900,901,null,null,null,null,null,null,null,null,161,166,191,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,186,170,169,174,8482,164,8470,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,902,904,905,906,938,null,908,null,910,939,null,911,null,null,null,null,940,941,942,943,970,912,972,962,973,971,944,974,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1038,1039,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1118,1119,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,198,272,null,294,null,306,null,321,319,null,330,216,338,null,358,222,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,230,273,240,295,305,307,312,322,320,329,331,248,339,223,359,254,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,nu
|
|||
|
"ibm866":[1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1025,1105,1028,1108,1031,1111,1038,1118,176,8729,183,8730,8470,164,9632,160],
|
|||
|
"iso-8859-2":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,260,728,321,164,317,346,167,168,352,350,356,377,173,381,379,176,261,731,322,180,318,347,711,184,353,351,357,378,733,382,380,340,193,194,258,196,313,262,199,268,201,280,203,282,205,206,270,272,323,327,211,212,336,214,215,344,366,218,368,220,221,354,223,341,225,226,259,228,314,263,231,269,233,281,235,283,237,238,271,273,324,328,243,244,337,246,247,345,367,250,369,252,253,355,729],
|
|||
|
"iso-8859-3":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,294,728,163,164,null,292,167,168,304,350,286,308,173,null,379,176,295,178,179,180,181,293,183,184,305,351,287,309,189,null,380,192,193,194,null,196,266,264,199,200,201,202,203,204,205,206,207,null,209,210,211,212,288,214,215,284,217,218,219,220,364,348,223,224,225,226,null,228,267,265,231,232,233,234,235,236,237,238,239,null,241,242,243,244,289,246,247,285,249,250,251,252,365,349,729],
|
|||
|
"iso-8859-4":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,260,312,342,164,296,315,167,168,352,274,290,358,173,381,175,176,261,731,343,180,297,316,711,184,353,275,291,359,330,382,331,256,193,194,195,196,197,198,302,268,201,280,203,278,205,206,298,272,325,332,310,212,213,214,215,216,370,218,219,220,360,362,223,257,225,226,227,228,229,230,303,269,233,281,235,279,237,238,299,273,326,333,311,244,245,246,247,248,371,250,251,252,361,363,729],
|
|||
|
"iso-8859-5":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,173,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,8470,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,167,1118,1119],
|
|||
|
"iso-8859-6":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,null,null,null,164,null,null,null,null,null,null,null,1548,173,null,null,null,null,null,null,null,null,null,null,null,null,null,1563,null,null,null,1567,null,1569,1570,1571,1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586,1587,1588,1589,1590,1591,1592,1593,1594,null,null,null,null,null,1600,1601,1602,1603,1604,1605,1606,1607,1608,1609,1610,1611,1612,1613,1614,1615,1616,1617,1618,null,null,null,null,null,null,null,null,null,null,null,null,null],
|
|||
|
"iso-8859-7":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,8216,8217,163,8364,8367,166,167,168,169,890,171,172,173,null,8213,176,177,178,179,900,901,902,183,904,905,906,187,908,189,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,null,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,null],
|
|||
|
"iso-8859-8":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,null,162,163,164,165,166,167,168,169,215,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,247,187,188,189,190,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,8215,1488,1489,1490,1491,1492,1493,1494,1495,1496,1497,1498,1499,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510,1511,1512,1513,1514,null,null,8206,8207,null],
|
|||
|
"iso-8859-10":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,260,274,290,298,296,310,167,315,272,352,358,381,173,362,330,176,261,275,291,299,297,311,183,316,273,353,359,382,8213,363,331,256,193,194,195,196,197,198,302,268,201,280,203,278,205,206,207,208,325,332,211,212,213,214,360,216,370,218,219,220,221,222,223,257,225,226,227,228,229,230,303,269,233,281,235,279,237,238,239,240,326,333,243,244,245,246,361,248,371,250,251,252,253,254,312],
|
|||
|
"iso-8859-13":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,8221,162,163,164,8222,166,167,216,169,342,171,172,173,174,198,176,177,178,179,8220,181,182,183,248,185,343,187,188,189,190,230,260,302,256,262,196,197,280,274,268,201,377,278,290,310,298,315,352,323,325,211,332,213,214,215,370,321,346,362,220,379,381,223,261,303,257,263,228,229,281,275,269,233,378,279,291,311,299,316,353,324,326,243,333,245,246,247,371,322,347,363,252,380,382,8217],
|
|||
|
"iso-8859-14":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,7682,7683,163,266,267,7690,167,7808,169,7810,7691,7922,173,174,376,7710,7711,288,289,7744,7745,182,7766,7809,7767,7811,7776,7923,7812,7813,7777,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,372,209,210,211,212,213,214,7786,216,217,218,219,220,221,374,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,373,241,242,243,244,245,246,7787,248,249,250,251,252,253,375,255],
|
|||
|
"iso-8859-15":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,8364,165,352,167,353,169,170,171,172,173,174,175,176,177,178,179,381,181,182,183,382,185,186,187,338,339,376,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255],
|
|||
|
"iso-8859-16":[128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,260,261,321,8364,8222,352,167,353,169,536,171,377,173,378,379,176,177,268,322,381,8221,182,183,382,269,537,187,338,339,376,380,192,193,194,258,196,262,198,199,200,201,202,203,204,205,206,207,272,323,210,211,212,336,214,346,368,217,218,219,220,280,538,223,224,225,226,259,228,263,230,231,232,233,234,235,236,237,238,239,273,324,242,243,244,337,246,347,369,249,250,251,252,281,539,255],
|
|||
|
"koi8-r":[9472,9474,9484,9488,9492,9496,9500,9508,9516,9524,9532,9600,9604,9608,9612,9616,9617,9618,9619,8992,9632,8729,8730,8776,8804,8805,160,8993,176,178,183,247,9552,9553,9554,1105,9555,9556,9557,9558,9559,9560,9561,9562,9563,9564,9565,9566,9567,9568,9569,1025,9570,9571,9572,9573,9574,9575,9576,9577,9578,9579,9580,169,1102,1072,1073,1094,1076,1077,1092,1075,1093,1080,1081,1082,1083,1084,1085,1086,1087,1103,1088,1089,1090,1091,1078,1074,1100,1099,1079,1096,1101,1097,1095,1098,1070,1040,1041,1062,1044,1045,1060,1043,1061,1048,1049,1050,1051,1052,1053,1054,1055,1071,1056,1057,1058,1059,1046,1042,1068,1067,1047,1064,1069,1065,1063,1066],
|
|||
|
"koi8-u":[9472,9474,9484,9488,9492,9496,9500,9508,9516,9524,9532,9600,9604,9608,9612,9616,9617,9618,9619,8992,9632,8729,8730,8776,8804,8805,160,8993,176,178,183,247,9552,9553,9554,1105,1108,9556,1110,1111,9559,9560,9561,9562,9563,1169,1118,9566,9567,9568,9569,1025,1028,9571,1030,1031,9574,9575,9576,9577,9578,1168,1038,169,1102,1072,1073,1094,1076,1077,1092,1075,1093,1080,1081,1082,1083,1084,1085,1086,1087,1103,1088,1089,1090,1091,1078,1074,1100,1099,1079,1096,1101,1097,1095,1098,1070,1040,1041,1062,1044,1045,1060,1043,1061,1048,1049,1050,1051,1052,1053,1054,1055,1071,1056,1057,1058,1059,1046,1042,1068,1067,1047,1064,1069,1065,1063,1066],
|
|||
|
"macintosh":[196,197,199,201,209,214,220,225,224,226,228,227,229,231,233,232,234,235,237,236,238,239,241,243,242,244,246,245,250,249,251,252,8224,176,162,163,167,8226,182,223,174,169,8482,180,168,8800,198,216,8734,177,8804,8805,165,181,8706,8721,8719,960,8747,170,186,937,230,248,191,161,172,8730,402,8776,8710,171,187,8230,160,192,195,213,338,339,8211,8212,8220,8221,8216,8217,247,9674,255,376,8260,8364,8249,8250,64257,64258,8225,183,8218,8222,8240,194,202,193,203,200,205,206,207,204,211,212,63743,210,218,219,217,305,710,732,175,728,729,730,184,733,731,711],
|
|||
|
"windows-874":[8364,129,130,131,132,8230,134,135,136,137,138,139,140,141,142,143,144,8216,8217,8220,8221,8226,8211,8212,152,153,154,155,156,157,158,159,160,3585,3586,3587,3588,3589,3590,3591,3592,3593,3594,3595,3596,3597,3598,3599,3600,3601,3602,3603,3604,3605,3606,3607,3608,3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,3619,3620,3621,3622,3623,3624,3625,3626,3627,3628,3629,3630,3631,3632,3633,3634,3635,3636,3637,3638,3639,3640,3641,3642,null,null,null,null,3647,3648,3649,3650,3651,3652,3653,3654,3655,3656,3657,3658,3659,3660,3661,3662,3663,3664,3665,3666,3667,3668,3669,3670,3671,3672,3673,3674,3675,null,null,null,null],
|
|||
|
"windows-1250":[8364,129,8218,131,8222,8230,8224,8225,136,8240,352,8249,346,356,381,377,144,8216,8217,8220,8221,8226,8211,8212,152,8482,353,8250,347,357,382,378,160,711,728,321,164,260,166,167,168,169,350,171,172,173,174,379,176,177,731,322,180,181,182,183,184,261,351,187,317,733,318,380,340,193,194,258,196,313,262,199,268,201,280,203,282,205,206,270,272,323,327,211,212,336,214,215,344,366,218,368,220,221,354,223,341,225,226,259,228,314,263,231,269,233,281,235,283,237,238,271,273,324,328,243,244,337,246,247,345,367,250,369,252,253,355,729],
|
|||
|
"windows-1251":[1026,1027,8218,1107,8222,8230,8224,8225,8364,8240,1033,8249,1034,1036,1035,1039,1106,8216,8217,8220,8221,8226,8211,8212,152,8482,1113,8250,1114,1116,1115,1119,160,1038,1118,1032,164,1168,166,167,1025,169,1028,171,172,173,174,1031,176,177,1030,1110,1169,181,182,183,1105,8470,1108,187,1112,1029,1109,1111,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103],
|
|||
|
"windows-1252":[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255],
|
|||
|
"windows-1253":[8364,129,8218,402,8222,8230,8224,8225,136,8240,138,8249,140,141,142,143,144,8216,8217,8220,8221,8226,8211,8212,152,8482,154,8250,156,157,158,159,160,901,902,163,164,165,166,167,168,169,null,171,172,173,174,8213,176,177,178,179,900,181,182,183,904,905,906,187,908,189,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,null,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,null],
|
|||
|
"windows-1254":[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,142,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,158,376,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,286,209,210,211,212,213,214,215,216,217,218,219,220,304,350,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,287,241,242,243,244,245,246,247,248,249,250,251,252,305,351,255],
|
|||
|
"windows-1255":[8364,129,8218,402,8222,8230,8224,8225,710,8240,138,8249,140,141,142,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,154,8250,156,157,158,159,160,161,162,163,8362,165,166,167,168,169,215,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,247,187,188,189,190,191,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471,1472,1473,1474,1475,1520,1521,1522,1523,1524,null,null,null,null,null,null,null,1488,1489,1490,1491,1492,1493,1494,1495,1496,1497,1498,1499,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510,1511,1512,1513,1514,null,null,8206,8207,null],
|
|||
|
"windows-1256":[8364,1662,8218,402,8222,8230,8224,8225,710,8240,1657,8249,338,1670,1688,1672,1711,8216,8217,8220,8221,8226,8211,8212,1705,8482,1681,8250,339,8204,8205,1722,160,1548,162,163,164,165,166,167,168,169,1726,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,1563,187,188,189,190,1567,1729,1569,1570,1571,1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586,1587,1588,1589,1590,215,1591,1592,1593,1594,1600,1601,1602,1603,224,1604,226,1605,1606,1607,1608,231,232,233,234,235,1609,1610,238,239,1611,1612,1613,1614,244,1615,1616,247,1617,249,1618,251,252,8206,8207,1746],
|
|||
|
"windows-1257":[8364,129,8218,131,8222,8230,8224,8225,136,8240,138,8249,140,168,711,184,144,8216,8217,8220,8221,8226,8211,8212,152,8482,154,8250,156,175,731,159,160,null,162,163,164,null,166,167,216,169,342,171,172,173,174,198,176,177,178,179,180,181,182,183,248,185,343,187,188,189,190,230,260,302,256,262,196,197,280,274,268,201,377,278,290,310,298,315,352,323,325,211,332,213,214,215,370,321,346,362,220,379,381,223,261,303,257,263,228,229,281,275,269,233,378,279,291,311,299,316,353,324,326,243,333,245,246,247,371,322,347,363,252,380,382,729],
|
|||
|
"windows-1258":[8364,129,8218,402,8222,8230,8224,8225,710,8240,138,8249,338,141,142,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,154,8250,339,157,158,376,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,258,196,197,198,199,200,201,202,203,768,205,206,207,272,209,777,211,212,416,214,215,216,217,218,219,220,431,771,223,224,225,226,259,228,229,230,231,232,233,234,235,769,237,238,239,273,241,803,243,244,417,246,247,248,249,250,251,252,432,8363,255],
|
|||
|
"x-mac-cyrillic":[1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,8224,176,1168,163,167,8226,182,1030,174,169,8482,1026,1106,8800,1027,1107,8734,177,8804,8805,1110,181,1169,1032,1028,1108,1031,1111,1033,1113,1034,1114,1112,1029,172,8730,402,8776,8710,171,187,8230,160,1035,1115,1036,1116,1109,8211,8212,8220,8221,8216,8217,247,8222,1038,1118,1039,1119,8470,1025,1105,1103,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,8364]
|
|||
|
};
|
|||
|
|
|||
|
// For strict environments where `this` inside the global scope
|
|||
|
// is `undefined`, take a pure object instead
|
|||
|
}(this || {}));
|
|||
|
},{}],87:[function(require,module,exports){
|
|||
|
// This is free and unencumbered software released into the public domain.
|
|||
|
// See LICENSE.md for more information.
|
|||
|
|
|||
|
/**
|
|||
|
* @fileoverview Global |this| required for resolving indexes in node.
|
|||
|
* @suppress {globalThis}
|
|||
|
*/
|
|||
|
(function(global) {
|
|||
|
'use strict';
|
|||
|
|
|||
|
// If we're in node require encoding-indexes and attach it to the global.
|
|||
|
if (typeof module !== "undefined" && module.exports &&
|
|||
|
!global["encoding-indexes"]) {
|
|||
|
global["encoding-indexes"] =
|
|||
|
require("./encoding-indexes.js")["encoding-indexes"];
|
|||
|
}
|
|||
|
|
|||
|
//
|
|||
|
// Utilities
|
|||
|
//
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} a The number to test.
|
|||
|
* @param {number} min The minimum value in the range, inclusive.
|
|||
|
* @param {number} max The maximum value in the range, inclusive.
|
|||
|
* @return {boolean} True if a >= min and a <= max.
|
|||
|
*/
|
|||
|
function inRange(a, min, max) {
|
|||
|
return min <= a && a <= max;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {!Array.<*>} array The array to check.
|
|||
|
* @param {*} item The item to look for in the array.
|
|||
|
* @return {boolean} True if the item appears in the array.
|
|||
|
*/
|
|||
|
function includes(array, item) {
|
|||
|
return array.indexOf(item) !== -1;
|
|||
|
}
|
|||
|
|
|||
|
var floor = Math.floor;
|
|||
|
|
|||
|
/**
|
|||
|
* @param {*} o
|
|||
|
* @return {Object}
|
|||
|
*/
|
|||
|
function ToDictionary(o) {
|
|||
|
if (o === undefined) return {};
|
|||
|
if (o === Object(o)) return o;
|
|||
|
throw TypeError('Could not convert argument to dictionary');
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {string} string Input string of UTF-16 code units.
|
|||
|
* @return {!Array.<number>} Code points.
|
|||
|
*/
|
|||
|
function stringToCodePoints(string) {
|
|||
|
// https://heycam.github.io/webidl/#dfn-obtain-unicode
|
|||
|
|
|||
|
// 1. Let S be the DOMString value.
|
|||
|
var s = String(string);
|
|||
|
|
|||
|
// 2. Let n be the length of S.
|
|||
|
var n = s.length;
|
|||
|
|
|||
|
// 3. Initialize i to 0.
|
|||
|
var i = 0;
|
|||
|
|
|||
|
// 4. Initialize U to be an empty sequence of Unicode characters.
|
|||
|
var u = [];
|
|||
|
|
|||
|
// 5. While i < n:
|
|||
|
while (i < n) {
|
|||
|
|
|||
|
// 1. Let c be the code unit in S at index i.
|
|||
|
var c = s.charCodeAt(i);
|
|||
|
|
|||
|
// 2. Depending on the value of c:
|
|||
|
|
|||
|
// c < 0xD800 or c > 0xDFFF
|
|||
|
if (c < 0xD800 || c > 0xDFFF) {
|
|||
|
// Append to U the Unicode character with code point c.
|
|||
|
u.push(c);
|
|||
|
}
|
|||
|
|
|||
|
// 0xDC00 ≤ c ≤ 0xDFFF
|
|||
|
else if (0xDC00 <= c && c <= 0xDFFF) {
|
|||
|
// Append to U a U+FFFD REPLACEMENT CHARACTER.
|
|||
|
u.push(0xFFFD);
|
|||
|
}
|
|||
|
|
|||
|
// 0xD800 ≤ c ≤ 0xDBFF
|
|||
|
else if (0xD800 <= c && c <= 0xDBFF) {
|
|||
|
// 1. If i = n−1, then append to U a U+FFFD REPLACEMENT
|
|||
|
// CHARACTER.
|
|||
|
if (i === n - 1) {
|
|||
|
u.push(0xFFFD);
|
|||
|
}
|
|||
|
// 2. Otherwise, i < n−1:
|
|||
|
else {
|
|||
|
// 1. Let d be the code unit in S at index i+1.
|
|||
|
var d = s.charCodeAt(i + 1);
|
|||
|
|
|||
|
// 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:
|
|||
|
if (0xDC00 <= d && d <= 0xDFFF) {
|
|||
|
// 1. Let a be c & 0x3FF.
|
|||
|
var a = c & 0x3FF;
|
|||
|
|
|||
|
// 2. Let b be d & 0x3FF.
|
|||
|
var b = d & 0x3FF;
|
|||
|
|
|||
|
// 3. Append to U the Unicode character with code point
|
|||
|
// 2^16+2^10*a+b.
|
|||
|
u.push(0x10000 + (a << 10) + b);
|
|||
|
|
|||
|
// 4. Set i to i+1.
|
|||
|
i += 1;
|
|||
|
}
|
|||
|
|
|||
|
// 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a
|
|||
|
// U+FFFD REPLACEMENT CHARACTER.
|
|||
|
else {
|
|||
|
u.push(0xFFFD);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 3. Set i to i+1.
|
|||
|
i += 1;
|
|||
|
}
|
|||
|
|
|||
|
// 6. Return U.
|
|||
|
return u;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {!Array.<number>} code_points Array of code points.
|
|||
|
* @return {string} string String of UTF-16 code units.
|
|||
|
*/
|
|||
|
function codePointsToString(code_points) {
|
|||
|
var s = '';
|
|||
|
for (var i = 0; i < code_points.length; ++i) {
|
|||
|
var cp = code_points[i];
|
|||
|
if (cp <= 0xFFFF) {
|
|||
|
s += String.fromCharCode(cp);
|
|||
|
} else {
|
|||
|
cp -= 0x10000;
|
|||
|
s += String.fromCharCode((cp >> 10) + 0xD800,
|
|||
|
(cp & 0x3FF) + 0xDC00);
|
|||
|
}
|
|||
|
}
|
|||
|
return s;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// Implementation of Encoding specification
|
|||
|
// https://encoding.spec.whatwg.org/
|
|||
|
//
|
|||
|
|
|||
|
//
|
|||
|
// 4. Terminology
|
|||
|
//
|
|||
|
|
|||
|
/**
|
|||
|
* An ASCII byte is a byte in the range 0x00 to 0x7F, inclusive.
|
|||
|
* @param {number} a The number to test.
|
|||
|
* @return {boolean} True if a is in the range 0x00 to 0x7F, inclusive.
|
|||
|
*/
|
|||
|
function isASCIIByte(a) {
|
|||
|
return 0x00 <= a && a <= 0x7F;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* An ASCII code point is a code point in the range U+0000 to
|
|||
|
* U+007F, inclusive.
|
|||
|
*/
|
|||
|
var isASCIICodePoint = isASCIIByte;
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* End-of-stream is a special token that signifies no more tokens
|
|||
|
* are in the stream.
|
|||
|
* @const
|
|||
|
*/ var end_of_stream = -1;
|
|||
|
|
|||
|
/**
|
|||
|
* A stream represents an ordered sequence of tokens.
|
|||
|
*
|
|||
|
* @constructor
|
|||
|
* @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
|
|||
|
* the stream.
|
|||
|
*/
|
|||
|
function Stream(tokens) {
|
|||
|
/** @type {!Array.<number>} */
|
|||
|
this.tokens = [].slice.call(tokens);
|
|||
|
// Reversed as push/pop is more efficient than shift/unshift.
|
|||
|
this.tokens.reverse();
|
|||
|
}
|
|||
|
|
|||
|
Stream.prototype = {
|
|||
|
/**
|
|||
|
* @return {boolean} True if end-of-stream has been hit.
|
|||
|
*/
|
|||
|
endOfStream: function() {
|
|||
|
return !this.tokens.length;
|
|||
|
},
|
|||
|
|
|||
|
/**
|
|||
|
* When a token is read from a stream, the first token in the
|
|||
|
* stream must be returned and subsequently removed, and
|
|||
|
* end-of-stream must be returned otherwise.
|
|||
|
*
|
|||
|
* @return {number} Get the next token from the stream, or
|
|||
|
* end_of_stream.
|
|||
|
*/
|
|||
|
read: function() {
|
|||
|
if (!this.tokens.length)
|
|||
|
return end_of_stream;
|
|||
|
return this.tokens.pop();
|
|||
|
},
|
|||
|
|
|||
|
/**
|
|||
|
* When one or more tokens are prepended to a stream, those tokens
|
|||
|
* must be inserted, in given order, before the first token in the
|
|||
|
* stream.
|
|||
|
*
|
|||
|
* @param {(number|!Array.<number>)} token The token(s) to prepend to the
|
|||
|
* stream.
|
|||
|
*/
|
|||
|
prepend: function(token) {
|
|||
|
if (Array.isArray(token)) {
|
|||
|
var tokens = /**@type {!Array.<number>}*/(token);
|
|||
|
while (tokens.length)
|
|||
|
this.tokens.push(tokens.pop());
|
|||
|
} else {
|
|||
|
this.tokens.push(token);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
/**
|
|||
|
* When one or more tokens are pushed to a stream, those tokens
|
|||
|
* must be inserted, in given order, after the last token in the
|
|||
|
* stream.
|
|||
|
*
|
|||
|
* @param {(number|!Array.<number>)} token The tokens(s) to push to the
|
|||
|
* stream.
|
|||
|
*/
|
|||
|
push: function(token) {
|
|||
|
if (Array.isArray(token)) {
|
|||
|
var tokens = /**@type {!Array.<number>}*/(token);
|
|||
|
while (tokens.length)
|
|||
|
this.tokens.unshift(tokens.shift());
|
|||
|
} else {
|
|||
|
this.tokens.unshift(token);
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
//
|
|||
|
// 5. Encodings
|
|||
|
//
|
|||
|
|
|||
|
// 5.1 Encoders and decoders
|
|||
|
|
|||
|
/** @const */
|
|||
|
var finished = -1;
|
|||
|
|
|||
|
/**
|
|||
|
* @param {boolean} fatal If true, decoding errors raise an exception.
|
|||
|
* @param {number=} opt_code_point Override the standard fallback code point.
|
|||
|
* @return {number} The code point to insert on a decoding error.
|
|||
|
*/
|
|||
|
function decoderError(fatal, opt_code_point) {
|
|||
|
if (fatal)
|
|||
|
throw TypeError('Decoder error');
|
|||
|
return opt_code_point || 0xFFFD;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} code_point The code point that could not be encoded.
|
|||
|
* @return {number} Always throws, no value is actually returned.
|
|||
|
*/
|
|||
|
function encoderError(code_point) {
|
|||
|
throw TypeError('The code point ' + code_point + ' could not be encoded.');
|
|||
|
}
|
|||
|
|
|||
|
/** @interface */
|
|||
|
function Decoder() {}
|
|||
|
Decoder.prototype = {
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point, or |finished|.
|
|||
|
*/
|
|||
|
handler: function(stream, bite) {}
|
|||
|
};
|
|||
|
|
|||
|
/** @interface */
|
|||
|
function Encoder() {}
|
|||
|
Encoder.prototype = {
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of code points being encoded.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.
|
|||
|
*/
|
|||
|
handler: function(stream, code_point) {}
|
|||
|
};
|
|||
|
|
|||
|
// 5.2 Names and labels
|
|||
|
|
|||
|
// TODO: Define @typedef for Encoding: {name:string,labels:Array.<string>}
|
|||
|
// https://github.com/google/closure-compiler/issues/247
|
|||
|
|
|||
|
/**
|
|||
|
* @param {string} label The encoding label.
|
|||
|
* @return {?{name:string,labels:Array.<string>}}
|
|||
|
*/
|
|||
|
function getEncoding(label) {
|
|||
|
// 1. Remove any leading and trailing ASCII whitespace from label.
|
|||
|
label = String(label).trim().toLowerCase();
|
|||
|
|
|||
|
// 2. If label is an ASCII case-insensitive match for any of the
|
|||
|
// labels listed in the table below, return the corresponding
|
|||
|
// encoding, and failure otherwise.
|
|||
|
if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) {
|
|||
|
return label_to_encoding[label];
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Encodings table: https://encoding.spec.whatwg.org/encodings.json
|
|||
|
* @const
|
|||
|
* @type {!Array.<{
|
|||
|
* heading: string,
|
|||
|
* encodings: Array.<{name:string,labels:Array.<string>}>
|
|||
|
* }>}
|
|||
|
*/
|
|||
|
var encodings = [
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"unicode-1-1-utf-8",
|
|||
|
"utf-8",
|
|||
|
"utf8"
|
|||
|
],
|
|||
|
"name": "UTF-8"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "The Encoding"
|
|||
|
},
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"866",
|
|||
|
"cp866",
|
|||
|
"csibm866",
|
|||
|
"ibm866"
|
|||
|
],
|
|||
|
"name": "IBM866"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatin2",
|
|||
|
"iso-8859-2",
|
|||
|
"iso-ir-101",
|
|||
|
"iso8859-2",
|
|||
|
"iso88592",
|
|||
|
"iso_8859-2",
|
|||
|
"iso_8859-2:1987",
|
|||
|
"l2",
|
|||
|
"latin2"
|
|||
|
],
|
|||
|
"name": "ISO-8859-2"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatin3",
|
|||
|
"iso-8859-3",
|
|||
|
"iso-ir-109",
|
|||
|
"iso8859-3",
|
|||
|
"iso88593",
|
|||
|
"iso_8859-3",
|
|||
|
"iso_8859-3:1988",
|
|||
|
"l3",
|
|||
|
"latin3"
|
|||
|
],
|
|||
|
"name": "ISO-8859-3"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatin4",
|
|||
|
"iso-8859-4",
|
|||
|
"iso-ir-110",
|
|||
|
"iso8859-4",
|
|||
|
"iso88594",
|
|||
|
"iso_8859-4",
|
|||
|
"iso_8859-4:1988",
|
|||
|
"l4",
|
|||
|
"latin4"
|
|||
|
],
|
|||
|
"name": "ISO-8859-4"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatincyrillic",
|
|||
|
"cyrillic",
|
|||
|
"iso-8859-5",
|
|||
|
"iso-ir-144",
|
|||
|
"iso8859-5",
|
|||
|
"iso88595",
|
|||
|
"iso_8859-5",
|
|||
|
"iso_8859-5:1988"
|
|||
|
],
|
|||
|
"name": "ISO-8859-5"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"arabic",
|
|||
|
"asmo-708",
|
|||
|
"csiso88596e",
|
|||
|
"csiso88596i",
|
|||
|
"csisolatinarabic",
|
|||
|
"ecma-114",
|
|||
|
"iso-8859-6",
|
|||
|
"iso-8859-6-e",
|
|||
|
"iso-8859-6-i",
|
|||
|
"iso-ir-127",
|
|||
|
"iso8859-6",
|
|||
|
"iso88596",
|
|||
|
"iso_8859-6",
|
|||
|
"iso_8859-6:1987"
|
|||
|
],
|
|||
|
"name": "ISO-8859-6"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatingreek",
|
|||
|
"ecma-118",
|
|||
|
"elot_928",
|
|||
|
"greek",
|
|||
|
"greek8",
|
|||
|
"iso-8859-7",
|
|||
|
"iso-ir-126",
|
|||
|
"iso8859-7",
|
|||
|
"iso88597",
|
|||
|
"iso_8859-7",
|
|||
|
"iso_8859-7:1987",
|
|||
|
"sun_eu_greek"
|
|||
|
],
|
|||
|
"name": "ISO-8859-7"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csiso88598e",
|
|||
|
"csisolatinhebrew",
|
|||
|
"hebrew",
|
|||
|
"iso-8859-8",
|
|||
|
"iso-8859-8-e",
|
|||
|
"iso-ir-138",
|
|||
|
"iso8859-8",
|
|||
|
"iso88598",
|
|||
|
"iso_8859-8",
|
|||
|
"iso_8859-8:1988",
|
|||
|
"visual"
|
|||
|
],
|
|||
|
"name": "ISO-8859-8"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csiso88598i",
|
|||
|
"iso-8859-8-i",
|
|||
|
"logical"
|
|||
|
],
|
|||
|
"name": "ISO-8859-8-I"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatin6",
|
|||
|
"iso-8859-10",
|
|||
|
"iso-ir-157",
|
|||
|
"iso8859-10",
|
|||
|
"iso885910",
|
|||
|
"l6",
|
|||
|
"latin6"
|
|||
|
],
|
|||
|
"name": "ISO-8859-10"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"iso-8859-13",
|
|||
|
"iso8859-13",
|
|||
|
"iso885913"
|
|||
|
],
|
|||
|
"name": "ISO-8859-13"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"iso-8859-14",
|
|||
|
"iso8859-14",
|
|||
|
"iso885914"
|
|||
|
],
|
|||
|
"name": "ISO-8859-14"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csisolatin9",
|
|||
|
"iso-8859-15",
|
|||
|
"iso8859-15",
|
|||
|
"iso885915",
|
|||
|
"iso_8859-15",
|
|||
|
"l9"
|
|||
|
],
|
|||
|
"name": "ISO-8859-15"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"iso-8859-16"
|
|||
|
],
|
|||
|
"name": "ISO-8859-16"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cskoi8r",
|
|||
|
"koi",
|
|||
|
"koi8",
|
|||
|
"koi8-r",
|
|||
|
"koi8_r"
|
|||
|
],
|
|||
|
"name": "KOI8-R"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"koi8-ru",
|
|||
|
"koi8-u"
|
|||
|
],
|
|||
|
"name": "KOI8-U"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csmacintosh",
|
|||
|
"mac",
|
|||
|
"macintosh",
|
|||
|
"x-mac-roman"
|
|||
|
],
|
|||
|
"name": "macintosh"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"dos-874",
|
|||
|
"iso-8859-11",
|
|||
|
"iso8859-11",
|
|||
|
"iso885911",
|
|||
|
"tis-620",
|
|||
|
"windows-874"
|
|||
|
],
|
|||
|
"name": "windows-874"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1250",
|
|||
|
"windows-1250",
|
|||
|
"x-cp1250"
|
|||
|
],
|
|||
|
"name": "windows-1250"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1251",
|
|||
|
"windows-1251",
|
|||
|
"x-cp1251"
|
|||
|
],
|
|||
|
"name": "windows-1251"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"ansi_x3.4-1968",
|
|||
|
"ascii",
|
|||
|
"cp1252",
|
|||
|
"cp819",
|
|||
|
"csisolatin1",
|
|||
|
"ibm819",
|
|||
|
"iso-8859-1",
|
|||
|
"iso-ir-100",
|
|||
|
"iso8859-1",
|
|||
|
"iso88591",
|
|||
|
"iso_8859-1",
|
|||
|
"iso_8859-1:1987",
|
|||
|
"l1",
|
|||
|
"latin1",
|
|||
|
"us-ascii",
|
|||
|
"windows-1252",
|
|||
|
"x-cp1252"
|
|||
|
],
|
|||
|
"name": "windows-1252"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1253",
|
|||
|
"windows-1253",
|
|||
|
"x-cp1253"
|
|||
|
],
|
|||
|
"name": "windows-1253"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1254",
|
|||
|
"csisolatin5",
|
|||
|
"iso-8859-9",
|
|||
|
"iso-ir-148",
|
|||
|
"iso8859-9",
|
|||
|
"iso88599",
|
|||
|
"iso_8859-9",
|
|||
|
"iso_8859-9:1989",
|
|||
|
"l5",
|
|||
|
"latin5",
|
|||
|
"windows-1254",
|
|||
|
"x-cp1254"
|
|||
|
],
|
|||
|
"name": "windows-1254"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1255",
|
|||
|
"windows-1255",
|
|||
|
"x-cp1255"
|
|||
|
],
|
|||
|
"name": "windows-1255"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1256",
|
|||
|
"windows-1256",
|
|||
|
"x-cp1256"
|
|||
|
],
|
|||
|
"name": "windows-1256"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1257",
|
|||
|
"windows-1257",
|
|||
|
"x-cp1257"
|
|||
|
],
|
|||
|
"name": "windows-1257"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cp1258",
|
|||
|
"windows-1258",
|
|||
|
"x-cp1258"
|
|||
|
],
|
|||
|
"name": "windows-1258"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"x-mac-cyrillic",
|
|||
|
"x-mac-ukrainian"
|
|||
|
],
|
|||
|
"name": "x-mac-cyrillic"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "Legacy single-byte encodings"
|
|||
|
},
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"chinese",
|
|||
|
"csgb2312",
|
|||
|
"csiso58gb231280",
|
|||
|
"gb2312",
|
|||
|
"gb_2312",
|
|||
|
"gb_2312-80",
|
|||
|
"gbk",
|
|||
|
"iso-ir-58",
|
|||
|
"x-gbk"
|
|||
|
],
|
|||
|
"name": "GBK"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"gb18030"
|
|||
|
],
|
|||
|
"name": "gb18030"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "Legacy multi-byte Chinese (simplified) encodings"
|
|||
|
},
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"big5",
|
|||
|
"big5-hkscs",
|
|||
|
"cn-big5",
|
|||
|
"csbig5",
|
|||
|
"x-x-big5"
|
|||
|
],
|
|||
|
"name": "Big5"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "Legacy multi-byte Chinese (traditional) encodings"
|
|||
|
},
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cseucpkdfmtjapanese",
|
|||
|
"euc-jp",
|
|||
|
"x-euc-jp"
|
|||
|
],
|
|||
|
"name": "EUC-JP"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csiso2022jp",
|
|||
|
"iso-2022-jp"
|
|||
|
],
|
|||
|
"name": "ISO-2022-JP"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csshiftjis",
|
|||
|
"ms932",
|
|||
|
"ms_kanji",
|
|||
|
"shift-jis",
|
|||
|
"shift_jis",
|
|||
|
"sjis",
|
|||
|
"windows-31j",
|
|||
|
"x-sjis"
|
|||
|
],
|
|||
|
"name": "Shift_JIS"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "Legacy multi-byte Japanese encodings"
|
|||
|
},
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"cseuckr",
|
|||
|
"csksc56011987",
|
|||
|
"euc-kr",
|
|||
|
"iso-ir-149",
|
|||
|
"korean",
|
|||
|
"ks_c_5601-1987",
|
|||
|
"ks_c_5601-1989",
|
|||
|
"ksc5601",
|
|||
|
"ksc_5601",
|
|||
|
"windows-949"
|
|||
|
],
|
|||
|
"name": "EUC-KR"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "Legacy multi-byte Korean encodings"
|
|||
|
},
|
|||
|
{
|
|||
|
"encodings": [
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"csiso2022kr",
|
|||
|
"hz-gb-2312",
|
|||
|
"iso-2022-cn",
|
|||
|
"iso-2022-cn-ext",
|
|||
|
"iso-2022-kr"
|
|||
|
],
|
|||
|
"name": "replacement"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"utf-16be"
|
|||
|
],
|
|||
|
"name": "UTF-16BE"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"utf-16",
|
|||
|
"utf-16le"
|
|||
|
],
|
|||
|
"name": "UTF-16LE"
|
|||
|
},
|
|||
|
{
|
|||
|
"labels": [
|
|||
|
"x-user-defined"
|
|||
|
],
|
|||
|
"name": "x-user-defined"
|
|||
|
}
|
|||
|
],
|
|||
|
"heading": "Legacy miscellaneous encodings"
|
|||
|
}
|
|||
|
];
|
|||
|
|
|||
|
// Label to encoding registry.
|
|||
|
/** @type {Object.<string,{name:string,labels:Array.<string>}>} */
|
|||
|
var label_to_encoding = {};
|
|||
|
encodings.forEach(function(category) {
|
|||
|
category.encodings.forEach(function(encoding) {
|
|||
|
encoding.labels.forEach(function(label) {
|
|||
|
label_to_encoding[label] = encoding;
|
|||
|
});
|
|||
|
});
|
|||
|
});
|
|||
|
|
|||
|
// Registry of of encoder/decoder factories, by encoding name.
|
|||
|
/** @type {Object.<string, function({fatal:boolean}): Encoder>} */
|
|||
|
var encoders = {};
|
|||
|
/** @type {Object.<string, function({fatal:boolean}): Decoder>} */
|
|||
|
var decoders = {};
|
|||
|
|
|||
|
//
|
|||
|
// 6. Indexes
|
|||
|
//
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} pointer The |pointer| to search for.
|
|||
|
* @param {(!Array.<?number>|undefined)} index The |index| to search within.
|
|||
|
* @return {?number} The code point corresponding to |pointer| in |index|,
|
|||
|
* or null if |code point| is not in |index|.
|
|||
|
*/
|
|||
|
function indexCodePointFor(pointer, index) {
|
|||
|
if (!index) return null;
|
|||
|
return index[pointer] || null;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} code_point The |code point| to search for.
|
|||
|
* @param {!Array.<?number>} index The |index| to search within.
|
|||
|
* @return {?number} The first pointer corresponding to |code point| in
|
|||
|
* |index|, or null if |code point| is not in |index|.
|
|||
|
*/
|
|||
|
function indexPointerFor(code_point, index) {
|
|||
|
var pointer = index.indexOf(code_point);
|
|||
|
return pointer === -1 ? null : pointer;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {string} name Name of the index.
|
|||
|
* @return {(!Array.<number>|!Array.<Array.<number>>)}
|
|||
|
* */
|
|||
|
function index(name) {
|
|||
|
if (!('encoding-indexes' in global)) {
|
|||
|
throw Error("Indexes missing." +
|
|||
|
" Did you forget to include encoding-indexes.js first?");
|
|||
|
}
|
|||
|
return global['encoding-indexes'][name];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} pointer The |pointer| to search for in the gb18030 index.
|
|||
|
* @return {?number} The code point corresponding to |pointer| in |index|,
|
|||
|
* or null if |code point| is not in the gb18030 index.
|
|||
|
*/
|
|||
|
function indexGB18030RangesCodePointFor(pointer) {
|
|||
|
// 1. If pointer is greater than 39419 and less than 189000, or
|
|||
|
// pointer is greater than 1237575, return null.
|
|||
|
if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575))
|
|||
|
return null;
|
|||
|
|
|||
|
// 2. If pointer is 7457, return code point U+E7C7.
|
|||
|
if (pointer === 7457) return 0xE7C7;
|
|||
|
|
|||
|
// 3. Let offset be the last pointer in index gb18030 ranges that
|
|||
|
// is equal to or less than pointer and let code point offset be
|
|||
|
// its corresponding code point.
|
|||
|
var offset = 0;
|
|||
|
var code_point_offset = 0;
|
|||
|
var idx = index('gb18030-ranges');
|
|||
|
var i;
|
|||
|
for (i = 0; i < idx.length; ++i) {
|
|||
|
/** @type {!Array.<number>} */
|
|||
|
var entry = idx[i];
|
|||
|
if (entry[0] <= pointer) {
|
|||
|
offset = entry[0];
|
|||
|
code_point_offset = entry[1];
|
|||
|
} else {
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 4. Return a code point whose value is code point offset +
|
|||
|
// pointer − offset.
|
|||
|
return code_point_offset + pointer - offset;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} code_point The |code point| to locate in the gb18030 index.
|
|||
|
* @return {number} The first pointer corresponding to |code point| in the
|
|||
|
* gb18030 index.
|
|||
|
*/
|
|||
|
function indexGB18030RangesPointerFor(code_point) {
|
|||
|
// 1. If code point is U+E7C7, return pointer 7457.
|
|||
|
if (code_point === 0xE7C7) return 7457;
|
|||
|
|
|||
|
// 2. Let offset be the last code point in index gb18030 ranges
|
|||
|
// that is equal to or less than code point and let pointer offset
|
|||
|
// be its corresponding pointer.
|
|||
|
var offset = 0;
|
|||
|
var pointer_offset = 0;
|
|||
|
var idx = index('gb18030-ranges');
|
|||
|
var i;
|
|||
|
for (i = 0; i < idx.length; ++i) {
|
|||
|
/** @type {!Array.<number>} */
|
|||
|
var entry = idx[i];
|
|||
|
if (entry[1] <= code_point) {
|
|||
|
offset = entry[1];
|
|||
|
pointer_offset = entry[0];
|
|||
|
} else {
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 3. Return a pointer whose value is pointer offset + code point
|
|||
|
// − offset.
|
|||
|
return pointer_offset + code_point - offset;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} code_point The |code_point| to search for in the Shift_JIS
|
|||
|
* index.
|
|||
|
* @return {?number} The code point corresponding to |pointer| in |index|,
|
|||
|
* or null if |code point| is not in the Shift_JIS index.
|
|||
|
*/
|
|||
|
function indexShiftJISPointerFor(code_point) {
|
|||
|
// 1. Let index be index jis0208 excluding all entries whose
|
|||
|
// pointer is in the range 8272 to 8835, inclusive.
|
|||
|
shift_jis_index = shift_jis_index ||
|
|||
|
index('jis0208').map(function(code_point, pointer) {
|
|||
|
return inRange(pointer, 8272, 8835) ? null : code_point;
|
|||
|
});
|
|||
|
var index_ = shift_jis_index;
|
|||
|
|
|||
|
// 2. Return the index pointer for code point in index.
|
|||
|
return index_.indexOf(code_point);
|
|||
|
}
|
|||
|
var shift_jis_index;
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} code_point The |code_point| to search for in the big5
|
|||
|
* index.
|
|||
|
* @return {?number} The code point corresponding to |pointer| in |index|,
|
|||
|
* or null if |code point| is not in the big5 index.
|
|||
|
*/
|
|||
|
function indexBig5PointerFor(code_point) {
|
|||
|
// 1. Let index be index Big5 excluding all entries whose pointer
|
|||
|
big5_index_no_hkscs = big5_index_no_hkscs ||
|
|||
|
index('big5').map(function(code_point, pointer) {
|
|||
|
return (pointer < (0xA1 - 0x81) * 157) ? null : code_point;
|
|||
|
});
|
|||
|
var index_ = big5_index_no_hkscs;
|
|||
|
|
|||
|
// 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or
|
|||
|
// U+5345, return the last pointer corresponding to code point in
|
|||
|
// index.
|
|||
|
if (code_point === 0x2550 || code_point === 0x255E ||
|
|||
|
code_point === 0x2561 || code_point === 0x256A ||
|
|||
|
code_point === 0x5341 || code_point === 0x5345) {
|
|||
|
return index_.lastIndexOf(code_point);
|
|||
|
}
|
|||
|
|
|||
|
// 3. Return the index pointer for code point in index.
|
|||
|
return indexPointerFor(code_point, index_);
|
|||
|
}
|
|||
|
var big5_index_no_hkscs;
|
|||
|
|
|||
|
//
|
|||
|
// 8. API
|
|||
|
//
|
|||
|
|
|||
|
/** @const */ var DEFAULT_ENCODING = 'utf-8';
|
|||
|
|
|||
|
// 8.1 Interface TextDecoder
|
|||
|
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @param {string=} label The label of the encoding;
|
|||
|
* defaults to 'utf-8'.
|
|||
|
* @param {Object=} options
|
|||
|
*/
|
|||
|
function TextDecoder(label, options) {
|
|||
|
// Web IDL conventions
|
|||
|
if (!(this instanceof TextDecoder))
|
|||
|
throw TypeError('Called as a function. Did you forget \'new\'?');
|
|||
|
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
|
|||
|
options = ToDictionary(options);
|
|||
|
|
|||
|
// A TextDecoder object has an associated encoding, decoder,
|
|||
|
// stream, ignore BOM flag (initially unset), BOM seen flag
|
|||
|
// (initially unset), error mode (initially replacement), and do
|
|||
|
// not flush flag (initially unset).
|
|||
|
|
|||
|
/** @private */
|
|||
|
this._encoding = null;
|
|||
|
/** @private @type {?Decoder} */
|
|||
|
this._decoder = null;
|
|||
|
/** @private @type {boolean} */
|
|||
|
this._ignoreBOM = false;
|
|||
|
/** @private @type {boolean} */
|
|||
|
this._BOMseen = false;
|
|||
|
/** @private @type {string} */
|
|||
|
this._error_mode = 'replacement';
|
|||
|
/** @private @type {boolean} */
|
|||
|
this._do_not_flush = false;
|
|||
|
|
|||
|
|
|||
|
// 1. Let encoding be the result of getting an encoding from
|
|||
|
// label.
|
|||
|
var encoding = getEncoding(label);
|
|||
|
|
|||
|
// 2. If encoding is failure or replacement, throw a RangeError.
|
|||
|
if (encoding === null || encoding.name === 'replacement')
|
|||
|
throw RangeError('Unknown encoding: ' + label);
|
|||
|
if (!decoders[encoding.name]) {
|
|||
|
throw Error('Decoder not present.' +
|
|||
|
' Did you forget to include encoding-indexes.js first?');
|
|||
|
}
|
|||
|
|
|||
|
// 3. Let dec be a new TextDecoder object.
|
|||
|
var dec = this;
|
|||
|
|
|||
|
// 4. Set dec's encoding to encoding.
|
|||
|
dec._encoding = encoding;
|
|||
|
|
|||
|
// 5. If options's fatal member is true, set dec's error mode to
|
|||
|
// fatal.
|
|||
|
if (Boolean(options['fatal']))
|
|||
|
dec._error_mode = 'fatal';
|
|||
|
|
|||
|
// 6. If options's ignoreBOM member is true, set dec's ignore BOM
|
|||
|
// flag.
|
|||
|
if (Boolean(options['ignoreBOM']))
|
|||
|
dec._ignoreBOM = true;
|
|||
|
|
|||
|
// For pre-ES5 runtimes:
|
|||
|
if (!Object.defineProperty) {
|
|||
|
this.encoding = dec._encoding.name.toLowerCase();
|
|||
|
this.fatal = dec._error_mode === 'fatal';
|
|||
|
this.ignoreBOM = dec._ignoreBOM;
|
|||
|
}
|
|||
|
|
|||
|
// 7. Return dec.
|
|||
|
return dec;
|
|||
|
}
|
|||
|
|
|||
|
if (Object.defineProperty) {
|
|||
|
// The encoding attribute's getter must return encoding's name.
|
|||
|
Object.defineProperty(TextDecoder.prototype, 'encoding', {
|
|||
|
/** @this {TextDecoder} */
|
|||
|
get: function() { return this._encoding.name.toLowerCase(); }
|
|||
|
});
|
|||
|
|
|||
|
// The fatal attribute's getter must return true if error mode
|
|||
|
// is fatal, and false otherwise.
|
|||
|
Object.defineProperty(TextDecoder.prototype, 'fatal', {
|
|||
|
/** @this {TextDecoder} */
|
|||
|
get: function() { return this._error_mode === 'fatal'; }
|
|||
|
});
|
|||
|
|
|||
|
// The ignoreBOM attribute's getter must return true if ignore
|
|||
|
// BOM flag is set, and false otherwise.
|
|||
|
Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
|
|||
|
/** @this {TextDecoder} */
|
|||
|
get: function() { return this._ignoreBOM; }
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {BufferSource=} input The buffer of bytes to decode.
|
|||
|
* @param {Object=} options
|
|||
|
* @return {string} The decoded string.
|
|||
|
*/
|
|||
|
TextDecoder.prototype.decode = function decode(input, options) {
|
|||
|
var bytes;
|
|||
|
if (typeof input === 'object' && input instanceof ArrayBuffer) {
|
|||
|
bytes = new Uint8Array(input);
|
|||
|
} else if (typeof input === 'object' && 'buffer' in input &&
|
|||
|
input.buffer instanceof ArrayBuffer) {
|
|||
|
bytes = new Uint8Array(input.buffer,
|
|||
|
input.byteOffset,
|
|||
|
input.byteLength);
|
|||
|
} else {
|
|||
|
bytes = new Uint8Array(0);
|
|||
|
}
|
|||
|
|
|||
|
options = ToDictionary(options);
|
|||
|
|
|||
|
// 1. If the do not flush flag is unset, set decoder to a new
|
|||
|
// encoding's decoder, set stream to a new stream, and unset the
|
|||
|
// BOM seen flag.
|
|||
|
if (!this._do_not_flush) {
|
|||
|
this._decoder = decoders[this._encoding.name]({
|
|||
|
fatal: this._error_mode === 'fatal'});
|
|||
|
this._BOMseen = false;
|
|||
|
}
|
|||
|
|
|||
|
// 2. If options's stream is true, set the do not flush flag, and
|
|||
|
// unset the do not flush flag otherwise.
|
|||
|
this._do_not_flush = Boolean(options['stream']);
|
|||
|
|
|||
|
// 3. If input is given, push a copy of input to stream.
|
|||
|
// TODO: Align with spec algorithm - maintain stream on instance.
|
|||
|
var input_stream = new Stream(bytes);
|
|||
|
|
|||
|
// 4. Let output be a new stream.
|
|||
|
var output = [];
|
|||
|
|
|||
|
/** @type {?(number|!Array.<number>)} */
|
|||
|
var result;
|
|||
|
|
|||
|
// 5. While true:
|
|||
|
while (true) {
|
|||
|
// 1. Let token be the result of reading from stream.
|
|||
|
var token = input_stream.read();
|
|||
|
|
|||
|
// 2. If token is end-of-stream and the do not flush flag is
|
|||
|
// set, return output, serialized.
|
|||
|
// TODO: Align with spec algorithm.
|
|||
|
if (token === end_of_stream)
|
|||
|
break;
|
|||
|
|
|||
|
// 3. Otherwise, run these subsubsteps:
|
|||
|
|
|||
|
// 1. Let result be the result of processing token for decoder,
|
|||
|
// stream, output, and error mode.
|
|||
|
result = this._decoder.handler(input_stream, token);
|
|||
|
|
|||
|
// 2. If result is finished, return output, serialized.
|
|||
|
if (result === finished)
|
|||
|
break;
|
|||
|
|
|||
|
if (result !== null) {
|
|||
|
if (Array.isArray(result))
|
|||
|
output.push.apply(output, /**@type {!Array.<number>}*/(result));
|
|||
|
else
|
|||
|
output.push(result);
|
|||
|
}
|
|||
|
|
|||
|
// 3. Otherwise, if result is error, throw a TypeError.
|
|||
|
// (Thrown in handler)
|
|||
|
|
|||
|
// 4. Otherwise, do nothing.
|
|||
|
}
|
|||
|
// TODO: Align with spec algorithm.
|
|||
|
if (!this._do_not_flush) {
|
|||
|
do {
|
|||
|
result = this._decoder.handler(input_stream, input_stream.read());
|
|||
|
if (result === finished)
|
|||
|
break;
|
|||
|
if (result === null)
|
|||
|
continue;
|
|||
|
if (Array.isArray(result))
|
|||
|
output.push.apply(output, /**@type {!Array.<number>}*/(result));
|
|||
|
else
|
|||
|
output.push(result);
|
|||
|
} while (!input_stream.endOfStream());
|
|||
|
this._decoder = null;
|
|||
|
}
|
|||
|
|
|||
|
// A TextDecoder object also has an associated serialize stream
|
|||
|
// algorithm...
|
|||
|
/**
|
|||
|
* @param {!Array.<number>} stream
|
|||
|
* @return {string}
|
|||
|
* @this {TextDecoder}
|
|||
|
*/
|
|||
|
function serializeStream(stream) {
|
|||
|
// 1. Let token be the result of reading from stream.
|
|||
|
// (Done in-place on array, rather than as a stream)
|
|||
|
|
|||
|
// 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
|
|||
|
// BOM flag and BOM seen flag are unset, run these subsubsteps:
|
|||
|
if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
|
|||
|
!this._ignoreBOM && !this._BOMseen) {
|
|||
|
if (stream.length > 0 && stream[0] === 0xFEFF) {
|
|||
|
// 1. If token is U+FEFF, set BOM seen flag.
|
|||
|
this._BOMseen = true;
|
|||
|
stream.shift();
|
|||
|
} else if (stream.length > 0) {
|
|||
|
// 2. Otherwise, if token is not end-of-stream, set BOM seen
|
|||
|
// flag and append token to stream.
|
|||
|
this._BOMseen = true;
|
|||
|
} else {
|
|||
|
// 3. Otherwise, if token is not end-of-stream, append token
|
|||
|
// to output.
|
|||
|
// (no-op)
|
|||
|
}
|
|||
|
}
|
|||
|
// 4. Otherwise, return output.
|
|||
|
return codePointsToString(stream);
|
|||
|
}
|
|||
|
|
|||
|
return serializeStream.call(this, output);
|
|||
|
};
|
|||
|
|
|||
|
// 8.2 Interface TextEncoder
|
|||
|
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @param {string=} label The label of the encoding. NONSTANDARD.
|
|||
|
* @param {Object=} options NONSTANDARD.
|
|||
|
*/
|
|||
|
function TextEncoder(label, options) {
|
|||
|
// Web IDL conventions
|
|||
|
if (!(this instanceof TextEncoder))
|
|||
|
throw TypeError('Called as a function. Did you forget \'new\'?');
|
|||
|
options = ToDictionary(options);
|
|||
|
|
|||
|
// A TextEncoder object has an associated encoding and encoder.
|
|||
|
|
|||
|
/** @private */
|
|||
|
this._encoding = null;
|
|||
|
/** @private @type {?Encoder} */
|
|||
|
this._encoder = null;
|
|||
|
|
|||
|
// Non-standard
|
|||
|
/** @private @type {boolean} */
|
|||
|
this._do_not_flush = false;
|
|||
|
/** @private @type {string} */
|
|||
|
this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';
|
|||
|
|
|||
|
// 1. Let enc be a new TextEncoder object.
|
|||
|
var enc = this;
|
|||
|
|
|||
|
// 2. Set enc's encoding to UTF-8's encoder.
|
|||
|
if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
|
|||
|
// NONSTANDARD behavior.
|
|||
|
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
|
|||
|
var encoding = getEncoding(label);
|
|||
|
if (encoding === null || encoding.name === 'replacement')
|
|||
|
throw RangeError('Unknown encoding: ' + label);
|
|||
|
if (!encoders[encoding.name]) {
|
|||
|
throw Error('Encoder not present.' +
|
|||
|
' Did you forget to include encoding-indexes.js first?');
|
|||
|
}
|
|||
|
enc._encoding = encoding;
|
|||
|
} else {
|
|||
|
// Standard behavior.
|
|||
|
enc._encoding = getEncoding('utf-8');
|
|||
|
|
|||
|
if (label !== undefined && 'console' in global) {
|
|||
|
console.warn('TextEncoder constructor called with encoding label, '
|
|||
|
+ 'which is ignored.');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// For pre-ES5 runtimes:
|
|||
|
if (!Object.defineProperty)
|
|||
|
this.encoding = enc._encoding.name.toLowerCase();
|
|||
|
|
|||
|
// 3. Return enc.
|
|||
|
return enc;
|
|||
|
}
|
|||
|
|
|||
|
if (Object.defineProperty) {
|
|||
|
// The encoding attribute's getter must return encoding's name.
|
|||
|
Object.defineProperty(TextEncoder.prototype, 'encoding', {
|
|||
|
/** @this {TextEncoder} */
|
|||
|
get: function() { return this._encoding.name.toLowerCase(); }
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @param {string=} opt_string The string to encode.
|
|||
|
* @param {Object=} options
|
|||
|
* @return {!Uint8Array} Encoded bytes, as a Uint8Array.
|
|||
|
*/
|
|||
|
TextEncoder.prototype.encode = function encode(opt_string, options) {
|
|||
|
opt_string = opt_string === undefined ? '' : String(opt_string);
|
|||
|
options = ToDictionary(options);
|
|||
|
|
|||
|
// NOTE: This option is nonstandard. None of the encodings
|
|||
|
// permitted for encoding (i.e. UTF-8, UTF-16) are stateful when
|
|||
|
// the input is a USVString so streaming is not necessary.
|
|||
|
if (!this._do_not_flush)
|
|||
|
this._encoder = encoders[this._encoding.name]({
|
|||
|
fatal: this._fatal === 'fatal'});
|
|||
|
this._do_not_flush = Boolean(options['stream']);
|
|||
|
|
|||
|
// 1. Convert input to a stream.
|
|||
|
var input = new Stream(stringToCodePoints(opt_string));
|
|||
|
|
|||
|
// 2. Let output be a new stream
|
|||
|
var output = [];
|
|||
|
|
|||
|
/** @type {?(number|!Array.<number>)} */
|
|||
|
var result;
|
|||
|
// 3. While true, run these substeps:
|
|||
|
while (true) {
|
|||
|
// 1. Let token be the result of reading from input.
|
|||
|
var token = input.read();
|
|||
|
if (token === end_of_stream)
|
|||
|
break;
|
|||
|
// 2. Let result be the result of processing token for encoder,
|
|||
|
// input, output.
|
|||
|
result = this._encoder.handler(input, token);
|
|||
|
if (result === finished)
|
|||
|
break;
|
|||
|
if (Array.isArray(result))
|
|||
|
output.push.apply(output, /**@type {!Array.<number>}*/(result));
|
|||
|
else
|
|||
|
output.push(result);
|
|||
|
}
|
|||
|
// TODO: Align with spec algorithm.
|
|||
|
if (!this._do_not_flush) {
|
|||
|
while (true) {
|
|||
|
result = this._encoder.handler(input, input.read());
|
|||
|
if (result === finished)
|
|||
|
break;
|
|||
|
if (Array.isArray(result))
|
|||
|
output.push.apply(output, /**@type {!Array.<number>}*/(result));
|
|||
|
else
|
|||
|
output.push(result);
|
|||
|
}
|
|||
|
this._encoder = null;
|
|||
|
}
|
|||
|
// 3. If result is finished, convert output into a byte sequence,
|
|||
|
// and then return a Uint8Array object wrapping an ArrayBuffer
|
|||
|
// containing output.
|
|||
|
return new Uint8Array(output);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// 9. The encoding
|
|||
|
//
|
|||
|
|
|||
|
// 9.1 utf-8
|
|||
|
|
|||
|
// 9.1.1 utf-8 decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function UTF8Decoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
|
|||
|
// utf-8's decoder's has an associated utf-8 code point, utf-8
|
|||
|
// bytes seen, and utf-8 bytes needed (all initially 0), a utf-8
|
|||
|
// lower boundary (initially 0x80), and a utf-8 upper boundary
|
|||
|
// (initially 0xBF).
|
|||
|
var /** @type {number} */ utf8_code_point = 0,
|
|||
|
/** @type {number} */ utf8_bytes_seen = 0,
|
|||
|
/** @type {number} */ utf8_bytes_needed = 0,
|
|||
|
/** @type {number} */ utf8_lower_boundary = 0x80,
|
|||
|
/** @type {number} */ utf8_upper_boundary = 0xBF;
|
|||
|
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and utf-8 bytes needed is not 0,
|
|||
|
// set utf-8 bytes needed to 0 and return error.
|
|||
|
if (bite === end_of_stream && utf8_bytes_needed !== 0) {
|
|||
|
utf8_bytes_needed = 0;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 2. If byte is end-of-stream, return finished.
|
|||
|
if (bite === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 3. If utf-8 bytes needed is 0, based on byte:
|
|||
|
if (utf8_bytes_needed === 0) {
|
|||
|
|
|||
|
// 0x00 to 0x7F
|
|||
|
if (inRange(bite, 0x00, 0x7F)) {
|
|||
|
// Return a code point whose value is byte.
|
|||
|
return bite;
|
|||
|
}
|
|||
|
|
|||
|
// 0xC2 to 0xDF
|
|||
|
else if (inRange(bite, 0xC2, 0xDF)) {
|
|||
|
// 1. Set utf-8 bytes needed to 1.
|
|||
|
utf8_bytes_needed = 1;
|
|||
|
|
|||
|
// 2. Set UTF-8 code point to byte & 0x1F.
|
|||
|
utf8_code_point = bite & 0x1F;
|
|||
|
}
|
|||
|
|
|||
|
// 0xE0 to 0xEF
|
|||
|
else if (inRange(bite, 0xE0, 0xEF)) {
|
|||
|
// 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.
|
|||
|
if (bite === 0xE0)
|
|||
|
utf8_lower_boundary = 0xA0;
|
|||
|
// 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.
|
|||
|
if (bite === 0xED)
|
|||
|
utf8_upper_boundary = 0x9F;
|
|||
|
// 3. Set utf-8 bytes needed to 2.
|
|||
|
utf8_bytes_needed = 2;
|
|||
|
// 4. Set UTF-8 code point to byte & 0xF.
|
|||
|
utf8_code_point = bite & 0xF;
|
|||
|
}
|
|||
|
|
|||
|
// 0xF0 to 0xF4
|
|||
|
else if (inRange(bite, 0xF0, 0xF4)) {
|
|||
|
// 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.
|
|||
|
if (bite === 0xF0)
|
|||
|
utf8_lower_boundary = 0x90;
|
|||
|
// 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.
|
|||
|
if (bite === 0xF4)
|
|||
|
utf8_upper_boundary = 0x8F;
|
|||
|
// 3. Set utf-8 bytes needed to 3.
|
|||
|
utf8_bytes_needed = 3;
|
|||
|
// 4. Set UTF-8 code point to byte & 0x7.
|
|||
|
utf8_code_point = bite & 0x7;
|
|||
|
}
|
|||
|
|
|||
|
// Otherwise
|
|||
|
else {
|
|||
|
// Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// Return continue.
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 4. If byte is not in the range utf-8 lower boundary to utf-8
|
|||
|
// upper boundary, inclusive, run these substeps:
|
|||
|
if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {
|
|||
|
|
|||
|
// 1. Set utf-8 code point, utf-8 bytes needed, and utf-8
|
|||
|
// bytes seen to 0, set utf-8 lower boundary to 0x80, and set
|
|||
|
// utf-8 upper boundary to 0xBF.
|
|||
|
utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
|
|||
|
utf8_lower_boundary = 0x80;
|
|||
|
utf8_upper_boundary = 0xBF;
|
|||
|
|
|||
|
// 2. Prepend byte to stream.
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 3. Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary
|
|||
|
// to 0xBF.
|
|||
|
utf8_lower_boundary = 0x80;
|
|||
|
utf8_upper_boundary = 0xBF;
|
|||
|
|
|||
|
// 6. Set UTF-8 code point to (UTF-8 code point << 6) | (byte &
|
|||
|
// 0x3F)
|
|||
|
utf8_code_point = (utf8_code_point << 6) | (bite & 0x3F);
|
|||
|
|
|||
|
// 7. Increase utf-8 bytes seen by one.
|
|||
|
utf8_bytes_seen += 1;
|
|||
|
|
|||
|
// 8. If utf-8 bytes seen is not equal to utf-8 bytes needed,
|
|||
|
// continue.
|
|||
|
if (utf8_bytes_seen !== utf8_bytes_needed)
|
|||
|
return null;
|
|||
|
|
|||
|
// 9. Let code point be utf-8 code point.
|
|||
|
var code_point = utf8_code_point;
|
|||
|
|
|||
|
// 10. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes
|
|||
|
// seen to 0.
|
|||
|
utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
|
|||
|
|
|||
|
// 11. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 9.1.2 utf-8 encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function UTF8Encoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. Set count and offset based on the range code point is in:
|
|||
|
var count, offset;
|
|||
|
// U+0080 to U+07FF, inclusive:
|
|||
|
if (inRange(code_point, 0x0080, 0x07FF)) {
|
|||
|
// 1 and 0xC0
|
|||
|
count = 1;
|
|||
|
offset = 0xC0;
|
|||
|
}
|
|||
|
// U+0800 to U+FFFF, inclusive:
|
|||
|
else if (inRange(code_point, 0x0800, 0xFFFF)) {
|
|||
|
// 2 and 0xE0
|
|||
|
count = 2;
|
|||
|
offset = 0xE0;
|
|||
|
}
|
|||
|
// U+10000 to U+10FFFF, inclusive:
|
|||
|
else if (inRange(code_point, 0x10000, 0x10FFFF)) {
|
|||
|
// 3 and 0xF0
|
|||
|
count = 3;
|
|||
|
offset = 0xF0;
|
|||
|
}
|
|||
|
|
|||
|
// 4. Let bytes be a byte sequence whose first byte is (code
|
|||
|
// point >> (6 × count)) + offset.
|
|||
|
var bytes = [(code_point >> (6 * count)) + offset];
|
|||
|
|
|||
|
// 5. Run these substeps while count is greater than 0:
|
|||
|
while (count > 0) {
|
|||
|
|
|||
|
// 1. Set temp to code point >> (6 × (count − 1)).
|
|||
|
var temp = code_point >> (6 * (count - 1));
|
|||
|
|
|||
|
// 2. Append to bytes 0x80 | (temp & 0x3F).
|
|||
|
bytes.push(0x80 | (temp & 0x3F));
|
|||
|
|
|||
|
// 3. Decrease count by one.
|
|||
|
count -= 1;
|
|||
|
}
|
|||
|
|
|||
|
// 6. Return bytes bytes, in order.
|
|||
|
return bytes;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['UTF-8'] = function(options) {
|
|||
|
return new UTF8Encoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['UTF-8'] = function(options) {
|
|||
|
return new UTF8Decoder(options);
|
|||
|
};
|
|||
|
|
|||
|
//
|
|||
|
// 10. Legacy single-byte encodings
|
|||
|
//
|
|||
|
|
|||
|
// 10.1 single-byte decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {!Array.<number>} index The encoding index.
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function SingleByteDecoder(index, options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream, return finished.
|
|||
|
if (bite === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If byte is an ASCII byte, return a code point whose value
|
|||
|
// is byte.
|
|||
|
if (isASCIIByte(bite))
|
|||
|
return bite;
|
|||
|
|
|||
|
// 3. Let code point be the index code point for byte − 0x80 in
|
|||
|
// index single-byte.
|
|||
|
var code_point = index[bite - 0x80];
|
|||
|
|
|||
|
// 4. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 5. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 10.2 single-byte encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {!Array.<?number>} index The encoding index.
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function SingleByteEncoder(index, options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. Let pointer be the index pointer for code point in index
|
|||
|
// single-byte.
|
|||
|
var pointer = indexPointerFor(code_point, index);
|
|||
|
|
|||
|
// 4. If pointer is null, return error with code point.
|
|||
|
if (pointer === null)
|
|||
|
encoderError(code_point);
|
|||
|
|
|||
|
// 5. Return a byte whose value is pointer + 0x80.
|
|||
|
return pointer + 0x80;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
(function() {
|
|||
|
if (!('encoding-indexes' in global))
|
|||
|
return;
|
|||
|
encodings.forEach(function(category) {
|
|||
|
if (category.heading !== 'Legacy single-byte encodings')
|
|||
|
return;
|
|||
|
category.encodings.forEach(function(encoding) {
|
|||
|
var name = encoding.name;
|
|||
|
var idx = index(name.toLowerCase());
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders[name] = function(options) {
|
|||
|
return new SingleByteDecoder(idx, options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders[name] = function(options) {
|
|||
|
return new SingleByteEncoder(idx, options);
|
|||
|
};
|
|||
|
});
|
|||
|
});
|
|||
|
}());
|
|||
|
|
|||
|
//
|
|||
|
// 11. Legacy multi-byte Chinese (simplified) encodings
|
|||
|
//
|
|||
|
|
|||
|
// 11.1 gbk
|
|||
|
|
|||
|
// 11.1.1 gbk decoder
|
|||
|
// gbk's decoder is gb18030's decoder.
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['GBK'] = function(options) {
|
|||
|
return new GB18030Decoder(options);
|
|||
|
};
|
|||
|
|
|||
|
// 11.1.2 gbk encoder
|
|||
|
// gbk's encoder is gb18030's encoder with its gbk flag set.
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['GBK'] = function(options) {
|
|||
|
return new GB18030Encoder(options, true);
|
|||
|
};
|
|||
|
|
|||
|
// 11.2 gb18030
|
|||
|
|
|||
|
// 11.2.1 gb18030 decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function GB18030Decoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
// gb18030's decoder has an associated gb18030 first, gb18030
|
|||
|
// second, and gb18030 third (all initially 0x00).
|
|||
|
var /** @type {number} */ gb18030_first = 0x00,
|
|||
|
/** @type {number} */ gb18030_second = 0x00,
|
|||
|
/** @type {number} */ gb18030_third = 0x00;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and gb18030 first, gb18030
|
|||
|
// second, and gb18030 third are 0x00, return finished.
|
|||
|
if (bite === end_of_stream && gb18030_first === 0x00 &&
|
|||
|
gb18030_second === 0x00 && gb18030_third === 0x00) {
|
|||
|
return finished;
|
|||
|
}
|
|||
|
// 2. If byte is end-of-stream, and gb18030 first, gb18030
|
|||
|
// second, or gb18030 third is not 0x00, set gb18030 first,
|
|||
|
// gb18030 second, and gb18030 third to 0x00, and return error.
|
|||
|
if (bite === end_of_stream &&
|
|||
|
(gb18030_first !== 0x00 || gb18030_second !== 0x00 ||
|
|||
|
gb18030_third !== 0x00)) {
|
|||
|
gb18030_first = 0x00;
|
|||
|
gb18030_second = 0x00;
|
|||
|
gb18030_third = 0x00;
|
|||
|
decoderError(fatal);
|
|||
|
}
|
|||
|
var code_point;
|
|||
|
// 3. If gb18030 third is not 0x00, run these substeps:
|
|||
|
if (gb18030_third !== 0x00) {
|
|||
|
// 1. Let code point be null.
|
|||
|
code_point = null;
|
|||
|
// 2. If byte is in the range 0x30 to 0x39, inclusive, set
|
|||
|
// code point to the index gb18030 ranges code point for
|
|||
|
// (((gb18030 first − 0x81) × 10 + gb18030 second − 0x30) ×
|
|||
|
// 126 + gb18030 third − 0x81) × 10 + byte − 0x30.
|
|||
|
if (inRange(bite, 0x30, 0x39)) {
|
|||
|
code_point = indexGB18030RangesCodePointFor(
|
|||
|
(((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 +
|
|||
|
gb18030_third - 0x81) * 10 + bite - 0x30);
|
|||
|
}
|
|||
|
|
|||
|
// 3. Let buffer be a byte sequence consisting of gb18030
|
|||
|
// second, gb18030 third, and byte, in order.
|
|||
|
var buffer = [gb18030_second, gb18030_third, bite];
|
|||
|
|
|||
|
// 4. Set gb18030 first, gb18030 second, and gb18030 third to
|
|||
|
// 0x00.
|
|||
|
gb18030_first = 0x00;
|
|||
|
gb18030_second = 0x00;
|
|||
|
gb18030_third = 0x00;
|
|||
|
|
|||
|
// 5. If code point is null, prepend buffer to stream and
|
|||
|
// return error.
|
|||
|
if (code_point === null) {
|
|||
|
stream.prepend(buffer);
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 6. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// 4. If gb18030 second is not 0x00, run these substeps:
|
|||
|
if (gb18030_second !== 0x00) {
|
|||
|
|
|||
|
// 1. If byte is in the range 0x81 to 0xFE, inclusive, set
|
|||
|
// gb18030 third to byte and return continue.
|
|||
|
if (inRange(bite, 0x81, 0xFE)) {
|
|||
|
gb18030_third = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 2. Prepend gb18030 second followed by byte to stream, set
|
|||
|
// gb18030 first and gb18030 second to 0x00, and return error.
|
|||
|
stream.prepend([gb18030_second, bite]);
|
|||
|
gb18030_first = 0x00;
|
|||
|
gb18030_second = 0x00;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 5. If gb18030 first is not 0x00, run these substeps:
|
|||
|
if (gb18030_first !== 0x00) {
|
|||
|
|
|||
|
// 1. If byte is in the range 0x30 to 0x39, inclusive, set
|
|||
|
// gb18030 second to byte and return continue.
|
|||
|
if (inRange(bite, 0x30, 0x39)) {
|
|||
|
gb18030_second = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 2. Let lead be gb18030 first, let pointer be null, and set
|
|||
|
// gb18030 first to 0x00.
|
|||
|
var lead = gb18030_first;
|
|||
|
var pointer = null;
|
|||
|
gb18030_first = 0x00;
|
|||
|
|
|||
|
// 3. Let offset be 0x40 if byte is less than 0x7F and 0x41
|
|||
|
// otherwise.
|
|||
|
var offset = bite < 0x7F ? 0x40 : 0x41;
|
|||
|
|
|||
|
// 4. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
|
|||
|
// to 0xFE, inclusive, set pointer to (lead − 0x81) × 190 +
|
|||
|
// (byte − offset).
|
|||
|
if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE))
|
|||
|
pointer = (lead - 0x81) * 190 + (bite - offset);
|
|||
|
|
|||
|
// 5. Let code point be null if pointer is null and the index
|
|||
|
// code point for pointer in index gb18030 otherwise.
|
|||
|
code_point = pointer === null ? null :
|
|||
|
indexCodePointFor(pointer, index('gb18030'));
|
|||
|
|
|||
|
// 6. If code point is null and byte is an ASCII byte, prepend
|
|||
|
// byte to stream.
|
|||
|
if (code_point === null && isASCIIByte(bite))
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 7. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 8. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// 6. If byte is an ASCII byte, return a code point whose value
|
|||
|
// is byte.
|
|||
|
if (isASCIIByte(bite))
|
|||
|
return bite;
|
|||
|
|
|||
|
// 7. If byte is 0x80, return code point U+20AC.
|
|||
|
if (bite === 0x80)
|
|||
|
return 0x20AC;
|
|||
|
|
|||
|
// 8. If byte is in the range 0x81 to 0xFE, inclusive, set
|
|||
|
// gb18030 first to byte and return continue.
|
|||
|
if (inRange(bite, 0x81, 0xFE)) {
|
|||
|
gb18030_first = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 9. Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 11.2.2 gb18030 encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
* @param {boolean=} gbk_flag
|
|||
|
*/
|
|||
|
function GB18030Encoder(options, gbk_flag) {
|
|||
|
var fatal = options.fatal;
|
|||
|
// gb18030's decoder has an associated gbk flag (initially unset).
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. If code point is U+E5E5, return error with code point.
|
|||
|
if (code_point === 0xE5E5)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 4. If the gbk flag is set and code point is U+20AC, return
|
|||
|
// byte 0x80.
|
|||
|
if (gbk_flag && code_point === 0x20AC)
|
|||
|
return 0x80;
|
|||
|
|
|||
|
// 5. Let pointer be the index pointer for code point in index
|
|||
|
// gb18030.
|
|||
|
var pointer = indexPointerFor(code_point, index('gb18030'));
|
|||
|
|
|||
|
// 6. If pointer is not null, run these substeps:
|
|||
|
if (pointer !== null) {
|
|||
|
|
|||
|
// 1. Let lead be floor(pointer / 190) + 0x81.
|
|||
|
var lead = floor(pointer / 190) + 0x81;
|
|||
|
|
|||
|
// 2. Let trail be pointer % 190.
|
|||
|
var trail = pointer % 190;
|
|||
|
|
|||
|
// 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise.
|
|||
|
var offset = trail < 0x3F ? 0x40 : 0x41;
|
|||
|
|
|||
|
// 4. Return two bytes whose values are lead and trail + offset.
|
|||
|
return [lead, trail + offset];
|
|||
|
}
|
|||
|
|
|||
|
// 7. If gbk flag is set, return error with code point.
|
|||
|
if (gbk_flag)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 8. Set pointer to the index gb18030 ranges pointer for code
|
|||
|
// point.
|
|||
|
pointer = indexGB18030RangesPointerFor(code_point);
|
|||
|
|
|||
|
// 9. Let byte1 be floor(pointer / 10 / 126 / 10).
|
|||
|
var byte1 = floor(pointer / 10 / 126 / 10);
|
|||
|
|
|||
|
// 10. Set pointer to pointer − byte1 × 10 × 126 × 10.
|
|||
|
pointer = pointer - byte1 * 10 * 126 * 10;
|
|||
|
|
|||
|
// 11. Let byte2 be floor(pointer / 10 / 126).
|
|||
|
var byte2 = floor(pointer / 10 / 126);
|
|||
|
|
|||
|
// 12. Set pointer to pointer − byte2 × 10 × 126.
|
|||
|
pointer = pointer - byte2 * 10 * 126;
|
|||
|
|
|||
|
// 13. Let byte3 be floor(pointer / 10).
|
|||
|
var byte3 = floor(pointer / 10);
|
|||
|
|
|||
|
// 14. Let byte4 be pointer − byte3 × 10.
|
|||
|
var byte4 = pointer - byte3 * 10;
|
|||
|
|
|||
|
// 15. Return four bytes whose values are byte1 + 0x81, byte2 +
|
|||
|
// 0x30, byte3 + 0x81, byte4 + 0x30.
|
|||
|
return [byte1 + 0x81,
|
|||
|
byte2 + 0x30,
|
|||
|
byte3 + 0x81,
|
|||
|
byte4 + 0x30];
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['gb18030'] = function(options) {
|
|||
|
return new GB18030Encoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['gb18030'] = function(options) {
|
|||
|
return new GB18030Decoder(options);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// 12. Legacy multi-byte Chinese (traditional) encodings
|
|||
|
//
|
|||
|
|
|||
|
// 12.1 Big5
|
|||
|
|
|||
|
// 12.1.1 Big5 decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function Big5Decoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
// Big5's decoder has an associated Big5 lead (initially 0x00).
|
|||
|
var /** @type {number} */ Big5_lead = 0x00;
|
|||
|
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and Big5 lead is not 0x00, set
|
|||
|
// Big5 lead to 0x00 and return error.
|
|||
|
if (bite === end_of_stream && Big5_lead !== 0x00) {
|
|||
|
Big5_lead = 0x00;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 2. If byte is end-of-stream and Big5 lead is 0x00, return
|
|||
|
// finished.
|
|||
|
if (bite === end_of_stream && Big5_lead === 0x00)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 3. If Big5 lead is not 0x00, let lead be Big5 lead, let
|
|||
|
// pointer be null, set Big5 lead to 0x00, and then run these
|
|||
|
// substeps:
|
|||
|
if (Big5_lead !== 0x00) {
|
|||
|
var lead = Big5_lead;
|
|||
|
var pointer = null;
|
|||
|
Big5_lead = 0x00;
|
|||
|
|
|||
|
// 1. Let offset be 0x40 if byte is less than 0x7F and 0x62
|
|||
|
// otherwise.
|
|||
|
var offset = bite < 0x7F ? 0x40 : 0x62;
|
|||
|
|
|||
|
// 2. If byte is in the range 0x40 to 0x7E, inclusive, or 0xA1
|
|||
|
// to 0xFE, inclusive, set pointer to (lead − 0x81) × 157 +
|
|||
|
// (byte − offset).
|
|||
|
if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE))
|
|||
|
pointer = (lead - 0x81) * 157 + (bite - offset);
|
|||
|
|
|||
|
// 3. If there is a row in the table below whose first column
|
|||
|
// is pointer, return the two code points listed in its second
|
|||
|
// column
|
|||
|
// Pointer | Code points
|
|||
|
// --------+--------------
|
|||
|
// 1133 | U+00CA U+0304
|
|||
|
// 1135 | U+00CA U+030C
|
|||
|
// 1164 | U+00EA U+0304
|
|||
|
// 1166 | U+00EA U+030C
|
|||
|
switch (pointer) {
|
|||
|
case 1133: return [0x00CA, 0x0304];
|
|||
|
case 1135: return [0x00CA, 0x030C];
|
|||
|
case 1164: return [0x00EA, 0x0304];
|
|||
|
case 1166: return [0x00EA, 0x030C];
|
|||
|
}
|
|||
|
|
|||
|
// 4. Let code point be null if pointer is null and the index
|
|||
|
// code point for pointer in index Big5 otherwise.
|
|||
|
var code_point = (pointer === null) ? null :
|
|||
|
indexCodePointFor(pointer, index('big5'));
|
|||
|
|
|||
|
// 5. If code point is null and byte is an ASCII byte, prepend
|
|||
|
// byte to stream.
|
|||
|
if (code_point === null && isASCIIByte(bite))
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 6. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 7. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// 4. If byte is an ASCII byte, return a code point whose value
|
|||
|
// is byte.
|
|||
|
if (isASCIIByte(bite))
|
|||
|
return bite;
|
|||
|
|
|||
|
// 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5
|
|||
|
// lead to byte and return continue.
|
|||
|
if (inRange(bite, 0x81, 0xFE)) {
|
|||
|
Big5_lead = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 6. Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 12.1.2 Big5 encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function Big5Encoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. Let pointer be the index Big5 pointer for code point.
|
|||
|
var pointer = indexBig5PointerFor(code_point);
|
|||
|
|
|||
|
// 4. If pointer is null, return error with code point.
|
|||
|
if (pointer === null)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 5. Let lead be floor(pointer / 157) + 0x81.
|
|||
|
var lead = floor(pointer / 157) + 0x81;
|
|||
|
|
|||
|
// 6. If lead is less than 0xA1, return error with code point.
|
|||
|
if (lead < 0xA1)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 7. Let trail be pointer % 157.
|
|||
|
var trail = pointer % 157;
|
|||
|
|
|||
|
// 8. Let offset be 0x40 if trail is less than 0x3F and 0x62
|
|||
|
// otherwise.
|
|||
|
var offset = trail < 0x3F ? 0x40 : 0x62;
|
|||
|
|
|||
|
// Return two bytes whose values are lead and trail + offset.
|
|||
|
return [lead, trail + offset];
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['Big5'] = function(options) {
|
|||
|
return new Big5Encoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['Big5'] = function(options) {
|
|||
|
return new Big5Decoder(options);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// 13. Legacy multi-byte Japanese encodings
|
|||
|
//
|
|||
|
|
|||
|
// 13.1 euc-jp
|
|||
|
|
|||
|
// 13.1.1 euc-jp decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function EUCJPDecoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
|
|||
|
// euc-jp's decoder has an associated euc-jp jis0212 flag
|
|||
|
// (initially unset) and euc-jp lead (initially 0x00).
|
|||
|
var /** @type {boolean} */ eucjp_jis0212_flag = false,
|
|||
|
/** @type {number} */ eucjp_lead = 0x00;
|
|||
|
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and euc-jp lead is not 0x00, set
|
|||
|
// euc-jp lead to 0x00, and return error.
|
|||
|
if (bite === end_of_stream && eucjp_lead !== 0x00) {
|
|||
|
eucjp_lead = 0x00;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 2. If byte is end-of-stream and euc-jp lead is 0x00, return
|
|||
|
// finished.
|
|||
|
if (bite === end_of_stream && eucjp_lead === 0x00)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 3. If euc-jp lead is 0x8E and byte is in the range 0xA1 to
|
|||
|
// 0xDF, inclusive, set euc-jp lead to 0x00 and return a code
|
|||
|
// point whose value is 0xFF61 − 0xA1 + byte.
|
|||
|
if (eucjp_lead === 0x8E && inRange(bite, 0xA1, 0xDF)) {
|
|||
|
eucjp_lead = 0x00;
|
|||
|
return 0xFF61 - 0xA1 + bite;
|
|||
|
}
|
|||
|
|
|||
|
// 4. If euc-jp lead is 0x8F and byte is in the range 0xA1 to
|
|||
|
// 0xFE, inclusive, set the euc-jp jis0212 flag, set euc-jp lead
|
|||
|
// to byte, and return continue.
|
|||
|
if (eucjp_lead === 0x8F && inRange(bite, 0xA1, 0xFE)) {
|
|||
|
eucjp_jis0212_flag = true;
|
|||
|
eucjp_lead = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 5. If euc-jp lead is not 0x00, let lead be euc-jp lead, set
|
|||
|
// euc-jp lead to 0x00, and run these substeps:
|
|||
|
if (eucjp_lead !== 0x00) {
|
|||
|
var lead = eucjp_lead;
|
|||
|
eucjp_lead = 0x00;
|
|||
|
|
|||
|
// 1. Let code point be null.
|
|||
|
var code_point = null;
|
|||
|
|
|||
|
// 2. If lead and byte are both in the range 0xA1 to 0xFE,
|
|||
|
// inclusive, set code point to the index code point for (lead
|
|||
|
// − 0xA1) × 94 + byte − 0xA1 in index jis0208 if the euc-jp
|
|||
|
// jis0212 flag is unset and in index jis0212 otherwise.
|
|||
|
if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) {
|
|||
|
code_point = indexCodePointFor(
|
|||
|
(lead - 0xA1) * 94 + (bite - 0xA1),
|
|||
|
index(!eucjp_jis0212_flag ? 'jis0208' : 'jis0212'));
|
|||
|
}
|
|||
|
|
|||
|
// 3. Unset the euc-jp jis0212 flag.
|
|||
|
eucjp_jis0212_flag = false;
|
|||
|
|
|||
|
// 4. If byte is not in the range 0xA1 to 0xFE, inclusive,
|
|||
|
// prepend byte to stream.
|
|||
|
if (!inRange(bite, 0xA1, 0xFE))
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 5. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 6. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// 6. If byte is an ASCII byte, return a code point whose value
|
|||
|
// is byte.
|
|||
|
if (isASCIIByte(bite))
|
|||
|
return bite;
|
|||
|
|
|||
|
// 7. If byte is 0x8E, 0x8F, or in the range 0xA1 to 0xFE,
|
|||
|
// inclusive, set euc-jp lead to byte and return continue.
|
|||
|
if (bite === 0x8E || bite === 0x8F || inRange(bite, 0xA1, 0xFE)) {
|
|||
|
eucjp_lead = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 8. Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 13.1.2 euc-jp encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function EUCJPEncoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. If code point is U+00A5, return byte 0x5C.
|
|||
|
if (code_point === 0x00A5)
|
|||
|
return 0x5C;
|
|||
|
|
|||
|
// 4. If code point is U+203E, return byte 0x7E.
|
|||
|
if (code_point === 0x203E)
|
|||
|
return 0x7E;
|
|||
|
|
|||
|
// 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
|
|||
|
// return two bytes whose values are 0x8E and code point −
|
|||
|
// 0xFF61 + 0xA1.
|
|||
|
if (inRange(code_point, 0xFF61, 0xFF9F))
|
|||
|
return [0x8E, code_point - 0xFF61 + 0xA1];
|
|||
|
|
|||
|
// 6. If code point is U+2212, set it to U+FF0D.
|
|||
|
if (code_point === 0x2212)
|
|||
|
code_point = 0xFF0D;
|
|||
|
|
|||
|
// 7. Let pointer be the index pointer for code point in index
|
|||
|
// jis0208.
|
|||
|
var pointer = indexPointerFor(code_point, index('jis0208'));
|
|||
|
|
|||
|
// 8. If pointer is null, return error with code point.
|
|||
|
if (pointer === null)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 9. Let lead be floor(pointer / 94) + 0xA1.
|
|||
|
var lead = floor(pointer / 94) + 0xA1;
|
|||
|
|
|||
|
// 10. Let trail be pointer % 94 + 0xA1.
|
|||
|
var trail = pointer % 94 + 0xA1;
|
|||
|
|
|||
|
// 11. Return two bytes whose values are lead and trail.
|
|||
|
return [lead, trail];
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['EUC-JP'] = function(options) {
|
|||
|
return new EUCJPEncoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['EUC-JP'] = function(options) {
|
|||
|
return new EUCJPDecoder(options);
|
|||
|
};
|
|||
|
|
|||
|
// 13.2 iso-2022-jp
|
|||
|
|
|||
|
// 13.2.1 iso-2022-jp decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function ISO2022JPDecoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/** @enum */
|
|||
|
var states = {
|
|||
|
ASCII: 0,
|
|||
|
Roman: 1,
|
|||
|
Katakana: 2,
|
|||
|
LeadByte: 3,
|
|||
|
TrailByte: 4,
|
|||
|
EscapeStart: 5,
|
|||
|
Escape: 6
|
|||
|
};
|
|||
|
// iso-2022-jp's decoder has an associated iso-2022-jp decoder
|
|||
|
// state (initially ASCII), iso-2022-jp decoder output state
|
|||
|
// (initially ASCII), iso-2022-jp lead (initially 0x00), and
|
|||
|
// iso-2022-jp output flag (initially unset).
|
|||
|
var /** @type {number} */ iso2022jp_decoder_state = states.ASCII,
|
|||
|
/** @type {number} */ iso2022jp_decoder_output_state = states.ASCII,
|
|||
|
/** @type {number} */ iso2022jp_lead = 0x00,
|
|||
|
/** @type {boolean} */ iso2022jp_output_flag = false;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// switching on iso-2022-jp decoder state:
|
|||
|
switch (iso2022jp_decoder_state) {
|
|||
|
default:
|
|||
|
case states.ASCII:
|
|||
|
// ASCII
|
|||
|
// Based on byte:
|
|||
|
|
|||
|
// 0x1B
|
|||
|
if (bite === 0x1B) {
|
|||
|
// Set iso-2022-jp decoder state to escape start and return
|
|||
|
// continue.
|
|||
|
iso2022jp_decoder_state = states.EscapeStart;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 0x00 to 0x7F, excluding 0x0E, 0x0F, and 0x1B
|
|||
|
if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E
|
|||
|
&& bite !== 0x0F && bite !== 0x1B) {
|
|||
|
// Unset the iso-2022-jp output flag and return a code point
|
|||
|
// whose value is byte.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return bite;
|
|||
|
}
|
|||
|
|
|||
|
// end-of-stream
|
|||
|
if (bite === end_of_stream) {
|
|||
|
// Return finished.
|
|||
|
return finished;
|
|||
|
}
|
|||
|
|
|||
|
// Otherwise
|
|||
|
// Unset the iso-2022-jp output flag and return error.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
case states.Roman:
|
|||
|
// Roman
|
|||
|
// Based on byte:
|
|||
|
|
|||
|
// 0x1B
|
|||
|
if (bite === 0x1B) {
|
|||
|
// Set iso-2022-jp decoder state to escape start and return
|
|||
|
// continue.
|
|||
|
iso2022jp_decoder_state = states.EscapeStart;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 0x5C
|
|||
|
if (bite === 0x5C) {
|
|||
|
// Unset the iso-2022-jp output flag and return code point
|
|||
|
// U+00A5.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return 0x00A5;
|
|||
|
}
|
|||
|
|
|||
|
// 0x7E
|
|||
|
if (bite === 0x7E) {
|
|||
|
// Unset the iso-2022-jp output flag and return code point
|
|||
|
// U+203E.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return 0x203E;
|
|||
|
}
|
|||
|
|
|||
|
// 0x00 to 0x7F, excluding 0x0E, 0x0F, 0x1B, 0x5C, and 0x7E
|
|||
|
if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E && bite !== 0x0F
|
|||
|
&& bite !== 0x1B && bite !== 0x5C && bite !== 0x7E) {
|
|||
|
// Unset the iso-2022-jp output flag and return a code point
|
|||
|
// whose value is byte.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return bite;
|
|||
|
}
|
|||
|
|
|||
|
// end-of-stream
|
|||
|
if (bite === end_of_stream) {
|
|||
|
// Return finished.
|
|||
|
return finished;
|
|||
|
}
|
|||
|
|
|||
|
// Otherwise
|
|||
|
// Unset the iso-2022-jp output flag and return error.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
case states.Katakana:
|
|||
|
// Katakana
|
|||
|
// Based on byte:
|
|||
|
|
|||
|
// 0x1B
|
|||
|
if (bite === 0x1B) {
|
|||
|
// Set iso-2022-jp decoder state to escape start and return
|
|||
|
// continue.
|
|||
|
iso2022jp_decoder_state = states.EscapeStart;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 0x21 to 0x5F
|
|||
|
if (inRange(bite, 0x21, 0x5F)) {
|
|||
|
// Unset the iso-2022-jp output flag and return a code point
|
|||
|
// whose value is 0xFF61 − 0x21 + byte.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return 0xFF61 - 0x21 + bite;
|
|||
|
}
|
|||
|
|
|||
|
// end-of-stream
|
|||
|
if (bite === end_of_stream) {
|
|||
|
// Return finished.
|
|||
|
return finished;
|
|||
|
}
|
|||
|
|
|||
|
// Otherwise
|
|||
|
// Unset the iso-2022-jp output flag and return error.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
case states.LeadByte:
|
|||
|
// Lead byte
|
|||
|
// Based on byte:
|
|||
|
|
|||
|
// 0x1B
|
|||
|
if (bite === 0x1B) {
|
|||
|
// Set iso-2022-jp decoder state to escape start and return
|
|||
|
// continue.
|
|||
|
iso2022jp_decoder_state = states.EscapeStart;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 0x21 to 0x7E
|
|||
|
if (inRange(bite, 0x21, 0x7E)) {
|
|||
|
// Unset the iso-2022-jp output flag, set iso-2022-jp lead
|
|||
|
// to byte, iso-2022-jp decoder state to trail byte, and
|
|||
|
// return continue.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
iso2022jp_lead = bite;
|
|||
|
iso2022jp_decoder_state = states.TrailByte;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// end-of-stream
|
|||
|
if (bite === end_of_stream) {
|
|||
|
// Return finished.
|
|||
|
return finished;
|
|||
|
}
|
|||
|
|
|||
|
// Otherwise
|
|||
|
// Unset the iso-2022-jp output flag and return error.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
case states.TrailByte:
|
|||
|
// Trail byte
|
|||
|
// Based on byte:
|
|||
|
|
|||
|
// 0x1B
|
|||
|
if (bite === 0x1B) {
|
|||
|
// Set iso-2022-jp decoder state to escape start and return
|
|||
|
// continue.
|
|||
|
iso2022jp_decoder_state = states.EscapeStart;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 0x21 to 0x7E
|
|||
|
if (inRange(bite, 0x21, 0x7E)) {
|
|||
|
// 1. Set the iso-2022-jp decoder state to lead byte.
|
|||
|
iso2022jp_decoder_state = states.LeadByte;
|
|||
|
|
|||
|
// 2. Let pointer be (iso-2022-jp lead − 0x21) × 94 + byte − 0x21.
|
|||
|
var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21;
|
|||
|
|
|||
|
// 3. Let code point be the index code point for pointer in
|
|||
|
// index jis0208.
|
|||
|
var code_point = indexCodePointFor(pointer, index('jis0208'));
|
|||
|
|
|||
|
// 4. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 5. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// end-of-stream
|
|||
|
if (bite === end_of_stream) {
|
|||
|
// Set the iso-2022-jp decoder state to lead byte, prepend
|
|||
|
// byte to stream, and return error.
|
|||
|
iso2022jp_decoder_state = states.LeadByte;
|
|||
|
stream.prepend(bite);
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// Otherwise
|
|||
|
// Set iso-2022-jp decoder state to lead byte and return
|
|||
|
// error.
|
|||
|
iso2022jp_decoder_state = states.LeadByte;
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
case states.EscapeStart:
|
|||
|
// Escape start
|
|||
|
|
|||
|
// 1. If byte is either 0x24 or 0x28, set iso-2022-jp lead to
|
|||
|
// byte, iso-2022-jp decoder state to escape, and return
|
|||
|
// continue.
|
|||
|
if (bite === 0x24 || bite === 0x28) {
|
|||
|
iso2022jp_lead = bite;
|
|||
|
iso2022jp_decoder_state = states.Escape;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 2. Prepend byte to stream.
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 3. Unset the iso-2022-jp output flag, set iso-2022-jp
|
|||
|
// decoder state to iso-2022-jp decoder output state, and
|
|||
|
// return error.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
iso2022jp_decoder_state = iso2022jp_decoder_output_state;
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
case states.Escape:
|
|||
|
// Escape
|
|||
|
|
|||
|
// 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to
|
|||
|
// 0x00.
|
|||
|
var lead = iso2022jp_lead;
|
|||
|
iso2022jp_lead = 0x00;
|
|||
|
|
|||
|
// 2. Let state be null.
|
|||
|
var state = null;
|
|||
|
|
|||
|
// 3. If lead is 0x28 and byte is 0x42, set state to ASCII.
|
|||
|
if (lead === 0x28 && bite === 0x42)
|
|||
|
state = states.ASCII;
|
|||
|
|
|||
|
// 4. If lead is 0x28 and byte is 0x4A, set state to Roman.
|
|||
|
if (lead === 0x28 && bite === 0x4A)
|
|||
|
state = states.Roman;
|
|||
|
|
|||
|
// 5. If lead is 0x28 and byte is 0x49, set state to Katakana.
|
|||
|
if (lead === 0x28 && bite === 0x49)
|
|||
|
state = states.Katakana;
|
|||
|
|
|||
|
// 6. If lead is 0x24 and byte is either 0x40 or 0x42, set
|
|||
|
// state to lead byte.
|
|||
|
if (lead === 0x24 && (bite === 0x40 || bite === 0x42))
|
|||
|
state = states.LeadByte;
|
|||
|
|
|||
|
// 7. If state is non-null, run these substeps:
|
|||
|
if (state !== null) {
|
|||
|
// 1. Set iso-2022-jp decoder state and iso-2022-jp decoder
|
|||
|
// output state to states.
|
|||
|
iso2022jp_decoder_state = iso2022jp_decoder_state = state;
|
|||
|
|
|||
|
// 2. Let output flag be the iso-2022-jp output flag.
|
|||
|
var output_flag = iso2022jp_output_flag;
|
|||
|
|
|||
|
// 3. Set the iso-2022-jp output flag.
|
|||
|
iso2022jp_output_flag = true;
|
|||
|
|
|||
|
// 4. Return continue, if output flag is unset, and error
|
|||
|
// otherwise.
|
|||
|
return !output_flag ? null : decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 8. Prepend lead and byte to stream.
|
|||
|
stream.prepend([lead, bite]);
|
|||
|
|
|||
|
// 9. Unset the iso-2022-jp output flag, set iso-2022-jp
|
|||
|
// decoder state to iso-2022-jp decoder output state and
|
|||
|
// return error.
|
|||
|
iso2022jp_output_flag = false;
|
|||
|
iso2022jp_decoder_state = iso2022jp_decoder_output_state;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 13.2.2 iso-2022-jp encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function ISO2022JPEncoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
// iso-2022-jp's encoder has an associated iso-2022-jp encoder
|
|||
|
// state which is one of ASCII, Roman, and jis0208 (initially
|
|||
|
// ASCII).
|
|||
|
/** @enum */
|
|||
|
var states = {
|
|||
|
ASCII: 0,
|
|||
|
Roman: 1,
|
|||
|
jis0208: 2
|
|||
|
};
|
|||
|
var /** @type {number} */ iso2022jp_state = states.ASCII;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream and iso-2022-jp encoder
|
|||
|
// state is not ASCII, prepend code point to stream, set
|
|||
|
// iso-2022-jp encoder state to ASCII, and return three bytes
|
|||
|
// 0x1B 0x28 0x42.
|
|||
|
if (code_point === end_of_stream &&
|
|||
|
iso2022jp_state !== states.ASCII) {
|
|||
|
stream.prepend(code_point);
|
|||
|
iso2022jp_state = states.ASCII;
|
|||
|
return [0x1B, 0x28, 0x42];
|
|||
|
}
|
|||
|
|
|||
|
// 2. If code point is end-of-stream and iso-2022-jp encoder
|
|||
|
// state is ASCII, return finished.
|
|||
|
if (code_point === end_of_stream && iso2022jp_state === states.ASCII)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 3. If ISO-2022-JP encoder state is ASCII or Roman, and code
|
|||
|
// point is U+000E, U+000F, or U+001B, return error with U+FFFD.
|
|||
|
if ((iso2022jp_state === states.ASCII ||
|
|||
|
iso2022jp_state === states.Roman) &&
|
|||
|
(code_point === 0x000E || code_point === 0x000F ||
|
|||
|
code_point === 0x001B)) {
|
|||
|
return encoderError(0xFFFD);
|
|||
|
}
|
|||
|
|
|||
|
// 4. If iso-2022-jp encoder state is ASCII and code point is an
|
|||
|
// ASCII code point, return a byte whose value is code point.
|
|||
|
if (iso2022jp_state === states.ASCII &&
|
|||
|
isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 5. If iso-2022-jp encoder state is Roman and code point is an
|
|||
|
// ASCII code point, excluding U+005C and U+007E, or is U+00A5
|
|||
|
// or U+203E, run these substeps:
|
|||
|
if (iso2022jp_state === states.Roman &&
|
|||
|
((isASCIICodePoint(code_point) &&
|
|||
|
code_point !== 0x005C && code_point !== 0x007E) ||
|
|||
|
(code_point == 0x00A5 || code_point == 0x203E))) {
|
|||
|
|
|||
|
// 1. If code point is an ASCII code point, return a byte
|
|||
|
// whose value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 2. If code point is U+00A5, return byte 0x5C.
|
|||
|
if (code_point === 0x00A5)
|
|||
|
return 0x5C;
|
|||
|
|
|||
|
// 3. If code point is U+203E, return byte 0x7E.
|
|||
|
if (code_point === 0x203E)
|
|||
|
return 0x7E;
|
|||
|
}
|
|||
|
|
|||
|
// 6. If code point is an ASCII code point, and iso-2022-jp
|
|||
|
// encoder state is not ASCII, prepend code point to stream, set
|
|||
|
// iso-2022-jp encoder state to ASCII, and return three bytes
|
|||
|
// 0x1B 0x28 0x42.
|
|||
|
if (isASCIICodePoint(code_point) &&
|
|||
|
iso2022jp_state !== states.ASCII) {
|
|||
|
stream.prepend(code_point);
|
|||
|
iso2022jp_state = states.ASCII;
|
|||
|
return [0x1B, 0x28, 0x42];
|
|||
|
}
|
|||
|
|
|||
|
// 7. If code point is either U+00A5 or U+203E, and iso-2022-jp
|
|||
|
// encoder state is not Roman, prepend code point to stream, set
|
|||
|
// iso-2022-jp encoder state to Roman, and return three bytes
|
|||
|
// 0x1B 0x28 0x4A.
|
|||
|
if ((code_point === 0x00A5 || code_point === 0x203E) &&
|
|||
|
iso2022jp_state !== states.Roman) {
|
|||
|
stream.prepend(code_point);
|
|||
|
iso2022jp_state = states.Roman;
|
|||
|
return [0x1B, 0x28, 0x4A];
|
|||
|
}
|
|||
|
|
|||
|
// 8. If code point is U+2212, set it to U+FF0D.
|
|||
|
if (code_point === 0x2212)
|
|||
|
code_point = 0xFF0D;
|
|||
|
|
|||
|
// 9. Let pointer be the index pointer for code point in index
|
|||
|
// jis0208.
|
|||
|
var pointer = indexPointerFor(code_point, index('jis0208'));
|
|||
|
|
|||
|
// 10. If pointer is null, return error with code point.
|
|||
|
if (pointer === null)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 11. If iso-2022-jp encoder state is not jis0208, prepend code
|
|||
|
// point to stream, set iso-2022-jp encoder state to jis0208,
|
|||
|
// and return three bytes 0x1B 0x24 0x42.
|
|||
|
if (iso2022jp_state !== states.jis0208) {
|
|||
|
stream.prepend(code_point);
|
|||
|
iso2022jp_state = states.jis0208;
|
|||
|
return [0x1B, 0x24, 0x42];
|
|||
|
}
|
|||
|
|
|||
|
// 12. Let lead be floor(pointer / 94) + 0x21.
|
|||
|
var lead = floor(pointer / 94) + 0x21;
|
|||
|
|
|||
|
// 13. Let trail be pointer % 94 + 0x21.
|
|||
|
var trail = pointer % 94 + 0x21;
|
|||
|
|
|||
|
// 14. Return two bytes whose values are lead and trail.
|
|||
|
return [lead, trail];
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['ISO-2022-JP'] = function(options) {
|
|||
|
return new ISO2022JPEncoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['ISO-2022-JP'] = function(options) {
|
|||
|
return new ISO2022JPDecoder(options);
|
|||
|
};
|
|||
|
|
|||
|
// 13.3 Shift_JIS
|
|||
|
|
|||
|
// 13.3.1 Shift_JIS decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function ShiftJISDecoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
// Shift_JIS's decoder has an associated Shift_JIS lead (initially
|
|||
|
// 0x00).
|
|||
|
var /** @type {number} */ Shift_JIS_lead = 0x00;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and Shift_JIS lead is not 0x00,
|
|||
|
// set Shift_JIS lead to 0x00 and return error.
|
|||
|
if (bite === end_of_stream && Shift_JIS_lead !== 0x00) {
|
|||
|
Shift_JIS_lead = 0x00;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 2. If byte is end-of-stream and Shift_JIS lead is 0x00,
|
|||
|
// return finished.
|
|||
|
if (bite === end_of_stream && Shift_JIS_lead === 0x00)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 3. If Shift_JIS lead is not 0x00, let lead be Shift_JIS lead,
|
|||
|
// let pointer be null, set Shift_JIS lead to 0x00, and then run
|
|||
|
// these substeps:
|
|||
|
if (Shift_JIS_lead !== 0x00) {
|
|||
|
var lead = Shift_JIS_lead;
|
|||
|
var pointer = null;
|
|||
|
Shift_JIS_lead = 0x00;
|
|||
|
|
|||
|
// 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41
|
|||
|
// otherwise.
|
|||
|
var offset = (bite < 0x7F) ? 0x40 : 0x41;
|
|||
|
|
|||
|
// 2. Let lead offset be 0x81, if lead is less than 0xA0, and
|
|||
|
// 0xC1 otherwise.
|
|||
|
var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1;
|
|||
|
|
|||
|
// 3. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
|
|||
|
// to 0xFC, inclusive, set pointer to (lead − lead offset) ×
|
|||
|
// 188 + byte − offset.
|
|||
|
if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC))
|
|||
|
pointer = (lead - lead_offset) * 188 + bite - offset;
|
|||
|
|
|||
|
// 4. If pointer is in the range 8836 to 10715, inclusive,
|
|||
|
// return a code point whose value is 0xE000 − 8836 + pointer.
|
|||
|
if (inRange(pointer, 8836, 10715))
|
|||
|
return 0xE000 - 8836 + pointer;
|
|||
|
|
|||
|
// 5. Let code point be null, if pointer is null, and the
|
|||
|
// index code point for pointer in index jis0208 otherwise.
|
|||
|
var code_point = (pointer === null) ? null :
|
|||
|
indexCodePointFor(pointer, index('jis0208'));
|
|||
|
|
|||
|
// 6. If code point is null and byte is an ASCII byte, prepend
|
|||
|
// byte to stream.
|
|||
|
if (code_point === null && isASCIIByte(bite))
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 7. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 8. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// 4. If byte is an ASCII byte or 0x80, return a code point
|
|||
|
// whose value is byte.
|
|||
|
if (isASCIIByte(bite) || bite === 0x80)
|
|||
|
return bite;
|
|||
|
|
|||
|
// 5. If byte is in the range 0xA1 to 0xDF, inclusive, return a
|
|||
|
// code point whose value is 0xFF61 − 0xA1 + byte.
|
|||
|
if (inRange(bite, 0xA1, 0xDF))
|
|||
|
return 0xFF61 - 0xA1 + bite;
|
|||
|
|
|||
|
// 6. If byte is in the range 0x81 to 0x9F, inclusive, or 0xE0
|
|||
|
// to 0xFC, inclusive, set Shift_JIS lead to byte and return
|
|||
|
// continue.
|
|||
|
if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) {
|
|||
|
Shift_JIS_lead = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 7. Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 13.3.2 Shift_JIS encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function ShiftJISEncoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point or U+0080, return a
|
|||
|
// byte whose value is code point.
|
|||
|
if (isASCIICodePoint(code_point) || code_point === 0x0080)
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. If code point is U+00A5, return byte 0x5C.
|
|||
|
if (code_point === 0x00A5)
|
|||
|
return 0x5C;
|
|||
|
|
|||
|
// 4. If code point is U+203E, return byte 0x7E.
|
|||
|
if (code_point === 0x203E)
|
|||
|
return 0x7E;
|
|||
|
|
|||
|
// 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
|
|||
|
// return a byte whose value is code point − 0xFF61 + 0xA1.
|
|||
|
if (inRange(code_point, 0xFF61, 0xFF9F))
|
|||
|
return code_point - 0xFF61 + 0xA1;
|
|||
|
|
|||
|
// 6. If code point is U+2212, set it to U+FF0D.
|
|||
|
if (code_point === 0x2212)
|
|||
|
code_point = 0xFF0D;
|
|||
|
|
|||
|
// 7. Let pointer be the index Shift_JIS pointer for code point.
|
|||
|
var pointer = indexShiftJISPointerFor(code_point);
|
|||
|
|
|||
|
// 8. If pointer is null, return error with code point.
|
|||
|
if (pointer === null)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 9. Let lead be floor(pointer / 188).
|
|||
|
var lead = floor(pointer / 188);
|
|||
|
|
|||
|
// 10. Let lead offset be 0x81, if lead is less than 0x1F, and
|
|||
|
// 0xC1 otherwise.
|
|||
|
var lead_offset = (lead < 0x1F) ? 0x81 : 0xC1;
|
|||
|
|
|||
|
// 11. Let trail be pointer % 188.
|
|||
|
var trail = pointer % 188;
|
|||
|
|
|||
|
// 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41
|
|||
|
// otherwise.
|
|||
|
var offset = (trail < 0x3F) ? 0x40 : 0x41;
|
|||
|
|
|||
|
// 13. Return two bytes whose values are lead + lead offset and
|
|||
|
// trail + offset.
|
|||
|
return [lead + lead_offset, trail + offset];
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['Shift_JIS'] = function(options) {
|
|||
|
return new ShiftJISEncoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['Shift_JIS'] = function(options) {
|
|||
|
return new ShiftJISDecoder(options);
|
|||
|
};
|
|||
|
|
|||
|
//
|
|||
|
// 14. Legacy multi-byte Korean encodings
|
|||
|
//
|
|||
|
|
|||
|
// 14.1 euc-kr
|
|||
|
|
|||
|
// 14.1.1 euc-kr decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function EUCKRDecoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
|
|||
|
// euc-kr's decoder has an associated euc-kr lead (initially 0x00).
|
|||
|
var /** @type {number} */ euckr_lead = 0x00;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and euc-kr lead is not 0x00, set
|
|||
|
// euc-kr lead to 0x00 and return error.
|
|||
|
if (bite === end_of_stream && euckr_lead !== 0) {
|
|||
|
euckr_lead = 0x00;
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 2. If byte is end-of-stream and euc-kr lead is 0x00, return
|
|||
|
// finished.
|
|||
|
if (bite === end_of_stream && euckr_lead === 0)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let
|
|||
|
// pointer be null, set euc-kr lead to 0x00, and then run these
|
|||
|
// substeps:
|
|||
|
if (euckr_lead !== 0x00) {
|
|||
|
var lead = euckr_lead;
|
|||
|
var pointer = null;
|
|||
|
euckr_lead = 0x00;
|
|||
|
|
|||
|
// 1. If byte is in the range 0x41 to 0xFE, inclusive, set
|
|||
|
// pointer to (lead − 0x81) × 190 + (byte − 0x41).
|
|||
|
if (inRange(bite, 0x41, 0xFE))
|
|||
|
pointer = (lead - 0x81) * 190 + (bite - 0x41);
|
|||
|
|
|||
|
// 2. Let code point be null, if pointer is null, and the
|
|||
|
// index code point for pointer in index euc-kr otherwise.
|
|||
|
var code_point = (pointer === null)
|
|||
|
? null : indexCodePointFor(pointer, index('euc-kr'));
|
|||
|
|
|||
|
// 3. If code point is null and byte is an ASCII byte, prepend
|
|||
|
// byte to stream.
|
|||
|
if (pointer === null && isASCIIByte(bite))
|
|||
|
stream.prepend(bite);
|
|||
|
|
|||
|
// 4. If code point is null, return error.
|
|||
|
if (code_point === null)
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 5. Return a code point whose value is code point.
|
|||
|
return code_point;
|
|||
|
}
|
|||
|
|
|||
|
// 4. If byte is an ASCII byte, return a code point whose value
|
|||
|
// is byte.
|
|||
|
if (isASCIIByte(bite))
|
|||
|
return bite;
|
|||
|
|
|||
|
// 5. If byte is in the range 0x81 to 0xFE, inclusive, set
|
|||
|
// euc-kr lead to byte and return continue.
|
|||
|
if (inRange(bite, 0x81, 0xFE)) {
|
|||
|
euckr_lead = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 6. Return error.
|
|||
|
return decoderError(fatal);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 14.1.2 euc-kr encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function EUCKREncoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. Let pointer be the index pointer for code point in index
|
|||
|
// euc-kr.
|
|||
|
var pointer = indexPointerFor(code_point, index('euc-kr'));
|
|||
|
|
|||
|
// 4. If pointer is null, return error with code point.
|
|||
|
if (pointer === null)
|
|||
|
return encoderError(code_point);
|
|||
|
|
|||
|
// 5. Let lead be floor(pointer / 190) + 0x81.
|
|||
|
var lead = floor(pointer / 190) + 0x81;
|
|||
|
|
|||
|
// 6. Let trail be pointer % 190 + 0x41.
|
|||
|
var trail = (pointer % 190) + 0x41;
|
|||
|
|
|||
|
// 7. Return two bytes whose values are lead and trail.
|
|||
|
return [lead, trail];
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['EUC-KR'] = function(options) {
|
|||
|
return new EUCKREncoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['EUC-KR'] = function(options) {
|
|||
|
return new EUCKRDecoder(options);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//
|
|||
|
// 15. Legacy miscellaneous encodings
|
|||
|
//
|
|||
|
|
|||
|
// 15.1 replacement
|
|||
|
|
|||
|
// Not needed - API throws RangeError
|
|||
|
|
|||
|
// 15.2 Common infrastructure for utf-16be and utf-16le
|
|||
|
|
|||
|
/**
|
|||
|
* @param {number} code_unit
|
|||
|
* @param {boolean} utf16be
|
|||
|
* @return {!Array.<number>} bytes
|
|||
|
*/
|
|||
|
function convertCodeUnitToBytes(code_unit, utf16be) {
|
|||
|
// 1. Let byte1 be code unit >> 8.
|
|||
|
var byte1 = code_unit >> 8;
|
|||
|
|
|||
|
// 2. Let byte2 be code unit & 0x00FF.
|
|||
|
var byte2 = code_unit & 0x00FF;
|
|||
|
|
|||
|
// 3. Then return the bytes in order:
|
|||
|
// utf-16be flag is set: byte1, then byte2.
|
|||
|
if (utf16be)
|
|||
|
return [byte1, byte2];
|
|||
|
// utf-16be flag is unset: byte2, then byte1.
|
|||
|
return [byte2, byte1];
|
|||
|
}
|
|||
|
|
|||
|
// 15.2.1 shared utf-16 decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {boolean} utf16_be True if big-endian, false if little-endian.
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function UTF16Decoder(utf16_be, options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
var /** @type {?number} */ utf16_lead_byte = null,
|
|||
|
/** @type {?number} */ utf16_lead_surrogate = null;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream and either utf-16 lead byte or
|
|||
|
// utf-16 lead surrogate is not null, set utf-16 lead byte and
|
|||
|
// utf-16 lead surrogate to null, and return error.
|
|||
|
if (bite === end_of_stream && (utf16_lead_byte !== null ||
|
|||
|
utf16_lead_surrogate !== null)) {
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 2. If byte is end-of-stream and utf-16 lead byte and utf-16
|
|||
|
// lead surrogate are null, return finished.
|
|||
|
if (bite === end_of_stream && utf16_lead_byte === null &&
|
|||
|
utf16_lead_surrogate === null) {
|
|||
|
return finished;
|
|||
|
}
|
|||
|
|
|||
|
// 3. If utf-16 lead byte is null, set utf-16 lead byte to byte
|
|||
|
// and return continue.
|
|||
|
if (utf16_lead_byte === null) {
|
|||
|
utf16_lead_byte = bite;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 4. Let code unit be the result of:
|
|||
|
var code_unit;
|
|||
|
if (utf16_be) {
|
|||
|
// utf-16be decoder flag is set
|
|||
|
// (utf-16 lead byte << 8) + byte.
|
|||
|
code_unit = (utf16_lead_byte << 8) + bite;
|
|||
|
} else {
|
|||
|
// utf-16be decoder flag is unset
|
|||
|
// (byte << 8) + utf-16 lead byte.
|
|||
|
code_unit = (bite << 8) + utf16_lead_byte;
|
|||
|
}
|
|||
|
// Then set utf-16 lead byte to null.
|
|||
|
utf16_lead_byte = null;
|
|||
|
|
|||
|
// 5. If utf-16 lead surrogate is not null, let lead surrogate
|
|||
|
// be utf-16 lead surrogate, set utf-16 lead surrogate to null,
|
|||
|
// and then run these substeps:
|
|||
|
if (utf16_lead_surrogate !== null) {
|
|||
|
var lead_surrogate = utf16_lead_surrogate;
|
|||
|
utf16_lead_surrogate = null;
|
|||
|
|
|||
|
// 1. If code unit is in the range U+DC00 to U+DFFF,
|
|||
|
// inclusive, return a code point whose value is 0x10000 +
|
|||
|
// ((lead surrogate − 0xD800) << 10) + (code unit − 0xDC00).
|
|||
|
if (inRange(code_unit, 0xDC00, 0xDFFF)) {
|
|||
|
return 0x10000 + (lead_surrogate - 0xD800) * 0x400 +
|
|||
|
(code_unit - 0xDC00);
|
|||
|
}
|
|||
|
|
|||
|
// 2. Prepend the sequence resulting of converting code unit
|
|||
|
// to bytes using utf-16be decoder flag to stream and return
|
|||
|
// error.
|
|||
|
stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be));
|
|||
|
return decoderError(fatal);
|
|||
|
}
|
|||
|
|
|||
|
// 6. If code unit is in the range U+D800 to U+DBFF, inclusive,
|
|||
|
// set utf-16 lead surrogate to code unit and return continue.
|
|||
|
if (inRange(code_unit, 0xD800, 0xDBFF)) {
|
|||
|
utf16_lead_surrogate = code_unit;
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// 7. If code unit is in the range U+DC00 to U+DFFF, inclusive,
|
|||
|
// return error.
|
|||
|
if (inRange(code_unit, 0xDC00, 0xDFFF))
|
|||
|
return decoderError(fatal);
|
|||
|
|
|||
|
// 8. Return code point code unit.
|
|||
|
return code_unit;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 15.2.2 shared utf-16 encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {boolean} utf16_be True if big-endian, false if little-endian.
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function UTF16Encoder(utf16_be, options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1. If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is in the range U+0000 to U+FFFF, inclusive,
|
|||
|
// return the sequence resulting of converting code point to
|
|||
|
// bytes using utf-16be encoder flag.
|
|||
|
if (inRange(code_point, 0x0000, 0xFFFF))
|
|||
|
return convertCodeUnitToBytes(code_point, utf16_be);
|
|||
|
|
|||
|
// 3. Let lead be ((code point − 0x10000) >> 10) + 0xD800,
|
|||
|
// converted to bytes using utf-16be encoder flag.
|
|||
|
var lead = convertCodeUnitToBytes(
|
|||
|
((code_point - 0x10000) >> 10) + 0xD800, utf16_be);
|
|||
|
|
|||
|
// 4. Let trail be ((code point − 0x10000) & 0x3FF) + 0xDC00,
|
|||
|
// converted to bytes using utf-16be encoder flag.
|
|||
|
var trail = convertCodeUnitToBytes(
|
|||
|
((code_point - 0x10000) & 0x3FF) + 0xDC00, utf16_be);
|
|||
|
|
|||
|
// 5. Return a byte sequence of lead followed by trail.
|
|||
|
return lead.concat(trail);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 15.3 utf-16be
|
|||
|
// 15.3.1 utf-16be decoder
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['UTF-16BE'] = function(options) {
|
|||
|
return new UTF16Encoder(true, options);
|
|||
|
};
|
|||
|
// 15.3.2 utf-16be encoder
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['UTF-16BE'] = function(options) {
|
|||
|
return new UTF16Decoder(true, options);
|
|||
|
};
|
|||
|
|
|||
|
// 15.4 utf-16le
|
|||
|
// 15.4.1 utf-16le decoder
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['UTF-16LE'] = function(options) {
|
|||
|
return new UTF16Encoder(false, options);
|
|||
|
};
|
|||
|
// 15.4.2 utf-16le encoder
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['UTF-16LE'] = function(options) {
|
|||
|
return new UTF16Decoder(false, options);
|
|||
|
};
|
|||
|
|
|||
|
// 15.5 x-user-defined
|
|||
|
|
|||
|
// 15.5.1 x-user-defined decoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Decoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function XUserDefinedDecoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream The stream of bytes being decoded.
|
|||
|
* @param {number} bite The next byte read from the stream.
|
|||
|
* @return {?(number|!Array.<number>)} The next code point(s)
|
|||
|
* decoded, or null if not enough data exists in the input
|
|||
|
* stream to decode a complete code point.
|
|||
|
*/
|
|||
|
this.handler = function(stream, bite) {
|
|||
|
// 1. If byte is end-of-stream, return finished.
|
|||
|
if (bite === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If byte is an ASCII byte, return a code point whose value
|
|||
|
// is byte.
|
|||
|
if (isASCIIByte(bite))
|
|||
|
return bite;
|
|||
|
|
|||
|
// 3. Return a code point whose value is 0xF780 + byte − 0x80.
|
|||
|
return 0xF780 + bite - 0x80;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// 15.5.2 x-user-defined encoder
|
|||
|
/**
|
|||
|
* @constructor
|
|||
|
* @implements {Encoder}
|
|||
|
* @param {{fatal: boolean}} options
|
|||
|
*/
|
|||
|
function XUserDefinedEncoder(options) {
|
|||
|
var fatal = options.fatal;
|
|||
|
/**
|
|||
|
* @param {Stream} stream Input stream.
|
|||
|
* @param {number} code_point Next code point read from the stream.
|
|||
|
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
|||
|
*/
|
|||
|
this.handler = function(stream, code_point) {
|
|||
|
// 1.If code point is end-of-stream, return finished.
|
|||
|
if (code_point === end_of_stream)
|
|||
|
return finished;
|
|||
|
|
|||
|
// 2. If code point is an ASCII code point, return a byte whose
|
|||
|
// value is code point.
|
|||
|
if (isASCIICodePoint(code_point))
|
|||
|
return code_point;
|
|||
|
|
|||
|
// 3. If code point is in the range U+F780 to U+F7FF, inclusive,
|
|||
|
// return a byte whose value is code point − 0xF780 + 0x80.
|
|||
|
if (inRange(code_point, 0xF780, 0xF7FF))
|
|||
|
return code_point - 0xF780 + 0x80;
|
|||
|
|
|||
|
// 4. Return error with code point.
|
|||
|
return encoderError(code_point);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
encoders['x-user-defined'] = function(options) {
|
|||
|
return new XUserDefinedEncoder(options);
|
|||
|
};
|
|||
|
/** @param {{fatal: boolean}} options */
|
|||
|
decoders['x-user-defined'] = function(options) {
|
|||
|
return new XUserDefinedDecoder(options);
|
|||
|
};
|
|||
|
|
|||
|
if (!global['TextEncoder'])
|
|||
|
global['TextEncoder'] = TextEncoder;
|
|||
|
if (!global['TextDecoder'])
|
|||
|
global['TextDecoder'] = TextDecoder;
|
|||
|
|
|||
|
if (typeof module !== "undefined" && module.exports) {
|
|||
|
module.exports = {
|
|||
|
TextEncoder: global['TextEncoder'],
|
|||
|
TextDecoder: global['TextDecoder'],
|
|||
|
EncodingIndexes: global["encoding-indexes"]
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// For strict environments where `this` inside the global scope
|
|||
|
// is `undefined`, take a pure object instead
|
|||
|
}(this || {}));
|
|||
|
},{"./encoding-indexes.js":86}],88:[function(require,module,exports){
|
|||
|
/*!
|
|||
|
|
|||
|
diff v4.0.1
|
|||
|
|
|||
|
Software License Agreement (BSD License)
|
|||
|
|
|||
|
Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
|
|||
|
|
|||
|
All rights reserved.
|
|||
|
|
|||
|
Redistribution and use of this software in source and binary forms, with or without modification,
|
|||
|
are permitted provided that the following conditions are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the
|
|||
|
following disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the
|
|||
|
following disclaimer in the documentation and/or other
|
|||
|
materials provided with the distribution.
|
|||
|
|
|||
|
* Neither the name of Kevin Decker nor the names of its
|
|||
|
contributors may be used to endorse or promote products
|
|||
|
derived from this software without specific prior
|
|||
|
written permission.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|||
|
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|||
|
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|||
|
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
@license
|
|||
|
*/
|
|||
|
(function (global, factory) {
|
|||
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|||
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|||
|
(global = global || self, factory(global.Diff = {}));
|
|||
|
}(this, function (exports) { 'use strict';
|
|||
|
|
|||
|
function Diff() {}
|
|||
|
Diff.prototype = {
|
|||
|
diff: function diff(oldString, newString) {
|
|||
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|||
|
var callback = options.callback;
|
|||
|
|
|||
|
if (typeof options === 'function') {
|
|||
|
callback = options;
|
|||
|
options = {};
|
|||
|
}
|
|||
|
|
|||
|
this.options = options;
|
|||
|
var self = this;
|
|||
|
|
|||
|
function done(value) {
|
|||
|
if (callback) {
|
|||
|
setTimeout(function () {
|
|||
|
callback(undefined, value);
|
|||
|
}, 0);
|
|||
|
return true;
|
|||
|
} else {
|
|||
|
return value;
|
|||
|
}
|
|||
|
} // Allow subclasses to massage the input prior to running
|
|||
|
|
|||
|
|
|||
|
oldString = this.castInput(oldString);
|
|||
|
newString = this.castInput(newString);
|
|||
|
oldString = this.removeEmpty(this.tokenize(oldString));
|
|||
|
newString = this.removeEmpty(this.tokenize(newString));
|
|||
|
var newLen = newString.length,
|
|||
|
oldLen = oldString.length;
|
|||
|
var editLength = 1;
|
|||
|
var maxEditLength = newLen + oldLen;
|
|||
|
var bestPath = [{
|
|||
|
newPos: -1,
|
|||
|
components: []
|
|||
|
}]; // Seed editLength = 0, i.e. the content starts with the same values
|
|||
|
|
|||
|
var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
|
|||
|
|
|||
|
if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
|
|||
|
// Identity per the equality and tokenizer
|
|||
|
return done([{
|
|||
|
value: this.join(newString),
|
|||
|
count: newString.length
|
|||
|
}]);
|
|||
|
} // Main worker method. checks all permutations of a given edit length for acceptance.
|
|||
|
|
|||
|
|
|||
|
function execEditLength() {
|
|||
|
for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
|
|||
|
var basePath = void 0;
|
|||
|
|
|||
|
var addPath = bestPath[diagonalPath - 1],
|
|||
|
removePath = bestPath[diagonalPath + 1],
|
|||
|
_oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
|
|||
|
|
|||
|
if (addPath) {
|
|||
|
// No one else is going to attempt to use this value, clear it
|
|||
|
bestPath[diagonalPath - 1] = undefined;
|
|||
|
}
|
|||
|
|
|||
|
var canAdd = addPath && addPath.newPos + 1 < newLen,
|
|||
|
canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
|
|||
|
|
|||
|
if (!canAdd && !canRemove) {
|
|||
|
// If this path is a terminal then prune
|
|||
|
bestPath[diagonalPath] = undefined;
|
|||
|
continue;
|
|||
|
} // Select the diagonal that we want to branch from. We select the prior
|
|||
|
// path whose position in the new string is the farthest from the origin
|
|||
|
// and does not pass the bounds of the diff graph
|
|||
|
|
|||
|
|
|||
|
if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
|
|||
|
basePath = clonePath(removePath);
|
|||
|
self.pushComponent(basePath.components, undefined, true);
|
|||
|
} else {
|
|||
|
basePath = addPath; // No need to clone, we've pulled it from the list
|
|||
|
|
|||
|
basePath.newPos++;
|
|||
|
self.pushComponent(basePath.components, true, undefined);
|
|||
|
}
|
|||
|
|
|||
|
_oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
|
|||
|
|
|||
|
if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
|
|||
|
return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
|
|||
|
} else {
|
|||
|
// Otherwise track this path as a potential candidate and continue.
|
|||
|
bestPath[diagonalPath] = basePath;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
editLength++;
|
|||
|
} // Performs the length of edit iteration. Is a bit fugly as this has to support the
|
|||
|
// sync and async mode which is never fun. Loops over execEditLength until a value
|
|||
|
// is produced.
|
|||
|
|
|||
|
|
|||
|
if (callback) {
|
|||
|
(function exec() {
|
|||
|
setTimeout(function () {
|
|||
|
// This should not happen, but we want to be safe.
|
|||
|
|
|||
|
/* istanbul ignore next */
|
|||
|
if (editLength > maxEditLength) {
|
|||
|
return callback();
|
|||
|
}
|
|||
|
|
|||
|
if (!execEditLength()) {
|
|||
|
exec();
|
|||
|
}
|
|||
|
}, 0);
|
|||
|
})();
|
|||
|
} else {
|
|||
|
while (editLength <= maxEditLength) {
|
|||
|
var ret = execEditLength();
|
|||
|
|
|||
|
if (ret) {
|
|||
|
return ret;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
pushComponent: function pushComponent(components, added, removed) {
|
|||
|
var last = components[components.length - 1];
|
|||
|
|
|||
|
if (last && last.added === added && last.removed === removed) {
|
|||
|
// We need to clone here as the component clone operation is just
|
|||
|
// as shallow array clone
|
|||
|
components[components.length - 1] = {
|
|||
|
count: last.count + 1,
|
|||
|
added: added,
|
|||
|
removed: removed
|
|||
|
};
|
|||
|
} else {
|
|||
|
components.push({
|
|||
|
count: 1,
|
|||
|
added: added,
|
|||
|
removed: removed
|
|||
|
});
|
|||
|
}
|
|||
|
},
|
|||
|
extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
|
|||
|
var newLen = newString.length,
|
|||
|
oldLen = oldString.length,
|
|||
|
newPos = basePath.newPos,
|
|||
|
oldPos = newPos - diagonalPath,
|
|||
|
commonCount = 0;
|
|||
|
|
|||
|
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
|
|||
|
newPos++;
|
|||
|
oldPos++;
|
|||
|
commonCount++;
|
|||
|
}
|
|||
|
|
|||
|
if (commonCount) {
|
|||
|
basePath.components.push({
|
|||
|
count: commonCount
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
basePath.newPos = newPos;
|
|||
|
return oldPos;
|
|||
|
},
|
|||
|
equals: function equals(left, right) {
|
|||
|
if (this.options.comparator) {
|
|||
|
return this.options.comparator(left, right);
|
|||
|
} else {
|
|||
|
return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|||
|
}
|
|||
|
},
|
|||
|
removeEmpty: function removeEmpty(array) {
|
|||
|
var ret = [];
|
|||
|
|
|||
|
for (var i = 0; i < array.length; i++) {
|
|||
|
if (array[i]) {
|
|||
|
ret.push(array[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return ret;
|
|||
|
},
|
|||
|
castInput: function castInput(value) {
|
|||
|
return value;
|
|||
|
},
|
|||
|
tokenize: function tokenize(value) {
|
|||
|
return value.split('');
|
|||
|
},
|
|||
|
join: function join(chars) {
|
|||
|
return chars.join('');
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
function buildValues(diff, components, newString, oldString, useLongestToken) {
|
|||
|
var componentPos = 0,
|
|||
|
componentLen = components.length,
|
|||
|
newPos = 0,
|
|||
|
oldPos = 0;
|
|||
|
|
|||
|
for (; componentPos < componentLen; componentPos++) {
|
|||
|
var component = components[componentPos];
|
|||
|
|
|||
|
if (!component.removed) {
|
|||
|
if (!component.added && useLongestToken) {
|
|||
|
var value = newString.slice(newPos, newPos + component.count);
|
|||
|
value = value.map(function (value, i) {
|
|||
|
var oldValue = oldString[oldPos + i];
|
|||
|
return oldValue.length > value.length ? oldValue : value;
|
|||
|
});
|
|||
|
component.value = diff.join(value);
|
|||
|
} else {
|
|||
|
component.value = diff.join(newString.slice(newPos, newPos + component.count));
|
|||
|
}
|
|||
|
|
|||
|
newPos += component.count; // Common case
|
|||
|
|
|||
|
if (!component.added) {
|
|||
|
oldPos += component.count;
|
|||
|
}
|
|||
|
} else {
|
|||
|
component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
|
|||
|
oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
|
|||
|
// The diffing algorithm is tied to add then remove output and this is the simplest
|
|||
|
// route to get the desired output with minimal overhead.
|
|||
|
|
|||
|
if (componentPos && components[componentPos - 1].added) {
|
|||
|
var tmp = components[componentPos - 1];
|
|||
|
components[componentPos - 1] = components[componentPos];
|
|||
|
components[componentPos] = tmp;
|
|||
|
}
|
|||
|
}
|
|||
|
} // Special case handle for when one terminal is ignored (i.e. whitespace).
|
|||
|
// For this case we merge the terminal into the prior string and drop the change.
|
|||
|
// This is only available for string mode.
|
|||
|
|
|||
|
|
|||
|
var lastComponent = components[componentLen - 1];
|
|||
|
|
|||
|
if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
|
|||
|
components[componentLen - 2].value += lastComponent.value;
|
|||
|
components.pop();
|
|||
|
}
|
|||
|
|
|||
|
return components;
|
|||
|
}
|
|||
|
|
|||
|
function clonePath(path) {
|
|||
|
return {
|
|||
|
newPos: path.newPos,
|
|||
|
components: path.components.slice(0)
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
var characterDiff = new Diff();
|
|||
|
function diffChars(oldStr, newStr, options) {
|
|||
|
return characterDiff.diff(oldStr, newStr, options);
|
|||
|
}
|
|||
|
|
|||
|
function generateOptions(options, defaults) {
|
|||
|
if (typeof options === 'function') {
|
|||
|
defaults.callback = options;
|
|||
|
} else if (options) {
|
|||
|
for (var name in options) {
|
|||
|
/* istanbul ignore else */
|
|||
|
if (options.hasOwnProperty(name)) {
|
|||
|
defaults[name] = options[name];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return defaults;
|
|||
|
}
|
|||
|
|
|||
|
//
|
|||
|
// Ranges and exceptions:
|
|||
|
// Latin-1 Supplement, 0080–00FF
|
|||
|
// - U+00D7 × Multiplication sign
|
|||
|
// - U+00F7 ÷ Division sign
|
|||
|
// Latin Extended-A, 0100–017F
|
|||
|
// Latin Extended-B, 0180–024F
|
|||
|
// IPA Extensions, 0250–02AF
|
|||
|
// Spacing Modifier Letters, 02B0–02FF
|
|||
|
// - U+02C7 ˇ ˇ Caron
|
|||
|
// - U+02D8 ˘ ˘ Breve
|
|||
|
// - U+02D9 ˙ ˙ Dot Above
|
|||
|
// - U+02DA ˚ ˚ Ring Above
|
|||
|
// - U+02DB ˛ ˛ Ogonek
|
|||
|
// - U+02DC ˜ ˜ Small Tilde
|
|||
|
// - U+02DD ˝ ˝ Double Acute Accent
|
|||
|
// Latin Extended Additional, 1E00–1EFF
|
|||
|
|
|||
|
var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
|
|||
|
var reWhitespace = /\S/;
|
|||
|
var wordDiff = new Diff();
|
|||
|
|
|||
|
wordDiff.equals = function (left, right) {
|
|||
|
if (this.options.ignoreCase) {
|
|||
|
left = left.toLowerCase();
|
|||
|
right = right.toLowerCase();
|
|||
|
}
|
|||
|
|
|||
|
return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
|
|||
|
};
|
|||
|
|
|||
|
wordDiff.tokenize = function (value) {
|
|||
|
var tokens = value.split(/(\s+|[()[\]{}'"]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
|
|||
|
|
|||
|
for (var i = 0; i < tokens.length - 1; i++) {
|
|||
|
// If we have an empty string in the next field and we have only word chars before and after, merge
|
|||
|
if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
|
|||
|
tokens[i] += tokens[i + 2];
|
|||
|
tokens.splice(i + 1, 2);
|
|||
|
i--;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return tokens;
|
|||
|
};
|
|||
|
|
|||
|
function diffWords(oldStr, newStr, options) {
|
|||
|
options = generateOptions(options, {
|
|||
|
ignoreWhitespace: true
|
|||
|
});
|
|||
|
return wordDiff.diff(oldStr, newStr, options);
|
|||
|
}
|
|||
|
function diffWordsWithSpace(oldStr, newStr, options) {
|
|||
|
return wordDiff.diff(oldStr, newStr, options);
|
|||
|
}
|
|||
|
|
|||
|
var lineDiff = new Diff();
|
|||
|
|
|||
|
lineDiff.tokenize = function (value) {
|
|||
|
var retLines = [],
|
|||
|
linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
|
|||
|
|
|||
|
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|||
|
linesAndNewlines.pop();
|
|||
|
} // Merge the content and line separators into single tokens
|
|||
|
|
|||
|
|
|||
|
for (var i = 0; i < linesAndNewlines.length; i++) {
|
|||
|
var line = linesAndNewlines[i];
|
|||
|
|
|||
|
if (i % 2 && !this.options.newlineIsToken) {
|
|||
|
retLines[retLines.length - 1] += line;
|
|||
|
} else {
|
|||
|
if (this.options.ignoreWhitespace) {
|
|||
|
line = line.trim();
|
|||
|
}
|
|||
|
|
|||
|
retLines.push(line);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return retLines;
|
|||
|
};
|
|||
|
|
|||
|
function diffLines(oldStr, newStr, callback) {
|
|||
|
return lineDiff.diff(oldStr, newStr, callback);
|
|||
|
}
|
|||
|
function diffTrimmedLines(oldStr, newStr, callback) {
|
|||
|
var options = generateOptions(callback, {
|
|||
|
ignoreWhitespace: true
|
|||
|
});
|
|||
|
return lineDiff.diff(oldStr, newStr, options);
|
|||
|
}
|
|||
|
|
|||
|
var sentenceDiff = new Diff();
|
|||
|
|
|||
|
sentenceDiff.tokenize = function (value) {
|
|||
|
return value.split(/(\S.+?[.!?])(?=\s+|$)/);
|
|||
|
};
|
|||
|
|
|||
|
function diffSentences(oldStr, newStr, callback) {
|
|||
|
return sentenceDiff.diff(oldStr, newStr, callback);
|
|||
|
}
|
|||
|
|
|||
|
var cssDiff = new Diff();
|
|||
|
|
|||
|
cssDiff.tokenize = function (value) {
|
|||
|
return value.split(/([{}:;,]|\s+)/);
|
|||
|
};
|
|||
|
|
|||
|
function diffCss(oldStr, newStr, callback) {
|
|||
|
return cssDiff.diff(oldStr, newStr, callback);
|
|||
|
}
|
|||
|
|
|||
|
function _typeof(obj) {
|
|||
|
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|||
|
_typeof = function (obj) {
|
|||
|
return typeof obj;
|
|||
|
};
|
|||
|
} else {
|
|||
|
_typeof = function (obj) {
|
|||
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return _typeof(obj);
|
|||
|
}
|
|||
|
|
|||
|
function _toConsumableArray(arr) {
|
|||
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
|||
|
}
|
|||
|
|
|||
|
function _arrayWithoutHoles(arr) {
|
|||
|
if (Array.isArray(arr)) {
|
|||
|
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|||
|
|
|||
|
return arr2;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function _iterableToArray(iter) {
|
|||
|
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
|||
|
}
|
|||
|
|
|||
|
function _nonIterableSpread() {
|
|||
|
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
|||
|
}
|
|||
|
|
|||
|
var objectPrototypeToString = Object.prototype.toString;
|
|||
|
var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
|
|||
|
// dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
|
|||
|
|
|||
|
jsonDiff.useLongestToken = true;
|
|||
|
jsonDiff.tokenize = lineDiff.tokenize;
|
|||
|
|
|||
|
jsonDiff.castInput = function (value) {
|
|||
|
var _this$options = this.options,
|
|||
|
undefinedReplacement = _this$options.undefinedReplacement,
|
|||
|
_this$options$stringi = _this$options.stringifyReplacer,
|
|||
|
stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
|
|||
|
return typeof v === 'undefined' ? undefinedReplacement : v;
|
|||
|
} : _this$options$stringi;
|
|||
|
return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
|
|||
|
};
|
|||
|
|
|||
|
jsonDiff.equals = function (left, right) {
|
|||
|
return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
|
|||
|
};
|
|||
|
|
|||
|
function diffJson(oldObj, newObj, options) {
|
|||
|
return jsonDiff.diff(oldObj, newObj, options);
|
|||
|
} // This function handles the presence of circular references by bailing out when encountering an
|
|||
|
// object that is already on the "stack" of items being processed. Accepts an optional replacer
|
|||
|
|
|||
|
function canonicalize(obj, stack, replacementStack, replacer, key) {
|
|||
|
stack = stack || [];
|
|||
|
replacementStack = replacementStack || [];
|
|||
|
|
|||
|
if (replacer) {
|
|||
|
obj = replacer(key, obj);
|
|||
|
}
|
|||
|
|
|||
|
var i;
|
|||
|
|
|||
|
for (i = 0; i < stack.length; i += 1) {
|
|||
|
if (stack[i] === obj) {
|
|||
|
return replacementStack[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var canonicalizedObj;
|
|||
|
|
|||
|
if ('[object Array]' === objectPrototypeToString.call(obj)) {
|
|||
|
stack.push(obj);
|
|||
|
canonicalizedObj = new Array(obj.length);
|
|||
|
replacementStack.push(canonicalizedObj);
|
|||
|
|
|||
|
for (i = 0; i < obj.length; i += 1) {
|
|||
|
canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
|
|||
|
}
|
|||
|
|
|||
|
stack.pop();
|
|||
|
replacementStack.pop();
|
|||
|
return canonicalizedObj;
|
|||
|
}
|
|||
|
|
|||
|
if (obj && obj.toJSON) {
|
|||
|
obj = obj.toJSON();
|
|||
|
}
|
|||
|
|
|||
|
if (_typeof(obj) === 'object' && obj !== null) {
|
|||
|
stack.push(obj);
|
|||
|
canonicalizedObj = {};
|
|||
|
replacementStack.push(canonicalizedObj);
|
|||
|
|
|||
|
var sortedKeys = [],
|
|||
|
_key;
|
|||
|
|
|||
|
for (_key in obj) {
|
|||
|
/* istanbul ignore else */
|
|||
|
if (obj.hasOwnProperty(_key)) {
|
|||
|
sortedKeys.push(_key);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
sortedKeys.sort();
|
|||
|
|
|||
|
for (i = 0; i < sortedKeys.length; i += 1) {
|
|||
|
_key = sortedKeys[i];
|
|||
|
canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
|
|||
|
}
|
|||
|
|
|||
|
stack.pop();
|
|||
|
replacementStack.pop();
|
|||
|
} else {
|
|||
|
canonicalizedObj = obj;
|
|||
|
}
|
|||
|
|
|||
|
return canonicalizedObj;
|
|||
|
}
|
|||
|
|
|||
|
var arrayDiff = new Diff();
|
|||
|
|
|||
|
arrayDiff.tokenize = function (value) {
|
|||
|
return value.slice();
|
|||
|
};
|
|||
|
|
|||
|
arrayDiff.join = arrayDiff.removeEmpty = function (value) {
|
|||
|
return value;
|
|||
|
};
|
|||
|
|
|||
|
function diffArrays(oldArr, newArr, callback) {
|
|||
|
return arrayDiff.diff(oldArr, newArr, callback);
|
|||
|
}
|
|||
|
|
|||
|
function parsePatch(uniDiff) {
|
|||
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|||
|
var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
|
|||
|
delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
|
|||
|
list = [],
|
|||
|
i = 0;
|
|||
|
|
|||
|
function parseIndex() {
|
|||
|
var index = {};
|
|||
|
list.push(index); // Parse diff metadata
|
|||
|
|
|||
|
while (i < diffstr.length) {
|
|||
|
var line = diffstr[i]; // File header found, end parsing diff metadata
|
|||
|
|
|||
|
if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
|
|||
|
break;
|
|||
|
} // Diff index
|
|||
|
|
|||
|
|
|||
|
var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
|||
|
|
|||
|
if (header) {
|
|||
|
index.index = header[1];
|
|||
|
}
|
|||
|
|
|||
|
i++;
|
|||
|
} // Parse file headers if they are defined. Unified diff requires them, but
|
|||
|
// there's no technical issues to have an isolated hunk without file header
|
|||
|
|
|||
|
|
|||
|
parseFileHeader(index);
|
|||
|
parseFileHeader(index); // Parse hunks
|
|||
|
|
|||
|
index.hunks = [];
|
|||
|
|
|||
|
while (i < diffstr.length) {
|
|||
|
var _line = diffstr[i];
|
|||
|
|
|||
|
if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
|
|||
|
break;
|
|||
|
} else if (/^@@/.test(_line)) {
|
|||
|
index.hunks.push(parseHunk());
|
|||
|
} else if (_line && options.strict) {
|
|||
|
// Ignore unexpected content unless in strict mode
|
|||
|
throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
|
|||
|
} else {
|
|||
|
i++;
|
|||
|
}
|
|||
|
}
|
|||
|
} // Parses the --- and +++ headers, if none are found, no lines
|
|||
|
// are consumed.
|
|||
|
|
|||
|
|
|||
|
function parseFileHeader(index) {
|
|||
|
var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
|
|||
|
|
|||
|
if (fileHeader) {
|
|||
|
var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
|
|||
|
var data = fileHeader[2].split('\t', 2);
|
|||
|
var fileName = data[0].replace(/\\\\/g, '\\');
|
|||
|
|
|||
|
if (/^".*"$/.test(fileName)) {
|
|||
|
fileName = fileName.substr(1, fileName.length - 2);
|
|||
|
}
|
|||
|
|
|||
|
index[keyPrefix + 'FileName'] = fileName;
|
|||
|
index[keyPrefix + 'Header'] = (data[1] || '').trim();
|
|||
|
i++;
|
|||
|
}
|
|||
|
} // Parses a hunk
|
|||
|
// This assumes that we are at the start of a hunk.
|
|||
|
|
|||
|
|
|||
|
function parseHunk() {
|
|||
|
var chunkHeaderIndex = i,
|
|||
|
chunkHeaderLine = diffstr[i++],
|
|||
|
chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|||
|
var hunk = {
|
|||
|
oldStart: +chunkHeader[1],
|
|||
|
oldLines: +chunkHeader[2] || 1,
|
|||
|
newStart: +chunkHeader[3],
|
|||
|
newLines: +chunkHeader[4] || 1,
|
|||
|
lines: [],
|
|||
|
linedelimiters: []
|
|||
|
};
|
|||
|
var addCount = 0,
|
|||
|
removeCount = 0;
|
|||
|
|
|||
|
for (; i < diffstr.length; i++) {
|
|||
|
// Lines starting with '---' could be mistaken for the "remove line" operation
|
|||
|
// But they could be the header for the next file. Therefore prune such cases out.
|
|||
|
if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
|
|||
|
|
|||
|
if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
|
|||
|
hunk.lines.push(diffstr[i]);
|
|||
|
hunk.linedelimiters.push(delimiters[i] || '\n');
|
|||
|
|
|||
|
if (operation === '+') {
|
|||
|
addCount++;
|
|||
|
} else if (operation === '-') {
|
|||
|
removeCount++;
|
|||
|
} else if (operation === ' ') {
|
|||
|
addCount++;
|
|||
|
removeCount++;
|
|||
|
}
|
|||
|
} else {
|
|||
|
break;
|
|||
|
}
|
|||
|
} // Handle the empty block count case
|
|||
|
|
|||
|
|
|||
|
if (!addCount && hunk.newLines === 1) {
|
|||
|
hunk.newLines = 0;
|
|||
|
}
|
|||
|
|
|||
|
if (!removeCount && hunk.oldLines === 1) {
|
|||
|
hunk.oldLines = 0;
|
|||
|
} // Perform optional sanity checking
|
|||
|
|
|||
|
|
|||
|
if (options.strict) {
|
|||
|
if (addCount !== hunk.newLines) {
|
|||
|
throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
|
|||
|
}
|
|||
|
|
|||
|
if (removeCount !== hunk.oldLines) {
|
|||
|
throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return hunk;
|
|||
|
}
|
|||
|
|
|||
|
while (i < diffstr.length) {
|
|||
|
parseIndex();
|
|||
|
}
|
|||
|
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
// Iterator that traverses in the range of [min, max], stepping
|
|||
|
// by distance from a given start position. I.e. for [0, 4], with
|
|||
|
// start of 2, this will iterate 2, 3, 1, 4, 0.
|
|||
|
function distanceIterator (start, minLine, maxLine) {
|
|||
|
var wantForward = true,
|
|||
|
backwardExhausted = false,
|
|||
|
forwardExhausted = false,
|
|||
|
localOffset = 1;
|
|||
|
return function iterator() {
|
|||
|
if (wantForward && !forwardExhausted) {
|
|||
|
if (backwardExhausted) {
|
|||
|
localOffset++;
|
|||
|
} else {
|
|||
|
wantForward = false;
|
|||
|
} // Check if trying to fit beyond text length, and if not, check it fits
|
|||
|
// after offset location (or desired location on first iteration)
|
|||
|
|
|||
|
|
|||
|
if (start + localOffset <= maxLine) {
|
|||
|
return localOffset;
|
|||
|
}
|
|||
|
|
|||
|
forwardExhausted = true;
|
|||
|
}
|
|||
|
|
|||
|
if (!backwardExhausted) {
|
|||
|
if (!forwardExhausted) {
|
|||
|
wantForward = true;
|
|||
|
} // Check if trying to fit before text beginning, and if not, check it fits
|
|||
|
// before offset location
|
|||
|
|
|||
|
|
|||
|
if (minLine <= start - localOffset) {
|
|||
|
return -localOffset++;
|
|||
|
}
|
|||
|
|
|||
|
backwardExhausted = true;
|
|||
|
return iterator();
|
|||
|
} // We tried to fit hunk before text beginning and beyond text length, then
|
|||
|
// hunk can't fit on the text. Return undefined
|
|||
|
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function applyPatch(source, uniDiff) {
|
|||
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|||
|
|
|||
|
if (typeof uniDiff === 'string') {
|
|||
|
uniDiff = parsePatch(uniDiff);
|
|||
|
}
|
|||
|
|
|||
|
if (Array.isArray(uniDiff)) {
|
|||
|
if (uniDiff.length > 1) {
|
|||
|
throw new Error('applyPatch only works with a single input.');
|
|||
|
}
|
|||
|
|
|||
|
uniDiff = uniDiff[0];
|
|||
|
} // Apply the diff to the input
|
|||
|
|
|||
|
|
|||
|
var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
|
|||
|
delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
|
|||
|
hunks = uniDiff.hunks,
|
|||
|
compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
|
|||
|
return line === patchContent;
|
|||
|
},
|
|||
|
errorCount = 0,
|
|||
|
fuzzFactor = options.fuzzFactor || 0,
|
|||
|
minLine = 0,
|
|||
|
offset = 0,
|
|||
|
removeEOFNL,
|
|||
|
addEOFNL;
|
|||
|
/**
|
|||
|
* Checks if the hunk exactly fits on the provided location
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
function hunkFits(hunk, toPos) {
|
|||
|
for (var j = 0; j < hunk.lines.length; j++) {
|
|||
|
var line = hunk.lines[j],
|
|||
|
operation = line.length > 0 ? line[0] : ' ',
|
|||
|
content = line.length > 0 ? line.substr(1) : line;
|
|||
|
|
|||
|
if (operation === ' ' || operation === '-') {
|
|||
|
// Context sanity check
|
|||
|
if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
|
|||
|
errorCount++;
|
|||
|
|
|||
|
if (errorCount > fuzzFactor) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
toPos++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
} // Search best fit offsets for each hunk based on the previous ones
|
|||
|
|
|||
|
|
|||
|
for (var i = 0; i < hunks.length; i++) {
|
|||
|
var hunk = hunks[i],
|
|||
|
maxLine = lines.length - hunk.oldLines,
|
|||
|
localOffset = 0,
|
|||
|
toPos = offset + hunk.oldStart - 1;
|
|||
|
var iterator = distanceIterator(toPos, minLine, maxLine);
|
|||
|
|
|||
|
for (; localOffset !== undefined; localOffset = iterator()) {
|
|||
|
if (hunkFits(hunk, toPos + localOffset)) {
|
|||
|
hunk.offset = offset += localOffset;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (localOffset === undefined) {
|
|||
|
return false;
|
|||
|
} // Set lower text limit to end of the current hunk, so next ones don't try
|
|||
|
// to fit over already patched text
|
|||
|
|
|||
|
|
|||
|
minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
|
|||
|
} // Apply patch hunks
|
|||
|
|
|||
|
|
|||
|
var diffOffset = 0;
|
|||
|
|
|||
|
for (var _i = 0; _i < hunks.length; _i++) {
|
|||
|
var _hunk = hunks[_i],
|
|||
|
_toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
|
|||
|
|
|||
|
diffOffset += _hunk.newLines - _hunk.oldLines;
|
|||
|
|
|||
|
if (_toPos < 0) {
|
|||
|
// Creating a new file
|
|||
|
_toPos = 0;
|
|||
|
}
|
|||
|
|
|||
|
for (var j = 0; j < _hunk.lines.length; j++) {
|
|||
|
var line = _hunk.lines[j],
|
|||
|
operation = line.length > 0 ? line[0] : ' ',
|
|||
|
content = line.length > 0 ? line.substr(1) : line,
|
|||
|
delimiter = _hunk.linedelimiters[j];
|
|||
|
|
|||
|
if (operation === ' ') {
|
|||
|
_toPos++;
|
|||
|
} else if (operation === '-') {
|
|||
|
lines.splice(_toPos, 1);
|
|||
|
delimiters.splice(_toPos, 1);
|
|||
|
/* istanbul ignore else */
|
|||
|
} else if (operation === '+') {
|
|||
|
lines.splice(_toPos, 0, content);
|
|||
|
delimiters.splice(_toPos, 0, delimiter);
|
|||
|
_toPos++;
|
|||
|
} else if (operation === '\\') {
|
|||
|
var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
|
|||
|
|
|||
|
if (previousOperation === '+') {
|
|||
|
removeEOFNL = true;
|
|||
|
} else if (previousOperation === '-') {
|
|||
|
addEOFNL = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
} // Handle EOFNL insertion/removal
|
|||
|
|
|||
|
|
|||
|
if (removeEOFNL) {
|
|||
|
while (!lines[lines.length - 1]) {
|
|||
|
lines.pop();
|
|||
|
delimiters.pop();
|
|||
|
}
|
|||
|
} else if (addEOFNL) {
|
|||
|
lines.push('');
|
|||
|
delimiters.push('\n');
|
|||
|
}
|
|||
|
|
|||
|
for (var _k = 0; _k < lines.length - 1; _k++) {
|
|||
|
lines[_k] = lines[_k] + delimiters[_k];
|
|||
|
}
|
|||
|
|
|||
|
return lines.join('');
|
|||
|
} // Wrapper that supports multiple file patches via callbacks.
|
|||
|
|
|||
|
function applyPatches(uniDiff, options) {
|
|||
|
if (typeof uniDiff === 'string') {
|
|||
|
uniDiff = parsePatch(uniDiff);
|
|||
|
}
|
|||
|
|
|||
|
var currentIndex = 0;
|
|||
|
|
|||
|
function processIndex() {
|
|||
|
var index = uniDiff[currentIndex++];
|
|||
|
|
|||
|
if (!index) {
|
|||
|
return options.complete();
|
|||
|
}
|
|||
|
|
|||
|
options.loadFile(index, function (err, data) {
|
|||
|
if (err) {
|
|||
|
return options.complete(err);
|
|||
|
}
|
|||
|
|
|||
|
var updatedContent = applyPatch(data, index, options);
|
|||
|
options.patched(index, updatedContent, function (err) {
|
|||
|
if (err) {
|
|||
|
return options.complete(err);
|
|||
|
}
|
|||
|
|
|||
|
processIndex();
|
|||
|
});
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
processIndex();
|
|||
|
}
|
|||
|
|
|||
|
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|||
|
if (!options) {
|
|||
|
options = {};
|
|||
|
}
|
|||
|
|
|||
|
if (typeof options.context === 'undefined') {
|
|||
|
options.context = 4;
|
|||
|
}
|
|||
|
|
|||
|
var diff = diffLines(oldStr, newStr, options);
|
|||
|
diff.push({
|
|||
|
value: '',
|
|||
|
lines: []
|
|||
|
}); // Append an empty value to make cleanup easier
|
|||
|
|
|||
|
function contextLines(lines) {
|
|||
|
return lines.map(function (entry) {
|
|||
|
return ' ' + entry;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
var hunks = [];
|
|||
|
var oldRangeStart = 0,
|
|||
|
newRangeStart = 0,
|
|||
|
curRange = [],
|
|||
|
oldLine = 1,
|
|||
|
newLine = 1;
|
|||
|
|
|||
|
var _loop = function _loop(i) {
|
|||
|
var current = diff[i],
|
|||
|
lines = current.lines || current.value.replace(/\n$/, '').split('\n');
|
|||
|
current.lines = lines;
|
|||
|
|
|||
|
if (current.added || current.removed) {
|
|||
|
var _curRange;
|
|||
|
|
|||
|
// If we have previous context, start with that
|
|||
|
if (!oldRangeStart) {
|
|||
|
var prev = diff[i - 1];
|
|||
|
oldRangeStart = oldLine;
|
|||
|
newRangeStart = newLine;
|
|||
|
|
|||
|
if (prev) {
|
|||
|
curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
|
|||
|
oldRangeStart -= curRange.length;
|
|||
|
newRangeStart -= curRange.length;
|
|||
|
}
|
|||
|
} // Output our changes
|
|||
|
|
|||
|
|
|||
|
(_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
|
|||
|
return (current.added ? '+' : '-') + entry;
|
|||
|
}))); // Track the updated file position
|
|||
|
|
|||
|
|
|||
|
if (current.added) {
|
|||
|
newLine += lines.length;
|
|||
|
} else {
|
|||
|
oldLine += lines.length;
|
|||
|
}
|
|||
|
} else {
|
|||
|
// Identical context lines. Track line changes
|
|||
|
if (oldRangeStart) {
|
|||
|
// Close out any changes that have been output (or join overlapping)
|
|||
|
if (lines.length <= options.context * 2 && i < diff.length - 2) {
|
|||
|
var _curRange2;
|
|||
|
|
|||
|
// Overlapping
|
|||
|
(_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
|
|||
|
} else {
|
|||
|
var _curRange3;
|
|||
|
|
|||
|
// end the range and output
|
|||
|
var contextSize = Math.min(lines.length, options.context);
|
|||
|
|
|||
|
(_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
|
|||
|
|
|||
|
var hunk = {
|
|||
|
oldStart: oldRangeStart,
|
|||
|
oldLines: oldLine - oldRangeStart + contextSize,
|
|||
|
newStart: newRangeStart,
|
|||
|
newLines: newLine - newRangeStart + contextSize,
|
|||
|
lines: curRange
|
|||
|
};
|
|||
|
|
|||
|
if (i >= diff.length - 2 && lines.length <= options.context) {
|
|||
|
// EOF is inside this hunk
|
|||
|
var oldEOFNewline = /\n$/.test(oldStr);
|
|||
|
var newEOFNewline = /\n$/.test(newStr);
|
|||
|
var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
|
|||
|
|
|||
|
if (!oldEOFNewline && noNlBeforeAdds) {
|
|||
|
// special case: old has no eol and no trailing context; no-nl can end up before adds
|
|||
|
curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
|
|||
|
}
|
|||
|
|
|||
|
if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
|
|||
|
curRange.push('\\ No newline at end of file');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
hunks.push(hunk);
|
|||
|
oldRangeStart = 0;
|
|||
|
newRangeStart = 0;
|
|||
|
curRange = [];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
oldLine += lines.length;
|
|||
|
newLine += lines.length;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
for (var i = 0; i < diff.length; i++) {
|
|||
|
_loop(i);
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
oldFileName: oldFileName,
|
|||
|
newFileName: newFileName,
|
|||
|
oldHeader: oldHeader,
|
|||
|
newHeader: newHeader,
|
|||
|
hunks: hunks
|
|||
|
};
|
|||
|
}
|
|||
|
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|||
|
var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|||
|
var ret = [];
|
|||
|
|
|||
|
if (oldFileName == newFileName) {
|
|||
|
ret.push('Index: ' + oldFileName);
|
|||
|
}
|
|||
|
|
|||
|
ret.push('===================================================================');
|
|||
|
ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
|
|||
|
ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
|
|||
|
|
|||
|
for (var i = 0; i < diff.hunks.length; i++) {
|
|||
|
var hunk = diff.hunks[i];
|
|||
|
ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
|
|||
|
ret.push.apply(ret, hunk.lines);
|
|||
|
}
|
|||
|
|
|||
|
return ret.join('\n') + '\n';
|
|||
|
}
|
|||
|
function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|||
|
return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
|
|||
|
}
|
|||
|
|
|||
|
function arrayEqual(a, b) {
|
|||
|
if (a.length !== b.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return arrayStartsWith(a, b);
|
|||
|
}
|
|||
|
function arrayStartsWith(array, start) {
|
|||
|
if (start.length > array.length) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
for (var i = 0; i < start.length; i++) {
|
|||
|
if (start[i] !== array[i]) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
function calcLineCount(hunk) {
|
|||
|
var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
|
|||
|
oldLines = _calcOldNewLineCount.oldLines,
|
|||
|
newLines = _calcOldNewLineCount.newLines;
|
|||
|
|
|||
|
if (oldLines !== undefined) {
|
|||
|
hunk.oldLines = oldLines;
|
|||
|
} else {
|
|||
|
delete hunk.oldLines;
|
|||
|
}
|
|||
|
|
|||
|
if (newLines !== undefined) {
|
|||
|
hunk.newLines = newLines;
|
|||
|
} else {
|
|||
|
delete hunk.newLines;
|
|||
|
}
|
|||
|
}
|
|||
|
function merge(mine, theirs, base) {
|
|||
|
mine = loadPatch(mine, base);
|
|||
|
theirs = loadPatch(theirs, base);
|
|||
|
var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
|
|||
|
// Leaving sanity checks on this to the API consumer that may know more about the
|
|||
|
// meaning in their own context.
|
|||
|
|
|||
|
if (mine.index || theirs.index) {
|
|||
|
ret.index = mine.index || theirs.index;
|
|||
|
}
|
|||
|
|
|||
|
if (mine.newFileName || theirs.newFileName) {
|
|||
|
if (!fileNameChanged(mine)) {
|
|||
|
// No header or no change in ours, use theirs (and ours if theirs does not exist)
|
|||
|
ret.oldFileName = theirs.oldFileName || mine.oldFileName;
|
|||
|
ret.newFileName = theirs.newFileName || mine.newFileName;
|
|||
|
ret.oldHeader = theirs.oldHeader || mine.oldHeader;
|
|||
|
ret.newHeader = theirs.newHeader || mine.newHeader;
|
|||
|
} else if (!fileNameChanged(theirs)) {
|
|||
|
// No header or no change in theirs, use ours
|
|||
|
ret.oldFileName = mine.oldFileName;
|
|||
|
ret.newFileName = mine.newFileName;
|
|||
|
ret.oldHeader = mine.oldHeader;
|
|||
|
ret.newHeader = mine.newHeader;
|
|||
|
} else {
|
|||
|
// Both changed... figure it out
|
|||
|
ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
|
|||
|
ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
|
|||
|
ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
|
|||
|
ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ret.hunks = [];
|
|||
|
var mineIndex = 0,
|
|||
|
theirsIndex = 0,
|
|||
|
mineOffset = 0,
|
|||
|
theirsOffset = 0;
|
|||
|
|
|||
|
while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
|
|||
|
var mineCurrent = mine.hunks[mineIndex] || {
|
|||
|
oldStart: Infinity
|
|||
|
},
|
|||
|
theirsCurrent = theirs.hunks[theirsIndex] || {
|
|||
|
oldStart: Infinity
|
|||
|
};
|
|||
|
|
|||
|
if (hunkBefore(mineCurrent, theirsCurrent)) {
|
|||
|
// This patch does not overlap with any of the others, yay.
|
|||
|
ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
|
|||
|
mineIndex++;
|
|||
|
theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
|
|||
|
} else if (hunkBefore(theirsCurrent, mineCurrent)) {
|
|||
|
// This patch does not overlap with any of the others, yay.
|
|||
|
ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
|
|||
|
theirsIndex++;
|
|||
|
mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
|
|||
|
} else {
|
|||
|
// Overlap, merge as best we can
|
|||
|
var mergedHunk = {
|
|||
|
oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
|
|||
|
oldLines: 0,
|
|||
|
newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
|
|||
|
newLines: 0,
|
|||
|
lines: []
|
|||
|
};
|
|||
|
mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
|
|||
|
theirsIndex++;
|
|||
|
mineIndex++;
|
|||
|
ret.hunks.push(mergedHunk);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
function loadPatch(param, base) {
|
|||
|
if (typeof param === 'string') {
|
|||
|
if (/^@@/m.test(param) || /^Index:/m.test(param)) {
|
|||
|
return parsePatch(param)[0];
|
|||
|
}
|
|||
|
|
|||
|
if (!base) {
|
|||
|
throw new Error('Must provide a base reference or pass in a patch');
|
|||
|
}
|
|||
|
|
|||
|
return structuredPatch(undefined, undefined, base, param);
|
|||
|
}
|
|||
|
|
|||
|
return param;
|
|||
|
}
|
|||
|
|
|||
|
function fileNameChanged(patch) {
|
|||
|
return patch.newFileName && patch.newFileName !== patch.oldFileName;
|
|||
|
}
|
|||
|
|
|||
|
function selectField(index, mine, theirs) {
|
|||
|
if (mine === theirs) {
|
|||
|
return mine;
|
|||
|
} else {
|
|||
|
index.conflict = true;
|
|||
|
return {
|
|||
|
mine: mine,
|
|||
|
theirs: theirs
|
|||
|
};
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function hunkBefore(test, check) {
|
|||
|
return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
|
|||
|
}
|
|||
|
|
|||
|
function cloneHunk(hunk, offset) {
|
|||
|
return {
|
|||
|
oldStart: hunk.oldStart,
|
|||
|
oldLines: hunk.oldLines,
|
|||
|
newStart: hunk.newStart + offset,
|
|||
|
newLines: hunk.newLines,
|
|||
|
lines: hunk.lines
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
|
|||
|
// This will generally result in a conflicted hunk, but there are cases where the context
|
|||
|
// is the only overlap where we can successfully merge the content here.
|
|||
|
var mine = {
|
|||
|
offset: mineOffset,
|
|||
|
lines: mineLines,
|
|||
|
index: 0
|
|||
|
},
|
|||
|
their = {
|
|||
|
offset: theirOffset,
|
|||
|
lines: theirLines,
|
|||
|
index: 0
|
|||
|
}; // Handle any leading content
|
|||
|
|
|||
|
insertLeading(hunk, mine, their);
|
|||
|
insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
|
|||
|
|
|||
|
while (mine.index < mine.lines.length && their.index < their.lines.length) {
|
|||
|
var mineCurrent = mine.lines[mine.index],
|
|||
|
theirCurrent = their.lines[their.index];
|
|||
|
|
|||
|
if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
|
|||
|
// Both modified ...
|
|||
|
mutualChange(hunk, mine, their);
|
|||
|
} else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
|
|||
|
var _hunk$lines;
|
|||
|
|
|||
|
// Mine inserted
|
|||
|
(_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
|
|||
|
} else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
|
|||
|
var _hunk$lines2;
|
|||
|
|
|||
|
// Theirs inserted
|
|||
|
(_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
|
|||
|
} else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
|
|||
|
// Mine removed or edited
|
|||
|
removal(hunk, mine, their);
|
|||
|
} else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
|
|||
|
// Their removed or edited
|
|||
|
removal(hunk, their, mine, true);
|
|||
|
} else if (mineCurrent === theirCurrent) {
|
|||
|
// Context identity
|
|||
|
hunk.lines.push(mineCurrent);
|
|||
|
mine.index++;
|
|||
|
their.index++;
|
|||
|
} else {
|
|||
|
// Context mismatch
|
|||
|
conflict(hunk, collectChange(mine), collectChange(their));
|
|||
|
}
|
|||
|
} // Now push anything that may be remaining
|
|||
|
|
|||
|
|
|||
|
insertTrailing(hunk, mine);
|
|||
|
insertTrailing(hunk, their);
|
|||
|
calcLineCount(hunk);
|
|||
|
}
|
|||
|
|
|||
|
function mutualChange(hunk, mine, their) {
|
|||
|
var myChanges = collectChange(mine),
|
|||
|
theirChanges = collectChange(their);
|
|||
|
|
|||
|
if (allRemoves(myChanges) && allRemoves(theirChanges)) {
|
|||
|
// Special case for remove changes that are supersets of one another
|
|||
|
if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
|
|||
|
var _hunk$lines3;
|
|||
|
|
|||
|
(_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
|
|||
|
|
|||
|
return;
|
|||
|
} else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
|
|||
|
var _hunk$lines4;
|
|||
|
|
|||
|
(_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
} else if (arrayEqual(myChanges, theirChanges)) {
|
|||
|
var _hunk$lines5;
|
|||
|
|
|||
|
(_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
conflict(hunk, myChanges, theirChanges);
|
|||
|
}
|
|||
|
|
|||
|
function removal(hunk, mine, their, swap) {
|
|||
|
var myChanges = collectChange(mine),
|
|||
|
theirChanges = collectContext(their, myChanges);
|
|||
|
|
|||
|
if (theirChanges.merged) {
|
|||
|
var _hunk$lines6;
|
|||
|
|
|||
|
(_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
|
|||
|
} else {
|
|||
|
conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function conflict(hunk, mine, their) {
|
|||
|
hunk.conflict = true;
|
|||
|
hunk.lines.push({
|
|||
|
conflict: true,
|
|||
|
mine: mine,
|
|||
|
theirs: their
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function insertLeading(hunk, insert, their) {
|
|||
|
while (insert.offset < their.offset && insert.index < insert.lines.length) {
|
|||
|
var line = insert.lines[insert.index++];
|
|||
|
hunk.lines.push(line);
|
|||
|
insert.offset++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function insertTrailing(hunk, insert) {
|
|||
|
while (insert.index < insert.lines.length) {
|
|||
|
var line = insert.lines[insert.index++];
|
|||
|
hunk.lines.push(line);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function collectChange(state) {
|
|||
|
var ret = [],
|
|||
|
operation = state.lines[state.index][0];
|
|||
|
|
|||
|
while (state.index < state.lines.length) {
|
|||
|
var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
|
|||
|
|
|||
|
if (operation === '-' && line[0] === '+') {
|
|||
|
operation = '+';
|
|||
|
}
|
|||
|
|
|||
|
if (operation === line[0]) {
|
|||
|
ret.push(line);
|
|||
|
state.index++;
|
|||
|
} else {
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
function collectContext(state, matchChanges) {
|
|||
|
var changes = [],
|
|||
|
merged = [],
|
|||
|
matchIndex = 0,
|
|||
|
contextChanges = false,
|
|||
|
conflicted = false;
|
|||
|
|
|||
|
while (matchIndex < matchChanges.length && state.index < state.lines.length) {
|
|||
|
var change = state.lines[state.index],
|
|||
|
match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
|
|||
|
|
|||
|
if (match[0] === '+') {
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
contextChanges = contextChanges || change[0] !== ' ';
|
|||
|
merged.push(match);
|
|||
|
matchIndex++; // Consume any additions in the other block as a conflict to attempt
|
|||
|
// to pull in the remaining context after this
|
|||
|
|
|||
|
if (change[0] === '+') {
|
|||
|
conflicted = true;
|
|||
|
|
|||
|
while (change[0] === '+') {
|
|||
|
changes.push(change);
|
|||
|
change = state.lines[++state.index];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (match.substr(1) === change.substr(1)) {
|
|||
|
changes.push(change);
|
|||
|
state.index++;
|
|||
|
} else {
|
|||
|
conflicted = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
|
|||
|
conflicted = true;
|
|||
|
}
|
|||
|
|
|||
|
if (conflicted) {
|
|||
|
return changes;
|
|||
|
}
|
|||
|
|
|||
|
while (matchIndex < matchChanges.length) {
|
|||
|
merged.push(matchChanges[matchIndex++]);
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
merged: merged,
|
|||
|
changes: changes
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function allRemoves(changes) {
|
|||
|
return changes.reduce(function (prev, change) {
|
|||
|
return prev && change[0] === '-';
|
|||
|
}, true);
|
|||
|
}
|
|||
|
|
|||
|
function skipRemoveSuperset(state, removeChanges, delta) {
|
|||
|
for (var i = 0; i < delta; i++) {
|
|||
|
var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
|
|||
|
|
|||
|
if (state.lines[state.index + i] !== ' ' + changeContent) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
state.index += delta;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
function calcOldNewLineCount(lines) {
|
|||
|
var oldLines = 0;
|
|||
|
var newLines = 0;
|
|||
|
lines.forEach(function (line) {
|
|||
|
if (typeof line !== 'string') {
|
|||
|
var myCount = calcOldNewLineCount(line.mine);
|
|||
|
var theirCount = calcOldNewLineCount(line.theirs);
|
|||
|
|
|||
|
if (oldLines !== undefined) {
|
|||
|
if (myCount.oldLines === theirCount.oldLines) {
|
|||
|
oldLines += myCount.oldLines;
|
|||
|
} else {
|
|||
|
oldLines = undefined;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (newLines !== undefined) {
|
|||
|
if (myCount.newLines === theirCount.newLines) {
|
|||
|
newLines += myCount.newLines;
|
|||
|
} else {
|
|||
|
newLines = undefined;
|
|||
|
}
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
|
|||
|
newLines++;
|
|||
|
}
|
|||
|
|
|||
|
if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
|
|||
|
oldLines++;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
return {
|
|||
|
oldLines: oldLines,
|
|||
|
newLines: newLines
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// See: http://code.google.com/p/google-diff-match-patch/wiki/API
|
|||
|
function convertChangesToDMP(changes) {
|
|||
|
var ret = [],
|
|||
|
change,
|
|||
|
operation;
|
|||
|
|
|||
|
for (var i = 0; i < changes.length; i++) {
|
|||
|
change = changes[i];
|
|||
|
|
|||
|
if (change.added) {
|
|||
|
operation = 1;
|
|||
|
} else if (change.removed) {
|
|||
|
operation = -1;
|
|||
|
} else {
|
|||
|
operation = 0;
|
|||
|
}
|
|||
|
|
|||
|
ret.push([operation, change.value]);
|
|||
|
}
|
|||
|
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
function convertChangesToXML(changes) {
|
|||
|
var ret = [];
|
|||
|
|
|||
|
for (var i = 0; i < changes.length; i++) {
|
|||
|
var change = changes[i];
|
|||
|
|
|||
|
if (change.added) {
|
|||
|
ret.push('<ins>');
|
|||
|
} else if (change.removed) {
|
|||
|
ret.push('<del>');
|
|||
|
}
|
|||
|
|
|||
|
ret.push(escapeHTML(change.value));
|
|||
|
|
|||
|
if (change.added) {
|
|||
|
ret.push('</ins>');
|
|||
|
} else if (change.removed) {
|
|||
|
ret.push('</del>');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return ret.join('');
|
|||
|
}
|
|||
|
|
|||
|
function escapeHTML(s) {
|
|||
|
var n = s;
|
|||
|
n = n.replace(/&/g, '&');
|
|||
|
n = n.replace(/</g, '<');
|
|||
|
n = n.replace(/>/g, '>');
|
|||
|
n = n.replace(/"/g, '"');
|
|||
|
return n;
|
|||
|
}
|
|||
|
|
|||
|
/* See LICENSE file for terms of use */
|
|||
|
|
|||
|
exports.Diff = Diff;
|
|||
|
exports.diffChars = diffChars;
|
|||
|
exports.diffWords = diffWords;
|
|||
|
exports.diffWordsWithSpace = diffWordsWithSpace;
|
|||
|
exports.diffLines = diffLines;
|
|||
|
exports.diffTrimmedLines = diffTrimmedLines;
|
|||
|
exports.diffSentences = diffSentences;
|
|||
|
exports.diffCss = diffCss;
|
|||
|
exports.diffJson = diffJson;
|
|||
|
exports.diffArrays = diffArrays;
|
|||
|
exports.structuredPatch = structuredPatch;
|
|||
|
exports.createTwoFilesPatch = createTwoFilesPatch;
|
|||
|
exports.createPatch = createPatch;
|
|||
|
exports.applyPatch = applyPatch;
|
|||
|
exports.applyPatches = applyPatches;
|
|||
|
exports.parsePatch = parsePatch;
|
|||
|
exports.merge = merge;
|
|||
|
exports.convertChangesToDMP = convertChangesToDMP;
|
|||
|
exports.convertChangesToXML = convertChangesToXML;
|
|||
|
exports.canonicalize = canonicalize;
|
|||
|
|
|||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|||
|
|
|||
|
}));
|
|||
|
|
|||
|
},{}],89:[function(require,module,exports){
|
|||
|
module.exports = Array.isArray || function (arr) {
|
|||
|
return Object.prototype.toString.call(arr) == '[object Array]';
|
|||
|
};
|
|||
|
|
|||
|
},{}],90:[function(require,module,exports){
|
|||
|
module.exports = extend;
|
|||
|
|
|||
|
/*
|
|||
|
var obj = {a: 3, b: 5};
|
|||
|
extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
|
|||
|
obj; // {a: 4, b: 5, c: 8}
|
|||
|
|
|||
|
var obj = {a: 3, b: 5};
|
|||
|
extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
|
|||
|
obj; // {a: 3, b: 5}
|
|||
|
|
|||
|
var arr = [1, 2, 3];
|
|||
|
var obj = {a: 3, b: 5};
|
|||
|
extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
|
|||
|
arr.push(4);
|
|||
|
obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}
|
|||
|
|
|||
|
var arr = [1, 2, 3];
|
|||
|
var obj = {a: 3, b: 5};
|
|||
|
extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
|
|||
|
arr.push(4);
|
|||
|
obj; // {a: 3, b: 5, c: [1, 2, 3]}
|
|||
|
|
|||
|
extend({a: 4, b: 5}); // {a: 4, b: 5}
|
|||
|
extend({a: 4, b: 5}, 3); {a: 4, b: 5}
|
|||
|
extend({a: 4, b: 5}, true); {a: 4, b: 5}
|
|||
|
extend('hello', {a: 4, b: 5}); // throws
|
|||
|
extend(3, {a: 4, b: 5}); // throws
|
|||
|
*/
|
|||
|
|
|||
|
function extend(/* [deep], obj1, obj2, [objn] */) {
|
|||
|
var args = [].slice.call(arguments);
|
|||
|
var deep = false;
|
|||
|
if (typeof args[0] == 'boolean') {
|
|||
|
deep = args.shift();
|
|||
|
}
|
|||
|
var result = args[0];
|
|||
|
if (isUnextendable(result)) {
|
|||
|
throw new Error('extendee must be an object');
|
|||
|
}
|
|||
|
var extenders = args.slice(1);
|
|||
|
var len = extenders.length;
|
|||
|
for (var i = 0; i < len; i++) {
|
|||
|
var extender = extenders[i];
|
|||
|
for (var key in extender) {
|
|||
|
if (extender.hasOwnProperty(key)) {
|
|||
|
var value = extender[key];
|
|||
|
if (deep && isCloneable(value)) {
|
|||
|
var base = Array.isArray(value) ? [] : {};
|
|||
|
result[key] = extend(
|
|||
|
true,
|
|||
|
result.hasOwnProperty(key) && !isUnextendable(result[key])
|
|||
|
? result[key]
|
|||
|
: base,
|
|||
|
value
|
|||
|
);
|
|||
|
} else {
|
|||
|
result[key] = value;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
function isCloneable(obj) {
|
|||
|
return Array.isArray(obj) || {}.toString.call(obj) == '[object Object]';
|
|||
|
}
|
|||
|
|
|||
|
function isUnextendable(val) {
|
|||
|
return !val || (typeof val != 'object' && typeof val != 'function');
|
|||
|
}
|
|||
|
|
|||
|
},{}],91:[function(require,module,exports){
|
|||
|
/**
|
|||
|
* lodash (Custom Build) <https://lodash.com/>
|
|||
|
* Build: `lodash modularize exports="npm" -o ./`
|
|||
|
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
|||
|
* Released under MIT license <https://lodash.com/license>
|
|||
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|||
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|||
|
*/
|
|||
|
|
|||
|
/** Used as the `TypeError` message for "Functions" methods. */
|
|||
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
|||
|
|
|||
|
/** Used to stand-in for `undefined` hash values. */
|
|||
|
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|||
|
|
|||
|
/** Used as references for various `Number` constants. */
|
|||
|
var INFINITY = 1 / 0;
|
|||
|
|
|||
|
/** `Object#toString` result references. */
|
|||
|
var funcTag = '[object Function]',
|
|||
|
genTag = '[object GeneratorFunction]',
|
|||
|
symbolTag = '[object Symbol]';
|
|||
|
|
|||
|
/** Used to match property names within property paths. */
|
|||
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
|||
|
reIsPlainProp = /^\w*$/,
|
|||
|
reLeadingDot = /^\./,
|
|||
|
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|||
|
|
|||
|
/**
|
|||
|
* Used to match `RegExp`
|
|||
|
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|||
|
*/
|
|||
|
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|||
|
|
|||
|
/** Used to match backslashes in property paths. */
|
|||
|
var reEscapeChar = /\\(\\)?/g;
|
|||
|
|
|||
|
/** Used to detect host constructors (Safari). */
|
|||
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|||
|
|
|||
|
/** Detect free variable `global` from Node.js. */
|
|||
|
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|||
|
|
|||
|
/** Detect free variable `self`. */
|
|||
|
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|||
|
|
|||
|
/** Used as a reference to the global object. */
|
|||
|
var root = freeGlobal || freeSelf || Function('return this')();
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the value at `key` of `object`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Object} [object] The object to query.
|
|||
|
* @param {string} key The key of the property to get.
|
|||
|
* @returns {*} Returns the property value.
|
|||
|
*/
|
|||
|
function getValue(object, key) {
|
|||
|
return object == null ? undefined : object[key];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is a host object in IE < 9.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
|||
|
*/
|
|||
|
function isHostObject(value) {
|
|||
|
// Many host objects are `Object` objects that can coerce to strings
|
|||
|
// despite having improperly defined `toString` methods.
|
|||
|
var result = false;
|
|||
|
if (value != null && typeof value.toString != 'function') {
|
|||
|
try {
|
|||
|
result = !!(value + '');
|
|||
|
} catch (e) {}
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
/** Used for built-in method references. */
|
|||
|
var arrayProto = Array.prototype,
|
|||
|
funcProto = Function.prototype,
|
|||
|
objectProto = Object.prototype;
|
|||
|
|
|||
|
/** Used to detect overreaching core-js shims. */
|
|||
|
var coreJsData = root['__core-js_shared__'];
|
|||
|
|
|||
|
/** Used to detect methods masquerading as native. */
|
|||
|
var maskSrcKey = (function() {
|
|||
|
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|||
|
return uid ? ('Symbol(src)_1.' + uid) : '';
|
|||
|
}());
|
|||
|
|
|||
|
/** Used to resolve the decompiled source of functions. */
|
|||
|
var funcToString = funcProto.toString;
|
|||
|
|
|||
|
/** Used to check objects for own properties. */
|
|||
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|||
|
|
|||
|
/**
|
|||
|
* Used to resolve the
|
|||
|
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|||
|
* of values.
|
|||
|
*/
|
|||
|
var objectToString = objectProto.toString;
|
|||
|
|
|||
|
/** Used to detect if a method is native. */
|
|||
|
var reIsNative = RegExp('^' +
|
|||
|
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
|||
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|||
|
);
|
|||
|
|
|||
|
/** Built-in value references. */
|
|||
|
var Symbol = root.Symbol,
|
|||
|
splice = arrayProto.splice;
|
|||
|
|
|||
|
/* Built-in method references that are verified to be native. */
|
|||
|
var Map = getNative(root, 'Map'),
|
|||
|
nativeCreate = getNative(Object, 'create');
|
|||
|
|
|||
|
/** Used to convert symbols to primitives and strings. */
|
|||
|
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
|||
|
symbolToString = symbolProto ? symbolProto.toString : undefined;
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a hash object.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @constructor
|
|||
|
* @param {Array} [entries] The key-value pairs to cache.
|
|||
|
*/
|
|||
|
function Hash(entries) {
|
|||
|
var index = -1,
|
|||
|
length = entries ? entries.length : 0;
|
|||
|
|
|||
|
this.clear();
|
|||
|
while (++index < length) {
|
|||
|
var entry = entries[index];
|
|||
|
this.set(entry[0], entry[1]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Removes all key-value entries from the hash.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name clear
|
|||
|
* @memberOf Hash
|
|||
|
*/
|
|||
|
function hashClear() {
|
|||
|
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Removes `key` and its value from the hash.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name delete
|
|||
|
* @memberOf Hash
|
|||
|
* @param {Object} hash The hash to modify.
|
|||
|
* @param {string} key The key of the value to remove.
|
|||
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|||
|
*/
|
|||
|
function hashDelete(key) {
|
|||
|
return this.has(key) && delete this.__data__[key];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the hash value for `key`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name get
|
|||
|
* @memberOf Hash
|
|||
|
* @param {string} key The key of the value to get.
|
|||
|
* @returns {*} Returns the entry value.
|
|||
|
*/
|
|||
|
function hashGet(key) {
|
|||
|
var data = this.__data__;
|
|||
|
if (nativeCreate) {
|
|||
|
var result = data[key];
|
|||
|
return result === HASH_UNDEFINED ? undefined : result;
|
|||
|
}
|
|||
|
return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if a hash value for `key` exists.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name has
|
|||
|
* @memberOf Hash
|
|||
|
* @param {string} key The key of the entry to check.
|
|||
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|||
|
*/
|
|||
|
function hashHas(key) {
|
|||
|
var data = this.__data__;
|
|||
|
return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sets the hash `key` to `value`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name set
|
|||
|
* @memberOf Hash
|
|||
|
* @param {string} key The key of the value to set.
|
|||
|
* @param {*} value The value to set.
|
|||
|
* @returns {Object} Returns the hash instance.
|
|||
|
*/
|
|||
|
function hashSet(key, value) {
|
|||
|
var data = this.__data__;
|
|||
|
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|||
|
return this;
|
|||
|
}
|
|||
|
|
|||
|
// Add methods to `Hash`.
|
|||
|
Hash.prototype.clear = hashClear;
|
|||
|
Hash.prototype['delete'] = hashDelete;
|
|||
|
Hash.prototype.get = hashGet;
|
|||
|
Hash.prototype.has = hashHas;
|
|||
|
Hash.prototype.set = hashSet;
|
|||
|
|
|||
|
/**
|
|||
|
* Creates an list cache object.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @constructor
|
|||
|
* @param {Array} [entries] The key-value pairs to cache.
|
|||
|
*/
|
|||
|
function ListCache(entries) {
|
|||
|
var index = -1,
|
|||
|
length = entries ? entries.length : 0;
|
|||
|
|
|||
|
this.clear();
|
|||
|
while (++index < length) {
|
|||
|
var entry = entries[index];
|
|||
|
this.set(entry[0], entry[1]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Removes all key-value entries from the list cache.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name clear
|
|||
|
* @memberOf ListCache
|
|||
|
*/
|
|||
|
function listCacheClear() {
|
|||
|
this.__data__ = [];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Removes `key` and its value from the list cache.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name delete
|
|||
|
* @memberOf ListCache
|
|||
|
* @param {string} key The key of the value to remove.
|
|||
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|||
|
*/
|
|||
|
function listCacheDelete(key) {
|
|||
|
var data = this.__data__,
|
|||
|
index = assocIndexOf(data, key);
|
|||
|
|
|||
|
if (index < 0) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
var lastIndex = data.length - 1;
|
|||
|
if (index == lastIndex) {
|
|||
|
data.pop();
|
|||
|
} else {
|
|||
|
splice.call(data, index, 1);
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the list cache value for `key`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name get
|
|||
|
* @memberOf ListCache
|
|||
|
* @param {string} key The key of the value to get.
|
|||
|
* @returns {*} Returns the entry value.
|
|||
|
*/
|
|||
|
function listCacheGet(key) {
|
|||
|
var data = this.__data__,
|
|||
|
index = assocIndexOf(data, key);
|
|||
|
|
|||
|
return index < 0 ? undefined : data[index][1];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if a list cache value for `key` exists.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name has
|
|||
|
* @memberOf ListCache
|
|||
|
* @param {string} key The key of the entry to check.
|
|||
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|||
|
*/
|
|||
|
function listCacheHas(key) {
|
|||
|
return assocIndexOf(this.__data__, key) > -1;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sets the list cache `key` to `value`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name set
|
|||
|
* @memberOf ListCache
|
|||
|
* @param {string} key The key of the value to set.
|
|||
|
* @param {*} value The value to set.
|
|||
|
* @returns {Object} Returns the list cache instance.
|
|||
|
*/
|
|||
|
function listCacheSet(key, value) {
|
|||
|
var data = this.__data__,
|
|||
|
index = assocIndexOf(data, key);
|
|||
|
|
|||
|
if (index < 0) {
|
|||
|
data.push([key, value]);
|
|||
|
} else {
|
|||
|
data[index][1] = value;
|
|||
|
}
|
|||
|
return this;
|
|||
|
}
|
|||
|
|
|||
|
// Add methods to `ListCache`.
|
|||
|
ListCache.prototype.clear = listCacheClear;
|
|||
|
ListCache.prototype['delete'] = listCacheDelete;
|
|||
|
ListCache.prototype.get = listCacheGet;
|
|||
|
ListCache.prototype.has = listCacheHas;
|
|||
|
ListCache.prototype.set = listCacheSet;
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a map cache object to store key-value pairs.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @constructor
|
|||
|
* @param {Array} [entries] The key-value pairs to cache.
|
|||
|
*/
|
|||
|
function MapCache(entries) {
|
|||
|
var index = -1,
|
|||
|
length = entries ? entries.length : 0;
|
|||
|
|
|||
|
this.clear();
|
|||
|
while (++index < length) {
|
|||
|
var entry = entries[index];
|
|||
|
this.set(entry[0], entry[1]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Removes all key-value entries from the map.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name clear
|
|||
|
* @memberOf MapCache
|
|||
|
*/
|
|||
|
function mapCacheClear() {
|
|||
|
this.__data__ = {
|
|||
|
'hash': new Hash,
|
|||
|
'map': new (Map || ListCache),
|
|||
|
'string': new Hash
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Removes `key` and its value from the map.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name delete
|
|||
|
* @memberOf MapCache
|
|||
|
* @param {string} key The key of the value to remove.
|
|||
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|||
|
*/
|
|||
|
function mapCacheDelete(key) {
|
|||
|
return getMapData(this, key)['delete'](key);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the map value for `key`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name get
|
|||
|
* @memberOf MapCache
|
|||
|
* @param {string} key The key of the value to get.
|
|||
|
* @returns {*} Returns the entry value.
|
|||
|
*/
|
|||
|
function mapCacheGet(key) {
|
|||
|
return getMapData(this, key).get(key);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if a map value for `key` exists.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name has
|
|||
|
* @memberOf MapCache
|
|||
|
* @param {string} key The key of the entry to check.
|
|||
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|||
|
*/
|
|||
|
function mapCacheHas(key) {
|
|||
|
return getMapData(this, key).has(key);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sets the map `key` to `value`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @name set
|
|||
|
* @memberOf MapCache
|
|||
|
* @param {string} key The key of the value to set.
|
|||
|
* @param {*} value The value to set.
|
|||
|
* @returns {Object} Returns the map cache instance.
|
|||
|
*/
|
|||
|
function mapCacheSet(key, value) {
|
|||
|
getMapData(this, key).set(key, value);
|
|||
|
return this;
|
|||
|
}
|
|||
|
|
|||
|
// Add methods to `MapCache`.
|
|||
|
MapCache.prototype.clear = mapCacheClear;
|
|||
|
MapCache.prototype['delete'] = mapCacheDelete;
|
|||
|
MapCache.prototype.get = mapCacheGet;
|
|||
|
MapCache.prototype.has = mapCacheHas;
|
|||
|
MapCache.prototype.set = mapCacheSet;
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Array} array The array to inspect.
|
|||
|
* @param {*} key The key to search for.
|
|||
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
|||
|
*/
|
|||
|
function assocIndexOf(array, key) {
|
|||
|
var length = array.length;
|
|||
|
while (length--) {
|
|||
|
if (eq(array[length][0], key)) {
|
|||
|
return length;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* The base implementation of `_.get` without support for default values.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Object} object The object to query.
|
|||
|
* @param {Array|string} path The path of the property to get.
|
|||
|
* @returns {*} Returns the resolved value.
|
|||
|
*/
|
|||
|
function baseGet(object, path) {
|
|||
|
path = isKey(path, object) ? [path] : castPath(path);
|
|||
|
|
|||
|
var index = 0,
|
|||
|
length = path.length;
|
|||
|
|
|||
|
while (object != null && index < length) {
|
|||
|
object = object[toKey(path[index++])];
|
|||
|
}
|
|||
|
return (index && index == length) ? object : undefined;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* The base implementation of `_.isNative` without bad shim checks.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is a native function,
|
|||
|
* else `false`.
|
|||
|
*/
|
|||
|
function baseIsNative(value) {
|
|||
|
if (!isObject(value) || isMasked(value)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
|||
|
return pattern.test(toSource(value));
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* The base implementation of `_.toString` which doesn't convert nullish
|
|||
|
* values to empty strings.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to process.
|
|||
|
* @returns {string} Returns the string.
|
|||
|
*/
|
|||
|
function baseToString(value) {
|
|||
|
// Exit early for strings to avoid a performance hit in some environments.
|
|||
|
if (typeof value == 'string') {
|
|||
|
return value;
|
|||
|
}
|
|||
|
if (isSymbol(value)) {
|
|||
|
return symbolToString ? symbolToString.call(value) : '';
|
|||
|
}
|
|||
|
var result = (value + '');
|
|||
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Casts `value` to a path array if it's not one.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to inspect.
|
|||
|
* @returns {Array} Returns the cast property path array.
|
|||
|
*/
|
|||
|
function castPath(value) {
|
|||
|
return isArray(value) ? value : stringToPath(value);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the data for `map`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Object} map The map to query.
|
|||
|
* @param {string} key The reference key.
|
|||
|
* @returns {*} Returns the map data.
|
|||
|
*/
|
|||
|
function getMapData(map, key) {
|
|||
|
var data = map.__data__;
|
|||
|
return isKeyable(key)
|
|||
|
? data[typeof key == 'string' ? 'string' : 'hash']
|
|||
|
: data.map;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the native function at `key` of `object`.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Object} object The object to query.
|
|||
|
* @param {string} key The key of the method to get.
|
|||
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
|||
|
*/
|
|||
|
function getNative(object, key) {
|
|||
|
var value = getValue(object, key);
|
|||
|
return baseIsNative(value) ? value : undefined;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is a property name and not a property path.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @param {Object} [object] The object to query keys on.
|
|||
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|||
|
*/
|
|||
|
function isKey(value, object) {
|
|||
|
if (isArray(value)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
var type = typeof value;
|
|||
|
if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
|||
|
value == null || isSymbol(value)) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
|||
|
(object != null && value in Object(object));
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is suitable for use as unique object key.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|||
|
*/
|
|||
|
function isKeyable(value) {
|
|||
|
var type = typeof value;
|
|||
|
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|||
|
? (value !== '__proto__')
|
|||
|
: (value === null);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `func` has its source masked.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Function} func The function to check.
|
|||
|
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|||
|
*/
|
|||
|
function isMasked(func) {
|
|||
|
return !!maskSrcKey && (maskSrcKey in func);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Converts `string` to a property path array.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {string} string The string to convert.
|
|||
|
* @returns {Array} Returns the property path array.
|
|||
|
*/
|
|||
|
var stringToPath = memoize(function(string) {
|
|||
|
string = toString(string);
|
|||
|
|
|||
|
var result = [];
|
|||
|
if (reLeadingDot.test(string)) {
|
|||
|
result.push('');
|
|||
|
}
|
|||
|
string.replace(rePropName, function(match, number, quote, string) {
|
|||
|
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
|||
|
});
|
|||
|
return result;
|
|||
|
});
|
|||
|
|
|||
|
/**
|
|||
|
* Converts `value` to a string key if it's not a string or symbol.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {*} value The value to inspect.
|
|||
|
* @returns {string|symbol} Returns the key.
|
|||
|
*/
|
|||
|
function toKey(value) {
|
|||
|
if (typeof value == 'string' || isSymbol(value)) {
|
|||
|
return value;
|
|||
|
}
|
|||
|
var result = (value + '');
|
|||
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Converts `func` to its source code.
|
|||
|
*
|
|||
|
* @private
|
|||
|
* @param {Function} func The function to process.
|
|||
|
* @returns {string} Returns the source code.
|
|||
|
*/
|
|||
|
function toSource(func) {
|
|||
|
if (func != null) {
|
|||
|
try {
|
|||
|
return funcToString.call(func);
|
|||
|
} catch (e) {}
|
|||
|
try {
|
|||
|
return (func + '');
|
|||
|
} catch (e) {}
|
|||
|
}
|
|||
|
return '';
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a function that memoizes the result of `func`. If `resolver` is
|
|||
|
* provided, it determines the cache key for storing the result based on the
|
|||
|
* arguments provided to the memoized function. By default, the first argument
|
|||
|
* provided to the memoized function is used as the map cache key. The `func`
|
|||
|
* is invoked with the `this` binding of the memoized function.
|
|||
|
*
|
|||
|
* **Note:** The cache is exposed as the `cache` property on the memoized
|
|||
|
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
|||
|
* constructor with one whose instances implement the
|
|||
|
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
|||
|
* method interface of `delete`, `get`, `has`, and `set`.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 0.1.0
|
|||
|
* @category Function
|
|||
|
* @param {Function} func The function to have its output memoized.
|
|||
|
* @param {Function} [resolver] The function to resolve the cache key.
|
|||
|
* @returns {Function} Returns the new memoized function.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* var object = { 'a': 1, 'b': 2 };
|
|||
|
* var other = { 'c': 3, 'd': 4 };
|
|||
|
*
|
|||
|
* var values = _.memoize(_.values);
|
|||
|
* values(object);
|
|||
|
* // => [1, 2]
|
|||
|
*
|
|||
|
* values(other);
|
|||
|
* // => [3, 4]
|
|||
|
*
|
|||
|
* object.a = 2;
|
|||
|
* values(object);
|
|||
|
* // => [1, 2]
|
|||
|
*
|
|||
|
* // Modify the result cache.
|
|||
|
* values.cache.set(object, ['a', 'b']);
|
|||
|
* values(object);
|
|||
|
* // => ['a', 'b']
|
|||
|
*
|
|||
|
* // Replace `_.memoize.Cache`.
|
|||
|
* _.memoize.Cache = WeakMap;
|
|||
|
*/
|
|||
|
function memoize(func, resolver) {
|
|||
|
if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
|
|||
|
throw new TypeError(FUNC_ERROR_TEXT);
|
|||
|
}
|
|||
|
var memoized = function() {
|
|||
|
var args = arguments,
|
|||
|
key = resolver ? resolver.apply(this, args) : args[0],
|
|||
|
cache = memoized.cache;
|
|||
|
|
|||
|
if (cache.has(key)) {
|
|||
|
return cache.get(key);
|
|||
|
}
|
|||
|
var result = func.apply(this, args);
|
|||
|
memoized.cache = cache.set(key, result);
|
|||
|
return result;
|
|||
|
};
|
|||
|
memoized.cache = new (memoize.Cache || MapCache);
|
|||
|
return memoized;
|
|||
|
}
|
|||
|
|
|||
|
// Assign cache to `_.memoize`.
|
|||
|
memoize.Cache = MapCache;
|
|||
|
|
|||
|
/**
|
|||
|
* Performs a
|
|||
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|||
|
* comparison between two values to determine if they are equivalent.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 4.0.0
|
|||
|
* @category Lang
|
|||
|
* @param {*} value The value to compare.
|
|||
|
* @param {*} other The other value to compare.
|
|||
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* var object = { 'a': 1 };
|
|||
|
* var other = { 'a': 1 };
|
|||
|
*
|
|||
|
* _.eq(object, object);
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.eq(object, other);
|
|||
|
* // => false
|
|||
|
*
|
|||
|
* _.eq('a', 'a');
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.eq('a', Object('a'));
|
|||
|
* // => false
|
|||
|
*
|
|||
|
* _.eq(NaN, NaN);
|
|||
|
* // => true
|
|||
|
*/
|
|||
|
function eq(value, other) {
|
|||
|
return value === other || (value !== value && other !== other);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is classified as an `Array` object.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 0.1.0
|
|||
|
* @category Lang
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* _.isArray([1, 2, 3]);
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.isArray(document.body.children);
|
|||
|
* // => false
|
|||
|
*
|
|||
|
* _.isArray('abc');
|
|||
|
* // => false
|
|||
|
*
|
|||
|
* _.isArray(_.noop);
|
|||
|
* // => false
|
|||
|
*/
|
|||
|
var isArray = Array.isArray;
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is classified as a `Function` object.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 0.1.0
|
|||
|
* @category Lang
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* _.isFunction(_);
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.isFunction(/abc/);
|
|||
|
* // => false
|
|||
|
*/
|
|||
|
function isFunction(value) {
|
|||
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|||
|
// in Safari 8-9 which returns 'object' for typed array and other constructors.
|
|||
|
var tag = isObject(value) ? objectToString.call(value) : '';
|
|||
|
return tag == funcTag || tag == genTag;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is the
|
|||
|
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|||
|
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 0.1.0
|
|||
|
* @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(_.noop);
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.isObject(null);
|
|||
|
* // => false
|
|||
|
*/
|
|||
|
function isObject(value) {
|
|||
|
var type = typeof value;
|
|||
|
return !!value && (type == 'object' || type == 'function');
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|||
|
* and has a `typeof` result of "object".
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 4.0.0
|
|||
|
* @category Lang
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* _.isObjectLike({});
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.isObjectLike([1, 2, 3]);
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.isObjectLike(_.noop);
|
|||
|
* // => false
|
|||
|
*
|
|||
|
* _.isObjectLike(null);
|
|||
|
* // => false
|
|||
|
*/
|
|||
|
function isObjectLike(value) {
|
|||
|
return !!value && typeof value == 'object';
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Checks if `value` is classified as a `Symbol` primitive or object.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 4.0.0
|
|||
|
* @category Lang
|
|||
|
* @param {*} value The value to check.
|
|||
|
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* _.isSymbol(Symbol.iterator);
|
|||
|
* // => true
|
|||
|
*
|
|||
|
* _.isSymbol('abc');
|
|||
|
* // => false
|
|||
|
*/
|
|||
|
function isSymbol(value) {
|
|||
|
return typeof value == 'symbol' ||
|
|||
|
(isObjectLike(value) && objectToString.call(value) == symbolTag);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Converts `value` to a string. An empty string is returned for `null`
|
|||
|
* and `undefined` values. The sign of `-0` is preserved.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 4.0.0
|
|||
|
* @category Lang
|
|||
|
* @param {*} value The value to process.
|
|||
|
* @returns {string} Returns the string.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* _.toString(null);
|
|||
|
* // => ''
|
|||
|
*
|
|||
|
* _.toString(-0);
|
|||
|
* // => '-0'
|
|||
|
*
|
|||
|
* _.toString([1, 2, 3]);
|
|||
|
* // => '1,2,3'
|
|||
|
*/
|
|||
|
function toString(value) {
|
|||
|
return value == null ? '' : baseToString(value);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets the value at `path` of `object`. If the resolved value is
|
|||
|
* `undefined`, the `defaultValue` is returned in its place.
|
|||
|
*
|
|||
|
* @static
|
|||
|
* @memberOf _
|
|||
|
* @since 3.7.0
|
|||
|
* @category Object
|
|||
|
* @param {Object} object The object to query.
|
|||
|
* @param {Array|string} path The path of the property to get.
|
|||
|
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
|||
|
* @returns {*} Returns the resolved value.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|||
|
*
|
|||
|
* _.get(object, 'a[0].b.c');
|
|||
|
* // => 3
|
|||
|
*
|
|||
|
* _.get(object, ['a', '0', 'b', 'c']);
|
|||
|
* // => 3
|
|||
|
*
|
|||
|
* _.get(object, 'a.b.c', 'default');
|
|||
|
* // => 'default'
|
|||
|
*/
|
|||
|
function get(object, path, defaultValue) {
|
|||
|
var result = object == null ? undefined : baseGet(object, path);
|
|||
|
return result === undefined ? defaultValue : result;
|
|||
|
}
|
|||
|
|
|||
|
module.exports = get;
|
|||
|
|
|||
|
},{}],92:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
// cache a reference to setTimeout, so that our reference won't be stubbed out
|
|||
|
// when using fake timers and errors will still get logged
|
|||
|
// https://github.com/cjohansen/Sinon.JS/issues/381
|
|||
|
var realSetTimeout = setTimeout;
|
|||
|
|
|||
|
function configureLogger(config) {
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
config = config || {};
|
|||
|
// Function which prints errors.
|
|||
|
if (!config.hasOwnProperty("logger")) {
|
|||
|
// eslint-disable-next-line no-empty-function
|
|||
|
config.logger = function() {};
|
|||
|
}
|
|||
|
// When set to true, any errors logged will be thrown immediately;
|
|||
|
// If set to false, the errors will be thrown in separate execution frame.
|
|||
|
if (!config.hasOwnProperty("useImmediateExceptions")) {
|
|||
|
config.useImmediateExceptions = true;
|
|||
|
}
|
|||
|
// wrap realSetTimeout with something we can stub in tests
|
|||
|
if (!config.hasOwnProperty("setTimeout")) {
|
|||
|
config.setTimeout = realSetTimeout;
|
|||
|
}
|
|||
|
|
|||
|
return function logError(label, e) {
|
|||
|
var msg = label + " threw exception: ";
|
|||
|
var err = {
|
|||
|
name: e.name || label,
|
|||
|
message: e.message || e.toString(),
|
|||
|
stack: e.stack
|
|||
|
};
|
|||
|
|
|||
|
function throwLoggedError() {
|
|||
|
err.message = msg + err.message;
|
|||
|
throw err;
|
|||
|
}
|
|||
|
|
|||
|
config.logger(msg + "[" + err.name + "] " + err.message);
|
|||
|
|
|||
|
if (err.stack) {
|
|||
|
config.logger(err.stack);
|
|||
|
}
|
|||
|
|
|||
|
if (config.useImmediateExceptions) {
|
|||
|
throwLoggedError();
|
|||
|
} else {
|
|||
|
config.setTimeout(throwLoggedError, 0);
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
module.exports = configureLogger;
|
|||
|
|
|||
|
},{}],93:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var Event = require("./event");
|
|||
|
|
|||
|
function CustomEvent(type, customData, target) {
|
|||
|
this.initEvent(type, false, false, target);
|
|||
|
this.detail = customData.detail || null;
|
|||
|
}
|
|||
|
|
|||
|
CustomEvent.prototype = new Event();
|
|||
|
|
|||
|
CustomEvent.prototype.constructor = CustomEvent;
|
|||
|
|
|||
|
module.exports = CustomEvent;
|
|||
|
|
|||
|
},{"./event":95}],94:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
function flattenOptions(options) {
|
|||
|
if (options !== Object(options)) {
|
|||
|
return {
|
|||
|
capture: Boolean(options),
|
|||
|
once: false,
|
|||
|
passive: false
|
|||
|
};
|
|||
|
}
|
|||
|
return {
|
|||
|
capture: Boolean(options.capture),
|
|||
|
once: Boolean(options.once),
|
|||
|
passive: Boolean(options.passive)
|
|||
|
};
|
|||
|
}
|
|||
|
function not(fn) {
|
|||
|
return function() {
|
|||
|
return !fn.apply(this, arguments);
|
|||
|
};
|
|||
|
}
|
|||
|
function hasListenerFilter(listener, capture) {
|
|||
|
return function(listenerSpec) {
|
|||
|
return (
|
|||
|
listenerSpec.capture === capture &&
|
|||
|
listenerSpec.listener === listener
|
|||
|
);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
var EventTarget = {
|
|||
|
// https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener
|
|||
|
addEventListener: function addEventListener(
|
|||
|
event,
|
|||
|
listener,
|
|||
|
providedOptions
|
|||
|
) {
|
|||
|
// 3. Let capture, passive, and once be the result of flattening more options.
|
|||
|
// Flatten property before executing step 2,
|
|||
|
// feture detection is usually based on registering handler with options object,
|
|||
|
// that has getter defined
|
|||
|
// addEventListener("load", () => {}, {
|
|||
|
// get once() { supportsOnce = true; }
|
|||
|
// });
|
|||
|
var options = flattenOptions(providedOptions);
|
|||
|
|
|||
|
// 2. If callback is null, then return.
|
|||
|
if (listener === null || listener === undefined) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
this.eventListeners = this.eventListeners || {};
|
|||
|
this.eventListeners[event] = this.eventListeners[event] || [];
|
|||
|
|
|||
|
// 4. If context object’s associated list of event listener
|
|||
|
// does not contain an event listener whose type is type,
|
|||
|
// callback is callback, and capture is capture, then append
|
|||
|
// a new event listener to it, whose type is type, callback is
|
|||
|
// callback, capture is capture, passive is passive, and once is once.
|
|||
|
if (
|
|||
|
!this.eventListeners[event].some(
|
|||
|
hasListenerFilter(listener, options.capture)
|
|||
|
)
|
|||
|
) {
|
|||
|
this.eventListeners[event].push({
|
|||
|
listener: listener,
|
|||
|
capture: options.capture,
|
|||
|
once: options.once
|
|||
|
});
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
// https://dom.spec.whatwg.org/#dom-eventtarget-removeeventlistener
|
|||
|
removeEventListener: function removeEventListener(
|
|||
|
event,
|
|||
|
listener,
|
|||
|
providedOptions
|
|||
|
) {
|
|||
|
if (!this.eventListeners || !this.eventListeners[event]) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// 2. Let capture be the result of flattening options.
|
|||
|
var options = flattenOptions(providedOptions);
|
|||
|
|
|||
|
// 3. If there is an event listener in the associated list of
|
|||
|
// event listeners whose type is type, callback is callback,
|
|||
|
// and capture is capture, then set that event listener’s
|
|||
|
// removed to true and remove it from the associated list of event listeners.
|
|||
|
this.eventListeners[event] = this.eventListeners[event].filter(
|
|||
|
not(hasListenerFilter(listener, options.capture))
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
dispatchEvent: function dispatchEvent(event) {
|
|||
|
if (!this.eventListeners || !this.eventListeners[event.type]) {
|
|||
|
return Boolean(event.defaultPrevented);
|
|||
|
}
|
|||
|
|
|||
|
var self = this;
|
|||
|
var type = event.type;
|
|||
|
var listeners = self.eventListeners[type];
|
|||
|
|
|||
|
// Remove listeners, that should be dispatched once
|
|||
|
// before running dispatch loop to avoid nested dispatch issues
|
|||
|
self.eventListeners[type] = listeners.filter(function(listenerSpec) {
|
|||
|
return !listenerSpec.once;
|
|||
|
});
|
|||
|
listeners.forEach(function(listenerSpec) {
|
|||
|
var listener = listenerSpec.listener;
|
|||
|
if (typeof listener === "function") {
|
|||
|
listener.call(self, event);
|
|||
|
} else {
|
|||
|
listener.handleEvent(event);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return Boolean(event.defaultPrevented);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
module.exports = EventTarget;
|
|||
|
|
|||
|
},{}],95:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
function Event(type, bubbles, cancelable, target) {
|
|||
|
this.initEvent(type, bubbles, cancelable, target);
|
|||
|
}
|
|||
|
|
|||
|
Event.prototype = {
|
|||
|
initEvent: function(type, bubbles, cancelable, target) {
|
|||
|
this.type = type;
|
|||
|
this.bubbles = bubbles;
|
|||
|
this.cancelable = cancelable;
|
|||
|
this.target = target;
|
|||
|
this.currentTarget = target;
|
|||
|
},
|
|||
|
|
|||
|
// eslint-disable-next-line no-empty-function
|
|||
|
stopPropagation: function() {},
|
|||
|
|
|||
|
preventDefault: function() {
|
|||
|
this.defaultPrevented = true;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
module.exports = Event;
|
|||
|
|
|||
|
},{}],96:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = {
|
|||
|
Event: require("./event"),
|
|||
|
ProgressEvent: require("./progress-event"),
|
|||
|
CustomEvent: require("./custom-event"),
|
|||
|
EventTarget: require("./event-target")
|
|||
|
};
|
|||
|
|
|||
|
},{"./custom-event":93,"./event":95,"./event-target":94,"./progress-event":97}],97:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var Event = require("./event");
|
|||
|
|
|||
|
function ProgressEvent(type, progressEventRaw, target) {
|
|||
|
this.initEvent(type, false, false, target);
|
|||
|
this.loaded =
|
|||
|
typeof progressEventRaw.loaded === "number"
|
|||
|
? progressEventRaw.loaded
|
|||
|
: null;
|
|||
|
this.total =
|
|||
|
typeof progressEventRaw.total === "number"
|
|||
|
? progressEventRaw.total
|
|||
|
: null;
|
|||
|
this.lengthComputable = Boolean(progressEventRaw.total);
|
|||
|
}
|
|||
|
|
|||
|
ProgressEvent.prototype = new Event();
|
|||
|
|
|||
|
ProgressEvent.prototype.constructor = ProgressEvent;
|
|||
|
|
|||
|
module.exports = ProgressEvent;
|
|||
|
|
|||
|
},{"./event":95}],98:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var FakeTimers = require("@sinonjs/fake-timers");
|
|||
|
var fakeServer = require("./index");
|
|||
|
|
|||
|
// eslint-disable-next-line no-empty-function
|
|||
|
function Server() {}
|
|||
|
Server.prototype = fakeServer;
|
|||
|
|
|||
|
var fakeServerWithClock = new Server();
|
|||
|
|
|||
|
fakeServerWithClock.addRequest = function addRequest(xhr) {
|
|||
|
if (xhr.async) {
|
|||
|
if (typeof setTimeout.clock === "object") {
|
|||
|
this.clock = setTimeout.clock;
|
|||
|
} else {
|
|||
|
this.clock = FakeTimers.install();
|
|||
|
this.resetClock = true;
|
|||
|
}
|
|||
|
|
|||
|
if (!this.longestTimeout) {
|
|||
|
var clockSetTimeout = this.clock.setTimeout;
|
|||
|
var clockSetInterval = this.clock.setInterval;
|
|||
|
var server = this;
|
|||
|
|
|||
|
this.clock.setTimeout = function(fn, timeout) {
|
|||
|
server.longestTimeout = Math.max(
|
|||
|
timeout,
|
|||
|
server.longestTimeout || 0
|
|||
|
);
|
|||
|
|
|||
|
return clockSetTimeout.apply(this, arguments);
|
|||
|
};
|
|||
|
|
|||
|
this.clock.setInterval = function(fn, timeout) {
|
|||
|
server.longestTimeout = Math.max(
|
|||
|
timeout,
|
|||
|
server.longestTimeout || 0
|
|||
|
);
|
|||
|
|
|||
|
return clockSetInterval.apply(this, arguments);
|
|||
|
};
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return fakeServer.addRequest.call(this, xhr);
|
|||
|
};
|
|||
|
|
|||
|
fakeServerWithClock.respond = function respond() {
|
|||
|
var returnVal = fakeServer.respond.apply(this, arguments);
|
|||
|
|
|||
|
if (this.clock) {
|
|||
|
this.clock.tick(this.longestTimeout || 0);
|
|||
|
this.longestTimeout = 0;
|
|||
|
|
|||
|
if (this.resetClock) {
|
|||
|
this.clock.uninstall();
|
|||
|
this.resetClock = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return returnVal;
|
|||
|
};
|
|||
|
|
|||
|
fakeServerWithClock.restore = function restore() {
|
|||
|
if (this.clock) {
|
|||
|
this.clock.uninstall();
|
|||
|
}
|
|||
|
|
|||
|
return fakeServer.restore.apply(this, arguments);
|
|||
|
};
|
|||
|
|
|||
|
module.exports = fakeServerWithClock;
|
|||
|
|
|||
|
},{"./index":99,"@sinonjs/fake-timers":57}],99:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var fakeXhr = require("../fake-xhr");
|
|||
|
var push = [].push;
|
|||
|
var log = require("./log");
|
|||
|
var configureLogError = require("../configure-logger");
|
|||
|
var pathToRegexp = require("path-to-regexp");
|
|||
|
|
|||
|
var supportsArrayBuffer = typeof ArrayBuffer !== "undefined";
|
|||
|
|
|||
|
function responseArray(handler) {
|
|||
|
var response = handler;
|
|||
|
|
|||
|
if (Object.prototype.toString.call(handler) !== "[object Array]") {
|
|||
|
response = [200, {}, handler];
|
|||
|
}
|
|||
|
|
|||
|
if (typeof response[2] !== "string") {
|
|||
|
if (!supportsArrayBuffer) {
|
|||
|
throw new TypeError(
|
|||
|
"Fake server response body should be a string, but was " +
|
|||
|
typeof response[2]
|
|||
|
);
|
|||
|
} else if (!(response[2] instanceof ArrayBuffer)) {
|
|||
|
throw new TypeError(
|
|||
|
"Fake server response body should be a string or ArrayBuffer, but was " +
|
|||
|
typeof response[2]
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return response;
|
|||
|
}
|
|||
|
|
|||
|
function getDefaultWindowLocation() {
|
|||
|
var winloc = {
|
|||
|
hostname: "localhost",
|
|||
|
port: process.env.PORT || 80,
|
|||
|
protocol: "http:"
|
|||
|
};
|
|||
|
winloc.host =
|
|||
|
winloc.hostname +
|
|||
|
(String(winloc.port) === "80" ? "" : ":" + winloc.port);
|
|||
|
return winloc;
|
|||
|
}
|
|||
|
|
|||
|
function getWindowLocation() {
|
|||
|
if (typeof window === "undefined") {
|
|||
|
// Fallback
|
|||
|
return getDefaultWindowLocation();
|
|||
|
}
|
|||
|
|
|||
|
if (typeof window.location !== "undefined") {
|
|||
|
// Browsers place location on window
|
|||
|
return window.location;
|
|||
|
}
|
|||
|
|
|||
|
if (
|
|||
|
typeof window.window !== "undefined" &&
|
|||
|
typeof window.window.location !== "undefined"
|
|||
|
) {
|
|||
|
// React Native on Android places location on window.window
|
|||
|
return window.window.location;
|
|||
|
}
|
|||
|
|
|||
|
return getDefaultWindowLocation();
|
|||
|
}
|
|||
|
|
|||
|
function matchOne(response, reqMethod, reqUrl) {
|
|||
|
var rmeth = response.method;
|
|||
|
var matchMethod = !rmeth || rmeth.toLowerCase() === reqMethod.toLowerCase();
|
|||
|
var url = response.url;
|
|||
|
var matchUrl =
|
|||
|
!url ||
|
|||
|
url === reqUrl ||
|
|||
|
(typeof url.test === "function" && url.test(reqUrl));
|
|||
|
|
|||
|
return matchMethod && matchUrl;
|
|||
|
}
|
|||
|
|
|||
|
function match(response, request) {
|
|||
|
var wloc = getWindowLocation();
|
|||
|
|
|||
|
var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host + "/");
|
|||
|
|
|||
|
var requestUrl = request.url;
|
|||
|
|
|||
|
if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) {
|
|||
|
requestUrl = requestUrl.replace(rCurrLoc, "/");
|
|||
|
}
|
|||
|
|
|||
|
if (matchOne(response, this.getHTTPMethod(request), requestUrl)) {
|
|||
|
if (typeof response.response === "function") {
|
|||
|
var ru = response.url;
|
|||
|
var args = [request].concat(
|
|||
|
ru && typeof ru.exec === "function"
|
|||
|
? ru.exec(requestUrl).slice(1)
|
|||
|
: []
|
|||
|
);
|
|||
|
return response.response.apply(response, args);
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
function incrementRequestCount() {
|
|||
|
var count = ++this.requestCount;
|
|||
|
|
|||
|
this.requested = true;
|
|||
|
|
|||
|
this.requestedOnce = count === 1;
|
|||
|
this.requestedTwice = count === 2;
|
|||
|
this.requestedThrice = count === 3;
|
|||
|
|
|||
|
this.firstRequest = this.getRequest(0);
|
|||
|
this.secondRequest = this.getRequest(1);
|
|||
|
this.thirdRequest = this.getRequest(2);
|
|||
|
|
|||
|
this.lastRequest = this.getRequest(count - 1);
|
|||
|
}
|
|||
|
|
|||
|
var fakeServer = {
|
|||
|
create: function(config) {
|
|||
|
var server = Object.create(this);
|
|||
|
server.configure(config);
|
|||
|
this.xhr = fakeXhr.useFakeXMLHttpRequest();
|
|||
|
server.requests = [];
|
|||
|
server.requestCount = 0;
|
|||
|
server.queue = [];
|
|||
|
server.responses = [];
|
|||
|
|
|||
|
this.xhr.onCreate = function(xhrObj) {
|
|||
|
xhrObj.unsafeHeadersEnabled = function() {
|
|||
|
return !(server.unsafeHeadersEnabled === false);
|
|||
|
};
|
|||
|
server.addRequest(xhrObj);
|
|||
|
};
|
|||
|
|
|||
|
return server;
|
|||
|
},
|
|||
|
|
|||
|
configure: function(config) {
|
|||
|
var self = this;
|
|||
|
var whitelist = {
|
|||
|
autoRespond: true,
|
|||
|
autoRespondAfter: true,
|
|||
|
respondImmediately: true,
|
|||
|
fakeHTTPMethods: true,
|
|||
|
logger: true,
|
|||
|
unsafeHeadersEnabled: true
|
|||
|
};
|
|||
|
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
config = config || {};
|
|||
|
|
|||
|
Object.keys(config).forEach(function(setting) {
|
|||
|
if (setting in whitelist) {
|
|||
|
self[setting] = config[setting];
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
self.logError = configureLogError(config);
|
|||
|
},
|
|||
|
|
|||
|
addRequest: function addRequest(xhrObj) {
|
|||
|
var server = this;
|
|||
|
push.call(this.requests, xhrObj);
|
|||
|
|
|||
|
incrementRequestCount.call(this);
|
|||
|
|
|||
|
xhrObj.onSend = function() {
|
|||
|
server.handleRequest(this);
|
|||
|
|
|||
|
if (server.respondImmediately) {
|
|||
|
server.respond();
|
|||
|
} else if (server.autoRespond && !server.responding) {
|
|||
|
setTimeout(function() {
|
|||
|
server.responding = false;
|
|||
|
server.respond();
|
|||
|
}, server.autoRespondAfter || 10);
|
|||
|
|
|||
|
server.responding = true;
|
|||
|
}
|
|||
|
};
|
|||
|
},
|
|||
|
|
|||
|
getHTTPMethod: function getHTTPMethod(request) {
|
|||
|
if (this.fakeHTTPMethods && /post/i.test(request.method)) {
|
|||
|
var matches = (request.requestBody || "").match(
|
|||
|
/_method=([^\b;]+)/
|
|||
|
);
|
|||
|
return matches ? matches[1] : request.method;
|
|||
|
}
|
|||
|
|
|||
|
return request.method;
|
|||
|
},
|
|||
|
|
|||
|
handleRequest: function handleRequest(xhr) {
|
|||
|
if (xhr.async) {
|
|||
|
push.call(this.queue, xhr);
|
|||
|
} else {
|
|||
|
this.processRequest(xhr);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
logger: function() {
|
|||
|
// no-op; override via configure()
|
|||
|
},
|
|||
|
|
|||
|
logError: configureLogError({}),
|
|||
|
|
|||
|
log: log,
|
|||
|
|
|||
|
respondWith: function respondWith(method, url, body) {
|
|||
|
if (arguments.length === 1 && typeof method !== "function") {
|
|||
|
this.response = responseArray(method);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (arguments.length === 1) {
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
body = method;
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
url = method = null;
|
|||
|
}
|
|||
|
|
|||
|
if (arguments.length === 2) {
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
body = url;
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
url = method;
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
method = null;
|
|||
|
}
|
|||
|
|
|||
|
// Escape port number to prevent "named" parameters in 'path-to-regexp' module
|
|||
|
if (typeof url === "string" && url !== "" && /:[0-9]+\//.test(url)) {
|
|||
|
var m = url.match(/^(https?:\/\/.*?):([0-9]+\/.*)$/);
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
url = m[1] + "\\:" + m[2];
|
|||
|
}
|
|||
|
|
|||
|
push.call(this.responses, {
|
|||
|
method: method,
|
|||
|
url:
|
|||
|
typeof url === "string" && url !== "" ? pathToRegexp(url) : url,
|
|||
|
response: typeof body === "function" ? body : responseArray(body)
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
respond: function respond() {
|
|||
|
if (arguments.length > 0) {
|
|||
|
this.respondWith.apply(this, arguments);
|
|||
|
}
|
|||
|
|
|||
|
var queue = this.queue || [];
|
|||
|
var requests = queue.splice(0, queue.length);
|
|||
|
var self = this;
|
|||
|
|
|||
|
requests.forEach(function(request) {
|
|||
|
self.processRequest(request);
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
respondAll: function respondAll() {
|
|||
|
if (this.respondImmediately) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
this.queue = this.requests.slice(0);
|
|||
|
|
|||
|
var request;
|
|||
|
while ((request = this.queue.shift())) {
|
|||
|
this.processRequest(request);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
processRequest: function processRequest(request) {
|
|||
|
try {
|
|||
|
if (request.aborted) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var response = this.response || [404, {}, ""];
|
|||
|
|
|||
|
if (this.responses) {
|
|||
|
for (var l = this.responses.length, i = l - 1; i >= 0; i--) {
|
|||
|
if (match.call(this, this.responses[i], request)) {
|
|||
|
response = this.responses[i].response;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (request.readyState !== 4) {
|
|||
|
this.log(response, request);
|
|||
|
|
|||
|
request.respond(response[0], response[1], response[2]);
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
this.logError("Fake server request processing", e);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
restore: function restore() {
|
|||
|
return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments);
|
|||
|
},
|
|||
|
|
|||
|
getRequest: function getRequest(index) {
|
|||
|
return this.requests[index] || null;
|
|||
|
},
|
|||
|
|
|||
|
reset: function reset() {
|
|||
|
this.resetBehavior();
|
|||
|
this.resetHistory();
|
|||
|
},
|
|||
|
|
|||
|
resetBehavior: function resetBehavior() {
|
|||
|
this.responses.length = this.queue.length = 0;
|
|||
|
},
|
|||
|
|
|||
|
resetHistory: function resetHistory() {
|
|||
|
this.requests.length = this.requestCount = 0;
|
|||
|
|
|||
|
this.requestedOnce = this.requestedTwice = this.requestedThrice = this.requested = false;
|
|||
|
|
|||
|
this.firstRequest = this.secondRequest = this.thirdRequest = this.lastRequest = null;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
module.exports = fakeServer;
|
|||
|
|
|||
|
},{"../configure-logger":92,"../fake-xhr":102,"./log":100,"path-to-regexp":104}],100:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
var inspect = require("util").inspect;
|
|||
|
|
|||
|
function log(response, request) {
|
|||
|
var str;
|
|||
|
|
|||
|
str = "Request:\n" + inspect(request) + "\n\n";
|
|||
|
str += "Response:\n" + inspect(response) + "\n\n";
|
|||
|
|
|||
|
/* istanbul ignore else: when this.logger is not a function, it can't be called */
|
|||
|
if (typeof this.logger === "function") {
|
|||
|
this.logger(str);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = log;
|
|||
|
|
|||
|
},{"util":109}],101:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.isSupported = (function() {
|
|||
|
try {
|
|||
|
return Boolean(new Blob());
|
|||
|
} catch (e) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
})();
|
|||
|
|
|||
|
},{}],102:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
var GlobalTextEncoder =
|
|||
|
typeof TextEncoder !== "undefined"
|
|||
|
? TextEncoder
|
|||
|
: require("@sinonjs/text-encoding").TextEncoder;
|
|||
|
var globalObject = require("@sinonjs/commons").global;
|
|||
|
var configureLogError = require("../configure-logger");
|
|||
|
var sinonEvent = require("../event");
|
|||
|
var extend = require("just-extend");
|
|||
|
|
|||
|
var supportsProgress = typeof ProgressEvent !== "undefined";
|
|||
|
var supportsCustomEvent = typeof CustomEvent !== "undefined";
|
|||
|
var supportsFormData = typeof FormData !== "undefined";
|
|||
|
var supportsArrayBuffer = typeof ArrayBuffer !== "undefined";
|
|||
|
var supportsBlob = require("./blob").isSupported;
|
|||
|
|
|||
|
function getWorkingXHR(globalScope) {
|
|||
|
var supportsXHR = typeof globalScope.XMLHttpRequest !== "undefined";
|
|||
|
if (supportsXHR) {
|
|||
|
return globalScope.XMLHttpRequest;
|
|||
|
}
|
|||
|
|
|||
|
var supportsActiveX = typeof globalScope.ActiveXObject !== "undefined";
|
|||
|
if (supportsActiveX) {
|
|||
|
return function() {
|
|||
|
return new globalScope.ActiveXObject("MSXML2.XMLHTTP.3.0");
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
// Ref: https://fetch.spec.whatwg.org/#forbidden-header-name
|
|||
|
var unsafeHeaders = {
|
|||
|
"Accept-Charset": true,
|
|||
|
"Access-Control-Request-Headers": true,
|
|||
|
"Access-Control-Request-Method": true,
|
|||
|
"Accept-Encoding": true,
|
|||
|
Connection: true,
|
|||
|
"Content-Length": true,
|
|||
|
Cookie: true,
|
|||
|
Cookie2: true,
|
|||
|
"Content-Transfer-Encoding": true,
|
|||
|
Date: true,
|
|||
|
DNT: true,
|
|||
|
Expect: true,
|
|||
|
Host: true,
|
|||
|
"Keep-Alive": true,
|
|||
|
Origin: true,
|
|||
|
Referer: true,
|
|||
|
TE: true,
|
|||
|
Trailer: true,
|
|||
|
"Transfer-Encoding": true,
|
|||
|
Upgrade: true,
|
|||
|
"User-Agent": true,
|
|||
|
Via: true
|
|||
|
};
|
|||
|
|
|||
|
function EventTargetHandler() {
|
|||
|
var self = this;
|
|||
|
var events = [
|
|||
|
"loadstart",
|
|||
|
"progress",
|
|||
|
"abort",
|
|||
|
"error",
|
|||
|
"load",
|
|||
|
"timeout",
|
|||
|
"loadend"
|
|||
|
];
|
|||
|
|
|||
|
function addEventListener(eventName) {
|
|||
|
self.addEventListener(eventName, function(event) {
|
|||
|
var listener = self["on" + eventName];
|
|||
|
|
|||
|
if (listener && typeof listener === "function") {
|
|||
|
listener.call(this, event);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
events.forEach(addEventListener);
|
|||
|
}
|
|||
|
|
|||
|
EventTargetHandler.prototype = sinonEvent.EventTarget;
|
|||
|
|
|||
|
function normalizeHeaderValue(value) {
|
|||
|
// Ref: https://fetch.spec.whatwg.org/#http-whitespace-bytes
|
|||
|
/*eslint no-control-regex: "off"*/
|
|||
|
return value.replace(/^[\x09\x0A\x0D\x20]+|[\x09\x0A\x0D\x20]+$/g, "");
|
|||
|
}
|
|||
|
|
|||
|
function getHeader(headers, header) {
|
|||
|
var foundHeader = Object.keys(headers).filter(function(h) {
|
|||
|
return h.toLowerCase() === header.toLowerCase();
|
|||
|
});
|
|||
|
|
|||
|
return foundHeader[0] || null;
|
|||
|
}
|
|||
|
|
|||
|
function excludeSetCookie2Header(header) {
|
|||
|
return !/^Set-Cookie2?$/i.test(header);
|
|||
|
}
|
|||
|
|
|||
|
function verifyResponseBodyType(body, responseType) {
|
|||
|
var error = null;
|
|||
|
var isString = typeof body === "string";
|
|||
|
|
|||
|
if (responseType === "arraybuffer") {
|
|||
|
if (!isString && !(body instanceof ArrayBuffer)) {
|
|||
|
error = new Error(
|
|||
|
"Attempted to respond to fake XMLHttpRequest with " +
|
|||
|
body +
|
|||
|
", which is not a string or ArrayBuffer."
|
|||
|
);
|
|||
|
error.name = "InvalidBodyException";
|
|||
|
}
|
|||
|
} else if (!isString) {
|
|||
|
error = new Error(
|
|||
|
"Attempted to respond to fake XMLHttpRequest with " +
|
|||
|
body +
|
|||
|
", which is not a string."
|
|||
|
);
|
|||
|
error.name = "InvalidBodyException";
|
|||
|
}
|
|||
|
|
|||
|
if (error) {
|
|||
|
throw error;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function convertToArrayBuffer(body, encoding) {
|
|||
|
if (body instanceof ArrayBuffer) {
|
|||
|
return body;
|
|||
|
}
|
|||
|
|
|||
|
return new GlobalTextEncoder(encoding || "utf-8").encode(body).buffer;
|
|||
|
}
|
|||
|
|
|||
|
function isXmlContentType(contentType) {
|
|||
|
return (
|
|||
|
!contentType ||
|
|||
|
/(text\/xml)|(application\/xml)|(\+xml)/.test(contentType)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
function clearResponse(xhr) {
|
|||
|
if (xhr.responseType === "" || xhr.responseType === "text") {
|
|||
|
xhr.response = xhr.responseText = "";
|
|||
|
} else {
|
|||
|
xhr.response = xhr.responseText = null;
|
|||
|
}
|
|||
|
xhr.responseXML = null;
|
|||
|
}
|
|||
|
|
|||
|
function fakeXMLHttpRequestFor(globalScope) {
|
|||
|
var isReactNative =
|
|||
|
globalScope.navigator &&
|
|||
|
globalScope.navigator.product === "ReactNative";
|
|||
|
var sinonXhr = { XMLHttpRequest: globalScope.XMLHttpRequest };
|
|||
|
sinonXhr.GlobalXMLHttpRequest = globalScope.XMLHttpRequest;
|
|||
|
sinonXhr.GlobalActiveXObject = globalScope.ActiveXObject;
|
|||
|
sinonXhr.supportsActiveX =
|
|||
|
typeof sinonXhr.GlobalActiveXObject !== "undefined";
|
|||
|
sinonXhr.supportsXHR = typeof sinonXhr.GlobalXMLHttpRequest !== "undefined";
|
|||
|
sinonXhr.workingXHR = getWorkingXHR(globalScope);
|
|||
|
sinonXhr.supportsTimeout =
|
|||
|
sinonXhr.supportsXHR &&
|
|||
|
"timeout" in new sinonXhr.GlobalXMLHttpRequest();
|
|||
|
sinonXhr.supportsCORS =
|
|||
|
isReactNative ||
|
|||
|
(sinonXhr.supportsXHR &&
|
|||
|
"withCredentials" in new sinonXhr.GlobalXMLHttpRequest());
|
|||
|
|
|||
|
// Note that for FakeXMLHttpRequest to work pre ES5
|
|||
|
// we lose some of the alignment with the spec.
|
|||
|
// To ensure as close a match as possible,
|
|||
|
// set responseType before calling open, send or respond;
|
|||
|
function FakeXMLHttpRequest(config) {
|
|||
|
EventTargetHandler.call(this);
|
|||
|
this.readyState = FakeXMLHttpRequest.UNSENT;
|
|||
|
this.requestHeaders = {};
|
|||
|
this.requestBody = null;
|
|||
|
this.status = 0;
|
|||
|
this.statusText = "";
|
|||
|
this.upload = new EventTargetHandler();
|
|||
|
this.responseType = "";
|
|||
|
this.response = "";
|
|||
|
this.logError = configureLogError(config);
|
|||
|
|
|||
|
if (sinonXhr.supportsTimeout) {
|
|||
|
this.timeout = 0;
|
|||
|
}
|
|||
|
|
|||
|
if (sinonXhr.supportsCORS) {
|
|||
|
this.withCredentials = false;
|
|||
|
}
|
|||
|
|
|||
|
if (typeof FakeXMLHttpRequest.onCreate === "function") {
|
|||
|
FakeXMLHttpRequest.onCreate(this);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function verifyState(xhr) {
|
|||
|
if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {
|
|||
|
throw new Error("INVALID_STATE_ERR");
|
|||
|
}
|
|||
|
|
|||
|
if (xhr.sendFlag) {
|
|||
|
throw new Error("INVALID_STATE_ERR");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// largest arity in XHR is 5 - XHR#open
|
|||
|
var apply = function(obj, method, args) {
|
|||
|
switch (args.length) {
|
|||
|
case 0:
|
|||
|
return obj[method]();
|
|||
|
case 1:
|
|||
|
return obj[method](args[0]);
|
|||
|
case 2:
|
|||
|
return obj[method](args[0], args[1]);
|
|||
|
case 3:
|
|||
|
return obj[method](args[0], args[1], args[2]);
|
|||
|
case 4:
|
|||
|
return obj[method](args[0], args[1], args[2], args[3]);
|
|||
|
case 5:
|
|||
|
return obj[method](args[0], args[1], args[2], args[3], args[4]);
|
|||
|
default:
|
|||
|
throw new Error("Unhandled case");
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
FakeXMLHttpRequest.filters = [];
|
|||
|
FakeXMLHttpRequest.addFilter = function addFilter(fn) {
|
|||
|
this.filters.push(fn);
|
|||
|
};
|
|||
|
FakeXMLHttpRequest.defake = function defake(fakeXhr, xhrArgs) {
|
|||
|
var xhr = new sinonXhr.workingXHR(); // eslint-disable-line new-cap
|
|||
|
|
|||
|
[
|
|||
|
"open",
|
|||
|
"setRequestHeader",
|
|||
|
"abort",
|
|||
|
"getResponseHeader",
|
|||
|
"getAllResponseHeaders",
|
|||
|
"addEventListener",
|
|||
|
"overrideMimeType",
|
|||
|
"removeEventListener"
|
|||
|
].forEach(function(method) {
|
|||
|
fakeXhr[method] = function() {
|
|||
|
return apply(xhr, method, arguments);
|
|||
|
};
|
|||
|
});
|
|||
|
|
|||
|
fakeXhr.send = function() {
|
|||
|
// Ref: https://xhr.spec.whatwg.org/#the-responsetype-attribute
|
|||
|
if (xhr.responseType !== fakeXhr.responseType) {
|
|||
|
xhr.responseType = fakeXhr.responseType;
|
|||
|
}
|
|||
|
return apply(xhr, "send", arguments);
|
|||
|
};
|
|||
|
|
|||
|
var copyAttrs = function(args) {
|
|||
|
args.forEach(function(attr) {
|
|||
|
fakeXhr[attr] = xhr[attr];
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
var stateChangeStart = function() {
|
|||
|
fakeXhr.readyState = xhr.readyState;
|
|||
|
if (xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) {
|
|||
|
copyAttrs(["status", "statusText"]);
|
|||
|
}
|
|||
|
if (xhr.readyState >= FakeXMLHttpRequest.LOADING) {
|
|||
|
copyAttrs(["response"]);
|
|||
|
if (xhr.responseType === "" || xhr.responseType === "text") {
|
|||
|
copyAttrs(["responseText"]);
|
|||
|
}
|
|||
|
}
|
|||
|
if (
|
|||
|
xhr.readyState === FakeXMLHttpRequest.DONE &&
|
|||
|
(xhr.responseType === "" || xhr.responseType === "document")
|
|||
|
) {
|
|||
|
copyAttrs(["responseXML"]);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var stateChangeEnd = function() {
|
|||
|
if (fakeXhr.onreadystatechange) {
|
|||
|
// eslint-disable-next-line no-useless-call
|
|||
|
fakeXhr.onreadystatechange.call(fakeXhr, {
|
|||
|
target: fakeXhr,
|
|||
|
currentTarget: fakeXhr
|
|||
|
});
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var stateChange = function stateChange() {
|
|||
|
stateChangeStart();
|
|||
|
stateChangeEnd();
|
|||
|
};
|
|||
|
|
|||
|
if (xhr.addEventListener) {
|
|||
|
xhr.addEventListener("readystatechange", stateChangeStart);
|
|||
|
|
|||
|
Object.keys(fakeXhr.eventListeners).forEach(function(event) {
|
|||
|
/*eslint-disable no-loop-func*/
|
|||
|
fakeXhr.eventListeners[event].forEach(function(handler) {
|
|||
|
xhr.addEventListener(event, handler.listener, {
|
|||
|
capture: handler.capture,
|
|||
|
once: handler.once
|
|||
|
});
|
|||
|
});
|
|||
|
/*eslint-enable no-loop-func*/
|
|||
|
});
|
|||
|
|
|||
|
xhr.addEventListener("readystatechange", stateChangeEnd);
|
|||
|
} else {
|
|||
|
xhr.onreadystatechange = stateChange;
|
|||
|
}
|
|||
|
apply(xhr, "open", xhrArgs);
|
|||
|
};
|
|||
|
FakeXMLHttpRequest.useFilters = false;
|
|||
|
|
|||
|
function verifyRequestOpened(xhr) {
|
|||
|
if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {
|
|||
|
throw new Error("INVALID_STATE_ERR - " + xhr.readyState);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function verifyRequestSent(xhr) {
|
|||
|
if (xhr.readyState === FakeXMLHttpRequest.DONE) {
|
|||
|
throw new Error("Request done");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function verifyHeadersReceived(xhr) {
|
|||
|
if (
|
|||
|
xhr.async &&
|
|||
|
xhr.readyState !== FakeXMLHttpRequest.HEADERS_RECEIVED
|
|||
|
) {
|
|||
|
throw new Error("No headers received");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function convertResponseBody(responseType, contentType, body) {
|
|||
|
if (responseType === "" || responseType === "text") {
|
|||
|
return body;
|
|||
|
} else if (supportsArrayBuffer && responseType === "arraybuffer") {
|
|||
|
return convertToArrayBuffer(body);
|
|||
|
} else if (responseType === "json") {
|
|||
|
try {
|
|||
|
return JSON.parse(body);
|
|||
|
} catch (e) {
|
|||
|
// Return parsing failure as null
|
|||
|
return null;
|
|||
|
}
|
|||
|
} else if (supportsBlob && responseType === "blob") {
|
|||
|
var blobOptions = {};
|
|||
|
if (contentType) {
|
|||
|
blobOptions.type = contentType;
|
|||
|
}
|
|||
|
return new Blob([convertToArrayBuffer(body)], blobOptions);
|
|||
|
} else if (responseType === "document") {
|
|||
|
if (isXmlContentType(contentType)) {
|
|||
|
return FakeXMLHttpRequest.parseXML(body);
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
throw new Error("Invalid responseType " + responseType);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Steps to follow when there is an error, according to:
|
|||
|
* https://xhr.spec.whatwg.org/#request-error-steps
|
|||
|
*/
|
|||
|
function requestErrorSteps(xhr) {
|
|||
|
clearResponse(xhr);
|
|||
|
xhr.errorFlag = true;
|
|||
|
xhr.requestHeaders = {};
|
|||
|
xhr.responseHeaders = {};
|
|||
|
|
|||
|
if (
|
|||
|
xhr.readyState !== FakeXMLHttpRequest.UNSENT &&
|
|||
|
xhr.sendFlag &&
|
|||
|
xhr.readyState !== FakeXMLHttpRequest.DONE
|
|||
|
) {
|
|||
|
xhr.readyStateChange(FakeXMLHttpRequest.DONE);
|
|||
|
xhr.sendFlag = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
FakeXMLHttpRequest.parseXML = function parseXML(text) {
|
|||
|
// Treat empty string as parsing failure
|
|||
|
if (text !== "") {
|
|||
|
try {
|
|||
|
if (typeof DOMParser !== "undefined") {
|
|||
|
var parser = new DOMParser();
|
|||
|
var parsererrorNS = "";
|
|||
|
|
|||
|
try {
|
|||
|
var parsererrors = parser
|
|||
|
.parseFromString("INVALID", "text/xml")
|
|||
|
.getElementsByTagName("parsererror");
|
|||
|
if (parsererrors.length) {
|
|||
|
parsererrorNS = parsererrors[0].namespaceURI;
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
// passing invalid XML makes IE11 throw
|
|||
|
// so no namespace needs to be determined
|
|||
|
}
|
|||
|
|
|||
|
var result;
|
|||
|
try {
|
|||
|
result = parser.parseFromString(text, "text/xml");
|
|||
|
} catch (err) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return result.getElementsByTagNameNS(
|
|||
|
parsererrorNS,
|
|||
|
"parsererror"
|
|||
|
).length
|
|||
|
? null
|
|||
|
: result;
|
|||
|
}
|
|||
|
var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
|
|||
|
xmlDoc.async = "false";
|
|||
|
xmlDoc.loadXML(text);
|
|||
|
return xmlDoc.parseError.errorCode !== 0 ? null : xmlDoc;
|
|||
|
} catch (e) {
|
|||
|
// Unable to parse XML - no biggie
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
};
|
|||
|
|
|||
|
FakeXMLHttpRequest.statusCodes = {
|
|||
|
100: "Continue",
|
|||
|
101: "Switching Protocols",
|
|||
|
200: "OK",
|
|||
|
201: "Created",
|
|||
|
202: "Accepted",
|
|||
|
203: "Non-Authoritative Information",
|
|||
|
204: "No Content",
|
|||
|
205: "Reset Content",
|
|||
|
206: "Partial Content",
|
|||
|
207: "Multi-Status",
|
|||
|
300: "Multiple Choice",
|
|||
|
301: "Moved Permanently",
|
|||
|
302: "Found",
|
|||
|
303: "See Other",
|
|||
|
304: "Not Modified",
|
|||
|
305: "Use Proxy",
|
|||
|
307: "Temporary Redirect",
|
|||
|
400: "Bad Request",
|
|||
|
401: "Unauthorized",
|
|||
|
402: "Payment Required",
|
|||
|
403: "Forbidden",
|
|||
|
404: "Not Found",
|
|||
|
405: "Method Not Allowed",
|
|||
|
406: "Not Acceptable",
|
|||
|
407: "Proxy Authentication Required",
|
|||
|
408: "Request Timeout",
|
|||
|
409: "Conflict",
|
|||
|
410: "Gone",
|
|||
|
411: "Length Required",
|
|||
|
412: "Precondition Failed",
|
|||
|
413: "Request Entity Too Large",
|
|||
|
414: "Request-URI Too Long",
|
|||
|
415: "Unsupported Media Type",
|
|||
|
416: "Requested Range Not Satisfiable",
|
|||
|
417: "Expectation Failed",
|
|||
|
422: "Unprocessable Entity",
|
|||
|
500: "Internal Server Error",
|
|||
|
501: "Not Implemented",
|
|||
|
502: "Bad Gateway",
|
|||
|
503: "Service Unavailable",
|
|||
|
504: "Gateway Timeout",
|
|||
|
505: "HTTP Version Not Supported"
|
|||
|
};
|
|||
|
|
|||
|
extend(FakeXMLHttpRequest.prototype, sinonEvent.EventTarget, {
|
|||
|
async: true,
|
|||
|
|
|||
|
open: function open(method, url, async, username, password) {
|
|||
|
this.method = method;
|
|||
|
this.url = url;
|
|||
|
this.async = typeof async === "boolean" ? async : true;
|
|||
|
this.username = username;
|
|||
|
this.password = password;
|
|||
|
clearResponse(this);
|
|||
|
this.requestHeaders = {};
|
|||
|
this.sendFlag = false;
|
|||
|
|
|||
|
if (FakeXMLHttpRequest.useFilters === true) {
|
|||
|
var xhrArgs = arguments;
|
|||
|
var defake = FakeXMLHttpRequest.filters.some(function(filter) {
|
|||
|
return filter.apply(this, xhrArgs);
|
|||
|
});
|
|||
|
if (defake) {
|
|||
|
FakeXMLHttpRequest.defake(this, arguments);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
this.readyStateChange(FakeXMLHttpRequest.OPENED);
|
|||
|
},
|
|||
|
|
|||
|
readyStateChange: function readyStateChange(state) {
|
|||
|
this.readyState = state;
|
|||
|
|
|||
|
var readyStateChangeEvent = new sinonEvent.Event(
|
|||
|
"readystatechange",
|
|||
|
false,
|
|||
|
false,
|
|||
|
this
|
|||
|
);
|
|||
|
var event, progress;
|
|||
|
|
|||
|
if (typeof this.onreadystatechange === "function") {
|
|||
|
try {
|
|||
|
this.onreadystatechange(readyStateChangeEvent);
|
|||
|
} catch (e) {
|
|||
|
this.logError("Fake XHR onreadystatechange handler", e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (this.readyState === FakeXMLHttpRequest.DONE) {
|
|||
|
if (this.timedOut || this.aborted || this.status === 0) {
|
|||
|
progress = { loaded: 0, total: 0 };
|
|||
|
event =
|
|||
|
(this.timedOut && "timeout") ||
|
|||
|
(this.aborted && "abort") ||
|
|||
|
"error";
|
|||
|
} else {
|
|||
|
progress = { loaded: 100, total: 100 };
|
|||
|
event = "load";
|
|||
|
}
|
|||
|
|
|||
|
if (supportsProgress) {
|
|||
|
this.upload.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent("progress", progress, this)
|
|||
|
);
|
|||
|
this.upload.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent(event, progress, this)
|
|||
|
);
|
|||
|
this.upload.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent("loadend", progress, this)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
this.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent("progress", progress, this)
|
|||
|
);
|
|||
|
this.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent(event, progress, this)
|
|||
|
);
|
|||
|
this.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent("loadend", progress, this)
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
this.dispatchEvent(readyStateChangeEvent);
|
|||
|
},
|
|||
|
|
|||
|
// Ref https://xhr.spec.whatwg.org/#the-setrequestheader()-method
|
|||
|
setRequestHeader: function setRequestHeader(header, value) {
|
|||
|
if (typeof value !== "string") {
|
|||
|
throw new TypeError(
|
|||
|
"By RFC7230, section 3.2.4, header values should be strings. Got " +
|
|||
|
typeof value
|
|||
|
);
|
|||
|
}
|
|||
|
verifyState(this);
|
|||
|
|
|||
|
var checkUnsafeHeaders = true;
|
|||
|
if (typeof this.unsafeHeadersEnabled === "function") {
|
|||
|
checkUnsafeHeaders = this.unsafeHeadersEnabled();
|
|||
|
}
|
|||
|
|
|||
|
if (
|
|||
|
checkUnsafeHeaders &&
|
|||
|
(getHeader(unsafeHeaders, header) !== null ||
|
|||
|
/^(Sec-|Proxy-)/i.test(header))
|
|||
|
) {
|
|||
|
throw new Error(
|
|||
|
// eslint-disable-next-line quotes
|
|||
|
'Refused to set unsafe header "' + header + '"'
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
value = normalizeHeaderValue(value);
|
|||
|
|
|||
|
var existingHeader = getHeader(this.requestHeaders, header);
|
|||
|
if (existingHeader) {
|
|||
|
this.requestHeaders[existingHeader] += ", " + value;
|
|||
|
} else {
|
|||
|
this.requestHeaders[header] = value;
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
setStatus: function setStatus(status) {
|
|||
|
var sanitizedStatus = typeof status === "number" ? status : 200;
|
|||
|
|
|||
|
verifyRequestOpened(this);
|
|||
|
this.status = sanitizedStatus;
|
|||
|
this.statusText = FakeXMLHttpRequest.statusCodes[sanitizedStatus];
|
|||
|
},
|
|||
|
|
|||
|
// Helps testing
|
|||
|
setResponseHeaders: function setResponseHeaders(headers) {
|
|||
|
verifyRequestOpened(this);
|
|||
|
|
|||
|
var responseHeaders = (this.responseHeaders = {});
|
|||
|
|
|||
|
Object.keys(headers).forEach(function(header) {
|
|||
|
responseHeaders[header] = headers[header];
|
|||
|
});
|
|||
|
|
|||
|
if (this.async) {
|
|||
|
this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED);
|
|||
|
} else {
|
|||
|
this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED;
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
// Currently treats ALL data as a DOMString (i.e. no Document)
|
|||
|
send: function send(data) {
|
|||
|
verifyState(this);
|
|||
|
|
|||
|
if (!/^(head)$/i.test(this.method)) {
|
|||
|
var contentType = getHeader(
|
|||
|
this.requestHeaders,
|
|||
|
"Content-Type"
|
|||
|
);
|
|||
|
if (this.requestHeaders[contentType]) {
|
|||
|
var value = this.requestHeaders[contentType].split(";");
|
|||
|
this.requestHeaders[contentType] =
|
|||
|
value[0] + ";charset=utf-8";
|
|||
|
} else if (supportsFormData && !(data instanceof FormData)) {
|
|||
|
this.requestHeaders["Content-Type"] =
|
|||
|
"text/plain;charset=utf-8";
|
|||
|
}
|
|||
|
|
|||
|
this.requestBody = data;
|
|||
|
}
|
|||
|
|
|||
|
this.errorFlag = false;
|
|||
|
this.sendFlag = this.async;
|
|||
|
clearResponse(this);
|
|||
|
|
|||
|
if (typeof this.onSend === "function") {
|
|||
|
this.onSend(this);
|
|||
|
}
|
|||
|
|
|||
|
// Only listen if setInterval and Date are a stubbed.
|
|||
|
if (
|
|||
|
sinonXhr.supportsTimeout &&
|
|||
|
typeof setInterval.clock === "object" &&
|
|||
|
typeof Date.clock === "object"
|
|||
|
) {
|
|||
|
var initiatedTime = Date.now();
|
|||
|
var self = this;
|
|||
|
|
|||
|
// Listen to any possible tick by fake timers and check to see if timeout has
|
|||
|
// been exceeded. It's important to note that timeout can be changed while a request
|
|||
|
// is in flight, so we must check anytime the end user forces a clock tick to make
|
|||
|
// sure timeout hasn't changed.
|
|||
|
// https://xhr.spec.whatwg.org/#dfnReturnLink-2
|
|||
|
var clearIntervalId = setInterval(function() {
|
|||
|
// Check if the readyState has been reset or is done. If this is the case, there
|
|||
|
// should be no timeout. This will also prevent aborted requests and
|
|||
|
// fakeServerWithClock from triggering unnecessary responses.
|
|||
|
if (
|
|||
|
self.readyState === FakeXMLHttpRequest.UNSENT ||
|
|||
|
self.readyState === FakeXMLHttpRequest.DONE
|
|||
|
) {
|
|||
|
clearInterval(clearIntervalId);
|
|||
|
} else if (
|
|||
|
typeof self.timeout === "number" &&
|
|||
|
self.timeout > 0
|
|||
|
) {
|
|||
|
if (Date.now() >= initiatedTime + self.timeout) {
|
|||
|
self.triggerTimeout();
|
|||
|
clearInterval(clearIntervalId);
|
|||
|
}
|
|||
|
}
|
|||
|
}, 1);
|
|||
|
}
|
|||
|
|
|||
|
this.dispatchEvent(
|
|||
|
new sinonEvent.Event("loadstart", false, false, this)
|
|||
|
);
|
|||
|
},
|
|||
|
|
|||
|
abort: function abort() {
|
|||
|
this.aborted = true;
|
|||
|
requestErrorSteps(this);
|
|||
|
this.readyState = FakeXMLHttpRequest.UNSENT;
|
|||
|
},
|
|||
|
|
|||
|
error: function() {
|
|||
|
clearResponse(this);
|
|||
|
this.errorFlag = true;
|
|||
|
this.requestHeaders = {};
|
|||
|
this.responseHeaders = {};
|
|||
|
|
|||
|
this.readyStateChange(FakeXMLHttpRequest.DONE);
|
|||
|
},
|
|||
|
|
|||
|
triggerTimeout: function triggerTimeout() {
|
|||
|
if (sinonXhr.supportsTimeout) {
|
|||
|
this.timedOut = true;
|
|||
|
requestErrorSteps(this);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
getResponseHeader: function getResponseHeader(header) {
|
|||
|
if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
if (/^Set-Cookie2?$/i.test(header)) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// eslint-disable-next-line no-param-reassign
|
|||
|
header = getHeader(this.responseHeaders, header);
|
|||
|
|
|||
|
return this.responseHeaders[header] || null;
|
|||
|
},
|
|||
|
|
|||
|
getAllResponseHeaders: function getAllResponseHeaders() {
|
|||
|
if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
|
|||
|
return "";
|
|||
|
}
|
|||
|
|
|||
|
var responseHeaders = this.responseHeaders;
|
|||
|
var headers = Object.keys(responseHeaders)
|
|||
|
.filter(excludeSetCookie2Header)
|
|||
|
.reduce(function(prev, header) {
|
|||
|
var value = responseHeaders[header];
|
|||
|
|
|||
|
return prev + (header + ": " + value + "\r\n");
|
|||
|
}, "");
|
|||
|
|
|||
|
return headers;
|
|||
|
},
|
|||
|
|
|||
|
setResponseBody: function setResponseBody(body) {
|
|||
|
verifyRequestSent(this);
|
|||
|
verifyHeadersReceived(this);
|
|||
|
verifyResponseBodyType(body, this.responseType);
|
|||
|
var contentType =
|
|||
|
this.overriddenMimeType ||
|
|||
|
this.getResponseHeader("Content-Type");
|
|||
|
|
|||
|
var isTextResponse =
|
|||
|
this.responseType === "" || this.responseType === "text";
|
|||
|
clearResponse(this);
|
|||
|
if (this.async) {
|
|||
|
var chunkSize = this.chunkSize || 10;
|
|||
|
var index = 0;
|
|||
|
|
|||
|
do {
|
|||
|
this.readyStateChange(FakeXMLHttpRequest.LOADING);
|
|||
|
|
|||
|
if (isTextResponse) {
|
|||
|
this.responseText = this.response += body.substring(
|
|||
|
index,
|
|||
|
index + chunkSize
|
|||
|
);
|
|||
|
}
|
|||
|
index += chunkSize;
|
|||
|
} while (index < body.length);
|
|||
|
}
|
|||
|
|
|||
|
this.response = convertResponseBody(
|
|||
|
this.responseType,
|
|||
|
contentType,
|
|||
|
body
|
|||
|
);
|
|||
|
if (isTextResponse) {
|
|||
|
this.responseText = this.response;
|
|||
|
}
|
|||
|
|
|||
|
if (this.responseType === "document") {
|
|||
|
this.responseXML = this.response;
|
|||
|
} else if (
|
|||
|
this.responseType === "" &&
|
|||
|
isXmlContentType(contentType)
|
|||
|
) {
|
|||
|
this.responseXML = FakeXMLHttpRequest.parseXML(
|
|||
|
this.responseText
|
|||
|
);
|
|||
|
}
|
|||
|
this.readyStateChange(FakeXMLHttpRequest.DONE);
|
|||
|
},
|
|||
|
|
|||
|
respond: function respond(status, headers, body) {
|
|||
|
this.setStatus(status);
|
|||
|
this.setResponseHeaders(headers || {});
|
|||
|
this.setResponseBody(body || "");
|
|||
|
},
|
|||
|
|
|||
|
uploadProgress: function uploadProgress(progressEventRaw) {
|
|||
|
if (supportsProgress) {
|
|||
|
this.upload.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent(
|
|||
|
"progress",
|
|||
|
progressEventRaw,
|
|||
|
this.upload
|
|||
|
)
|
|||
|
);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
downloadProgress: function downloadProgress(progressEventRaw) {
|
|||
|
if (supportsProgress) {
|
|||
|
this.dispatchEvent(
|
|||
|
new sinonEvent.ProgressEvent(
|
|||
|
"progress",
|
|||
|
progressEventRaw,
|
|||
|
this
|
|||
|
)
|
|||
|
);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
uploadError: function uploadError(error) {
|
|||
|
if (supportsCustomEvent) {
|
|||
|
this.upload.dispatchEvent(
|
|||
|
new sinonEvent.CustomEvent("error", { detail: error })
|
|||
|
);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
overrideMimeType: function overrideMimeType(type) {
|
|||
|
if (this.readyState >= FakeXMLHttpRequest.LOADING) {
|
|||
|
throw new Error("INVALID_STATE_ERR");
|
|||
|
}
|
|||
|
this.overriddenMimeType = type;
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
var states = {
|
|||
|
UNSENT: 0,
|
|||
|
OPENED: 1,
|
|||
|
HEADERS_RECEIVED: 2,
|
|||
|
LOADING: 3,
|
|||
|
DONE: 4
|
|||
|
};
|
|||
|
|
|||
|
extend(FakeXMLHttpRequest, states);
|
|||
|
extend(FakeXMLHttpRequest.prototype, states);
|
|||
|
|
|||
|
function useFakeXMLHttpRequest() {
|
|||
|
FakeXMLHttpRequest.restore = function restore(keepOnCreate) {
|
|||
|
if (sinonXhr.supportsXHR) {
|
|||
|
globalScope.XMLHttpRequest = sinonXhr.GlobalXMLHttpRequest;
|
|||
|
}
|
|||
|
|
|||
|
if (sinonXhr.supportsActiveX) {
|
|||
|
globalScope.ActiveXObject = sinonXhr.GlobalActiveXObject;
|
|||
|
}
|
|||
|
|
|||
|
delete FakeXMLHttpRequest.restore;
|
|||
|
|
|||
|
if (keepOnCreate !== true) {
|
|||
|
delete FakeXMLHttpRequest.onCreate;
|
|||
|
}
|
|||
|
};
|
|||
|
if (sinonXhr.supportsXHR) {
|
|||
|
globalScope.XMLHttpRequest = FakeXMLHttpRequest;
|
|||
|
}
|
|||
|
|
|||
|
if (sinonXhr.supportsActiveX) {
|
|||
|
globalScope.ActiveXObject = function ActiveXObject(objId) {
|
|||
|
if (
|
|||
|
objId === "Microsoft.XMLHTTP" ||
|
|||
|
/^Msxml2\.XMLHTTP/i.test(objId)
|
|||
|
) {
|
|||
|
return new FakeXMLHttpRequest();
|
|||
|
}
|
|||
|
|
|||
|
return new sinonXhr.GlobalActiveXObject(objId);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return FakeXMLHttpRequest;
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
xhr: sinonXhr,
|
|||
|
FakeXMLHttpRequest: FakeXMLHttpRequest,
|
|||
|
useFakeXMLHttpRequest: useFakeXMLHttpRequest
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
module.exports = extend(fakeXMLHttpRequestFor(globalObject), {
|
|||
|
fakeXMLHttpRequestFor: fakeXMLHttpRequestFor
|
|||
|
});
|
|||
|
|
|||
|
},{"../configure-logger":92,"../event":96,"./blob":101,"@sinonjs/commons":45,"@sinonjs/text-encoding":85,"just-extend":90}],103:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
|
|||
|
module.exports = {
|
|||
|
fakeServer: require("./fake-server"),
|
|||
|
fakeServerWithClock: require("./fake-server/fake-server-with-clock"),
|
|||
|
fakeXhr: require("./fake-xhr")
|
|||
|
};
|
|||
|
|
|||
|
},{"./fake-server":99,"./fake-server/fake-server-with-clock":98,"./fake-xhr":102}],104:[function(require,module,exports){
|
|||
|
var isarray = require('isarray')
|
|||
|
|
|||
|
/**
|
|||
|
* Expose `pathToRegexp`.
|
|||
|
*/
|
|||
|
module.exports = pathToRegexp
|
|||
|
module.exports.parse = parse
|
|||
|
module.exports.compile = compile
|
|||
|
module.exports.tokensToFunction = tokensToFunction
|
|||
|
module.exports.tokensToRegExp = tokensToRegExp
|
|||
|
|
|||
|
/**
|
|||
|
* The main path matching regexp utility.
|
|||
|
*
|
|||
|
* @type {RegExp}
|
|||
|
*/
|
|||
|
var PATH_REGEXP = new RegExp([
|
|||
|
// Match escaped characters that would otherwise appear in future matches.
|
|||
|
// This allows the user to escape special characters that won't transform.
|
|||
|
'(\\\\.)',
|
|||
|
// Match Express-style parameters and un-named parameters with a prefix
|
|||
|
// and optional suffixes. Matches appear as:
|
|||
|
//
|
|||
|
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
|
|||
|
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
|
|||
|
// "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
|
|||
|
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
|
|||
|
].join('|'), 'g')
|
|||
|
|
|||
|
/**
|
|||
|
* Parse a string for the raw tokens.
|
|||
|
*
|
|||
|
* @param {string} str
|
|||
|
* @param {Object=} options
|
|||
|
* @return {!Array}
|
|||
|
*/
|
|||
|
function parse (str, options) {
|
|||
|
var tokens = []
|
|||
|
var key = 0
|
|||
|
var index = 0
|
|||
|
var path = ''
|
|||
|
var defaultDelimiter = options && options.delimiter || '/'
|
|||
|
var res
|
|||
|
|
|||
|
while ((res = PATH_REGEXP.exec(str)) != null) {
|
|||
|
var m = res[0]
|
|||
|
var escaped = res[1]
|
|||
|
var offset = res.index
|
|||
|
path += str.slice(index, offset)
|
|||
|
index = offset + m.length
|
|||
|
|
|||
|
// Ignore already escaped sequences.
|
|||
|
if (escaped) {
|
|||
|
path += escaped[1]
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
var next = str[index]
|
|||
|
var prefix = res[2]
|
|||
|
var name = res[3]
|
|||
|
var capture = res[4]
|
|||
|
var group = res[5]
|
|||
|
var modifier = res[6]
|
|||
|
var asterisk = res[7]
|
|||
|
|
|||
|
// Push the current path onto the tokens.
|
|||
|
if (path) {
|
|||
|
tokens.push(path)
|
|||
|
path = ''
|
|||
|
}
|
|||
|
|
|||
|
var partial = prefix != null && next != null && next !== prefix
|
|||
|
var repeat = modifier === '+' || modifier === '*'
|
|||
|
var optional = modifier === '?' || modifier === '*'
|
|||
|
var delimiter = res[2] || defaultDelimiter
|
|||
|
var pattern = capture || group
|
|||
|
|
|||
|
tokens.push({
|
|||
|
name: name || key++,
|
|||
|
prefix: prefix || '',
|
|||
|
delimiter: delimiter,
|
|||
|
optional: optional,
|
|||
|
repeat: repeat,
|
|||
|
partial: partial,
|
|||
|
asterisk: !!asterisk,
|
|||
|
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
// Match any characters still remaining.
|
|||
|
if (index < str.length) {
|
|||
|
path += str.substr(index)
|
|||
|
}
|
|||
|
|
|||
|
// If the path exists, push it onto the end.
|
|||
|
if (path) {
|
|||
|
tokens.push(path)
|
|||
|
}
|
|||
|
|
|||
|
return tokens
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Compile a string to a template function for the path.
|
|||
|
*
|
|||
|
* @param {string} str
|
|||
|
* @param {Object=} options
|
|||
|
* @return {!function(Object=, Object=)}
|
|||
|
*/
|
|||
|
function compile (str, options) {
|
|||
|
return tokensToFunction(parse(str, options), options)
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Prettier encoding of URI path segments.
|
|||
|
*
|
|||
|
* @param {string}
|
|||
|
* @return {string}
|
|||
|
*/
|
|||
|
function encodeURIComponentPretty (str) {
|
|||
|
return encodeURI(str).replace(/[\/?#]/g, function (c) {
|
|||
|
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
|
|||
|
*
|
|||
|
* @param {string}
|
|||
|
* @return {string}
|
|||
|
*/
|
|||
|
function encodeAsterisk (str) {
|
|||
|
return encodeURI(str).replace(/[?#]/g, function (c) {
|
|||
|
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Expose a method for transforming tokens into the path function.
|
|||
|
*/
|
|||
|
function tokensToFunction (tokens, options) {
|
|||
|
// Compile all the tokens into regexps.
|
|||
|
var matches = new Array(tokens.length)
|
|||
|
|
|||
|
// Compile all the patterns before compilation.
|
|||
|
for (var i = 0; i < tokens.length; i++) {
|
|||
|
if (typeof tokens[i] === 'object') {
|
|||
|
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options))
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return function (obj, opts) {
|
|||
|
var path = ''
|
|||
|
var data = obj || {}
|
|||
|
var options = opts || {}
|
|||
|
var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent
|
|||
|
|
|||
|
for (var i = 0; i < tokens.length; i++) {
|
|||
|
var token = tokens[i]
|
|||
|
|
|||
|
if (typeof token === 'string') {
|
|||
|
path += token
|
|||
|
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
var value = data[token.name]
|
|||
|
var segment
|
|||
|
|
|||
|
if (value == null) {
|
|||
|
if (token.optional) {
|
|||
|
// Prepend partial segment prefixes.
|
|||
|
if (token.partial) {
|
|||
|
path += token.prefix
|
|||
|
}
|
|||
|
|
|||
|
continue
|
|||
|
} else {
|
|||
|
throw new TypeError('Expected "' + token.name + '" to be defined')
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (isarray(value)) {
|
|||
|
if (!token.repeat) {
|
|||
|
throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
|
|||
|
}
|
|||
|
|
|||
|
if (value.length === 0) {
|
|||
|
if (token.optional) {
|
|||
|
continue
|
|||
|
} else {
|
|||
|
throw new TypeError('Expected "' + token.name + '" to not be empty')
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (var j = 0; j < value.length; j++) {
|
|||
|
segment = encode(value[j])
|
|||
|
|
|||
|
if (!matches[i].test(segment)) {
|
|||
|
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
|
|||
|
}
|
|||
|
|
|||
|
path += (j === 0 ? token.prefix : token.delimiter) + segment
|
|||
|
}
|
|||
|
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
segment = token.asterisk ? encodeAsterisk(value) : encode(value)
|
|||
|
|
|||
|
if (!matches[i].test(segment)) {
|
|||
|
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
|
|||
|
}
|
|||
|
|
|||
|
path += token.prefix + segment
|
|||
|
}
|
|||
|
|
|||
|
return path
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Escape a regular expression string.
|
|||
|
*
|
|||
|
* @param {string} str
|
|||
|
* @return {string}
|
|||
|
*/
|
|||
|
function escapeString (str) {
|
|||
|
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Escape the capturing group by escaping special characters and meaning.
|
|||
|
*
|
|||
|
* @param {string} group
|
|||
|
* @return {string}
|
|||
|
*/
|
|||
|
function escapeGroup (group) {
|
|||
|
return group.replace(/([=!:$\/()])/g, '\\$1')
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Attach the keys as a property of the regexp.
|
|||
|
*
|
|||
|
* @param {!RegExp} re
|
|||
|
* @param {Array} keys
|
|||
|
* @return {!RegExp}
|
|||
|
*/
|
|||
|
function attachKeys (re, keys) {
|
|||
|
re.keys = keys
|
|||
|
return re
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Get the flags for a regexp from the options.
|
|||
|
*
|
|||
|
* @param {Object} options
|
|||
|
* @return {string}
|
|||
|
*/
|
|||
|
function flags (options) {
|
|||
|
return options && options.sensitive ? '' : 'i'
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Pull out keys from a regexp.
|
|||
|
*
|
|||
|
* @param {!RegExp} path
|
|||
|
* @param {!Array} keys
|
|||
|
* @return {!RegExp}
|
|||
|
*/
|
|||
|
function regexpToRegexp (path, keys) {
|
|||
|
// Use a negative lookahead to match only capturing groups.
|
|||
|
var groups = path.source.match(/\((?!\?)/g)
|
|||
|
|
|||
|
if (groups) {
|
|||
|
for (var i = 0; i < groups.length; i++) {
|
|||
|
keys.push({
|
|||
|
name: i,
|
|||
|
prefix: null,
|
|||
|
delimiter: null,
|
|||
|
optional: false,
|
|||
|
repeat: false,
|
|||
|
partial: false,
|
|||
|
asterisk: false,
|
|||
|
pattern: null
|
|||
|
})
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return attachKeys(path, keys)
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Transform an array into a regexp.
|
|||
|
*
|
|||
|
* @param {!Array} path
|
|||
|
* @param {Array} keys
|
|||
|
* @param {!Object} options
|
|||
|
* @return {!RegExp}
|
|||
|
*/
|
|||
|
function arrayToRegexp (path, keys, options) {
|
|||
|
var parts = []
|
|||
|
|
|||
|
for (var i = 0; i < path.length; i++) {
|
|||
|
parts.push(pathToRegexp(path[i], keys, options).source)
|
|||
|
}
|
|||
|
|
|||
|
var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options))
|
|||
|
|
|||
|
return attachKeys(regexp, keys)
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Create a path regexp from string input.
|
|||
|
*
|
|||
|
* @param {string} path
|
|||
|
* @param {!Array} keys
|
|||
|
* @param {!Object} options
|
|||
|
* @return {!RegExp}
|
|||
|
*/
|
|||
|
function stringToRegexp (path, keys, options) {
|
|||
|
return tokensToRegExp(parse(path, options), keys, options)
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Expose a function for taking tokens and returning a RegExp.
|
|||
|
*
|
|||
|
* @param {!Array} tokens
|
|||
|
* @param {(Array|Object)=} keys
|
|||
|
* @param {Object=} options
|
|||
|
* @return {!RegExp}
|
|||
|
*/
|
|||
|
function tokensToRegExp (tokens, keys, options) {
|
|||
|
if (!isarray(keys)) {
|
|||
|
options = /** @type {!Object} */ (keys || options)
|
|||
|
keys = []
|
|||
|
}
|
|||
|
|
|||
|
options = options || {}
|
|||
|
|
|||
|
var strict = options.strict
|
|||
|
var end = options.end !== false
|
|||
|
var route = ''
|
|||
|
|
|||
|
// Iterate over the tokens and create our regexp string.
|
|||
|
for (var i = 0; i < tokens.length; i++) {
|
|||
|
var token = tokens[i]
|
|||
|
|
|||
|
if (typeof token === 'string') {
|
|||
|
route += escapeString(token)
|
|||
|
} else {
|
|||
|
var prefix = escapeString(token.prefix)
|
|||
|
var capture = '(?:' + token.pattern + ')'
|
|||
|
|
|||
|
keys.push(token)
|
|||
|
|
|||
|
if (token.repeat) {
|
|||
|
capture += '(?:' + prefix + capture + ')*'
|
|||
|
}
|
|||
|
|
|||
|
if (token.optional) {
|
|||
|
if (!token.partial) {
|
|||
|
capture = '(?:' + prefix + '(' + capture + '))?'
|
|||
|
} else {
|
|||
|
capture = prefix + '(' + capture + ')?'
|
|||
|
}
|
|||
|
} else {
|
|||
|
capture = prefix + '(' + capture + ')'
|
|||
|
}
|
|||
|
|
|||
|
route += capture
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var delimiter = escapeString(options.delimiter || '/')
|
|||
|
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter
|
|||
|
|
|||
|
// In non-strict mode we allow a slash at the end of match. If the path to
|
|||
|
// match already ends with a slash, we remove it for consistency. The slash
|
|||
|
// is valid at the end of a path match, not in the middle. This is important
|
|||
|
// in non-ending mode, where "/test/" shouldn't match "/test//route".
|
|||
|
if (!strict) {
|
|||
|
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'
|
|||
|
}
|
|||
|
|
|||
|
if (end) {
|
|||
|
route += '$'
|
|||
|
} else {
|
|||
|
// In non-ending mode, we need the capturing groups to match as much as
|
|||
|
// possible by using a positive lookahead to the end or next path segment.
|
|||
|
route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'
|
|||
|
}
|
|||
|
|
|||
|
return attachKeys(new RegExp('^' + route, flags(options)), keys)
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Normalize the given path string, returning a regular expression.
|
|||
|
*
|
|||
|
* An empty array can be passed in for the keys, which will hold the
|
|||
|
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
|||
|
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
|||
|
*
|
|||
|
* @param {(string|RegExp|Array)} path
|
|||
|
* @param {(Array|Object)=} keys
|
|||
|
* @param {Object=} options
|
|||
|
* @return {!RegExp}
|
|||
|
*/
|
|||
|
function pathToRegexp (path, keys, options) {
|
|||
|
if (!isarray(keys)) {
|
|||
|
options = /** @type {!Object} */ (keys || options)
|
|||
|
keys = []
|
|||
|
}
|
|||
|
|
|||
|
options = options || {}
|
|||
|
|
|||
|
if (path instanceof RegExp) {
|
|||
|
return regexpToRegexp(path, /** @type {!Array} */ (keys))
|
|||
|
}
|
|||
|
|
|||
|
if (isarray(path)) {
|
|||
|
return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
|
|||
|
}
|
|||
|
|
|||
|
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
|
|||
|
}
|
|||
|
|
|||
|
},{"isarray":89}],105:[function(require,module,exports){
|
|||
|
'use strict';
|
|||
|
module.exports = {
|
|||
|
stdout: false,
|
|||
|
stderr: false
|
|||
|
};
|
|||
|
|
|||
|
},{}],106:[function(require,module,exports){
|
|||
|
(function (global, factory) {
|
|||
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|||
|
typeof define === 'function' && define.amd ? define(factory) :
|
|||
|
(global.typeDetect = factory());
|
|||
|
}(this, (function () { 'use strict';
|
|||
|
|
|||
|
/* !
|
|||
|
* 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 : global; // 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;
|
|||
|
|
|||
|
})));
|
|||
|
|
|||
|
},{}],107:[function(require,module,exports){
|
|||
|
if (typeof Object.create === 'function') {
|
|||
|
// implementation from standard node.js 'util' module
|
|||
|
module.exports = function inherits(ctor, superCtor) {
|
|||
|
ctor.super_ = superCtor
|
|||
|
ctor.prototype = Object.create(superCtor.prototype, {
|
|||
|
constructor: {
|
|||
|
value: ctor,
|
|||
|
enumerable: false,
|
|||
|
writable: true,
|
|||
|
configurable: true
|
|||
|
}
|
|||
|
});
|
|||
|
};
|
|||
|
} else {
|
|||
|
// old school shim for old browsers
|
|||
|
module.exports = function inherits(ctor, superCtor) {
|
|||
|
ctor.super_ = superCtor
|
|||
|
var TempCtor = function () {}
|
|||
|
TempCtor.prototype = superCtor.prototype
|
|||
|
ctor.prototype = new TempCtor()
|
|||
|
ctor.prototype.constructor = ctor
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
},{}],108:[function(require,module,exports){
|
|||
|
module.exports = function isBuffer(arg) {
|
|||
|
return arg && typeof arg === 'object'
|
|||
|
&& typeof arg.copy === 'function'
|
|||
|
&& typeof arg.fill === 'function'
|
|||
|
&& typeof arg.readUInt8 === 'function';
|
|||
|
}
|
|||
|
},{}],109:[function(require,module,exports){
|
|||
|
// Copyright Joyent, Inc. and other Node contributors.
|
|||
|
//
|
|||
|
// 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.
|
|||
|
|
|||
|
var formatRegExp = /%[sdj%]/g;
|
|||
|
exports.format = function(f) {
|
|||
|
if (!isString(f)) {
|
|||
|
var objects = [];
|
|||
|
for (var i = 0; i < arguments.length; i++) {
|
|||
|
objects.push(inspect(arguments[i]));
|
|||
|
}
|
|||
|
return objects.join(' ');
|
|||
|
}
|
|||
|
|
|||
|
var i = 1;
|
|||
|
var args = arguments;
|
|||
|
var len = args.length;
|
|||
|
var str = String(f).replace(formatRegExp, function(x) {
|
|||
|
if (x === '%%') return '%';
|
|||
|
if (i >= len) return x;
|
|||
|
switch (x) {
|
|||
|
case '%s': return String(args[i++]);
|
|||
|
case '%d': return Number(args[i++]);
|
|||
|
case '%j':
|
|||
|
try {
|
|||
|
return JSON.stringify(args[i++]);
|
|||
|
} catch (_) {
|
|||
|
return '[Circular]';
|
|||
|
}
|
|||
|
default:
|
|||
|
return x;
|
|||
|
}
|
|||
|
});
|
|||
|
for (var x = args[i]; i < len; x = args[++i]) {
|
|||
|
if (isNull(x) || !isObject(x)) {
|
|||
|
str += ' ' + x;
|
|||
|
} else {
|
|||
|
str += ' ' + inspect(x);
|
|||
|
}
|
|||
|
}
|
|||
|
return str;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
// Mark that a method should not be used.
|
|||
|
// Returns a modified function which warns once by default.
|
|||
|
// If --no-deprecation is set, then it is a no-op.
|
|||
|
exports.deprecate = function(fn, msg) {
|
|||
|
// Allow for deprecating things in the process of starting up.
|
|||
|
if (isUndefined(global.process)) {
|
|||
|
return function() {
|
|||
|
return exports.deprecate(fn, msg).apply(this, arguments);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
if (process.noDeprecation === true) {
|
|||
|
return fn;
|
|||
|
}
|
|||
|
|
|||
|
var warned = false;
|
|||
|
function deprecated() {
|
|||
|
if (!warned) {
|
|||
|
if (process.throwDeprecation) {
|
|||
|
throw new Error(msg);
|
|||
|
} else if (process.traceDeprecation) {
|
|||
|
console.trace(msg);
|
|||
|
} else {
|
|||
|
console.error(msg);
|
|||
|
}
|
|||
|
warned = true;
|
|||
|
}
|
|||
|
return fn.apply(this, arguments);
|
|||
|
}
|
|||
|
|
|||
|
return deprecated;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
var debugs = {};
|
|||
|
var debugEnviron;
|
|||
|
exports.debuglog = function(set) {
|
|||
|
if (isUndefined(debugEnviron))
|
|||
|
debugEnviron = process.env.NODE_DEBUG || '';
|
|||
|
set = set.toUpperCase();
|
|||
|
if (!debugs[set]) {
|
|||
|
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
|||
|
var pid = process.pid;
|
|||
|
debugs[set] = function() {
|
|||
|
var msg = exports.format.apply(exports, arguments);
|
|||
|
console.error('%s %d: %s', set, pid, msg);
|
|||
|
};
|
|||
|
} else {
|
|||
|
debugs[set] = function() {};
|
|||
|
}
|
|||
|
}
|
|||
|
return debugs[set];
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Echos the value of a value. Trys to print the value out
|
|||
|
* in the best way possible given the different types.
|
|||
|
*
|
|||
|
* @param {Object} obj The object to print out.
|
|||
|
* @param {Object} opts Optional options object that alters the output.
|
|||
|
*/
|
|||
|
/* legacy: obj, showHidden, depth, colors*/
|
|||
|
function inspect(obj, opts) {
|
|||
|
// default options
|
|||
|
var ctx = {
|
|||
|
seen: [],
|
|||
|
stylize: stylizeNoColor
|
|||
|
};
|
|||
|
// legacy...
|
|||
|
if (arguments.length >= 3) ctx.depth = arguments[2];
|
|||
|
if (arguments.length >= 4) ctx.colors = arguments[3];
|
|||
|
if (isBoolean(opts)) {
|
|||
|
// legacy...
|
|||
|
ctx.showHidden = opts;
|
|||
|
} else if (opts) {
|
|||
|
// got an "options" object
|
|||
|
exports._extend(ctx, opts);
|
|||
|
}
|
|||
|
// set default options
|
|||
|
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
|||
|
if (isUndefined(ctx.depth)) ctx.depth = 2;
|
|||
|
if (isUndefined(ctx.colors)) ctx.colors = false;
|
|||
|
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
|||
|
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
|||
|
return formatValue(ctx, obj, ctx.depth);
|
|||
|
}
|
|||
|
exports.inspect = inspect;
|
|||
|
|
|||
|
|
|||
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|||
|
inspect.colors = {
|
|||
|
'bold' : [1, 22],
|
|||
|
'italic' : [3, 23],
|
|||
|
'underline' : [4, 24],
|
|||
|
'inverse' : [7, 27],
|
|||
|
'white' : [37, 39],
|
|||
|
'grey' : [90, 39],
|
|||
|
'black' : [30, 39],
|
|||
|
'blue' : [34, 39],
|
|||
|
'cyan' : [36, 39],
|
|||
|
'green' : [32, 39],
|
|||
|
'magenta' : [35, 39],
|
|||
|
'red' : [31, 39],
|
|||
|
'yellow' : [33, 39]
|
|||
|
};
|
|||
|
|
|||
|
// Don't use 'blue' not visible on cmd.exe
|
|||
|
inspect.styles = {
|
|||
|
'special': 'cyan',
|
|||
|
'number': 'yellow',
|
|||
|
'boolean': 'yellow',
|
|||
|
'undefined': 'grey',
|
|||
|
'null': 'bold',
|
|||
|
'string': 'green',
|
|||
|
'date': 'magenta',
|
|||
|
// "name": intentionally not styling
|
|||
|
'regexp': 'red'
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
function stylizeWithColor(str, styleType) {
|
|||
|
var style = inspect.styles[styleType];
|
|||
|
|
|||
|
if (style) {
|
|||
|
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
|||
|
'\u001b[' + inspect.colors[style][1] + 'm';
|
|||
|
} else {
|
|||
|
return str;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function stylizeNoColor(str, styleType) {
|
|||
|
return str;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function arrayToHash(array) {
|
|||
|
var hash = {};
|
|||
|
|
|||
|
array.forEach(function(val, idx) {
|
|||
|
hash[val] = true;
|
|||
|
});
|
|||
|
|
|||
|
return hash;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatValue(ctx, value, recurseTimes) {
|
|||
|
// Provide a hook for user-specified inspect functions.
|
|||
|
// Check that value is an object with an inspect function on it
|
|||
|
if (ctx.customInspect &&
|
|||
|
value &&
|
|||
|
isFunction(value.inspect) &&
|
|||
|
// Filter out the util module, it's inspect function is special
|
|||
|
value.inspect !== exports.inspect &&
|
|||
|
// Also filter out any prototype objects using the circular check.
|
|||
|
!(value.constructor && value.constructor.prototype === value)) {
|
|||
|
var ret = value.inspect(recurseTimes, ctx);
|
|||
|
if (!isString(ret)) {
|
|||
|
ret = formatValue(ctx, ret, recurseTimes);
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
// Primitive types cannot have properties
|
|||
|
var primitive = formatPrimitive(ctx, value);
|
|||
|
if (primitive) {
|
|||
|
return primitive;
|
|||
|
}
|
|||
|
|
|||
|
// Look up the keys of the object.
|
|||
|
var keys = Object.keys(value);
|
|||
|
var visibleKeys = arrayToHash(keys);
|
|||
|
|
|||
|
if (ctx.showHidden) {
|
|||
|
keys = Object.getOwnPropertyNames(value);
|
|||
|
}
|
|||
|
|
|||
|
// IE doesn't make error fields non-enumerable
|
|||
|
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
|
|||
|
if (isError(value)
|
|||
|
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
|||
|
return formatError(value);
|
|||
|
}
|
|||
|
|
|||
|
// Some type of object without properties can be shortcutted.
|
|||
|
if (keys.length === 0) {
|
|||
|
if (isFunction(value)) {
|
|||
|
var name = value.name ? ': ' + value.name : '';
|
|||
|
return ctx.stylize('[Function' + name + ']', 'special');
|
|||
|
}
|
|||
|
if (isRegExp(value)) {
|
|||
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|||
|
}
|
|||
|
if (isDate(value)) {
|
|||
|
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
|||
|
}
|
|||
|
if (isError(value)) {
|
|||
|
return formatError(value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var base = '', array = false, braces = ['{', '}'];
|
|||
|
|
|||
|
// Make Array say that they are Array
|
|||
|
if (isArray(value)) {
|
|||
|
array = true;
|
|||
|
braces = ['[', ']'];
|
|||
|
}
|
|||
|
|
|||
|
// Make functions say that they are functions
|
|||
|
if (isFunction(value)) {
|
|||
|
var n = value.name ? ': ' + value.name : '';
|
|||
|
base = ' [Function' + n + ']';
|
|||
|
}
|
|||
|
|
|||
|
// Make RegExps say that they are RegExps
|
|||
|
if (isRegExp(value)) {
|
|||
|
base = ' ' + RegExp.prototype.toString.call(value);
|
|||
|
}
|
|||
|
|
|||
|
// Make dates with properties first say the date
|
|||
|
if (isDate(value)) {
|
|||
|
base = ' ' + Date.prototype.toUTCString.call(value);
|
|||
|
}
|
|||
|
|
|||
|
// Make error with message first say the error
|
|||
|
if (isError(value)) {
|
|||
|
base = ' ' + formatError(value);
|
|||
|
}
|
|||
|
|
|||
|
if (keys.length === 0 && (!array || value.length == 0)) {
|
|||
|
return braces[0] + base + braces[1];
|
|||
|
}
|
|||
|
|
|||
|
if (recurseTimes < 0) {
|
|||
|
if (isRegExp(value)) {
|
|||
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|||
|
} else {
|
|||
|
return ctx.stylize('[Object]', 'special');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ctx.seen.push(value);
|
|||
|
|
|||
|
var output;
|
|||
|
if (array) {
|
|||
|
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|||
|
} else {
|
|||
|
output = keys.map(function(key) {
|
|||
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
ctx.seen.pop();
|
|||
|
|
|||
|
return reduceToSingleString(output, base, braces);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatPrimitive(ctx, value) {
|
|||
|
if (isUndefined(value))
|
|||
|
return ctx.stylize('undefined', 'undefined');
|
|||
|
if (isString(value)) {
|
|||
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|||
|
.replace(/'/g, "\\'")
|
|||
|
.replace(/\\"/g, '"') + '\'';
|
|||
|
return ctx.stylize(simple, 'string');
|
|||
|
}
|
|||
|
if (isNumber(value))
|
|||
|
return ctx.stylize('' + value, 'number');
|
|||
|
if (isBoolean(value))
|
|||
|
return ctx.stylize('' + value, 'boolean');
|
|||
|
// For some reason typeof null is "object", so special case here.
|
|||
|
if (isNull(value))
|
|||
|
return ctx.stylize('null', 'null');
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatError(value) {
|
|||
|
return '[' + Error.prototype.toString.call(value) + ']';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|||
|
var output = [];
|
|||
|
for (var i = 0, l = value.length; i < l; ++i) {
|
|||
|
if (hasOwnProperty(value, String(i))) {
|
|||
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|||
|
String(i), true));
|
|||
|
} else {
|
|||
|
output.push('');
|
|||
|
}
|
|||
|
}
|
|||
|
keys.forEach(function(key) {
|
|||
|
if (!key.match(/^\d+$/)) {
|
|||
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|||
|
key, true));
|
|||
|
}
|
|||
|
});
|
|||
|
return output;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|||
|
var name, str, desc;
|
|||
|
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|||
|
if (desc.get) {
|
|||
|
if (desc.set) {
|
|||
|
str = ctx.stylize('[Getter/Setter]', 'special');
|
|||
|
} else {
|
|||
|
str = ctx.stylize('[Getter]', 'special');
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (desc.set) {
|
|||
|
str = ctx.stylize('[Setter]', 'special');
|
|||
|
}
|
|||
|
}
|
|||
|
if (!hasOwnProperty(visibleKeys, key)) {
|
|||
|
name = '[' + key + ']';
|
|||
|
}
|
|||
|
if (!str) {
|
|||
|
if (ctx.seen.indexOf(desc.value) < 0) {
|
|||
|
if (isNull(recurseTimes)) {
|
|||
|
str = formatValue(ctx, desc.value, null);
|
|||
|
} else {
|
|||
|
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
|||
|
}
|
|||
|
if (str.indexOf('\n') > -1) {
|
|||
|
if (array) {
|
|||
|
str = str.split('\n').map(function(line) {
|
|||
|
return ' ' + line;
|
|||
|
}).join('\n').substr(2);
|
|||
|
} else {
|
|||
|
str = '\n' + str.split('\n').map(function(line) {
|
|||
|
return ' ' + line;
|
|||
|
}).join('\n');
|
|||
|
}
|
|||
|
}
|
|||
|
} else {
|
|||
|
str = ctx.stylize('[Circular]', 'special');
|
|||
|
}
|
|||
|
}
|
|||
|
if (isUndefined(name)) {
|
|||
|
if (array && key.match(/^\d+$/)) {
|
|||
|
return str;
|
|||
|
}
|
|||
|
name = JSON.stringify('' + key);
|
|||
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|||
|
name = name.substr(1, name.length - 2);
|
|||
|
name = ctx.stylize(name, 'name');
|
|||
|
} else {
|
|||
|
name = name.replace(/'/g, "\\'")
|
|||
|
.replace(/\\"/g, '"')
|
|||
|
.replace(/(^"|"$)/g, "'");
|
|||
|
name = ctx.stylize(name, 'string');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return name + ': ' + str;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function reduceToSingleString(output, base, braces) {
|
|||
|
var numLinesEst = 0;
|
|||
|
var length = output.reduce(function(prev, cur) {
|
|||
|
numLinesEst++;
|
|||
|
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|||
|
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
|||
|
}, 0);
|
|||
|
|
|||
|
if (length > 60) {
|
|||
|
return braces[0] +
|
|||
|
(base === '' ? '' : base + '\n ') +
|
|||
|
' ' +
|
|||
|
output.join(',\n ') +
|
|||
|
' ' +
|
|||
|
braces[1];
|
|||
|
}
|
|||
|
|
|||
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|||
|
// because it is fragile and can be easily faked with `Object.create()`.
|
|||
|
function isArray(ar) {
|
|||
|
return Array.isArray(ar);
|
|||
|
}
|
|||
|
exports.isArray = isArray;
|
|||
|
|
|||
|
function isBoolean(arg) {
|
|||
|
return typeof arg === 'boolean';
|
|||
|
}
|
|||
|
exports.isBoolean = isBoolean;
|
|||
|
|
|||
|
function isNull(arg) {
|
|||
|
return arg === null;
|
|||
|
}
|
|||
|
exports.isNull = isNull;
|
|||
|
|
|||
|
function isNullOrUndefined(arg) {
|
|||
|
return arg == null;
|
|||
|
}
|
|||
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|||
|
|
|||
|
function isNumber(arg) {
|
|||
|
return typeof arg === 'number';
|
|||
|
}
|
|||
|
exports.isNumber = isNumber;
|
|||
|
|
|||
|
function isString(arg) {
|
|||
|
return typeof arg === 'string';
|
|||
|
}
|
|||
|
exports.isString = isString;
|
|||
|
|
|||
|
function isSymbol(arg) {
|
|||
|
return typeof arg === 'symbol';
|
|||
|
}
|
|||
|
exports.isSymbol = isSymbol;
|
|||
|
|
|||
|
function isUndefined(arg) {
|
|||
|
return arg === void 0;
|
|||
|
}
|
|||
|
exports.isUndefined = isUndefined;
|
|||
|
|
|||
|
function isRegExp(re) {
|
|||
|
return isObject(re) && objectToString(re) === '[object RegExp]';
|
|||
|
}
|
|||
|
exports.isRegExp = isRegExp;
|
|||
|
|
|||
|
function isObject(arg) {
|
|||
|
return typeof arg === 'object' && arg !== null;
|
|||
|
}
|
|||
|
exports.isObject = isObject;
|
|||
|
|
|||
|
function isDate(d) {
|
|||
|
return isObject(d) && objectToString(d) === '[object Date]';
|
|||
|
}
|
|||
|
exports.isDate = isDate;
|
|||
|
|
|||
|
function isError(e) {
|
|||
|
return isObject(e) &&
|
|||
|
(objectToString(e) === '[object Error]' || e instanceof Error);
|
|||
|
}
|
|||
|
exports.isError = isError;
|
|||
|
|
|||
|
function isFunction(arg) {
|
|||
|
return typeof arg === 'function';
|
|||
|
}
|
|||
|
exports.isFunction = isFunction;
|
|||
|
|
|||
|
function isPrimitive(arg) {
|
|||
|
return arg === null ||
|
|||
|
typeof arg === 'boolean' ||
|
|||
|
typeof arg === 'number' ||
|
|||
|
typeof arg === 'string' ||
|
|||
|
typeof arg === 'symbol' || // ES6 symbol
|
|||
|
typeof arg === 'undefined';
|
|||
|
}
|
|||
|
exports.isPrimitive = isPrimitive;
|
|||
|
|
|||
|
exports.isBuffer = require('./support/isBuffer');
|
|||
|
|
|||
|
function objectToString(o) {
|
|||
|
return Object.prototype.toString.call(o);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function pad(n) {
|
|||
|
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|||
|
'Oct', 'Nov', 'Dec'];
|
|||
|
|
|||
|
// 26 Feb 16:19:34
|
|||
|
function timestamp() {
|
|||
|
var d = new Date();
|
|||
|
var time = [pad(d.getHours()),
|
|||
|
pad(d.getMinutes()),
|
|||
|
pad(d.getSeconds())].join(':');
|
|||
|
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// log is just a thin wrapper to console.log that prepends a timestamp
|
|||
|
exports.log = function() {
|
|||
|
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Inherit the prototype methods from one constructor into another.
|
|||
|
*
|
|||
|
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
|||
|
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
|||
|
* during bootstrapping this function needs to be rewritten using some native
|
|||
|
* functions as prototype setup using normal JavaScript does not work as
|
|||
|
* expected during bootstrapping (see mirror.js in r114903).
|
|||
|
*
|
|||
|
* @param {function} ctor Constructor function which needs to inherit the
|
|||
|
* prototype.
|
|||
|
* @param {function} superCtor Constructor function to inherit prototype from.
|
|||
|
*/
|
|||
|
exports.inherits = require('inherits');
|
|||
|
|
|||
|
exports._extend = function(origin, add) {
|
|||
|
// Don't do anything if add isn't an object
|
|||
|
if (!add || !isObject(add)) return origin;
|
|||
|
|
|||
|
var keys = Object.keys(add);
|
|||
|
var i = keys.length;
|
|||
|
while (i--) {
|
|||
|
origin[keys[i]] = add[keys[i]];
|
|||
|
}
|
|||
|
return origin;
|
|||
|
};
|
|||
|
|
|||
|
function hasOwnProperty(obj, prop) {
|
|||
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|||
|
}
|
|||
|
|
|||
|
},{"./support/isBuffer":108,"inherits":107}]},{},[1]);
|
|||
|
|
|||
|
export default sinon;
|
|||
|
const _serverPrototype = sinon.serverPrototype;
|
|||
|
export { _serverPrototype as serverPrototype };
|
|||
|
const _getFakes = sinon.getFakes;
|
|||
|
export { _getFakes as getFakes };
|
|||
|
const _getRestorers = sinon.getRestorers;
|
|||
|
export { _getRestorers as getRestorers };
|
|||
|
const _createStubInstance = sinon.createStubInstance;
|
|||
|
export { _createStubInstance as createStubInstance };
|
|||
|
const _inject = sinon.inject;
|
|||
|
export { _inject as inject };
|
|||
|
const _mock = sinon.mock;
|
|||
|
export { _mock as mock };
|
|||
|
const _reset = sinon.reset;
|
|||
|
export { _reset as reset };
|
|||
|
const _resetBehavior = sinon.resetBehavior;
|
|||
|
export { _resetBehavior as resetBehavior };
|
|||
|
const _resetHistory = sinon.resetHistory;
|
|||
|
export { _resetHistory as resetHistory };
|
|||
|
const _restore = sinon.restore;
|
|||
|
export { _restore as restore };
|
|||
|
const _restoreContext = sinon.restoreContext;
|
|||
|
export { _restoreContext as restoreContext };
|
|||
|
const _replace = sinon.replace;
|
|||
|
export { _replace as replace };
|
|||
|
const _replaceGetter = sinon.replaceGetter;
|
|||
|
export { _replaceGetter as replaceGetter };
|
|||
|
const _replaceSetter = sinon.replaceSetter;
|
|||
|
export { _replaceSetter as replaceSetter };
|
|||
|
const _spy = sinon.spy;
|
|||
|
export { _spy as spy };
|
|||
|
const _stub = sinon.stub;
|
|||
|
export { _stub as stub };
|
|||
|
const _fake = sinon.fake;
|
|||
|
export { _fake as fake };
|
|||
|
const _useFakeTimers = sinon.useFakeTimers;
|
|||
|
export { _useFakeTimers as useFakeTimers };
|
|||
|
const _verify = sinon.verify;
|
|||
|
export { _verify as verify };
|
|||
|
const _verifyAndRestore = sinon.verifyAndRestore;
|
|||
|
export { _verifyAndRestore as verifyAndRestore };
|
|||
|
const _useFakeServer = sinon.useFakeServer;
|
|||
|
export { _useFakeServer as useFakeServer };
|
|||
|
const _useFakeXMLHttpRequest = sinon.useFakeXMLHttpRequest;
|
|||
|
export { _useFakeXMLHttpRequest as useFakeXMLHttpRequest };
|
|||
|
const _usingPromise = sinon.usingPromise;
|
|||
|
export { _usingPromise as usingPromise };
|
|||
|
const _createSandbox = sinon.createSandbox;
|
|||
|
export { _createSandbox as createSandbox };
|
|||
|
const _assert = sinon.assert;
|
|||
|
export { _assert as assert };
|
|||
|
const _match = sinon.match;
|
|||
|
export { _match as match };
|
|||
|
const _restoreObject = sinon.restoreObject;
|
|||
|
export { _restoreObject as restoreObject };
|
|||
|
const _expectation = sinon.expectation;
|
|||
|
export { _expectation as expectation };
|
|||
|
const _defaultConfig = sinon.defaultConfig;
|
|||
|
export { _defaultConfig as defaultConfig };
|
|||
|
const _setFormatter = sinon.setFormatter;
|
|||
|
export { _setFormatter as setFormatter };
|
|||
|
const _timers = sinon.timers;
|
|||
|
export { _timers as timers };
|
|||
|
const _xhr = sinon.xhr;
|
|||
|
export { _xhr as xhr };
|
|||
|
const _FakeXMLHttpRequest = sinon.FakeXMLHttpRequest;
|
|||
|
export { _FakeXMLHttpRequest as FakeXMLHttpRequest };
|
|||
|
const _fakeServer = sinon.fakeServer;
|
|||
|
export { _fakeServer as fakeServer };
|
|||
|
const _fakeServerWithClock = sinon.fakeServerWithClock;
|
|||
|
export { _fakeServerWithClock as fakeServerWithClock };
|
|||
|
const _createFakeServer = sinon.createFakeServer;
|
|||
|
export { _createFakeServer as createFakeServer };
|
|||
|
const _createFakeServerWithClock = sinon.createFakeServerWithClock;
|
|||
|
export { _createFakeServerWithClock as createFakeServerWithClock };
|
|||
|
const _addBehavior = sinon.addBehavior;
|
|||
|
export { _addBehavior as addBehavior };
|