16047 lines
490 KiB
JavaScript
16047 lines
490 KiB
JavaScript
|
(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){
|
||
|
(function (process,global){
|
||
|
'use strict';
|
||
|
|
||
|
/* eslint no-unused-vars: off */
|
||
|
/* eslint-env commonjs */
|
||
|
|
||
|
/**
|
||
|
* Shim process.stdout.
|
||
|
*/
|
||
|
|
||
|
process.stdout = require('browser-stdout')({level: false});
|
||
|
|
||
|
var Mocha = require('./lib/mocha');
|
||
|
|
||
|
/**
|
||
|
* Create a Mocha instance.
|
||
|
*
|
||
|
* @return {undefined}
|
||
|
*/
|
||
|
|
||
|
var mocha = new Mocha({reporter: 'html'});
|
||
|
|
||
|
/**
|
||
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
||
|
*/
|
||
|
|
||
|
var Date = global.Date;
|
||
|
var setTimeout = global.setTimeout;
|
||
|
var setInterval = global.setInterval;
|
||
|
var clearTimeout = global.clearTimeout;
|
||
|
var clearInterval = global.clearInterval;
|
||
|
|
||
|
var uncaughtExceptionHandlers = [];
|
||
|
|
||
|
var originalOnerrorHandler = global.onerror;
|
||
|
|
||
|
/**
|
||
|
* Remove uncaughtException listener.
|
||
|
* Revert to original onerror handler if previously defined.
|
||
|
*/
|
||
|
|
||
|
process.removeListener = function(e, fn) {
|
||
|
if (e === 'uncaughtException') {
|
||
|
if (originalOnerrorHandler) {
|
||
|
global.onerror = originalOnerrorHandler;
|
||
|
} else {
|
||
|
global.onerror = function() {};
|
||
|
}
|
||
|
var i = uncaughtExceptionHandlers.indexOf(fn);
|
||
|
if (i !== -1) {
|
||
|
uncaughtExceptionHandlers.splice(i, 1);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Implements uncaughtException listener.
|
||
|
*/
|
||
|
|
||
|
process.on = function(e, fn) {
|
||
|
if (e === 'uncaughtException') {
|
||
|
global.onerror = function(err, url, line) {
|
||
|
fn(new Error(err + ' (' + url + ':' + line + ')'));
|
||
|
return !mocha.allowUncaught;
|
||
|
};
|
||
|
uncaughtExceptionHandlers.push(fn);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// The BDD UI is registered by default, but no UI will be functional in the
|
||
|
// browser without an explicit call to the overridden `mocha.ui` (see below).
|
||
|
// Ensure that this default UI does not expose its methods to the global scope.
|
||
|
mocha.suite.removeAllListeners('pre-require');
|
||
|
|
||
|
var immediateQueue = [];
|
||
|
var immediateTimeout;
|
||
|
|
||
|
function timeslice() {
|
||
|
var immediateStart = new Date().getTime();
|
||
|
while (immediateQueue.length && new Date().getTime() - immediateStart < 100) {
|
||
|
immediateQueue.shift()();
|
||
|
}
|
||
|
if (immediateQueue.length) {
|
||
|
immediateTimeout = setTimeout(timeslice, 0);
|
||
|
} else {
|
||
|
immediateTimeout = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* High-performance override of Runner.immediately.
|
||
|
*/
|
||
|
|
||
|
Mocha.Runner.immediately = function(callback) {
|
||
|
immediateQueue.push(callback);
|
||
|
if (!immediateTimeout) {
|
||
|
immediateTimeout = setTimeout(timeslice, 0);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Function to allow assertion libraries to throw errors directly into mocha.
|
||
|
* This is useful when running tests in a browser because window.onerror will
|
||
|
* only receive the 'message' attribute of the Error.
|
||
|
*/
|
||
|
mocha.throwError = function(err) {
|
||
|
uncaughtExceptionHandlers.forEach(function(fn) {
|
||
|
fn(err);
|
||
|
});
|
||
|
throw err;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Override ui to ensure that the ui functions are initialized.
|
||
|
* Normally this would happen in Mocha.prototype.loadFiles.
|
||
|
*/
|
||
|
|
||
|
mocha.ui = function(ui) {
|
||
|
Mocha.prototype.ui.call(this, ui);
|
||
|
this.suite.emit('pre-require', global, null, this);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Setup mocha with the given setting options.
|
||
|
*/
|
||
|
|
||
|
mocha.setup = function(opts) {
|
||
|
if (typeof opts === 'string') {
|
||
|
opts = {ui: opts};
|
||
|
}
|
||
|
for (var opt in opts) {
|
||
|
if (opts.hasOwnProperty(opt)) {
|
||
|
this[opt](opts[opt]);
|
||
|
}
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run mocha, returning the Runner.
|
||
|
*/
|
||
|
|
||
|
mocha.run = function(fn) {
|
||
|
var options = mocha.options;
|
||
|
mocha.globals('location');
|
||
|
|
||
|
var query = Mocha.utils.parseQuery(global.location.search || '');
|
||
|
if (query.grep) {
|
||
|
mocha.grep(query.grep);
|
||
|
}
|
||
|
if (query.fgrep) {
|
||
|
mocha.fgrep(query.fgrep);
|
||
|
}
|
||
|
if (query.invert) {
|
||
|
mocha.invert();
|
||
|
}
|
||
|
|
||
|
return Mocha.prototype.run.call(mocha, function(err) {
|
||
|
// The DOM Document is not available in Web Workers.
|
||
|
var document = global.document;
|
||
|
if (
|
||
|
document &&
|
||
|
document.getElementById('mocha') &&
|
||
|
options.noHighlighting !== true
|
||
|
) {
|
||
|
Mocha.utils.highlightTags('code');
|
||
|
}
|
||
|
if (fn) {
|
||
|
fn(err);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Expose the process shim.
|
||
|
* https://github.com/mochajs/mocha/pull/916
|
||
|
*/
|
||
|
|
||
|
Mocha.process = process;
|
||
|
|
||
|
/**
|
||
|
* Expose mocha.
|
||
|
*/
|
||
|
|
||
|
global.Mocha = Mocha;
|
||
|
global.mocha = mocha;
|
||
|
|
||
|
// this allows test/acceptance/required-tokens.js to pass; thus,
|
||
|
// you can now do `const describe = require('mocha').describe` in a
|
||
|
// browser context (assuming browserification). should fix #880
|
||
|
module.exports = global;
|
||
|
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"./lib/mocha":13,"_process":56,"browser-stdout":39}],2:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
// just stub out growl
|
||
|
|
||
|
module.exports = require('../utils').noop;
|
||
|
|
||
|
},{"../utils":36}],3:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Expose `Progress`.
|
||
|
*/
|
||
|
|
||
|
module.exports = Progress;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Progress` indicator.
|
||
|
*/
|
||
|
function Progress() {
|
||
|
this.percent = 0;
|
||
|
this.size(0);
|
||
|
this.fontSize(11);
|
||
|
this.font('helvetica, arial, sans-serif');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Set progress size to `size`.
|
||
|
*
|
||
|
* @api public
|
||
|
* @param {number} size
|
||
|
* @return {Progress} Progress instance.
|
||
|
*/
|
||
|
Progress.prototype.size = function(size) {
|
||
|
this._size = size;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set text to `text`.
|
||
|
*
|
||
|
* @api public
|
||
|
* @param {string} text
|
||
|
* @return {Progress} Progress instance.
|
||
|
*/
|
||
|
Progress.prototype.text = function(text) {
|
||
|
this._text = text;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set font size to `size`.
|
||
|
*
|
||
|
* @api public
|
||
|
* @param {number} size
|
||
|
* @return {Progress} Progress instance.
|
||
|
*/
|
||
|
Progress.prototype.fontSize = function(size) {
|
||
|
this._fontSize = size;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set font to `family`.
|
||
|
*
|
||
|
* @param {string} family
|
||
|
* @return {Progress} Progress instance.
|
||
|
*/
|
||
|
Progress.prototype.font = function(family) {
|
||
|
this._font = family;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Update percentage to `n`.
|
||
|
*
|
||
|
* @param {number} n
|
||
|
* @return {Progress} Progress instance.
|
||
|
*/
|
||
|
Progress.prototype.update = function(n) {
|
||
|
this.percent = n;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Draw on `ctx`.
|
||
|
*
|
||
|
* @param {CanvasRenderingContext2d} ctx
|
||
|
* @return {Progress} Progress instance.
|
||
|
*/
|
||
|
Progress.prototype.draw = function(ctx) {
|
||
|
try {
|
||
|
var percent = Math.min(this.percent, 100);
|
||
|
var size = this._size;
|
||
|
var half = size / 2;
|
||
|
var x = half;
|
||
|
var y = half;
|
||
|
var rad = half - 1;
|
||
|
var fontSize = this._fontSize;
|
||
|
|
||
|
ctx.font = fontSize + 'px ' + this._font;
|
||
|
|
||
|
var angle = Math.PI * 2 * (percent / 100);
|
||
|
ctx.clearRect(0, 0, size, size);
|
||
|
|
||
|
// outer circle
|
||
|
ctx.strokeStyle = '#9f9f9f';
|
||
|
ctx.beginPath();
|
||
|
ctx.arc(x, y, rad, 0, angle, false);
|
||
|
ctx.stroke();
|
||
|
|
||
|
// inner circle
|
||
|
ctx.strokeStyle = '#eee';
|
||
|
ctx.beginPath();
|
||
|
ctx.arc(x, y, rad - 1, 0, angle, true);
|
||
|
ctx.stroke();
|
||
|
|
||
|
// text
|
||
|
var text = this._text || (percent | 0) + '%';
|
||
|
var w = ctx.measureText(text).width;
|
||
|
|
||
|
ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
|
||
|
} catch (ignore) {
|
||
|
// don't fail if we can't render progress
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
},{}],4:[function(require,module,exports){
|
||
|
(function (global){
|
||
|
'use strict';
|
||
|
|
||
|
exports.isatty = function isatty() {
|
||
|
return true;
|
||
|
};
|
||
|
|
||
|
exports.getWindowSize = function getWindowSize() {
|
||
|
if ('innerHeight' in global) {
|
||
|
return [global.innerHeight, global.innerWidth];
|
||
|
}
|
||
|
// In a Web Worker, the DOM Window is not available.
|
||
|
return [640, 480];
|
||
|
};
|
||
|
|
||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{}],5:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Context
|
||
|
*/
|
||
|
/**
|
||
|
* Expose `Context`.
|
||
|
*/
|
||
|
|
||
|
module.exports = Context;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Context`.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
function Context() {}
|
||
|
|
||
|
/**
|
||
|
* Set or get the context `Runnable` to `runnable`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Runnable} runnable
|
||
|
* @return {Context} context
|
||
|
*/
|
||
|
Context.prototype.runnable = function(runnable) {
|
||
|
if (!arguments.length) {
|
||
|
return this._runnable;
|
||
|
}
|
||
|
this.test = this._runnable = runnable;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get test timeout `ms`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number} ms
|
||
|
* @return {Context} self
|
||
|
*/
|
||
|
Context.prototype.timeout = function(ms) {
|
||
|
if (!arguments.length) {
|
||
|
return this.runnable().timeout();
|
||
|
}
|
||
|
this.runnable().timeout(ms);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set test timeout `enabled`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {boolean} enabled
|
||
|
* @return {Context} self
|
||
|
*/
|
||
|
Context.prototype.enableTimeouts = function(enabled) {
|
||
|
if (!arguments.length) {
|
||
|
return this.runnable().enableTimeouts();
|
||
|
}
|
||
|
this.runnable().enableTimeouts(enabled);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get test slowness threshold `ms`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number} ms
|
||
|
* @return {Context} self
|
||
|
*/
|
||
|
Context.prototype.slow = function(ms) {
|
||
|
if (!arguments.length) {
|
||
|
return this.runnable().slow();
|
||
|
}
|
||
|
this.runnable().slow(ms);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Mark a test as skipped.
|
||
|
*
|
||
|
* @api private
|
||
|
* @throws Pending
|
||
|
*/
|
||
|
Context.prototype.skip = function() {
|
||
|
this.runnable().skip();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get a number of allowed retries on failed tests
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number} n
|
||
|
* @return {Context} self
|
||
|
*/
|
||
|
Context.prototype.retries = function(n) {
|
||
|
if (!arguments.length) {
|
||
|
return this.runnable().retries();
|
||
|
}
|
||
|
this.runnable().retries(n);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
},{}],6:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
var Runnable = require('./runnable');
|
||
|
var inherits = require('./utils').inherits;
|
||
|
|
||
|
/**
|
||
|
* Expose `Hook`.
|
||
|
*/
|
||
|
|
||
|
module.exports = Hook;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Hook` with the given `title` and callback `fn`
|
||
|
*
|
||
|
* @class
|
||
|
* @extends Runnable
|
||
|
* @param {String} title
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
function Hook(title, fn) {
|
||
|
Runnable.call(this, title, fn);
|
||
|
this.type = 'hook';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Runnable.prototype`.
|
||
|
*/
|
||
|
inherits(Hook, Runnable);
|
||
|
|
||
|
/**
|
||
|
* Get or set the test `err`.
|
||
|
*
|
||
|
* @memberof Hook
|
||
|
* @public
|
||
|
* @param {Error} err
|
||
|
* @return {Error}
|
||
|
*/
|
||
|
Hook.prototype.error = function(err) {
|
||
|
if (!arguments.length) {
|
||
|
err = this._error;
|
||
|
this._error = null;
|
||
|
return err;
|
||
|
}
|
||
|
|
||
|
this._error = err;
|
||
|
};
|
||
|
|
||
|
},{"./runnable":32,"./utils":36}],7:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
var Test = require('../test');
|
||
|
|
||
|
/**
|
||
|
* BDD-style interface:
|
||
|
*
|
||
|
* describe('Array', function() {
|
||
|
* describe('#indexOf()', function() {
|
||
|
* it('should return -1 when not present', function() {
|
||
|
* // ...
|
||
|
* });
|
||
|
*
|
||
|
* it('should return the index when present', function() {
|
||
|
* // ...
|
||
|
* });
|
||
|
* });
|
||
|
* });
|
||
|
*
|
||
|
* @param {Suite} suite Root suite.
|
||
|
*/
|
||
|
module.exports = function bddInterface(suite) {
|
||
|
var suites = [suite];
|
||
|
|
||
|
suite.on('pre-require', function(context, file, mocha) {
|
||
|
var common = require('./common')(suites, context, mocha);
|
||
|
|
||
|
context.before = common.before;
|
||
|
context.after = common.after;
|
||
|
context.beforeEach = common.beforeEach;
|
||
|
context.afterEach = common.afterEach;
|
||
|
context.run = mocha.options.delay && common.runWithSuite(suite);
|
||
|
/**
|
||
|
* Describe a "suite" with the given `title`
|
||
|
* and callback `fn` containing nested suites
|
||
|
* and/or tests.
|
||
|
*/
|
||
|
|
||
|
context.describe = context.context = function(title, fn) {
|
||
|
return common.suite.create({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: fn
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Pending describe.
|
||
|
*/
|
||
|
|
||
|
context.xdescribe = context.xcontext = context.describe.skip = function(
|
||
|
title,
|
||
|
fn
|
||
|
) {
|
||
|
return common.suite.skip({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: fn
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Exclusive suite.
|
||
|
*/
|
||
|
|
||
|
context.describe.only = function(title, fn) {
|
||
|
return common.suite.only({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: fn
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Describe a specification or test-case
|
||
|
* with the given `title` and callback `fn`
|
||
|
* acting as a thunk.
|
||
|
*/
|
||
|
|
||
|
context.it = context.specify = function(title, fn) {
|
||
|
var suite = suites[0];
|
||
|
if (suite.isPending()) {
|
||
|
fn = null;
|
||
|
}
|
||
|
var test = new Test(title, fn);
|
||
|
test.file = file;
|
||
|
suite.addTest(test);
|
||
|
return test;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Exclusive test-case.
|
||
|
*/
|
||
|
|
||
|
context.it.only = function(title, fn) {
|
||
|
return common.test.only(mocha, context.it(title, fn));
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Pending test case.
|
||
|
*/
|
||
|
|
||
|
context.xit = context.xspecify = context.it.skip = function(title) {
|
||
|
return context.it(title);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Number of attempts to retry.
|
||
|
*/
|
||
|
context.it.retries = function(n) {
|
||
|
context.retries(n);
|
||
|
};
|
||
|
});
|
||
|
};
|
||
|
|
||
|
},{"../test":35,"./common":8}],8:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
var Suite = require('../suite');
|
||
|
|
||
|
/**
|
||
|
* Functions common to more than one interface.
|
||
|
*
|
||
|
* @param {Suite[]} suites
|
||
|
* @param {Context} context
|
||
|
* @param {Mocha} mocha
|
||
|
* @return {Object} An object containing common functions.
|
||
|
*/
|
||
|
module.exports = function(suites, context, mocha) {
|
||
|
return {
|
||
|
/**
|
||
|
* This is only present if flag --delay is passed into Mocha. It triggers
|
||
|
* root suite execution.
|
||
|
*
|
||
|
* @param {Suite} suite The root suite.
|
||
|
* @return {Function} A function which runs the root suite
|
||
|
*/
|
||
|
runWithSuite: function runWithSuite(suite) {
|
||
|
return function run() {
|
||
|
suite.run();
|
||
|
};
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Execute before running tests.
|
||
|
*
|
||
|
* @param {string} name
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
before: function(name, fn) {
|
||
|
suites[0].beforeAll(name, fn);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Execute after running tests.
|
||
|
*
|
||
|
* @param {string} name
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
after: function(name, fn) {
|
||
|
suites[0].afterAll(name, fn);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Execute before each test case.
|
||
|
*
|
||
|
* @param {string} name
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
beforeEach: function(name, fn) {
|
||
|
suites[0].beforeEach(name, fn);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Execute after each test case.
|
||
|
*
|
||
|
* @param {string} name
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
afterEach: function(name, fn) {
|
||
|
suites[0].afterEach(name, fn);
|
||
|
},
|
||
|
|
||
|
suite: {
|
||
|
/**
|
||
|
* Create an exclusive Suite; convenience function
|
||
|
* See docstring for create() below.
|
||
|
*
|
||
|
* @param {Object} opts
|
||
|
* @returns {Suite}
|
||
|
*/
|
||
|
only: function only(opts) {
|
||
|
opts.isOnly = true;
|
||
|
return this.create(opts);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Create a Suite, but skip it; convenience function
|
||
|
* See docstring for create() below.
|
||
|
*
|
||
|
* @param {Object} opts
|
||
|
* @returns {Suite}
|
||
|
*/
|
||
|
skip: function skip(opts) {
|
||
|
opts.pending = true;
|
||
|
return this.create(opts);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Creates a suite.
|
||
|
* @param {Object} opts Options
|
||
|
* @param {string} opts.title Title of Suite
|
||
|
* @param {Function} [opts.fn] Suite Function (not always applicable)
|
||
|
* @param {boolean} [opts.pending] Is Suite pending?
|
||
|
* @param {string} [opts.file] Filepath where this Suite resides
|
||
|
* @param {boolean} [opts.isOnly] Is Suite exclusive?
|
||
|
* @returns {Suite}
|
||
|
*/
|
||
|
create: function create(opts) {
|
||
|
var suite = Suite.create(suites[0], opts.title);
|
||
|
suite.pending = Boolean(opts.pending);
|
||
|
suite.file = opts.file;
|
||
|
suites.unshift(suite);
|
||
|
if (opts.isOnly) {
|
||
|
suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
|
||
|
}
|
||
|
if (typeof opts.fn === 'function') {
|
||
|
opts.fn.call(suite);
|
||
|
suites.shift();
|
||
|
} else if (typeof opts.fn === 'undefined' && !suite.pending) {
|
||
|
throw new Error(
|
||
|
'Suite "' +
|
||
|
suite.fullTitle() +
|
||
|
'" was defined but no callback was supplied. Supply a callback or explicitly skip the suite.'
|
||
|
);
|
||
|
} else if (!opts.fn && suite.pending) {
|
||
|
suites.shift();
|
||
|
}
|
||
|
|
||
|
return suite;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
test: {
|
||
|
/**
|
||
|
* Exclusive test-case.
|
||
|
*
|
||
|
* @param {Object} mocha
|
||
|
* @param {Function} test
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
only: function(mocha, test) {
|
||
|
test.parent._onlyTests = test.parent._onlyTests.concat(test);
|
||
|
return test;
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Pending test case.
|
||
|
*
|
||
|
* @param {string} title
|
||
|
*/
|
||
|
skip: function(title) {
|
||
|
context.test(title);
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Number of retry attempts
|
||
|
*
|
||
|
* @param {number} n
|
||
|
*/
|
||
|
retries: function(n) {
|
||
|
context.retries(n);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
};
|
||
|
|
||
|
},{"../suite":34}],9:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
var Suite = require('../suite');
|
||
|
var Test = require('../test');
|
||
|
|
||
|
/**
|
||
|
* Exports-style (as Node.js module) interface:
|
||
|
*
|
||
|
* exports.Array = {
|
||
|
* '#indexOf()': {
|
||
|
* 'should return -1 when the value is not present': function() {
|
||
|
*
|
||
|
* },
|
||
|
*
|
||
|
* 'should return the correct index when the value is present': function() {
|
||
|
*
|
||
|
* }
|
||
|
* }
|
||
|
* };
|
||
|
*
|
||
|
* @param {Suite} suite Root suite.
|
||
|
*/
|
||
|
module.exports = function(suite) {
|
||
|
var suites = [suite];
|
||
|
|
||
|
suite.on('require', visit);
|
||
|
|
||
|
function visit(obj, file) {
|
||
|
var suite;
|
||
|
for (var key in obj) {
|
||
|
if (typeof obj[key] === 'function') {
|
||
|
var fn = obj[key];
|
||
|
switch (key) {
|
||
|
case 'before':
|
||
|
suites[0].beforeAll(fn);
|
||
|
break;
|
||
|
case 'after':
|
||
|
suites[0].afterAll(fn);
|
||
|
break;
|
||
|
case 'beforeEach':
|
||
|
suites[0].beforeEach(fn);
|
||
|
break;
|
||
|
case 'afterEach':
|
||
|
suites[0].afterEach(fn);
|
||
|
break;
|
||
|
default:
|
||
|
var test = new Test(key, fn);
|
||
|
test.file = file;
|
||
|
suites[0].addTest(test);
|
||
|
}
|
||
|
} else {
|
||
|
suite = Suite.create(suites[0], key);
|
||
|
suites.unshift(suite);
|
||
|
visit(obj[key], file);
|
||
|
suites.shift();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
},{"../suite":34,"../test":35}],10:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
exports.bdd = require('./bdd');
|
||
|
exports.tdd = require('./tdd');
|
||
|
exports.qunit = require('./qunit');
|
||
|
exports.exports = require('./exports');
|
||
|
|
||
|
},{"./bdd":7,"./exports":9,"./qunit":11,"./tdd":12}],11:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
var Test = require('../test');
|
||
|
|
||
|
/**
|
||
|
* QUnit-style interface:
|
||
|
*
|
||
|
* suite('Array');
|
||
|
*
|
||
|
* test('#length', function() {
|
||
|
* var arr = [1,2,3];
|
||
|
* ok(arr.length == 3);
|
||
|
* });
|
||
|
*
|
||
|
* test('#indexOf()', function() {
|
||
|
* var arr = [1,2,3];
|
||
|
* ok(arr.indexOf(1) == 0);
|
||
|
* ok(arr.indexOf(2) == 1);
|
||
|
* ok(arr.indexOf(3) == 2);
|
||
|
* });
|
||
|
*
|
||
|
* suite('String');
|
||
|
*
|
||
|
* test('#length', function() {
|
||
|
* ok('foo'.length == 3);
|
||
|
* });
|
||
|
*
|
||
|
* @param {Suite} suite Root suite.
|
||
|
*/
|
||
|
module.exports = function qUnitInterface(suite) {
|
||
|
var suites = [suite];
|
||
|
|
||
|
suite.on('pre-require', function(context, file, mocha) {
|
||
|
var common = require('./common')(suites, context, mocha);
|
||
|
|
||
|
context.before = common.before;
|
||
|
context.after = common.after;
|
||
|
context.beforeEach = common.beforeEach;
|
||
|
context.afterEach = common.afterEach;
|
||
|
context.run = mocha.options.delay && common.runWithSuite(suite);
|
||
|
/**
|
||
|
* Describe a "suite" with the given `title`.
|
||
|
*/
|
||
|
|
||
|
context.suite = function(title) {
|
||
|
if (suites.length > 1) {
|
||
|
suites.shift();
|
||
|
}
|
||
|
return common.suite.create({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: false
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Exclusive Suite.
|
||
|
*/
|
||
|
|
||
|
context.suite.only = function(title) {
|
||
|
if (suites.length > 1) {
|
||
|
suites.shift();
|
||
|
}
|
||
|
return common.suite.only({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: false
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Describe a specification or test-case
|
||
|
* with the given `title` and callback `fn`
|
||
|
* acting as a thunk.
|
||
|
*/
|
||
|
|
||
|
context.test = function(title, fn) {
|
||
|
var test = new Test(title, fn);
|
||
|
test.file = file;
|
||
|
suites[0].addTest(test);
|
||
|
return test;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Exclusive test-case.
|
||
|
*/
|
||
|
|
||
|
context.test.only = function(title, fn) {
|
||
|
return common.test.only(mocha, context.test(title, fn));
|
||
|
};
|
||
|
|
||
|
context.test.skip = common.test.skip;
|
||
|
context.test.retries = common.test.retries;
|
||
|
});
|
||
|
};
|
||
|
|
||
|
},{"../test":35,"./common":8}],12:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
var Test = require('../test');
|
||
|
|
||
|
/**
|
||
|
* TDD-style interface:
|
||
|
*
|
||
|
* suite('Array', function() {
|
||
|
* suite('#indexOf()', function() {
|
||
|
* suiteSetup(function() {
|
||
|
*
|
||
|
* });
|
||
|
*
|
||
|
* test('should return -1 when not present', function() {
|
||
|
*
|
||
|
* });
|
||
|
*
|
||
|
* test('should return the index when present', function() {
|
||
|
*
|
||
|
* });
|
||
|
*
|
||
|
* suiteTeardown(function() {
|
||
|
*
|
||
|
* });
|
||
|
* });
|
||
|
* });
|
||
|
*
|
||
|
* @param {Suite} suite Root suite.
|
||
|
*/
|
||
|
module.exports = function(suite) {
|
||
|
var suites = [suite];
|
||
|
|
||
|
suite.on('pre-require', function(context, file, mocha) {
|
||
|
var common = require('./common')(suites, context, mocha);
|
||
|
|
||
|
context.setup = common.beforeEach;
|
||
|
context.teardown = common.afterEach;
|
||
|
context.suiteSetup = common.before;
|
||
|
context.suiteTeardown = common.after;
|
||
|
context.run = mocha.options.delay && common.runWithSuite(suite);
|
||
|
|
||
|
/**
|
||
|
* Describe a "suite" with the given `title` and callback `fn` containing
|
||
|
* nested suites and/or tests.
|
||
|
*/
|
||
|
context.suite = function(title, fn) {
|
||
|
return common.suite.create({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: fn
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Pending suite.
|
||
|
*/
|
||
|
context.suite.skip = function(title, fn) {
|
||
|
return common.suite.skip({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: fn
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Exclusive test-case.
|
||
|
*/
|
||
|
context.suite.only = function(title, fn) {
|
||
|
return common.suite.only({
|
||
|
title: title,
|
||
|
file: file,
|
||
|
fn: fn
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Describe a specification or test-case with the given `title` and
|
||
|
* callback `fn` acting as a thunk.
|
||
|
*/
|
||
|
context.test = function(title, fn) {
|
||
|
var suite = suites[0];
|
||
|
if (suite.isPending()) {
|
||
|
fn = null;
|
||
|
}
|
||
|
var test = new Test(title, fn);
|
||
|
test.file = file;
|
||
|
suite.addTest(test);
|
||
|
return test;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Exclusive test-case.
|
||
|
*/
|
||
|
|
||
|
context.test.only = function(title, fn) {
|
||
|
return common.test.only(mocha, context.test(title, fn));
|
||
|
};
|
||
|
|
||
|
context.test.skip = common.test.skip;
|
||
|
context.test.retries = common.test.retries;
|
||
|
});
|
||
|
};
|
||
|
|
||
|
},{"../test":35,"./common":8}],13:[function(require,module,exports){
|
||
|
(function (process,global,__dirname){
|
||
|
'use strict';
|
||
|
|
||
|
/*!
|
||
|
* mocha
|
||
|
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
||
|
* MIT Licensed
|
||
|
*/
|
||
|
|
||
|
var escapeRe = require('escape-string-regexp');
|
||
|
var path = require('path');
|
||
|
var reporters = require('./reporters');
|
||
|
var utils = require('./utils');
|
||
|
|
||
|
exports = module.exports = Mocha;
|
||
|
|
||
|
/**
|
||
|
* To require local UIs and reporters when running in node.
|
||
|
*/
|
||
|
|
||
|
if (!process.browser) {
|
||
|
var cwd = process.cwd();
|
||
|
module.paths.push(cwd, path.join(cwd, 'node_modules'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Expose internals.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @public
|
||
|
* @class utils
|
||
|
* @memberof Mocha
|
||
|
*/
|
||
|
exports.utils = utils;
|
||
|
exports.interfaces = require('./interfaces');
|
||
|
/**
|
||
|
*
|
||
|
* @memberof Mocha
|
||
|
* @public
|
||
|
*/
|
||
|
exports.reporters = reporters;
|
||
|
exports.Runnable = require('./runnable');
|
||
|
exports.Context = require('./context');
|
||
|
/**
|
||
|
*
|
||
|
* @memberof Mocha
|
||
|
*/
|
||
|
exports.Runner = require('./runner');
|
||
|
exports.Suite = require('./suite');
|
||
|
exports.Hook = require('./hook');
|
||
|
exports.Test = require('./test');
|
||
|
|
||
|
/**
|
||
|
* Return image `name` path.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} name
|
||
|
* @return {string}
|
||
|
*/
|
||
|
function image(name) {
|
||
|
return path.join(__dirname, '..', 'assets', 'growl', name + '.png');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Set up mocha with `options`.
|
||
|
*
|
||
|
* Options:
|
||
|
*
|
||
|
* - `ui` name "bdd", "tdd", "exports" etc
|
||
|
* - `reporter` reporter instance, defaults to `mocha.reporters.spec`
|
||
|
* - `globals` array of accepted globals
|
||
|
* - `timeout` timeout in milliseconds
|
||
|
* - `retries` number of times to retry failed tests
|
||
|
* - `bail` bail on the first test failure
|
||
|
* - `slow` milliseconds to wait before considering a test slow
|
||
|
* - `ignoreLeaks` ignore global leaks
|
||
|
* - `fullTrace` display the full stack-trace on failing
|
||
|
* - `grep` string or regexp to filter tests with
|
||
|
*
|
||
|
* @class Mocha
|
||
|
* @param {Object} options
|
||
|
*/
|
||
|
function Mocha(options) {
|
||
|
options = options || {};
|
||
|
this.files = [];
|
||
|
this.options = options;
|
||
|
if (options.grep) {
|
||
|
this.grep(new RegExp(options.grep));
|
||
|
}
|
||
|
if (options.fgrep) {
|
||
|
this.fgrep(options.fgrep);
|
||
|
}
|
||
|
this.suite = new exports.Suite('', new exports.Context());
|
||
|
this.ui(options.ui);
|
||
|
this.bail(options.bail);
|
||
|
this.reporter(options.reporter, options.reporterOptions);
|
||
|
if (typeof options.timeout !== 'undefined' && options.timeout !== null) {
|
||
|
this.timeout(options.timeout);
|
||
|
}
|
||
|
if (typeof options.retries !== 'undefined' && options.retries !== null) {
|
||
|
this.retries(options.retries);
|
||
|
}
|
||
|
this.useColors(options.useColors);
|
||
|
if (options.enableTimeouts !== null) {
|
||
|
this.enableTimeouts(options.enableTimeouts);
|
||
|
}
|
||
|
if (options.slow) {
|
||
|
this.slow(options.slow);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Enable or disable bailing on the first failure.
|
||
|
*
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {boolean} [bail]
|
||
|
*/
|
||
|
Mocha.prototype.bail = function(bail) {
|
||
|
if (!arguments.length) {
|
||
|
bail = true;
|
||
|
}
|
||
|
this.suite.bail(bail);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Add test `file`.
|
||
|
*
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {string} file
|
||
|
*/
|
||
|
Mocha.prototype.addFile = function(file) {
|
||
|
this.files.push(file);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set reporter to `reporter`, defaults to "spec".
|
||
|
*
|
||
|
* @public
|
||
|
* @param {String|Function} reporter name or constructor
|
||
|
* @param {Object} reporterOptions optional options
|
||
|
* @api public
|
||
|
* @param {string|Function} reporter name or constructor
|
||
|
* @param {Object} reporterOptions optional options
|
||
|
*/
|
||
|
Mocha.prototype.reporter = function(reporter, reporterOptions) {
|
||
|
if (typeof reporter === 'function') {
|
||
|
this._reporter = reporter;
|
||
|
} else {
|
||
|
reporter = reporter || 'spec';
|
||
|
var _reporter;
|
||
|
// Try to load a built-in reporter.
|
||
|
if (reporters[reporter]) {
|
||
|
_reporter = reporters[reporter];
|
||
|
}
|
||
|
// Try to load reporters from process.cwd() and node_modules
|
||
|
if (!_reporter) {
|
||
|
try {
|
||
|
_reporter = require(reporter);
|
||
|
} catch (err) {
|
||
|
if (err.message.indexOf('Cannot find module') !== -1) {
|
||
|
// Try to load reporters from a path (absolute or relative)
|
||
|
try {
|
||
|
_reporter = require(path.resolve(process.cwd(), reporter));
|
||
|
} catch (_err) {
|
||
|
err.message.indexOf('Cannot find module') !== -1
|
||
|
? console.warn('"' + reporter + '" reporter not found')
|
||
|
: console.warn(
|
||
|
'"' +
|
||
|
reporter +
|
||
|
'" reporter blew up with error:\n' +
|
||
|
err.stack
|
||
|
);
|
||
|
}
|
||
|
} else {
|
||
|
console.warn(
|
||
|
'"' + reporter + '" reporter blew up with error:\n' + err.stack
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!_reporter && reporter === 'teamcity') {
|
||
|
console.warn(
|
||
|
'The Teamcity reporter was moved to a package named ' +
|
||
|
'mocha-teamcity-reporter ' +
|
||
|
'(https://npmjs.org/package/mocha-teamcity-reporter).'
|
||
|
);
|
||
|
}
|
||
|
if (!_reporter) {
|
||
|
throw new Error('invalid reporter "' + reporter + '"');
|
||
|
}
|
||
|
this._reporter = _reporter;
|
||
|
}
|
||
|
this.options.reporterOptions = reporterOptions;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set test UI `name`, defaults to "bdd".
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {string} bdd
|
||
|
*/
|
||
|
Mocha.prototype.ui = function(name) {
|
||
|
name = name || 'bdd';
|
||
|
this._ui = exports.interfaces[name];
|
||
|
if (!this._ui) {
|
||
|
try {
|
||
|
this._ui = require(name);
|
||
|
} catch (err) {
|
||
|
throw new Error('invalid interface "' + name + '"');
|
||
|
}
|
||
|
}
|
||
|
this._ui = this._ui(this.suite);
|
||
|
|
||
|
this.suite.on('pre-require', function(context) {
|
||
|
exports.afterEach = context.afterEach || context.teardown;
|
||
|
exports.after = context.after || context.suiteTeardown;
|
||
|
exports.beforeEach = context.beforeEach || context.setup;
|
||
|
exports.before = context.before || context.suiteSetup;
|
||
|
exports.describe = context.describe || context.suite;
|
||
|
exports.it = context.it || context.test;
|
||
|
exports.xit = context.xit || context.test.skip;
|
||
|
exports.setup = context.setup || context.beforeEach;
|
||
|
exports.suiteSetup = context.suiteSetup || context.before;
|
||
|
exports.suiteTeardown = context.suiteTeardown || context.after;
|
||
|
exports.suite = context.suite || context.describe;
|
||
|
exports.teardown = context.teardown || context.afterEach;
|
||
|
exports.test = context.test || context.it;
|
||
|
exports.run = context.run;
|
||
|
});
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Load registered files.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Mocha.prototype.loadFiles = function(fn) {
|
||
|
var self = this;
|
||
|
var suite = this.suite;
|
||
|
this.files.forEach(function(file) {
|
||
|
file = path.resolve(file);
|
||
|
suite.emit('pre-require', global, file, self);
|
||
|
suite.emit('require', require(file), file, self);
|
||
|
suite.emit('post-require', global, file, self);
|
||
|
});
|
||
|
fn && fn();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Enable growl support.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Mocha.prototype._growl = function(runner, reporter) {
|
||
|
var notify = require('growl');
|
||
|
|
||
|
runner.on('end', function() {
|
||
|
var stats = reporter.stats;
|
||
|
if (stats.failures) {
|
||
|
var msg = stats.failures + ' of ' + runner.total + ' tests failed';
|
||
|
notify(msg, {name: 'mocha', title: 'Failed', image: image('error')});
|
||
|
} else {
|
||
|
notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
|
||
|
name: 'mocha',
|
||
|
title: 'Passed',
|
||
|
image: image('ok')
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Escape string and add it to grep as a regexp.
|
||
|
*
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param str
|
||
|
* @returns {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.fgrep = function(str) {
|
||
|
return this.grep(new RegExp(escapeRe(str)));
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Add regexp to grep, if `re` is a string it is escaped.
|
||
|
*
|
||
|
* @public
|
||
|
* @param {RegExp|String} re
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @param {RegExp|string} re
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.grep = function(re) {
|
||
|
if (utils.isString(re)) {
|
||
|
// extract args if it's regex-like, i.e: [string, pattern, flag]
|
||
|
var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
|
||
|
this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
|
||
|
} else {
|
||
|
this.options.grep = re;
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
/**
|
||
|
* Invert `.grep()` matches.
|
||
|
*
|
||
|
* @public
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
*/
|
||
|
Mocha.prototype.invert = function() {
|
||
|
this.options.invert = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Ignore global leaks.
|
||
|
*
|
||
|
* @public
|
||
|
* @param {Boolean} ignore
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @param {boolean} ignore
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.ignoreLeaks = function(ignore) {
|
||
|
this.options.ignoreLeaks = Boolean(ignore);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Enable global leak checking.
|
||
|
*
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.checkLeaks = function() {
|
||
|
this.options.ignoreLeaks = false;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Display long stack-trace on failing
|
||
|
*
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.fullTrace = function() {
|
||
|
this.options.fullStackTrace = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Enable growl support.
|
||
|
*
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.growl = function() {
|
||
|
this.options.growl = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Ignore `globals` array or string.
|
||
|
*
|
||
|
* @param {Array|String} globals
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {Array|string} globals
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.globals = function(globals) {
|
||
|
this.options.globals = (this.options.globals || []).concat(globals);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Emit color output.
|
||
|
*
|
||
|
* @param {Boolean} colors
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {boolean} colors
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.useColors = function(colors) {
|
||
|
if (colors !== undefined) {
|
||
|
this.options.useColors = colors;
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Use inline diffs rather than +/-.
|
||
|
*
|
||
|
* @param {Boolean} inlineDiffs
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {boolean} inlineDiffs
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
|
||
|
this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Do not show diffs at all.
|
||
|
*
|
||
|
* @param {Boolean} hideDiff
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {boolean} hideDiff
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.hideDiff = function(hideDiff) {
|
||
|
this.options.hideDiff = hideDiff !== undefined && hideDiff;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set the timeout in milliseconds.
|
||
|
*
|
||
|
* @param {Number} timeout
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {number} timeout
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.timeout = function(timeout) {
|
||
|
this.suite.timeout(timeout);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set the number of times to retry failed tests.
|
||
|
*
|
||
|
* @param {Number} retry times
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.retries = function(n) {
|
||
|
this.suite.retries(n);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set slowness threshold in milliseconds.
|
||
|
*
|
||
|
* @param {Number} slow
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {number} slow
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.slow = function(slow) {
|
||
|
this.suite.slow(slow);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Enable timeouts.
|
||
|
*
|
||
|
* @param {Boolean} enabled
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {boolean} enabled
|
||
|
* @return {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.enableTimeouts = function(enabled) {
|
||
|
this.suite.enableTimeouts(
|
||
|
arguments.length && enabled !== undefined ? enabled : true
|
||
|
);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Makes all tests async (accepting a callback)
|
||
|
*
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.asyncOnly = function() {
|
||
|
this.options.asyncOnly = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Disable syntax highlighting (in browser).
|
||
|
*
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.noHighlighting = function() {
|
||
|
this.options.noHighlighting = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Enable uncaught errors to propagate (in browser).
|
||
|
*
|
||
|
* @return {Mocha}
|
||
|
* @api public
|
||
|
* @public
|
||
|
*/
|
||
|
Mocha.prototype.allowUncaught = function() {
|
||
|
this.options.allowUncaught = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Delay root suite execution.
|
||
|
* @returns {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.delay = function delay() {
|
||
|
this.options.delay = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Tests marked only fail the suite
|
||
|
* @returns {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.forbidOnly = function() {
|
||
|
this.options.forbidOnly = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Pending tests and tests marked skip fail the suite
|
||
|
* @returns {Mocha}
|
||
|
*/
|
||
|
Mocha.prototype.forbidPending = function() {
|
||
|
this.options.forbidPending = true;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run tests and invoke `fn()` when complete.
|
||
|
*
|
||
|
* Note that `loadFiles` relies on Node's `require` to execute
|
||
|
* the test interface functions and will be subject to the
|
||
|
* cache - if the files are already in the `require` cache,
|
||
|
* they will effectively be skipped. Therefore, to run tests
|
||
|
* multiple times or to run tests in files that are already
|
||
|
* in the `require` cache, make sure to clear them from the
|
||
|
* cache first in whichever manner best suits your needs.
|
||
|
*
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {Function} fn
|
||
|
* @return {Runner}
|
||
|
*/
|
||
|
Mocha.prototype.run = function(fn) {
|
||
|
if (this.files.length) {
|
||
|
this.loadFiles();
|
||
|
}
|
||
|
var suite = this.suite;
|
||
|
var options = this.options;
|
||
|
options.files = this.files;
|
||
|
var runner = new exports.Runner(suite, options.delay);
|
||
|
var reporter = new this._reporter(runner, options);
|
||
|
runner.ignoreLeaks = options.ignoreLeaks !== false;
|
||
|
runner.fullStackTrace = options.fullStackTrace;
|
||
|
runner.asyncOnly = options.asyncOnly;
|
||
|
runner.allowUncaught = options.allowUncaught;
|
||
|
runner.forbidOnly = options.forbidOnly;
|
||
|
runner.forbidPending = options.forbidPending;
|
||
|
if (options.grep) {
|
||
|
runner.grep(options.grep, options.invert);
|
||
|
}
|
||
|
if (options.globals) {
|
||
|
runner.globals(options.globals);
|
||
|
}
|
||
|
if (options.growl) {
|
||
|
this._growl(runner, reporter);
|
||
|
}
|
||
|
if (options.useColors !== undefined) {
|
||
|
exports.reporters.Base.useColors = options.useColors;
|
||
|
}
|
||
|
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
|
||
|
exports.reporters.Base.hideDiff = options.hideDiff;
|
||
|
|
||
|
function done(failures) {
|
||
|
if (reporter.done) {
|
||
|
reporter.done(failures, fn);
|
||
|
} else {
|
||
|
fn && fn(failures);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return runner.run(done);
|
||
|
};
|
||
|
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/lib")
|
||
|
},{"./context":5,"./hook":6,"./interfaces":10,"./reporters":20,"./runnable":32,"./runner":33,"./suite":34,"./test":35,"./utils":36,"_process":56,"escape-string-regexp":46,"growl":2,"path":40}],14:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module milliseconds
|
||
|
*/
|
||
|
/**
|
||
|
* Helpers.
|
||
|
*/
|
||
|
|
||
|
var s = 1000;
|
||
|
var m = s * 60;
|
||
|
var h = m * 60;
|
||
|
var d = h * 24;
|
||
|
var y = d * 365.25;
|
||
|
|
||
|
/**
|
||
|
* Parse or format the given `val`.
|
||
|
*
|
||
|
* @memberof Mocha
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {string|number} val
|
||
|
* @return {string|number}
|
||
|
*/
|
||
|
module.exports = function(val) {
|
||
|
if (typeof val === 'string') {
|
||
|
return parse(val);
|
||
|
}
|
||
|
return format(val);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Parse the given `str` and return milliseconds.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} str
|
||
|
* @return {number}
|
||
|
*/
|
||
|
function parse(str) {
|
||
|
var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(
|
||
|
str
|
||
|
);
|
||
|
if (!match) {
|
||
|
return;
|
||
|
}
|
||
|
var n = parseFloat(match[1]);
|
||
|
var type = (match[2] || 'ms').toLowerCase();
|
||
|
switch (type) {
|
||
|
case 'years':
|
||
|
case 'year':
|
||
|
case 'y':
|
||
|
return n * y;
|
||
|
case 'days':
|
||
|
case 'day':
|
||
|
case 'd':
|
||
|
return n * d;
|
||
|
case 'hours':
|
||
|
case 'hour':
|
||
|
case 'h':
|
||
|
return n * h;
|
||
|
case 'minutes':
|
||
|
case 'minute':
|
||
|
case 'm':
|
||
|
return n * m;
|
||
|
case 'seconds':
|
||
|
case 'second':
|
||
|
case 's':
|
||
|
return n * s;
|
||
|
case 'ms':
|
||
|
return n;
|
||
|
default:
|
||
|
// No default case
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Format for `ms`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number} ms
|
||
|
* @return {string}
|
||
|
*/
|
||
|
function format(ms) {
|
||
|
if (ms >= d) {
|
||
|
return Math.round(ms / d) + 'd';
|
||
|
}
|
||
|
if (ms >= h) {
|
||
|
return Math.round(ms / h) + 'h';
|
||
|
}
|
||
|
if (ms >= m) {
|
||
|
return Math.round(ms / m) + 'm';
|
||
|
}
|
||
|
if (ms >= s) {
|
||
|
return Math.round(ms / s) + 's';
|
||
|
}
|
||
|
return ms + 'ms';
|
||
|
}
|
||
|
|
||
|
},{}],15:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
module.exports = Pending;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Pending` error with the given message.
|
||
|
*
|
||
|
* @param {string} message
|
||
|
*/
|
||
|
function Pending(message) {
|
||
|
this.message = message;
|
||
|
}
|
||
|
|
||
|
},{}],16:[function(require,module,exports){
|
||
|
(function (process,global){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Base
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var tty = require('tty');
|
||
|
var diff = require('diff');
|
||
|
var ms = require('../ms');
|
||
|
var utils = require('../utils');
|
||
|
var supportsColor = process.browser ? null : require('supports-color');
|
||
|
|
||
|
/**
|
||
|
* Expose `Base`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Base;
|
||
|
|
||
|
/**
|
||
|
* Save timer references to avoid Sinon interfering.
|
||
|
* See: https://github.com/mochajs/mocha/issues/237
|
||
|
*/
|
||
|
|
||
|
/* eslint-disable no-unused-vars, no-native-reassign */
|
||
|
var Date = global.Date;
|
||
|
var setTimeout = global.setTimeout;
|
||
|
var setInterval = global.setInterval;
|
||
|
var clearTimeout = global.clearTimeout;
|
||
|
var clearInterval = global.clearInterval;
|
||
|
/* eslint-enable no-unused-vars, no-native-reassign */
|
||
|
|
||
|
/**
|
||
|
* Check if both stdio streams are associated with a tty.
|
||
|
*/
|
||
|
|
||
|
var isatty = tty.isatty(1) && tty.isatty(2);
|
||
|
|
||
|
/**
|
||
|
* Enable coloring by default, except in the browser interface.
|
||
|
*/
|
||
|
|
||
|
exports.useColors =
|
||
|
!process.browser &&
|
||
|
(supportsColor.stdout || process.env.MOCHA_COLORS !== undefined);
|
||
|
|
||
|
/**
|
||
|
* Inline diffs instead of +/-
|
||
|
*/
|
||
|
|
||
|
exports.inlineDiffs = false;
|
||
|
|
||
|
/**
|
||
|
* Default color map.
|
||
|
*/
|
||
|
|
||
|
exports.colors = {
|
||
|
pass: 90,
|
||
|
fail: 31,
|
||
|
'bright pass': 92,
|
||
|
'bright fail': 91,
|
||
|
'bright yellow': 93,
|
||
|
pending: 36,
|
||
|
suite: 0,
|
||
|
'error title': 0,
|
||
|
'error message': 31,
|
||
|
'error stack': 90,
|
||
|
checkmark: 32,
|
||
|
fast: 90,
|
||
|
medium: 33,
|
||
|
slow: 31,
|
||
|
green: 32,
|
||
|
light: 90,
|
||
|
'diff gutter': 90,
|
||
|
'diff added': 32,
|
||
|
'diff removed': 31
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Default symbol map.
|
||
|
*/
|
||
|
|
||
|
exports.symbols = {
|
||
|
ok: '✓',
|
||
|
err: '✖',
|
||
|
dot: '․',
|
||
|
comma: ',',
|
||
|
bang: '!'
|
||
|
};
|
||
|
|
||
|
// With node.js on Windows: use symbols available in terminal default fonts
|
||
|
if (process.platform === 'win32') {
|
||
|
exports.symbols.ok = '\u221A';
|
||
|
exports.symbols.err = '\u00D7';
|
||
|
exports.symbols.dot = '.';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Color `str` with the given `type`,
|
||
|
* allowing colors to be disabled,
|
||
|
* as well as user-defined color
|
||
|
* schemes.
|
||
|
*
|
||
|
* @param {string} type
|
||
|
* @param {string} str
|
||
|
* @return {string}
|
||
|
* @api private
|
||
|
*/
|
||
|
var color = (exports.color = function(type, str) {
|
||
|
if (!exports.useColors) {
|
||
|
return String(str);
|
||
|
}
|
||
|
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Expose term window size, with some defaults for when stderr is not a tty.
|
||
|
*/
|
||
|
|
||
|
exports.window = {
|
||
|
width: 75
|
||
|
};
|
||
|
|
||
|
if (isatty) {
|
||
|
exports.window.width = process.stdout.getWindowSize
|
||
|
? process.stdout.getWindowSize(1)[0]
|
||
|
: tty.getWindowSize()[1];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Expose some basic cursor interactions that are common among reporters.
|
||
|
*/
|
||
|
|
||
|
exports.cursor = {
|
||
|
hide: function() {
|
||
|
isatty && process.stdout.write('\u001b[?25l');
|
||
|
},
|
||
|
|
||
|
show: function() {
|
||
|
isatty && process.stdout.write('\u001b[?25h');
|
||
|
},
|
||
|
|
||
|
deleteLine: function() {
|
||
|
isatty && process.stdout.write('\u001b[2K');
|
||
|
},
|
||
|
|
||
|
beginningOfLine: function() {
|
||
|
isatty && process.stdout.write('\u001b[0G');
|
||
|
},
|
||
|
|
||
|
CR: function() {
|
||
|
if (isatty) {
|
||
|
exports.cursor.deleteLine();
|
||
|
exports.cursor.beginningOfLine();
|
||
|
} else {
|
||
|
process.stdout.write('\r');
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
function showDiff(err) {
|
||
|
return (
|
||
|
err &&
|
||
|
err.showDiff !== false &&
|
||
|
sameType(err.actual, err.expected) &&
|
||
|
err.expected !== undefined
|
||
|
);
|
||
|
}
|
||
|
|
||
|
function stringifyDiffObjs(err) {
|
||
|
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
||
|
err.actual = utils.stringify(err.actual);
|
||
|
err.expected = utils.stringify(err.expected);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns a diff between 2 strings with coloured ANSI output.
|
||
|
*
|
||
|
* The diff will be either inline or unified dependant on the value
|
||
|
* of `Base.inlineDiff`.
|
||
|
*
|
||
|
* @param {string} actual
|
||
|
* @param {string} expected
|
||
|
* @return {string} Diff
|
||
|
*/
|
||
|
var generateDiff = (exports.generateDiff = function(actual, expected) {
|
||
|
return exports.inlineDiffs
|
||
|
? inlineDiff(actual, expected)
|
||
|
: unifiedDiff(actual, expected);
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Output the given `failures` as a list.
|
||
|
*
|
||
|
* @public
|
||
|
* @memberof Mocha.reporters.Base
|
||
|
* @variation 1
|
||
|
* @param {Array} failures
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
exports.list = function(failures) {
|
||
|
console.log();
|
||
|
failures.forEach(function(test, i) {
|
||
|
// format
|
||
|
var fmt =
|
||
|
color('error title', ' %s) %s:\n') +
|
||
|
color('error message', ' %s') +
|
||
|
color('error stack', '\n%s\n');
|
||
|
|
||
|
// msg
|
||
|
var msg;
|
||
|
var err = test.err;
|
||
|
var message;
|
||
|
if (err.message && typeof err.message.toString === 'function') {
|
||
|
message = err.message + '';
|
||
|
} else if (typeof err.inspect === 'function') {
|
||
|
message = err.inspect() + '';
|
||
|
} else {
|
||
|
message = '';
|
||
|
}
|
||
|
var stack = err.stack || message;
|
||
|
var index = message ? stack.indexOf(message) : -1;
|
||
|
|
||
|
if (index === -1) {
|
||
|
msg = message;
|
||
|
} else {
|
||
|
index += message.length;
|
||
|
msg = stack.slice(0, index);
|
||
|
// remove msg from stack
|
||
|
stack = stack.slice(index + 1);
|
||
|
}
|
||
|
|
||
|
// uncaught
|
||
|
if (err.uncaught) {
|
||
|
msg = 'Uncaught ' + msg;
|
||
|
}
|
||
|
// explicitly show diff
|
||
|
if (!exports.hideDiff && showDiff(err)) {
|
||
|
stringifyDiffObjs(err);
|
||
|
fmt =
|
||
|
color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
|
||
|
var match = message.match(/^([^:]+): expected/);
|
||
|
msg = '\n ' + color('error message', match ? match[1] : msg);
|
||
|
|
||
|
msg += generateDiff(err.actual, err.expected);
|
||
|
}
|
||
|
|
||
|
// indent stack trace
|
||
|
stack = stack.replace(/^/gm, ' ');
|
||
|
|
||
|
// indented test title
|
||
|
var testTitle = '';
|
||
|
test.titlePath().forEach(function(str, index) {
|
||
|
if (index !== 0) {
|
||
|
testTitle += '\n ';
|
||
|
}
|
||
|
for (var i = 0; i < index; i++) {
|
||
|
testTitle += ' ';
|
||
|
}
|
||
|
testTitle += str;
|
||
|
});
|
||
|
|
||
|
console.log(fmt, i + 1, testTitle, msg, stack);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Base` reporter.
|
||
|
*
|
||
|
* All other reporters generally
|
||
|
* inherit from this reporter, providing
|
||
|
* stats such as test duration, number
|
||
|
* of tests passed / failed etc.
|
||
|
*
|
||
|
* @memberof Mocha.reporters
|
||
|
* @public
|
||
|
* @class
|
||
|
* @param {Runner} runner
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function Base(runner) {
|
||
|
var stats = (this.stats = {
|
||
|
suites: 0,
|
||
|
tests: 0,
|
||
|
passes: 0,
|
||
|
pending: 0,
|
||
|
failures: 0
|
||
|
});
|
||
|
var failures = (this.failures = []);
|
||
|
|
||
|
if (!runner) {
|
||
|
return;
|
||
|
}
|
||
|
this.runner = runner;
|
||
|
|
||
|
runner.stats = stats;
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
stats.start = new Date();
|
||
|
});
|
||
|
|
||
|
runner.on('suite', function(suite) {
|
||
|
stats.suites = stats.suites || 0;
|
||
|
suite.root || stats.suites++;
|
||
|
});
|
||
|
|
||
|
runner.on('test end', function() {
|
||
|
stats.tests = stats.tests || 0;
|
||
|
stats.tests++;
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
stats.passes = stats.passes || 0;
|
||
|
|
||
|
if (test.duration > test.slow()) {
|
||
|
test.speed = 'slow';
|
||
|
} else if (test.duration > test.slow() / 2) {
|
||
|
test.speed = 'medium';
|
||
|
} else {
|
||
|
test.speed = 'fast';
|
||
|
}
|
||
|
|
||
|
stats.passes++;
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test, err) {
|
||
|
stats.failures = stats.failures || 0;
|
||
|
stats.failures++;
|
||
|
if (showDiff(err)) {
|
||
|
stringifyDiffObjs(err);
|
||
|
}
|
||
|
test.err = err;
|
||
|
failures.push(test);
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
stats.end = new Date();
|
||
|
stats.duration = stats.end - stats.start;
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function() {
|
||
|
stats.pending++;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Output common epilogue used by many of
|
||
|
* the bundled reporters.
|
||
|
*
|
||
|
* @memberof Mocha.reporters.Base
|
||
|
* @public
|
||
|
* @api public
|
||
|
*/
|
||
|
Base.prototype.epilogue = function() {
|
||
|
var stats = this.stats;
|
||
|
var fmt;
|
||
|
|
||
|
console.log();
|
||
|
|
||
|
// passes
|
||
|
fmt =
|
||
|
color('bright pass', ' ') +
|
||
|
color('green', ' %d passing') +
|
||
|
color('light', ' (%s)');
|
||
|
|
||
|
console.log(fmt, stats.passes || 0, ms(stats.duration));
|
||
|
|
||
|
// pending
|
||
|
if (stats.pending) {
|
||
|
fmt = color('pending', ' ') + color('pending', ' %d pending');
|
||
|
|
||
|
console.log(fmt, stats.pending);
|
||
|
}
|
||
|
|
||
|
// failures
|
||
|
if (stats.failures) {
|
||
|
fmt = color('fail', ' %d failing');
|
||
|
|
||
|
console.log(fmt, stats.failures);
|
||
|
|
||
|
Base.list(this.failures);
|
||
|
console.log();
|
||
|
}
|
||
|
|
||
|
console.log();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Pad the given `str` to `len`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} str
|
||
|
* @param {string} len
|
||
|
* @return {string}
|
||
|
*/
|
||
|
function pad(str, len) {
|
||
|
str = String(str);
|
||
|
return Array(len - str.length + 1).join(' ') + str;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns an inline diff between 2 strings with coloured ANSI output.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {String} actual
|
||
|
* @param {String} expected
|
||
|
* @return {string} Diff
|
||
|
*/
|
||
|
function inlineDiff(actual, expected) {
|
||
|
var msg = errorDiff(actual, expected);
|
||
|
|
||
|
// linenos
|
||
|
var lines = msg.split('\n');
|
||
|
if (lines.length > 4) {
|
||
|
var width = String(lines.length).length;
|
||
|
msg = lines
|
||
|
.map(function(str, i) {
|
||
|
return pad(++i, width) + ' |' + ' ' + str;
|
||
|
})
|
||
|
.join('\n');
|
||
|
}
|
||
|
|
||
|
// legend
|
||
|
msg =
|
||
|
'\n' +
|
||
|
color('diff removed', 'actual') +
|
||
|
' ' +
|
||
|
color('diff added', 'expected') +
|
||
|
'\n\n' +
|
||
|
msg +
|
||
|
'\n';
|
||
|
|
||
|
// indent
|
||
|
msg = msg.replace(/^/gm, ' ');
|
||
|
return msg;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns a unified diff between two strings with coloured ANSI output.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {String} actual
|
||
|
* @param {String} expected
|
||
|
* @return {string} The diff.
|
||
|
*/
|
||
|
function unifiedDiff(actual, expected) {
|
||
|
var indent = ' ';
|
||
|
function cleanUp(line) {
|
||
|
if (line[0] === '+') {
|
||
|
return indent + colorLines('diff added', line);
|
||
|
}
|
||
|
if (line[0] === '-') {
|
||
|
return indent + colorLines('diff removed', line);
|
||
|
}
|
||
|
if (line.match(/@@/)) {
|
||
|
return '--';
|
||
|
}
|
||
|
if (line.match(/\\ No newline/)) {
|
||
|
return null;
|
||
|
}
|
||
|
return indent + line;
|
||
|
}
|
||
|
function notBlank(line) {
|
||
|
return typeof line !== 'undefined' && line !== null;
|
||
|
}
|
||
|
var msg = diff.createPatch('string', actual, expected);
|
||
|
var lines = msg.split('\n').splice(5);
|
||
|
return (
|
||
|
'\n ' +
|
||
|
colorLines('diff added', '+ expected') +
|
||
|
' ' +
|
||
|
colorLines('diff removed', '- actual') +
|
||
|
'\n\n' +
|
||
|
lines
|
||
|
.map(cleanUp)
|
||
|
.filter(notBlank)
|
||
|
.join('\n')
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a character diff for `err`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {String} actual
|
||
|
* @param {String} expected
|
||
|
* @return {string} the diff
|
||
|
*/
|
||
|
function errorDiff(actual, expected) {
|
||
|
return diff
|
||
|
.diffWordsWithSpace(actual, expected)
|
||
|
.map(function(str) {
|
||
|
if (str.added) {
|
||
|
return colorLines('diff added', str.value);
|
||
|
}
|
||
|
if (str.removed) {
|
||
|
return colorLines('diff removed', str.value);
|
||
|
}
|
||
|
return str.value;
|
||
|
})
|
||
|
.join('');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Color lines for `str`, using the color `name`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} name
|
||
|
* @param {string} str
|
||
|
* @return {string}
|
||
|
*/
|
||
|
function colorLines(name, str) {
|
||
|
return str
|
||
|
.split('\n')
|
||
|
.map(function(str) {
|
||
|
return color(name, str);
|
||
|
})
|
||
|
.join('\n');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Object#toString reference.
|
||
|
*/
|
||
|
var objToString = Object.prototype.toString;
|
||
|
|
||
|
/**
|
||
|
* Check that a / b have the same type.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} a
|
||
|
* @param {Object} b
|
||
|
* @return {boolean}
|
||
|
*/
|
||
|
function sameType(a, b) {
|
||
|
return objToString.call(a) === objToString.call(b);
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"../ms":14,"../utils":36,"_process":56,"diff":45,"supports-color":40,"tty":4}],17:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Doc
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var utils = require('../utils');
|
||
|
|
||
|
/**
|
||
|
* Expose `Doc`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Doc;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Doc` reporter.
|
||
|
*
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends {Base}
|
||
|
* @public
|
||
|
* @param {Runner} runner
|
||
|
* @api public
|
||
|
*/
|
||
|
function Doc(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var indents = 2;
|
||
|
|
||
|
function indent() {
|
||
|
return Array(indents).join(' ');
|
||
|
}
|
||
|
|
||
|
runner.on('suite', function(suite) {
|
||
|
if (suite.root) {
|
||
|
return;
|
||
|
}
|
||
|
++indents;
|
||
|
console.log('%s<section class="suite">', indent());
|
||
|
++indents;
|
||
|
console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
|
||
|
console.log('%s<dl>', indent());
|
||
|
});
|
||
|
|
||
|
runner.on('suite end', function(suite) {
|
||
|
if (suite.root) {
|
||
|
return;
|
||
|
}
|
||
|
console.log('%s</dl>', indent());
|
||
|
--indents;
|
||
|
console.log('%s</section>', indent());
|
||
|
--indents;
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
|
||
|
var code = utils.escape(utils.clean(test.body));
|
||
|
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test, err) {
|
||
|
console.log(
|
||
|
'%s <dt class="error">%s</dt>',
|
||
|
indent(),
|
||
|
utils.escape(test.title)
|
||
|
);
|
||
|
var code = utils.escape(utils.clean(test.body));
|
||
|
console.log(
|
||
|
'%s <dd class="error"><pre><code>%s</code></pre></dd>',
|
||
|
indent(),
|
||
|
code
|
||
|
);
|
||
|
console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
},{"../utils":36,"./base":16}],18:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Dot
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
var color = Base.color;
|
||
|
|
||
|
/**
|
||
|
* Expose `Dot`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Dot;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Dot` matrix test reporter.
|
||
|
*
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function Dot(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var width = (Base.window.width * 0.75) | 0;
|
||
|
var n = -1;
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
process.stdout.write('\n');
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function() {
|
||
|
if (++n % width === 0) {
|
||
|
process.stdout.write('\n ');
|
||
|
}
|
||
|
process.stdout.write(color('pending', Base.symbols.comma));
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
if (++n % width === 0) {
|
||
|
process.stdout.write('\n ');
|
||
|
}
|
||
|
if (test.speed === 'slow') {
|
||
|
process.stdout.write(color('bright yellow', Base.symbols.dot));
|
||
|
} else {
|
||
|
process.stdout.write(color(test.speed, Base.symbols.dot));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function() {
|
||
|
if (++n % width === 0) {
|
||
|
process.stdout.write('\n ');
|
||
|
}
|
||
|
process.stdout.write(color('fail', Base.symbols.bang));
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
console.log();
|
||
|
self.epilogue();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(Dot, Base);
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],19:[function(require,module,exports){
|
||
|
(function (global){
|
||
|
'use strict';
|
||
|
|
||
|
/* eslint-env browser */
|
||
|
/**
|
||
|
* @module HTML
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var utils = require('../utils');
|
||
|
var Progress = require('../browser/progress');
|
||
|
var escapeRe = require('escape-string-regexp');
|
||
|
var escape = utils.escape;
|
||
|
|
||
|
/**
|
||
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
||
|
*/
|
||
|
|
||
|
/* eslint-disable no-unused-vars, no-native-reassign */
|
||
|
var Date = global.Date;
|
||
|
var setTimeout = global.setTimeout;
|
||
|
var setInterval = global.setInterval;
|
||
|
var clearTimeout = global.clearTimeout;
|
||
|
var clearInterval = global.clearInterval;
|
||
|
/* eslint-enable no-unused-vars, no-native-reassign */
|
||
|
|
||
|
/**
|
||
|
* Expose `HTML`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = HTML;
|
||
|
|
||
|
/**
|
||
|
* Stats template.
|
||
|
*/
|
||
|
|
||
|
var statsTemplate =
|
||
|
'<ul id="mocha-stats">' +
|
||
|
'<li class="progress"><canvas width="40" height="40"></canvas></li>' +
|
||
|
'<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
|
||
|
'<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
|
||
|
'<li class="duration">duration: <em>0</em>s</li>' +
|
||
|
'</ul>';
|
||
|
|
||
|
var playIcon = '‣';
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `HTML` reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function HTML(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var stats = this.stats;
|
||
|
var stat = fragment(statsTemplate);
|
||
|
var items = stat.getElementsByTagName('li');
|
||
|
var passes = items[1].getElementsByTagName('em')[0];
|
||
|
var passesLink = items[1].getElementsByTagName('a')[0];
|
||
|
var failures = items[2].getElementsByTagName('em')[0];
|
||
|
var failuresLink = items[2].getElementsByTagName('a')[0];
|
||
|
var duration = items[3].getElementsByTagName('em')[0];
|
||
|
var canvas = stat.getElementsByTagName('canvas')[0];
|
||
|
var report = fragment('<ul id="mocha-report"></ul>');
|
||
|
var stack = [report];
|
||
|
var progress;
|
||
|
var ctx;
|
||
|
var root = document.getElementById('mocha');
|
||
|
|
||
|
if (canvas.getContext) {
|
||
|
var ratio = window.devicePixelRatio || 1;
|
||
|
canvas.style.width = canvas.width;
|
||
|
canvas.style.height = canvas.height;
|
||
|
canvas.width *= ratio;
|
||
|
canvas.height *= ratio;
|
||
|
ctx = canvas.getContext('2d');
|
||
|
ctx.scale(ratio, ratio);
|
||
|
progress = new Progress();
|
||
|
}
|
||
|
|
||
|
if (!root) {
|
||
|
return error('#mocha div missing, add it to your document');
|
||
|
}
|
||
|
|
||
|
// pass toggle
|
||
|
on(passesLink, 'click', function(evt) {
|
||
|
evt.preventDefault();
|
||
|
unhide();
|
||
|
var name = /pass/.test(report.className) ? '' : ' pass';
|
||
|
report.className = report.className.replace(/fail|pass/g, '') + name;
|
||
|
if (report.className.trim()) {
|
||
|
hideSuitesWithout('test pass');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// failure toggle
|
||
|
on(failuresLink, 'click', function(evt) {
|
||
|
evt.preventDefault();
|
||
|
unhide();
|
||
|
var name = /fail/.test(report.className) ? '' : ' fail';
|
||
|
report.className = report.className.replace(/fail|pass/g, '') + name;
|
||
|
if (report.className.trim()) {
|
||
|
hideSuitesWithout('test fail');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
root.appendChild(stat);
|
||
|
root.appendChild(report);
|
||
|
|
||
|
if (progress) {
|
||
|
progress.size(40);
|
||
|
}
|
||
|
|
||
|
runner.on('suite', function(suite) {
|
||
|
if (suite.root) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// suite
|
||
|
var url = self.suiteURL(suite);
|
||
|
var el = fragment(
|
||
|
'<li class="suite"><h1><a href="%s">%s</a></h1></li>',
|
||
|
url,
|
||
|
escape(suite.title)
|
||
|
);
|
||
|
|
||
|
// container
|
||
|
stack[0].appendChild(el);
|
||
|
stack.unshift(document.createElement('ul'));
|
||
|
el.appendChild(stack[0]);
|
||
|
});
|
||
|
|
||
|
runner.on('suite end', function(suite) {
|
||
|
if (suite.root) {
|
||
|
updateStats();
|
||
|
return;
|
||
|
}
|
||
|
stack.shift();
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
var url = self.testURL(test);
|
||
|
var markup =
|
||
|
'<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
|
||
|
'<a href="%s" class="replay">' +
|
||
|
playIcon +
|
||
|
'</a></h2></li>';
|
||
|
var el = fragment(markup, test.speed, test.title, test.duration, url);
|
||
|
self.addCodeToggle(el, test.body);
|
||
|
appendToStack(el);
|
||
|
updateStats();
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test) {
|
||
|
var el = fragment(
|
||
|
'<li class="test fail"><h2>%e <a href="%e" class="replay">' +
|
||
|
playIcon +
|
||
|
'</a></h2></li>',
|
||
|
test.title,
|
||
|
self.testURL(test)
|
||
|
);
|
||
|
var stackString; // Note: Includes leading newline
|
||
|
var message = test.err.toString();
|
||
|
|
||
|
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
|
||
|
// check for the result of the stringifying.
|
||
|
if (message === '[object Error]') {
|
||
|
message = test.err.message;
|
||
|
}
|
||
|
|
||
|
if (test.err.stack) {
|
||
|
var indexOfMessage = test.err.stack.indexOf(test.err.message);
|
||
|
if (indexOfMessage === -1) {
|
||
|
stackString = test.err.stack;
|
||
|
} else {
|
||
|
stackString = test.err.stack.substr(
|
||
|
test.err.message.length + indexOfMessage
|
||
|
);
|
||
|
}
|
||
|
} else if (test.err.sourceURL && test.err.line !== undefined) {
|
||
|
// Safari doesn't give you a stack. Let's at least provide a source line.
|
||
|
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
|
||
|
}
|
||
|
|
||
|
stackString = stackString || '';
|
||
|
|
||
|
if (test.err.htmlMessage && stackString) {
|
||
|
el.appendChild(
|
||
|
fragment(
|
||
|
'<div class="html-error">%s\n<pre class="error">%e</pre></div>',
|
||
|
test.err.htmlMessage,
|
||
|
stackString
|
||
|
)
|
||
|
);
|
||
|
} else if (test.err.htmlMessage) {
|
||
|
el.appendChild(
|
||
|
fragment('<div class="html-error">%s</div>', test.err.htmlMessage)
|
||
|
);
|
||
|
} else {
|
||
|
el.appendChild(
|
||
|
fragment('<pre class="error">%e%e</pre>', message, stackString)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
self.addCodeToggle(el, test.body);
|
||
|
appendToStack(el);
|
||
|
updateStats();
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function(test) {
|
||
|
var el = fragment(
|
||
|
'<li class="test pass pending"><h2>%e</h2></li>',
|
||
|
test.title
|
||
|
);
|
||
|
appendToStack(el);
|
||
|
updateStats();
|
||
|
});
|
||
|
|
||
|
function appendToStack(el) {
|
||
|
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
|
||
|
if (stack[0]) {
|
||
|
stack[0].appendChild(el);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function updateStats() {
|
||
|
// TODO: add to stats
|
||
|
var percent = (stats.tests / runner.total * 100) | 0;
|
||
|
if (progress) {
|
||
|
progress.update(percent).draw(ctx);
|
||
|
}
|
||
|
|
||
|
// update stats
|
||
|
var ms = new Date() - stats.start;
|
||
|
text(passes, stats.passes);
|
||
|
text(failures, stats.failures);
|
||
|
text(duration, (ms / 1000).toFixed(2));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Makes a URL, preserving querystring ("search") parameters.
|
||
|
*
|
||
|
* @param {string} s
|
||
|
* @return {string} A new URL.
|
||
|
*/
|
||
|
function makeUrl(s) {
|
||
|
var search = window.location.search;
|
||
|
|
||
|
// Remove previous grep query parameter if present
|
||
|
if (search) {
|
||
|
search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
window.location.pathname +
|
||
|
(search ? search + '&' : '?') +
|
||
|
'grep=' +
|
||
|
encodeURIComponent(escapeRe(s))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Provide suite URL.
|
||
|
*
|
||
|
* @param {Object} [suite]
|
||
|
*/
|
||
|
HTML.prototype.suiteURL = function(suite) {
|
||
|
return makeUrl(suite.fullTitle());
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Provide test URL.
|
||
|
*
|
||
|
* @param {Object} [test]
|
||
|
*/
|
||
|
HTML.prototype.testURL = function(test) {
|
||
|
return makeUrl(test.fullTitle());
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Adds code toggle functionality for the provided test's list element.
|
||
|
*
|
||
|
* @param {HTMLLIElement} el
|
||
|
* @param {string} contents
|
||
|
*/
|
||
|
HTML.prototype.addCodeToggle = function(el, contents) {
|
||
|
var h2 = el.getElementsByTagName('h2')[0];
|
||
|
|
||
|
on(h2, 'click', function() {
|
||
|
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
|
||
|
});
|
||
|
|
||
|
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
|
||
|
el.appendChild(pre);
|
||
|
pre.style.display = 'none';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Display error `msg`.
|
||
|
*
|
||
|
* @param {string} msg
|
||
|
*/
|
||
|
function error(msg) {
|
||
|
document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a DOM fragment from `html`.
|
||
|
*
|
||
|
* @param {string} html
|
||
|
*/
|
||
|
function fragment(html) {
|
||
|
var args = arguments;
|
||
|
var div = document.createElement('div');
|
||
|
var i = 1;
|
||
|
|
||
|
div.innerHTML = html.replace(/%([se])/g, function(_, type) {
|
||
|
switch (type) {
|
||
|
case 's':
|
||
|
return String(args[i++]);
|
||
|
case 'e':
|
||
|
return escape(args[i++]);
|
||
|
// no default
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return div.firstChild;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check for suites that do not have elements
|
||
|
* with `classname`, and hide them.
|
||
|
*
|
||
|
* @param {text} classname
|
||
|
*/
|
||
|
function hideSuitesWithout(classname) {
|
||
|
var suites = document.getElementsByClassName('suite');
|
||
|
for (var i = 0; i < suites.length; i++) {
|
||
|
var els = suites[i].getElementsByClassName(classname);
|
||
|
if (!els.length) {
|
||
|
suites[i].className += ' hidden';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Unhide .hidden suites.
|
||
|
*/
|
||
|
function unhide() {
|
||
|
var els = document.getElementsByClassName('suite hidden');
|
||
|
for (var i = 0; i < els.length; ++i) {
|
||
|
els[i].className = els[i].className.replace('suite hidden', 'suite');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Set an element's text contents.
|
||
|
*
|
||
|
* @param {HTMLElement} el
|
||
|
* @param {string} contents
|
||
|
*/
|
||
|
function text(el, contents) {
|
||
|
if (el.textContent) {
|
||
|
el.textContent = contents;
|
||
|
} else {
|
||
|
el.innerText = contents;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Listen on `event` with callback `fn`.
|
||
|
*/
|
||
|
function on(el, event, fn) {
|
||
|
if (el.addEventListener) {
|
||
|
el.addEventListener(event, fn, false);
|
||
|
} else {
|
||
|
el.attachEvent('on' + event, fn);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"../browser/progress":3,"../utils":36,"./base":16,"escape-string-regexp":46}],20:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
// Alias exports to a their normalized format Mocha#reporter to prevent a need
|
||
|
// for dynamic (try/catch) requires, which Browserify doesn't handle.
|
||
|
exports.Base = exports.base = require('./base');
|
||
|
exports.Dot = exports.dot = require('./dot');
|
||
|
exports.Doc = exports.doc = require('./doc');
|
||
|
exports.TAP = exports.tap = require('./tap');
|
||
|
exports.JSON = exports.json = require('./json');
|
||
|
exports.HTML = exports.html = require('./html');
|
||
|
exports.List = exports.list = require('./list');
|
||
|
exports.Min = exports.min = require('./min');
|
||
|
exports.Spec = exports.spec = require('./spec');
|
||
|
exports.Nyan = exports.nyan = require('./nyan');
|
||
|
exports.XUnit = exports.xunit = require('./xunit');
|
||
|
exports.Markdown = exports.markdown = require('./markdown');
|
||
|
exports.Progress = exports.progress = require('./progress');
|
||
|
exports.Landing = exports.landing = require('./landing');
|
||
|
exports.JSONStream = exports['json-stream'] = require('./json-stream');
|
||
|
|
||
|
},{"./base":16,"./doc":17,"./dot":18,"./html":19,"./json":22,"./json-stream":21,"./landing":23,"./list":24,"./markdown":25,"./min":26,"./nyan":27,"./progress":28,"./spec":29,"./tap":30,"./xunit":31}],21:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module JSONStream
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
|
||
|
/**
|
||
|
* Expose `List`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = List;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `JSONStream` test reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @name JSONStream
|
||
|
* @class JSONStream
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function List(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var total = runner.total;
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
console.log(JSON.stringify(['start', {total: total}]));
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
console.log(JSON.stringify(['pass', clean(test)]));
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test, err) {
|
||
|
test = clean(test);
|
||
|
test.err = err.message;
|
||
|
test.stack = err.stack || null;
|
||
|
console.log(JSON.stringify(['fail', test]));
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
process.stdout.write(JSON.stringify(['end', self.stats]));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a plain-object representation of `test`
|
||
|
* free of cyclic properties etc.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} test
|
||
|
* @return {Object}
|
||
|
*/
|
||
|
function clean(test) {
|
||
|
return {
|
||
|
title: test.title,
|
||
|
fullTitle: test.fullTitle(),
|
||
|
duration: test.duration,
|
||
|
currentRetry: test.currentRetry()
|
||
|
};
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"./base":16,"_process":56}],22:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module JSON
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
|
||
|
/**
|
||
|
* Expose `JSON`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = JSONReporter;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `JSON` reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class JSON
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function JSONReporter(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var tests = [];
|
||
|
var pending = [];
|
||
|
var failures = [];
|
||
|
var passes = [];
|
||
|
|
||
|
runner.on('test end', function(test) {
|
||
|
tests.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
passes.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test) {
|
||
|
failures.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function(test) {
|
||
|
pending.push(test);
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
var obj = {
|
||
|
stats: self.stats,
|
||
|
tests: tests.map(clean),
|
||
|
pending: pending.map(clean),
|
||
|
failures: failures.map(clean),
|
||
|
passes: passes.map(clean)
|
||
|
};
|
||
|
|
||
|
runner.testResults = obj;
|
||
|
|
||
|
process.stdout.write(JSON.stringify(obj, null, 2));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a plain-object representation of `test`
|
||
|
* free of cyclic properties etc.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} test
|
||
|
* @return {Object}
|
||
|
*/
|
||
|
function clean(test) {
|
||
|
var err = test.err || {};
|
||
|
if (err instanceof Error) {
|
||
|
err = errorJSON(err);
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
title: test.title,
|
||
|
fullTitle: test.fullTitle(),
|
||
|
duration: test.duration,
|
||
|
currentRetry: test.currentRetry(),
|
||
|
err: cleanCycles(err)
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Replaces any circular references inside `obj` with '[object Object]'
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} obj
|
||
|
* @return {Object}
|
||
|
*/
|
||
|
function cleanCycles(obj) {
|
||
|
var cache = [];
|
||
|
return JSON.parse(
|
||
|
JSON.stringify(obj, function(key, value) {
|
||
|
if (typeof value === 'object' && value !== null) {
|
||
|
if (cache.indexOf(value) !== -1) {
|
||
|
// Instead of going in a circle, we'll print [object Object]
|
||
|
return '' + value;
|
||
|
}
|
||
|
cache.push(value);
|
||
|
}
|
||
|
|
||
|
return value;
|
||
|
})
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Transform an Error object into a JSON object.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Error} err
|
||
|
* @return {Object}
|
||
|
*/
|
||
|
function errorJSON(err) {
|
||
|
var res = {};
|
||
|
Object.getOwnPropertyNames(err).forEach(function(key) {
|
||
|
res[key] = err[key];
|
||
|
}, err);
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"./base":16,"_process":56}],23:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Landing
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
var cursor = Base.cursor;
|
||
|
var color = Base.color;
|
||
|
|
||
|
/**
|
||
|
* Expose `Landing`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Landing;
|
||
|
|
||
|
/**
|
||
|
* Airplane color.
|
||
|
*/
|
||
|
|
||
|
Base.colors.plane = 0;
|
||
|
|
||
|
/**
|
||
|
* Airplane crash color.
|
||
|
*/
|
||
|
|
||
|
Base.colors['plane crash'] = 31;
|
||
|
|
||
|
/**
|
||
|
* Runway color.
|
||
|
*/
|
||
|
|
||
|
Base.colors.runway = 90;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Landing` reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function Landing(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var width = (Base.window.width * 0.75) | 0;
|
||
|
var total = runner.total;
|
||
|
var stream = process.stdout;
|
||
|
var plane = color('plane', '✈');
|
||
|
var crashed = -1;
|
||
|
var n = 0;
|
||
|
|
||
|
function runway() {
|
||
|
var buf = Array(width).join('-');
|
||
|
return ' ' + color('runway', buf);
|
||
|
}
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
stream.write('\n\n\n ');
|
||
|
cursor.hide();
|
||
|
});
|
||
|
|
||
|
runner.on('test end', function(test) {
|
||
|
// check if the plane crashed
|
||
|
var col = crashed === -1 ? (width * ++n / total) | 0 : crashed;
|
||
|
|
||
|
// show the crash
|
||
|
if (test.state === 'failed') {
|
||
|
plane = color('plane crash', '✈');
|
||
|
crashed = col;
|
||
|
}
|
||
|
|
||
|
// render landing strip
|
||
|
stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
|
||
|
stream.write(runway());
|
||
|
stream.write('\n ');
|
||
|
stream.write(color('runway', Array(col).join('⋅')));
|
||
|
stream.write(plane);
|
||
|
stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
|
||
|
stream.write(runway());
|
||
|
stream.write('\u001b[0m');
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
cursor.show();
|
||
|
console.log();
|
||
|
self.epilogue();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(Landing, Base);
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],24:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module List
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
var color = Base.color;
|
||
|
var cursor = Base.cursor;
|
||
|
|
||
|
/**
|
||
|
* Expose `List`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = List;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `List` test reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function List(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var n = 0;
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
console.log();
|
||
|
});
|
||
|
|
||
|
runner.on('test', function(test) {
|
||
|
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function(test) {
|
||
|
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
||
|
console.log(fmt, test.fullTitle());
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
var fmt =
|
||
|
color('checkmark', ' ' + Base.symbols.ok) +
|
||
|
color('pass', ' %s: ') +
|
||
|
color(test.speed, '%dms');
|
||
|
cursor.CR();
|
||
|
console.log(fmt, test.fullTitle(), test.duration);
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test) {
|
||
|
cursor.CR();
|
||
|
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
||
|
});
|
||
|
|
||
|
runner.once('end', self.epilogue.bind(self));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(List, Base);
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],25:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Markdown
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var utils = require('../utils');
|
||
|
|
||
|
/**
|
||
|
* Constants
|
||
|
*/
|
||
|
|
||
|
var SUITE_PREFIX = '$';
|
||
|
|
||
|
/**
|
||
|
* Expose `Markdown`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Markdown;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Markdown` reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function Markdown(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var level = 0;
|
||
|
var buf = '';
|
||
|
|
||
|
function title(str) {
|
||
|
return Array(level).join('#') + ' ' + str;
|
||
|
}
|
||
|
|
||
|
function mapTOC(suite, obj) {
|
||
|
var ret = obj;
|
||
|
var key = SUITE_PREFIX + suite.title;
|
||
|
|
||
|
obj = obj[key] = obj[key] || {suite: suite};
|
||
|
suite.suites.forEach(function(suite) {
|
||
|
mapTOC(suite, obj);
|
||
|
});
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
function stringifyTOC(obj, level) {
|
||
|
++level;
|
||
|
var buf = '';
|
||
|
var link;
|
||
|
for (var key in obj) {
|
||
|
if (key === 'suite') {
|
||
|
continue;
|
||
|
}
|
||
|
if (key !== SUITE_PREFIX) {
|
||
|
link = ' - [' + key.substring(1) + ']';
|
||
|
link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
|
||
|
buf += Array(level).join(' ') + link;
|
||
|
}
|
||
|
buf += stringifyTOC(obj[key], level);
|
||
|
}
|
||
|
return buf;
|
||
|
}
|
||
|
|
||
|
function generateTOC(suite) {
|
||
|
var obj = mapTOC(suite, {});
|
||
|
return stringifyTOC(obj, 0);
|
||
|
}
|
||
|
|
||
|
generateTOC(runner.suite);
|
||
|
|
||
|
runner.on('suite', function(suite) {
|
||
|
++level;
|
||
|
var slug = utils.slug(suite.fullTitle());
|
||
|
buf += '<a name="' + slug + '"></a>' + '\n';
|
||
|
buf += title(suite.title) + '\n';
|
||
|
});
|
||
|
|
||
|
runner.on('suite end', function() {
|
||
|
--level;
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
var code = utils.clean(test.body);
|
||
|
buf += test.title + '.\n';
|
||
|
buf += '\n```js\n';
|
||
|
buf += code + '\n';
|
||
|
buf += '```\n\n';
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
process.stdout.write('# TOC\n');
|
||
|
process.stdout.write(generateTOC(runner.suite));
|
||
|
process.stdout.write(buf);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],26:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Min
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
|
||
|
/**
|
||
|
* Expose `Min`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Min;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Min` minimal test reporter (best used with --watch).
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function Min(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
// clear screen
|
||
|
process.stdout.write('\u001b[2J');
|
||
|
// set cursor position
|
||
|
process.stdout.write('\u001b[1;3H');
|
||
|
});
|
||
|
|
||
|
runner.once('end', this.epilogue.bind(this));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(Min, Base);
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],27:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Nyan
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
|
||
|
/**
|
||
|
* Expose `Dot`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = NyanCat;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Dot` matrix test reporter.
|
||
|
*
|
||
|
* @param {Runner} runner
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @class Nyan
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
*/
|
||
|
|
||
|
function NyanCat(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var width = (Base.window.width * 0.75) | 0;
|
||
|
var nyanCatWidth = (this.nyanCatWidth = 11);
|
||
|
|
||
|
this.colorIndex = 0;
|
||
|
this.numberOfLines = 4;
|
||
|
this.rainbowColors = self.generateColors();
|
||
|
this.scoreboardWidth = 5;
|
||
|
this.tick = 0;
|
||
|
this.trajectories = [[], [], [], []];
|
||
|
this.trajectoryWidthMax = width - nyanCatWidth;
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
Base.cursor.hide();
|
||
|
self.draw();
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function() {
|
||
|
self.draw();
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function() {
|
||
|
self.draw();
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function() {
|
||
|
self.draw();
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
Base.cursor.show();
|
||
|
for (var i = 0; i < self.numberOfLines; i++) {
|
||
|
write('\n');
|
||
|
}
|
||
|
self.epilogue();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(NyanCat, Base);
|
||
|
|
||
|
/**
|
||
|
* Draw the nyan cat
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.draw = function() {
|
||
|
this.appendRainbow();
|
||
|
this.drawScoreboard();
|
||
|
this.drawRainbow();
|
||
|
this.drawNyanCat();
|
||
|
this.tick = !this.tick;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Draw the "scoreboard" showing the number
|
||
|
* of passes, failures and pending tests.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.drawScoreboard = function() {
|
||
|
var stats = this.stats;
|
||
|
|
||
|
function draw(type, n) {
|
||
|
write(' ');
|
||
|
write(Base.color(type, n));
|
||
|
write('\n');
|
||
|
}
|
||
|
|
||
|
draw('green', stats.passes);
|
||
|
draw('fail', stats.failures);
|
||
|
draw('pending', stats.pending);
|
||
|
write('\n');
|
||
|
|
||
|
this.cursorUp(this.numberOfLines);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Append the rainbow.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.appendRainbow = function() {
|
||
|
var segment = this.tick ? '_' : '-';
|
||
|
var rainbowified = this.rainbowify(segment);
|
||
|
|
||
|
for (var index = 0; index < this.numberOfLines; index++) {
|
||
|
var trajectory = this.trajectories[index];
|
||
|
if (trajectory.length >= this.trajectoryWidthMax) {
|
||
|
trajectory.shift();
|
||
|
}
|
||
|
trajectory.push(rainbowified);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Draw the rainbow.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.drawRainbow = function() {
|
||
|
var self = this;
|
||
|
|
||
|
this.trajectories.forEach(function(line) {
|
||
|
write('\u001b[' + self.scoreboardWidth + 'C');
|
||
|
write(line.join(''));
|
||
|
write('\n');
|
||
|
});
|
||
|
|
||
|
this.cursorUp(this.numberOfLines);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Draw the nyan cat
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
NyanCat.prototype.drawNyanCat = function() {
|
||
|
var self = this;
|
||
|
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
|
||
|
var dist = '\u001b[' + startWidth + 'C';
|
||
|
var padding = '';
|
||
|
|
||
|
write(dist);
|
||
|
write('_,------,');
|
||
|
write('\n');
|
||
|
|
||
|
write(dist);
|
||
|
padding = self.tick ? ' ' : ' ';
|
||
|
write('_|' + padding + '/\\_/\\ ');
|
||
|
write('\n');
|
||
|
|
||
|
write(dist);
|
||
|
padding = self.tick ? '_' : '__';
|
||
|
var tail = self.tick ? '~' : '^';
|
||
|
write(tail + '|' + padding + this.face() + ' ');
|
||
|
write('\n');
|
||
|
|
||
|
write(dist);
|
||
|
padding = self.tick ? ' ' : ' ';
|
||
|
write(padding + '"" "" ');
|
||
|
write('\n');
|
||
|
|
||
|
this.cursorUp(this.numberOfLines);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Draw nyan cat face.
|
||
|
*
|
||
|
* @api private
|
||
|
* @return {string}
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.face = function() {
|
||
|
var stats = this.stats;
|
||
|
if (stats.failures) {
|
||
|
return '( x .x)';
|
||
|
} else if (stats.pending) {
|
||
|
return '( o .o)';
|
||
|
} else if (stats.passes) {
|
||
|
return '( ^ .^)';
|
||
|
}
|
||
|
return '( - .-)';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Move cursor up `n`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number} n
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.cursorUp = function(n) {
|
||
|
write('\u001b[' + n + 'A');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Move cursor down `n`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number} n
|
||
|
*/
|
||
|
|
||
|
NyanCat.prototype.cursorDown = function(n) {
|
||
|
write('\u001b[' + n + 'B');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Generate rainbow colors.
|
||
|
*
|
||
|
* @api private
|
||
|
* @return {Array}
|
||
|
*/
|
||
|
NyanCat.prototype.generateColors = function() {
|
||
|
var colors = [];
|
||
|
|
||
|
for (var i = 0; i < 6 * 7; i++) {
|
||
|
var pi3 = Math.floor(Math.PI / 3);
|
||
|
var n = i * (1.0 / 6);
|
||
|
var r = Math.floor(3 * Math.sin(n) + 3);
|
||
|
var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
|
||
|
var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
|
||
|
colors.push(36 * r + 6 * g + b + 16);
|
||
|
}
|
||
|
|
||
|
return colors;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Apply rainbow to the given `str`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} str
|
||
|
* @return {string}
|
||
|
*/
|
||
|
NyanCat.prototype.rainbowify = function(str) {
|
||
|
if (!Base.useColors) {
|
||
|
return str;
|
||
|
}
|
||
|
var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
|
||
|
this.colorIndex += 1;
|
||
|
return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Stdout helper.
|
||
|
*
|
||
|
* @param {string} string A message to write to stdout.
|
||
|
*/
|
||
|
function write(string) {
|
||
|
process.stdout.write(string);
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],28:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Progress
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
var color = Base.color;
|
||
|
var cursor = Base.cursor;
|
||
|
|
||
|
/**
|
||
|
* Expose `Progress`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Progress;
|
||
|
|
||
|
/**
|
||
|
* General progress bar color.
|
||
|
*/
|
||
|
|
||
|
Base.colors.progress = 90;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Progress` bar test reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
* @param {Object} options
|
||
|
*/
|
||
|
function Progress(runner, options) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var width = (Base.window.width * 0.5) | 0;
|
||
|
var total = runner.total;
|
||
|
var complete = 0;
|
||
|
var lastN = -1;
|
||
|
|
||
|
// default chars
|
||
|
options = options || {};
|
||
|
var reporterOptions = options.reporterOptions || {};
|
||
|
|
||
|
options.open = reporterOptions.open || '[';
|
||
|
options.complete = reporterOptions.complete || '▬';
|
||
|
options.incomplete = reporterOptions.incomplete || Base.symbols.dot;
|
||
|
options.close = reporterOptions.close || ']';
|
||
|
options.verbose = reporterOptions.verbose || false;
|
||
|
|
||
|
// tests started
|
||
|
runner.on('start', function() {
|
||
|
console.log();
|
||
|
cursor.hide();
|
||
|
});
|
||
|
|
||
|
// tests complete
|
||
|
runner.on('test end', function() {
|
||
|
complete++;
|
||
|
|
||
|
var percent = complete / total;
|
||
|
var n = (width * percent) | 0;
|
||
|
var i = width - n;
|
||
|
|
||
|
if (n === lastN && !options.verbose) {
|
||
|
// Don't re-render the line if it hasn't changed
|
||
|
return;
|
||
|
}
|
||
|
lastN = n;
|
||
|
|
||
|
cursor.CR();
|
||
|
process.stdout.write('\u001b[J');
|
||
|
process.stdout.write(color('progress', ' ' + options.open));
|
||
|
process.stdout.write(Array(n).join(options.complete));
|
||
|
process.stdout.write(Array(i).join(options.incomplete));
|
||
|
process.stdout.write(color('progress', options.close));
|
||
|
if (options.verbose) {
|
||
|
process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// tests are complete, output some stats
|
||
|
// and the failures if any
|
||
|
runner.once('end', function() {
|
||
|
cursor.show();
|
||
|
console.log();
|
||
|
self.epilogue();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(Progress, Base);
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"../utils":36,"./base":16,"_process":56}],29:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Spec
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var inherits = require('../utils').inherits;
|
||
|
var color = Base.color;
|
||
|
|
||
|
/**
|
||
|
* Expose `Spec`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Spec;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Spec` test reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function Spec(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var self = this;
|
||
|
var indents = 0;
|
||
|
var n = 0;
|
||
|
|
||
|
function indent() {
|
||
|
return Array(indents).join(' ');
|
||
|
}
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
console.log();
|
||
|
});
|
||
|
|
||
|
runner.on('suite', function(suite) {
|
||
|
++indents;
|
||
|
console.log(color('suite', '%s%s'), indent(), suite.title);
|
||
|
});
|
||
|
|
||
|
runner.on('suite end', function() {
|
||
|
--indents;
|
||
|
if (indents === 1) {
|
||
|
console.log();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function(test) {
|
||
|
var fmt = indent() + color('pending', ' - %s');
|
||
|
console.log(fmt, test.title);
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
var fmt;
|
||
|
if (test.speed === 'fast') {
|
||
|
fmt =
|
||
|
indent() +
|
||
|
color('checkmark', ' ' + Base.symbols.ok) +
|
||
|
color('pass', ' %s');
|
||
|
console.log(fmt, test.title);
|
||
|
} else {
|
||
|
fmt =
|
||
|
indent() +
|
||
|
color('checkmark', ' ' + Base.symbols.ok) +
|
||
|
color('pass', ' %s') +
|
||
|
color(test.speed, ' (%dms)');
|
||
|
console.log(fmt, test.title, test.duration);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test) {
|
||
|
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
|
||
|
});
|
||
|
|
||
|
runner.once('end', self.epilogue.bind(self));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(Spec, Base);
|
||
|
|
||
|
},{"../utils":36,"./base":16}],30:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module TAP
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
|
||
|
/**
|
||
|
* Expose `TAP`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = TAP;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `TAP` reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function TAP(runner) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var n = 1;
|
||
|
var passes = 0;
|
||
|
var failures = 0;
|
||
|
|
||
|
runner.on('start', function() {
|
||
|
var total = runner.grepTotal(runner.suite);
|
||
|
console.log('%d..%d', 1, total);
|
||
|
});
|
||
|
|
||
|
runner.on('test end', function() {
|
||
|
++n;
|
||
|
});
|
||
|
|
||
|
runner.on('pending', function(test) {
|
||
|
console.log('ok %d %s # SKIP -', n, title(test));
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
passes++;
|
||
|
console.log('ok %d %s', n, title(test));
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test, err) {
|
||
|
failures++;
|
||
|
console.log('not ok %d %s', n, title(test));
|
||
|
if (err.stack) {
|
||
|
console.log(err.stack.replace(/^/gm, ' '));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
console.log('# tests ' + (passes + failures));
|
||
|
console.log('# pass ' + passes);
|
||
|
console.log('# fail ' + failures);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a TAP-safe title of `test`
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} test
|
||
|
* @return {String}
|
||
|
*/
|
||
|
function title(test) {
|
||
|
return test.fullTitle().replace(/#/g, '');
|
||
|
}
|
||
|
|
||
|
},{"./base":16}],31:[function(require,module,exports){
|
||
|
(function (process,global){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module XUnit
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var Base = require('./base');
|
||
|
var utils = require('../utils');
|
||
|
var inherits = utils.inherits;
|
||
|
var fs = require('fs');
|
||
|
var escape = utils.escape;
|
||
|
var mkdirp = require('mkdirp');
|
||
|
var path = require('path');
|
||
|
|
||
|
/**
|
||
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
||
|
*/
|
||
|
|
||
|
/* eslint-disable no-unused-vars, no-native-reassign */
|
||
|
var Date = global.Date;
|
||
|
var setTimeout = global.setTimeout;
|
||
|
var setInterval = global.setInterval;
|
||
|
var clearTimeout = global.clearTimeout;
|
||
|
var clearInterval = global.clearInterval;
|
||
|
/* eslint-enable no-unused-vars, no-native-reassign */
|
||
|
|
||
|
/**
|
||
|
* Expose `XUnit`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = XUnit;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `XUnit` reporter.
|
||
|
*
|
||
|
* @public
|
||
|
* @class
|
||
|
* @memberof Mocha.reporters
|
||
|
* @extends Mocha.reporters.Base
|
||
|
* @api public
|
||
|
* @param {Runner} runner
|
||
|
*/
|
||
|
function XUnit(runner, options) {
|
||
|
Base.call(this, runner);
|
||
|
|
||
|
var stats = this.stats;
|
||
|
var tests = [];
|
||
|
var self = this;
|
||
|
|
||
|
// the name of the test suite, as it will appear in the resulting XML file
|
||
|
var suiteName;
|
||
|
|
||
|
// the default name of the test suite if none is provided
|
||
|
var DEFAULT_SUITE_NAME = 'Mocha Tests';
|
||
|
|
||
|
if (options && options.reporterOptions) {
|
||
|
if (options.reporterOptions.output) {
|
||
|
if (!fs.createWriteStream) {
|
||
|
throw new Error('file output not supported in browser');
|
||
|
}
|
||
|
|
||
|
mkdirp.sync(path.dirname(options.reporterOptions.output));
|
||
|
self.fileStream = fs.createWriteStream(options.reporterOptions.output);
|
||
|
}
|
||
|
|
||
|
// get the suite name from the reporter options (if provided)
|
||
|
suiteName = options.reporterOptions.suiteName;
|
||
|
}
|
||
|
|
||
|
// fall back to the default suite name
|
||
|
suiteName = suiteName || DEFAULT_SUITE_NAME;
|
||
|
|
||
|
runner.on('pending', function(test) {
|
||
|
tests.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('pass', function(test) {
|
||
|
tests.push(test);
|
||
|
});
|
||
|
|
||
|
runner.on('fail', function(test) {
|
||
|
tests.push(test);
|
||
|
});
|
||
|
|
||
|
runner.once('end', function() {
|
||
|
self.write(
|
||
|
tag(
|
||
|
'testsuite',
|
||
|
{
|
||
|
name: suiteName,
|
||
|
tests: stats.tests,
|
||
|
failures: stats.failures,
|
||
|
errors: stats.failures,
|
||
|
skipped: stats.tests - stats.failures - stats.passes,
|
||
|
timestamp: new Date().toUTCString(),
|
||
|
time: stats.duration / 1000 || 0
|
||
|
},
|
||
|
false
|
||
|
)
|
||
|
);
|
||
|
|
||
|
tests.forEach(function(t) {
|
||
|
self.test(t);
|
||
|
});
|
||
|
|
||
|
self.write('</testsuite>');
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Base.prototype`.
|
||
|
*/
|
||
|
inherits(XUnit, Base);
|
||
|
|
||
|
/**
|
||
|
* Override done to close the stream (if it's a file).
|
||
|
*
|
||
|
* @param failures
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
XUnit.prototype.done = function(failures, fn) {
|
||
|
if (this.fileStream) {
|
||
|
this.fileStream.end(function() {
|
||
|
fn(failures);
|
||
|
});
|
||
|
} else {
|
||
|
fn(failures);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Write out the given line.
|
||
|
*
|
||
|
* @param {string} line
|
||
|
*/
|
||
|
XUnit.prototype.write = function(line) {
|
||
|
if (this.fileStream) {
|
||
|
this.fileStream.write(line + '\n');
|
||
|
} else if (typeof process === 'object' && process.stdout) {
|
||
|
process.stdout.write(line + '\n');
|
||
|
} else {
|
||
|
console.log(line);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Output tag for the given `test.`
|
||
|
*
|
||
|
* @param {Test} test
|
||
|
*/
|
||
|
XUnit.prototype.test = function(test) {
|
||
|
var attrs = {
|
||
|
classname: test.parent.fullTitle(),
|
||
|
name: test.title,
|
||
|
time: test.duration / 1000 || 0
|
||
|
};
|
||
|
|
||
|
if (test.state === 'failed') {
|
||
|
var err = test.err;
|
||
|
this.write(
|
||
|
tag(
|
||
|
'testcase',
|
||
|
attrs,
|
||
|
false,
|
||
|
tag(
|
||
|
'failure',
|
||
|
{},
|
||
|
false,
|
||
|
escape(err.message) + '\n' + escape(err.stack)
|
||
|
)
|
||
|
)
|
||
|
);
|
||
|
} else if (test.isPending()) {
|
||
|
this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
|
||
|
} else {
|
||
|
this.write(tag('testcase', attrs, true));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* HTML tag helper.
|
||
|
*
|
||
|
* @param name
|
||
|
* @param attrs
|
||
|
* @param close
|
||
|
* @param content
|
||
|
* @return {string}
|
||
|
*/
|
||
|
function tag(name, attrs, close, content) {
|
||
|
var end = close ? '/>' : '>';
|
||
|
var pairs = [];
|
||
|
var tag;
|
||
|
|
||
|
for (var key in attrs) {
|
||
|
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
|
||
|
pairs.push(key + '="' + escape(attrs[key]) + '"');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
|
||
|
if (content) {
|
||
|
tag += content + '</' + name + end;
|
||
|
}
|
||
|
return tag;
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"../utils":36,"./base":16,"_process":56,"fs":40,"mkdirp":53,"path":40}],32:[function(require,module,exports){
|
||
|
(function (global){
|
||
|
'use strict';
|
||
|
var EventEmitter = require('events').EventEmitter;
|
||
|
var Pending = require('./pending');
|
||
|
var debug = require('debug')('mocha:runnable');
|
||
|
var milliseconds = require('./ms');
|
||
|
var utils = require('./utils');
|
||
|
|
||
|
/**
|
||
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
||
|
*/
|
||
|
|
||
|
/* eslint-disable no-unused-vars, no-native-reassign */
|
||
|
var Date = global.Date;
|
||
|
var setTimeout = global.setTimeout;
|
||
|
var setInterval = global.setInterval;
|
||
|
var clearTimeout = global.clearTimeout;
|
||
|
var clearInterval = global.clearInterval;
|
||
|
/* eslint-enable no-unused-vars, no-native-reassign */
|
||
|
|
||
|
var toString = Object.prototype.toString;
|
||
|
|
||
|
module.exports = Runnable;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Runnable` with the given `title` and callback `fn`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||
|
*
|
||
|
* @class
|
||
|
* @extends EventEmitter
|
||
|
* @param {String} title
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
function Runnable(title, fn) {
|
||
|
this.title = title;
|
||
|
this.fn = fn;
|
||
|
this.body = (fn || '').toString();
|
||
|
this.async = fn && fn.length;
|
||
|
this.sync = !this.async;
|
||
|
this._timeout = 2000;
|
||
|
this._slow = 75;
|
||
|
this._enableTimeouts = true;
|
||
|
this.timedOut = false;
|
||
|
this._retries = -1;
|
||
|
this._currentRetry = 0;
|
||
|
this.pending = false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `EventEmitter.prototype`.
|
||
|
*/
|
||
|
utils.inherits(Runnable, EventEmitter);
|
||
|
|
||
|
/**
|
||
|
* Set & get timeout `ms`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number|string} ms
|
||
|
* @return {Runnable|number} ms or Runnable instance.
|
||
|
*/
|
||
|
Runnable.prototype.timeout = function(ms) {
|
||
|
if (!arguments.length) {
|
||
|
return this._timeout;
|
||
|
}
|
||
|
// see #1652 for reasoning
|
||
|
if (ms === 0 || ms > Math.pow(2, 31)) {
|
||
|
this._enableTimeouts = false;
|
||
|
}
|
||
|
if (typeof ms === 'string') {
|
||
|
ms = milliseconds(ms);
|
||
|
}
|
||
|
debug('timeout %d', ms);
|
||
|
this._timeout = ms;
|
||
|
if (this.timer) {
|
||
|
this.resetTimeout();
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get slow `ms`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number|string} ms
|
||
|
* @return {Runnable|number} ms or Runnable instance.
|
||
|
*/
|
||
|
Runnable.prototype.slow = function(ms) {
|
||
|
if (!arguments.length || typeof ms === 'undefined') {
|
||
|
return this._slow;
|
||
|
}
|
||
|
if (typeof ms === 'string') {
|
||
|
ms = milliseconds(ms);
|
||
|
}
|
||
|
debug('slow %d', ms);
|
||
|
this._slow = ms;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set and get whether timeout is `enabled`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {boolean} enabled
|
||
|
* @return {Runnable|boolean} enabled or Runnable instance.
|
||
|
*/
|
||
|
Runnable.prototype.enableTimeouts = function(enabled) {
|
||
|
if (!arguments.length) {
|
||
|
return this._enableTimeouts;
|
||
|
}
|
||
|
debug('enableTimeouts %s', enabled);
|
||
|
this._enableTimeouts = enabled;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Halt and mark as pending.
|
||
|
*
|
||
|
* @memberof Mocha.Runnable
|
||
|
* @public
|
||
|
* @api public
|
||
|
*/
|
||
|
Runnable.prototype.skip = function() {
|
||
|
throw new Pending('sync skip');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Check if this runnable or its parent suite is marked as pending.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Runnable.prototype.isPending = function() {
|
||
|
return this.pending || (this.parent && this.parent.isPending());
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return `true` if this Runnable has failed.
|
||
|
* @return {boolean}
|
||
|
* @private
|
||
|
*/
|
||
|
Runnable.prototype.isFailed = function() {
|
||
|
return !this.isPending() && this.state === 'failed';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return `true` if this Runnable has passed.
|
||
|
* @return {boolean}
|
||
|
* @private
|
||
|
*/
|
||
|
Runnable.prototype.isPassed = function() {
|
||
|
return !this.isPending() && this.state === 'passed';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get number of retries.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Runnable.prototype.retries = function(n) {
|
||
|
if (!arguments.length) {
|
||
|
return this._retries;
|
||
|
}
|
||
|
this._retries = n;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get current retry
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Runnable.prototype.currentRetry = function(n) {
|
||
|
if (!arguments.length) {
|
||
|
return this._currentRetry;
|
||
|
}
|
||
|
this._currentRetry = n;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return the full title generated by recursively concatenating the parent's
|
||
|
* full title.
|
||
|
*
|
||
|
* @memberof Mocha.Runnable
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @return {string}
|
||
|
*/
|
||
|
Runnable.prototype.fullTitle = function() {
|
||
|
return this.titlePath().join(' ');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return the title path generated by concatenating the parent's title path with the title.
|
||
|
*
|
||
|
* @memberof Mocha.Runnable
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @return {string}
|
||
|
*/
|
||
|
Runnable.prototype.titlePath = function() {
|
||
|
return this.parent.titlePath().concat([this.title]);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Clear the timeout.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Runnable.prototype.clearTimeout = function() {
|
||
|
clearTimeout(this.timer);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Inspect the runnable void of private properties.
|
||
|
*
|
||
|
* @api private
|
||
|
* @return {string}
|
||
|
*/
|
||
|
Runnable.prototype.inspect = function() {
|
||
|
return JSON.stringify(
|
||
|
this,
|
||
|
function(key, val) {
|
||
|
if (key[0] === '_') {
|
||
|
return;
|
||
|
}
|
||
|
if (key === 'parent') {
|
||
|
return '#<Suite>';
|
||
|
}
|
||
|
if (key === 'ctx') {
|
||
|
return '#<Context>';
|
||
|
}
|
||
|
return val;
|
||
|
},
|
||
|
2
|
||
|
);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Reset the timeout.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Runnable.prototype.resetTimeout = function() {
|
||
|
var self = this;
|
||
|
var ms = this.timeout() || 1e9;
|
||
|
|
||
|
if (!this._enableTimeouts) {
|
||
|
return;
|
||
|
}
|
||
|
this.clearTimeout();
|
||
|
this.timer = setTimeout(function() {
|
||
|
if (!self._enableTimeouts) {
|
||
|
return;
|
||
|
}
|
||
|
self.callback(self._timeoutError(ms));
|
||
|
self.timedOut = true;
|
||
|
}, ms);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get a list of whitelisted globals for this test run.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string[]} globals
|
||
|
*/
|
||
|
Runnable.prototype.globals = function(globals) {
|
||
|
if (!arguments.length) {
|
||
|
return this._allowedGlobals;
|
||
|
}
|
||
|
this._allowedGlobals = globals;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run the test and invoke `fn(err)`.
|
||
|
*
|
||
|
* @param {Function} fn
|
||
|
* @api private
|
||
|
*/
|
||
|
Runnable.prototype.run = function(fn) {
|
||
|
var self = this;
|
||
|
var start = new Date();
|
||
|
var ctx = this.ctx;
|
||
|
var finished;
|
||
|
var emitted;
|
||
|
|
||
|
// Sometimes the ctx exists, but it is not runnable
|
||
|
if (ctx && ctx.runnable) {
|
||
|
ctx.runnable(this);
|
||
|
}
|
||
|
|
||
|
// called multiple times
|
||
|
function multiple(err) {
|
||
|
if (emitted) {
|
||
|
return;
|
||
|
}
|
||
|
emitted = true;
|
||
|
var msg = 'done() called multiple times';
|
||
|
if (err && err.message) {
|
||
|
err.message += " (and Mocha's " + msg + ')';
|
||
|
self.emit('error', err);
|
||
|
} else {
|
||
|
self.emit('error', new Error(msg));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// finished
|
||
|
function done(err) {
|
||
|
var ms = self.timeout();
|
||
|
if (self.timedOut) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (finished) {
|
||
|
return multiple(err);
|
||
|
}
|
||
|
|
||
|
self.clearTimeout();
|
||
|
self.duration = new Date() - start;
|
||
|
finished = true;
|
||
|
if (!err && self.duration > ms && self._enableTimeouts) {
|
||
|
err = self._timeoutError(ms);
|
||
|
}
|
||
|
fn(err);
|
||
|
}
|
||
|
|
||
|
// for .resetTimeout()
|
||
|
this.callback = done;
|
||
|
|
||
|
// explicit async with `done` argument
|
||
|
if (this.async) {
|
||
|
this.resetTimeout();
|
||
|
|
||
|
// allows skip() to be used in an explicit async context
|
||
|
this.skip = function asyncSkip() {
|
||
|
done(new Pending('async skip call'));
|
||
|
// halt execution. the Runnable will be marked pending
|
||
|
// by the previous call, and the uncaught handler will ignore
|
||
|
// the failure.
|
||
|
throw new Pending('async skip; aborting execution');
|
||
|
};
|
||
|
|
||
|
if (this.allowUncaught) {
|
||
|
return callFnAsync(this.fn);
|
||
|
}
|
||
|
try {
|
||
|
callFnAsync(this.fn);
|
||
|
} catch (err) {
|
||
|
emitted = true;
|
||
|
done(utils.getError(err));
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (this.allowUncaught) {
|
||
|
if (this.isPending()) {
|
||
|
done();
|
||
|
} else {
|
||
|
callFn(this.fn);
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// sync or promise-returning
|
||
|
try {
|
||
|
if (this.isPending()) {
|
||
|
done();
|
||
|
} else {
|
||
|
callFn(this.fn);
|
||
|
}
|
||
|
} catch (err) {
|
||
|
emitted = true;
|
||
|
done(utils.getError(err));
|
||
|
}
|
||
|
|
||
|
function callFn(fn) {
|
||
|
var result = fn.call(ctx);
|
||
|
if (result && typeof result.then === 'function') {
|
||
|
self.resetTimeout();
|
||
|
result.then(
|
||
|
function() {
|
||
|
done();
|
||
|
// Return null so libraries like bluebird do not warn about
|
||
|
// subsequently constructed Promises.
|
||
|
return null;
|
||
|
},
|
||
|
function(reason) {
|
||
|
done(reason || new Error('Promise rejected with no or falsy reason'));
|
||
|
}
|
||
|
);
|
||
|
} else {
|
||
|
if (self.asyncOnly) {
|
||
|
return done(
|
||
|
new Error(
|
||
|
'--async-only option in use without declaring `done()` or returning a promise'
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
done();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function callFnAsync(fn) {
|
||
|
var result = fn.call(ctx, function(err) {
|
||
|
if (err instanceof Error || toString.call(err) === '[object Error]') {
|
||
|
return done(err);
|
||
|
}
|
||
|
if (err) {
|
||
|
if (Object.prototype.toString.call(err) === '[object Object]') {
|
||
|
return done(
|
||
|
new Error('done() invoked with non-Error: ' + JSON.stringify(err))
|
||
|
);
|
||
|
}
|
||
|
return done(new Error('done() invoked with non-Error: ' + err));
|
||
|
}
|
||
|
if (result && utils.isPromise(result)) {
|
||
|
return done(
|
||
|
new Error(
|
||
|
'Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
done();
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Instantiates a "timeout" error
|
||
|
*
|
||
|
* @param {number} ms - Timeout (in milliseconds)
|
||
|
* @returns {Error} a "timeout" error
|
||
|
* @private
|
||
|
*/
|
||
|
Runnable.prototype._timeoutError = function(ms) {
|
||
|
var msg =
|
||
|
'Timeout of ' +
|
||
|
ms +
|
||
|
'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
|
||
|
if (this.file) {
|
||
|
msg += ' (' + this.file + ')';
|
||
|
}
|
||
|
return new Error(msg);
|
||
|
};
|
||
|
|
||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"./ms":14,"./pending":15,"./utils":36,"debug":43,"events":47}],33:[function(require,module,exports){
|
||
|
(function (process,global){
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* @module Runner
|
||
|
*/
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
var EventEmitter = require('events').EventEmitter;
|
||
|
var Pending = require('./pending');
|
||
|
var utils = require('./utils');
|
||
|
var inherits = utils.inherits;
|
||
|
var debug = require('debug')('mocha:runner');
|
||
|
var Runnable = require('./runnable');
|
||
|
var stackFilter = utils.stackTraceFilter();
|
||
|
var stringify = utils.stringify;
|
||
|
var type = utils.type;
|
||
|
var undefinedError = utils.undefinedError;
|
||
|
|
||
|
/**
|
||
|
* Non-enumerable globals.
|
||
|
*/
|
||
|
|
||
|
var globals = [
|
||
|
'setTimeout',
|
||
|
'clearTimeout',
|
||
|
'setInterval',
|
||
|
'clearInterval',
|
||
|
'XMLHttpRequest',
|
||
|
'Date',
|
||
|
'setImmediate',
|
||
|
'clearImmediate'
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* Expose `Runner`.
|
||
|
*/
|
||
|
|
||
|
module.exports = Runner;
|
||
|
|
||
|
/**
|
||
|
* Initialize a `Runner` for the given `suite`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||
|
*
|
||
|
* Events:
|
||
|
*
|
||
|
* - `start` execution started
|
||
|
* - `end` execution complete
|
||
|
* - `suite` (suite) test suite execution started
|
||
|
* - `suite end` (suite) all tests (and sub-suites) have finished
|
||
|
* - `test` (test) test execution started
|
||
|
* - `test end` (test) test completed
|
||
|
* - `hook` (hook) hook execution started
|
||
|
* - `hook end` (hook) hook complete
|
||
|
* - `pass` (test) test passed
|
||
|
* - `fail` (test, err) test failed
|
||
|
* - `pending` (test) test pending
|
||
|
*
|
||
|
* @memberof Mocha
|
||
|
* @public
|
||
|
* @class
|
||
|
* @api public
|
||
|
* @param {Suite} [suite] Root suite
|
||
|
* @param {boolean} [delay] Whether or not to delay execution of root suite
|
||
|
* until ready.
|
||
|
*/
|
||
|
function Runner(suite, delay) {
|
||
|
var self = this;
|
||
|
this._globals = [];
|
||
|
this._abort = false;
|
||
|
this._delay = delay;
|
||
|
this.suite = suite;
|
||
|
this.started = false;
|
||
|
this.total = suite.total();
|
||
|
this.failures = 0;
|
||
|
this.on('test end', function(test) {
|
||
|
self.checkGlobals(test);
|
||
|
});
|
||
|
this.on('hook end', function(hook) {
|
||
|
self.checkGlobals(hook);
|
||
|
});
|
||
|
this._defaultGrep = /.*/;
|
||
|
this.grep(this._defaultGrep);
|
||
|
this.globals(this.globalProps().concat(extraGlobals()));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Wrapper for setImmediate, process.nextTick, or browser polyfill.
|
||
|
*
|
||
|
* @param {Function} fn
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.immediately = global.setImmediate || process.nextTick;
|
||
|
|
||
|
/**
|
||
|
* Inherit from `EventEmitter.prototype`.
|
||
|
*/
|
||
|
inherits(Runner, EventEmitter);
|
||
|
|
||
|
/**
|
||
|
* Run tests with full titles matching `re`. Updates runner.total
|
||
|
* with number of tests matched.
|
||
|
*
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @memberof Mocha.Runner
|
||
|
* @param {RegExp} re
|
||
|
* @param {boolean} invert
|
||
|
* @return {Runner} Runner instance.
|
||
|
*/
|
||
|
Runner.prototype.grep = function(re, invert) {
|
||
|
debug('grep %s', re);
|
||
|
this._grep = re;
|
||
|
this._invert = invert;
|
||
|
this.total = this.grepTotal(this.suite);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Returns the number of tests matching the grep search for the
|
||
|
* given suite.
|
||
|
*
|
||
|
* @memberof Mocha.Runner
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @param {Suite} suite
|
||
|
* @return {number}
|
||
|
*/
|
||
|
Runner.prototype.grepTotal = function(suite) {
|
||
|
var self = this;
|
||
|
var total = 0;
|
||
|
|
||
|
suite.eachTest(function(test) {
|
||
|
var match = self._grep.test(test.fullTitle());
|
||
|
if (self._invert) {
|
||
|
match = !match;
|
||
|
}
|
||
|
if (match) {
|
||
|
total++;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return total;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return a list of global properties.
|
||
|
*
|
||
|
* @return {Array}
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.globalProps = function() {
|
||
|
var props = Object.keys(global);
|
||
|
|
||
|
// non-enumerables
|
||
|
for (var i = 0; i < globals.length; ++i) {
|
||
|
if (~props.indexOf(globals[i])) {
|
||
|
continue;
|
||
|
}
|
||
|
props.push(globals[i]);
|
||
|
}
|
||
|
|
||
|
return props;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Allow the given `arr` of globals.
|
||
|
*
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @memberof Mocha.Runner
|
||
|
* @param {Array} arr
|
||
|
* @return {Runner} Runner instance.
|
||
|
*/
|
||
|
Runner.prototype.globals = function(arr) {
|
||
|
if (!arguments.length) {
|
||
|
return this._globals;
|
||
|
}
|
||
|
debug('globals %j', arr);
|
||
|
this._globals = this._globals.concat(arr);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Check for global variable leaks.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.checkGlobals = function(test) {
|
||
|
if (this.ignoreLeaks) {
|
||
|
return;
|
||
|
}
|
||
|
var ok = this._globals;
|
||
|
|
||
|
var globals = this.globalProps();
|
||
|
var leaks;
|
||
|
|
||
|
if (test) {
|
||
|
ok = ok.concat(test._allowedGlobals || []);
|
||
|
}
|
||
|
|
||
|
if (this.prevGlobalsLength === globals.length) {
|
||
|
return;
|
||
|
}
|
||
|
this.prevGlobalsLength = globals.length;
|
||
|
|
||
|
leaks = filterLeaks(ok, globals);
|
||
|
this._globals = this._globals.concat(leaks);
|
||
|
|
||
|
if (leaks.length > 1) {
|
||
|
this.fail(
|
||
|
test,
|
||
|
new Error('global leaks detected: ' + leaks.join(', ') + '')
|
||
|
);
|
||
|
} else if (leaks.length) {
|
||
|
this.fail(test, new Error('global leak detected: ' + leaks[0]));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Fail the given `test`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Test} test
|
||
|
* @param {Error} err
|
||
|
*/
|
||
|
Runner.prototype.fail = function(test, err) {
|
||
|
if (test.isPending()) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
++this.failures;
|
||
|
test.state = 'failed';
|
||
|
|
||
|
if (!(err instanceof Error || (err && typeof err.message === 'string'))) {
|
||
|
err = new Error(
|
||
|
'the ' +
|
||
|
type(err) +
|
||
|
' ' +
|
||
|
stringify(err) +
|
||
|
' was thrown, throw an Error :)'
|
||
|
);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
err.stack =
|
||
|
this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
|
||
|
} catch (ignore) {
|
||
|
// some environments do not take kindly to monkeying with the stack
|
||
|
}
|
||
|
|
||
|
this.emit('fail', test, err);
|
||
|
if (this.suite.bail()) {
|
||
|
this.emit('end');
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Fail the given `hook` with `err`.
|
||
|
*
|
||
|
* Hook failures work in the following pattern:
|
||
|
* - If bail, then exit
|
||
|
* - Failed `before` hook skips all tests in a suite and subsuites,
|
||
|
* but jumps to corresponding `after` hook
|
||
|
* - Failed `before each` hook skips remaining tests in a
|
||
|
* suite and jumps to corresponding `after each` hook,
|
||
|
* which is run only once
|
||
|
* - Failed `after` hook does not alter
|
||
|
* execution order
|
||
|
* - Failed `after each` hook skips remaining tests in a
|
||
|
* suite and subsuites, but executes other `after each`
|
||
|
* hooks
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Hook} hook
|
||
|
* @param {Error} err
|
||
|
*/
|
||
|
Runner.prototype.failHook = function(hook, err) {
|
||
|
if (hook.ctx && hook.ctx.currentTest) {
|
||
|
hook.originalTitle = hook.originalTitle || hook.title;
|
||
|
hook.title =
|
||
|
hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
|
||
|
}
|
||
|
|
||
|
this.fail(hook, err);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run hook `name` callbacks and then invoke `fn()`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} name
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
|
||
|
Runner.prototype.hook = function(name, fn) {
|
||
|
var suite = this.suite;
|
||
|
var hooks = suite['_' + name];
|
||
|
var self = this;
|
||
|
|
||
|
function next(i) {
|
||
|
var hook = hooks[i];
|
||
|
if (!hook) {
|
||
|
return fn();
|
||
|
}
|
||
|
self.currentRunnable = hook;
|
||
|
|
||
|
hook.ctx.currentTest = self.test;
|
||
|
|
||
|
self.emit('hook', hook);
|
||
|
|
||
|
if (!hook.listeners('error').length) {
|
||
|
hook.on('error', function(err) {
|
||
|
self.failHook(hook, err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
hook.run(function(err) {
|
||
|
var testError = hook.error();
|
||
|
if (testError) {
|
||
|
self.fail(self.test, testError);
|
||
|
}
|
||
|
if (err) {
|
||
|
if (err instanceof Pending) {
|
||
|
if (name === 'beforeEach' || name === 'afterEach') {
|
||
|
self.test.pending = true;
|
||
|
} else {
|
||
|
suite.tests.forEach(function(test) {
|
||
|
test.pending = true;
|
||
|
});
|
||
|
// a pending hook won't be executed twice.
|
||
|
hook.pending = true;
|
||
|
}
|
||
|
} else {
|
||
|
self.failHook(hook, err);
|
||
|
|
||
|
// stop executing hooks, notify callee of hook err
|
||
|
return fn(err);
|
||
|
}
|
||
|
}
|
||
|
self.emit('hook end', hook);
|
||
|
delete hook.ctx.currentTest;
|
||
|
next(++i);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
Runner.immediately(function() {
|
||
|
next(0);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run hook `name` for the given array of `suites`
|
||
|
* in order, and callback `fn(err, errSuite)`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} name
|
||
|
* @param {Array} suites
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
Runner.prototype.hooks = function(name, suites, fn) {
|
||
|
var self = this;
|
||
|
var orig = this.suite;
|
||
|
|
||
|
function next(suite) {
|
||
|
self.suite = suite;
|
||
|
|
||
|
if (!suite) {
|
||
|
self.suite = orig;
|
||
|
return fn();
|
||
|
}
|
||
|
|
||
|
self.hook(name, function(err) {
|
||
|
if (err) {
|
||
|
var errSuite = self.suite;
|
||
|
self.suite = orig;
|
||
|
return fn(err, errSuite);
|
||
|
}
|
||
|
|
||
|
next(suites.pop());
|
||
|
});
|
||
|
}
|
||
|
|
||
|
next(suites.pop());
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run hooks from the top level down.
|
||
|
*
|
||
|
* @param {String} name
|
||
|
* @param {Function} fn
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.hookUp = function(name, fn) {
|
||
|
var suites = [this.suite].concat(this.parents()).reverse();
|
||
|
this.hooks(name, suites, fn);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run hooks from the bottom up.
|
||
|
*
|
||
|
* @param {String} name
|
||
|
* @param {Function} fn
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.hookDown = function(name, fn) {
|
||
|
var suites = [this.suite].concat(this.parents());
|
||
|
this.hooks(name, suites, fn);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return an array of parent Suites from
|
||
|
* closest to furthest.
|
||
|
*
|
||
|
* @return {Array}
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.parents = function() {
|
||
|
var suite = this.suite;
|
||
|
var suites = [];
|
||
|
while (suite.parent) {
|
||
|
suite = suite.parent;
|
||
|
suites.push(suite);
|
||
|
}
|
||
|
return suites;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run the current test and callback `fn(err)`.
|
||
|
*
|
||
|
* @param {Function} fn
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.runTest = function(fn) {
|
||
|
var self = this;
|
||
|
var test = this.test;
|
||
|
|
||
|
if (!test) {
|
||
|
return;
|
||
|
}
|
||
|
if (this.forbidOnly && hasOnly(this.parents().reverse()[0] || this.suite)) {
|
||
|
fn(new Error('`.only` forbidden'));
|
||
|
return;
|
||
|
}
|
||
|
if (this.asyncOnly) {
|
||
|
test.asyncOnly = true;
|
||
|
}
|
||
|
test.on('error', function(err) {
|
||
|
self.fail(test, err);
|
||
|
});
|
||
|
if (this.allowUncaught) {
|
||
|
test.allowUncaught = true;
|
||
|
return test.run(fn);
|
||
|
}
|
||
|
try {
|
||
|
test.run(fn);
|
||
|
} catch (err) {
|
||
|
fn(err);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run tests in the given `suite` and invoke the callback `fn()` when complete.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Suite} suite
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
Runner.prototype.runTests = function(suite, fn) {
|
||
|
var self = this;
|
||
|
var tests = suite.tests.slice();
|
||
|
var test;
|
||
|
|
||
|
function hookErr(_, errSuite, after) {
|
||
|
// before/after Each hook for errSuite failed:
|
||
|
var orig = self.suite;
|
||
|
|
||
|
// for failed 'after each' hook start from errSuite parent,
|
||
|
// otherwise start from errSuite itself
|
||
|
self.suite = after ? errSuite.parent : errSuite;
|
||
|
|
||
|
if (self.suite) {
|
||
|
// call hookUp afterEach
|
||
|
self.hookUp('afterEach', function(err2, errSuite2) {
|
||
|
self.suite = orig;
|
||
|
// some hooks may fail even now
|
||
|
if (err2) {
|
||
|
return hookErr(err2, errSuite2, true);
|
||
|
}
|
||
|
// report error suite
|
||
|
fn(errSuite);
|
||
|
});
|
||
|
} else {
|
||
|
// there is no need calling other 'after each' hooks
|
||
|
self.suite = orig;
|
||
|
fn(errSuite);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function next(err, errSuite) {
|
||
|
// if we bail after first err
|
||
|
if (self.failures && suite._bail) {
|
||
|
return fn();
|
||
|
}
|
||
|
|
||
|
if (self._abort) {
|
||
|
return fn();
|
||
|
}
|
||
|
|
||
|
if (err) {
|
||
|
return hookErr(err, errSuite, true);
|
||
|
}
|
||
|
|
||
|
// next test
|
||
|
test = tests.shift();
|
||
|
|
||
|
// all done
|
||
|
if (!test) {
|
||
|
return fn();
|
||
|
}
|
||
|
|
||
|
// grep
|
||
|
var match = self._grep.test(test.fullTitle());
|
||
|
if (self._invert) {
|
||
|
match = !match;
|
||
|
}
|
||
|
if (!match) {
|
||
|
// Run immediately only if we have defined a grep. When we
|
||
|
// define a grep — It can cause maximum callstack error if
|
||
|
// the grep is doing a large recursive loop by neglecting
|
||
|
// all tests. The run immediately function also comes with
|
||
|
// a performance cost. So we don't want to run immediately
|
||
|
// if we run the whole test suite, because running the whole
|
||
|
// test suite don't do any immediate recursive loops. Thus,
|
||
|
// allowing a JS runtime to breathe.
|
||
|
if (self._grep !== self._defaultGrep) {
|
||
|
Runner.immediately(next);
|
||
|
} else {
|
||
|
next();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (test.isPending()) {
|
||
|
if (self.forbidPending) {
|
||
|
test.isPending = alwaysFalse;
|
||
|
self.fail(test, new Error('Pending test forbidden'));
|
||
|
delete test.isPending;
|
||
|
} else {
|
||
|
self.emit('pending', test);
|
||
|
}
|
||
|
self.emit('test end', test);
|
||
|
return next();
|
||
|
}
|
||
|
|
||
|
// execute test and hook(s)
|
||
|
self.emit('test', (self.test = test));
|
||
|
self.hookDown('beforeEach', function(err, errSuite) {
|
||
|
if (test.isPending()) {
|
||
|
if (self.forbidPending) {
|
||
|
test.isPending = alwaysFalse;
|
||
|
self.fail(test, new Error('Pending test forbidden'));
|
||
|
delete test.isPending;
|
||
|
} else {
|
||
|
self.emit('pending', test);
|
||
|
}
|
||
|
self.emit('test end', test);
|
||
|
return next();
|
||
|
}
|
||
|
if (err) {
|
||
|
return hookErr(err, errSuite, false);
|
||
|
}
|
||
|
self.currentRunnable = self.test;
|
||
|
self.runTest(function(err) {
|
||
|
test = self.test;
|
||
|
if (err) {
|
||
|
var retry = test.currentRetry();
|
||
|
if (err instanceof Pending && self.forbidPending) {
|
||
|
self.fail(test, new Error('Pending test forbidden'));
|
||
|
} else if (err instanceof Pending) {
|
||
|
test.pending = true;
|
||
|
self.emit('pending', test);
|
||
|
} else if (retry < test.retries()) {
|
||
|
var clonedTest = test.clone();
|
||
|
clonedTest.currentRetry(retry + 1);
|
||
|
tests.unshift(clonedTest);
|
||
|
|
||
|
// Early return + hook trigger so that it doesn't
|
||
|
// increment the count wrong
|
||
|
return self.hookUp('afterEach', next);
|
||
|
} else {
|
||
|
self.fail(test, err);
|
||
|
}
|
||
|
self.emit('test end', test);
|
||
|
|
||
|
if (err instanceof Pending) {
|
||
|
return next();
|
||
|
}
|
||
|
|
||
|
return self.hookUp('afterEach', next);
|
||
|
}
|
||
|
|
||
|
test.state = 'passed';
|
||
|
self.emit('pass', test);
|
||
|
self.emit('test end', test);
|
||
|
self.hookUp('afterEach', next);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
this.next = next;
|
||
|
this.hookErr = hookErr;
|
||
|
next();
|
||
|
};
|
||
|
|
||
|
function alwaysFalse() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Run the given `suite` and invoke the callback `fn()` when complete.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Suite} suite
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
Runner.prototype.runSuite = function(suite, fn) {
|
||
|
var i = 0;
|
||
|
var self = this;
|
||
|
var total = this.grepTotal(suite);
|
||
|
var afterAllHookCalled = false;
|
||
|
|
||
|
debug('run suite %s', suite.fullTitle());
|
||
|
|
||
|
if (!total || (self.failures && suite._bail)) {
|
||
|
return fn();
|
||
|
}
|
||
|
|
||
|
this.emit('suite', (this.suite = suite));
|
||
|
|
||
|
function next(errSuite) {
|
||
|
if (errSuite) {
|
||
|
// current suite failed on a hook from errSuite
|
||
|
if (errSuite === suite) {
|
||
|
// if errSuite is current suite
|
||
|
// continue to the next sibling suite
|
||
|
return done();
|
||
|
}
|
||
|
// errSuite is among the parents of current suite
|
||
|
// stop execution of errSuite and all sub-suites
|
||
|
return done(errSuite);
|
||
|
}
|
||
|
|
||
|
if (self._abort) {
|
||
|
return done();
|
||
|
}
|
||
|
|
||
|
var curr = suite.suites[i++];
|
||
|
if (!curr) {
|
||
|
return done();
|
||
|
}
|
||
|
|
||
|
// Avoid grep neglecting large number of tests causing a
|
||
|
// huge recursive loop and thus a maximum call stack error.
|
||
|
// See comment in `this.runTests()` for more information.
|
||
|
if (self._grep !== self._defaultGrep) {
|
||
|
Runner.immediately(function() {
|
||
|
self.runSuite(curr, next);
|
||
|
});
|
||
|
} else {
|
||
|
self.runSuite(curr, next);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function done(errSuite) {
|
||
|
self.suite = suite;
|
||
|
self.nextSuite = next;
|
||
|
|
||
|
if (afterAllHookCalled) {
|
||
|
fn(errSuite);
|
||
|
} else {
|
||
|
// mark that the afterAll block has been called once
|
||
|
// and so can be skipped if there is an error in it.
|
||
|
afterAllHookCalled = true;
|
||
|
|
||
|
// remove reference to test
|
||
|
delete self.test;
|
||
|
|
||
|
self.hook('afterAll', function() {
|
||
|
self.emit('suite end', suite);
|
||
|
fn(errSuite);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
this.nextSuite = next;
|
||
|
|
||
|
this.hook('beforeAll', function(err) {
|
||
|
if (err) {
|
||
|
return done();
|
||
|
}
|
||
|
self.runTests(suite, next);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Handle uncaught exceptions.
|
||
|
*
|
||
|
* @param {Error} err
|
||
|
* @api private
|
||
|
*/
|
||
|
Runner.prototype.uncaught = function(err) {
|
||
|
if (err) {
|
||
|
debug(
|
||
|
'uncaught exception %s',
|
||
|
err ===
|
||
|
function() {
|
||
|
return this;
|
||
|
}.call(err)
|
||
|
? err.message || err
|
||
|
: err
|
||
|
);
|
||
|
} else {
|
||
|
debug('uncaught undefined exception');
|
||
|
err = undefinedError();
|
||
|
}
|
||
|
err.uncaught = true;
|
||
|
|
||
|
var runnable = this.currentRunnable;
|
||
|
|
||
|
if (!runnable) {
|
||
|
runnable = new Runnable('Uncaught error outside test suite');
|
||
|
runnable.parent = this.suite;
|
||
|
|
||
|
if (this.started) {
|
||
|
this.fail(runnable, err);
|
||
|
} else {
|
||
|
// Can't recover from this failure
|
||
|
this.emit('start');
|
||
|
this.fail(runnable, err);
|
||
|
this.emit('end');
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
runnable.clearTimeout();
|
||
|
|
||
|
// Ignore errors if already failed or pending
|
||
|
// See #3226
|
||
|
if (runnable.isFailed() || runnable.isPending()) {
|
||
|
return;
|
||
|
}
|
||
|
// we cannot recover gracefully if a Runnable has already passed
|
||
|
// then fails asynchronously
|
||
|
var alreadyPassed = runnable.isPassed();
|
||
|
// this will change the state to "failed" regardless of the current value
|
||
|
this.fail(runnable, err);
|
||
|
if (!alreadyPassed) {
|
||
|
// recover from test
|
||
|
if (runnable.type === 'test') {
|
||
|
this.emit('test end', runnable);
|
||
|
this.hookUp('afterEach', this.next);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// recover from hooks
|
||
|
var errSuite = this.suite;
|
||
|
// if hook failure is in afterEach block
|
||
|
if (runnable.fullTitle().indexOf('after each') > -1) {
|
||
|
return this.hookErr(err, errSuite, true);
|
||
|
}
|
||
|
// if hook failure is in beforeEach block
|
||
|
if (runnable.fullTitle().indexOf('before each') > -1) {
|
||
|
return this.hookErr(err, errSuite, false);
|
||
|
}
|
||
|
// if hook failure is in after or before blocks
|
||
|
return this.nextSuite(errSuite);
|
||
|
}
|
||
|
|
||
|
// bail
|
||
|
this.emit('end');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Cleans up the references to all the deferred functions
|
||
|
* (before/after/beforeEach/afterEach) and tests of a Suite.
|
||
|
* These must be deleted otherwise a memory leak can happen,
|
||
|
* as those functions may reference variables from closures,
|
||
|
* thus those variables can never be garbage collected as long
|
||
|
* as the deferred functions exist.
|
||
|
*
|
||
|
* @param {Suite} suite
|
||
|
*/
|
||
|
function cleanSuiteReferences(suite) {
|
||
|
function cleanArrReferences(arr) {
|
||
|
for (var i = 0; i < arr.length; i++) {
|
||
|
delete arr[i].fn;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (Array.isArray(suite._beforeAll)) {
|
||
|
cleanArrReferences(suite._beforeAll);
|
||
|
}
|
||
|
|
||
|
if (Array.isArray(suite._beforeEach)) {
|
||
|
cleanArrReferences(suite._beforeEach);
|
||
|
}
|
||
|
|
||
|
if (Array.isArray(suite._afterAll)) {
|
||
|
cleanArrReferences(suite._afterAll);
|
||
|
}
|
||
|
|
||
|
if (Array.isArray(suite._afterEach)) {
|
||
|
cleanArrReferences(suite._afterEach);
|
||
|
}
|
||
|
|
||
|
for (var i = 0; i < suite.tests.length; i++) {
|
||
|
delete suite.tests[i].fn;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Run the root suite and invoke `fn(failures)`
|
||
|
* on completion.
|
||
|
*
|
||
|
* @api public
|
||
|
* @public
|
||
|
* @memberof Mocha.Runner
|
||
|
* @param {Function} fn
|
||
|
* @return {Runner} Runner instance.
|
||
|
*/
|
||
|
Runner.prototype.run = function(fn) {
|
||
|
var self = this;
|
||
|
var rootSuite = this.suite;
|
||
|
|
||
|
fn = fn || function() {};
|
||
|
|
||
|
function uncaught(err) {
|
||
|
self.uncaught(err);
|
||
|
}
|
||
|
|
||
|
function start() {
|
||
|
// If there is an `only` filter
|
||
|
if (hasOnly(rootSuite)) {
|
||
|
filterOnly(rootSuite);
|
||
|
}
|
||
|
self.started = true;
|
||
|
self.emit('start');
|
||
|
self.runSuite(rootSuite, function() {
|
||
|
debug('finished running');
|
||
|
self.emit('end');
|
||
|
});
|
||
|
}
|
||
|
|
||
|
debug('start');
|
||
|
|
||
|
// references cleanup to avoid memory leaks
|
||
|
this.on('suite end', cleanSuiteReferences);
|
||
|
|
||
|
// callback
|
||
|
this.on('end', function() {
|
||
|
debug('end');
|
||
|
process.removeListener('uncaughtException', uncaught);
|
||
|
fn(self.failures);
|
||
|
});
|
||
|
|
||
|
// uncaught exception
|
||
|
process.on('uncaughtException', uncaught);
|
||
|
|
||
|
if (this._delay) {
|
||
|
// for reporters, I guess.
|
||
|
// might be nice to debounce some dots while we wait.
|
||
|
this.emit('waiting', rootSuite);
|
||
|
rootSuite.once('run', start);
|
||
|
} else {
|
||
|
start();
|
||
|
}
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Cleanly abort execution.
|
||
|
*
|
||
|
* @memberof Mocha.Runner
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @return {Runner} Runner instance.
|
||
|
*/
|
||
|
Runner.prototype.abort = function() {
|
||
|
debug('aborting');
|
||
|
this._abort = true;
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Filter suites based on `isOnly` logic.
|
||
|
*
|
||
|
* @param {Array} suite
|
||
|
* @returns {Boolean}
|
||
|
* @api private
|
||
|
*/
|
||
|
function filterOnly(suite) {
|
||
|
if (suite._onlyTests.length) {
|
||
|
// If the suite contains `only` tests, run those and ignore any nested suites.
|
||
|
suite.tests = suite._onlyTests;
|
||
|
suite.suites = [];
|
||
|
} else {
|
||
|
// Otherwise, do not run any of the tests in this suite.
|
||
|
suite.tests = [];
|
||
|
suite._onlySuites.forEach(function(onlySuite) {
|
||
|
// If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
|
||
|
// Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
|
||
|
if (hasOnly(onlySuite)) {
|
||
|
filterOnly(onlySuite);
|
||
|
}
|
||
|
});
|
||
|
// Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
|
||
|
suite.suites = suite.suites.filter(function(childSuite) {
|
||
|
return (
|
||
|
suite._onlySuites.indexOf(childSuite) !== -1 || filterOnly(childSuite)
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
// Keep the suite only if there is something to run
|
||
|
return suite.tests.length || suite.suites.length;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determines whether a suite has an `only` test or suite as a descendant.
|
||
|
*
|
||
|
* @param {Array} suite
|
||
|
* @returns {Boolean}
|
||
|
* @api private
|
||
|
*/
|
||
|
function hasOnly(suite) {
|
||
|
return (
|
||
|
suite._onlyTests.length ||
|
||
|
suite._onlySuites.length ||
|
||
|
suite.suites.some(hasOnly)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Filter leaks with the given globals flagged as `ok`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Array} ok
|
||
|
* @param {Array} globals
|
||
|
* @return {Array}
|
||
|
*/
|
||
|
function filterLeaks(ok, globals) {
|
||
|
return globals.filter(function(key) {
|
||
|
// Firefox and Chrome exposes iframes as index inside the window object
|
||
|
if (/^\d+/.test(key)) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// in firefox
|
||
|
// if runner runs in an iframe, this iframe's window.getInterface method
|
||
|
// not init at first it is assigned in some seconds
|
||
|
if (global.navigator && /^getInterface/.test(key)) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// an iframe could be approached by window[iframeIndex]
|
||
|
// in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
|
||
|
if (global.navigator && /^\d+/.test(key)) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// Opera and IE expose global variables for HTML element IDs (issue #243)
|
||
|
if (/^mocha-/.test(key)) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
var matched = ok.filter(function(ok) {
|
||
|
if (~ok.indexOf('*')) {
|
||
|
return key.indexOf(ok.split('*')[0]) === 0;
|
||
|
}
|
||
|
return key === ok;
|
||
|
});
|
||
|
return !matched.length && (!global.navigator || key !== 'onerror');
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Array of globals dependent on the environment.
|
||
|
*
|
||
|
* @return {Array}
|
||
|
* @api private
|
||
|
*/
|
||
|
function extraGlobals() {
|
||
|
if (typeof process === 'object' && typeof process.version === 'string') {
|
||
|
var parts = process.version.split('.');
|
||
|
var nodeVersion = parts.reduce(function(a, v) {
|
||
|
return (a << 8) | v;
|
||
|
});
|
||
|
|
||
|
// 'errno' was renamed to process._errno in v0.9.11.
|
||
|
|
||
|
if (nodeVersion < 0x00090b) {
|
||
|
return ['errno'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"./pending":15,"./runnable":32,"./utils":36,"_process":56,"debug":43,"events":47}],34:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
/**
|
||
|
* @module Suite
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
var EventEmitter = require('events').EventEmitter;
|
||
|
var Hook = require('./hook');
|
||
|
var utils = require('./utils');
|
||
|
var inherits = utils.inherits;
|
||
|
var debug = require('debug')('mocha:suite');
|
||
|
var milliseconds = require('./ms');
|
||
|
|
||
|
/**
|
||
|
* Expose `Suite`.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = Suite;
|
||
|
|
||
|
/**
|
||
|
* Create a new `Suite` with the given `title` and parent `Suite`. When a suite
|
||
|
* with the same title is already present, that suite is returned to provide
|
||
|
* nicer reporter and more flexible meta-testing.
|
||
|
*
|
||
|
* @memberof Mocha
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {Suite} parent
|
||
|
* @param {string} title
|
||
|
* @return {Suite}
|
||
|
*/
|
||
|
exports.create = function(parent, title) {
|
||
|
var suite = new Suite(title, parent.ctx);
|
||
|
suite.parent = parent;
|
||
|
title = suite.fullTitle();
|
||
|
parent.addSuite(suite);
|
||
|
return suite;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Suite` with the given `title` and `ctx`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||
|
*
|
||
|
* @memberof Mocha
|
||
|
* @public
|
||
|
* @class
|
||
|
* @param {string} title
|
||
|
* @param {Context} parentContext
|
||
|
*/
|
||
|
function Suite(title, parentContext) {
|
||
|
if (!utils.isString(title)) {
|
||
|
throw new Error(
|
||
|
'Suite `title` should be a "string" but "' +
|
||
|
typeof title +
|
||
|
'" was given instead.'
|
||
|
);
|
||
|
}
|
||
|
this.title = title;
|
||
|
function Context() {}
|
||
|
Context.prototype = parentContext;
|
||
|
this.ctx = new Context();
|
||
|
this.suites = [];
|
||
|
this.tests = [];
|
||
|
this.pending = false;
|
||
|
this._beforeEach = [];
|
||
|
this._beforeAll = [];
|
||
|
this._afterEach = [];
|
||
|
this._afterAll = [];
|
||
|
this.root = !title;
|
||
|
this._timeout = 2000;
|
||
|
this._enableTimeouts = true;
|
||
|
this._slow = 75;
|
||
|
this._bail = false;
|
||
|
this._retries = -1;
|
||
|
this._onlyTests = [];
|
||
|
this._onlySuites = [];
|
||
|
this.delayed = false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `EventEmitter.prototype`.
|
||
|
*/
|
||
|
inherits(Suite, EventEmitter);
|
||
|
|
||
|
/**
|
||
|
* Return a clone of this `Suite`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @return {Suite}
|
||
|
*/
|
||
|
Suite.prototype.clone = function() {
|
||
|
var suite = new Suite(this.title);
|
||
|
debug('clone');
|
||
|
suite.ctx = this.ctx;
|
||
|
suite.timeout(this.timeout());
|
||
|
suite.retries(this.retries());
|
||
|
suite.enableTimeouts(this.enableTimeouts());
|
||
|
suite.slow(this.slow());
|
||
|
suite.bail(this.bail());
|
||
|
return suite;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get timeout `ms` or short-hand such as "2s".
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number|string} ms
|
||
|
* @return {Suite|number} for chaining
|
||
|
*/
|
||
|
Suite.prototype.timeout = function(ms) {
|
||
|
if (!arguments.length) {
|
||
|
return this._timeout;
|
||
|
}
|
||
|
if (ms.toString() === '0') {
|
||
|
this._enableTimeouts = false;
|
||
|
}
|
||
|
if (typeof ms === 'string') {
|
||
|
ms = milliseconds(ms);
|
||
|
}
|
||
|
debug('timeout %d', ms);
|
||
|
this._timeout = parseInt(ms, 10);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get number of times to retry a failed test.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number|string} n
|
||
|
* @return {Suite|number} for chaining
|
||
|
*/
|
||
|
Suite.prototype.retries = function(n) {
|
||
|
if (!arguments.length) {
|
||
|
return this._retries;
|
||
|
}
|
||
|
debug('retries %d', n);
|
||
|
this._retries = parseInt(n, 10) || 0;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get timeout to `enabled`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {boolean} enabled
|
||
|
* @return {Suite|boolean} self or enabled
|
||
|
*/
|
||
|
Suite.prototype.enableTimeouts = function(enabled) {
|
||
|
if (!arguments.length) {
|
||
|
return this._enableTimeouts;
|
||
|
}
|
||
|
debug('enableTimeouts %s', enabled);
|
||
|
this._enableTimeouts = enabled;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get slow `ms` or short-hand such as "2s".
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {number|string} ms
|
||
|
* @return {Suite|number} for chaining
|
||
|
*/
|
||
|
Suite.prototype.slow = function(ms) {
|
||
|
if (!arguments.length) {
|
||
|
return this._slow;
|
||
|
}
|
||
|
if (typeof ms === 'string') {
|
||
|
ms = milliseconds(ms);
|
||
|
}
|
||
|
debug('slow %d', ms);
|
||
|
this._slow = ms;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set or get whether to bail after first error.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {boolean} bail
|
||
|
* @return {Suite|number} for chaining
|
||
|
*/
|
||
|
Suite.prototype.bail = function(bail) {
|
||
|
if (!arguments.length) {
|
||
|
return this._bail;
|
||
|
}
|
||
|
debug('bail %s', bail);
|
||
|
this._bail = bail;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Check if this suite or its parent suite is marked as pending.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
Suite.prototype.isPending = function() {
|
||
|
return this.pending || (this.parent && this.parent.isPending());
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Generic hook-creator.
|
||
|
* @private
|
||
|
* @param {string} title - Title of hook
|
||
|
* @param {Function} fn - Hook callback
|
||
|
* @returns {Hook} A new hook
|
||
|
*/
|
||
|
Suite.prototype._createHook = function(title, fn) {
|
||
|
var hook = new Hook(title, fn);
|
||
|
hook.parent = this;
|
||
|
hook.timeout(this.timeout());
|
||
|
hook.retries(this.retries());
|
||
|
hook.enableTimeouts(this.enableTimeouts());
|
||
|
hook.slow(this.slow());
|
||
|
hook.ctx = this.ctx;
|
||
|
hook.file = this.file;
|
||
|
return hook;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run `fn(test[, done])` before running tests.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} title
|
||
|
* @param {Function} fn
|
||
|
* @return {Suite} for chaining
|
||
|
*/
|
||
|
Suite.prototype.beforeAll = function(title, fn) {
|
||
|
if (this.isPending()) {
|
||
|
return this;
|
||
|
}
|
||
|
if (typeof title === 'function') {
|
||
|
fn = title;
|
||
|
title = fn.name;
|
||
|
}
|
||
|
title = '"before all" hook' + (title ? ': ' + title : '');
|
||
|
|
||
|
var hook = this._createHook(title, fn);
|
||
|
this._beforeAll.push(hook);
|
||
|
this.emit('beforeAll', hook);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run `fn(test[, done])` after running tests.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} title
|
||
|
* @param {Function} fn
|
||
|
* @return {Suite} for chaining
|
||
|
*/
|
||
|
Suite.prototype.afterAll = function(title, fn) {
|
||
|
if (this.isPending()) {
|
||
|
return this;
|
||
|
}
|
||
|
if (typeof title === 'function') {
|
||
|
fn = title;
|
||
|
title = fn.name;
|
||
|
}
|
||
|
title = '"after all" hook' + (title ? ': ' + title : '');
|
||
|
|
||
|
var hook = this._createHook(title, fn);
|
||
|
this._afterAll.push(hook);
|
||
|
this.emit('afterAll', hook);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run `fn(test[, done])` before each test case.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} title
|
||
|
* @param {Function} fn
|
||
|
* @return {Suite} for chaining
|
||
|
*/
|
||
|
Suite.prototype.beforeEach = function(title, fn) {
|
||
|
if (this.isPending()) {
|
||
|
return this;
|
||
|
}
|
||
|
if (typeof title === 'function') {
|
||
|
fn = title;
|
||
|
title = fn.name;
|
||
|
}
|
||
|
title = '"before each" hook' + (title ? ': ' + title : '');
|
||
|
|
||
|
var hook = this._createHook(title, fn);
|
||
|
this._beforeEach.push(hook);
|
||
|
this.emit('beforeEach', hook);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Run `fn(test[, done])` after each test case.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} title
|
||
|
* @param {Function} fn
|
||
|
* @return {Suite} for chaining
|
||
|
*/
|
||
|
Suite.prototype.afterEach = function(title, fn) {
|
||
|
if (this.isPending()) {
|
||
|
return this;
|
||
|
}
|
||
|
if (typeof title === 'function') {
|
||
|
fn = title;
|
||
|
title = fn.name;
|
||
|
}
|
||
|
title = '"after each" hook' + (title ? ': ' + title : '');
|
||
|
|
||
|
var hook = this._createHook(title, fn);
|
||
|
this._afterEach.push(hook);
|
||
|
this.emit('afterEach', hook);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Add a test `suite`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Suite} suite
|
||
|
* @return {Suite} for chaining
|
||
|
*/
|
||
|
Suite.prototype.addSuite = function(suite) {
|
||
|
suite.parent = this;
|
||
|
suite.timeout(this.timeout());
|
||
|
suite.retries(this.retries());
|
||
|
suite.enableTimeouts(this.enableTimeouts());
|
||
|
suite.slow(this.slow());
|
||
|
suite.bail(this.bail());
|
||
|
this.suites.push(suite);
|
||
|
this.emit('suite', suite);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Add a `test` to this suite.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Test} test
|
||
|
* @return {Suite} for chaining
|
||
|
*/
|
||
|
Suite.prototype.addTest = function(test) {
|
||
|
test.parent = this;
|
||
|
test.timeout(this.timeout());
|
||
|
test.retries(this.retries());
|
||
|
test.enableTimeouts(this.enableTimeouts());
|
||
|
test.slow(this.slow());
|
||
|
test.ctx = this.ctx;
|
||
|
this.tests.push(test);
|
||
|
this.emit('test', test);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return the full title generated by recursively concatenating the parent's
|
||
|
* full title.
|
||
|
*
|
||
|
* @memberof Mocha.Suite
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @return {string}
|
||
|
*/
|
||
|
Suite.prototype.fullTitle = function() {
|
||
|
return this.titlePath().join(' ');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return the title path generated by recursively concatenating the parent's
|
||
|
* title path.
|
||
|
*
|
||
|
* @memberof Mocha.Suite
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @return {string}
|
||
|
*/
|
||
|
Suite.prototype.titlePath = function() {
|
||
|
var result = [];
|
||
|
if (this.parent) {
|
||
|
result = result.concat(this.parent.titlePath());
|
||
|
}
|
||
|
if (!this.root) {
|
||
|
result.push(this.title);
|
||
|
}
|
||
|
return result;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Return the total number of tests.
|
||
|
*
|
||
|
* @memberof Mocha.Suite
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @return {number}
|
||
|
*/
|
||
|
Suite.prototype.total = function() {
|
||
|
return (
|
||
|
this.suites.reduce(function(sum, suite) {
|
||
|
return sum + suite.total();
|
||
|
}, 0) + this.tests.length
|
||
|
);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Iterates through each suite recursively to find all tests. Applies a
|
||
|
* function in the format `fn(test)`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Function} fn
|
||
|
* @return {Suite}
|
||
|
*/
|
||
|
Suite.prototype.eachTest = function(fn) {
|
||
|
this.tests.forEach(fn);
|
||
|
this.suites.forEach(function(suite) {
|
||
|
suite.eachTest(fn);
|
||
|
});
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* This will run the root suite if we happen to be running in delayed mode.
|
||
|
*/
|
||
|
Suite.prototype.run = function run() {
|
||
|
if (this.root) {
|
||
|
this.emit('run');
|
||
|
}
|
||
|
};
|
||
|
|
||
|
},{"./hook":6,"./ms":14,"./utils":36,"debug":43,"events":47}],35:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
var Runnable = require('./runnable');
|
||
|
var utils = require('./utils');
|
||
|
var isString = utils.isString;
|
||
|
|
||
|
module.exports = Test;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Test` with the given `title` and callback `fn`.
|
||
|
*
|
||
|
* @class
|
||
|
* @extends Runnable
|
||
|
* @param {String} title
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
function Test(title, fn) {
|
||
|
if (!isString(title)) {
|
||
|
throw new Error(
|
||
|
'Test `title` should be a "string" but "' +
|
||
|
typeof title +
|
||
|
'" was given instead.'
|
||
|
);
|
||
|
}
|
||
|
Runnable.call(this, title, fn);
|
||
|
this.pending = !fn;
|
||
|
this.type = 'test';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Inherit from `Runnable.prototype`.
|
||
|
*/
|
||
|
utils.inherits(Test, Runnable);
|
||
|
|
||
|
Test.prototype.clone = function() {
|
||
|
var test = new Test(this.title, this.fn);
|
||
|
test.timeout(this.timeout());
|
||
|
test.slow(this.slow());
|
||
|
test.enableTimeouts(this.enableTimeouts());
|
||
|
test.retries(this.retries());
|
||
|
test.currentRetry(this.currentRetry());
|
||
|
test.globals(this.globals());
|
||
|
test.parent = this.parent;
|
||
|
test.file = this.file;
|
||
|
test.ctx = this.ctx;
|
||
|
return test;
|
||
|
};
|
||
|
|
||
|
},{"./runnable":32,"./utils":36}],36:[function(require,module,exports){
|
||
|
(function (process,Buffer){
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* @module
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
*/
|
||
|
|
||
|
var debug = require('debug')('mocha:watch');
|
||
|
var fs = require('fs');
|
||
|
var glob = require('glob');
|
||
|
var path = require('path');
|
||
|
var join = path.join;
|
||
|
var he = require('he');
|
||
|
|
||
|
/**
|
||
|
* Ignored directories.
|
||
|
*/
|
||
|
|
||
|
var ignore = ['node_modules', '.git'];
|
||
|
|
||
|
exports.inherits = require('util').inherits;
|
||
|
|
||
|
/**
|
||
|
* Escape special characters in the given string of html.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} html
|
||
|
* @return {string}
|
||
|
*/
|
||
|
exports.escape = function(html) {
|
||
|
return he.encode(String(html), {useNamedReferences: false});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Test if the given obj is type of string.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} obj
|
||
|
* @return {boolean}
|
||
|
*/
|
||
|
exports.isString = function(obj) {
|
||
|
return typeof obj === 'string';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Watch the given `files` for changes
|
||
|
* and invoke `fn(file)` on modification.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Array} files
|
||
|
* @param {Function} fn
|
||
|
*/
|
||
|
exports.watch = function(files, fn) {
|
||
|
var options = {interval: 100};
|
||
|
files.forEach(function(file) {
|
||
|
debug('file %s', file);
|
||
|
fs.watchFile(file, options, function(curr, prev) {
|
||
|
if (prev.mtime < curr.mtime) {
|
||
|
fn(file);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Ignored files.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} path
|
||
|
* @return {boolean}
|
||
|
*/
|
||
|
function ignored(path) {
|
||
|
return !~ignore.indexOf(path);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Lookup files in the given `dir`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} dir
|
||
|
* @param {string[]} [ext=['.js']]
|
||
|
* @param {Array} [ret=[]]
|
||
|
* @return {Array}
|
||
|
*/
|
||
|
exports.files = function(dir, ext, ret) {
|
||
|
ret = ret || [];
|
||
|
ext = ext || ['js'];
|
||
|
|
||
|
var re = new RegExp('\\.(' + ext.join('|') + ')$');
|
||
|
|
||
|
fs
|
||
|
.readdirSync(dir)
|
||
|
.filter(ignored)
|
||
|
.forEach(function(path) {
|
||
|
path = join(dir, path);
|
||
|
if (fs.lstatSync(path).isDirectory()) {
|
||
|
exports.files(path, ext, ret);
|
||
|
} else if (path.match(re)) {
|
||
|
ret.push(path);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Compute a slug from the given `str`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} str
|
||
|
* @return {string}
|
||
|
*/
|
||
|
exports.slug = function(str) {
|
||
|
return str
|
||
|
.toLowerCase()
|
||
|
.replace(/ +/g, '-')
|
||
|
.replace(/[^-\w]/g, '');
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Strip the function definition from `str`, and re-indent for pre whitespace.
|
||
|
*
|
||
|
* @param {string} str
|
||
|
* @return {string}
|
||
|
*/
|
||
|
exports.clean = function(str) {
|
||
|
str = str
|
||
|
.replace(/\r\n?|[\n\u2028\u2029]/g, '\n')
|
||
|
.replace(/^\uFEFF/, '')
|
||
|
// (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
|
||
|
.replace(
|
||
|
/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/,
|
||
|
'$1$2$3'
|
||
|
);
|
||
|
|
||
|
var spaces = str.match(/^\n?( *)/)[1].length;
|
||
|
var tabs = str.match(/^\n?(\t*)/)[1].length;
|
||
|
var re = new RegExp(
|
||
|
'^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}',
|
||
|
'gm'
|
||
|
);
|
||
|
|
||
|
str = str.replace(re, '');
|
||
|
|
||
|
return str.trim();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Parse the given `qs`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} qs
|
||
|
* @return {Object}
|
||
|
*/
|
||
|
exports.parseQuery = function(qs) {
|
||
|
return qs
|
||
|
.replace('?', '')
|
||
|
.split('&')
|
||
|
.reduce(function(obj, pair) {
|
||
|
var i = pair.indexOf('=');
|
||
|
var key = pair.slice(0, i);
|
||
|
var val = pair.slice(++i);
|
||
|
|
||
|
// Due to how the URLSearchParams API treats spaces
|
||
|
obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
|
||
|
|
||
|
return obj;
|
||
|
}, {});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Highlight the given string of `js`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} js
|
||
|
* @return {string}
|
||
|
*/
|
||
|
function highlight(js) {
|
||
|
return js
|
||
|
.replace(/</g, '<')
|
||
|
.replace(/>/g, '>')
|
||
|
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
|
||
|
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
||
|
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
||
|
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
||
|
.replace(
|
||
|
/\bnew[ \t]+(\w+)/gm,
|
||
|
'<span class="keyword">new</span> <span class="init">$1</span>'
|
||
|
)
|
||
|
.replace(
|
||
|
/\b(function|new|throw|return|var|if|else)\b/gm,
|
||
|
'<span class="keyword">$1</span>'
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Highlight the contents of tag `name`.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {string} name
|
||
|
*/
|
||
|
exports.highlightTags = function(name) {
|
||
|
var code = document.getElementById('mocha').getElementsByTagName(name);
|
||
|
for (var i = 0, len = code.length; i < len; ++i) {
|
||
|
code[i].innerHTML = highlight(code[i].innerHTML);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* If a value could have properties, and has none, this function is called,
|
||
|
* which returns a string representation of the empty value.
|
||
|
*
|
||
|
* Functions w/ no properties return `'[Function]'`
|
||
|
* Arrays w/ length === 0 return `'[]'`
|
||
|
* Objects w/ no properties return `'{}'`
|
||
|
* All else: return result of `value.toString()`
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {*} value The value to inspect.
|
||
|
* @param {string} typeHint The type of the value
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
function emptyRepresentation(value, typeHint) {
|
||
|
switch (typeHint) {
|
||
|
case 'function':
|
||
|
return '[Function]';
|
||
|
case 'object':
|
||
|
return '{}';
|
||
|
case 'array':
|
||
|
return '[]';
|
||
|
default:
|
||
|
return value.toString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Takes some variable and asks `Object.prototype.toString()` what it thinks it
|
||
|
* is.
|
||
|
*
|
||
|
* @api private
|
||
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
|
||
|
* @param {*} value The value to test.
|
||
|
* @returns {string} Computed type
|
||
|
* @example
|
||
|
* type({}) // 'object'
|
||
|
* type([]) // 'array'
|
||
|
* type(1) // 'number'
|
||
|
* type(false) // 'boolean'
|
||
|
* type(Infinity) // 'number'
|
||
|
* type(null) // 'null'
|
||
|
* type(new Date()) // 'date'
|
||
|
* type(/foo/) // 'regexp'
|
||
|
* type('type') // 'string'
|
||
|
* type(global) // 'global'
|
||
|
* type(new String('foo') // 'object'
|
||
|
*/
|
||
|
var type = (exports.type = function type(value) {
|
||
|
if (value === undefined) {
|
||
|
return 'undefined';
|
||
|
} else if (value === null) {
|
||
|
return 'null';
|
||
|
} else if (Buffer.isBuffer(value)) {
|
||
|
return 'buffer';
|
||
|
}
|
||
|
return Object.prototype.toString
|
||
|
.call(value)
|
||
|
.replace(/^\[.+\s(.+?)]$/, '$1')
|
||
|
.toLowerCase();
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Stringify `value`. Different behavior depending on type of value:
|
||
|
*
|
||
|
* - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
|
||
|
* - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
|
||
|
* - If `value` is an *empty* object, function, or array, return result of function
|
||
|
* {@link emptyRepresentation}.
|
||
|
* - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
|
||
|
* JSON.stringify().
|
||
|
*
|
||
|
* @api private
|
||
|
* @see exports.type
|
||
|
* @param {*} value
|
||
|
* @return {string}
|
||
|
*/
|
||
|
exports.stringify = function(value) {
|
||
|
var typeHint = type(value);
|
||
|
|
||
|
if (!~['object', 'array', 'function'].indexOf(typeHint)) {
|
||
|
if (typeHint === 'buffer') {
|
||
|
var json = Buffer.prototype.toJSON.call(value);
|
||
|
// Based on the toJSON result
|
||
|
return jsonStringify(
|
||
|
json.data && json.type ? json.data : json,
|
||
|
2
|
||
|
).replace(/,(\n|$)/g, '$1');
|
||
|
}
|
||
|
|
||
|
// IE7/IE8 has a bizarre String constructor; needs to be coerced
|
||
|
// into an array and back to obj.
|
||
|
if (typeHint === 'string' && typeof value === 'object') {
|
||
|
value = value.split('').reduce(function(acc, char, idx) {
|
||
|
acc[idx] = char;
|
||
|
return acc;
|
||
|
}, {});
|
||
|
typeHint = 'object';
|
||
|
} else {
|
||
|
return jsonStringify(value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (var prop in value) {
|
||
|
if (Object.prototype.hasOwnProperty.call(value, prop)) {
|
||
|
return jsonStringify(
|
||
|
exports.canonicalize(value, null, typeHint),
|
||
|
2
|
||
|
).replace(/,(\n|$)/g, '$1');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return emptyRepresentation(value, typeHint);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* like JSON.stringify but more sense.
|
||
|
*
|
||
|
* @api private
|
||
|
* @param {Object} object
|
||
|
* @param {number=} spaces
|
||
|
* @param {number=} depth
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
function jsonStringify(object, spaces, depth) {
|
||
|
if (typeof spaces === 'undefined') {
|
||
|
// primitive types
|
||
|
return _stringify(object);
|
||
|
}
|
||
|
|
||
|
depth = depth || 1;
|
||
|
var space = spaces * depth;
|
||
|
var str = Array.isArray(object) ? '[' : '{';
|
||
|
var end = Array.isArray(object) ? ']' : '}';
|
||
|
var length =
|
||
|
typeof object.length === 'number'
|
||
|
? object.length
|
||
|
: Object.keys(object).length;
|
||
|
// `.repeat()` polyfill
|
||
|
function repeat(s, n) {
|
||
|
return new Array(n).join(s);
|
||
|
}
|
||
|
|
||
|
function _stringify(val) {
|
||
|
switch (type(val)) {
|
||
|
case 'null':
|
||
|
case 'undefined':
|
||
|
val = '[' + val + ']';
|
||
|
break;
|
||
|
case 'array':
|
||
|
case 'object':
|
||
|
val = jsonStringify(val, spaces, depth + 1);
|
||
|
break;
|
||
|
case 'boolean':
|
||
|
case 'regexp':
|
||
|
case 'symbol':
|
||
|
case 'number':
|
||
|
val =
|
||
|
val === 0 && 1 / val === -Infinity // `-0`
|
||
|
? '-0'
|
||
|
: val.toString();
|
||
|
break;
|
||
|
case 'date':
|
||
|
var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
|
||
|
val = '[Date: ' + sDate + ']';
|
||
|
break;
|
||
|
case 'buffer':
|
||
|
var json = val.toJSON();
|
||
|
// Based on the toJSON result
|
||
|
json = json.data && json.type ? json.data : json;
|
||
|
val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
|
||
|
break;
|
||
|
default:
|
||
|
val =
|
||
|
val === '[Function]' || val === '[Circular]'
|
||
|
? val
|
||
|
: JSON.stringify(val); // string
|
||
|
}
|
||
|
return val;
|
||
|
}
|
||
|
|
||
|
for (var i in object) {
|
||
|
if (!Object.prototype.hasOwnProperty.call(object, i)) {
|
||
|
continue; // not my business
|
||
|
}
|
||
|
--length;
|
||
|
str +=
|
||
|
'\n ' +
|
||
|
repeat(' ', space) +
|
||
|
(Array.isArray(object) ? '' : '"' + i + '": ') + // key
|
||
|
_stringify(object[i]) + // value
|
||
|
(length ? ',' : ''); // comma
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
str +
|
||
|
// [], {}
|
||
|
(str.length !== 1 ? '\n' + repeat(' ', --space) + end : end)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return a new Thing that has the keys in sorted order. Recursive.
|
||
|
*
|
||
|
* If the Thing...
|
||
|
* - has already been seen, return string `'[Circular]'`
|
||
|
* - is `undefined`, return string `'[undefined]'`
|
||
|
* - is `null`, return value `null`
|
||
|
* - is some other primitive, return the value
|
||
|
* - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
|
||
|
* - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
|
||
|
* - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
|
||
|
*
|
||
|
* @api private
|
||
|
* @see {@link exports.stringify}
|
||
|
* @param {*} value Thing to inspect. May or may not have properties.
|
||
|
* @param {Array} [stack=[]] Stack of seen values
|
||
|
* @param {string} [typeHint] Type hint
|
||
|
* @return {(Object|Array|Function|string|undefined)}
|
||
|
*/
|
||
|
exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
||
|
var canonicalizedObj;
|
||
|
/* eslint-disable no-unused-vars */
|
||
|
var prop;
|
||
|
/* eslint-enable no-unused-vars */
|
||
|
typeHint = typeHint || type(value);
|
||
|
function withStack(value, fn) {
|
||
|
stack.push(value);
|
||
|
fn();
|
||
|
stack.pop();
|
||
|
}
|
||
|
|
||
|
stack = stack || [];
|
||
|
|
||
|
if (stack.indexOf(value) !== -1) {
|
||
|
return '[Circular]';
|
||
|
}
|
||
|
|
||
|
switch (typeHint) {
|
||
|
case 'undefined':
|
||
|
case 'buffer':
|
||
|
case 'null':
|
||
|
canonicalizedObj = value;
|
||
|
break;
|
||
|
case 'array':
|
||
|
withStack(value, function() {
|
||
|
canonicalizedObj = value.map(function(item) {
|
||
|
return exports.canonicalize(item, stack);
|
||
|
});
|
||
|
});
|
||
|
break;
|
||
|
case 'function':
|
||
|
/* eslint-disable guard-for-in */
|
||
|
for (prop in value) {
|
||
|
canonicalizedObj = {};
|
||
|
break;
|
||
|
}
|
||
|
/* eslint-enable guard-for-in */
|
||
|
if (!canonicalizedObj) {
|
||
|
canonicalizedObj = emptyRepresentation(value, typeHint);
|
||
|
break;
|
||
|
}
|
||
|
/* falls through */
|
||
|
case 'object':
|
||
|
canonicalizedObj = canonicalizedObj || {};
|
||
|
withStack(value, function() {
|
||
|
Object.keys(value)
|
||
|
.sort()
|
||
|
.forEach(function(key) {
|
||
|
canonicalizedObj[key] = exports.canonicalize(value[key], stack);
|
||
|
});
|
||
|
});
|
||
|
break;
|
||
|
case 'date':
|
||
|
case 'number':
|
||
|
case 'regexp':
|
||
|
case 'boolean':
|
||
|
case 'symbol':
|
||
|
canonicalizedObj = value;
|
||
|
break;
|
||
|
default:
|
||
|
canonicalizedObj = value + '';
|
||
|
}
|
||
|
|
||
|
return canonicalizedObj;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Lookup file names at the given `path`.
|
||
|
*
|
||
|
* @memberof Mocha.utils
|
||
|
* @public
|
||
|
* @api public
|
||
|
* @param {string} filepath Base path to start searching from.
|
||
|
* @param {string[]} extensions File extensions to look for.
|
||
|
* @param {boolean} recursive Whether or not to recurse into subdirectories.
|
||
|
* @return {string[]} An array of paths.
|
||
|
*/
|
||
|
exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
|
||
|
var files = [];
|
||
|
|
||
|
if (!fs.existsSync(filepath)) {
|
||
|
if (fs.existsSync(filepath + '.js')) {
|
||
|
filepath += '.js';
|
||
|
} else {
|
||
|
files = glob.sync(filepath);
|
||
|
if (!files.length) {
|
||
|
throw new Error("cannot resolve path (or pattern) '" + filepath + "'");
|
||
|
}
|
||
|
return files;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
var stat = fs.statSync(filepath);
|
||
|
if (stat.isFile()) {
|
||
|
return filepath;
|
||
|
}
|
||
|
} catch (err) {
|
||
|
// ignore error
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
fs.readdirSync(filepath).forEach(function(file) {
|
||
|
file = path.join(filepath, file);
|
||
|
try {
|
||
|
var stat = fs.statSync(file);
|
||
|
if (stat.isDirectory()) {
|
||
|
if (recursive) {
|
||
|
files = files.concat(lookupFiles(file, extensions, recursive));
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
} catch (err) {
|
||
|
// ignore error
|
||
|
return;
|
||
|
}
|
||
|
if (!extensions) {
|
||
|
throw new Error(
|
||
|
'extensions parameter required when filepath is a directory'
|
||
|
);
|
||
|
}
|
||
|
var re = new RegExp('\\.(?:' + extensions.join('|') + ')$');
|
||
|
if (!stat.isFile() || !re.test(file) || path.basename(file)[0] === '.') {
|
||
|
return;
|
||
|
}
|
||
|
files.push(file);
|
||
|
});
|
||
|
|
||
|
return files;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Generate an undefined error with a message warning the user.
|
||
|
*
|
||
|
* @return {Error}
|
||
|
*/
|
||
|
|
||
|
exports.undefinedError = function() {
|
||
|
return new Error(
|
||
|
'Caught undefined error, did you throw without specifying what?'
|
||
|
);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Generate an undefined error if `err` is not defined.
|
||
|
*
|
||
|
* @param {Error} err
|
||
|
* @return {Error}
|
||
|
*/
|
||
|
|
||
|
exports.getError = function(err) {
|
||
|
return err || exports.undefinedError();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @summary
|
||
|
* This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
|
||
|
* @description
|
||
|
* When invoking this function you get a filter function that get the Error.stack as an input,
|
||
|
* and return a prettify output.
|
||
|
* (i.e: strip Mocha and internal node functions from stack trace).
|
||
|
* @returns {Function}
|
||
|
*/
|
||
|
exports.stackTraceFilter = function() {
|
||
|
// TODO: Replace with `process.browser`
|
||
|
var is = typeof document === 'undefined' ? {node: true} : {browser: true};
|
||
|
var slash = path.sep;
|
||
|
var cwd;
|
||
|
if (is.node) {
|
||
|
cwd = process.cwd() + slash;
|
||
|
} else {
|
||
|
cwd = (typeof location === 'undefined'
|
||
|
? window.location
|
||
|
: location
|
||
|
).href.replace(/\/[^/]*$/, '/');
|
||
|
slash = '/';
|
||
|
}
|
||
|
|
||
|
function isMochaInternal(line) {
|
||
|
return (
|
||
|
~line.indexOf('node_modules' + slash + 'mocha' + slash) ||
|
||
|
~line.indexOf('node_modules' + slash + 'mocha.js') ||
|
||
|
~line.indexOf('bower_components' + slash + 'mocha.js') ||
|
||
|
~line.indexOf(slash + 'mocha.js')
|
||
|
);
|
||
|
}
|
||
|
|
||
|
function isNodeInternal(line) {
|
||
|
return (
|
||
|
~line.indexOf('(timers.js:') ||
|
||
|
~line.indexOf('(events.js:') ||
|
||
|
~line.indexOf('(node.js:') ||
|
||
|
~line.indexOf('(module.js:') ||
|
||
|
~line.indexOf('GeneratorFunctionPrototype.next (native)') ||
|
||
|
false
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return function(stack) {
|
||
|
stack = stack.split('\n');
|
||
|
|
||
|
stack = stack.reduce(function(list, line) {
|
||
|
if (isMochaInternal(line)) {
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
if (is.node && isNodeInternal(line)) {
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
// Clean up cwd(absolute)
|
||
|
if (/\(?.+:\d+:\d+\)?$/.test(line)) {
|
||
|
line = line.replace('(' + cwd, '(');
|
||
|
}
|
||
|
|
||
|
list.push(line);
|
||
|
return list;
|
||
|
}, []);
|
||
|
|
||
|
return stack.join('\n');
|
||
|
};
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Crude, but effective.
|
||
|
* @api
|
||
|
* @param {*} value
|
||
|
* @returns {boolean} Whether or not `value` is a Promise
|
||
|
*/
|
||
|
exports.isPromise = function isPromise(value) {
|
||
|
return typeof value === 'object' && typeof value.then === 'function';
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* It's a noop.
|
||
|
* @api
|
||
|
*/
|
||
|
exports.noop = function() {};
|
||
|
|
||
|
}).call(this,require('_process'),require("buffer").Buffer)
|
||
|
},{"_process":56,"buffer":41,"debug":43,"fs":40,"glob":40,"he":48,"path":40,"util":76}],37:[function(require,module,exports){
|
||
|
'use strict'
|
||
|
|
||
|
exports.byteLength = byteLength
|
||
|
exports.toByteArray = toByteArray
|
||
|
exports.fromByteArray = fromByteArray
|
||
|
|
||
|
var lookup = []
|
||
|
var revLookup = []
|
||
|
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
||
|
|
||
|
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||
|
for (var i = 0, len = code.length; i < len; ++i) {
|
||
|
lookup[i] = code[i]
|
||
|
revLookup[code.charCodeAt(i)] = i
|
||
|
}
|
||
|
|
||
|
// Support decoding URL-safe base64 strings, as Node.js does.
|
||
|
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
||
|
revLookup['-'.charCodeAt(0)] = 62
|
||
|
revLookup['_'.charCodeAt(0)] = 63
|
||
|
|
||
|
function getLens (b64) {
|
||
|
var len = b64.length
|
||
|
|
||
|
if (len % 4 > 0) {
|
||
|
throw new Error('Invalid string. Length must be a multiple of 4')
|
||
|
}
|
||
|
|
||
|
// Trim off extra bytes after placeholder bytes are found
|
||
|
// See: https://github.com/beatgammit/base64-js/issues/42
|
||
|
var validLen = b64.indexOf('=')
|
||
|
if (validLen === -1) validLen = len
|
||
|
|
||
|
var placeHoldersLen = validLen === len
|
||
|
? 0
|
||
|
: 4 - (validLen % 4)
|
||
|
|
||
|
return [validLen, placeHoldersLen]
|
||
|
}
|
||
|
|
||
|
// base64 is 4/3 + up to two characters of the original data
|
||
|
function byteLength (b64) {
|
||
|
var lens = getLens(b64)
|
||
|
var validLen = lens[0]
|
||
|
var placeHoldersLen = lens[1]
|
||
|
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
||
|
}
|
||
|
|
||
|
function _byteLength (b64, validLen, placeHoldersLen) {
|
||
|
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
||
|
}
|
||
|
|
||
|
function toByteArray (b64) {
|
||
|
var tmp
|
||
|
var lens = getLens(b64)
|
||
|
var validLen = lens[0]
|
||
|
var placeHoldersLen = lens[1]
|
||
|
|
||
|
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
||
|
|
||
|
var curByte = 0
|
||
|
|
||
|
// if there are placeholders, only get up to the last complete 4 chars
|
||
|
var len = placeHoldersLen > 0
|
||
|
? validLen - 4
|
||
|
: validLen
|
||
|
|
||
|
for (var i = 0; i < len; i += 4) {
|
||
|
tmp =
|
||
|
(revLookup[b64.charCodeAt(i)] << 18) |
|
||
|
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
||
|
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
||
|
revLookup[b64.charCodeAt(i + 3)]
|
||
|
arr[curByte++] = (tmp >> 16) & 0xFF
|
||
|
arr[curByte++] = (tmp >> 8) & 0xFF
|
||
|
arr[curByte++] = tmp & 0xFF
|
||
|
}
|
||
|
|
||
|
if (placeHoldersLen === 2) {
|
||
|
tmp =
|
||
|
(revLookup[b64.charCodeAt(i)] << 2) |
|
||
|
(revLookup[b64.charCodeAt(i + 1)] >> 4)
|
||
|
arr[curByte++] = tmp & 0xFF
|
||
|
}
|
||
|
|
||
|
if (placeHoldersLen === 1) {
|
||
|
tmp =
|
||
|
(revLookup[b64.charCodeAt(i)] << 10) |
|
||
|
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
||
|
(revLookup[b64.charCodeAt(i + 2)] >> 2)
|
||
|
arr[curByte++] = (tmp >> 8) & 0xFF
|
||
|
arr[curByte++] = tmp & 0xFF
|
||
|
}
|
||
|
|
||
|
return arr
|
||
|
}
|
||
|
|
||
|
function tripletToBase64 (num) {
|
||
|
return lookup[num >> 18 & 0x3F] +
|
||
|
lookup[num >> 12 & 0x3F] +
|
||
|
lookup[num >> 6 & 0x3F] +
|
||
|
lookup[num & 0x3F]
|
||
|
}
|
||
|
|
||
|
function encodeChunk (uint8, start, end) {
|
||
|
var tmp
|
||
|
var output = []
|
||
|
for (var i = start; i < end; i += 3) {
|
||
|
tmp =
|
||
|
((uint8[i] << 16) & 0xFF0000) +
|
||
|
((uint8[i + 1] << 8) & 0xFF00) +
|
||
|
(uint8[i + 2] & 0xFF)
|
||
|
output.push(tripletToBase64(tmp))
|
||
|
}
|
||
|
return output.join('')
|
||
|
}
|
||
|
|
||
|
function fromByteArray (uint8) {
|
||
|
var tmp
|
||
|
var len = uint8.length
|
||
|
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
|
||
|
var parts = []
|
||
|
var maxChunkLength = 16383 // must be multiple of 3
|
||
|
|
||
|
// go through the array every three bytes, we'll deal with trailing stuff later
|
||
|
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
||
|
parts.push(encodeChunk(
|
||
|
uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
|
||
|
))
|
||
|
}
|
||
|
|
||
|
// pad the end with zeros, but make sure to not forget the extra bytes
|
||
|
if (extraBytes === 1) {
|
||
|
tmp = uint8[len - 1]
|
||
|
parts.push(
|
||
|
lookup[tmp >> 2] +
|
||
|
lookup[(tmp << 4) & 0x3F] +
|
||
|
'=='
|
||
|
)
|
||
|
} else if (extraBytes === 2) {
|
||
|
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
||
|
parts.push(
|
||
|
lookup[tmp >> 10] +
|
||
|
lookup[(tmp >> 4) & 0x3F] +
|
||
|
lookup[(tmp << 2) & 0x3F] +
|
||
|
'='
|
||
|
)
|
||
|
}
|
||
|
|
||
|
return parts.join('')
|
||
|
}
|
||
|
|
||
|
},{}],38:[function(require,module,exports){
|
||
|
|
||
|
},{}],39:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
var WritableStream = require('stream').Writable
|
||
|
var inherits = require('util').inherits
|
||
|
|
||
|
module.exports = BrowserStdout
|
||
|
|
||
|
|
||
|
inherits(BrowserStdout, WritableStream)
|
||
|
|
||
|
function BrowserStdout(opts) {
|
||
|
if (!(this instanceof BrowserStdout)) return new BrowserStdout(opts)
|
||
|
|
||
|
opts = opts || {}
|
||
|
WritableStream.call(this, opts)
|
||
|
this.label = (opts.label !== undefined) ? opts.label : 'stdout'
|
||
|
}
|
||
|
|
||
|
BrowserStdout.prototype._write = function(chunks, encoding, cb) {
|
||
|
var output = chunks.toString ? chunks.toString() : chunks
|
||
|
if (this.label === false) {
|
||
|
console.log(output)
|
||
|
} else {
|
||
|
console.log(this.label+':', output)
|
||
|
}
|
||
|
process.nextTick(cb)
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"_process":56,"stream":71,"util":76}],40:[function(require,module,exports){
|
||
|
arguments[4][38][0].apply(exports,arguments)
|
||
|
},{"dup":38}],41:[function(require,module,exports){
|
||
|
/*!
|
||
|
* The buffer module from node.js, for the browser.
|
||
|
*
|
||
|
* @author Feross Aboukhadijeh <https://feross.org>
|
||
|
* @license MIT
|
||
|
*/
|
||
|
/* eslint-disable no-proto */
|
||
|
|
||
|
'use strict'
|
||
|
|
||
|
var base64 = require('base64-js')
|
||
|
var ieee754 = require('ieee754')
|
||
|
|
||
|
exports.Buffer = Buffer
|
||
|
exports.SlowBuffer = SlowBuffer
|
||
|
exports.INSPECT_MAX_BYTES = 50
|
||
|
|
||
|
var K_MAX_LENGTH = 0x7fffffff
|
||
|
exports.kMaxLength = K_MAX_LENGTH
|
||
|
|
||
|
/**
|
||
|
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
||
|
* === true Use Uint8Array implementation (fastest)
|
||
|
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
||
|
* implementation (most compatible, even IE6)
|
||
|
*
|
||
|
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
||
|
* Opera 11.6+, iOS 4.2+.
|
||
|
*
|
||
|
* We report that the browser does not support typed arrays if the are not subclassable
|
||
|
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
||
|
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
||
|
* for __proto__ and has a buggy typed array implementation.
|
||
|
*/
|
||
|
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
|
||
|
|
||
|
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
||
|
typeof console.error === 'function') {
|
||
|
console.error(
|
||
|
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
||
|
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
||
|
)
|
||
|
}
|
||
|
|
||
|
function typedArraySupport () {
|
||
|
// Can typed array instances can be augmented?
|
||
|
try {
|
||
|
var arr = new Uint8Array(1)
|
||
|
arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
|
||
|
return arr.foo() === 42
|
||
|
} catch (e) {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(Buffer.prototype, 'parent', {
|
||
|
get: function () {
|
||
|
if (!(this instanceof Buffer)) {
|
||
|
return undefined
|
||
|
}
|
||
|
return this.buffer
|
||
|
}
|
||
|
})
|
||
|
|
||
|
Object.defineProperty(Buffer.prototype, 'offset', {
|
||
|
get: function () {
|
||
|
if (!(this instanceof Buffer)) {
|
||
|
return undefined
|
||
|
}
|
||
|
return this.byteOffset
|
||
|
}
|
||
|
})
|
||
|
|
||
|
function createBuffer (length) {
|
||
|
if (length > K_MAX_LENGTH) {
|
||
|
throw new RangeError('Invalid typed array length')
|
||
|
}
|
||
|
// Return an augmented `Uint8Array` instance
|
||
|
var buf = new Uint8Array(length)
|
||
|
buf.__proto__ = Buffer.prototype
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* The Buffer constructor returns instances of `Uint8Array` that have their
|
||
|
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
||
|
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
||
|
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
||
|
* returns a single octet.
|
||
|
*
|
||
|
* The `Uint8Array` prototype remains unmodified.
|
||
|
*/
|
||
|
|
||
|
function Buffer (arg, encodingOrOffset, length) {
|
||
|
// Common case.
|
||
|
if (typeof arg === 'number') {
|
||
|
if (typeof encodingOrOffset === 'string') {
|
||
|
throw new Error(
|
||
|
'If encoding is specified then the first argument must be a string'
|
||
|
)
|
||
|
}
|
||
|
return allocUnsafe(arg)
|
||
|
}
|
||
|
return from(arg, encodingOrOffset, length)
|
||
|
}
|
||
|
|
||
|
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
|
||
|
if (typeof Symbol !== 'undefined' && Symbol.species &&
|
||
|
Buffer[Symbol.species] === Buffer) {
|
||
|
Object.defineProperty(Buffer, Symbol.species, {
|
||
|
value: null,
|
||
|
configurable: true,
|
||
|
enumerable: false,
|
||
|
writable: false
|
||
|
})
|
||
|
}
|
||
|
|
||
|
Buffer.poolSize = 8192 // not used by this implementation
|
||
|
|
||
|
function from (value, encodingOrOffset, length) {
|
||
|
if (typeof value === 'number') {
|
||
|
throw new TypeError('"value" argument must not be a number')
|
||
|
}
|
||
|
|
||
|
if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
|
||
|
return fromArrayBuffer(value, encodingOrOffset, length)
|
||
|
}
|
||
|
|
||
|
if (typeof value === 'string') {
|
||
|
return fromString(value, encodingOrOffset)
|
||
|
}
|
||
|
|
||
|
return fromObject(value)
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
||
|
* if value is a number.
|
||
|
* Buffer.from(str[, encoding])
|
||
|
* Buffer.from(array)
|
||
|
* Buffer.from(buffer)
|
||
|
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
||
|
**/
|
||
|
Buffer.from = function (value, encodingOrOffset, length) {
|
||
|
return from(value, encodingOrOffset, length)
|
||
|
}
|
||
|
|
||
|
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
||
|
// https://github.com/feross/buffer/pull/148
|
||
|
Buffer.prototype.__proto__ = Uint8Array.prototype
|
||
|
Buffer.__proto__ = Uint8Array
|
||
|
|
||
|
function assertSize (size) {
|
||
|
if (typeof size !== 'number') {
|
||
|
throw new TypeError('"size" argument must be of type number')
|
||
|
} else if (size < 0) {
|
||
|
throw new RangeError('"size" argument must not be negative')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function alloc (size, fill, encoding) {
|
||
|
assertSize(size)
|
||
|
if (size <= 0) {
|
||
|
return createBuffer(size)
|
||
|
}
|
||
|
if (fill !== undefined) {
|
||
|
// Only pay attention to encoding if it's a string. This
|
||
|
// prevents accidentally sending in a number that would
|
||
|
// be interpretted as a start offset.
|
||
|
return typeof encoding === 'string'
|
||
|
? createBuffer(size).fill(fill, encoding)
|
||
|
: createBuffer(size).fill(fill)
|
||
|
}
|
||
|
return createBuffer(size)
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates a new filled Buffer instance.
|
||
|
* alloc(size[, fill[, encoding]])
|
||
|
**/
|
||
|
Buffer.alloc = function (size, fill, encoding) {
|
||
|
return alloc(size, fill, encoding)
|
||
|
}
|
||
|
|
||
|
function allocUnsafe (size) {
|
||
|
assertSize(size)
|
||
|
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
||
|
* */
|
||
|
Buffer.allocUnsafe = function (size) {
|
||
|
return allocUnsafe(size)
|
||
|
}
|
||
|
/**
|
||
|
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
||
|
*/
|
||
|
Buffer.allocUnsafeSlow = function (size) {
|
||
|
return allocUnsafe(size)
|
||
|
}
|
||
|
|
||
|
function fromString (string, encoding) {
|
||
|
if (typeof encoding !== 'string' || encoding === '') {
|
||
|
encoding = 'utf8'
|
||
|
}
|
||
|
|
||
|
if (!Buffer.isEncoding(encoding)) {
|
||
|
throw new TypeError('Unknown encoding: ' + encoding)
|
||
|
}
|
||
|
|
||
|
var length = byteLength(string, encoding) | 0
|
||
|
var buf = createBuffer(length)
|
||
|
|
||
|
var actual = buf.write(string, encoding)
|
||
|
|
||
|
if (actual !== length) {
|
||
|
// Writing a hex string, for example, that contains invalid characters will
|
||
|
// cause everything after the first invalid character to be ignored. (e.g.
|
||
|
// 'abxxcd' will be treated as 'ab')
|
||
|
buf = buf.slice(0, actual)
|
||
|
}
|
||
|
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
function fromArrayLike (array) {
|
||
|
var length = array.length < 0 ? 0 : checked(array.length) | 0
|
||
|
var buf = createBuffer(length)
|
||
|
for (var i = 0; i < length; i += 1) {
|
||
|
buf[i] = array[i] & 255
|
||
|
}
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
function fromArrayBuffer (array, byteOffset, length) {
|
||
|
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
||
|
throw new RangeError('"offset" is outside of buffer bounds')
|
||
|
}
|
||
|
|
||
|
if (array.byteLength < byteOffset + (length || 0)) {
|
||
|
throw new RangeError('"length" is outside of buffer bounds')
|
||
|
}
|
||
|
|
||
|
var buf
|
||
|
if (byteOffset === undefined && length === undefined) {
|
||
|
buf = new Uint8Array(array)
|
||
|
} else if (length === undefined) {
|
||
|
buf = new Uint8Array(array, byteOffset)
|
||
|
} else {
|
||
|
buf = new Uint8Array(array, byteOffset, length)
|
||
|
}
|
||
|
|
||
|
// Return an augmented `Uint8Array` instance
|
||
|
buf.__proto__ = Buffer.prototype
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
function fromObject (obj) {
|
||
|
if (Buffer.isBuffer(obj)) {
|
||
|
var len = checked(obj.length) | 0
|
||
|
var buf = createBuffer(len)
|
||
|
|
||
|
if (buf.length === 0) {
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
obj.copy(buf, 0, 0, len)
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
if (obj) {
|
||
|
if (ArrayBuffer.isView(obj) || 'length' in obj) {
|
||
|
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
||
|
return createBuffer(0)
|
||
|
}
|
||
|
return fromArrayLike(obj)
|
||
|
}
|
||
|
|
||
|
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
||
|
return fromArrayLike(obj.data)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
|
||
|
}
|
||
|
|
||
|
function checked (length) {
|
||
|
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
||
|
// length is NaN (which is otherwise coerced to zero.)
|
||
|
if (length >= K_MAX_LENGTH) {
|
||
|
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
||
|
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
||
|
}
|
||
|
return length | 0
|
||
|
}
|
||
|
|
||
|
function SlowBuffer (length) {
|
||
|
if (+length != length) { // eslint-disable-line eqeqeq
|
||
|
length = 0
|
||
|
}
|
||
|
return Buffer.alloc(+length)
|
||
|
}
|
||
|
|
||
|
Buffer.isBuffer = function isBuffer (b) {
|
||
|
return b != null && b._isBuffer === true
|
||
|
}
|
||
|
|
||
|
Buffer.compare = function compare (a, b) {
|
||
|
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
||
|
throw new TypeError('Arguments must be Buffers')
|
||
|
}
|
||
|
|
||
|
if (a === b) return 0
|
||
|
|
||
|
var x = a.length
|
||
|
var y = b.length
|
||
|
|
||
|
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
||
|
if (a[i] !== b[i]) {
|
||
|
x = a[i]
|
||
|
y = b[i]
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (x < y) return -1
|
||
|
if (y < x) return 1
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
Buffer.isEncoding = function isEncoding (encoding) {
|
||
|
switch (String(encoding).toLowerCase()) {
|
||
|
case 'hex':
|
||
|
case 'utf8':
|
||
|
case 'utf-8':
|
||
|
case 'ascii':
|
||
|
case 'latin1':
|
||
|
case 'binary':
|
||
|
case 'base64':
|
||
|
case 'ucs2':
|
||
|
case 'ucs-2':
|
||
|
case 'utf16le':
|
||
|
case 'utf-16le':
|
||
|
return true
|
||
|
default:
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Buffer.concat = function concat (list, length) {
|
||
|
if (!Array.isArray(list)) {
|
||
|
throw new TypeError('"list" argument must be an Array of Buffers')
|
||
|
}
|
||
|
|
||
|
if (list.length === 0) {
|
||
|
return Buffer.alloc(0)
|
||
|
}
|
||
|
|
||
|
var i
|
||
|
if (length === undefined) {
|
||
|
length = 0
|
||
|
for (i = 0; i < list.length; ++i) {
|
||
|
length += list[i].length
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var buffer = Buffer.allocUnsafe(length)
|
||
|
var pos = 0
|
||
|
for (i = 0; i < list.length; ++i) {
|
||
|
var buf = list[i]
|
||
|
if (ArrayBuffer.isView(buf)) {
|
||
|
buf = Buffer.from(buf)
|
||
|
}
|
||
|
if (!Buffer.isBuffer(buf)) {
|
||
|
throw new TypeError('"list" argument must be an Array of Buffers')
|
||
|
}
|
||
|
buf.copy(buffer, pos)
|
||
|
pos += buf.length
|
||
|
}
|
||
|
return buffer
|
||
|
}
|
||
|
|
||
|
function byteLength (string, encoding) {
|
||
|
if (Buffer.isBuffer(string)) {
|
||
|
return string.length
|
||
|
}
|
||
|
if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
|
||
|
return string.byteLength
|
||
|
}
|
||
|
if (typeof string !== 'string') {
|
||
|
string = '' + string
|
||
|
}
|
||
|
|
||
|
var len = string.length
|
||
|
if (len === 0) return 0
|
||
|
|
||
|
// Use a for loop to avoid recursion
|
||
|
var loweredCase = false
|
||
|
for (;;) {
|
||
|
switch (encoding) {
|
||
|
case 'ascii':
|
||
|
case 'latin1':
|
||
|
case 'binary':
|
||
|
return len
|
||
|
case 'utf8':
|
||
|
case 'utf-8':
|
||
|
case undefined:
|
||
|
return utf8ToBytes(string).length
|
||
|
case 'ucs2':
|
||
|
case 'ucs-2':
|
||
|
case 'utf16le':
|
||
|
case 'utf-16le':
|
||
|
return len * 2
|
||
|
case 'hex':
|
||
|
return len >>> 1
|
||
|
case 'base64':
|
||
|
return base64ToBytes(string).length
|
||
|
default:
|
||
|
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
||
|
encoding = ('' + encoding).toLowerCase()
|
||
|
loweredCase = true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
Buffer.byteLength = byteLength
|
||
|
|
||
|
function slowToString (encoding, start, end) {
|
||
|
var loweredCase = false
|
||
|
|
||
|
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
||
|
// property of a typed array.
|
||
|
|
||
|
// This behaves neither like String nor Uint8Array in that we set start/end
|
||
|
// to their upper/lower bounds if the value passed is out of range.
|
||
|
// undefined is handled specially as per ECMA-262 6th Edition,
|
||
|
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
||
|
if (start === undefined || start < 0) {
|
||
|
start = 0
|
||
|
}
|
||
|
// Return early if start > this.length. Done here to prevent potential uint32
|
||
|
// coercion fail below.
|
||
|
if (start > this.length) {
|
||
|
return ''
|
||
|
}
|
||
|
|
||
|
if (end === undefined || end > this.length) {
|
||
|
end = this.length
|
||
|
}
|
||
|
|
||
|
if (end <= 0) {
|
||
|
return ''
|
||
|
}
|
||
|
|
||
|
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
||
|
end >>>= 0
|
||
|
start >>>= 0
|
||
|
|
||
|
if (end <= start) {
|
||
|
return ''
|
||
|
}
|
||
|
|
||
|
if (!encoding) encoding = 'utf8'
|
||
|
|
||
|
while (true) {
|
||
|
switch (encoding) {
|
||
|
case 'hex':
|
||
|
return hexSlice(this, start, end)
|
||
|
|
||
|
case 'utf8':
|
||
|
case 'utf-8':
|
||
|
return utf8Slice(this, start, end)
|
||
|
|
||
|
case 'ascii':
|
||
|
return asciiSlice(this, start, end)
|
||
|
|
||
|
case 'latin1':
|
||
|
case 'binary':
|
||
|
return latin1Slice(this, start, end)
|
||
|
|
||
|
case 'base64':
|
||
|
return base64Slice(this, start, end)
|
||
|
|
||
|
case 'ucs2':
|
||
|
case 'ucs-2':
|
||
|
case 'utf16le':
|
||
|
case 'utf-16le':
|
||
|
return utf16leSlice(this, start, end)
|
||
|
|
||
|
default:
|
||
|
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
||
|
encoding = (encoding + '').toLowerCase()
|
||
|
loweredCase = true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
||
|
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
||
|
// reliably in a browserify context because there could be multiple different
|
||
|
// copies of the 'buffer' package in use. This method works even for Buffer
|
||
|
// instances that were created from another copy of the `buffer` package.
|
||
|
// See: https://github.com/feross/buffer/issues/154
|
||
|
Buffer.prototype._isBuffer = true
|
||
|
|
||
|
function swap (b, n, m) {
|
||
|
var i = b[n]
|
||
|
b[n] = b[m]
|
||
|
b[m] = i
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.swap16 = function swap16 () {
|
||
|
var len = this.length
|
||
|
if (len % 2 !== 0) {
|
||
|
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
||
|
}
|
||
|
for (var i = 0; i < len; i += 2) {
|
||
|
swap(this, i, i + 1)
|
||
|
}
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.swap32 = function swap32 () {
|
||
|
var len = this.length
|
||
|
if (len % 4 !== 0) {
|
||
|
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
||
|
}
|
||
|
for (var i = 0; i < len; i += 4) {
|
||
|
swap(this, i, i + 3)
|
||
|
swap(this, i + 1, i + 2)
|
||
|
}
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.swap64 = function swap64 () {
|
||
|
var len = this.length
|
||
|
if (len % 8 !== 0) {
|
||
|
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
||
|
}
|
||
|
for (var i = 0; i < len; i += 8) {
|
||
|
swap(this, i, i + 7)
|
||
|
swap(this, i + 1, i + 6)
|
||
|
swap(this, i + 2, i + 5)
|
||
|
swap(this, i + 3, i + 4)
|
||
|
}
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.toString = function toString () {
|
||
|
var length = this.length
|
||
|
if (length === 0) return ''
|
||
|
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
||
|
return slowToString.apply(this, arguments)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.toLocaleString = Buffer.prototype.toString
|
||
|
|
||
|
Buffer.prototype.equals = function equals (b) {
|
||
|
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
||
|
if (this === b) return true
|
||
|
return Buffer.compare(this, b) === 0
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.inspect = function inspect () {
|
||
|
var str = ''
|
||
|
var max = exports.INSPECT_MAX_BYTES
|
||
|
if (this.length > 0) {
|
||
|
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
|
||
|
if (this.length > max) str += ' ... '
|
||
|
}
|
||
|
return '<Buffer ' + str + '>'
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
||
|
if (!Buffer.isBuffer(target)) {
|
||
|
throw new TypeError('Argument must be a Buffer')
|
||
|
}
|
||
|
|
||
|
if (start === undefined) {
|
||
|
start = 0
|
||
|
}
|
||
|
if (end === undefined) {
|
||
|
end = target ? target.length : 0
|
||
|
}
|
||
|
if (thisStart === undefined) {
|
||
|
thisStart = 0
|
||
|
}
|
||
|
if (thisEnd === undefined) {
|
||
|
thisEnd = this.length
|
||
|
}
|
||
|
|
||
|
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
||
|
throw new RangeError('out of range index')
|
||
|
}
|
||
|
|
||
|
if (thisStart >= thisEnd && start >= end) {
|
||
|
return 0
|
||
|
}
|
||
|
if (thisStart >= thisEnd) {
|
||
|
return -1
|
||
|
}
|
||
|
if (start >= end) {
|
||
|
return 1
|
||
|
}
|
||
|
|
||
|
start >>>= 0
|
||
|
end >>>= 0
|
||
|
thisStart >>>= 0
|
||
|
thisEnd >>>= 0
|
||
|
|
||
|
if (this === target) return 0
|
||
|
|
||
|
var x = thisEnd - thisStart
|
||
|
var y = end - start
|
||
|
var len = Math.min(x, y)
|
||
|
|
||
|
var thisCopy = this.slice(thisStart, thisEnd)
|
||
|
var targetCopy = target.slice(start, end)
|
||
|
|
||
|
for (var i = 0; i < len; ++i) {
|
||
|
if (thisCopy[i] !== targetCopy[i]) {
|
||
|
x = thisCopy[i]
|
||
|
y = targetCopy[i]
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (x < y) return -1
|
||
|
if (y < x) return 1
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
||
|
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
||
|
//
|
||
|
// Arguments:
|
||
|
// - buffer - a Buffer to search
|
||
|
// - val - a string, Buffer, or number
|
||
|
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
||
|
// - encoding - an optional encoding, relevant is val is a string
|
||
|
// - dir - true for indexOf, false for lastIndexOf
|
||
|
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
||
|
// Empty buffer means no match
|
||
|
if (buffer.length === 0) return -1
|
||
|
|
||
|
// Normalize byteOffset
|
||
|
if (typeof byteOffset === 'string') {
|
||
|
encoding = byteOffset
|
||
|
byteOffset = 0
|
||
|
} else if (byteOffset > 0x7fffffff) {
|
||
|
byteOffset = 0x7fffffff
|
||
|
} else if (byteOffset < -0x80000000) {
|
||
|
byteOffset = -0x80000000
|
||
|
}
|
||
|
byteOffset = +byteOffset // Coerce to Number.
|
||
|
if (numberIsNaN(byteOffset)) {
|
||
|
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
||
|
byteOffset = dir ? 0 : (buffer.length - 1)
|
||
|
}
|
||
|
|
||
|
// Normalize byteOffset: negative offsets start from the end of the buffer
|
||
|
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
||
|
if (byteOffset >= buffer.length) {
|
||
|
if (dir) return -1
|
||
|
else byteOffset = buffer.length - 1
|
||
|
} else if (byteOffset < 0) {
|
||
|
if (dir) byteOffset = 0
|
||
|
else return -1
|
||
|
}
|
||
|
|
||
|
// Normalize val
|
||
|
if (typeof val === 'string') {
|
||
|
val = Buffer.from(val, encoding)
|
||
|
}
|
||
|
|
||
|
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
||
|
if (Buffer.isBuffer(val)) {
|
||
|
// Special case: looking for empty string/buffer always fails
|
||
|
if (val.length === 0) {
|
||
|
return -1
|
||
|
}
|
||
|
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
||
|
} else if (typeof val === 'number') {
|
||
|
val = val & 0xFF // Search for a byte value [0-255]
|
||
|
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
||
|
if (dir) {
|
||
|
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
||
|
} else {
|
||
|
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
||
|
}
|
||
|
}
|
||
|
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
||
|
}
|
||
|
|
||
|
throw new TypeError('val must be string, number or Buffer')
|
||
|
}
|
||
|
|
||
|
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
||
|
var indexSize = 1
|
||
|
var arrLength = arr.length
|
||
|
var valLength = val.length
|
||
|
|
||
|
if (encoding !== undefined) {
|
||
|
encoding = String(encoding).toLowerCase()
|
||
|
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
||
|
encoding === 'utf16le' || encoding === 'utf-16le') {
|
||
|
if (arr.length < 2 || val.length < 2) {
|
||
|
return -1
|
||
|
}
|
||
|
indexSize = 2
|
||
|
arrLength /= 2
|
||
|
valLength /= 2
|
||
|
byteOffset /= 2
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function read (buf, i) {
|
||
|
if (indexSize === 1) {
|
||
|
return buf[i]
|
||
|
} else {
|
||
|
return buf.readUInt16BE(i * indexSize)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var i
|
||
|
if (dir) {
|
||
|
var foundIndex = -1
|
||
|
for (i = byteOffset; i < arrLength; i++) {
|
||
|
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
||
|
if (foundIndex === -1) foundIndex = i
|
||
|
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
||
|
} else {
|
||
|
if (foundIndex !== -1) i -= i - foundIndex
|
||
|
foundIndex = -1
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
||
|
for (i = byteOffset; i >= 0; i--) {
|
||
|
var found = true
|
||
|
for (var j = 0; j < valLength; j++) {
|
||
|
if (read(arr, i + j) !== read(val, j)) {
|
||
|
found = false
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
if (found) return i
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return -1
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
||
|
return this.indexOf(val, byteOffset, encoding) !== -1
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
||
|
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
||
|
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
||
|
}
|
||
|
|
||
|
function hexWrite (buf, string, offset, length) {
|
||
|
offset = Number(offset) || 0
|
||
|
var remaining = buf.length - offset
|
||
|
if (!length) {
|
||
|
length = remaining
|
||
|
} else {
|
||
|
length = Number(length)
|
||
|
if (length > remaining) {
|
||
|
length = remaining
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var strLen = string.length
|
||
|
|
||
|
if (length > strLen / 2) {
|
||
|
length = strLen / 2
|
||
|
}
|
||
|
for (var i = 0; i < length; ++i) {
|
||
|
var parsed = parseInt(string.substr(i * 2, 2), 16)
|
||
|
if (numberIsNaN(parsed)) return i
|
||
|
buf[offset + i] = parsed
|
||
|
}
|
||
|
return i
|
||
|
}
|
||
|
|
||
|
function utf8Write (buf, string, offset, length) {
|
||
|
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
||
|
}
|
||
|
|
||
|
function asciiWrite (buf, string, offset, length) {
|
||
|
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
||
|
}
|
||
|
|
||
|
function latin1Write (buf, string, offset, length) {
|
||
|
return asciiWrite(buf, string, offset, length)
|
||
|
}
|
||
|
|
||
|
function base64Write (buf, string, offset, length) {
|
||
|
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
||
|
}
|
||
|
|
||
|
function ucs2Write (buf, string, offset, length) {
|
||
|
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
||
|
// Buffer#write(string)
|
||
|
if (offset === undefined) {
|
||
|
encoding = 'utf8'
|
||
|
length = this.length
|
||
|
offset = 0
|
||
|
// Buffer#write(string, encoding)
|
||
|
} else if (length === undefined && typeof offset === 'string') {
|
||
|
encoding = offset
|
||
|
length = this.length
|
||
|
offset = 0
|
||
|
// Buffer#write(string, offset[, length][, encoding])
|
||
|
} else if (isFinite(offset)) {
|
||
|
offset = offset >>> 0
|
||
|
if (isFinite(length)) {
|
||
|
length = length >>> 0
|
||
|
if (encoding === undefined) encoding = 'utf8'
|
||
|
} else {
|
||
|
encoding = length
|
||
|
length = undefined
|
||
|
}
|
||
|
} else {
|
||
|
throw new Error(
|
||
|
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
||
|
)
|
||
|
}
|
||
|
|
||
|
var remaining = this.length - offset
|
||
|
if (length === undefined || length > remaining) length = remaining
|
||
|
|
||
|
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
||
|
throw new RangeError('Attempt to write outside buffer bounds')
|
||
|
}
|
||
|
|
||
|
if (!encoding) encoding = 'utf8'
|
||
|
|
||
|
var loweredCase = false
|
||
|
for (;;) {
|
||
|
switch (encoding) {
|
||
|
case 'hex':
|
||
|
return hexWrite(this, string, offset, length)
|
||
|
|
||
|
case 'utf8':
|
||
|
case 'utf-8':
|
||
|
return utf8Write(this, string, offset, length)
|
||
|
|
||
|
case 'ascii':
|
||
|
return asciiWrite(this, string, offset, length)
|
||
|
|
||
|
case 'latin1':
|
||
|
case 'binary':
|
||
|
return latin1Write(this, string, offset, length)
|
||
|
|
||
|
case 'base64':
|
||
|
// Warning: maxLength not taken into account in base64Write
|
||
|
return base64Write(this, string, offset, length)
|
||
|
|
||
|
case 'ucs2':
|
||
|
case 'ucs-2':
|
||
|
case 'utf16le':
|
||
|
case 'utf-16le':
|
||
|
return ucs2Write(this, string, offset, length)
|
||
|
|
||
|
default:
|
||
|
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
||
|
encoding = ('' + encoding).toLowerCase()
|
||
|
loweredCase = true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.toJSON = function toJSON () {
|
||
|
return {
|
||
|
type: 'Buffer',
|
||
|
data: Array.prototype.slice.call(this._arr || this, 0)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function base64Slice (buf, start, end) {
|
||
|
if (start === 0 && end === buf.length) {
|
||
|
return base64.fromByteArray(buf)
|
||
|
} else {
|
||
|
return base64.fromByteArray(buf.slice(start, end))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function utf8Slice (buf, start, end) {
|
||
|
end = Math.min(buf.length, end)
|
||
|
var res = []
|
||
|
|
||
|
var i = start
|
||
|
while (i < end) {
|
||
|
var firstByte = buf[i]
|
||
|
var codePoint = null
|
||
|
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
||
|
: (firstByte > 0xDF) ? 3
|
||
|
: (firstByte > 0xBF) ? 2
|
||
|
: 1
|
||
|
|
||
|
if (i + bytesPerSequence <= end) {
|
||
|
var secondByte, thirdByte, fourthByte, tempCodePoint
|
||
|
|
||
|
switch (bytesPerSequence) {
|
||
|
case 1:
|
||
|
if (firstByte < 0x80) {
|
||
|
codePoint = firstByte
|
||
|
}
|
||
|
break
|
||
|
case 2:
|
||
|
secondByte = buf[i + 1]
|
||
|
if ((secondByte & 0xC0) === 0x80) {
|
||
|
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
||
|
if (tempCodePoint > 0x7F) {
|
||
|
codePoint = tempCodePoint
|
||
|
}
|
||
|
}
|
||
|
break
|
||
|
case 3:
|
||
|
secondByte = buf[i + 1]
|
||
|
thirdByte = buf[i + 2]
|
||
|
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
||
|
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
||
|
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
||
|
codePoint = tempCodePoint
|
||
|
}
|
||
|
}
|
||
|
break
|
||
|
case 4:
|
||
|
secondByte = buf[i + 1]
|
||
|
thirdByte = buf[i + 2]
|
||
|
fourthByte = buf[i + 3]
|
||
|
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
||
|
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
||
|
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
||
|
codePoint = tempCodePoint
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (codePoint === null) {
|
||
|
// we did not generate a valid codePoint so insert a
|
||
|
// replacement char (U+FFFD) and advance only 1 byte
|
||
|
codePoint = 0xFFFD
|
||
|
bytesPerSequence = 1
|
||
|
} else if (codePoint > 0xFFFF) {
|
||
|
// encode to utf16 (surrogate pair dance)
|
||
|
codePoint -= 0x10000
|
||
|
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
||
|
codePoint = 0xDC00 | codePoint & 0x3FF
|
||
|
}
|
||
|
|
||
|
res.push(codePoint)
|
||
|
i += bytesPerSequence
|
||
|
}
|
||
|
|
||
|
return decodeCodePointsArray(res)
|
||
|
}
|
||
|
|
||
|
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
||
|
// the lowest limit is Chrome, with 0x10000 args.
|
||
|
// We go 1 magnitude less, for safety
|
||
|
var MAX_ARGUMENTS_LENGTH = 0x1000
|
||
|
|
||
|
function decodeCodePointsArray (codePoints) {
|
||
|
var len = codePoints.length
|
||
|
if (len <= MAX_ARGUMENTS_LENGTH) {
|
||
|
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
||
|
}
|
||
|
|
||
|
// Decode in chunks to avoid "call stack size exceeded".
|
||
|
var res = ''
|
||
|
var i = 0
|
||
|
while (i < len) {
|
||
|
res += String.fromCharCode.apply(
|
||
|
String,
|
||
|
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
||
|
)
|
||
|
}
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
function asciiSlice (buf, start, end) {
|
||
|
var ret = ''
|
||
|
end = Math.min(buf.length, end)
|
||
|
|
||
|
for (var i = start; i < end; ++i) {
|
||
|
ret += String.fromCharCode(buf[i] & 0x7F)
|
||
|
}
|
||
|
return ret
|
||
|
}
|
||
|
|
||
|
function latin1Slice (buf, start, end) {
|
||
|
var ret = ''
|
||
|
end = Math.min(buf.length, end)
|
||
|
|
||
|
for (var i = start; i < end; ++i) {
|
||
|
ret += String.fromCharCode(buf[i])
|
||
|
}
|
||
|
return ret
|
||
|
}
|
||
|
|
||
|
function hexSlice (buf, start, end) {
|
||
|
var len = buf.length
|
||
|
|
||
|
if (!start || start < 0) start = 0
|
||
|
if (!end || end < 0 || end > len) end = len
|
||
|
|
||
|
var out = ''
|
||
|
for (var i = start; i < end; ++i) {
|
||
|
out += toHex(buf[i])
|
||
|
}
|
||
|
return out
|
||
|
}
|
||
|
|
||
|
function utf16leSlice (buf, start, end) {
|
||
|
var bytes = buf.slice(start, end)
|
||
|
var res = ''
|
||
|
for (var i = 0; i < bytes.length; i += 2) {
|
||
|
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
|
||
|
}
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.slice = function slice (start, end) {
|
||
|
var len = this.length
|
||
|
start = ~~start
|
||
|
end = end === undefined ? len : ~~end
|
||
|
|
||
|
if (start < 0) {
|
||
|
start += len
|
||
|
if (start < 0) start = 0
|
||
|
} else if (start > len) {
|
||
|
start = len
|
||
|
}
|
||
|
|
||
|
if (end < 0) {
|
||
|
end += len
|
||
|
if (end < 0) end = 0
|
||
|
} else if (end > len) {
|
||
|
end = len
|
||
|
}
|
||
|
|
||
|
if (end < start) end = start
|
||
|
|
||
|
var newBuf = this.subarray(start, end)
|
||
|
// Return an augmented `Uint8Array` instance
|
||
|
newBuf.__proto__ = Buffer.prototype
|
||
|
return newBuf
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Need to make sure that buffer isn't trying to write out of bounds.
|
||
|
*/
|
||
|
function checkOffset (offset, ext, length) {
|
||
|
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
||
|
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
byteLength = byteLength >>> 0
|
||
|
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
||
|
|
||
|
var val = this[offset]
|
||
|
var mul = 1
|
||
|
var i = 0
|
||
|
while (++i < byteLength && (mul *= 0x100)) {
|
||
|
val += this[offset + i] * mul
|
||
|
}
|
||
|
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
byteLength = byteLength >>> 0
|
||
|
if (!noAssert) {
|
||
|
checkOffset(offset, byteLength, this.length)
|
||
|
}
|
||
|
|
||
|
var val = this[offset + --byteLength]
|
||
|
var mul = 1
|
||
|
while (byteLength > 0 && (mul *= 0x100)) {
|
||
|
val += this[offset + --byteLength] * mul
|
||
|
}
|
||
|
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 1, this.length)
|
||
|
return this[offset]
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 2, this.length)
|
||
|
return this[offset] | (this[offset + 1] << 8)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 2, this.length)
|
||
|
return (this[offset] << 8) | this[offset + 1]
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 4, this.length)
|
||
|
|
||
|
return ((this[offset]) |
|
||
|
(this[offset + 1] << 8) |
|
||
|
(this[offset + 2] << 16)) +
|
||
|
(this[offset + 3] * 0x1000000)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 4, this.length)
|
||
|
|
||
|
return (this[offset] * 0x1000000) +
|
||
|
((this[offset + 1] << 16) |
|
||
|
(this[offset + 2] << 8) |
|
||
|
this[offset + 3])
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
byteLength = byteLength >>> 0
|
||
|
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
||
|
|
||
|
var val = this[offset]
|
||
|
var mul = 1
|
||
|
var i = 0
|
||
|
while (++i < byteLength && (mul *= 0x100)) {
|
||
|
val += this[offset + i] * mul
|
||
|
}
|
||
|
mul *= 0x80
|
||
|
|
||
|
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
||
|
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
byteLength = byteLength >>> 0
|
||
|
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
||
|
|
||
|
var i = byteLength
|
||
|
var mul = 1
|
||
|
var val = this[offset + --i]
|
||
|
while (i > 0 && (mul *= 0x100)) {
|
||
|
val += this[offset + --i] * mul
|
||
|
}
|
||
|
mul *= 0x80
|
||
|
|
||
|
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
||
|
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 1, this.length)
|
||
|
if (!(this[offset] & 0x80)) return (this[offset])
|
||
|
return ((0xff - this[offset] + 1) * -1)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 2, this.length)
|
||
|
var val = this[offset] | (this[offset + 1] << 8)
|
||
|
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 2, this.length)
|
||
|
var val = this[offset + 1] | (this[offset] << 8)
|
||
|
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 4, this.length)
|
||
|
|
||
|
return (this[offset]) |
|
||
|
(this[offset + 1] << 8) |
|
||
|
(this[offset + 2] << 16) |
|
||
|
(this[offset + 3] << 24)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 4, this.length)
|
||
|
|
||
|
return (this[offset] << 24) |
|
||
|
(this[offset + 1] << 16) |
|
||
|
(this[offset + 2] << 8) |
|
||
|
(this[offset + 3])
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 4, this.length)
|
||
|
return ieee754.read(this, offset, true, 23, 4)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 4, this.length)
|
||
|
return ieee754.read(this, offset, false, 23, 4)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 8, this.length)
|
||
|
return ieee754.read(this, offset, true, 52, 8)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkOffset(offset, 8, this.length)
|
||
|
return ieee754.read(this, offset, false, 52, 8)
|
||
|
}
|
||
|
|
||
|
function checkInt (buf, value, offset, ext, max, min) {
|
||
|
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
||
|
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
||
|
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
byteLength = byteLength >>> 0
|
||
|
if (!noAssert) {
|
||
|
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
||
|
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
||
|
}
|
||
|
|
||
|
var mul = 1
|
||
|
var i = 0
|
||
|
this[offset] = value & 0xFF
|
||
|
while (++i < byteLength && (mul *= 0x100)) {
|
||
|
this[offset + i] = (value / mul) & 0xFF
|
||
|
}
|
||
|
|
||
|
return offset + byteLength
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
byteLength = byteLength >>> 0
|
||
|
if (!noAssert) {
|
||
|
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
||
|
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
||
|
}
|
||
|
|
||
|
var i = byteLength - 1
|
||
|
var mul = 1
|
||
|
this[offset + i] = value & 0xFF
|
||
|
while (--i >= 0 && (mul *= 0x100)) {
|
||
|
this[offset + i] = (value / mul) & 0xFF
|
||
|
}
|
||
|
|
||
|
return offset + byteLength
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
||
|
this[offset] = (value & 0xff)
|
||
|
return offset + 1
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
||
|
this[offset] = (value & 0xff)
|
||
|
this[offset + 1] = (value >>> 8)
|
||
|
return offset + 2
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
||
|
this[offset] = (value >>> 8)
|
||
|
this[offset + 1] = (value & 0xff)
|
||
|
return offset + 2
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
||
|
this[offset + 3] = (value >>> 24)
|
||
|
this[offset + 2] = (value >>> 16)
|
||
|
this[offset + 1] = (value >>> 8)
|
||
|
this[offset] = (value & 0xff)
|
||
|
return offset + 4
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
||
|
this[offset] = (value >>> 24)
|
||
|
this[offset + 1] = (value >>> 16)
|
||
|
this[offset + 2] = (value >>> 8)
|
||
|
this[offset + 3] = (value & 0xff)
|
||
|
return offset + 4
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) {
|
||
|
var limit = Math.pow(2, (8 * byteLength) - 1)
|
||
|
|
||
|
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
||
|
}
|
||
|
|
||
|
var i = 0
|
||
|
var mul = 1
|
||
|
var sub = 0
|
||
|
this[offset] = value & 0xFF
|
||
|
while (++i < byteLength && (mul *= 0x100)) {
|
||
|
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
||
|
sub = 1
|
||
|
}
|
||
|
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
||
|
}
|
||
|
|
||
|
return offset + byteLength
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) {
|
||
|
var limit = Math.pow(2, (8 * byteLength) - 1)
|
||
|
|
||
|
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
||
|
}
|
||
|
|
||
|
var i = byteLength - 1
|
||
|
var mul = 1
|
||
|
var sub = 0
|
||
|
this[offset + i] = value & 0xFF
|
||
|
while (--i >= 0 && (mul *= 0x100)) {
|
||
|
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
||
|
sub = 1
|
||
|
}
|
||
|
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
||
|
}
|
||
|
|
||
|
return offset + byteLength
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
||
|
if (value < 0) value = 0xff + value + 1
|
||
|
this[offset] = (value & 0xff)
|
||
|
return offset + 1
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
||
|
this[offset] = (value & 0xff)
|
||
|
this[offset + 1] = (value >>> 8)
|
||
|
return offset + 2
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
||
|
this[offset] = (value >>> 8)
|
||
|
this[offset + 1] = (value & 0xff)
|
||
|
return offset + 2
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
||
|
this[offset] = (value & 0xff)
|
||
|
this[offset + 1] = (value >>> 8)
|
||
|
this[offset + 2] = (value >>> 16)
|
||
|
this[offset + 3] = (value >>> 24)
|
||
|
return offset + 4
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
||
|
if (value < 0) value = 0xffffffff + value + 1
|
||
|
this[offset] = (value >>> 24)
|
||
|
this[offset + 1] = (value >>> 16)
|
||
|
this[offset + 2] = (value >>> 8)
|
||
|
this[offset + 3] = (value & 0xff)
|
||
|
return offset + 4
|
||
|
}
|
||
|
|
||
|
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
||
|
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
||
|
if (offset < 0) throw new RangeError('Index out of range')
|
||
|
}
|
||
|
|
||
|
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) {
|
||
|
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
||
|
}
|
||
|
ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
||
|
return offset + 4
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
||
|
return writeFloat(this, value, offset, true, noAssert)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
||
|
return writeFloat(this, value, offset, false, noAssert)
|
||
|
}
|
||
|
|
||
|
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
||
|
value = +value
|
||
|
offset = offset >>> 0
|
||
|
if (!noAssert) {
|
||
|
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
||
|
}
|
||
|
ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
||
|
return offset + 8
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
||
|
return writeDouble(this, value, offset, true, noAssert)
|
||
|
}
|
||
|
|
||
|
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
||
|
return writeDouble(this, value, offset, false, noAssert)
|
||
|
}
|
||
|
|
||
|
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
||
|
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
||
|
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
||
|
if (!start) start = 0
|
||
|
if (!end && end !== 0) end = this.length
|
||
|
if (targetStart >= target.length) targetStart = target.length
|
||
|
if (!targetStart) targetStart = 0
|
||
|
if (end > 0 && end < start) end = start
|
||
|
|
||
|
// Copy 0 bytes; we're done
|
||
|
if (end === start) return 0
|
||
|
if (target.length === 0 || this.length === 0) return 0
|
||
|
|
||
|
// Fatal error conditions
|
||
|
if (targetStart < 0) {
|
||
|
throw new RangeError('targetStart out of bounds')
|
||
|
}
|
||
|
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
||
|
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
||
|
|
||
|
// Are we oob?
|
||
|
if (end > this.length) end = this.length
|
||
|
if (target.length - targetStart < end - start) {
|
||
|
end = target.length - targetStart + start
|
||
|
}
|
||
|
|
||
|
var len = end - start
|
||
|
|
||
|
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
||
|
// Use built-in when available, missing from IE11
|
||
|
this.copyWithin(targetStart, start, end)
|
||
|
} else if (this === target && start < targetStart && targetStart < end) {
|
||
|
// descending copy from end
|
||
|
for (var i = len - 1; i >= 0; --i) {
|
||
|
target[i + targetStart] = this[i + start]
|
||
|
}
|
||
|
} else {
|
||
|
Uint8Array.prototype.set.call(
|
||
|
target,
|
||
|
this.subarray(start, end),
|
||
|
targetStart
|
||
|
)
|
||
|
}
|
||
|
|
||
|
return len
|
||
|
}
|
||
|
|
||
|
// Usage:
|
||
|
// buffer.fill(number[, offset[, end]])
|
||
|
// buffer.fill(buffer[, offset[, end]])
|
||
|
// buffer.fill(string[, offset[, end]][, encoding])
|
||
|
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
||
|
// Handle string cases:
|
||
|
if (typeof val === 'string') {
|
||
|
if (typeof start === 'string') {
|
||
|
encoding = start
|
||
|
start = 0
|
||
|
end = this.length
|
||
|
} else if (typeof end === 'string') {
|
||
|
encoding = end
|
||
|
end = this.length
|
||
|
}
|
||
|
if (encoding !== undefined && typeof encoding !== 'string') {
|
||
|
throw new TypeError('encoding must be a string')
|
||
|
}
|
||
|
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
||
|
throw new TypeError('Unknown encoding: ' + encoding)
|
||
|
}
|
||
|
if (val.length === 1) {
|
||
|
var code = val.charCodeAt(0)
|
||
|
if ((encoding === 'utf8' && code < 128) ||
|
||
|
encoding === 'latin1') {
|
||
|
// Fast path: If `val` fits into a single byte, use that numeric value.
|
||
|
val = code
|
||
|
}
|
||
|
}
|
||
|
} else if (typeof val === 'number') {
|
||
|
val = val & 255
|
||
|
}
|
||
|
|
||
|
// Invalid ranges are not set to a default, so can range check early.
|
||
|
if (start < 0 || this.length < start || this.length < end) {
|
||
|
throw new RangeError('Out of range index')
|
||
|
}
|
||
|
|
||
|
if (end <= start) {
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
start = start >>> 0
|
||
|
end = end === undefined ? this.length : end >>> 0
|
||
|
|
||
|
if (!val) val = 0
|
||
|
|
||
|
var i
|
||
|
if (typeof val === 'number') {
|
||
|
for (i = start; i < end; ++i) {
|
||
|
this[i] = val
|
||
|
}
|
||
|
} else {
|
||
|
var bytes = Buffer.isBuffer(val)
|
||
|
? val
|
||
|
: new Buffer(val, encoding)
|
||
|
var len = bytes.length
|
||
|
if (len === 0) {
|
||
|
throw new TypeError('The value "' + val +
|
||
|
'" is invalid for argument "value"')
|
||
|
}
|
||
|
for (i = 0; i < end - start; ++i) {
|
||
|
this[i + start] = bytes[i % len]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
// HELPER FUNCTIONS
|
||
|
// ================
|
||
|
|
||
|
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
|
||
|
|
||
|
function base64clean (str) {
|
||
|
// Node takes equal signs as end of the Base64 encoding
|
||
|
str = str.split('=')[0]
|
||
|
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
||
|
str = str.trim().replace(INVALID_BASE64_RE, '')
|
||
|
// Node converts strings with length < 2 to ''
|
||
|
if (str.length < 2) return ''
|
||
|
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
||
|
while (str.length % 4 !== 0) {
|
||
|
str = str + '='
|
||
|
}
|
||
|
return str
|
||
|
}
|
||
|
|
||
|
function toHex (n) {
|
||
|
if (n < 16) return '0' + n.toString(16)
|
||
|
return n.toString(16)
|
||
|
}
|
||
|
|
||
|
function utf8ToBytes (string, units) {
|
||
|
units = units || Infinity
|
||
|
var codePoint
|
||
|
var length = string.length
|
||
|
var leadSurrogate = null
|
||
|
var bytes = []
|
||
|
|
||
|
for (var i = 0; i < length; ++i) {
|
||
|
codePoint = string.charCodeAt(i)
|
||
|
|
||
|
// is surrogate component
|
||
|
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
||
|
// last char was a lead
|
||
|
if (!leadSurrogate) {
|
||
|
// no lead yet
|
||
|
if (codePoint > 0xDBFF) {
|
||
|
// unexpected trail
|
||
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
||
|
continue
|
||
|
} else if (i + 1 === length) {
|
||
|
// unpaired lead
|
||
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
// valid lead
|
||
|
leadSurrogate = codePoint
|
||
|
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
// 2 leads in a row
|
||
|
if (codePoint < 0xDC00) {
|
||
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
||
|
leadSurrogate = codePoint
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
// valid surrogate pair
|
||
|
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
||
|
} else if (leadSurrogate) {
|
||
|
// valid bmp char, but last char was a lead
|
||
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
||
|
}
|
||
|
|
||
|
leadSurrogate = null
|
||
|
|
||
|
// encode utf8
|
||
|
if (codePoint < 0x80) {
|
||
|
if ((units -= 1) < 0) break
|
||
|
bytes.push(codePoint)
|
||
|
} else if (codePoint < 0x800) {
|
||
|
if ((units -= 2) < 0) break
|
||
|
bytes.push(
|
||
|
codePoint >> 0x6 | 0xC0,
|
||
|
codePoint & 0x3F | 0x80
|
||
|
)
|
||
|
} else if (codePoint < 0x10000) {
|
||
|
if ((units -= 3) < 0) break
|
||
|
bytes.push(
|
||
|
codePoint >> 0xC | 0xE0,
|
||
|
codePoint >> 0x6 & 0x3F | 0x80,
|
||
|
codePoint & 0x3F | 0x80
|
||
|
)
|
||
|
} else if (codePoint < 0x110000) {
|
||
|
if ((units -= 4) < 0) break
|
||
|
bytes.push(
|
||
|
codePoint >> 0x12 | 0xF0,
|
||
|
codePoint >> 0xC & 0x3F | 0x80,
|
||
|
codePoint >> 0x6 & 0x3F | 0x80,
|
||
|
codePoint & 0x3F | 0x80
|
||
|
)
|
||
|
} else {
|
||
|
throw new Error('Invalid code point')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return bytes
|
||
|
}
|
||
|
|
||
|
function asciiToBytes (str) {
|
||
|
var byteArray = []
|
||
|
for (var i = 0; i < str.length; ++i) {
|
||
|
// Node's code seems to be doing this and not & 0x7F..
|
||
|
byteArray.push(str.charCodeAt(i) & 0xFF)
|
||
|
}
|
||
|
return byteArray
|
||
|
}
|
||
|
|
||
|
function utf16leToBytes (str, units) {
|
||
|
var c, hi, lo
|
||
|
var byteArray = []
|
||
|
for (var i = 0; i < str.length; ++i) {
|
||
|
if ((units -= 2) < 0) break
|
||
|
|
||
|
c = str.charCodeAt(i)
|
||
|
hi = c >> 8
|
||
|
lo = c % 256
|
||
|
byteArray.push(lo)
|
||
|
byteArray.push(hi)
|
||
|
}
|
||
|
|
||
|
return byteArray
|
||
|
}
|
||
|
|
||
|
function base64ToBytes (str) {
|
||
|
return base64.toByteArray(base64clean(str))
|
||
|
}
|
||
|
|
||
|
function blitBuffer (src, dst, offset, length) {
|
||
|
for (var i = 0; i < length; ++i) {
|
||
|
if ((i + offset >= dst.length) || (i >= src.length)) break
|
||
|
dst[i + offset] = src[i]
|
||
|
}
|
||
|
return i
|
||
|
}
|
||
|
|
||
|
// ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
|
||
|
// but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
|
||
|
function isArrayBuffer (obj) {
|
||
|
return obj instanceof ArrayBuffer ||
|
||
|
(obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
|
||
|
typeof obj.byteLength === 'number')
|
||
|
}
|
||
|
|
||
|
function numberIsNaN (obj) {
|
||
|
return obj !== obj // eslint-disable-line no-self-compare
|
||
|
}
|
||
|
|
||
|
},{"base64-js":37,"ieee754":49}],42:[function(require,module,exports){
|
||
|
(function (Buffer){
|
||
|
// 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.
|
||
|
|
||
|
// NOTE: These type checking functions intentionally don't use `instanceof`
|
||
|
// because it is fragile and can be easily faked with `Object.create()`.
|
||
|
|
||
|
function isArray(arg) {
|
||
|
if (Array.isArray) {
|
||
|
return Array.isArray(arg);
|
||
|
}
|
||
|
return objectToString(arg) === '[object Array]';
|
||
|
}
|
||
|
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 objectToString(re) === '[object RegExp]';
|
||
|
}
|
||
|
exports.isRegExp = isRegExp;
|
||
|
|
||
|
function isObject(arg) {
|
||
|
return typeof arg === 'object' && arg !== null;
|
||
|
}
|
||
|
exports.isObject = isObject;
|
||
|
|
||
|
function isDate(d) {
|
||
|
return objectToString(d) === '[object Date]';
|
||
|
}
|
||
|
exports.isDate = isDate;
|
||
|
|
||
|
function isError(e) {
|
||
|
return (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 = Buffer.isBuffer;
|
||
|
|
||
|
function objectToString(o) {
|
||
|
return Object.prototype.toString.call(o);
|
||
|
}
|
||
|
|
||
|
}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
|
||
|
},{"../../is-buffer/index.js":51}],43:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
/**
|
||
|
* This is the web browser implementation of `debug()`.
|
||
|
*
|
||
|
* Expose `debug()` as the module.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = require('./debug');
|
||
|
exports.log = log;
|
||
|
exports.formatArgs = formatArgs;
|
||
|
exports.save = save;
|
||
|
exports.load = load;
|
||
|
exports.useColors = useColors;
|
||
|
exports.storage = 'undefined' != typeof chrome
|
||
|
&& 'undefined' != typeof chrome.storage
|
||
|
? chrome.storage.local
|
||
|
: localstorage();
|
||
|
|
||
|
/**
|
||
|
* Colors.
|
||
|
*/
|
||
|
|
||
|
exports.colors = [
|
||
|
'#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC',
|
||
|
'#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF',
|
||
|
'#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC',
|
||
|
'#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF',
|
||
|
'#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC',
|
||
|
'#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033',
|
||
|
'#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366',
|
||
|
'#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
|
||
|
'#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC',
|
||
|
'#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF',
|
||
|
'#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||
|
* and the Firebug extension (any Firefox version) are known
|
||
|
* to support "%c" CSS customizations.
|
||
|
*
|
||
|
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||
|
*/
|
||
|
|
||
|
function useColors() {
|
||
|
// NB: In an Electron preload script, document will be defined but not fully
|
||
|
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||
|
// explicitly
|
||
|
if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// Internet Explorer and Edge do not support colors.
|
||
|
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// is webkit? http://stackoverflow.com/a/16459606/376773
|
||
|
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||
|
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
||
|
// is firebug? http://stackoverflow.com/a/398120/376773
|
||
|
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
||
|
// is firefox >= v31?
|
||
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||
|
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
||
|
// double check webkit in userAgent just in case we are in a worker
|
||
|
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||
|
*/
|
||
|
|
||
|
exports.formatters.j = function(v) {
|
||
|
try {
|
||
|
return JSON.stringify(v);
|
||
|
} catch (err) {
|
||
|
return '[UnexpectedJSONParseError]: ' + err.message;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Colorize log arguments if enabled.
|
||
|
*
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function formatArgs(args) {
|
||
|
var useColors = this.useColors;
|
||
|
|
||
|
args[0] = (useColors ? '%c' : '')
|
||
|
+ this.namespace
|
||
|
+ (useColors ? ' %c' : ' ')
|
||
|
+ args[0]
|
||
|
+ (useColors ? '%c ' : ' ')
|
||
|
+ '+' + exports.humanize(this.diff);
|
||
|
|
||
|
if (!useColors) return;
|
||
|
|
||
|
var c = 'color: ' + this.color;
|
||
|
args.splice(1, 0, c, 'color: inherit')
|
||
|
|
||
|
// the final "%c" is somewhat tricky, because there could be other
|
||
|
// arguments passed either before or after the %c, so we need to
|
||
|
// figure out the correct index to insert the CSS into
|
||
|
var index = 0;
|
||
|
var lastC = 0;
|
||
|
args[0].replace(/%[a-zA-Z%]/g, function(match) {
|
||
|
if ('%%' === match) return;
|
||
|
index++;
|
||
|
if ('%c' === match) {
|
||
|
// we only are interested in the *last* %c
|
||
|
// (the user may have provided their own)
|
||
|
lastC = index;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
args.splice(lastC, 0, c);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Invokes `console.log()` when available.
|
||
|
* No-op when `console.log` is not a "function".
|
||
|
*
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function log() {
|
||
|
// this hackery is required for IE8/9, where
|
||
|
// the `console.log` function doesn't have 'apply'
|
||
|
return 'object' === typeof console
|
||
|
&& console.log
|
||
|
&& Function.prototype.apply.call(console.log, console, arguments);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Save `namespaces`.
|
||
|
*
|
||
|
* @param {String} namespaces
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function save(namespaces) {
|
||
|
try {
|
||
|
if (null == namespaces) {
|
||
|
exports.storage.removeItem('debug');
|
||
|
} else {
|
||
|
exports.storage.debug = namespaces;
|
||
|
}
|
||
|
} catch(e) {}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Load `namespaces`.
|
||
|
*
|
||
|
* @return {String} returns the previously persisted debug modes
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function load() {
|
||
|
var r;
|
||
|
try {
|
||
|
r = exports.storage.debug;
|
||
|
} catch(e) {}
|
||
|
|
||
|
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||
|
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||
|
r = process.env.DEBUG;
|
||
|
}
|
||
|
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Enable namespaces listed in `localStorage.debug` initially.
|
||
|
*/
|
||
|
|
||
|
exports.enable(load());
|
||
|
|
||
|
/**
|
||
|
* Localstorage attempts to return the localstorage.
|
||
|
*
|
||
|
* This is necessary because safari throws
|
||
|
* when a user disables cookies/localstorage
|
||
|
* and you attempt to access it.
|
||
|
*
|
||
|
* @return {LocalStorage}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function localstorage() {
|
||
|
try {
|
||
|
return window.localStorage;
|
||
|
} catch (e) {}
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"./debug":44,"_process":56}],44:[function(require,module,exports){
|
||
|
|
||
|
/**
|
||
|
* This is the common logic for both the Node.js and web browser
|
||
|
* implementations of `debug()`.
|
||
|
*
|
||
|
* Expose `debug()` as the module.
|
||
|
*/
|
||
|
|
||
|
exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
|
||
|
exports.coerce = coerce;
|
||
|
exports.disable = disable;
|
||
|
exports.enable = enable;
|
||
|
exports.enabled = enabled;
|
||
|
exports.humanize = require('ms');
|
||
|
|
||
|
/**
|
||
|
* Active `debug` instances.
|
||
|
*/
|
||
|
exports.instances = [];
|
||
|
|
||
|
/**
|
||
|
* The currently active debug mode names, and names to skip.
|
||
|
*/
|
||
|
|
||
|
exports.names = [];
|
||
|
exports.skips = [];
|
||
|
|
||
|
/**
|
||
|
* Map of special "%n" handling functions, for the debug "format" argument.
|
||
|
*
|
||
|
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||
|
*/
|
||
|
|
||
|
exports.formatters = {};
|
||
|
|
||
|
/**
|
||
|
* Select a color.
|
||
|
* @param {String} namespace
|
||
|
* @return {Number}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function selectColor(namespace) {
|
||
|
var hash = 0, i;
|
||
|
|
||
|
for (i in namespace) {
|
||
|
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
||
|
hash |= 0; // Convert to 32bit integer
|
||
|
}
|
||
|
|
||
|
return exports.colors[Math.abs(hash) % exports.colors.length];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Create a debugger with the given `namespace`.
|
||
|
*
|
||
|
* @param {String} namespace
|
||
|
* @return {Function}
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function createDebug(namespace) {
|
||
|
|
||
|
var prevTime;
|
||
|
|
||
|
function debug() {
|
||
|
// disabled?
|
||
|
if (!debug.enabled) return;
|
||
|
|
||
|
var self = debug;
|
||
|
|
||
|
// set `diff` timestamp
|
||
|
var curr = +new Date();
|
||
|
var ms = curr - (prevTime || curr);
|
||
|
self.diff = ms;
|
||
|
self.prev = prevTime;
|
||
|
self.curr = curr;
|
||
|
prevTime = curr;
|
||
|
|
||
|
// turn the `arguments` into a proper Array
|
||
|
var args = new Array(arguments.length);
|
||
|
for (var i = 0; i < args.length; i++) {
|
||
|
args[i] = arguments[i];
|
||
|
}
|
||
|
|
||
|
args[0] = exports.coerce(args[0]);
|
||
|
|
||
|
if ('string' !== typeof args[0]) {
|
||
|
// anything else let's inspect with %O
|
||
|
args.unshift('%O');
|
||
|
}
|
||
|
|
||
|
// apply any `formatters` transformations
|
||
|
var index = 0;
|
||
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
||
|
// if we encounter an escaped % then don't increase the array index
|
||
|
if (match === '%%') return match;
|
||
|
index++;
|
||
|
var formatter = exports.formatters[format];
|
||
|
if ('function' === typeof formatter) {
|
||
|
var val = args[index];
|
||
|
match = formatter.call(self, val);
|
||
|
|
||
|
// now we need to remove `args[index]` since it's inlined in the `format`
|
||
|
args.splice(index, 1);
|
||
|
index--;
|
||
|
}
|
||
|
return match;
|
||
|
});
|
||
|
|
||
|
// apply env-specific formatting (colors, etc.)
|
||
|
exports.formatArgs.call(self, args);
|
||
|
|
||
|
var logFn = debug.log || exports.log || console.log.bind(console);
|
||
|
logFn.apply(self, args);
|
||
|
}
|
||
|
|
||
|
debug.namespace = namespace;
|
||
|
debug.enabled = exports.enabled(namespace);
|
||
|
debug.useColors = exports.useColors();
|
||
|
debug.color = selectColor(namespace);
|
||
|
debug.destroy = destroy;
|
||
|
|
||
|
// env-specific initialization logic for debug instances
|
||
|
if ('function' === typeof exports.init) {
|
||
|
exports.init(debug);
|
||
|
}
|
||
|
|
||
|
exports.instances.push(debug);
|
||
|
|
||
|
return debug;
|
||
|
}
|
||
|
|
||
|
function destroy () {
|
||
|
var index = exports.instances.indexOf(this);
|
||
|
if (index !== -1) {
|
||
|
exports.instances.splice(index, 1);
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Enables a debug mode by namespaces. This can include modes
|
||
|
* separated by a colon and wildcards.
|
||
|
*
|
||
|
* @param {String} namespaces
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function enable(namespaces) {
|
||
|
exports.save(namespaces);
|
||
|
|
||
|
exports.names = [];
|
||
|
exports.skips = [];
|
||
|
|
||
|
var i;
|
||
|
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||
|
var len = split.length;
|
||
|
|
||
|
for (i = 0; i < len; i++) {
|
||
|
if (!split[i]) continue; // ignore empty strings
|
||
|
namespaces = split[i].replace(/\*/g, '.*?');
|
||
|
if (namespaces[0] === '-') {
|
||
|
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||
|
} else {
|
||
|
exports.names.push(new RegExp('^' + namespaces + '$'));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (i = 0; i < exports.instances.length; i++) {
|
||
|
var instance = exports.instances[i];
|
||
|
instance.enabled = exports.enabled(instance.namespace);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Disable debug output.
|
||
|
*
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function disable() {
|
||
|
exports.enable('');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns true if the given mode name is enabled, false otherwise.
|
||
|
*
|
||
|
* @param {String} name
|
||
|
* @return {Boolean}
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function enabled(name) {
|
||
|
if (name[name.length - 1] === '*') {
|
||
|
return true;
|
||
|
}
|
||
|
var i, len;
|
||
|
for (i = 0, len = exports.skips.length; i < len; i++) {
|
||
|
if (exports.skips[i].test(name)) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
for (i = 0, len = exports.names.length; i < len; i++) {
|
||
|
if (exports.names[i].test(name)) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Coerce `val`.
|
||
|
*
|
||
|
* @param {Mixed} val
|
||
|
* @return {Mixed}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function coerce(val) {
|
||
|
if (val instanceof Error) return val.stack || val.message;
|
||
|
return val;
|
||
|
}
|
||
|
|
||
|
},{"ms":54}],45:[function(require,module,exports){
|
||
|
/*!
|
||
|
|
||
|
diff v3.5.0
|
||
|
|
||
|
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 webpackUniversalModuleDefinition(root, factory) {
|
||
|
if(typeof exports === 'object' && typeof module === 'object')
|
||
|
module.exports = factory();
|
||
|
else if(false)
|
||
|
define([], factory);
|
||
|
else if(typeof exports === 'object')
|
||
|
exports["JsDiff"] = factory();
|
||
|
else
|
||
|
root["JsDiff"] = factory();
|
||
|
})(this, function() {
|
||
|
return /******/ (function(modules) { // webpackBootstrap
|
||
|
/******/ // The module cache
|
||
|
/******/ var installedModules = {};
|
||
|
|
||
|
/******/ // The require function
|
||
|
/******/ function __webpack_require__(moduleId) {
|
||
|
|
||
|
/******/ // Check if module is in cache
|
||
|
/******/ if(installedModules[moduleId])
|
||
|
/******/ return installedModules[moduleId].exports;
|
||
|
|
||
|
/******/ // Create a new module (and put it into the cache)
|
||
|
/******/ var module = installedModules[moduleId] = {
|
||
|
/******/ exports: {},
|
||
|
/******/ id: moduleId,
|
||
|
/******/ loaded: false
|
||
|
/******/ };
|
||
|
|
||
|
/******/ // Execute the module function
|
||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||
|
|
||
|
/******/ // Flag the module as loaded
|
||
|
/******/ module.loaded = true;
|
||
|
|
||
|
/******/ // Return the exports of the module
|
||
|
/******/ return module.exports;
|
||
|
/******/ }
|
||
|
|
||
|
|
||
|
/******/ // expose the modules object (__webpack_modules__)
|
||
|
/******/ __webpack_require__.m = modules;
|
||
|
|
||
|
/******/ // expose the module cache
|
||
|
/******/ __webpack_require__.c = installedModules;
|
||
|
|
||
|
/******/ // __webpack_public_path__
|
||
|
/******/ __webpack_require__.p = "";
|
||
|
|
||
|
/******/ // Load entry module and return exports
|
||
|
/******/ return __webpack_require__(0);
|
||
|
/******/ })
|
||
|
/************************************************************************/
|
||
|
/******/ ([
|
||
|
/* 0 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.canonicalize = exports.convertChangesToXML = exports.convertChangesToDMP = exports.merge = exports.parsePatch = exports.applyPatches = exports.applyPatch = exports.createPatch = exports.createTwoFilesPatch = exports.structuredPatch = exports.diffArrays = exports.diffJson = exports.diffCss = exports.diffSentences = exports.diffTrimmedLines = exports.diffLines = exports.diffWordsWithSpace = exports.diffWords = exports.diffChars = exports.Diff = undefined;
|
||
|
|
||
|
/*istanbul ignore end*/var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
/*istanbul ignore end*/var /*istanbul ignore start*/_character = __webpack_require__(2) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_word = __webpack_require__(3) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_line = __webpack_require__(5) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_sentence = __webpack_require__(6) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_css = __webpack_require__(7) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_json = __webpack_require__(8) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_array = __webpack_require__(9) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_apply = __webpack_require__(10) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_parse = __webpack_require__(11) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_merge = __webpack_require__(13) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_create = __webpack_require__(14) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_dmp = __webpack_require__(16) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_xml = __webpack_require__(17) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/* See LICENSE file for terms of use */
|
||
|
|
||
|
/*
|
||
|
* Text diff implementation.
|
||
|
*
|
||
|
* This library supports the following APIS:
|
||
|
* JsDiff.diffChars: Character by character diff
|
||
|
* JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
|
||
|
* JsDiff.diffLines: Line based diff
|
||
|
*
|
||
|
* JsDiff.diffCss: Diff targeted at CSS content
|
||
|
*
|
||
|
* These methods are based on the implementation proposed in
|
||
|
* "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
|
||
|
* http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
|
||
|
*/
|
||
|
exports. /*istanbul ignore end*/Diff = _base2['default'];
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffChars = _character.diffChars;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffWords = _word.diffWords;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = _word.diffWordsWithSpace;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffLines = _line.diffLines;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = _line.diffTrimmedLines;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffSentences = _sentence.diffSentences;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffCss = _css.diffCss;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffJson = _json.diffJson;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffArrays = _array.diffArrays;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/structuredPatch = _create.structuredPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = _create.createTwoFilesPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = _create.createPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatch = _apply.applyPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = _apply.applyPatches;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/parsePatch = _parse.parsePatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/merge = _merge.merge;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToDMP = _dmp.convertChangesToDMP;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToXML = _xml.convertChangesToXML;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = _json.canonicalize;
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 1 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports['default'] = /*istanbul ignore end*/Diff;
|
||
|
function Diff() {}
|
||
|
|
||
|
Diff.prototype = {
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/diff: function diff(oldString, newString) {
|
||
|
/*istanbul ignore start*/var /*istanbul ignore end*/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 = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/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 });
|
||
|
}
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/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;
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/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();
|
||
|
}
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/removeEmpty: function removeEmpty(array) {
|
||
|
var ret = [];
|
||
|
for (var i = 0; i < array.length; i++) {
|
||
|
if (array[i]) {
|
||
|
ret.push(array[i]);
|
||
|
}
|
||
|
}
|
||
|
return ret;
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/castInput: function castInput(value) {
|
||
|
return value;
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/tokenize: function tokenize(value) {
|
||
|
return value.split('');
|
||
|
},
|
||
|
/*istanbul ignore start*/ /*istanbul ignore end*/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) };
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 2 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.characterDiff = undefined;
|
||
|
exports. /*istanbul ignore end*/diffChars = diffChars;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/var characterDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/characterDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
function diffChars(oldStr, newStr, options) {
|
||
|
return characterDiff.diff(oldStr, newStr, options);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 3 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.wordDiff = undefined;
|
||
|
exports. /*istanbul ignore end*/diffWords = diffWords;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = diffWordsWithSpace;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
/*istanbul ignore end*/var /*istanbul ignore start*/_params = __webpack_require__(4) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/ // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
|
||
|
//
|
||
|
// 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 = /*istanbul ignore start*/exports. /*istanbul ignore end*/wordDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
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 = /*istanbul ignore start*/(0, _params.generateOptions) /*istanbul ignore end*/(options, { ignoreWhitespace: true });
|
||
|
return wordDiff.diff(oldStr, newStr, options);
|
||
|
}
|
||
|
|
||
|
function diffWordsWithSpace(oldStr, newStr, options) {
|
||
|
return wordDiff.diff(oldStr, newStr, options);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 4 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/generateOptions = generateOptions;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 5 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.lineDiff = undefined;
|
||
|
exports. /*istanbul ignore end*/diffLines = diffLines;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = diffTrimmedLines;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
/*istanbul ignore end*/var /*istanbul ignore start*/_params = __webpack_require__(4) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/var lineDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/lineDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
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 = /*istanbul ignore start*/(0, _params.generateOptions) /*istanbul ignore end*/(callback, { ignoreWhitespace: true });
|
||
|
return lineDiff.diff(oldStr, newStr, options);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 6 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.sentenceDiff = undefined;
|
||
|
exports. /*istanbul ignore end*/diffSentences = diffSentences;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/var sentenceDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/sentenceDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
sentenceDiff.tokenize = function (value) {
|
||
|
return value.split(/(\S.+?[.!?])(?=\s+|$)/);
|
||
|
};
|
||
|
|
||
|
function diffSentences(oldStr, newStr, callback) {
|
||
|
return sentenceDiff.diff(oldStr, newStr, callback);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 7 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.cssDiff = undefined;
|
||
|
exports. /*istanbul ignore end*/diffCss = diffCss;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/var cssDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/cssDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
cssDiff.tokenize = function (value) {
|
||
|
return value.split(/([{}:;,]|\s+)/);
|
||
|
};
|
||
|
|
||
|
function diffCss(oldStr, newStr, callback) {
|
||
|
return cssDiff.diff(oldStr, newStr, callback);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 8 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.jsonDiff = undefined;
|
||
|
|
||
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||
|
|
||
|
exports. /*istanbul ignore end*/diffJson = diffJson;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = canonicalize;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
/*istanbul ignore end*/var /*istanbul ignore start*/_line = __webpack_require__(5) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/var objectPrototypeToString = Object.prototype.toString;
|
||
|
|
||
|
var jsonDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/jsonDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
// 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 = /*istanbul ignore start*/_line.lineDiff /*istanbul ignore end*/.tokenize;
|
||
|
jsonDiff.castInput = function (value) {
|
||
|
/*istanbul ignore start*/var _options = /*istanbul ignore end*/this.options,
|
||
|
undefinedReplacement = _options.undefinedReplacement,
|
||
|
_options$stringifyRep = _options.stringifyReplacer,
|
||
|
stringifyReplacer = _options$stringifyRep === undefined ? function (k, v) /*istanbul ignore start*/{
|
||
|
return (/*istanbul ignore end*/typeof v === 'undefined' ? undefinedReplacement : v
|
||
|
);
|
||
|
} : _options$stringifyRep;
|
||
|
|
||
|
|
||
|
return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
|
||
|
};
|
||
|
jsonDiff.equals = function (left, right) {
|
||
|
return (/*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/.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 = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
|
||
|
|
||
|
for (i = 0; i < stack.length; i += 1) {
|
||
|
if (stack[i] === obj) {
|
||
|
return replacementStack[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var canonicalizedObj = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
|
||
|
|
||
|
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 ( /*istanbul ignore start*/(typeof /*istanbul ignore end*/obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
|
||
|
stack.push(obj);
|
||
|
canonicalizedObj = {};
|
||
|
replacementStack.push(canonicalizedObj);
|
||
|
var sortedKeys = [],
|
||
|
_key = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 9 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.arrayDiff = undefined;
|
||
|
exports. /*istanbul ignore end*/diffArrays = diffArrays;
|
||
|
|
||
|
var /*istanbul ignore start*/_base = __webpack_require__(1) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _base2 = _interopRequireDefault(_base);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/var arrayDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/arrayDiff = new /*istanbul ignore start*/_base2['default'] /*istanbul ignore end*/();
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 10 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/applyPatch = applyPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = applyPatches;
|
||
|
|
||
|
var /*istanbul ignore start*/_parse = __webpack_require__(11) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_distanceIterator = __webpack_require__(12) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/var _distanceIterator2 = _interopRequireDefault(_distanceIterator);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||
|
|
||
|
/*istanbul ignore end*/function applyPatch(source, uniDiff) {
|
||
|
/*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||
|
|
||
|
if (typeof uniDiff === 'string') {
|
||
|
uniDiff = /*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(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) /*istanbul ignore start*/{
|
||
|
return (/*istanbul ignore end*/line === patchContent
|
||
|
);
|
||
|
},
|
||
|
errorCount = 0,
|
||
|
fuzzFactor = options.fuzzFactor || 0,
|
||
|
minLine = 0,
|
||
|
offset = 0,
|
||
|
removeEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
|
||
|
addEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
|
||
|
|
||
|
/**
|
||
|
* 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 = /*istanbul ignore start*/(0, _distanceIterator2['default']) /*istanbul ignore end*/(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 = /*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(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();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 11 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/parsePatch = parsePatch;
|
||
|
function parsePatch(uniDiff) {
|
||
|
/*istanbul ignore start*/var /*istanbul ignore end*/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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 12 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/"use strict";
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
|
||
|
exports["default"] = /*istanbul ignore end*/function (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
|
||
|
};
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 13 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/calcLineCount = calcLineCount;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/merge = merge;
|
||
|
|
||
|
var /*istanbul ignore start*/_create = __webpack_require__(14) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_parse = __webpack_require__(11) /*istanbul ignore end*/;
|
||
|
|
||
|
var /*istanbul ignore start*/_array = __webpack_require__(15) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||
|
|
||
|
/*istanbul ignore end*/function calcLineCount(hunk) {
|
||
|
/*istanbul ignore start*/var _calcOldNewLineCount = /*istanbul ignore end*/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 (/*istanbul ignore start*/(0, _parse.parsePatch) /*istanbul ignore end*/(param)[0]
|
||
|
);
|
||
|
}
|
||
|
|
||
|
if (!base) {
|
||
|
throw new Error('Must provide a base reference or pass in a patch');
|
||
|
}
|
||
|
return (/*istanbul ignore start*/(0, _create.structuredPatch) /*istanbul ignore end*/(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] === ' ') {
|
||
|
/*istanbul ignore start*/var _hunk$lines;
|
||
|
|
||
|
/*istanbul ignore end*/ // Mine inserted
|
||
|
/*istanbul ignore start*/(_hunk$lines = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/collectChange(mine)));
|
||
|
} else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
|
||
|
/*istanbul ignore start*/var _hunk$lines2;
|
||
|
|
||
|
/*istanbul ignore end*/ // Theirs inserted
|
||
|
/*istanbul ignore start*/(_hunk$lines2 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/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 ( /*istanbul ignore start*/(0, _array.arrayStartsWith) /*istanbul ignore end*/(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
|
||
|
/*istanbul ignore start*/var _hunk$lines3;
|
||
|
|
||
|
/*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines3 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/myChanges));
|
||
|
return;
|
||
|
} else if ( /*istanbul ignore start*/(0, _array.arrayStartsWith) /*istanbul ignore end*/(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
|
||
|
/*istanbul ignore start*/var _hunk$lines4;
|
||
|
|
||
|
/*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines4 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines4 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/theirChanges));
|
||
|
return;
|
||
|
}
|
||
|
} else if ( /*istanbul ignore start*/(0, _array.arrayEqual) /*istanbul ignore end*/(myChanges, theirChanges)) {
|
||
|
/*istanbul ignore start*/var _hunk$lines5;
|
||
|
|
||
|
/*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines5 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines5 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/myChanges));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
conflict(hunk, myChanges, theirChanges);
|
||
|
}
|
||
|
|
||
|
function removal(hunk, mine, their, swap) {
|
||
|
var myChanges = collectChange(mine),
|
||
|
theirChanges = collectContext(their, myChanges);
|
||
|
if (theirChanges.merged) {
|
||
|
/*istanbul ignore start*/var _hunk$lines6;
|
||
|
|
||
|
/*istanbul ignore end*/ /*istanbul ignore start*/(_hunk$lines6 = /*istanbul ignore end*/hunk.lines).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_hunk$lines6 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/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 };
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 14 */
|
||
|
/***/ (function(module, exports, __webpack_require__) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/structuredPatch = structuredPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = createTwoFilesPatch;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = createPatch;
|
||
|
|
||
|
var /*istanbul ignore start*/_line = __webpack_require__(5) /*istanbul ignore end*/;
|
||
|
|
||
|
/*istanbul ignore start*/function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||
|
|
||
|
/*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
||
|
if (!options) {
|
||
|
options = {};
|
||
|
}
|
||
|
if (typeof options.context === 'undefined') {
|
||
|
options.context = 4;
|
||
|
}
|
||
|
|
||
|
var diff = /*istanbul ignore start*/(0, _line.diffLines) /*istanbul ignore end*/(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;
|
||
|
|
||
|
/*istanbul ignore start*/var _loop = function _loop( /*istanbul ignore end*/i) {
|
||
|
var current = diff[i],
|
||
|
lines = current.lines || current.value.replace(/\n$/, '').split('\n');
|
||
|
current.lines = lines;
|
||
|
|
||
|
if (current.added || current.removed) {
|
||
|
/*istanbul ignore start*/var _curRange;
|
||
|
|
||
|
/*istanbul ignore end*/ // 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
|
||
|
/*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/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) {
|
||
|
/*istanbul ignore start*/var _curRange2;
|
||
|
|
||
|
/*istanbul ignore end*/ // Overlapping
|
||
|
/*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
|
||
|
} else {
|
||
|
/*istanbul ignore start*/var _curRange3;
|
||
|
|
||
|
/*istanbul ignore end*/ // end the range and output
|
||
|
var contextSize = Math.min(lines.length, options.context);
|
||
|
/*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/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);
|
||
|
if (lines.length == 0 && !oldEOFNewline) {
|
||
|
// 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');
|
||
|
} else if (!oldEOFNewline || !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++) {
|
||
|
/*istanbul ignore start*/_loop( /*istanbul ignore end*/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);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 15 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/"use strict";
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/arrayEqual = arrayEqual;
|
||
|
/*istanbul ignore start*/exports. /*istanbul ignore end*/arrayStartsWith = arrayStartsWith;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 16 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/"use strict";
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/convertChangesToDMP = convertChangesToDMP;
|
||
|
// See: http://code.google.com/p/google-diff-match-patch/wiki/API
|
||
|
function convertChangesToDMP(changes) {
|
||
|
var ret = [],
|
||
|
change = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
|
||
|
operation = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ }),
|
||
|
/* 17 */
|
||
|
/***/ (function(module, exports) {
|
||
|
|
||
|
/*istanbul ignore start*/'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports. /*istanbul ignore end*/convertChangesToXML = convertChangesToXML;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/***/ })
|
||
|
/******/ ])
|
||
|
});
|
||
|
;
|
||
|
},{}],46:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
||
|
|
||
|
module.exports = function (str) {
|
||
|
if (typeof str !== 'string') {
|
||
|
throw new TypeError('Expected a string');
|
||
|
}
|
||
|
|
||
|
return str.replace(matchOperatorsRe, '\\$&');
|
||
|
};
|
||
|
|
||
|
},{}],47:[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 objectCreate = Object.create || objectCreatePolyfill
|
||
|
var objectKeys = Object.keys || objectKeysPolyfill
|
||
|
var bind = Function.prototype.bind || functionBindPolyfill
|
||
|
|
||
|
function EventEmitter() {
|
||
|
if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
|
||
|
this._events = objectCreate(null);
|
||
|
this._eventsCount = 0;
|
||
|
}
|
||
|
|
||
|
this._maxListeners = this._maxListeners || undefined;
|
||
|
}
|
||
|
module.exports = EventEmitter;
|
||
|
|
||
|
// Backwards-compat with node 0.10.x
|
||
|
EventEmitter.EventEmitter = EventEmitter;
|
||
|
|
||
|
EventEmitter.prototype._events = undefined;
|
||
|
EventEmitter.prototype._maxListeners = undefined;
|
||
|
|
||
|
// By default EventEmitters will print a warning if more than 10 listeners are
|
||
|
// added to it. This is a useful default which helps finding memory leaks.
|
||
|
var defaultMaxListeners = 10;
|
||
|
|
||
|
var hasDefineProperty;
|
||
|
try {
|
||
|
var o = {};
|
||
|
if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
|
||
|
hasDefineProperty = o.x === 0;
|
||
|
} catch (err) { hasDefineProperty = false }
|
||
|
if (hasDefineProperty) {
|
||
|
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
||
|
enumerable: true,
|
||
|
get: function() {
|
||
|
return defaultMaxListeners;
|
||
|
},
|
||
|
set: function(arg) {
|
||
|
// check whether the input is a positive number (whose value is zero or
|
||
|
// greater and not a NaN).
|
||
|
if (typeof arg !== 'number' || arg < 0 || arg !== arg)
|
||
|
throw new TypeError('"defaultMaxListeners" must be a positive number');
|
||
|
defaultMaxListeners = arg;
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
EventEmitter.defaultMaxListeners = defaultMaxListeners;
|
||
|
}
|
||
|
|
||
|
// Obviously not all Emitters should be limited to 10. This function allows
|
||
|
// that to be increased. Set to zero for unlimited.
|
||
|
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
||
|
if (typeof n !== 'number' || n < 0 || isNaN(n))
|
||
|
throw new TypeError('"n" argument must be a positive number');
|
||
|
this._maxListeners = n;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
function $getMaxListeners(that) {
|
||
|
if (that._maxListeners === undefined)
|
||
|
return EventEmitter.defaultMaxListeners;
|
||
|
return that._maxListeners;
|
||
|
}
|
||
|
|
||
|
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
||
|
return $getMaxListeners(this);
|
||
|
};
|
||
|
|
||
|
// These standalone emit* functions are used to optimize calling of event
|
||
|
// handlers for fast cases because emit() itself often has a variable number of
|
||
|
// arguments and can be deoptimized because of that. These functions always have
|
||
|
// the same number of arguments and thus do not get deoptimized, so the code
|
||
|
// inside them can execute faster.
|
||
|
function emitNone(handler, isFn, self) {
|
||
|
if (isFn)
|
||
|
handler.call(self);
|
||
|
else {
|
||
|
var len = handler.length;
|
||
|
var listeners = arrayClone(handler, len);
|
||
|
for (var i = 0; i < len; ++i)
|
||
|
listeners[i].call(self);
|
||
|
}
|
||
|
}
|
||
|
function emitOne(handler, isFn, self, arg1) {
|
||
|
if (isFn)
|
||
|
handler.call(self, arg1);
|
||
|
else {
|
||
|
var len = handler.length;
|
||
|
var listeners = arrayClone(handler, len);
|
||
|
for (var i = 0; i < len; ++i)
|
||
|
listeners[i].call(self, arg1);
|
||
|
}
|
||
|
}
|
||
|
function emitTwo(handler, isFn, self, arg1, arg2) {
|
||
|
if (isFn)
|
||
|
handler.call(self, arg1, arg2);
|
||
|
else {
|
||
|
var len = handler.length;
|
||
|
var listeners = arrayClone(handler, len);
|
||
|
for (var i = 0; i < len; ++i)
|
||
|
listeners[i].call(self, arg1, arg2);
|
||
|
}
|
||
|
}
|
||
|
function emitThree(handler, isFn, self, arg1, arg2, arg3) {
|
||
|
if (isFn)
|
||
|
handler.call(self, arg1, arg2, arg3);
|
||
|
else {
|
||
|
var len = handler.length;
|
||
|
var listeners = arrayClone(handler, len);
|
||
|
for (var i = 0; i < len; ++i)
|
||
|
listeners[i].call(self, arg1, arg2, arg3);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function emitMany(handler, isFn, self, args) {
|
||
|
if (isFn)
|
||
|
handler.apply(self, args);
|
||
|
else {
|
||
|
var len = handler.length;
|
||
|
var listeners = arrayClone(handler, len);
|
||
|
for (var i = 0; i < len; ++i)
|
||
|
listeners[i].apply(self, args);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
EventEmitter.prototype.emit = function emit(type) {
|
||
|
var er, handler, len, args, i, events;
|
||
|
var doError = (type === 'error');
|
||
|
|
||
|
events = this._events;
|
||
|
if (events)
|
||
|
doError = (doError && events.error == null);
|
||
|
else if (!doError)
|
||
|
return false;
|
||
|
|
||
|
// If there is no 'error' event listener then throw.
|
||
|
if (doError) {
|
||
|
if (arguments.length > 1)
|
||
|
er = arguments[1];
|
||
|
if (er instanceof Error) {
|
||
|
throw er; // Unhandled 'error' event
|
||
|
} else {
|
||
|
// At least give some kind of context to the user
|
||
|
var err = new Error('Unhandled "error" event. (' + er + ')');
|
||
|
err.context = er;
|
||
|
throw err;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
handler = events[type];
|
||
|
|
||
|
if (!handler)
|
||
|
return false;
|
||
|
|
||
|
var isFn = typeof handler === 'function';
|
||
|
len = arguments.length;
|
||
|
switch (len) {
|
||
|
// fast cases
|
||
|
case 1:
|
||
|
emitNone(handler, isFn, this);
|
||
|
break;
|
||
|
case 2:
|
||
|
emitOne(handler, isFn, this, arguments[1]);
|
||
|
break;
|
||
|
case 3:
|
||
|
emitTwo(handler, isFn, this, arguments[1], arguments[2]);
|
||
|
break;
|
||
|
case 4:
|
||
|
emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
|
||
|
break;
|
||
|
// slower
|
||
|
default:
|
||
|
args = new Array(len - 1);
|
||
|
for (i = 1; i < len; i++)
|
||
|
args[i - 1] = arguments[i];
|
||
|
emitMany(handler, isFn, this, args);
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
};
|
||
|
|
||
|
function _addListener(target, type, listener, prepend) {
|
||
|
var m;
|
||
|
var events;
|
||
|
var existing;
|
||
|
|
||
|
if (typeof listener !== 'function')
|
||
|
throw new TypeError('"listener" argument must be a function');
|
||
|
|
||
|
events = target._events;
|
||
|
if (!events) {
|
||
|
events = target._events = objectCreate(null);
|
||
|
target._eventsCount = 0;
|
||
|
} else {
|
||
|
// To avoid recursion in the case that type === "newListener"! Before
|
||
|
// adding it to the listeners, first emit "newListener".
|
||
|
if (events.newListener) {
|
||
|
target.emit('newListener', type,
|
||
|
listener.listener ? listener.listener : listener);
|
||
|
|
||
|
// Re-assign `events` because a newListener handler could have caused the
|
||
|
// this._events to be assigned to a new object
|
||
|
events = target._events;
|
||
|
}
|
||
|
existing = events[type];
|
||
|
}
|
||
|
|
||
|
if (!existing) {
|
||
|
// Optimize the case of one listener. Don't need the extra array object.
|
||
|
existing = events[type] = listener;
|
||
|
++target._eventsCount;
|
||
|
} else {
|
||
|
if (typeof existing === 'function') {
|
||
|
// Adding the second element, need to change to array.
|
||
|
existing = events[type] =
|
||
|
prepend ? [listener, existing] : [existing, listener];
|
||
|
} else {
|
||
|
// If we've already got an array, just append.
|
||
|
if (prepend) {
|
||
|
existing.unshift(listener);
|
||
|
} else {
|
||
|
existing.push(listener);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Check for listener leak
|
||
|
if (!existing.warned) {
|
||
|
m = $getMaxListeners(target);
|
||
|
if (m && m > 0 && existing.length > m) {
|
||
|
existing.warned = true;
|
||
|
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
||
|
existing.length + ' "' + String(type) + '" listeners ' +
|
||
|
'added. Use emitter.setMaxListeners() to ' +
|
||
|
'increase limit.');
|
||
|
w.name = 'MaxListenersExceededWarning';
|
||
|
w.emitter = target;
|
||
|
w.type = type;
|
||
|
w.count = existing.length;
|
||
|
if (typeof console === 'object' && console.warn) {
|
||
|
console.warn('%s: %s', w.name, w.message);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return target;
|
||
|
}
|
||
|
|
||
|
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
||
|
return _addListener(this, type, listener, false);
|
||
|
};
|
||
|
|
||
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||
|
|
||
|
EventEmitter.prototype.prependListener =
|
||
|
function prependListener(type, listener) {
|
||
|
return _addListener(this, type, listener, true);
|
||
|
};
|
||
|
|
||
|
function onceWrapper() {
|
||
|
if (!this.fired) {
|
||
|
this.target.removeListener(this.type, this.wrapFn);
|
||
|
this.fired = true;
|
||
|
switch (arguments.length) {
|
||
|
case 0:
|
||
|
return this.listener.call(this.target);
|
||
|
case 1:
|
||
|
return this.listener.call(this.target, arguments[0]);
|
||
|
case 2:
|
||
|
return this.listener.call(this.target, arguments[0], arguments[1]);
|
||
|
case 3:
|
||
|
return this.listener.call(this.target, arguments[0], arguments[1],
|
||
|
arguments[2]);
|
||
|
default:
|
||
|
var args = new Array(arguments.length);
|
||
|
for (var i = 0; i < args.length; ++i)
|
||
|
args[i] = arguments[i];
|
||
|
this.listener.apply(this.target, args);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _onceWrap(target, type, listener) {
|
||
|
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
||
|
var wrapped = bind.call(onceWrapper, state);
|
||
|
wrapped.listener = listener;
|
||
|
state.wrapFn = wrapped;
|
||
|
return wrapped;
|
||
|
}
|
||
|
|
||
|
EventEmitter.prototype.once = function once(type, listener) {
|
||
|
if (typeof listener !== 'function')
|
||
|
throw new TypeError('"listener" argument must be a function');
|
||
|
this.on(type, _onceWrap(this, type, listener));
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
EventEmitter.prototype.prependOnceListener =
|
||
|
function prependOnceListener(type, listener) {
|
||
|
if (typeof listener !== 'function')
|
||
|
throw new TypeError('"listener" argument must be a function');
|
||
|
this.prependListener(type, _onceWrap(this, type, listener));
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
// Emits a 'removeListener' event if and only if the listener was removed.
|
||
|
EventEmitter.prototype.removeListener =
|
||
|
function removeListener(type, listener) {
|
||
|
var list, events, position, i, originalListener;
|
||
|
|
||
|
if (typeof listener !== 'function')
|
||
|
throw new TypeError('"listener" argument must be a function');
|
||
|
|
||
|
events = this._events;
|
||
|
if (!events)
|
||
|
return this;
|
||
|
|
||
|
list = events[type];
|
||
|
if (!list)
|
||
|
return this;
|
||
|
|
||
|
if (list === listener || list.listener === listener) {
|
||
|
if (--this._eventsCount === 0)
|
||
|
this._events = objectCreate(null);
|
||
|
else {
|
||
|
delete events[type];
|
||
|
if (events.removeListener)
|
||
|
this.emit('removeListener', type, list.listener || listener);
|
||
|
}
|
||
|
} else if (typeof list !== 'function') {
|
||
|
position = -1;
|
||
|
|
||
|
for (i = list.length - 1; i >= 0; i--) {
|
||
|
if (list[i] === listener || list[i].listener === listener) {
|
||
|
originalListener = list[i].listener;
|
||
|
position = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (position < 0)
|
||
|
return this;
|
||
|
|
||
|
if (position === 0)
|
||
|
list.shift();
|
||
|
else
|
||
|
spliceOne(list, position);
|
||
|
|
||
|
if (list.length === 1)
|
||
|
events[type] = list[0];
|
||
|
|
||
|
if (events.removeListener)
|
||
|
this.emit('removeListener', type, originalListener || listener);
|
||
|
}
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
EventEmitter.prototype.removeAllListeners =
|
||
|
function removeAllListeners(type) {
|
||
|
var listeners, events, i;
|
||
|
|
||
|
events = this._events;
|
||
|
if (!events)
|
||
|
return this;
|
||
|
|
||
|
// not listening for removeListener, no need to emit
|
||
|
if (!events.removeListener) {
|
||
|
if (arguments.length === 0) {
|
||
|
this._events = objectCreate(null);
|
||
|
this._eventsCount = 0;
|
||
|
} else if (events[type]) {
|
||
|
if (--this._eventsCount === 0)
|
||
|
this._events = objectCreate(null);
|
||
|
else
|
||
|
delete events[type];
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
// emit removeListener for all listeners on all events
|
||
|
if (arguments.length === 0) {
|
||
|
var keys = objectKeys(events);
|
||
|
var key;
|
||
|
for (i = 0; i < keys.length; ++i) {
|
||
|
key = keys[i];
|
||
|
if (key === 'removeListener') continue;
|
||
|
this.removeAllListeners(key);
|
||
|
}
|
||
|
this.removeAllListeners('removeListener');
|
||
|
this._events = objectCreate(null);
|
||
|
this._eventsCount = 0;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
listeners = events[type];
|
||
|
|
||
|
if (typeof listeners === 'function') {
|
||
|
this.removeListener(type, listeners);
|
||
|
} else if (listeners) {
|
||
|
// LIFO order
|
||
|
for (i = listeners.length - 1; i >= 0; i--) {
|
||
|
this.removeListener(type, listeners[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
EventEmitter.prototype.listeners = function listeners(type) {
|
||
|
var evlistener;
|
||
|
var ret;
|
||
|
var events = this._events;
|
||
|
|
||
|
if (!events)
|
||
|
ret = [];
|
||
|
else {
|
||
|
evlistener = events[type];
|
||
|
if (!evlistener)
|
||
|
ret = [];
|
||
|
else if (typeof evlistener === 'function')
|
||
|
ret = [evlistener.listener || evlistener];
|
||
|
else
|
||
|
ret = unwrapListeners(evlistener);
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
EventEmitter.listenerCount = function(emitter, type) {
|
||
|
if (typeof emitter.listenerCount === 'function') {
|
||
|
return emitter.listenerCount(type);
|
||
|
} else {
|
||
|
return listenerCount.call(emitter, type);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
EventEmitter.prototype.listenerCount = listenerCount;
|
||
|
function listenerCount(type) {
|
||
|
var events = this._events;
|
||
|
|
||
|
if (events) {
|
||
|
var evlistener = events[type];
|
||
|
|
||
|
if (typeof evlistener === 'function') {
|
||
|
return 1;
|
||
|
} else if (evlistener) {
|
||
|
return evlistener.length;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
EventEmitter.prototype.eventNames = function eventNames() {
|
||
|
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
|
||
|
};
|
||
|
|
||
|
// About 1.5x faster than the two-arg version of Array#splice().
|
||
|
function spliceOne(list, index) {
|
||
|
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
|
||
|
list[i] = list[k];
|
||
|
list.pop();
|
||
|
}
|
||
|
|
||
|
function arrayClone(arr, n) {
|
||
|
var copy = new Array(n);
|
||
|
for (var i = 0; i < n; ++i)
|
||
|
copy[i] = arr[i];
|
||
|
return copy;
|
||
|
}
|
||
|
|
||
|
function unwrapListeners(arr) {
|
||
|
var ret = new Array(arr.length);
|
||
|
for (var i = 0; i < ret.length; ++i) {
|
||
|
ret[i] = arr[i].listener || arr[i];
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
function objectCreatePolyfill(proto) {
|
||
|
var F = function() {};
|
||
|
F.prototype = proto;
|
||
|
return new F;
|
||
|
}
|
||
|
function objectKeysPolyfill(obj) {
|
||
|
var keys = [];
|
||
|
for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
|
||
|
keys.push(k);
|
||
|
}
|
||
|
return k;
|
||
|
}
|
||
|
function functionBindPolyfill(context) {
|
||
|
var fn = this;
|
||
|
return function () {
|
||
|
return fn.apply(context, arguments);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
},{}],48:[function(require,module,exports){
|
||
|
(function (global){
|
||
|
/*! https://mths.be/he v1.1.1 by @mathias | MIT license */
|
||
|
;(function(root) {
|
||
|
|
||
|
// Detect free variables `exports`.
|
||
|
var freeExports = typeof exports == 'object' && exports;
|
||
|
|
||
|
// Detect free variable `module`.
|
||
|
var freeModule = typeof module == 'object' && module &&
|
||
|
module.exports == freeExports && module;
|
||
|
|
||
|
// Detect free variable `global`, from Node.js or Browserified code,
|
||
|
// and use it as `root`.
|
||
|
var freeGlobal = typeof global == 'object' && global;
|
||
|
if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
||
|
root = freeGlobal;
|
||
|
}
|
||
|
|
||
|
/*--------------------------------------------------------------------------*/
|
||
|
|
||
|
// All astral symbols.
|
||
|
var regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||
|
// All ASCII symbols (not just printable ASCII) except those listed in the
|
||
|
// first column of the overrides table.
|
||
|
// https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides
|
||
|
var regexAsciiWhitelist = /[\x01-\x7F]/g;
|
||
|
// All BMP symbols that are not ASCII newlines, printable ASCII symbols, or
|
||
|
// code points listed in the first column of the overrides table on
|
||
|
// https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides.
|
||
|
var regexBmpWhitelist = /[\x01-\t\x0B\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g;
|
||
|
|
||
|
var regexEncodeNonAscii = /<\u20D2|=\u20E5|>\u20D2|\u205F\u200A|\u219D\u0338|\u2202\u0338|\u2220\u20D2|\u2229\uFE00|\u222A\uFE00|\u223C\u20D2|\u223D\u0331|\u223E\u0333|\u2242\u0338|\u224B\u0338|\u224D\u20D2|\u224E\u0338|\u224F\u0338|\u2250\u0338|\u2261\u20E5|\u2264\u20D2|\u2265\u20D2|\u2266\u0338|\u2267\u0338|\u2268\uFE00|\u2269\uFE00|\u226A\u0338|\u226A\u20D2|\u226B\u0338|\u226B\u20D2|\u227F\u0338|\u2282\u20D2|\u2283\u20D2|\u228A\uFE00|\u228B\uFE00|\u228F\u0338|\u2290\u0338|\u2293\uFE00|\u2294\uFE00|\u22B4\u20D2|\u22B5\u20D2|\u22D8\u0338|\u22D9\u0338|\u22DA\uFE00|\u22DB\uFE00|\u22F5\u0338|\u22F9\u0338|\u2933\u0338|\u29CF\u0338|\u29D0\u0338|\u2A6D\u0338|\u2A70\u0338|\u2A7D\u0338|\u2A7E\u0338|\u2AA1\u0338|\u2AA2\u0338|\u2AAC\uFE00|\u2AAD\uFE00|\u2AAF\u0338|\u2AB0\u0338|\u2AC5\u0338|\u2AC6\u0338|\u2ACB\uFE00|\u2ACC\uFE00|\u2AFD\u20E5|[\xA0-\u0113\u0116-\u0122\u0124-\u012B\u012E-\u014D\u0150-\u017E\u0192\u01B5\u01F5\u0237\u02C6\u02C7\u02D8-\u02DD\u0311\u0391-\u03A1\u03A3-\u03A9\u03B1-\u03C9\u03D1\u03D2\u03D5\u03D6\u03DC\u03DD\u03F0\u03F1\u03F5\u03F6\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E\u045F\u2002-\u2005\u2007-\u2010\u2013-\u2016\u2018-\u201A\u201C-\u201E\u2020-\u2022\u2025\u2026\u2030-\u2035\u2039\u203A\u203E\u2041\u2043\u2044\u204F\u2057\u205F-\u2063\u20AC\u20DB\u20DC\u2102\u2105\u210A-\u2113\u2115-\u211E\u2122\u2124\u2127-\u2129\u212C\u212D\u212F-\u2131\u2133-\u2138\u2145-\u2148\u2153-\u215E\u2190-\u219B\u219D-\u21A7\u21A9-\u21AE\u21B0-\u21B3\u21B5-\u21B7\u21BA-\u21DB\u21DD\u21E4\u21E5\u21F5\u21FD-\u2205\u2207-\u2209\u220B\u220C\u220F-\u2214\u2216-\u2218\u221A\u221D-\u2238\u223A-\u2257\u2259\u225A\u225C\u225F-\u2262\u2264-\u228B\u228D-\u229B\u229D-\u22A5\u22A7-\u22B0\u22B2-\u22BB\u22BD-\u22DB\u22DE-\u22E3\u22E6-\u22F7\u22F9-\u22FE\u2305\u2306\u2308-\u2310\u2312\u2313\u2315\u2316\u231C-\u231F\u2322\u2323\u232D\u232E\u2336\u233D\u233F\u237C\u23B0\u23B1\u23B4-\u23B6\u23DC-\u23DF\u23E2\u23E7\u2423\u24C8\u2500\u2502\u250C\u2510\u2514\u2518\u251C\u2524\u252C\u2534\u253C\u2550-\u256C\u2580\u2584\u2588\u2591-\u2593\u25A1\u25AA\u25AB\u25AD\u25AE\u25B1\u25B3-\u25B5\u25B8\u25B9\u25BD-\u25BF\u25C2\u25C3\u25CA\u25CB\u25EC\u25EF\u25F8-\u25FC\u2605\u2606\u260E\u2640\u2642\u2660\u2663\u2665\u2666\u266A\u266D-\u266F\u2713\u2717\u2720\u2736\u2758\u2772\u2773\u27C8\u27C9\u27E6-\u27ED\u27F5-\u27FA\u27FC\u27FF\u2902-\u2905\u290C-\u2913\u2916\u2919-\u2920\u2923-\u292A\u2933\u2935-\u2939\u293C\u293D\u2945\u2948-\u294B\u294E-\u2976\u2978\u2979\u297B-\u297F\u2985\u2986\u298B-\u2996\u299A\u299C\u299D\u29A4-\u29B7\u29B9\u29BB\u29BC\u29BE-\u29C5\u29C9\u29CD-\u29D0\u29DC-\u29DE\u29E3-\u29E5\u29EB\u29F4\u29F6\u2A00-\u2A02\u2A04\u2A06\u2A0C\u2A0D\u2A10-\u2A17\u2A22-\u2A27\u2A29\u2A2A\u2A2D-\u2A31\u2A33-\u2A3C\u2A3F\u2A40\u2A42-\u2A4D\u2A50\u2A53-\u2A58\u2A5A-\u2A5D\u2A5F\u2A66\u2A6A\u2A6D-\u2A75\u2A77-\u2A9A\u2A9D-\u2AA2\u2AA4-\u2AB0\u2AB3-\u2AC8\u2ACB\u2ACC\u2ACF-\u2ADB\u2AE4\u2AE6-\u2AE9\u2AEB-\u2AF3\u2AFD\uFB00-\uFB04]|\uD835[\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDCCF\uDD04\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDD6B]/g;
|
||
|
var encodeMap = {'\xAD':'shy','\u200C':'zwnj','\u200D':'zwj','\u200E':'lrm','\u2063':'ic','\u2062':'it','\u2061':'af','\u200F':'rlm','\u200B':'ZeroWidthSpace','\u2060':'NoBreak','\u0311':'DownBreve','\u20DB':'tdot','\u20DC':'DotDot','\t':'Tab','\n':'NewLine','\u2008':'puncsp','\u205F':'MediumSpace','\u2009':'thinsp','\u200A':'hairsp','\u2004':'emsp13','\u2002':'ensp','\u2005':'emsp14','\u2003':'emsp','\u2007':'numsp','\xA0':'nbsp','\u205F\u200A':'ThickSpace','\u203E':'oline','_':'lowbar','\u2010':'dash','\u2013':'ndash','\u2014':'mdash','\u2015':'horbar',',':'comma',';':'semi','\u204F':'bsemi',':':'colon','\u2A74':'Colone','!':'excl','\xA1':'iexcl','?':'quest','\xBF':'iquest','.':'period','\u2025':'nldr','\u2026':'mldr','\xB7':'middot','\'':'apos','\u2018':'lsquo','\u2019':'rsquo','\u201A':'sbquo','\u2039':'lsaquo','\u203A':'rsaquo','"':'quot','\u201C':'ldquo','\u201D':'rdquo','\u201E':'bdquo','\xAB':'laquo','\xBB':'raquo','(':'lpar',')':'rpar','[':'lsqb',']':'rsqb','{':'lcub','}':'rcub','\u2308':'lceil','\u2309':'rceil','\u230A':'lfloor','\u230B':'rfloor','\u2985':'lopar','\u2986':'ropar','\u298B':'lbrke','\u298C':'rbrke','\u298D':'lbrkslu','\u298E':'rbrksld','\u298F':'lbrksld','\u2990':'rbrkslu','\u2991':'langd','\u2992':'rangd','\u2993':'lparlt','\u2994':'rpargt','\u2995':'gtlPar','\u2996':'ltrPar','\u27E6':'lobrk','\u27E7':'robrk','\u27E8':'lang','\u27E9':'rang','\u27EA':'Lang','\u27EB':'Rang','\u27EC':'loang','\u27ED':'roang','\u2772':'lbbrk','\u2773':'rbbrk','\u2016':'Vert','\xA7':'sect','\xB6':'para','@':'commat','*':'ast','/':'sol','undefined':null,'&':'amp','#':'num','%':'percnt','\u2030':'permil','\u2031':'pertenk','\u2020':'dagger','\u2021':'Dagger','\u2022':'bull','\u2043':'hybull','\u2032':'prime','\u2033':'Prime','\u2034':'tprime','\u2057':'qprime','\u2035':'bprime','\u2041':'caret','`':'grave','\xB4':'acute','\u02DC':'tilde','^':'Hat','\xAF':'macr','\u02D8':'breve','\u02D9':'dot','\xA8':'die','\u02DA':'ring','\u02DD':'dblac','\xB8':'cedil','\u02DB':'ogon','\u02C6':'circ','\u02C7':'caron','\xB0':'deg','\xA9':'copy','\xAE':'reg','\u2117':'copysr','\u2118':'wp','\u211E':'rx','\u2127':'mho','\u2129':'iiota','\u2190':'larr','\u219A':'nlarr','\u2192':'rarr','\u219B':'nrarr','\u2191':'uarr','\u2193':'darr','\u2194':'harr','\u21AE':'nharr','\u2195':'varr','\u2196':'nwarr','\u2197':'nearr','\u2198':'searr','\u2199':'swarr','\u219D':'rarrw','\u219D\u0338':'nrarrw','\u219E':'Larr','\u219F':'Uarr','\u21A0':'Rarr','\u21A1':'Darr','\u21A2':'larrtl','\u21A3':'rarrtl','\u21A4':'mapstoleft','\u21A5':'mapstoup','\u21A6':'map','\u21A7':'mapstodown','\u21A9':'larrhk','\u21AA':'rarrhk','\u21AB':'larrlp','\u21AC':'rarrlp','\u21AD':'harrw','\u21B0':'lsh','\u21B1':'rsh','\u21B2':'ldsh','\u21B3':'rdsh','\u21B5':'crarr','\u21B6':'cularr','\u21B7':'curarr','\u21BA':'olarr','\u21BB':'orarr','\u21BC':'lharu','\u21BD':'lhard','\u21BE':'uharr','\u21BF':'uharl','\u21C0':'rharu','\u21C1':'rhard','\u21C2':'dharr','\u21C3':'dharl','\u21C4':'rlarr','\u21C5':'udarr','\u21C6':'lrarr','\u21C7':'llarr','\u21C8':'uuarr','\u21C9':'rrarr','\u21CA':'ddarr','\u21CB':'lrhar','\u21CC':'rlhar','\u21D0':'lArr','\u21CD':'nlArr','\u21D1':'uArr','\u21D2':'rArr','\u21CF':'nrArr','\u21D3':'dArr','\u21D4':'iff','\u21CE':'nhArr','\u21D5':'vArr','\u21D6':'nwArr','\u21D7':'neArr','\u21D8':'seArr','\u21D9':'swArr','\u21DA':'lAarr','\u21DB':'rAarr','\u21DD':'zigrarr','\u21E4':'larrb','\u21E5':'rarrb','\u21F5':'duarr','\u21FD':'loarr','\u21FE':'roarr','\u21FF':'hoarr','\u2200':'forall','\u2201':'comp','\u2202':'part','\u2202\u0338':'npart','\u2203':'exist','\u2204':'nexist','\u2205':'empty','\u2207':'Del','\u2208':'in','\u2209':'notin','\u220B':'ni','\u220C':'notni','\u03F6':'bepsi','\u220F':'prod','\u2210':'coprod','\u2211':'sum','+':'plus','\xB1':'pm','\xF7':'div','\xD7':'times','<':'lt','\u226E':'nlt','<\u20D2':'nvlt','=':'equals','\u2260':'ne','=\u20E5':'bne','\u2A75':'Equal','>':'gt','\u226F':'ngt','>\u20D2':'nvgt','\xAC':'not','|':'vert','\xA6':'brvbar','\u2212':'minus','\u2213':'mp','\u2214':'plusdo','\u2044':'frasl','\u2216':'setmn','\u2217':'lowast','\u22
|
||
|
|
||
|
var regexEscape = /["&'<>`]/g;
|
||
|
var escapeMap = {
|
||
|
'"': '"',
|
||
|
'&': '&',
|
||
|
'\'': ''',
|
||
|
'<': '<',
|
||
|
// See https://mathiasbynens.be/notes/ambiguous-ampersands: in HTML, the
|
||
|
// following is not strictly necessary unless it’s part of a tag or an
|
||
|
// unquoted attribute value. We’re only escaping it to support those
|
||
|
// situations, and for XML support.
|
||
|
'>': '>',
|
||
|
// In Internet Explorer ≤ 8, the backtick character can be used
|
||
|
// to break out of (un)quoted attribute values or HTML comments.
|
||
|
// See http://html5sec.org/#102, http://html5sec.org/#108, and
|
||
|
// http://html5sec.org/#133.
|
||
|
'`': '`'
|
||
|
};
|
||
|
|
||
|
var regexInvalidEntity = /&#(?:[xX][^a-fA-F0-9]|[^0-9xX])/;
|
||
|
var regexInvalidRawCodePoint = /[\0-\x08\x0B\x0E-\x1F\x7F-\x9F\uFDD0-\uFDEF\uFFFE\uFFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F\uDBBF\uDBFF][\uDFFE\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
||
|
var regexDecode = /&#([0-9]+)(;?)|&#[xX]([a-fA-F0-9]+)(;?)|&([0-9a-zA-Z]+);|&(Aacute|Agrave|Atilde|Ccedil|Eacute|Egrave|Iacute|Igrave|Ntilde|Oacute|Ograve|Oslash|Otilde|Uacute|Ugrave|Yacute|aacute|agrave|atilde|brvbar|ccedil|curren|divide|eacute|egrave|frac12|frac14|frac34|iacute|igrave|iquest|middot|ntilde|oacute|ograve|oslash|otilde|plusmn|uacute|ugrave|yacute|AElig|Acirc|Aring|Ecirc|Icirc|Ocirc|THORN|Ucirc|acirc|acute|aelig|aring|cedil|ecirc|icirc|iexcl|laquo|micro|ocirc|pound|raquo|szlig|thorn|times|ucirc|Auml|COPY|Euml|Iuml|Ouml|QUOT|Uuml|auml|cent|copy|euml|iuml|macr|nbsp|ordf|ordm|ouml|para|quot|sect|sup1|sup2|sup3|uuml|yuml|AMP|ETH|REG|amp|deg|eth|not|reg|shy|uml|yen|GT|LT|gt|lt)([=a-zA-Z0-9])?/g;
|
||
|
var decodeMap = {'aacute':'\xE1','Aacute':'\xC1','abreve':'\u0103','Abreve':'\u0102','ac':'\u223E','acd':'\u223F','acE':'\u223E\u0333','acirc':'\xE2','Acirc':'\xC2','acute':'\xB4','acy':'\u0430','Acy':'\u0410','aelig':'\xE6','AElig':'\xC6','af':'\u2061','afr':'\uD835\uDD1E','Afr':'\uD835\uDD04','agrave':'\xE0','Agrave':'\xC0','alefsym':'\u2135','aleph':'\u2135','alpha':'\u03B1','Alpha':'\u0391','amacr':'\u0101','Amacr':'\u0100','amalg':'\u2A3F','amp':'&','AMP':'&','and':'\u2227','And':'\u2A53','andand':'\u2A55','andd':'\u2A5C','andslope':'\u2A58','andv':'\u2A5A','ang':'\u2220','ange':'\u29A4','angle':'\u2220','angmsd':'\u2221','angmsdaa':'\u29A8','angmsdab':'\u29A9','angmsdac':'\u29AA','angmsdad':'\u29AB','angmsdae':'\u29AC','angmsdaf':'\u29AD','angmsdag':'\u29AE','angmsdah':'\u29AF','angrt':'\u221F','angrtvb':'\u22BE','angrtvbd':'\u299D','angsph':'\u2222','angst':'\xC5','angzarr':'\u237C','aogon':'\u0105','Aogon':'\u0104','aopf':'\uD835\uDD52','Aopf':'\uD835\uDD38','ap':'\u2248','apacir':'\u2A6F','ape':'\u224A','apE':'\u2A70','apid':'\u224B','apos':'\'','ApplyFunction':'\u2061','approx':'\u2248','approxeq':'\u224A','aring':'\xE5','Aring':'\xC5','ascr':'\uD835\uDCB6','Ascr':'\uD835\uDC9C','Assign':'\u2254','ast':'*','asymp':'\u2248','asympeq':'\u224D','atilde':'\xE3','Atilde':'\xC3','auml':'\xE4','Auml':'\xC4','awconint':'\u2233','awint':'\u2A11','backcong':'\u224C','backepsilon':'\u03F6','backprime':'\u2035','backsim':'\u223D','backsimeq':'\u22CD','Backslash':'\u2216','Barv':'\u2AE7','barvee':'\u22BD','barwed':'\u2305','Barwed':'\u2306','barwedge':'\u2305','bbrk':'\u23B5','bbrktbrk':'\u23B6','bcong':'\u224C','bcy':'\u0431','Bcy':'\u0411','bdquo':'\u201E','becaus':'\u2235','because':'\u2235','Because':'\u2235','bemptyv':'\u29B0','bepsi':'\u03F6','bernou':'\u212C','Bernoullis':'\u212C','beta':'\u03B2','Beta':'\u0392','beth':'\u2136','between':'\u226C','bfr':'\uD835\uDD1F','Bfr':'\uD835\uDD05','bigcap':'\u22C2','bigcirc':'\u25EF','bigcup':'\u22C3','bigodot':'\u2A00','bigoplus':'\u2A01','bigotimes':'\u2A02','bigsqcup':'\u2A06','bigstar':'\u2605','bigtriangledown':'\u25BD','bigtriangleup':'\u25B3','biguplus':'\u2A04','bigvee':'\u22C1','bigwedge':'\u22C0','bkarow':'\u290D','blacklozenge':'\u29EB','blacksquare':'\u25AA','blacktriangle':'\u25B4','blacktriangledown':'\u25BE','blacktriangleleft':'\u25C2','blacktriangleright':'\u25B8','blank':'\u2423','blk12':'\u2592','blk14':'\u2591','blk34':'\u2593','block':'\u2588','bne':'=\u20E5','bnequiv':'\u2261\u20E5','bnot':'\u2310','bNot':'\u2AED','bopf':'\uD835\uDD53','Bopf':'\uD835\uDD39','bot':'\u22A5','bottom':'\u22A5','bowtie':'\u22C8','boxbox':'\u29C9','boxdl':'\u2510','boxdL':'\u2555','boxDl':'\u2556','boxDL':'\u2557','boxdr':'\u250C','boxdR':'\u2552','boxDr':'\u2553','boxDR':'\u2554','boxh':'\u2500','boxH':'\u2550','boxhd':'\u252C','boxhD':'\u2565','boxHd':'\u2564','boxHD':'\u2566','boxhu':'\u2534','boxhU':'\u2568','boxHu':'\u2567','boxHU':'\u2569','boxminus':'\u229F','boxplus':'\u229E','boxtimes':'\u22A0','boxul':'\u2518','boxuL':'\u255B','boxUl':'\u255C','boxUL':'\u255D','boxur':'\u2514','boxuR':'\u2558','boxUr':'\u2559','boxUR':'\u255A','boxv':'\u2502','boxV':'\u2551','boxvh':'\u253C','boxvH':'\u256A','boxVh':'\u256B','boxVH':'\u256C','boxvl':'\u2524','boxvL':'\u2561','boxVl':'\u2562','boxVL':'\u2563','boxvr':'\u251C','boxvR':'\u255E','boxVr':'\u255F','boxVR':'\u2560','bprime':'\u2035','breve':'\u02D8','Breve':'\u02D8','brvbar':'\xA6','bscr':'\uD835\uDCB7','Bscr':'\u212C','bsemi':'\u204F','bsim':'\u223D','bsime':'\u22CD','bsol':'\\','bsolb':'\u29C5','bsolhsub':'\u27C8','bull':'\u2022','bullet':'\u2022','bump':'\u224E','bumpe':'\u224F','bumpE':'\u2AAE','bumpeq':'\u224F','Bumpeq':'\u224E','cacute':'\u0107','Cacute':'\u0106','cap':'\u2229','Cap':'\u22D2','capand':'\u2A44','capbrcup':'\u2A49','capcap':'\u2A4B','capcup':'\u2A47','capdot':'\u2A40','CapitalDifferentialD':'\u2145','caps':'\u2229\uFE00','caret':'\u2041','caron':'\u02C7','Cayleys':'\u212D','ccaps':'\u2A4D','ccaron':'\u010D','Ccaron':'\u010C','ccedil':'\xE7','Ccedil':'\xC7','ccirc':'\u0109','Ccirc':'\u0108','Cconint':'\
|
||
|
var decodeMapLegacy = {'aacute':'\xE1','Aacute':'\xC1','acirc':'\xE2','Acirc':'\xC2','acute':'\xB4','aelig':'\xE6','AElig':'\xC6','agrave':'\xE0','Agrave':'\xC0','amp':'&','AMP':'&','aring':'\xE5','Aring':'\xC5','atilde':'\xE3','Atilde':'\xC3','auml':'\xE4','Auml':'\xC4','brvbar':'\xA6','ccedil':'\xE7','Ccedil':'\xC7','cedil':'\xB8','cent':'\xA2','copy':'\xA9','COPY':'\xA9','curren':'\xA4','deg':'\xB0','divide':'\xF7','eacute':'\xE9','Eacute':'\xC9','ecirc':'\xEA','Ecirc':'\xCA','egrave':'\xE8','Egrave':'\xC8','eth':'\xF0','ETH':'\xD0','euml':'\xEB','Euml':'\xCB','frac12':'\xBD','frac14':'\xBC','frac34':'\xBE','gt':'>','GT':'>','iacute':'\xED','Iacute':'\xCD','icirc':'\xEE','Icirc':'\xCE','iexcl':'\xA1','igrave':'\xEC','Igrave':'\xCC','iquest':'\xBF','iuml':'\xEF','Iuml':'\xCF','laquo':'\xAB','lt':'<','LT':'<','macr':'\xAF','micro':'\xB5','middot':'\xB7','nbsp':'\xA0','not':'\xAC','ntilde':'\xF1','Ntilde':'\xD1','oacute':'\xF3','Oacute':'\xD3','ocirc':'\xF4','Ocirc':'\xD4','ograve':'\xF2','Ograve':'\xD2','ordf':'\xAA','ordm':'\xBA','oslash':'\xF8','Oslash':'\xD8','otilde':'\xF5','Otilde':'\xD5','ouml':'\xF6','Ouml':'\xD6','para':'\xB6','plusmn':'\xB1','pound':'\xA3','quot':'"','QUOT':'"','raquo':'\xBB','reg':'\xAE','REG':'\xAE','sect':'\xA7','shy':'\xAD','sup1':'\xB9','sup2':'\xB2','sup3':'\xB3','szlig':'\xDF','thorn':'\xFE','THORN':'\xDE','times':'\xD7','uacute':'\xFA','Uacute':'\xDA','ucirc':'\xFB','Ucirc':'\xDB','ugrave':'\xF9','Ugrave':'\xD9','uml':'\xA8','uuml':'\xFC','Uuml':'\xDC','yacute':'\xFD','Yacute':'\xDD','yen':'\xA5','yuml':'\xFF'};
|
||
|
var decodeMapNumeric = {'0':'\uFFFD','128':'\u20AC','130':'\u201A','131':'\u0192','132':'\u201E','133':'\u2026','134':'\u2020','135':'\u2021','136':'\u02C6','137':'\u2030','138':'\u0160','139':'\u2039','140':'\u0152','142':'\u017D','145':'\u2018','146':'\u2019','147':'\u201C','148':'\u201D','149':'\u2022','150':'\u2013','151':'\u2014','152':'\u02DC','153':'\u2122','154':'\u0161','155':'\u203A','156':'\u0153','158':'\u017E','159':'\u0178'};
|
||
|
var invalidReferenceCodePoints = [1,2,3,4,5,6,7,8,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,127,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,64976,64977,64978,64979,64980,64981,64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,65004,65005,65006,65007,65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111];
|
||
|
|
||
|
/*--------------------------------------------------------------------------*/
|
||
|
|
||
|
var stringFromCharCode = String.fromCharCode;
|
||
|
|
||
|
var object = {};
|
||
|
var hasOwnProperty = object.hasOwnProperty;
|
||
|
var has = function(object, propertyName) {
|
||
|
return hasOwnProperty.call(object, propertyName);
|
||
|
};
|
||
|
|
||
|
var contains = function(array, value) {
|
||
|
var index = -1;
|
||
|
var length = array.length;
|
||
|
while (++index < length) {
|
||
|
if (array[index] == value) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
var merge = function(options, defaults) {
|
||
|
if (!options) {
|
||
|
return defaults;
|
||
|
}
|
||
|
var result = {};
|
||
|
var key;
|
||
|
for (key in defaults) {
|
||
|
// A `hasOwnProperty` check is not needed here, since only recognized
|
||
|
// option names are used anyway. Any others are ignored.
|
||
|
result[key] = has(options, key) ? options[key] : defaults[key];
|
||
|
}
|
||
|
return result;
|
||
|
};
|
||
|
|
||
|
// Modified version of `ucs2encode`; see https://mths.be/punycode.
|
||
|
var codePointToSymbol = function(codePoint, strict) {
|
||
|
var output = '';
|
||
|
if ((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF) {
|
||
|
// See issue #4:
|
||
|
// “Otherwise, if the number is in the range 0xD800 to 0xDFFF or is
|
||
|
// greater than 0x10FFFF, then this is a parse error. Return a U+FFFD
|
||
|
// REPLACEMENT CHARACTER.”
|
||
|
if (strict) {
|
||
|
parseError('character reference outside the permissible Unicode range');
|
||
|
}
|
||
|
return '\uFFFD';
|
||
|
}
|
||
|
if (has(decodeMapNumeric, codePoint)) {
|
||
|
if (strict) {
|
||
|
parseError('disallowed character reference');
|
||
|
}
|
||
|
return decodeMapNumeric[codePoint];
|
||
|
}
|
||
|
if (strict && contains(invalidReferenceCodePoints, codePoint)) {
|
||
|
parseError('disallowed character reference');
|
||
|
}
|
||
|
if (codePoint > 0xFFFF) {
|
||
|
codePoint -= 0x10000;
|
||
|
output += stringFromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
|
||
|
codePoint = 0xDC00 | codePoint & 0x3FF;
|
||
|
}
|
||
|
output += stringFromCharCode(codePoint);
|
||
|
return output;
|
||
|
};
|
||
|
|
||
|
var hexEscape = function(codePoint) {
|
||
|
return '&#x' + codePoint.toString(16).toUpperCase() + ';';
|
||
|
};
|
||
|
|
||
|
var decEscape = function(codePoint) {
|
||
|
return '&#' + codePoint + ';';
|
||
|
};
|
||
|
|
||
|
var parseError = function(message) {
|
||
|
throw Error('Parse error: ' + message);
|
||
|
};
|
||
|
|
||
|
/*--------------------------------------------------------------------------*/
|
||
|
|
||
|
var encode = function(string, options) {
|
||
|
options = merge(options, encode.options);
|
||
|
var strict = options.strict;
|
||
|
if (strict && regexInvalidRawCodePoint.test(string)) {
|
||
|
parseError('forbidden code point');
|
||
|
}
|
||
|
var encodeEverything = options.encodeEverything;
|
||
|
var useNamedReferences = options.useNamedReferences;
|
||
|
var allowUnsafeSymbols = options.allowUnsafeSymbols;
|
||
|
var escapeCodePoint = options.decimal ? decEscape : hexEscape;
|
||
|
|
||
|
var escapeBmpSymbol = function(symbol) {
|
||
|
return escapeCodePoint(symbol.charCodeAt(0));
|
||
|
};
|
||
|
|
||
|
if (encodeEverything) {
|
||
|
// Encode ASCII symbols.
|
||
|
string = string.replace(regexAsciiWhitelist, function(symbol) {
|
||
|
// Use named references if requested & possible.
|
||
|
if (useNamedReferences && has(encodeMap, symbol)) {
|
||
|
return '&' + encodeMap[symbol] + ';';
|
||
|
}
|
||
|
return escapeBmpSymbol(symbol);
|
||
|
});
|
||
|
// Shorten a few escapes that represent two symbols, of which at least one
|
||
|
// is within the ASCII range.
|
||
|
if (useNamedReferences) {
|
||
|
string = string
|
||
|
.replace(/>\u20D2/g, '>⃒')
|
||
|
.replace(/<\u20D2/g, '<⃒')
|
||
|
.replace(/fj/g, 'fj');
|
||
|
}
|
||
|
// Encode non-ASCII symbols.
|
||
|
if (useNamedReferences) {
|
||
|
// Encode non-ASCII symbols that can be replaced with a named reference.
|
||
|
string = string.replace(regexEncodeNonAscii, function(string) {
|
||
|
// Note: there is no need to check `has(encodeMap, string)` here.
|
||
|
return '&' + encodeMap[string] + ';';
|
||
|
});
|
||
|
}
|
||
|
// Note: any remaining non-ASCII symbols are handled outside of the `if`.
|
||
|
} else if (useNamedReferences) {
|
||
|
// Apply named character references.
|
||
|
// Encode `<>"'&` using named character references.
|
||
|
if (!allowUnsafeSymbols) {
|
||
|
string = string.replace(regexEscape, function(string) {
|
||
|
return '&' + encodeMap[string] + ';'; // no need to check `has()` here
|
||
|
});
|
||
|
}
|
||
|
// Shorten escapes that represent two symbols, of which at least one is
|
||
|
// `<>"'&`.
|
||
|
string = string
|
||
|
.replace(/>\u20D2/g, '>⃒')
|
||
|
.replace(/<\u20D2/g, '<⃒');
|
||
|
// Encode non-ASCII symbols that can be replaced with a named reference.
|
||
|
string = string.replace(regexEncodeNonAscii, function(string) {
|
||
|
// Note: there is no need to check `has(encodeMap, string)` here.
|
||
|
return '&' + encodeMap[string] + ';';
|
||
|
});
|
||
|
} else if (!allowUnsafeSymbols) {
|
||
|
// Encode `<>"'&` using hexadecimal escapes, now that they’re not handled
|
||
|
// using named character references.
|
||
|
string = string.replace(regexEscape, escapeBmpSymbol);
|
||
|
}
|
||
|
return string
|
||
|
// Encode astral symbols.
|
||
|
.replace(regexAstralSymbols, function($0) {
|
||
|
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||
|
var high = $0.charCodeAt(0);
|
||
|
var low = $0.charCodeAt(1);
|
||
|
var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
|
||
|
return escapeCodePoint(codePoint);
|
||
|
})
|
||
|
// Encode any remaining BMP symbols that are not printable ASCII symbols
|
||
|
// using a hexadecimal escape.
|
||
|
.replace(regexBmpWhitelist, escapeBmpSymbol);
|
||
|
};
|
||
|
// Expose default options (so they can be overridden globally).
|
||
|
encode.options = {
|
||
|
'allowUnsafeSymbols': false,
|
||
|
'encodeEverything': false,
|
||
|
'strict': false,
|
||
|
'useNamedReferences': false,
|
||
|
'decimal' : false
|
||
|
};
|
||
|
|
||
|
var decode = function(html, options) {
|
||
|
options = merge(options, decode.options);
|
||
|
var strict = options.strict;
|
||
|
if (strict && regexInvalidEntity.test(html)) {
|
||
|
parseError('malformed character reference');
|
||
|
}
|
||
|
return html.replace(regexDecode, function($0, $1, $2, $3, $4, $5, $6, $7) {
|
||
|
var codePoint;
|
||
|
var semicolon;
|
||
|
var decDigits;
|
||
|
var hexDigits;
|
||
|
var reference;
|
||
|
var next;
|
||
|
if ($1) {
|
||
|
// Decode decimal escapes, e.g. `𝌆`.
|
||
|
decDigits = $1;
|
||
|
semicolon = $2;
|
||
|
if (strict && !semicolon) {
|
||
|
parseError('character reference was not terminated by a semicolon');
|
||
|
}
|
||
|
codePoint = parseInt(decDigits, 10);
|
||
|
return codePointToSymbol(codePoint, strict);
|
||
|
}
|
||
|
if ($3) {
|
||
|
// Decode hexadecimal escapes, e.g. `𝌆`.
|
||
|
hexDigits = $3;
|
||
|
semicolon = $4;
|
||
|
if (strict && !semicolon) {
|
||
|
parseError('character reference was not terminated by a semicolon');
|
||
|
}
|
||
|
codePoint = parseInt(hexDigits, 16);
|
||
|
return codePointToSymbol(codePoint, strict);
|
||
|
}
|
||
|
if ($5) {
|
||
|
// Decode named character references with trailing `;`, e.g. `©`.
|
||
|
reference = $5;
|
||
|
if (has(decodeMap, reference)) {
|
||
|
return decodeMap[reference];
|
||
|
} else {
|
||
|
// Ambiguous ampersand. https://mths.be/notes/ambiguous-ampersands
|
||
|
if (strict) {
|
||
|
parseError(
|
||
|
'named character reference was not terminated by a semicolon'
|
||
|
);
|
||
|
}
|
||
|
return $0;
|
||
|
}
|
||
|
}
|
||
|
// If we’re still here, it’s a legacy reference for sure. No need for an
|
||
|
// extra `if` check.
|
||
|
// Decode named character references without trailing `;`, e.g. `&`
|
||
|
// This is only a parse error if it gets converted to `&`, or if it is
|
||
|
// followed by `=` in an attribute context.
|
||
|
reference = $6;
|
||
|
next = $7;
|
||
|
if (next && options.isAttributeValue) {
|
||
|
if (strict && next == '=') {
|
||
|
parseError('`&` did not start a character reference');
|
||
|
}
|
||
|
return $0;
|
||
|
} else {
|
||
|
if (strict) {
|
||
|
parseError(
|
||
|
'named character reference was not terminated by a semicolon'
|
||
|
);
|
||
|
}
|
||
|
// Note: there is no need to check `has(decodeMapLegacy, reference)`.
|
||
|
return decodeMapLegacy[reference] + (next || '');
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
// Expose default options (so they can be overridden globally).
|
||
|
decode.options = {
|
||
|
'isAttributeValue': false,
|
||
|
'strict': false
|
||
|
};
|
||
|
|
||
|
var escape = function(string) {
|
||
|
return string.replace(regexEscape, function($0) {
|
||
|
// Note: there is no need to check `has(escapeMap, $0)` here.
|
||
|
return escapeMap[$0];
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/*--------------------------------------------------------------------------*/
|
||
|
|
||
|
var he = {
|
||
|
'version': '1.1.1',
|
||
|
'encode': encode,
|
||
|
'decode': decode,
|
||
|
'escape': escape,
|
||
|
'unescape': decode
|
||
|
};
|
||
|
|
||
|
// Some AMD build optimizers, like r.js, check for specific condition patterns
|
||
|
// like the following:
|
||
|
if (
|
||
|
false
|
||
|
) {
|
||
|
define(function() {
|
||
|
return he;
|
||
|
});
|
||
|
} else if (freeExports && !freeExports.nodeType) {
|
||
|
if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
|
||
|
freeModule.exports = he;
|
||
|
} else { // in Narwhal or RingoJS v0.7.0-
|
||
|
for (var key in he) {
|
||
|
has(he, key) && (freeExports[key] = he[key]);
|
||
|
}
|
||
|
}
|
||
|
} else { // in Rhino or a web browser
|
||
|
root.he = he;
|
||
|
}
|
||
|
|
||
|
}(this));
|
||
|
|
||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{}],49:[function(require,module,exports){
|
||
|
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
||
|
var e, m
|
||
|
var eLen = (nBytes * 8) - mLen - 1
|
||
|
var eMax = (1 << eLen) - 1
|
||
|
var eBias = eMax >> 1
|
||
|
var nBits = -7
|
||
|
var i = isLE ? (nBytes - 1) : 0
|
||
|
var d = isLE ? -1 : 1
|
||
|
var s = buffer[offset + i]
|
||
|
|
||
|
i += d
|
||
|
|
||
|
e = s & ((1 << (-nBits)) - 1)
|
||
|
s >>= (-nBits)
|
||
|
nBits += eLen
|
||
|
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
||
|
|
||
|
m = e & ((1 << (-nBits)) - 1)
|
||
|
e >>= (-nBits)
|
||
|
nBits += mLen
|
||
|
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
||
|
|
||
|
if (e === 0) {
|
||
|
e = 1 - eBias
|
||
|
} else if (e === eMax) {
|
||
|
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
||
|
} else {
|
||
|
m = m + Math.pow(2, mLen)
|
||
|
e = e - eBias
|
||
|
}
|
||
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
||
|
}
|
||
|
|
||
|
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
||
|
var e, m, c
|
||
|
var eLen = (nBytes * 8) - mLen - 1
|
||
|
var eMax = (1 << eLen) - 1
|
||
|
var eBias = eMax >> 1
|
||
|
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
||
|
var i = isLE ? 0 : (nBytes - 1)
|
||
|
var d = isLE ? 1 : -1
|
||
|
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
||
|
|
||
|
value = Math.abs(value)
|
||
|
|
||
|
if (isNaN(value) || value === Infinity) {
|
||
|
m = isNaN(value) ? 1 : 0
|
||
|
e = eMax
|
||
|
} else {
|
||
|
e = Math.floor(Math.log(value) / Math.LN2)
|
||
|
if (value * (c = Math.pow(2, -e)) < 1) {
|
||
|
e--
|
||
|
c *= 2
|
||
|
}
|
||
|
if (e + eBias >= 1) {
|
||
|
value += rt / c
|
||
|
} else {
|
||
|
value += rt * Math.pow(2, 1 - eBias)
|
||
|
}
|
||
|
if (value * c >= 2) {
|
||
|
e++
|
||
|
c /= 2
|
||
|
}
|
||
|
|
||
|
if (e + eBias >= eMax) {
|
||
|
m = 0
|
||
|
e = eMax
|
||
|
} else if (e + eBias >= 1) {
|
||
|
m = ((value * c) - 1) * Math.pow(2, mLen)
|
||
|
e = e + eBias
|
||
|
} else {
|
||
|
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
||
|
e = 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
||
|
|
||
|
e = (e << mLen) | m
|
||
|
eLen += mLen
|
||
|
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
||
|
|
||
|
buffer[offset + i - d] |= s * 128
|
||
|
}
|
||
|
|
||
|
},{}],50:[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
|
||
|
}
|
||
|
}
|
||
|
|
||
|
},{}],51:[function(require,module,exports){
|
||
|
/*!
|
||
|
* Determine if an object is a Buffer
|
||
|
*
|
||
|
* @author Feross Aboukhadijeh <https://feross.org>
|
||
|
* @license MIT
|
||
|
*/
|
||
|
|
||
|
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
||
|
// Object.prototype.constructor. Remove this eventually
|
||
|
module.exports = function (obj) {
|
||
|
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
|
||
|
}
|
||
|
|
||
|
function isBuffer (obj) {
|
||
|
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
||
|
}
|
||
|
|
||
|
// For Node v0.10 support. Remove this eventually.
|
||
|
function isSlowBuffer (obj) {
|
||
|
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
|
||
|
}
|
||
|
|
||
|
},{}],52:[function(require,module,exports){
|
||
|
var toString = {}.toString;
|
||
|
|
||
|
module.exports = Array.isArray || function (arr) {
|
||
|
return toString.call(arr) == '[object Array]';
|
||
|
};
|
||
|
|
||
|
},{}],53:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
var path = require('path');
|
||
|
var fs = require('fs');
|
||
|
var _0777 = parseInt('0777', 8);
|
||
|
|
||
|
module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
|
||
|
|
||
|
function mkdirP (p, opts, f, made) {
|
||
|
if (typeof opts === 'function') {
|
||
|
f = opts;
|
||
|
opts = {};
|
||
|
}
|
||
|
else if (!opts || typeof opts !== 'object') {
|
||
|
opts = { mode: opts };
|
||
|
}
|
||
|
|
||
|
var mode = opts.mode;
|
||
|
var xfs = opts.fs || fs;
|
||
|
|
||
|
if (mode === undefined) {
|
||
|
mode = _0777 & (~process.umask());
|
||
|
}
|
||
|
if (!made) made = null;
|
||
|
|
||
|
var cb = f || function () {};
|
||
|
p = path.resolve(p);
|
||
|
|
||
|
xfs.mkdir(p, mode, function (er) {
|
||
|
if (!er) {
|
||
|
made = made || p;
|
||
|
return cb(null, made);
|
||
|
}
|
||
|
switch (er.code) {
|
||
|
case 'ENOENT':
|
||
|
mkdirP(path.dirname(p), opts, function (er, made) {
|
||
|
if (er) cb(er, made);
|
||
|
else mkdirP(p, opts, cb, made);
|
||
|
});
|
||
|
break;
|
||
|
|
||
|
// In the case of any other error, just see if there's a dir
|
||
|
// there already. If so, then hooray! If not, then something
|
||
|
// is borked.
|
||
|
default:
|
||
|
xfs.stat(p, function (er2, stat) {
|
||
|
// if the stat fails, then that's super weird.
|
||
|
// let the original error be the failure reason.
|
||
|
if (er2 || !stat.isDirectory()) cb(er, made)
|
||
|
else cb(null, made);
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
mkdirP.sync = function sync (p, opts, made) {
|
||
|
if (!opts || typeof opts !== 'object') {
|
||
|
opts = { mode: opts };
|
||
|
}
|
||
|
|
||
|
var mode = opts.mode;
|
||
|
var xfs = opts.fs || fs;
|
||
|
|
||
|
if (mode === undefined) {
|
||
|
mode = _0777 & (~process.umask());
|
||
|
}
|
||
|
if (!made) made = null;
|
||
|
|
||
|
p = path.resolve(p);
|
||
|
|
||
|
try {
|
||
|
xfs.mkdirSync(p, mode);
|
||
|
made = made || p;
|
||
|
}
|
||
|
catch (err0) {
|
||
|
switch (err0.code) {
|
||
|
case 'ENOENT' :
|
||
|
made = sync(path.dirname(p), opts, made);
|
||
|
sync(p, opts, made);
|
||
|
break;
|
||
|
|
||
|
// In the case of any other error, just see if there's a dir
|
||
|
// there already. If so, then hooray! If not, then something
|
||
|
// is borked.
|
||
|
default:
|
||
|
var stat;
|
||
|
try {
|
||
|
stat = xfs.statSync(p);
|
||
|
}
|
||
|
catch (err1) {
|
||
|
throw err0;
|
||
|
}
|
||
|
if (!stat.isDirectory()) throw err0;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return made;
|
||
|
};
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"_process":56,"fs":40,"path":40}],54:[function(require,module,exports){
|
||
|
/**
|
||
|
* Helpers.
|
||
|
*/
|
||
|
|
||
|
var s = 1000;
|
||
|
var m = s * 60;
|
||
|
var h = m * 60;
|
||
|
var d = h * 24;
|
||
|
var y = d * 365.25;
|
||
|
|
||
|
/**
|
||
|
* Parse or format the given `val`.
|
||
|
*
|
||
|
* Options:
|
||
|
*
|
||
|
* - `long` verbose formatting [false]
|
||
|
*
|
||
|
* @param {String|Number} val
|
||
|
* @param {Object} [options]
|
||
|
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||
|
* @return {String|Number}
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
module.exports = function(val, options) {
|
||
|
options = options || {};
|
||
|
var type = typeof val;
|
||
|
if (type === 'string' && val.length > 0) {
|
||
|
return parse(val);
|
||
|
} else if (type === 'number' && isNaN(val) === false) {
|
||
|
return options.long ? fmtLong(val) : fmtShort(val);
|
||
|
}
|
||
|
throw new Error(
|
||
|
'val is not a non-empty string or a valid number. val=' +
|
||
|
JSON.stringify(val)
|
||
|
);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Parse the given `str` and return milliseconds.
|
||
|
*
|
||
|
* @param {String} str
|
||
|
* @return {Number}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function parse(str) {
|
||
|
str = String(str);
|
||
|
if (str.length > 100) {
|
||
|
return;
|
||
|
}
|
||
|
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
|
||
|
str
|
||
|
);
|
||
|
if (!match) {
|
||
|
return;
|
||
|
}
|
||
|
var n = parseFloat(match[1]);
|
||
|
var type = (match[2] || 'ms').toLowerCase();
|
||
|
switch (type) {
|
||
|
case 'years':
|
||
|
case 'year':
|
||
|
case 'yrs':
|
||
|
case 'yr':
|
||
|
case 'y':
|
||
|
return n * y;
|
||
|
case 'days':
|
||
|
case 'day':
|
||
|
case 'd':
|
||
|
return n * d;
|
||
|
case 'hours':
|
||
|
case 'hour':
|
||
|
case 'hrs':
|
||
|
case 'hr':
|
||
|
case 'h':
|
||
|
return n * h;
|
||
|
case 'minutes':
|
||
|
case 'minute':
|
||
|
case 'mins':
|
||
|
case 'min':
|
||
|
case 'm':
|
||
|
return n * m;
|
||
|
case 'seconds':
|
||
|
case 'second':
|
||
|
case 'secs':
|
||
|
case 'sec':
|
||
|
case 's':
|
||
|
return n * s;
|
||
|
case 'milliseconds':
|
||
|
case 'millisecond':
|
||
|
case 'msecs':
|
||
|
case 'msec':
|
||
|
case 'ms':
|
||
|
return n;
|
||
|
default:
|
||
|
return undefined;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Short format for `ms`.
|
||
|
*
|
||
|
* @param {Number} ms
|
||
|
* @return {String}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function fmtShort(ms) {
|
||
|
if (ms >= d) {
|
||
|
return Math.round(ms / d) + 'd';
|
||
|
}
|
||
|
if (ms >= h) {
|
||
|
return Math.round(ms / h) + 'h';
|
||
|
}
|
||
|
if (ms >= m) {
|
||
|
return Math.round(ms / m) + 'm';
|
||
|
}
|
||
|
if (ms >= s) {
|
||
|
return Math.round(ms / s) + 's';
|
||
|
}
|
||
|
return ms + 'ms';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Long format for `ms`.
|
||
|
*
|
||
|
* @param {Number} ms
|
||
|
* @return {String}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function fmtLong(ms) {
|
||
|
return plural(ms, d, 'day') ||
|
||
|
plural(ms, h, 'hour') ||
|
||
|
plural(ms, m, 'minute') ||
|
||
|
plural(ms, s, 'second') ||
|
||
|
ms + ' ms';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Pluralization helper.
|
||
|
*/
|
||
|
|
||
|
function plural(ms, n, name) {
|
||
|
if (ms < n) {
|
||
|
return;
|
||
|
}
|
||
|
if (ms < n * 1.5) {
|
||
|
return Math.floor(ms / n) + ' ' + name;
|
||
|
}
|
||
|
return Math.ceil(ms / n) + ' ' + name + 's';
|
||
|
}
|
||
|
|
||
|
},{}],55:[function(require,module,exports){
|
||
|
(function (process){
|
||
|
'use strict';
|
||
|
|
||
|
if (!process.version ||
|
||
|
process.version.indexOf('v0.') === 0 ||
|
||
|
process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
|
||
|
module.exports = { nextTick: nextTick };
|
||
|
} else {
|
||
|
module.exports = process
|
||
|
}
|
||
|
|
||
|
function nextTick(fn, arg1, arg2, arg3) {
|
||
|
if (typeof fn !== 'function') {
|
||
|
throw new TypeError('"callback" argument must be a function');
|
||
|
}
|
||
|
var len = arguments.length;
|
||
|
var args, i;
|
||
|
switch (len) {
|
||
|
case 0:
|
||
|
case 1:
|
||
|
return process.nextTick(fn);
|
||
|
case 2:
|
||
|
return process.nextTick(function afterTickOne() {
|
||
|
fn.call(null, arg1);
|
||
|
});
|
||
|
case 3:
|
||
|
return process.nextTick(function afterTickTwo() {
|
||
|
fn.call(null, arg1, arg2);
|
||
|
});
|
||
|
case 4:
|
||
|
return process.nextTick(function afterTickThree() {
|
||
|
fn.call(null, arg1, arg2, arg3);
|
||
|
});
|
||
|
default:
|
||
|
args = new Array(len - 1);
|
||
|
i = 0;
|
||
|
while (i < args.length) {
|
||
|
args[i++] = arguments[i];
|
||
|
}
|
||
|
return process.nextTick(function afterTick() {
|
||
|
fn.apply(null, args);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}).call(this,require('_process'))
|
||
|
},{"_process":56}],56:[function(require,module,exports){
|
||
|
// shim for using process in browser
|
||
|
var process = module.exports = {};
|
||
|
|
||
|
// cached from whatever global is present so that test runners that stub it
|
||
|
// don't break things. But we need to wrap it in a try catch in case it is
|
||
|
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
||
|
// function because try/catches deoptimize in certain engines.
|
||
|
|
||
|
var cachedSetTimeout;
|
||
|
var cachedClearTimeout;
|
||
|
|
||
|
function defaultSetTimout() {
|
||
|
throw new Error('setTimeout has not been defined');
|
||
|
}
|
||
|
function defaultClearTimeout () {
|
||
|
throw new Error('clearTimeout has not been defined');
|
||
|
}
|
||
|
(function () {
|
||
|
try {
|
||
|
if (typeof setTimeout === 'function') {
|
||
|
cachedSetTimeout = setTimeout;
|
||
|
} else {
|
||
|
cachedSetTimeout = defaultSetTimout;
|
||
|
}
|
||
|
} catch (e) {
|
||
|
cachedSetTimeout = defaultSetTimout;
|
||
|
}
|
||
|
try {
|
||
|
if (typeof clearTimeout === 'function') {
|
||
|
cachedClearTimeout = clearTimeout;
|
||
|
} else {
|
||
|
cachedClearTimeout = defaultClearTimeout;
|
||
|
}
|
||
|
} catch (e) {
|
||
|
cachedClearTimeout = defaultClearTimeout;
|
||
|
}
|
||
|
} ())
|
||
|
function runTimeout(fun) {
|
||
|
if (cachedSetTimeout === setTimeout) {
|
||
|
//normal enviroments in sane situations
|
||
|
return setTimeout(fun, 0);
|
||
|
}
|
||
|
// if setTimeout wasn't available but was latter defined
|
||
|
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
||
|
cachedSetTimeout = setTimeout;
|
||
|
return setTimeout(fun, 0);
|
||
|
}
|
||
|
try {
|
||
|
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||
|
return cachedSetTimeout(fun, 0);
|
||
|
} catch(e){
|
||
|
try {
|
||
|
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||
|
return cachedSetTimeout.call(null, fun, 0);
|
||
|
} catch(e){
|
||
|
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
||
|
return cachedSetTimeout.call(this, fun, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
function runClearTimeout(marker) {
|
||
|
if (cachedClearTimeout === clearTimeout) {
|
||
|
//normal enviroments in sane situations
|
||
|
return clearTimeout(marker);
|
||
|
}
|
||
|
// if clearTimeout wasn't available but was latter defined
|
||
|
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
||
|
cachedClearTimeout = clearTimeout;
|
||
|
return clearTimeout(marker);
|
||
|
}
|
||
|
try {
|
||
|
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||
|
return cachedClearTimeout(marker);
|
||
|
} catch (e){
|
||
|
try {
|
||
|
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||
|
return cachedClearTimeout.call(null, marker);
|
||
|
} catch (e){
|
||
|
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
||
|
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
||
|
return cachedClearTimeout.call(this, marker);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
var queue = [];
|
||
|
var draining = false;
|
||
|
var currentQueue;
|
||
|
var queueIndex = -1;
|
||
|
|
||
|
function cleanUpNextTick() {
|
||
|
if (!draining || !currentQueue) {
|
||
|
return;
|
||
|
}
|
||
|
draining = false;
|
||
|
if (currentQueue.length) {
|
||
|
queue = currentQueue.concat(queue);
|
||
|
} else {
|
||
|
queueIndex = -1;
|
||
|
}
|
||
|
if (queue.length) {
|
||
|
drainQueue();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function drainQueue() {
|
||
|
if (draining) {
|
||
|
return;
|
||
|
}
|
||
|
var timeout = runTimeout(cleanUpNextTick);
|
||
|
draining = true;
|
||
|
|
||
|
var len = queue.length;
|
||
|
while(len) {
|
||
|
currentQueue = queue;
|
||
|
queue = [];
|
||
|
while (++queueIndex < len) {
|
||
|
if (currentQueue) {
|
||
|
currentQueue[queueIndex].run();
|
||
|
}
|
||
|
}
|
||
|
queueIndex = -1;
|
||
|
len = queue.length;
|
||
|
}
|
||
|
currentQueue = null;
|
||
|
draining = false;
|
||
|
runClearTimeout(timeout);
|
||
|
}
|
||
|
|
||
|
process.nextTick = function (fun) {
|
||
|
var args = new Array(arguments.length - 1);
|
||
|
if (arguments.length > 1) {
|
||
|
for (var i = 1; i < arguments.length; i++) {
|
||
|
args[i - 1] = arguments[i];
|
||
|
}
|
||
|
}
|
||
|
queue.push(new Item(fun, args));
|
||
|
if (queue.length === 1 && !draining) {
|
||
|
runTimeout(drainQueue);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// v8 likes predictible objects
|
||
|
function Item(fun, array) {
|
||
|
this.fun = fun;
|
||
|
this.array = array;
|
||
|
}
|
||
|
Item.prototype.run = function () {
|
||
|
this.fun.apply(null, this.array);
|
||
|
};
|
||
|
process.title = 'browser';
|
||
|
process.browser = true;
|
||
|
process.env = {};
|
||
|
process.argv = [];
|
||
|
process.version = ''; // empty string to avoid regexp issues
|
||
|
process.versions = {};
|
||
|
|
||
|
function noop() {}
|
||
|
|
||
|
process.on = noop;
|
||
|
process.addListener = noop;
|
||
|
process.once = noop;
|
||
|
process.off = noop;
|
||
|
process.removeListener = noop;
|
||
|
process.removeAllListeners = noop;
|
||
|
process.emit = noop;
|
||
|
process.prependListener = noop;
|
||
|
process.prependOnceListener = noop;
|
||
|
|
||
|
process.listeners = function (name) { return [] }
|
||
|
|
||
|
process.binding = function (name) {
|
||
|
throw new Error('process.binding is not supported');
|
||
|
};
|
||
|
|
||
|
process.cwd = function () { return '/' };
|
||
|
process.chdir = function (dir) {
|
||
|
throw new Error('process.chdir is not supported');
|
||
|
};
|
||
|
process.umask = function() { return 0; };
|
||
|
|
||
|
},{}],57:[function(require,module,exports){
|
||
|
module.exports = require('./lib/_stream_duplex.js');
|
||
|
|
||
|
},{"./lib/_stream_duplex.js":58}],58:[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.
|
||
|
|
||
|
// a duplex stream is just a stream that is both readable and writable.
|
||
|
// Since JS doesn't have multiple prototypal inheritance, this class
|
||
|
// prototypally inherits from Readable, and then parasitically from
|
||
|
// Writable.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var pna = require('process-nextick-args');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var objectKeys = Object.keys || function (obj) {
|
||
|
var keys = [];
|
||
|
for (var key in obj) {
|
||
|
keys.push(key);
|
||
|
}return keys;
|
||
|
};
|
||
|
/*</replacement>*/
|
||
|
|
||
|
module.exports = Duplex;
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var util = require('core-util-is');
|
||
|
util.inherits = require('inherits');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
var Readable = require('./_stream_readable');
|
||
|
var Writable = require('./_stream_writable');
|
||
|
|
||
|
util.inherits(Duplex, Readable);
|
||
|
|
||
|
{
|
||
|
// avoid scope creep, the keys array can then be collected
|
||
|
var keys = objectKeys(Writable.prototype);
|
||
|
for (var v = 0; v < keys.length; v++) {
|
||
|
var method = keys[v];
|
||
|
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function Duplex(options) {
|
||
|
if (!(this instanceof Duplex)) return new Duplex(options);
|
||
|
|
||
|
Readable.call(this, options);
|
||
|
Writable.call(this, options);
|
||
|
|
||
|
if (options && options.readable === false) this.readable = false;
|
||
|
|
||
|
if (options && options.writable === false) this.writable = false;
|
||
|
|
||
|
this.allowHalfOpen = true;
|
||
|
if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
||
|
|
||
|
this.once('end', onend);
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
||
|
// making it explicit this property is not enumerable
|
||
|
// because otherwise some prototype manipulation in
|
||
|
// userland will fail
|
||
|
enumerable: false,
|
||
|
get: function () {
|
||
|
return this._writableState.highWaterMark;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// the no-half-open enforcer
|
||
|
function onend() {
|
||
|
// if we allow half-open state, or if the writable side ended,
|
||
|
// then we're ok.
|
||
|
if (this.allowHalfOpen || this._writableState.ended) return;
|
||
|
|
||
|
// no more data can be written.
|
||
|
// But allow more writes to happen in this tick.
|
||
|
pna.nextTick(onEndNT, this);
|
||
|
}
|
||
|
|
||
|
function onEndNT(self) {
|
||
|
self.end();
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(Duplex.prototype, 'destroyed', {
|
||
|
get: function () {
|
||
|
if (this._readableState === undefined || this._writableState === undefined) {
|
||
|
return false;
|
||
|
}
|
||
|
return this._readableState.destroyed && this._writableState.destroyed;
|
||
|
},
|
||
|
set: function (value) {
|
||
|
// we ignore the value if the stream
|
||
|
// has not been initialized yet
|
||
|
if (this._readableState === undefined || this._writableState === undefined) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// backward compatibility, the user is explicitly
|
||
|
// managing destroyed
|
||
|
this._readableState.destroyed = value;
|
||
|
this._writableState.destroyed = value;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Duplex.prototype._destroy = function (err, cb) {
|
||
|
this.push(null);
|
||
|
this.end();
|
||
|
|
||
|
pna.nextTick(cb, err);
|
||
|
};
|
||
|
},{"./_stream_readable":60,"./_stream_writable":62,"core-util-is":42,"inherits":50,"process-nextick-args":55}],59:[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.
|
||
|
|
||
|
// a passthrough stream.
|
||
|
// basically just the most minimal sort of Transform stream.
|
||
|
// Every written chunk gets output as-is.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
module.exports = PassThrough;
|
||
|
|
||
|
var Transform = require('./_stream_transform');
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var util = require('core-util-is');
|
||
|
util.inherits = require('inherits');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
util.inherits(PassThrough, Transform);
|
||
|
|
||
|
function PassThrough(options) {
|
||
|
if (!(this instanceof PassThrough)) return new PassThrough(options);
|
||
|
|
||
|
Transform.call(this, options);
|
||
|
}
|
||
|
|
||
|
PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
||
|
cb(null, chunk);
|
||
|
};
|
||
|
},{"./_stream_transform":61,"core-util-is":42,"inherits":50}],60:[function(require,module,exports){
|
||
|
(function (process,global){
|
||
|
// 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.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var pna = require('process-nextick-args');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
module.exports = Readable;
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var isArray = require('isarray');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var Duplex;
|
||
|
/*</replacement>*/
|
||
|
|
||
|
Readable.ReadableState = ReadableState;
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var EE = require('events').EventEmitter;
|
||
|
|
||
|
var EElistenerCount = function (emitter, type) {
|
||
|
return emitter.listeners(type).length;
|
||
|
};
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var Stream = require('./internal/streams/stream');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var Buffer = require('safe-buffer').Buffer;
|
||
|
var OurUint8Array = global.Uint8Array || function () {};
|
||
|
function _uint8ArrayToBuffer(chunk) {
|
||
|
return Buffer.from(chunk);
|
||
|
}
|
||
|
function _isUint8Array(obj) {
|
||
|
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
||
|
}
|
||
|
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var util = require('core-util-is');
|
||
|
util.inherits = require('inherits');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var debugUtil = require('util');
|
||
|
var debug = void 0;
|
||
|
if (debugUtil && debugUtil.debuglog) {
|
||
|
debug = debugUtil.debuglog('stream');
|
||
|
} else {
|
||
|
debug = function () {};
|
||
|
}
|
||
|
/*</replacement>*/
|
||
|
|
||
|
var BufferList = require('./internal/streams/BufferList');
|
||
|
var destroyImpl = require('./internal/streams/destroy');
|
||
|
var StringDecoder;
|
||
|
|
||
|
util.inherits(Readable, Stream);
|
||
|
|
||
|
var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
||
|
|
||
|
function prependListener(emitter, event, fn) {
|
||
|
// Sadly this is not cacheable as some libraries bundle their own
|
||
|
// event emitter implementation with them.
|
||
|
if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
|
||
|
|
||
|
// This is a hack to make sure that our error handler is attached before any
|
||
|
// userland ones. NEVER DO THIS. This is here only because this code needs
|
||
|
// to continue to work with older versions of Node.js that do not include
|
||
|
// the prependListener() method. The goal is to eventually remove this hack.
|
||
|
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
|
||
|
}
|
||
|
|
||
|
function ReadableState(options, stream) {
|
||
|
Duplex = Duplex || require('./_stream_duplex');
|
||
|
|
||
|
options = options || {};
|
||
|
|
||
|
// Duplex streams are both readable and writable, but share
|
||
|
// the same options object.
|
||
|
// However, some cases require setting options to different
|
||
|
// values for the readable and the writable sides of the duplex stream.
|
||
|
// These options can be provided separately as readableXXX and writableXXX.
|
||
|
var isDuplex = stream instanceof Duplex;
|
||
|
|
||
|
// object stream flag. Used to make read(n) ignore n and to
|
||
|
// make all the buffer merging and length checks go away
|
||
|
this.objectMode = !!options.objectMode;
|
||
|
|
||
|
if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
||
|
|
||
|
// the point at which it stops calling _read() to fill the buffer
|
||
|
// Note: 0 is a valid value, means "don't call _read preemptively ever"
|
||
|
var hwm = options.highWaterMark;
|
||
|
var readableHwm = options.readableHighWaterMark;
|
||
|
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
||
|
|
||
|
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
|
||
|
|
||
|
// cast to ints.
|
||
|
this.highWaterMark = Math.floor(this.highWaterMark);
|
||
|
|
||
|
// A linked list is used to store data chunks instead of an array because the
|
||
|
// linked list can remove elements from the beginning faster than
|
||
|
// array.shift()
|
||
|
this.buffer = new BufferList();
|
||
|
this.length = 0;
|
||
|
this.pipes = null;
|
||
|
this.pipesCount = 0;
|
||
|
this.flowing = null;
|
||
|
this.ended = false;
|
||
|
this.endEmitted = false;
|
||
|
this.reading = false;
|
||
|
|
||
|
// a flag to be able to tell if the event 'readable'/'data' is emitted
|
||
|
// immediately, or on a later tick. We set this to true at first, because
|
||
|
// any actions that shouldn't happen until "later" should generally also
|
||
|
// not happen before the first read call.
|
||
|
this.sync = true;
|
||
|
|
||
|
// whenever we return null, then we set a flag to say
|
||
|
// that we're awaiting a 'readable' event emission.
|
||
|
this.needReadable = false;
|
||
|
this.emittedReadable = false;
|
||
|
this.readableListening = false;
|
||
|
this.resumeScheduled = false;
|
||
|
|
||
|
// has it been destroyed
|
||
|
this.destroyed = false;
|
||
|
|
||
|
// Crypto is kind of old and crusty. Historically, its default string
|
||
|
// encoding is 'binary' so we have to make this configurable.
|
||
|
// Everything else in the universe uses 'utf8', though.
|
||
|
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||
|
|
||
|
// the number of writers that are awaiting a drain event in .pipe()s
|
||
|
this.awaitDrain = 0;
|
||
|
|
||
|
// if true, a maybeReadMore has been scheduled
|
||
|
this.readingMore = false;
|
||
|
|
||
|
this.decoder = null;
|
||
|
this.encoding = null;
|
||
|
if (options.encoding) {
|
||
|
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
|
||
|
this.decoder = new StringDecoder(options.encoding);
|
||
|
this.encoding = options.encoding;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function Readable(options) {
|
||
|
Duplex = Duplex || require('./_stream_duplex');
|
||
|
|
||
|
if (!(this instanceof Readable)) return new Readable(options);
|
||
|
|
||
|
this._readableState = new ReadableState(options, this);
|
||
|
|
||
|
// legacy
|
||
|
this.readable = true;
|
||
|
|
||
|
if (options) {
|
||
|
if (typeof options.read === 'function') this._read = options.read;
|
||
|
|
||
|
if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
||
|
}
|
||
|
|
||
|
Stream.call(this);
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(Readable.prototype, 'destroyed', {
|
||
|
get: function () {
|
||
|
if (this._readableState === undefined) {
|
||
|
return false;
|
||
|
}
|
||
|
return this._readableState.destroyed;
|
||
|
},
|
||
|
set: function (value) {
|
||
|
// we ignore the value if the stream
|
||
|
// has not been initialized yet
|
||
|
if (!this._readableState) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// backward compatibility, the user is explicitly
|
||
|
// managing destroyed
|
||
|
this._readableState.destroyed = value;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Readable.prototype.destroy = destroyImpl.destroy;
|
||
|
Readable.prototype._undestroy = destroyImpl.undestroy;
|
||
|
Readable.prototype._destroy = function (err, cb) {
|
||
|
this.push(null);
|
||
|
cb(err);
|
||
|
};
|
||
|
|
||
|
// Manually shove something into the read() buffer.
|
||
|
// This returns true if the highWaterMark has not been hit yet,
|
||
|
// similar to how Writable.write() returns true if you should
|
||
|
// write() some more.
|
||
|
Readable.prototype.push = function (chunk, encoding) {
|
||
|
var state = this._readableState;
|
||
|
var skipChunkCheck;
|
||
|
|
||
|
if (!state.objectMode) {
|
||
|
if (typeof chunk === 'string') {
|
||
|
encoding = encoding || state.defaultEncoding;
|
||
|
if (encoding !== state.encoding) {
|
||
|
chunk = Buffer.from(chunk, encoding);
|
||
|
encoding = '';
|
||
|
}
|
||
|
skipChunkCheck = true;
|
||
|
}
|
||
|
} else {
|
||
|
skipChunkCheck = true;
|
||
|
}
|
||
|
|
||
|
return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
||
|
};
|
||
|
|
||
|
// Unshift should *always* be something directly out of read()
|
||
|
Readable.prototype.unshift = function (chunk) {
|
||
|
return readableAddChunk(this, chunk, null, true, false);
|
||
|
};
|
||
|
|
||
|
function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
||
|
var state = stream._readableState;
|
||
|
if (chunk === null) {
|
||
|
state.reading = false;
|
||
|
onEofChunk(stream, state);
|
||
|
} else {
|
||
|
var er;
|
||
|
if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
||
|
if (er) {
|
||
|
stream.emit('error', er);
|
||
|
} else if (state.objectMode || chunk && chunk.length > 0) {
|
||
|
if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
||
|
chunk = _uint8ArrayToBuffer(chunk);
|
||
|
}
|
||
|
|
||
|
if (addToFront) {
|
||
|
if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
|
||
|
} else if (state.ended) {
|
||
|
stream.emit('error', new Error('stream.push() after EOF'));
|
||
|
} else {
|
||
|
state.reading = false;
|
||
|
if (state.decoder && !encoding) {
|
||
|
chunk = state.decoder.write(chunk);
|
||
|
if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
|
||
|
} else {
|
||
|
addChunk(stream, state, chunk, false);
|
||
|
}
|
||
|
}
|
||
|
} else if (!addToFront) {
|
||
|
state.reading = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return needMoreData(state);
|
||
|
}
|
||
|
|
||
|
function addChunk(stream, state, chunk, addToFront) {
|
||
|
if (state.flowing && state.length === 0 && !state.sync) {
|
||
|
stream.emit('data', chunk);
|
||
|
stream.read(0);
|
||
|
} else {
|
||
|
// update the buffer info.
|
||
|
state.length += state.objectMode ? 1 : chunk.length;
|
||
|
if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
||
|
|
||
|
if (state.needReadable) emitReadable(stream);
|
||
|
}
|
||
|
maybeReadMore(stream, state);
|
||
|
}
|
||
|
|
||
|
function chunkInvalid(state, chunk) {
|
||
|
var er;
|
||
|
if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
||
|
er = new TypeError('Invalid non-string/buffer chunk');
|
||
|
}
|
||
|
return er;
|
||
|
}
|
||
|
|
||
|
// if it's past the high water mark, we can push in some more.
|
||
|
// Also, if we have no data yet, we can stand some
|
||
|
// more bytes. This is to work around cases where hwm=0,
|
||
|
// such as the repl. Also, if the push() triggered a
|
||
|
// readable event, and the user called read(largeNumber) such that
|
||
|
// needReadable was set, then we ought to push more, so that another
|
||
|
// 'readable' event will be triggered.
|
||
|
function needMoreData(state) {
|
||
|
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
||
|
}
|
||
|
|
||
|
Readable.prototype.isPaused = function () {
|
||
|
return this._readableState.flowing === false;
|
||
|
};
|
||
|
|
||
|
// backwards compatibility.
|
||
|
Readable.prototype.setEncoding = function (enc) {
|
||
|
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
|
||
|
this._readableState.decoder = new StringDecoder(enc);
|
||
|
this._readableState.encoding = enc;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
// Don't raise the hwm > 8MB
|
||
|
var MAX_HWM = 0x800000;
|
||
|
function computeNewHighWaterMark(n) {
|
||
|
if (n >= MAX_HWM) {
|
||
|
n = MAX_HWM;
|
||
|
} else {
|
||
|
// Get the next highest power of 2 to prevent increasing hwm excessively in
|
||
|
// tiny amounts
|
||
|
n--;
|
||
|
n |= n >>> 1;
|
||
|
n |= n >>> 2;
|
||
|
n |= n >>> 4;
|
||
|
n |= n >>> 8;
|
||
|
n |= n >>> 16;
|
||
|
n++;
|
||
|
}
|
||
|
return n;
|
||
|
}
|
||
|
|
||
|
// This function is designed to be inlinable, so please take care when making
|
||
|
// changes to the function body.
|
||
|
function howMuchToRead(n, state) {
|
||
|
if (n <= 0 || state.length === 0 && state.ended) return 0;
|
||
|
if (state.objectMode) return 1;
|
||
|
if (n !== n) {
|
||
|
// Only flow one buffer at a time
|
||
|
if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
|
||
|
}
|
||
|
// If we're asking for more than the current hwm, then raise the hwm.
|
||
|
if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
||
|
if (n <= state.length) return n;
|
||
|
// Don't have enough
|
||
|
if (!state.ended) {
|
||
|
state.needReadable = true;
|
||
|
return 0;
|
||
|
}
|
||
|
return state.length;
|
||
|
}
|
||
|
|
||
|
// you can override either this method, or the async _read(n) below.
|
||
|
Readable.prototype.read = function (n) {
|
||
|
debug('read', n);
|
||
|
n = parseInt(n, 10);
|
||
|
var state = this._readableState;
|
||
|
var nOrig = n;
|
||
|
|
||
|
if (n !== 0) state.emittedReadable = false;
|
||
|
|
||
|
// if we're doing read(0) to trigger a readable event, but we
|
||
|
// already have a bunch of data in the buffer, then just trigger
|
||
|
// the 'readable' event and move on.
|
||
|
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
||
|
debug('read: emitReadable', state.length, state.ended);
|
||
|
if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
n = howMuchToRead(n, state);
|
||
|
|
||
|
// if we've ended, and we're now clear, then finish it up.
|
||
|
if (n === 0 && state.ended) {
|
||
|
if (state.length === 0) endReadable(this);
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
// All the actual chunk generation logic needs to be
|
||
|
// *below* the call to _read. The reason is that in certain
|
||
|
// synthetic stream cases, such as passthrough streams, _read
|
||
|
// may be a completely synchronous operation which may change
|
||
|
// the state of the read buffer, providing enough data when
|
||
|
// before there was *not* enough.
|
||
|
//
|
||
|
// So, the steps are:
|
||
|
// 1. Figure out what the state of things will be after we do
|
||
|
// a read from the buffer.
|
||
|
//
|
||
|
// 2. If that resulting state will trigger a _read, then call _read.
|
||
|
// Note that this may be asynchronous, or synchronous. Yes, it is
|
||
|
// deeply ugly to write APIs this way, but that still doesn't mean
|
||
|
// that the Readable class should behave improperly, as streams are
|
||
|
// designed to be sync/async agnostic.
|
||
|
// Take note if the _read call is sync or async (ie, if the read call
|
||
|
// has returned yet), so that we know whether or not it's safe to emit
|
||
|
// 'readable' etc.
|
||
|
//
|
||
|
// 3. Actually pull the requested chunks out of the buffer and return.
|
||
|
|
||
|
// if we need a readable event, then we need to do some reading.
|
||
|
var doRead = state.needReadable;
|
||
|
debug('need readable', doRead);
|
||
|
|
||
|
// if we currently have less than the highWaterMark, then also read some
|
||
|
if (state.length === 0 || state.length - n < state.highWaterMark) {
|
||
|
doRead = true;
|
||
|
debug('length less than watermark', doRead);
|
||
|
}
|
||
|
|
||
|
// however, if we've ended, then there's no point, and if we're already
|
||
|
// reading, then it's unnecessary.
|
||
|
if (state.ended || state.reading) {
|
||
|
doRead = false;
|
||
|
debug('reading or ended', doRead);
|
||
|
} else if (doRead) {
|
||
|
debug('do read');
|
||
|
state.reading = true;
|
||
|
state.sync = true;
|
||
|
// if the length is currently zero, then we *need* a readable event.
|
||
|
if (state.length === 0) state.needReadable = true;
|
||
|
// call internal read method
|
||
|
this._read(state.highWaterMark);
|
||
|
state.sync = false;
|
||
|
// If _read pushed data synchronously, then `reading` will be false,
|
||
|
// and we need to re-evaluate how much data we can return to the user.
|
||
|
if (!state.reading) n = howMuchToRead(nOrig, state);
|
||
|
}
|
||
|
|
||
|
var ret;
|
||
|
if (n > 0) ret = fromList(n, state);else ret = null;
|
||
|
|
||
|
if (ret === null) {
|
||
|
state.needReadable = true;
|
||
|
n = 0;
|
||
|
} else {
|
||
|
state.length -= n;
|
||
|
}
|
||
|
|
||
|
if (state.length === 0) {
|
||
|
// If we have nothing in the buffer, then we want to know
|
||
|
// as soon as we *do* get something into the buffer.
|
||
|
if (!state.ended) state.needReadable = true;
|
||
|
|
||
|
// If we tried to read() past the EOF, then emit end on the next tick.
|
||
|
if (nOrig !== n && state.ended) endReadable(this);
|
||
|
}
|
||
|
|
||
|
if (ret !== null) this.emit('data', ret);
|
||
|
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
function onEofChunk(stream, state) {
|
||
|
if (state.ended) return;
|
||
|
if (state.decoder) {
|
||
|
var chunk = state.decoder.end();
|
||
|
if (chunk && chunk.length) {
|
||
|
state.buffer.push(chunk);
|
||
|
state.length += state.objectMode ? 1 : chunk.length;
|
||
|
}
|
||
|
}
|
||
|
state.ended = true;
|
||
|
|
||
|
// emit 'readable' now to make sure it gets picked up.
|
||
|
emitReadable(stream);
|
||
|
}
|
||
|
|
||
|
// Don't emit readable right away in sync mode, because this can trigger
|
||
|
// another read() call => stack overflow. This way, it might trigger
|
||
|
// a nextTick recursion warning, but that's not so bad.
|
||
|
function emitReadable(stream) {
|
||
|
var state = stream._readableState;
|
||
|
state.needReadable = false;
|
||
|
if (!state.emittedReadable) {
|
||
|
debug('emitReadable', state.flowing);
|
||
|
state.emittedReadable = true;
|
||
|
if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function emitReadable_(stream) {
|
||
|
debug('emit readable');
|
||
|
stream.emit('readable');
|
||
|
flow(stream);
|
||
|
}
|
||
|
|
||
|
// at this point, the user has presumably seen the 'readable' event,
|
||
|
// and called read() to consume some data. that may have triggered
|
||
|
// in turn another _read(n) call, in which case reading = true if
|
||
|
// it's in progress.
|
||
|
// However, if we're not ended, or reading, and the length < hwm,
|
||
|
// then go ahead and try to read some more preemptively.
|
||
|
function maybeReadMore(stream, state) {
|
||
|
if (!state.readingMore) {
|
||
|
state.readingMore = true;
|
||
|
pna.nextTick(maybeReadMore_, stream, state);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function maybeReadMore_(stream, state) {
|
||
|
var len = state.length;
|
||
|
while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
|
||
|
debug('maybeReadMore read 0');
|
||
|
stream.read(0);
|
||
|
if (len === state.length)
|
||
|
// didn't get any data, stop spinning.
|
||
|
break;else len = state.length;
|
||
|
}
|
||
|
state.readingMore = false;
|
||
|
}
|
||
|
|
||
|
// abstract method. to be overridden in specific implementation classes.
|
||
|
// call cb(er, data) where data is <= n in length.
|
||
|
// for virtual (non-string, non-buffer) streams, "length" is somewhat
|
||
|
// arbitrary, and perhaps not very meaningful.
|
||
|
Readable.prototype._read = function (n) {
|
||
|
this.emit('error', new Error('_read() is not implemented'));
|
||
|
};
|
||
|
|
||
|
Readable.prototype.pipe = function (dest, pipeOpts) {
|
||
|
var src = this;
|
||
|
var state = this._readableState;
|
||
|
|
||
|
switch (state.pipesCount) {
|
||
|
case 0:
|
||
|
state.pipes = dest;
|
||
|
break;
|
||
|
case 1:
|
||
|
state.pipes = [state.pipes, dest];
|
||
|
break;
|
||
|
default:
|
||
|
state.pipes.push(dest);
|
||
|
break;
|
||
|
}
|
||
|
state.pipesCount += 1;
|
||
|
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
||
|
|
||
|
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
||
|
|
||
|
var endFn = doEnd ? onend : unpipe;
|
||
|
if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
|
||
|
|
||
|
dest.on('unpipe', onunpipe);
|
||
|
function onunpipe(readable, unpipeInfo) {
|
||
|
debug('onunpipe');
|
||
|
if (readable === src) {
|
||
|
if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
||
|
unpipeInfo.hasUnpiped = true;
|
||
|
cleanup();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function onend() {
|
||
|
debug('onend');
|
||
|
dest.end();
|
||
|
}
|
||
|
|
||
|
// when the dest drains, it reduces the awaitDrain counter
|
||
|
// on the source. This would be more elegant with a .once()
|
||
|
// handler in flow(), but adding and removing repeatedly is
|
||
|
// too slow.
|
||
|
var ondrain = pipeOnDrain(src);
|
||
|
dest.on('drain', ondrain);
|
||
|
|
||
|
var cleanedUp = false;
|
||
|
function cleanup() {
|
||
|
debug('cleanup');
|
||
|
// cleanup event handlers once the pipe is broken
|
||
|
dest.removeListener('close', onclose);
|
||
|
dest.removeListener('finish', onfinish);
|
||
|
dest.removeListener('drain', ondrain);
|
||
|
dest.removeListener('error', onerror);
|
||
|
dest.removeListener('unpipe', onunpipe);
|
||
|
src.removeListener('end', onend);
|
||
|
src.removeListener('end', unpipe);
|
||
|
src.removeListener('data', ondata);
|
||
|
|
||
|
cleanedUp = true;
|
||
|
|
||
|
// if the reader is waiting for a drain event from this
|
||
|
// specific writer, then it would cause it to never start
|
||
|
// flowing again.
|
||
|
// So, if this is awaiting a drain, then we just call it now.
|
||
|
// If we don't know, then assume that we are waiting for one.
|
||
|
if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
||
|
}
|
||
|
|
||
|
// If the user pushes more data while we're writing to dest then we'll end up
|
||
|
// in ondata again. However, we only want to increase awaitDrain once because
|
||
|
// dest will only emit one 'drain' event for the multiple writes.
|
||
|
// => Introduce a guard on increasing awaitDrain.
|
||
|
var increasedAwaitDrain = false;
|
||
|
src.on('data', ondata);
|
||
|
function ondata(chunk) {
|
||
|
debug('ondata');
|
||
|
increasedAwaitDrain = false;
|
||
|
var ret = dest.write(chunk);
|
||
|
if (false === ret && !increasedAwaitDrain) {
|
||
|
// If the user unpiped during `dest.write()`, it is possible
|
||
|
// to get stuck in a permanently paused state if that write
|
||
|
// also returned false.
|
||
|
// => Check whether `dest` is still a piping destination.
|
||
|
if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
||
|
debug('false write response, pause', src._readableState.awaitDrain);
|
||
|
src._readableState.awaitDrain++;
|
||
|
increasedAwaitDrain = true;
|
||
|
}
|
||
|
src.pause();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// if the dest has an error, then stop piping into it.
|
||
|
// however, don't suppress the throwing behavior for this.
|
||
|
function onerror(er) {
|
||
|
debug('onerror', er);
|
||
|
unpipe();
|
||
|
dest.removeListener('error', onerror);
|
||
|
if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
|
||
|
}
|
||
|
|
||
|
// Make sure our error handler is attached before userland ones.
|
||
|
prependListener(dest, 'error', onerror);
|
||
|
|
||
|
// Both close and finish should trigger unpipe, but only once.
|
||
|
function onclose() {
|
||
|
dest.removeListener('finish', onfinish);
|
||
|
unpipe();
|
||
|
}
|
||
|
dest.once('close', onclose);
|
||
|
function onfinish() {
|
||
|
debug('onfinish');
|
||
|
dest.removeListener('close', onclose);
|
||
|
unpipe();
|
||
|
}
|
||
|
dest.once('finish', onfinish);
|
||
|
|
||
|
function unpipe() {
|
||
|
debug('unpipe');
|
||
|
src.unpipe(dest);
|
||
|
}
|
||
|
|
||
|
// tell the dest that it's being piped to
|
||
|
dest.emit('pipe', src);
|
||
|
|
||
|
// start the flow if it hasn't been started already.
|
||
|
if (!state.flowing) {
|
||
|
debug('pipe resume');
|
||
|
src.resume();
|
||
|
}
|
||
|
|
||
|
return dest;
|
||
|
};
|
||
|
|
||
|
function pipeOnDrain(src) {
|
||
|
return function () {
|
||
|
var state = src._readableState;
|
||
|
debug('pipeOnDrain', state.awaitDrain);
|
||
|
if (state.awaitDrain) state.awaitDrain--;
|
||
|
if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
||
|
state.flowing = true;
|
||
|
flow(src);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
Readable.prototype.unpipe = function (dest) {
|
||
|
var state = this._readableState;
|
||
|
var unpipeInfo = { hasUnpiped: false };
|
||
|
|
||
|
// if we're not piping anywhere, then do nothing.
|
||
|
if (state.pipesCount === 0) return this;
|
||
|
|
||
|
// just one destination. most common case.
|
||
|
if (state.pipesCount === 1) {
|
||
|
// passed in one, but it's not the right one.
|
||
|
if (dest && dest !== state.pipes) return this;
|
||
|
|
||
|
if (!dest) dest = state.pipes;
|
||
|
|
||
|
// got a match.
|
||
|
state.pipes = null;
|
||
|
state.pipesCount = 0;
|
||
|
state.flowing = false;
|
||
|
if (dest) dest.emit('unpipe', this, unpipeInfo);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
// slow case. multiple pipe destinations.
|
||
|
|
||
|
if (!dest) {
|
||
|
// remove all.
|
||
|
var dests = state.pipes;
|
||
|
var len = state.pipesCount;
|
||
|
state.pipes = null;
|
||
|
state.pipesCount = 0;
|
||
|
state.flowing = false;
|
||
|
|
||
|
for (var i = 0; i < len; i++) {
|
||
|
dests[i].emit('unpipe', this, unpipeInfo);
|
||
|
}return this;
|
||
|
}
|
||
|
|
||
|
// try to find the right one.
|
||
|
var index = indexOf(state.pipes, dest);
|
||
|
if (index === -1) return this;
|
||
|
|
||
|
state.pipes.splice(index, 1);
|
||
|
state.pipesCount -= 1;
|
||
|
if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
||
|
|
||
|
dest.emit('unpipe', this, unpipeInfo);
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
// set up data events if they are asked for
|
||
|
// Ensure readable listeners eventually get something
|
||
|
Readable.prototype.on = function (ev, fn) {
|
||
|
var res = Stream.prototype.on.call(this, ev, fn);
|
||
|
|
||
|
if (ev === 'data') {
|
||
|
// Start flowing on next tick if stream isn't explicitly paused
|
||
|
if (this._readableState.flowing !== false) this.resume();
|
||
|
} else if (ev === 'readable') {
|
||
|
var state = this._readableState;
|
||
|
if (!state.endEmitted && !state.readableListening) {
|
||
|
state.readableListening = state.needReadable = true;
|
||
|
state.emittedReadable = false;
|
||
|
if (!state.reading) {
|
||
|
pna.nextTick(nReadingNextTick, this);
|
||
|
} else if (state.length) {
|
||
|
emitReadable(this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
};
|
||
|
Readable.prototype.addListener = Readable.prototype.on;
|
||
|
|
||
|
function nReadingNextTick(self) {
|
||
|
debug('readable nexttick read 0');
|
||
|
self.read(0);
|
||
|
}
|
||
|
|
||
|
// pause() and resume() are remnants of the legacy readable stream API
|
||
|
// If the user uses them, then switch into old mode.
|
||
|
Readable.prototype.resume = function () {
|
||
|
var state = this._readableState;
|
||
|
if (!state.flowing) {
|
||
|
debug('resume');
|
||
|
state.flowing = true;
|
||
|
resume(this, state);
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
function resume(stream, state) {
|
||
|
if (!state.resumeScheduled) {
|
||
|
state.resumeScheduled = true;
|
||
|
pna.nextTick(resume_, stream, state);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function resume_(stream, state) {
|
||
|
if (!state.reading) {
|
||
|
debug('resume read 0');
|
||
|
stream.read(0);
|
||
|
}
|
||
|
|
||
|
state.resumeScheduled = false;
|
||
|
state.awaitDrain = 0;
|
||
|
stream.emit('resume');
|
||
|
flow(stream);
|
||
|
if (state.flowing && !state.reading) stream.read(0);
|
||
|
}
|
||
|
|
||
|
Readable.prototype.pause = function () {
|
||
|
debug('call pause flowing=%j', this._readableState.flowing);
|
||
|
if (false !== this._readableState.flowing) {
|
||
|
debug('pause');
|
||
|
this._readableState.flowing = false;
|
||
|
this.emit('pause');
|
||
|
}
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
function flow(stream) {
|
||
|
var state = stream._readableState;
|
||
|
debug('flow', state.flowing);
|
||
|
while (state.flowing && stream.read() !== null) {}
|
||
|
}
|
||
|
|
||
|
// wrap an old-style stream as the async data source.
|
||
|
// This is *not* part of the readable stream interface.
|
||
|
// It is an ugly unfortunate mess of history.
|
||
|
Readable.prototype.wrap = function (stream) {
|
||
|
var _this = this;
|
||
|
|
||
|
var state = this._readableState;
|
||
|
var paused = false;
|
||
|
|
||
|
stream.on('end', function () {
|
||
|
debug('wrapped end');
|
||
|
if (state.decoder && !state.ended) {
|
||
|
var chunk = state.decoder.end();
|
||
|
if (chunk && chunk.length) _this.push(chunk);
|
||
|
}
|
||
|
|
||
|
_this.push(null);
|
||
|
});
|
||
|
|
||
|
stream.on('data', function (chunk) {
|
||
|
debug('wrapped data');
|
||
|
if (state.decoder) chunk = state.decoder.write(chunk);
|
||
|
|
||
|
// don't skip over falsy values in objectMode
|
||
|
if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
||
|
|
||
|
var ret = _this.push(chunk);
|
||
|
if (!ret) {
|
||
|
paused = true;
|
||
|
stream.pause();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// proxy all the other methods.
|
||
|
// important when wrapping filters and duplexes.
|
||
|
for (var i in stream) {
|
||
|
if (this[i] === undefined && typeof stream[i] === 'function') {
|
||
|
this[i] = function (method) {
|
||
|
return function () {
|
||
|
return stream[method].apply(stream, arguments);
|
||
|
};
|
||
|
}(i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// proxy certain important events.
|
||
|
for (var n = 0; n < kProxyEvents.length; n++) {
|
||
|
stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
||
|
}
|
||
|
|
||
|
// when we try to consume some more bytes, simply unpause the
|
||
|
// underlying stream.
|
||
|
this._read = function (n) {
|
||
|
debug('wrapped _read', n);
|
||
|
if (paused) {
|
||
|
paused = false;
|
||
|
stream.resume();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
||
|
// making it explicit this property is not enumerable
|
||
|
// because otherwise some prototype manipulation in
|
||
|
// userland will fail
|
||
|
enumerable: false,
|
||
|
get: function () {
|
||
|
return this._readableState.highWaterMark;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// exposed for testing purposes only.
|
||
|
Readable._fromList = fromList;
|
||
|
|
||
|
// Pluck off n bytes from an array of buffers.
|
||
|
// Length is the combined lengths of all the buffers in the list.
|
||
|
// This function is designed to be inlinable, so please take care when making
|
||
|
// changes to the function body.
|
||
|
function fromList(n, state) {
|
||
|
// nothing buffered
|
||
|
if (state.length === 0) return null;
|
||
|
|
||
|
var ret;
|
||
|
if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
||
|
// read it all, truncate the list
|
||
|
if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
|
||
|
state.buffer.clear();
|
||
|
} else {
|
||
|
// read part of list
|
||
|
ret = fromListPartial(n, state.buffer, state.decoder);
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
// Extracts only enough buffered data to satisfy the amount requested.
|
||
|
// This function is designed to be inlinable, so please take care when making
|
||
|
// changes to the function body.
|
||
|
function fromListPartial(n, list, hasStrings) {
|
||
|
var ret;
|
||
|
if (n < list.head.data.length) {
|
||
|
// slice is the same for buffers and strings
|
||
|
ret = list.head.data.slice(0, n);
|
||
|
list.head.data = list.head.data.slice(n);
|
||
|
} else if (n === list.head.data.length) {
|
||
|
// first chunk is a perfect match
|
||
|
ret = list.shift();
|
||
|
} else {
|
||
|
// result spans more than one buffer
|
||
|
ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
// Copies a specified amount of characters from the list of buffered data
|
||
|
// chunks.
|
||
|
// This function is designed to be inlinable, so please take care when making
|
||
|
// changes to the function body.
|
||
|
function copyFromBufferString(n, list) {
|
||
|
var p = list.head;
|
||
|
var c = 1;
|
||
|
var ret = p.data;
|
||
|
n -= ret.length;
|
||
|
while (p = p.next) {
|
||
|
var str = p.data;
|
||
|
var nb = n > str.length ? str.length : n;
|
||
|
if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
||
|
n -= nb;
|
||
|
if (n === 0) {
|
||
|
if (nb === str.length) {
|
||
|
++c;
|
||
|
if (p.next) list.head = p.next;else list.head = list.tail = null;
|
||
|
} else {
|
||
|
list.head = p;
|
||
|
p.data = str.slice(nb);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
++c;
|
||
|
}
|
||
|
list.length -= c;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
// Copies a specified amount of bytes from the list of buffered data chunks.
|
||
|
// This function is designed to be inlinable, so please take care when making
|
||
|
// changes to the function body.
|
||
|
function copyFromBuffer(n, list) {
|
||
|
var ret = Buffer.allocUnsafe(n);
|
||
|
var p = list.head;
|
||
|
var c = 1;
|
||
|
p.data.copy(ret);
|
||
|
n -= p.data.length;
|
||
|
while (p = p.next) {
|
||
|
var buf = p.data;
|
||
|
var nb = n > buf.length ? buf.length : n;
|
||
|
buf.copy(ret, ret.length - n, 0, nb);
|
||
|
n -= nb;
|
||
|
if (n === 0) {
|
||
|
if (nb === buf.length) {
|
||
|
++c;
|
||
|
if (p.next) list.head = p.next;else list.head = list.tail = null;
|
||
|
} else {
|
||
|
list.head = p;
|
||
|
p.data = buf.slice(nb);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
++c;
|
||
|
}
|
||
|
list.length -= c;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
function endReadable(stream) {
|
||
|
var state = stream._readableState;
|
||
|
|
||
|
// If we get here before consuming all the bytes, then that is a
|
||
|
// bug in node. Should never happen.
|
||
|
if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
|
||
|
|
||
|
if (!state.endEmitted) {
|
||
|
state.ended = true;
|
||
|
pna.nextTick(endReadableNT, state, stream);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function endReadableNT(state, stream) {
|
||
|
// Check that we didn't get one last unshift.
|
||
|
if (!state.endEmitted && state.length === 0) {
|
||
|
state.endEmitted = true;
|
||
|
stream.readable = false;
|
||
|
stream.emit('end');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function indexOf(xs, x) {
|
||
|
for (var i = 0, l = xs.length; i < l; i++) {
|
||
|
if (xs[i] === x) return i;
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"./_stream_duplex":58,"./internal/streams/BufferList":63,"./internal/streams/destroy":64,"./internal/streams/stream":65,"_process":56,"core-util-is":42,"events":47,"inherits":50,"isarray":52,"process-nextick-args":55,"safe-buffer":70,"string_decoder/":72,"util":38}],61:[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.
|
||
|
|
||
|
// a transform stream is a readable/writable stream where you do
|
||
|
// something with the data. Sometimes it's called a "filter",
|
||
|
// but that's not a great name for it, since that implies a thing where
|
||
|
// some bits pass through, and others are simply ignored. (That would
|
||
|
// be a valid example of a transform, of course.)
|
||
|
//
|
||
|
// While the output is causally related to the input, it's not a
|
||
|
// necessarily symmetric or synchronous transformation. For example,
|
||
|
// a zlib stream might take multiple plain-text writes(), and then
|
||
|
// emit a single compressed chunk some time in the future.
|
||
|
//
|
||
|
// Here's how this works:
|
||
|
//
|
||
|
// The Transform stream has all the aspects of the readable and writable
|
||
|
// stream classes. When you write(chunk), that calls _write(chunk,cb)
|
||
|
// internally, and returns false if there's a lot of pending writes
|
||
|
// buffered up. When you call read(), that calls _read(n) until
|
||
|
// there's enough pending readable data buffered up.
|
||
|
//
|
||
|
// In a transform stream, the written data is placed in a buffer. When
|
||
|
// _read(n) is called, it transforms the queued up data, calling the
|
||
|
// buffered _write cb's as it consumes chunks. If consuming a single
|
||
|
// written chunk would result in multiple output chunks, then the first
|
||
|
// outputted bit calls the readcb, and subsequent chunks just go into
|
||
|
// the read buffer, and will cause it to emit 'readable' if necessary.
|
||
|
//
|
||
|
// This way, back-pressure is actually determined by the reading side,
|
||
|
// since _read has to be called to start processing a new chunk. However,
|
||
|
// a pathological inflate type of transform can cause excessive buffering
|
||
|
// here. For example, imagine a stream where every byte of input is
|
||
|
// interpreted as an integer from 0-255, and then results in that many
|
||
|
// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
|
||
|
// 1kb of data being output. In this case, you could write a very small
|
||
|
// amount of input, and end up with a very large amount of output. In
|
||
|
// such a pathological inflating mechanism, there'd be no way to tell
|
||
|
// the system to stop doing the transform. A single 4MB write could
|
||
|
// cause the system to run out of memory.
|
||
|
//
|
||
|
// However, even in such a pathological case, only a single written chunk
|
||
|
// would be consumed, and then the rest would wait (un-transformed) until
|
||
|
// the results of the previous transformed chunk were consumed.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
module.exports = Transform;
|
||
|
|
||
|
var Duplex = require('./_stream_duplex');
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var util = require('core-util-is');
|
||
|
util.inherits = require('inherits');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
util.inherits(Transform, Duplex);
|
||
|
|
||
|
function afterTransform(er, data) {
|
||
|
var ts = this._transformState;
|
||
|
ts.transforming = false;
|
||
|
|
||
|
var cb = ts.writecb;
|
||
|
|
||
|
if (!cb) {
|
||
|
return this.emit('error', new Error('write callback called multiple times'));
|
||
|
}
|
||
|
|
||
|
ts.writechunk = null;
|
||
|
ts.writecb = null;
|
||
|
|
||
|
if (data != null) // single equals check for both `null` and `undefined`
|
||
|
this.push(data);
|
||
|
|
||
|
cb(er);
|
||
|
|
||
|
var rs = this._readableState;
|
||
|
rs.reading = false;
|
||
|
if (rs.needReadable || rs.length < rs.highWaterMark) {
|
||
|
this._read(rs.highWaterMark);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function Transform(options) {
|
||
|
if (!(this instanceof Transform)) return new Transform(options);
|
||
|
|
||
|
Duplex.call(this, options);
|
||
|
|
||
|
this._transformState = {
|
||
|
afterTransform: afterTransform.bind(this),
|
||
|
needTransform: false,
|
||
|
transforming: false,
|
||
|
writecb: null,
|
||
|
writechunk: null,
|
||
|
writeencoding: null
|
||
|
};
|
||
|
|
||
|
// start out asking for a readable event once data is transformed.
|
||
|
this._readableState.needReadable = true;
|
||
|
|
||
|
// we have implemented the _read method, and done the other things
|
||
|
// that Readable wants before the first _read call, so unset the
|
||
|
// sync guard flag.
|
||
|
this._readableState.sync = false;
|
||
|
|
||
|
if (options) {
|
||
|
if (typeof options.transform === 'function') this._transform = options.transform;
|
||
|
|
||
|
if (typeof options.flush === 'function') this._flush = options.flush;
|
||
|
}
|
||
|
|
||
|
// When the writable side finishes, then flush out anything remaining.
|
||
|
this.on('prefinish', prefinish);
|
||
|
}
|
||
|
|
||
|
function prefinish() {
|
||
|
var _this = this;
|
||
|
|
||
|
if (typeof this._flush === 'function') {
|
||
|
this._flush(function (er, data) {
|
||
|
done(_this, er, data);
|
||
|
});
|
||
|
} else {
|
||
|
done(this, null, null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Transform.prototype.push = function (chunk, encoding) {
|
||
|
this._transformState.needTransform = false;
|
||
|
return Duplex.prototype.push.call(this, chunk, encoding);
|
||
|
};
|
||
|
|
||
|
// This is the part where you do stuff!
|
||
|
// override this function in implementation classes.
|
||
|
// 'chunk' is an input chunk.
|
||
|
//
|
||
|
// Call `push(newChunk)` to pass along transformed output
|
||
|
// to the readable side. You may call 'push' zero or more times.
|
||
|
//
|
||
|
// Call `cb(err)` when you are done with this chunk. If you pass
|
||
|
// an error, then that'll put the hurt on the whole operation. If you
|
||
|
// never call cb(), then you'll never get another chunk.
|
||
|
Transform.prototype._transform = function (chunk, encoding, cb) {
|
||
|
throw new Error('_transform() is not implemented');
|
||
|
};
|
||
|
|
||
|
Transform.prototype._write = function (chunk, encoding, cb) {
|
||
|
var ts = this._transformState;
|
||
|
ts.writecb = cb;
|
||
|
ts.writechunk = chunk;
|
||
|
ts.writeencoding = encoding;
|
||
|
if (!ts.transforming) {
|
||
|
var rs = this._readableState;
|
||
|
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Doesn't matter what the args are here.
|
||
|
// _transform does all the work.
|
||
|
// That we got here means that the readable side wants more data.
|
||
|
Transform.prototype._read = function (n) {
|
||
|
var ts = this._transformState;
|
||
|
|
||
|
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
||
|
ts.transforming = true;
|
||
|
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
||
|
} else {
|
||
|
// mark that we need a transform, so that any data that comes in
|
||
|
// will get processed, now that we've asked for it.
|
||
|
ts.needTransform = true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Transform.prototype._destroy = function (err, cb) {
|
||
|
var _this2 = this;
|
||
|
|
||
|
Duplex.prototype._destroy.call(this, err, function (err2) {
|
||
|
cb(err2);
|
||
|
_this2.emit('close');
|
||
|
});
|
||
|
};
|
||
|
|
||
|
function done(stream, er, data) {
|
||
|
if (er) return stream.emit('error', er);
|
||
|
|
||
|
if (data != null) // single equals check for both `null` and `undefined`
|
||
|
stream.push(data);
|
||
|
|
||
|
// if there's nothing in the write buffer, then that means
|
||
|
// that nothing more will ever be provided
|
||
|
if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
|
||
|
|
||
|
if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
|
||
|
|
||
|
return stream.push(null);
|
||
|
}
|
||
|
},{"./_stream_duplex":58,"core-util-is":42,"inherits":50}],62:[function(require,module,exports){
|
||
|
(function (process,global){
|
||
|
// 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.
|
||
|
|
||
|
// A bit simpler than readable streams.
|
||
|
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
|
||
|
// the drain event emission and buffering.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var pna = require('process-nextick-args');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
module.exports = Writable;
|
||
|
|
||
|
/* <replacement> */
|
||
|
function WriteReq(chunk, encoding, cb) {
|
||
|
this.chunk = chunk;
|
||
|
this.encoding = encoding;
|
||
|
this.callback = cb;
|
||
|
this.next = null;
|
||
|
}
|
||
|
|
||
|
// It seems a linked list but it is not
|
||
|
// there will be only 2 of these for each stream
|
||
|
function CorkedRequest(state) {
|
||
|
var _this = this;
|
||
|
|
||
|
this.next = null;
|
||
|
this.entry = null;
|
||
|
this.finish = function () {
|
||
|
onCorkedFinish(_this, state);
|
||
|
};
|
||
|
}
|
||
|
/* </replacement> */
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var Duplex;
|
||
|
/*</replacement>*/
|
||
|
|
||
|
Writable.WritableState = WritableState;
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var util = require('core-util-is');
|
||
|
util.inherits = require('inherits');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var internalUtil = {
|
||
|
deprecate: require('util-deprecate')
|
||
|
};
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
var Stream = require('./internal/streams/stream');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var Buffer = require('safe-buffer').Buffer;
|
||
|
var OurUint8Array = global.Uint8Array || function () {};
|
||
|
function _uint8ArrayToBuffer(chunk) {
|
||
|
return Buffer.from(chunk);
|
||
|
}
|
||
|
function _isUint8Array(obj) {
|
||
|
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
||
|
}
|
||
|
|
||
|
/*</replacement>*/
|
||
|
|
||
|
var destroyImpl = require('./internal/streams/destroy');
|
||
|
|
||
|
util.inherits(Writable, Stream);
|
||
|
|
||
|
function nop() {}
|
||
|
|
||
|
function WritableState(options, stream) {
|
||
|
Duplex = Duplex || require('./_stream_duplex');
|
||
|
|
||
|
options = options || {};
|
||
|
|
||
|
// Duplex streams are both readable and writable, but share
|
||
|
// the same options object.
|
||
|
// However, some cases require setting options to different
|
||
|
// values for the readable and the writable sides of the duplex stream.
|
||
|
// These options can be provided separately as readableXXX and writableXXX.
|
||
|
var isDuplex = stream instanceof Duplex;
|
||
|
|
||
|
// object stream flag to indicate whether or not this stream
|
||
|
// contains buffers or objects.
|
||
|
this.objectMode = !!options.objectMode;
|
||
|
|
||
|
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
||
|
|
||
|
// the point at which write() starts returning false
|
||
|
// Note: 0 is a valid value, means that we always return false if
|
||
|
// the entire buffer is not flushed immediately on write()
|
||
|
var hwm = options.highWaterMark;
|
||
|
var writableHwm = options.writableHighWaterMark;
|
||
|
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
||
|
|
||
|
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
|
||
|
|
||
|
// cast to ints.
|
||
|
this.highWaterMark = Math.floor(this.highWaterMark);
|
||
|
|
||
|
// if _final has been called
|
||
|
this.finalCalled = false;
|
||
|
|
||
|
// drain event flag.
|
||
|
this.needDrain = false;
|
||
|
// at the start of calling end()
|
||
|
this.ending = false;
|
||
|
// when end() has been called, and returned
|
||
|
this.ended = false;
|
||
|
// when 'finish' is emitted
|
||
|
this.finished = false;
|
||
|
|
||
|
// has it been destroyed
|
||
|
this.destroyed = false;
|
||
|
|
||
|
// should we decode strings into buffers before passing to _write?
|
||
|
// this is here so that some node-core streams can optimize string
|
||
|
// handling at a lower level.
|
||
|
var noDecode = options.decodeStrings === false;
|
||
|
this.decodeStrings = !noDecode;
|
||
|
|
||
|
// Crypto is kind of old and crusty. Historically, its default string
|
||
|
// encoding is 'binary' so we have to make this configurable.
|
||
|
// Everything else in the universe uses 'utf8', though.
|
||
|
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||
|
|
||
|
// not an actual buffer we keep track of, but a measurement
|
||
|
// of how much we're waiting to get pushed to some underlying
|
||
|
// socket or file.
|
||
|
this.length = 0;
|
||
|
|
||
|
// a flag to see when we're in the middle of a write.
|
||
|
this.writing = false;
|
||
|
|
||
|
// when true all writes will be buffered until .uncork() call
|
||
|
this.corked = 0;
|
||
|
|
||
|
// a flag to be able to tell if the onwrite cb is called immediately,
|
||
|
// or on a later tick. We set this to true at first, because any
|
||
|
// actions that shouldn't happen until "later" should generally also
|
||
|
// not happen before the first write call.
|
||
|
this.sync = true;
|
||
|
|
||
|
// a flag to know if we're processing previously buffered items, which
|
||
|
// may call the _write() callback in the same tick, so that we don't
|
||
|
// end up in an overlapped onwrite situation.
|
||
|
this.bufferProcessing = false;
|
||
|
|
||
|
// the callback that's passed to _write(chunk,cb)
|
||
|
this.onwrite = function (er) {
|
||
|
onwrite(stream, er);
|
||
|
};
|
||
|
|
||
|
// the callback that the user supplies to write(chunk,encoding,cb)
|
||
|
this.writecb = null;
|
||
|
|
||
|
// the amount that is being written when _write is called.
|
||
|
this.writelen = 0;
|
||
|
|
||
|
this.bufferedRequest = null;
|
||
|
this.lastBufferedRequest = null;
|
||
|
|
||
|
// number of pending user-supplied write callbacks
|
||
|
// this must be 0 before 'finish' can be emitted
|
||
|
this.pendingcb = 0;
|
||
|
|
||
|
// emit prefinish if the only thing we're waiting for is _write cbs
|
||
|
// This is relevant for synchronous Transform streams
|
||
|
this.prefinished = false;
|
||
|
|
||
|
// True if the error was already emitted and should not be thrown again
|
||
|
this.errorEmitted = false;
|
||
|
|
||
|
// count buffered requests
|
||
|
this.bufferedRequestCount = 0;
|
||
|
|
||
|
// allocate the first CorkedRequest, there is always
|
||
|
// one allocated and free to use, and we maintain at most two
|
||
|
this.corkedRequestsFree = new CorkedRequest(this);
|
||
|
}
|
||
|
|
||
|
WritableState.prototype.getBuffer = function getBuffer() {
|
||
|
var current = this.bufferedRequest;
|
||
|
var out = [];
|
||
|
while (current) {
|
||
|
out.push(current);
|
||
|
current = current.next;
|
||
|
}
|
||
|
return out;
|
||
|
};
|
||
|
|
||
|
(function () {
|
||
|
try {
|
||
|
Object.defineProperty(WritableState.prototype, 'buffer', {
|
||
|
get: internalUtil.deprecate(function () {
|
||
|
return this.getBuffer();
|
||
|
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
||
|
});
|
||
|
} catch (_) {}
|
||
|
})();
|
||
|
|
||
|
// Test _writableState for inheritance to account for Duplex streams,
|
||
|
// whose prototype chain only points to Readable.
|
||
|
var realHasInstance;
|
||
|
if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
||
|
realHasInstance = Function.prototype[Symbol.hasInstance];
|
||
|
Object.defineProperty(Writable, Symbol.hasInstance, {
|
||
|
value: function (object) {
|
||
|
if (realHasInstance.call(this, object)) return true;
|
||
|
if (this !== Writable) return false;
|
||
|
|
||
|
return object && object._writableState instanceof WritableState;
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
realHasInstance = function (object) {
|
||
|
return object instanceof this;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
function Writable(options) {
|
||
|
Duplex = Duplex || require('./_stream_duplex');
|
||
|
|
||
|
// Writable ctor is applied to Duplexes, too.
|
||
|
// `realHasInstance` is necessary because using plain `instanceof`
|
||
|
// would return false, as no `_writableState` property is attached.
|
||
|
|
||
|
// Trying to use the custom `instanceof` for Writable here will also break the
|
||
|
// Node.js LazyTransform implementation, which has a non-trivial getter for
|
||
|
// `_writableState` that would lead to infinite recursion.
|
||
|
if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
|
||
|
return new Writable(options);
|
||
|
}
|
||
|
|
||
|
this._writableState = new WritableState(options, this);
|
||
|
|
||
|
// legacy.
|
||
|
this.writable = true;
|
||
|
|
||
|
if (options) {
|
||
|
if (typeof options.write === 'function') this._write = options.write;
|
||
|
|
||
|
if (typeof options.writev === 'function') this._writev = options.writev;
|
||
|
|
||
|
if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
||
|
|
||
|
if (typeof options.final === 'function') this._final = options.final;
|
||
|
}
|
||
|
|
||
|
Stream.call(this);
|
||
|
}
|
||
|
|
||
|
// Otherwise people can pipe Writable streams, which is just wrong.
|
||
|
Writable.prototype.pipe = function () {
|
||
|
this.emit('error', new Error('Cannot pipe, not readable'));
|
||
|
};
|
||
|
|
||
|
function writeAfterEnd(stream, cb) {
|
||
|
var er = new Error('write after end');
|
||
|
// TODO: defer error events consistently everywhere, not just the cb
|
||
|
stream.emit('error', er);
|
||
|
pna.nextTick(cb, er);
|
||
|
}
|
||
|
|
||
|
// Checks that a user-supplied chunk is valid, especially for the particular
|
||
|
// mode the stream is in. Currently this means that `null` is never accepted
|
||
|
// and undefined/non-string values are only allowed in object mode.
|
||
|
function validChunk(stream, state, chunk, cb) {
|
||
|
var valid = true;
|
||
|
var er = false;
|
||
|
|
||
|
if (chunk === null) {
|
||
|
er = new TypeError('May not write null values to stream');
|
||
|
} else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
||
|
er = new TypeError('Invalid non-string/buffer chunk');
|
||
|
}
|
||
|
if (er) {
|
||
|
stream.emit('error', er);
|
||
|
pna.nextTick(cb, er);
|
||
|
valid = false;
|
||
|
}
|
||
|
return valid;
|
||
|
}
|
||
|
|
||
|
Writable.prototype.write = function (chunk, encoding, cb) {
|
||
|
var state = this._writableState;
|
||
|
var ret = false;
|
||
|
var isBuf = !state.objectMode && _isUint8Array(chunk);
|
||
|
|
||
|
if (isBuf && !Buffer.isBuffer(chunk)) {
|
||
|
chunk = _uint8ArrayToBuffer(chunk);
|
||
|
}
|
||
|
|
||
|
if (typeof encoding === 'function') {
|
||
|
cb = encoding;
|
||
|
encoding = null;
|
||
|
}
|
||
|
|
||
|
if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
||
|
|
||
|
if (typeof cb !== 'function') cb = nop;
|
||
|
|
||
|
if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
||
|
state.pendingcb++;
|
||
|
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
Writable.prototype.cork = function () {
|
||
|
var state = this._writableState;
|
||
|
|
||
|
state.corked++;
|
||
|
};
|
||
|
|
||
|
Writable.prototype.uncork = function () {
|
||
|
var state = this._writableState;
|
||
|
|
||
|
if (state.corked) {
|
||
|
state.corked--;
|
||
|
|
||
|
if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
||
|
// node::ParseEncoding() requires lower case.
|
||
|
if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
||
|
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
|
||
|
this._writableState.defaultEncoding = encoding;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
function decodeChunk(state, chunk, encoding) {
|
||
|
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
||
|
chunk = Buffer.from(chunk, encoding);
|
||
|
}
|
||
|
return chunk;
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
||
|
// making it explicit this property is not enumerable
|
||
|
// because otherwise some prototype manipulation in
|
||
|
// userland will fail
|
||
|
enumerable: false,
|
||
|
get: function () {
|
||
|
return this._writableState.highWaterMark;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// if we're already writing something, then just put this
|
||
|
// in the queue, and wait our turn. Otherwise, call _write
|
||
|
// If we return false, then we need a drain event, so set that flag.
|
||
|
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
||
|
if (!isBuf) {
|
||
|
var newChunk = decodeChunk(state, chunk, encoding);
|
||
|
if (chunk !== newChunk) {
|
||
|
isBuf = true;
|
||
|
encoding = 'buffer';
|
||
|
chunk = newChunk;
|
||
|
}
|
||
|
}
|
||
|
var len = state.objectMode ? 1 : chunk.length;
|
||
|
|
||
|
state.length += len;
|
||
|
|
||
|
var ret = state.length < state.highWaterMark;
|
||
|
// we must ensure that previous needDrain will not be reset to false.
|
||
|
if (!ret) state.needDrain = true;
|
||
|
|
||
|
if (state.writing || state.corked) {
|
||
|
var last = state.lastBufferedRequest;
|
||
|
state.lastBufferedRequest = {
|
||
|
chunk: chunk,
|
||
|
encoding: encoding,
|
||
|
isBuf: isBuf,
|
||
|
callback: cb,
|
||
|
next: null
|
||
|
};
|
||
|
if (last) {
|
||
|
last.next = state.lastBufferedRequest;
|
||
|
} else {
|
||
|
state.bufferedRequest = state.lastBufferedRequest;
|
||
|
}
|
||
|
state.bufferedRequestCount += 1;
|
||
|
} else {
|
||
|
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
||
|
state.writelen = len;
|
||
|
state.writecb = cb;
|
||
|
state.writing = true;
|
||
|
state.sync = true;
|
||
|
if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
||
|
state.sync = false;
|
||
|
}
|
||
|
|
||
|
function onwriteError(stream, state, sync, er, cb) {
|
||
|
--state.pendingcb;
|
||
|
|
||
|
if (sync) {
|
||
|
// defer the callback if we are being called synchronously
|
||
|
// to avoid piling up things on the stack
|
||
|
pna.nextTick(cb, er);
|
||
|
// this can emit finish, and it will always happen
|
||
|
// after error
|
||
|
pna.nextTick(finishMaybe, stream, state);
|
||
|
stream._writableState.errorEmitted = true;
|
||
|
stream.emit('error', er);
|
||
|
} else {
|
||
|
// the caller expect this to happen before if
|
||
|
// it is async
|
||
|
cb(er);
|
||
|
stream._writableState.errorEmitted = true;
|
||
|
stream.emit('error', er);
|
||
|
// this can emit finish, but finish must
|
||
|
// always follow error
|
||
|
finishMaybe(stream, state);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function onwriteStateUpdate(state) {
|
||
|
state.writing = false;
|
||
|
state.writecb = null;
|
||
|
state.length -= state.writelen;
|
||
|
state.writelen = 0;
|
||
|
}
|
||
|
|
||
|
function onwrite(stream, er) {
|
||
|
var state = stream._writableState;
|
||
|
var sync = state.sync;
|
||
|
var cb = state.writecb;
|
||
|
|
||
|
onwriteStateUpdate(state);
|
||
|
|
||
|
if (er) onwriteError(stream, state, sync, er, cb);else {
|
||
|
// Check if we're actually ready to finish, but don't emit yet
|
||
|
var finished = needFinish(state);
|
||
|
|
||
|
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
||
|
clearBuffer(stream, state);
|
||
|
}
|
||
|
|
||
|
if (sync) {
|
||
|
/*<replacement>*/
|
||
|
asyncWrite(afterWrite, stream, state, finished, cb);
|
||
|
/*</replacement>*/
|
||
|
} else {
|
||
|
afterWrite(stream, state, finished, cb);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function afterWrite(stream, state, finished, cb) {
|
||
|
if (!finished) onwriteDrain(stream, state);
|
||
|
state.pendingcb--;
|
||
|
cb();
|
||
|
finishMaybe(stream, state);
|
||
|
}
|
||
|
|
||
|
// Must force callback to be called on nextTick, so that we don't
|
||
|
// emit 'drain' before the write() consumer gets the 'false' return
|
||
|
// value, and has a chance to attach a 'drain' listener.
|
||
|
function onwriteDrain(stream, state) {
|
||
|
if (state.length === 0 && state.needDrain) {
|
||
|
state.needDrain = false;
|
||
|
stream.emit('drain');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// if there's something in the buffer waiting, then process it
|
||
|
function clearBuffer(stream, state) {
|
||
|
state.bufferProcessing = true;
|
||
|
var entry = state.bufferedRequest;
|
||
|
|
||
|
if (stream._writev && entry && entry.next) {
|
||
|
// Fast case, write everything using _writev()
|
||
|
var l = state.bufferedRequestCount;
|
||
|
var buffer = new Array(l);
|
||
|
var holder = state.corkedRequestsFree;
|
||
|
holder.entry = entry;
|
||
|
|
||
|
var count = 0;
|
||
|
var allBuffers = true;
|
||
|
while (entry) {
|
||
|
buffer[count] = entry;
|
||
|
if (!entry.isBuf) allBuffers = false;
|
||
|
entry = entry.next;
|
||
|
count += 1;
|
||
|
}
|
||
|
buffer.allBuffers = allBuffers;
|
||
|
|
||
|
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
||
|
|
||
|
// doWrite is almost always async, defer these to save a bit of time
|
||
|
// as the hot path ends with doWrite
|
||
|
state.pendingcb++;
|
||
|
state.lastBufferedRequest = null;
|
||
|
if (holder.next) {
|
||
|
state.corkedRequestsFree = holder.next;
|
||
|
holder.next = null;
|
||
|
} else {
|
||
|
state.corkedRequestsFree = new CorkedRequest(state);
|
||
|
}
|
||
|
state.bufferedRequestCount = 0;
|
||
|
} else {
|
||
|
// Slow case, write chunks one-by-one
|
||
|
while (entry) {
|
||
|
var chunk = entry.chunk;
|
||
|
var encoding = entry.encoding;
|
||
|
var cb = entry.callback;
|
||
|
var len = state.objectMode ? 1 : chunk.length;
|
||
|
|
||
|
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||
|
entry = entry.next;
|
||
|
state.bufferedRequestCount--;
|
||
|
// if we didn't call the onwrite immediately, then
|
||
|
// it means that we need to wait until it does.
|
||
|
// also, that means that the chunk and cb are currently
|
||
|
// being processed, so move the buffer counter past them.
|
||
|
if (state.writing) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (entry === null) state.lastBufferedRequest = null;
|
||
|
}
|
||
|
|
||
|
state.bufferedRequest = entry;
|
||
|
state.bufferProcessing = false;
|
||
|
}
|
||
|
|
||
|
Writable.prototype._write = function (chunk, encoding, cb) {
|
||
|
cb(new Error('_write() is not implemented'));
|
||
|
};
|
||
|
|
||
|
Writable.prototype._writev = null;
|
||
|
|
||
|
Writable.prototype.end = function (chunk, encoding, cb) {
|
||
|
var state = this._writableState;
|
||
|
|
||
|
if (typeof chunk === 'function') {
|
||
|
cb = chunk;
|
||
|
chunk = null;
|
||
|
encoding = null;
|
||
|
} else if (typeof encoding === 'function') {
|
||
|
cb = encoding;
|
||
|
encoding = null;
|
||
|
}
|
||
|
|
||
|
if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
||
|
|
||
|
// .end() fully uncorks
|
||
|
if (state.corked) {
|
||
|
state.corked = 1;
|
||
|
this.uncork();
|
||
|
}
|
||
|
|
||
|
// ignore unnecessary end() calls.
|
||
|
if (!state.ending && !state.finished) endWritable(this, state, cb);
|
||
|
};
|
||
|
|
||
|
function needFinish(state) {
|
||
|
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
||
|
}
|
||
|
function callFinal(stream, state) {
|
||
|
stream._final(function (err) {
|
||
|
state.pendingcb--;
|
||
|
if (err) {
|
||
|
stream.emit('error', err);
|
||
|
}
|
||
|
state.prefinished = true;
|
||
|
stream.emit('prefinish');
|
||
|
finishMaybe(stream, state);
|
||
|
});
|
||
|
}
|
||
|
function prefinish(stream, state) {
|
||
|
if (!state.prefinished && !state.finalCalled) {
|
||
|
if (typeof stream._final === 'function') {
|
||
|
state.pendingcb++;
|
||
|
state.finalCalled = true;
|
||
|
pna.nextTick(callFinal, stream, state);
|
||
|
} else {
|
||
|
state.prefinished = true;
|
||
|
stream.emit('prefinish');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function finishMaybe(stream, state) {
|
||
|
var need = needFinish(state);
|
||
|
if (need) {
|
||
|
prefinish(stream, state);
|
||
|
if (state.pendingcb === 0) {
|
||
|
state.finished = true;
|
||
|
stream.emit('finish');
|
||
|
}
|
||
|
}
|
||
|
return need;
|
||
|
}
|
||
|
|
||
|
function endWritable(stream, state, cb) {
|
||
|
state.ending = true;
|
||
|
finishMaybe(stream, state);
|
||
|
if (cb) {
|
||
|
if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
|
||
|
}
|
||
|
state.ended = true;
|
||
|
stream.writable = false;
|
||
|
}
|
||
|
|
||
|
function onCorkedFinish(corkReq, state, err) {
|
||
|
var entry = corkReq.entry;
|
||
|
corkReq.entry = null;
|
||
|
while (entry) {
|
||
|
var cb = entry.callback;
|
||
|
state.pendingcb--;
|
||
|
cb(err);
|
||
|
entry = entry.next;
|
||
|
}
|
||
|
if (state.corkedRequestsFree) {
|
||
|
state.corkedRequestsFree.next = corkReq;
|
||
|
} else {
|
||
|
state.corkedRequestsFree = corkReq;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(Writable.prototype, 'destroyed', {
|
||
|
get: function () {
|
||
|
if (this._writableState === undefined) {
|
||
|
return false;
|
||
|
}
|
||
|
return this._writableState.destroyed;
|
||
|
},
|
||
|
set: function (value) {
|
||
|
// we ignore the value if the stream
|
||
|
// has not been initialized yet
|
||
|
if (!this._writableState) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// backward compatibility, the user is explicitly
|
||
|
// managing destroyed
|
||
|
this._writableState.destroyed = value;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Writable.prototype.destroy = destroyImpl.destroy;
|
||
|
Writable.prototype._undestroy = destroyImpl.undestroy;
|
||
|
Writable.prototype._destroy = function (err, cb) {
|
||
|
this.end();
|
||
|
cb(err);
|
||
|
};
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"./_stream_duplex":58,"./internal/streams/destroy":64,"./internal/streams/stream":65,"_process":56,"core-util-is":42,"inherits":50,"process-nextick-args":55,"safe-buffer":70,"util-deprecate":73}],63:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||
|
|
||
|
var Buffer = require('safe-buffer').Buffer;
|
||
|
var util = require('util');
|
||
|
|
||
|
function copyBuffer(src, target, offset) {
|
||
|
src.copy(target, offset);
|
||
|
}
|
||
|
|
||
|
module.exports = function () {
|
||
|
function BufferList() {
|
||
|
_classCallCheck(this, BufferList);
|
||
|
|
||
|
this.head = null;
|
||
|
this.tail = null;
|
||
|
this.length = 0;
|
||
|
}
|
||
|
|
||
|
BufferList.prototype.push = function push(v) {
|
||
|
var entry = { data: v, next: null };
|
||
|
if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
||
|
this.tail = entry;
|
||
|
++this.length;
|
||
|
};
|
||
|
|
||
|
BufferList.prototype.unshift = function unshift(v) {
|
||
|
var entry = { data: v, next: this.head };
|
||
|
if (this.length === 0) this.tail = entry;
|
||
|
this.head = entry;
|
||
|
++this.length;
|
||
|
};
|
||
|
|
||
|
BufferList.prototype.shift = function shift() {
|
||
|
if (this.length === 0) return;
|
||
|
var ret = this.head.data;
|
||
|
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
||
|
--this.length;
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
BufferList.prototype.clear = function clear() {
|
||
|
this.head = this.tail = null;
|
||
|
this.length = 0;
|
||
|
};
|
||
|
|
||
|
BufferList.prototype.join = function join(s) {
|
||
|
if (this.length === 0) return '';
|
||
|
var p = this.head;
|
||
|
var ret = '' + p.data;
|
||
|
while (p = p.next) {
|
||
|
ret += s + p.data;
|
||
|
}return ret;
|
||
|
};
|
||
|
|
||
|
BufferList.prototype.concat = function concat(n) {
|
||
|
if (this.length === 0) return Buffer.alloc(0);
|
||
|
if (this.length === 1) return this.head.data;
|
||
|
var ret = Buffer.allocUnsafe(n >>> 0);
|
||
|
var p = this.head;
|
||
|
var i = 0;
|
||
|
while (p) {
|
||
|
copyBuffer(p.data, ret, i);
|
||
|
i += p.data.length;
|
||
|
p = p.next;
|
||
|
}
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
return BufferList;
|
||
|
}();
|
||
|
|
||
|
if (util && util.inspect && util.inspect.custom) {
|
||
|
module.exports.prototype[util.inspect.custom] = function () {
|
||
|
var obj = util.inspect({ length: this.length });
|
||
|
return this.constructor.name + ' ' + obj;
|
||
|
};
|
||
|
}
|
||
|
},{"safe-buffer":70,"util":38}],64:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var pna = require('process-nextick-args');
|
||
|
/*</replacement>*/
|
||
|
|
||
|
// undocumented cb() API, needed for core, not for public API
|
||
|
function destroy(err, cb) {
|
||
|
var _this = this;
|
||
|
|
||
|
var readableDestroyed = this._readableState && this._readableState.destroyed;
|
||
|
var writableDestroyed = this._writableState && this._writableState.destroyed;
|
||
|
|
||
|
if (readableDestroyed || writableDestroyed) {
|
||
|
if (cb) {
|
||
|
cb(err);
|
||
|
} else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
|
||
|
pna.nextTick(emitErrorNT, this, err);
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
// we set destroyed to true before firing error callbacks in order
|
||
|
// to make it re-entrance safe in case destroy() is called within callbacks
|
||
|
|
||
|
if (this._readableState) {
|
||
|
this._readableState.destroyed = true;
|
||
|
}
|
||
|
|
||
|
// if this is a duplex stream mark the writable part as destroyed as well
|
||
|
if (this._writableState) {
|
||
|
this._writableState.destroyed = true;
|
||
|
}
|
||
|
|
||
|
this._destroy(err || null, function (err) {
|
||
|
if (!cb && err) {
|
||
|
pna.nextTick(emitErrorNT, _this, err);
|
||
|
if (_this._writableState) {
|
||
|
_this._writableState.errorEmitted = true;
|
||
|
}
|
||
|
} else if (cb) {
|
||
|
cb(err);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
function undestroy() {
|
||
|
if (this._readableState) {
|
||
|
this._readableState.destroyed = false;
|
||
|
this._readableState.reading = false;
|
||
|
this._readableState.ended = false;
|
||
|
this._readableState.endEmitted = false;
|
||
|
}
|
||
|
|
||
|
if (this._writableState) {
|
||
|
this._writableState.destroyed = false;
|
||
|
this._writableState.ended = false;
|
||
|
this._writableState.ending = false;
|
||
|
this._writableState.finished = false;
|
||
|
this._writableState.errorEmitted = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function emitErrorNT(self, err) {
|
||
|
self.emit('error', err);
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
destroy: destroy,
|
||
|
undestroy: undestroy
|
||
|
};
|
||
|
},{"process-nextick-args":55}],65:[function(require,module,exports){
|
||
|
module.exports = require('events').EventEmitter;
|
||
|
|
||
|
},{"events":47}],66:[function(require,module,exports){
|
||
|
module.exports = require('./readable').PassThrough
|
||
|
|
||
|
},{"./readable":67}],67:[function(require,module,exports){
|
||
|
exports = module.exports = require('./lib/_stream_readable.js');
|
||
|
exports.Stream = exports;
|
||
|
exports.Readable = exports;
|
||
|
exports.Writable = require('./lib/_stream_writable.js');
|
||
|
exports.Duplex = require('./lib/_stream_duplex.js');
|
||
|
exports.Transform = require('./lib/_stream_transform.js');
|
||
|
exports.PassThrough = require('./lib/_stream_passthrough.js');
|
||
|
|
||
|
},{"./lib/_stream_duplex.js":58,"./lib/_stream_passthrough.js":59,"./lib/_stream_readable.js":60,"./lib/_stream_transform.js":61,"./lib/_stream_writable.js":62}],68:[function(require,module,exports){
|
||
|
module.exports = require('./readable').Transform
|
||
|
|
||
|
},{"./readable":67}],69:[function(require,module,exports){
|
||
|
module.exports = require('./lib/_stream_writable.js');
|
||
|
|
||
|
},{"./lib/_stream_writable.js":62}],70:[function(require,module,exports){
|
||
|
/* eslint-disable node/no-deprecated-api */
|
||
|
var buffer = require('buffer')
|
||
|
var Buffer = buffer.Buffer
|
||
|
|
||
|
// alternative to using Object.keys for old browsers
|
||
|
function copyProps (src, dst) {
|
||
|
for (var key in src) {
|
||
|
dst[key] = src[key]
|
||
|
}
|
||
|
}
|
||
|
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
||
|
module.exports = buffer
|
||
|
} else {
|
||
|
// Copy properties from require('buffer')
|
||
|
copyProps(buffer, exports)
|
||
|
exports.Buffer = SafeBuffer
|
||
|
}
|
||
|
|
||
|
function SafeBuffer (arg, encodingOrOffset, length) {
|
||
|
return Buffer(arg, encodingOrOffset, length)
|
||
|
}
|
||
|
|
||
|
// Copy static methods from Buffer
|
||
|
copyProps(Buffer, SafeBuffer)
|
||
|
|
||
|
SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
||
|
if (typeof arg === 'number') {
|
||
|
throw new TypeError('Argument must not be a number')
|
||
|
}
|
||
|
return Buffer(arg, encodingOrOffset, length)
|
||
|
}
|
||
|
|
||
|
SafeBuffer.alloc = function (size, fill, encoding) {
|
||
|
if (typeof size !== 'number') {
|
||
|
throw new TypeError('Argument must be a number')
|
||
|
}
|
||
|
var buf = Buffer(size)
|
||
|
if (fill !== undefined) {
|
||
|
if (typeof encoding === 'string') {
|
||
|
buf.fill(fill, encoding)
|
||
|
} else {
|
||
|
buf.fill(fill)
|
||
|
}
|
||
|
} else {
|
||
|
buf.fill(0)
|
||
|
}
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
SafeBuffer.allocUnsafe = function (size) {
|
||
|
if (typeof size !== 'number') {
|
||
|
throw new TypeError('Argument must be a number')
|
||
|
}
|
||
|
return Buffer(size)
|
||
|
}
|
||
|
|
||
|
SafeBuffer.allocUnsafeSlow = function (size) {
|
||
|
if (typeof size !== 'number') {
|
||
|
throw new TypeError('Argument must be a number')
|
||
|
}
|
||
|
return buffer.SlowBuffer(size)
|
||
|
}
|
||
|
|
||
|
},{"buffer":41}],71:[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.
|
||
|
|
||
|
module.exports = Stream;
|
||
|
|
||
|
var EE = require('events').EventEmitter;
|
||
|
var inherits = require('inherits');
|
||
|
|
||
|
inherits(Stream, EE);
|
||
|
Stream.Readable = require('readable-stream/readable.js');
|
||
|
Stream.Writable = require('readable-stream/writable.js');
|
||
|
Stream.Duplex = require('readable-stream/duplex.js');
|
||
|
Stream.Transform = require('readable-stream/transform.js');
|
||
|
Stream.PassThrough = require('readable-stream/passthrough.js');
|
||
|
|
||
|
// Backwards-compat with node 0.4.x
|
||
|
Stream.Stream = Stream;
|
||
|
|
||
|
|
||
|
|
||
|
// old-style streams. Note that the pipe method (the only relevant
|
||
|
// part of this class) is overridden in the Readable class.
|
||
|
|
||
|
function Stream() {
|
||
|
EE.call(this);
|
||
|
}
|
||
|
|
||
|
Stream.prototype.pipe = function(dest, options) {
|
||
|
var source = this;
|
||
|
|
||
|
function ondata(chunk) {
|
||
|
if (dest.writable) {
|
||
|
if (false === dest.write(chunk) && source.pause) {
|
||
|
source.pause();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
source.on('data', ondata);
|
||
|
|
||
|
function ondrain() {
|
||
|
if (source.readable && source.resume) {
|
||
|
source.resume();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
dest.on('drain', ondrain);
|
||
|
|
||
|
// If the 'end' option is not supplied, dest.end() will be called when
|
||
|
// source gets the 'end' or 'close' events. Only dest.end() once.
|
||
|
if (!dest._isStdio && (!options || options.end !== false)) {
|
||
|
source.on('end', onend);
|
||
|
source.on('close', onclose);
|
||
|
}
|
||
|
|
||
|
var didOnEnd = false;
|
||
|
function onend() {
|
||
|
if (didOnEnd) return;
|
||
|
didOnEnd = true;
|
||
|
|
||
|
dest.end();
|
||
|
}
|
||
|
|
||
|
|
||
|
function onclose() {
|
||
|
if (didOnEnd) return;
|
||
|
didOnEnd = true;
|
||
|
|
||
|
if (typeof dest.destroy === 'function') dest.destroy();
|
||
|
}
|
||
|
|
||
|
// don't leave dangling pipes when there are errors.
|
||
|
function onerror(er) {
|
||
|
cleanup();
|
||
|
if (EE.listenerCount(this, 'error') === 0) {
|
||
|
throw er; // Unhandled stream error in pipe.
|
||
|
}
|
||
|
}
|
||
|
|
||
|
source.on('error', onerror);
|
||
|
dest.on('error', onerror);
|
||
|
|
||
|
// remove all the event listeners that were added.
|
||
|
function cleanup() {
|
||
|
source.removeListener('data', ondata);
|
||
|
dest.removeListener('drain', ondrain);
|
||
|
|
||
|
source.removeListener('end', onend);
|
||
|
source.removeListener('close', onclose);
|
||
|
|
||
|
source.removeListener('error', onerror);
|
||
|
dest.removeListener('error', onerror);
|
||
|
|
||
|
source.removeListener('end', cleanup);
|
||
|
source.removeListener('close', cleanup);
|
||
|
|
||
|
dest.removeListener('close', cleanup);
|
||
|
}
|
||
|
|
||
|
source.on('end', cleanup);
|
||
|
source.on('close', cleanup);
|
||
|
|
||
|
dest.on('close', cleanup);
|
||
|
|
||
|
dest.emit('pipe', source);
|
||
|
|
||
|
// Allow for unix-like usage: A.pipe(B).pipe(C)
|
||
|
return dest;
|
||
|
};
|
||
|
|
||
|
},{"events":47,"inherits":50,"readable-stream/duplex.js":57,"readable-stream/passthrough.js":66,"readable-stream/readable.js":67,"readable-stream/transform.js":68,"readable-stream/writable.js":69}],72:[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.
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
/*<replacement>*/
|
||
|
|
||
|
var Buffer = require('safe-buffer').Buffer;
|
||
|
/*</replacement>*/
|
||
|
|
||
|
var isEncoding = Buffer.isEncoding || function (encoding) {
|
||
|
encoding = '' + encoding;
|
||
|
switch (encoding && encoding.toLowerCase()) {
|
||
|
case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
|
||
|
return true;
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
function _normalizeEncoding(enc) {
|
||
|
if (!enc) return 'utf8';
|
||
|
var retried;
|
||
|
while (true) {
|
||
|
switch (enc) {
|
||
|
case 'utf8':
|
||
|
case 'utf-8':
|
||
|
return 'utf8';
|
||
|
case 'ucs2':
|
||
|
case 'ucs-2':
|
||
|
case 'utf16le':
|
||
|
case 'utf-16le':
|
||
|
return 'utf16le';
|
||
|
case 'latin1':
|
||
|
case 'binary':
|
||
|
return 'latin1';
|
||
|
case 'base64':
|
||
|
case 'ascii':
|
||
|
case 'hex':
|
||
|
return enc;
|
||
|
default:
|
||
|
if (retried) return; // undefined
|
||
|
enc = ('' + enc).toLowerCase();
|
||
|
retried = true;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Do not cache `Buffer.isEncoding` when checking encoding names as some
|
||
|
// modules monkey-patch it to support additional encodings
|
||
|
function normalizeEncoding(enc) {
|
||
|
var nenc = _normalizeEncoding(enc);
|
||
|
if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
||
|
return nenc || enc;
|
||
|
}
|
||
|
|
||
|
// StringDecoder provides an interface for efficiently splitting a series of
|
||
|
// buffers into a series of JS strings without breaking apart multi-byte
|
||
|
// characters.
|
||
|
exports.StringDecoder = StringDecoder;
|
||
|
function StringDecoder(encoding) {
|
||
|
this.encoding = normalizeEncoding(encoding);
|
||
|
var nb;
|
||
|
switch (this.encoding) {
|
||
|
case 'utf16le':
|
||
|
this.text = utf16Text;
|
||
|
this.end = utf16End;
|
||
|
nb = 4;
|
||
|
break;
|
||
|
case 'utf8':
|
||
|
this.fillLast = utf8FillLast;
|
||
|
nb = 4;
|
||
|
break;
|
||
|
case 'base64':
|
||
|
this.text = base64Text;
|
||
|
this.end = base64End;
|
||
|
nb = 3;
|
||
|
break;
|
||
|
default:
|
||
|
this.write = simpleWrite;
|
||
|
this.end = simpleEnd;
|
||
|
return;
|
||
|
}
|
||
|
this.lastNeed = 0;
|
||
|
this.lastTotal = 0;
|
||
|
this.lastChar = Buffer.allocUnsafe(nb);
|
||
|
}
|
||
|
|
||
|
StringDecoder.prototype.write = function (buf) {
|
||
|
if (buf.length === 0) return '';
|
||
|
var r;
|
||
|
var i;
|
||
|
if (this.lastNeed) {
|
||
|
r = this.fillLast(buf);
|
||
|
if (r === undefined) return '';
|
||
|
i = this.lastNeed;
|
||
|
this.lastNeed = 0;
|
||
|
} else {
|
||
|
i = 0;
|
||
|
}
|
||
|
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
||
|
return r || '';
|
||
|
};
|
||
|
|
||
|
StringDecoder.prototype.end = utf8End;
|
||
|
|
||
|
// Returns only complete characters in a Buffer
|
||
|
StringDecoder.prototype.text = utf8Text;
|
||
|
|
||
|
// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
|
||
|
StringDecoder.prototype.fillLast = function (buf) {
|
||
|
if (this.lastNeed <= buf.length) {
|
||
|
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
||
|
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
||
|
}
|
||
|
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
||
|
this.lastNeed -= buf.length;
|
||
|
};
|
||
|
|
||
|
// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
|
||
|
// continuation byte. If an invalid byte is detected, -2 is returned.
|
||
|
function utf8CheckByte(byte) {
|
||
|
if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
|
||
|
return byte >> 6 === 0x02 ? -1 : -2;
|
||
|
}
|
||
|
|
||
|
// Checks at most 3 bytes at the end of a Buffer in order to detect an
|
||
|
// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
|
||
|
// needed to complete the UTF-8 character (if applicable) are returned.
|
||
|
function utf8CheckIncomplete(self, buf, i) {
|
||
|
var j = buf.length - 1;
|
||
|
if (j < i) return 0;
|
||
|
var nb = utf8CheckByte(buf[j]);
|
||
|
if (nb >= 0) {
|
||
|
if (nb > 0) self.lastNeed = nb - 1;
|
||
|
return nb;
|
||
|
}
|
||
|
if (--j < i || nb === -2) return 0;
|
||
|
nb = utf8CheckByte(buf[j]);
|
||
|
if (nb >= 0) {
|
||
|
if (nb > 0) self.lastNeed = nb - 2;
|
||
|
return nb;
|
||
|
}
|
||
|
if (--j < i || nb === -2) return 0;
|
||
|
nb = utf8CheckByte(buf[j]);
|
||
|
if (nb >= 0) {
|
||
|
if (nb > 0) {
|
||
|
if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
||
|
}
|
||
|
return nb;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
// Validates as many continuation bytes for a multi-byte UTF-8 character as
|
||
|
// needed or are available. If we see a non-continuation byte where we expect
|
||
|
// one, we "replace" the validated continuation bytes we've seen so far with
|
||
|
// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
|
||
|
// behavior. The continuation byte check is included three times in the case
|
||
|
// where all of the continuation bytes for a character exist in the same buffer.
|
||
|
// It is also done this way as a slight performance increase instead of using a
|
||
|
// loop.
|
||
|
function utf8CheckExtraBytes(self, buf, p) {
|
||
|
if ((buf[0] & 0xC0) !== 0x80) {
|
||
|
self.lastNeed = 0;
|
||
|
return '\ufffd';
|
||
|
}
|
||
|
if (self.lastNeed > 1 && buf.length > 1) {
|
||
|
if ((buf[1] & 0xC0) !== 0x80) {
|
||
|
self.lastNeed = 1;
|
||
|
return '\ufffd';
|
||
|
}
|
||
|
if (self.lastNeed > 2 && buf.length > 2) {
|
||
|
if ((buf[2] & 0xC0) !== 0x80) {
|
||
|
self.lastNeed = 2;
|
||
|
return '\ufffd';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
|
||
|
function utf8FillLast(buf) {
|
||
|
var p = this.lastTotal - this.lastNeed;
|
||
|
var r = utf8CheckExtraBytes(this, buf, p);
|
||
|
if (r !== undefined) return r;
|
||
|
if (this.lastNeed <= buf.length) {
|
||
|
buf.copy(this.lastChar, p, 0, this.lastNeed);
|
||
|
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
||
|
}
|
||
|
buf.copy(this.lastChar, p, 0, buf.length);
|
||
|
this.lastNeed -= buf.length;
|
||
|
}
|
||
|
|
||
|
// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
|
||
|
// partial character, the character's bytes are buffered until the required
|
||
|
// number of bytes are available.
|
||
|
function utf8Text(buf, i) {
|
||
|
var total = utf8CheckIncomplete(this, buf, i);
|
||
|
if (!this.lastNeed) return buf.toString('utf8', i);
|
||
|
this.lastTotal = total;
|
||
|
var end = buf.length - (total - this.lastNeed);
|
||
|
buf.copy(this.lastChar, 0, end);
|
||
|
return buf.toString('utf8', i, end);
|
||
|
}
|
||
|
|
||
|
// For UTF-8, a replacement character is added when ending on a partial
|
||
|
// character.
|
||
|
function utf8End(buf) {
|
||
|
var r = buf && buf.length ? this.write(buf) : '';
|
||
|
if (this.lastNeed) return r + '\ufffd';
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
// UTF-16LE typically needs two bytes per character, but even if we have an even
|
||
|
// number of bytes available, we need to check if we end on a leading/high
|
||
|
// surrogate. In that case, we need to wait for the next two bytes in order to
|
||
|
// decode the last character properly.
|
||
|
function utf16Text(buf, i) {
|
||
|
if ((buf.length - i) % 2 === 0) {
|
||
|
var r = buf.toString('utf16le', i);
|
||
|
if (r) {
|
||
|
var c = r.charCodeAt(r.length - 1);
|
||
|
if (c >= 0xD800 && c <= 0xDBFF) {
|
||
|
this.lastNeed = 2;
|
||
|
this.lastTotal = 4;
|
||
|
this.lastChar[0] = buf[buf.length - 2];
|
||
|
this.lastChar[1] = buf[buf.length - 1];
|
||
|
return r.slice(0, -1);
|
||
|
}
|
||
|
}
|
||
|
return r;
|
||
|
}
|
||
|
this.lastNeed = 1;
|
||
|
this.lastTotal = 2;
|
||
|
this.lastChar[0] = buf[buf.length - 1];
|
||
|
return buf.toString('utf16le', i, buf.length - 1);
|
||
|
}
|
||
|
|
||
|
// For UTF-16LE we do not explicitly append special replacement characters if we
|
||
|
// end on a partial character, we simply let v8 handle that.
|
||
|
function utf16End(buf) {
|
||
|
var r = buf && buf.length ? this.write(buf) : '';
|
||
|
if (this.lastNeed) {
|
||
|
var end = this.lastTotal - this.lastNeed;
|
||
|
return r + this.lastChar.toString('utf16le', 0, end);
|
||
|
}
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
function base64Text(buf, i) {
|
||
|
var n = (buf.length - i) % 3;
|
||
|
if (n === 0) return buf.toString('base64', i);
|
||
|
this.lastNeed = 3 - n;
|
||
|
this.lastTotal = 3;
|
||
|
if (n === 1) {
|
||
|
this.lastChar[0] = buf[buf.length - 1];
|
||
|
} else {
|
||
|
this.lastChar[0] = buf[buf.length - 2];
|
||
|
this.lastChar[1] = buf[buf.length - 1];
|
||
|
}
|
||
|
return buf.toString('base64', i, buf.length - n);
|
||
|
}
|
||
|
|
||
|
function base64End(buf) {
|
||
|
var r = buf && buf.length ? this.write(buf) : '';
|
||
|
if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
|
||
|
function simpleWrite(buf) {
|
||
|
return buf.toString(this.encoding);
|
||
|
}
|
||
|
|
||
|
function simpleEnd(buf) {
|
||
|
return buf && buf.length ? this.write(buf) : '';
|
||
|
}
|
||
|
},{"safe-buffer":70}],73:[function(require,module,exports){
|
||
|
(function (global){
|
||
|
|
||
|
/**
|
||
|
* Module exports.
|
||
|
*/
|
||
|
|
||
|
module.exports = deprecate;
|
||
|
|
||
|
/**
|
||
|
* Mark that a method should not be used.
|
||
|
* Returns a modified function which warns once by default.
|
||
|
*
|
||
|
* If `localStorage.noDeprecation = true` is set, then it is a no-op.
|
||
|
*
|
||
|
* If `localStorage.throwDeprecation = true` is set, then deprecated functions
|
||
|
* will throw an Error when invoked.
|
||
|
*
|
||
|
* If `localStorage.traceDeprecation = true` is set, then deprecated functions
|
||
|
* will invoke `console.trace()` instead of `console.error()`.
|
||
|
*
|
||
|
* @param {Function} fn - the function to deprecate
|
||
|
* @param {String} msg - the string to print to the console when `fn` is invoked
|
||
|
* @returns {Function} a new "deprecated" version of `fn`
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function deprecate (fn, msg) {
|
||
|
if (config('noDeprecation')) {
|
||
|
return fn;
|
||
|
}
|
||
|
|
||
|
var warned = false;
|
||
|
function deprecated() {
|
||
|
if (!warned) {
|
||
|
if (config('throwDeprecation')) {
|
||
|
throw new Error(msg);
|
||
|
} else if (config('traceDeprecation')) {
|
||
|
console.trace(msg);
|
||
|
} else {
|
||
|
console.warn(msg);
|
||
|
}
|
||
|
warned = true;
|
||
|
}
|
||
|
return fn.apply(this, arguments);
|
||
|
}
|
||
|
|
||
|
return deprecated;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks `localStorage` for boolean values for the given `name`.
|
||
|
*
|
||
|
* @param {String} name
|
||
|
* @returns {Boolean}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function config (name) {
|
||
|
// accessing global.localStorage can trigger a DOMException in sandboxed iframes
|
||
|
try {
|
||
|
if (!global.localStorage) return false;
|
||
|
} catch (_) {
|
||
|
return false;
|
||
|
}
|
||
|
var val = global.localStorage[name];
|
||
|
if (null == val) return false;
|
||
|
return String(val).toLowerCase() === 'true';
|
||
|
}
|
||
|
|
||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{}],74:[function(require,module,exports){
|
||
|
arguments[4][50][0].apply(exports,arguments)
|
||
|
},{"dup":50}],75:[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';
|
||
|
}
|
||
|
},{}],76:[function(require,module,exports){
|
||
|
(function (process,global){
|
||
|
// 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);
|
||
|
}
|
||
|
|
||
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
|
},{"./support/isBuffer":75,"_process":56,"inherits":74}]},{},[1]);
|