Commit 8bdf5627 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

Merge branch 'MLAB-667' into 'testing'

Mlab 667

See merge request !151
parents de3756a3 cf9f5af3
Pipeline #6632 passed with stage
in 6 seconds
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _eachOf = require('./eachOf.js');
var _eachOf2 = _interopRequireDefault(_eachOf);
var _withoutIndex = require('./internal/withoutIndex.js');
var _withoutIndex2 = _interopRequireDefault(_withoutIndex);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies the function `iteratee` to each item in `coll`, in parallel.
* The `iteratee` is called with an item from the list, and a callback for when
* it has finished. If the `iteratee` passes an error to its `callback`, the
* main `callback` (for the `each` function) is immediately called with the
* error.
*
* Note, that since this function applies `iteratee` to each item in parallel,
* there is no guarantee that the iteratee functions will complete in order.
*
* @name each
* @static
* @memberOf module:Collections
* @method
* @alias forEach
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to
* each item in `coll`. Invoked with (item, callback).
* The array index is not passed to the iteratee.
* If you need the index, use `eachOf`.
* @param {Function} [callback] - A callback which is called when all
* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
* @example
*
* // dir1 is a directory that contains file1.txt, file2.txt
* // dir2 is a directory that contains file3.txt, file4.txt
* // dir3 is a directory that contains file5.txt
* // dir4 does not exist
*
* const fileList = [ 'dir1/file2.txt', 'dir2/file3.txt', 'dir/file5.txt'];
* const withMissingFileList = ['dir1/file1.txt', 'dir4/file2.txt'];
*
* // asynchronous function that deletes a file
* const deleteFile = function(file, callback) {
* fs.unlink(file, callback);
* };
*
* // Using callbacks
* async.each(fileList, deleteFile, function(err) {
* if( err ) {
* console.log(err);
* } else {
* console.log('All files have been deleted successfully');
* }
* });
*
* // Error Handling
* async.each(withMissingFileList, deleteFile, function(err){
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* // since dir4/file2.txt does not exist
* // dir1/file1.txt could have been deleted
* });
*
* // Using Promises
* async.each(fileList, deleteFile)
* .then( () => {
* console.log('All files have been deleted successfully');
* }).catch( err => {
* console.log(err);
* });
*
* // Error Handling
* async.each(fileList, deleteFile)
* .then( () => {
* console.log('All files have been deleted successfully');
* }).catch( err => {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* // since dir4/file2.txt does not exist
* // dir1/file1.txt could have been deleted
* });
*
* // Using async/await
* async () => {
* try {
* await async.each(files, deleteFile);
* }
* catch (err) {
* console.log(err);
* }
* }
*
* // Error Handling
* async () => {
* try {
* await async.each(withMissingFileList, deleteFile);
* }
* catch (err) {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* // since dir4/file2.txt does not exist
* // dir1/file1.txt could have been deleted
* }
* }
*
*/
function eachLimit(coll, iteratee, callback) {
return (0, _eachOf2.default)(coll, (0, _withoutIndex2.default)((0, _wrapAsync2.default)(iteratee)), callback);
}
exports.default = (0, _awaitify2.default)(eachLimit, 3);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _eachOfLimit = require('./internal/eachOfLimit.js');
var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
var _withoutIndex = require('./internal/withoutIndex.js');
var _withoutIndex2 = _interopRequireDefault(_withoutIndex);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
*
* @name eachLimit
* @static
* @memberOf module:Collections
* @method
* @see [async.each]{@link module:Collections.each}
* @alias forEachLimit
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.
* @param {AsyncFunction} iteratee - An async function to apply to each item in
* `coll`.
* The array index is not passed to the iteratee.
* If you need the index, use `eachOfLimit`.
* Invoked with (item, callback).
* @param {Function} [callback] - A callback which is called when all
* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
function eachLimit(coll, limit, iteratee, callback) {
return (0, _eachOfLimit2.default)(limit)(coll, (0, _withoutIndex2.default)((0, _wrapAsync2.default)(iteratee)), callback);
}
exports.default = (0, _awaitify2.default)(eachLimit, 4);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _isArrayLike = require('./internal/isArrayLike.js');
var _isArrayLike2 = _interopRequireDefault(_isArrayLike);
var _breakLoop = require('./internal/breakLoop.js');
var _breakLoop2 = _interopRequireDefault(_breakLoop);
var _eachOfLimit = require('./eachOfLimit.js');
var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
var _once = require('./internal/once.js');
var _once2 = _interopRequireDefault(_once);
var _onlyOnce = require('./internal/onlyOnce.js');
var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// eachOf implementation optimized for array-likes
function eachOfArrayLike(coll, iteratee, callback) {
callback = (0, _once2.default)(callback);
var index = 0,
completed = 0,
{ length } = coll,
canceled = false;
if (length === 0) {
callback(null);
}
function iteratorCallback(err, value) {
if (err === false) {
canceled = true;
}
if (canceled === true) return;
if (err) {
callback(err);
} else if (++completed === length || value === _breakLoop2.default) {
callback(null);
}
}
for (; index < length; index++) {
iteratee(coll[index], index, (0, _onlyOnce2.default)(iteratorCallback));
}
}
// a generic version of eachOf which can handle array, object, and iterator cases.
function eachOfGeneric(coll, iteratee, callback) {
return (0, _eachOfLimit2.default)(coll, Infinity, iteratee, callback);
}
/**
* Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
* to the iteratee.
*
* @name eachOf
* @static
* @memberOf module:Collections
* @method
* @alias forEachOf
* @category Collection
* @see [async.each]{@link module:Collections.each}
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A function to apply to each
* item in `coll`.
* The `key` is the item's key, or index in the case of an array.
* Invoked with (item, key, callback).
* @param {Function} [callback] - A callback which is called when all
* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
* @example
*
* // dev.json is a file containing a valid json object config for dev environment
* // dev.json is a file containing a valid json object config for test environment
* // prod.json is a file containing a valid json object config for prod environment
* // invalid.json is a file with a malformed json object
*
* let configs = {}; //global variable
* let validConfigFileMap = {dev: 'dev.json', test: 'test.json', prod: 'prod.json'};
* let invalidConfigFileMap = {dev: 'dev.json', test: 'test.json', invalid: 'invalid.json'};
*
* // asynchronous function that reads a json file and parses the contents as json object
* function parseFile(file, key, callback) {
* fs.readFile(file, "utf8", function(err, data) {
* if (err) return calback(err);
* try {
* configs[key] = JSON.parse(data);
* } catch (e) {
* return callback(e);
* }
* callback();
* });
* }
*
* // Using callbacks
* async.forEachOf(validConfigFileMap, parseFile, function (err) {
* if (err) {
* console.error(err);
* } else {
* console.log(configs);
* // configs is now a map of JSON data, e.g.
* // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
* }
* });
*
* //Error handing
* async.forEachOf(invalidConfigFileMap, parseFile, function (err) {
* if (err) {
* console.error(err);
* // JSON parse error exception
* } else {
* console.log(configs);
* }
* });
*
* // Using Promises
* async.forEachOf(validConfigFileMap, parseFile)
* .then( () => {
* console.log(configs);
* // configs is now a map of JSON data, e.g.
* // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
* }).catch( err => {
* console.error(err);
* });
*
* //Error handing
* async.forEachOf(invalidConfigFileMap, parseFile)
* .then( () => {
* console.log(configs);
* }).catch( err => {
* console.error(err);
* // JSON parse error exception
* });
*
* // Using async/await
* async () => {
* try {
* let result = await async.forEachOf(validConfigFileMap, parseFile);
* console.log(configs);
* // configs is now a map of JSON data, e.g.
* // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
* }
* catch (err) {
* console.log(err);
* }
* }
*
* //Error handing
* async () => {
* try {
* let result = await async.forEachOf(invalidConfigFileMap, parseFile);
* console.log(configs);
* }
* catch (err) {
* console.log(err);
* // JSON parse error exception
* }
* }
*
*/
function eachOf(coll, iteratee, callback) {
var eachOfImplementation = (0, _isArrayLike2.default)(coll) ? eachOfArrayLike : eachOfGeneric;
return eachOfImplementation(coll, (0, _wrapAsync2.default)(iteratee), callback);
}
exports.default = (0, _awaitify2.default)(eachOf, 3);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _eachOfLimit2 = require('./internal/eachOfLimit.js');
var _eachOfLimit3 = _interopRequireDefault(_eachOfLimit2);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
* time.
*
* @name eachOfLimit
* @static
* @memberOf module:Collections
* @method
* @see [async.eachOf]{@link module:Collections.eachOf}
* @alias forEachOfLimit
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.
* @param {AsyncFunction} iteratee - An async function to apply to each
* item in `coll`. The `key` is the item's key, or index in the case of an
* array.
* Invoked with (item, key, callback).
* @param {Function} [callback] - A callback which is called when all
* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
function eachOfLimit(coll, limit, iteratee, callback) {
return (0, _eachOfLimit3.default)(limit)(coll, (0, _wrapAsync2.default)(iteratee), callback);
}
exports.default = (0, _awaitify2.default)(eachOfLimit, 4);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _eachOfLimit = require('./eachOfLimit.js');
var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
*
* @name eachOfSeries
* @static
* @memberOf module:Collections
* @method
* @see [async.eachOf]{@link module:Collections.eachOf}
* @alias forEachOfSeries
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in
* `coll`.
* Invoked with (item, key, callback).
* @param {Function} [callback] - A callback which is called when all `iteratee`
* functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
function eachOfSeries(coll, iteratee, callback) {
return (0, _eachOfLimit2.default)(coll, 1, iteratee, callback);
}
exports.default = (0, _awaitify2.default)(eachOfSeries, 3);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _eachLimit = require('./eachLimit.js');
var _eachLimit2 = _interopRequireDefault(_eachLimit);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
*
* Note, that unlike [`each`]{@link module:Collections.each}, this function applies iteratee to each item
* in series and therefore the iteratee functions will complete in order.
* @name eachSeries
* @static
* @memberOf module:Collections
* @method
* @see [async.each]{@link module:Collections.each}
* @alias forEachSeries
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each
* item in `coll`.
* The array index is not passed to the iteratee.
* If you need the index, use `eachOfSeries`.
* Invoked with (item, callback).
* @param {Function} [callback] - A callback which is called when all
* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
function eachSeries(coll, iteratee, callback) {
return (0, _eachLimit2.default)(coll, 1, iteratee, callback);
}
exports.default = (0, _awaitify2.default)(eachSeries, 3);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _onlyOnce = require('./internal/onlyOnce.js');
var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
var _ensureAsync = require('./ensureAsync.js');
var _ensureAsync2 = _interopRequireDefault(_ensureAsync);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Calls the asynchronous function `fn` with a callback parameter that allows it
* to call itself again, in series, indefinitely.
* If an error is passed to the callback then `errback` is called with the
* error, and execution stops, otherwise it will never be called.
*
* @name forever
* @static
* @memberOf module:ControlFlow
* @method
* @category Control Flow
* @param {AsyncFunction} fn - an async function to call repeatedly.
* Invoked with (next).
* @param {Function} [errback] - when `fn` passes an error to it's callback,
* this function will be called, and execution stops. Invoked with (err).
* @returns {Promise} a promise that rejects if an error occurs and an errback
* is not passed
* @example
*
* async.forever(
* function(next) {
* // next is suitable for passing to things that need a callback(err [, whatever]);
* // it will result in this function being called again.
* },
* function(err) {
* // if next is called with a value in its first parameter, it will appear
* // in here as 'err', and execution will stop.
* }
* );
*/
function forever(fn, errback) {
var done = (0, _onlyOnce2.default)(errback);
var task = (0, _wrapAsync2.default)((0, _ensureAsync2.default)(fn));
function next(err) {
if (err) return done(err);
if (err === false) return;
task(next);
}
return next();
}
exports.default = (0, _awaitify2.default)(forever, 2);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = groupBy;
var _groupByLimit = require('./groupByLimit.js');
var _groupByLimit2 = _interopRequireDefault(_groupByLimit);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Returns a new object, where each value corresponds to an array of items, from
* `coll`, that returned the corresponding key. That is, the keys of the object
* correspond to the values passed to the `iteratee` callback.
*
* Note: Since this function applies the `iteratee` to each item in parallel,
* there is no guarantee that the `iteratee` functions will complete in order.
* However, the values for each key in the `result` will be in the same order as
* the original `coll`. For Objects, the values will roughly be in the order of
* the original Objects' keys (but this can vary across JavaScript engines).
*
* @name groupBy
* @static
* @memberOf module:Collections
* @method
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in
* `coll`.
* The iteratee should complete with a `key` to group the value under.
* Invoked with (value, callback).
* @param {Function} [callback] - A callback which is called when all `iteratee`
* functions have finished, or an error occurs. Result is an `Object` whoses
* properties are arrays of values which returned the corresponding key.
* @returns {Promise} a promise, if no callback is passed
* @example
*
* // dir1 is a directory that contains file1.txt, file2.txt
* // dir2 is a directory that contains file3.txt, file4.txt
* // dir3 is a directory that contains file5.txt
* // dir4 does not exist
*
* const files = ['dir1/file1.txt','dir2','dir4']
*
* // asynchronous function that detects file type as none, file, or directory
* function detectFile(file, callback) {
* fs.stat(file, function(err, stat) {
* if (err) {
* return callback(null, 'none');
* }
* callback(null, stat.isDirectory() ? 'directory' : 'file');
* });
* }
*
* //Using callbacks
* async.groupBy(files, detectFile, function(err, result) {
* if(err) {
* console.log(err);
* } else {
* console.log(result);
* // {
* // file: [ 'dir1/file1.txt' ],
* // none: [ 'dir4' ],
* // directory: [ 'dir2']
* // }
* // result is object containing the files grouped by type
* }
* });
*
* // Using Promises
* async.groupBy(files, detectFile)
* .then( result => {
* console.log(result);
* // {
* // file: [ 'dir1/file1.txt' ],
* // none: [ 'dir4' ],
* // directory: [ 'dir2']
* // }
* // result is object containing the files grouped by type
* }).catch( err => {
* console.log(err);
* });
*
* // Using async/await
* async () => {
* try {
* let result = await async.groupBy(files, detectFile);
* console.log(result);
* // {
* // file: [ 'dir1/file1.txt' ],
* // none: [ 'dir4' ],
* // directory: [ 'dir2']
* // }
* // result is object containing the files grouped by type
* }
* catch (err) {
* console.log(err);
* }
* }
*
*/
function groupBy(coll, iteratee, callback) {
return (0, _groupByLimit2.default)(coll, Infinity, iteratee, callback);
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _mapLimit = require('./mapLimit.js');
var _mapLimit2 = _interopRequireDefault(_mapLimit);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.
*
* @name groupByLimit
* @static
* @memberOf module:Collections
* @method
* @see [async.groupBy]{@link module:Collections.groupBy}
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.
* @param {AsyncFunction} iteratee - An async function to apply to each item in
* `coll`.
* The iteratee should complete with a `key` to group the value under.
* Invoked with (value, callback).
* @param {Function} [callback] - A callback which is called when all `iteratee`
* functions have finished, or an error occurs. Result is an `Object` whoses
* properties are arrays of values which returned the corresponding key.
* @returns {Promise} a promise, if no callback is passed
*/
function groupByLimit(coll, limit, iteratee, callback) {
var _iteratee = (0, _wrapAsync2.default)(iteratee);
return (0, _mapLimit2.default)(coll, limit, (val, iterCb) => {
_iteratee(val, (err, key) => {
if (err) return iterCb(err);
return iterCb(err, { key, val });
});
}, (err, mapResults) => {
var result = {};
// from MDN, handle object having an `hasOwnProperty` prop
var { hasOwnProperty } = Object.prototype;
for (var i = 0; i < mapResults.length; i++) {
if (mapResults[i]) {
var { key } = mapResults[i];
var { val } = mapResults[i];
if (hasOwnProperty.call(result, key)) {
result[key].push(val);
} else {
result[key] = [val];
}
}
}
return callback(err, result);
});
}
exports.default = (0, _awaitify2.default)(groupByLimit, 4);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = groupBySeries;
var _groupByLimit = require('./groupByLimit.js');
var _groupByLimit2 = _interopRequireDefault(_groupByLimit);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* The same as [`groupBy`]{@link module:Collections.groupBy} but runs only a single async operation at a time.
*
* @name groupBySeries
* @static
* @memberOf module:Collections
* @method
* @see [async.groupBy]{@link module:Collections.groupBy}
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in
* `coll`.
* The iteratee should complete with a `key` to group the value under.
* Invoked with (value, callback).
* @param {Function} [callback] - A callback which is called when all `iteratee`
* functions have finished, or an error occurs. Result is an `Object` whose
* properties are arrays of values which returned the corresponding key.
* @returns {Promise} a promise, if no callback is passed
*/
function groupBySeries(coll, iteratee, callback) {
return (0, _groupByLimit2.default)(coll, 1, iteratee, callback);
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.doDuring = exports.during = exports.wrapSync = undefined;
exports.selectSeries = exports.selectLimit = exports.select = exports.foldr = exports.foldl = exports.inject = exports.forEachOfLimit = exports.forEachOfSeries = exports.forEachOf = exports.forEachLimit = exports.forEachSeries = exports.forEach = exports.flatMapSeries = exports.flatMapLimit = exports.flatMap = exports.findSeries = exports.findLimit = exports.find = exports.anySeries = exports.anyLimit = exports.any = exports.allSeries = exports.allLimit = exports.all = exports.whilst = exports.waterfall = exports.until = exports.unmemoize = exports.tryEach = exports.transform = exports.timesSeries = exports.timesLimit = exports.times = exports.timeout = exports.sortBy = exports.someSeries = exports.someLimit = exports.some = exports.setImmediate = exports.series = exports.seq = exports.retryable = exports.retry = exports.rejectSeries = exports.rejectLimit = exports.reject = exports.reflectAll = exports.reflect = exports.reduceRight = exports.reduce = exports.race = exports.queue = exports.priorityQueue = exports.parallelLimit = exports.parallel = exports.nextTick = exports.memoize = exports.mapValuesSeries = exports.mapValuesLimit = exports.mapValues = exports.mapSeries = exports.mapLimit = exports.map = exports.log = exports.groupBySeries = exports.groupByLimit = exports.groupBy = exports.forever = exports.filterSeries = exports.filterLimit = exports.filter = exports.everySeries = exports.everyLimit = exports.every = exports.ensureAsync = exports.eachSeries = exports.eachOfSeries = exports.eachOfLimit = exports.eachOf = exports.eachLimit = exports.each = exports.doWhilst = exports.doUntil = exports.dir = exports.detectSeries = exports.detectLimit = exports.detect = exports.constant = exports.concatSeries = exports.concatLimit = exports.concat = exports.compose = exports.cargoQueue = exports.cargo = exports.autoInject = exports.auto = exports.asyncify = exports.applyEachSeries = exports.applyEach = exports.apply = undefined;
var _apply = require('./apply');
var _apply2 = _interopRequireDefault(_apply);
var _applyEach = require('./applyEach');
var _applyEach2 = _interopRequireDefault(_applyEach);
var _applyEachSeries = require('./applyEachSeries');
var _applyEachSeries2 = _interopRequireDefault(_applyEachSeries);
var _asyncify = require('./asyncify');
var _asyncify2 = _interopRequireDefault(_asyncify);
var _auto = require('./auto');
var _auto2 = _interopRequireDefault(_auto);
var _autoInject = require('./autoInject');
var _autoInject2 = _interopRequireDefault(_autoInject);
var _cargo = require('./cargo');
var _cargo2 = _interopRequireDefault(_cargo);
var _cargoQueue = require('./cargoQueue');
var _cargoQueue2 = _interopRequireDefault(_cargoQueue);
var _compose = require('./compose');
var _compose2 = _interopRequireDefault(_compose);
var _concat = require('./concat');
var _concat2 = _interopRequireDefault(_concat);
var _concatLimit = require('./concatLimit');
var _concatLimit2 = _interopRequireDefault(_concatLimit);
var _concatSeries = require('./concatSeries');
var _concatSeries2 = _interopRequireDefault(_concatSeries);
var _constant = require('./constant');
var _constant2 = _interopRequireDefault(_constant);
var _detect = require('./detect');
var _detect2 = _interopRequireDefault(_detect);
var _detectLimit = require('./detectLimit');
var _detectLimit2 = _interopRequireDefault(_detectLimit);
var _detectSeries = require('./detectSeries');
var _detectSeries2 = _interopRequireDefault(_detectSeries);
var _dir = require('./dir');
var _dir2 = _interopRequireDefault(_dir);
var _doUntil = require('./doUntil');
var _doUntil2 = _interopRequireDefault(_doUntil);
var _doWhilst = require('./doWhilst');
var _doWhilst2 = _interopRequireDefault(_doWhilst);
var _each = require('./each');
var _each2 = _interopRequireDefault(_each);
var _eachLimit = require('./eachLimit');
var _eachLimit2 = _interopRequireDefault(_eachLimit);
var _eachOf = require('./eachOf');
var _eachOf2 = _interopRequireDefault(_eachOf);
var _eachOfLimit = require('./eachOfLimit');
var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
var _eachOfSeries = require('./eachOfSeries');
var _eachOfSeries2 = _interopRequireDefault(_eachOfSeries);
var _eachSeries = require('./eachSeries');
var _eachSeries2 = _interopRequireDefault(_eachSeries);
var _ensureAsync = require('./ensureAsync');
var _ensureAsync2 = _interopRequireDefault(_ensureAsync);
var _every = require('./every');
var _every2 = _interopRequireDefault(_every);
var _everyLimit = require('./everyLimit');
var _everyLimit2 = _interopRequireDefault(_everyLimit);
var _everySeries = require('./everySeries');
var _everySeries2 = _interopRequireDefault(_everySeries);
var _filter = require('./filter');
var _filter2 = _interopRequireDefault(_filter);
var _filterLimit = require('./filterLimit');
var _filterLimit2 = _interopRequireDefault(_filterLimit);
var _filterSeries = require('./filterSeries');
var _filterSeries2 = _interopRequireDefault(_filterSeries);
var _forever = require('./forever');
var _forever2 = _interopRequireDefault(_forever);
var _groupBy = require('./groupBy');
var _groupBy2 = _interopRequireDefault(_groupBy);
var _groupByLimit = require('./groupByLimit');
var _groupByLimit2 = _interopRequireDefault(_groupByLimit);
var _groupBySeries = require('./groupBySeries');
var _groupBySeries2 = _interopRequireDefault(_groupBySeries);
var _log = require('./log');
var _log2 = _interopRequireDefault(_log);
var _map = require('./map');
var _map2 = _interopRequireDefault(_map);
var _mapLimit = require('./mapLimit');
var _mapLimit2 = _interopRequireDefault(_mapLimit);
var _mapSeries = require('./mapSeries');
var _mapSeries2 = _interopRequireDefault(_mapSeries);
var _mapValues = require('./mapValues');
var _mapValues2 = _interopRequireDefault(_mapValues);
var _mapValuesLimit = require('./mapValuesLimit');
var _mapValuesLimit2 = _interopRequireDefault(_mapValuesLimit);
var _mapValuesSeries = require('./mapValuesSeries');
var _mapValuesSeries2 = _interopRequireDefault(_mapValuesSeries);
var _memoize = require('./memoize');
var _memoize2 = _interopRequireDefault(_memoize);
var _nextTick = require('./nextTick');
var _nextTick2 = _interopRequireDefault(_nextTick);
var _parallel = require('./parallel');
var _parallel2 = _interopRequireDefault(_parallel);
var _parallelLimit = require('./parallelLimit');
var _parallelLimit2 = _interopRequireDefault(_parallelLimit);
var _priorityQueue = require('./priorityQueue');
var _priorityQueue2 = _interopRequireDefault(_priorityQueue);
var _queue = require('./queue');
var _queue2 = _interopRequireDefault(_queue);
var _race = require('./race');
var _race2 = _interopRequireDefault(_race);
var _reduce = require('./reduce');
var _reduce2 = _interopRequireDefault(_reduce);
var _reduceRight = require('./reduceRight');
var _reduceRight2 = _interopRequireDefault(_reduceRight);
var _reflect = require('./reflect');
var _reflect2 = _interopRequireDefault(_reflect);
var _reflectAll = require('./reflectAll');
var _reflectAll2 = _interopRequireDefault(_reflectAll);
var _reject = require('./reject');
var _reject2 = _interopRequireDefault(_reject);
var _rejectLimit = require('./rejectLimit');
var _rejectLimit2 = _interopRequireDefault(_rejectLimit);
var _rejectSeries = require('./rejectSeries');
var _rejectSeries2 = _interopRequireDefault(_rejectSeries);
var _retry = require('./retry');
var _retry2 = _interopRequireDefault(_retry);
var _retryable = require('./retryable');
var _retryable2 = _interopRequireDefault(_retryable);
var _seq = require('./seq');
var _seq2 = _interopRequireDefault(_seq);
var _series = require('./series');
var _series2 = _interopRequireDefault(_series);
var _setImmediate = require('./setImmediate');
var _setImmediate2 = _interopRequireDefault(_setImmediate);
var _some = require('./some');
var _some2 = _interopRequireDefault(_some);
var _someLimit = require('./someLimit');
var _someLimit2 = _interopRequireDefault(_someLimit);
var _someSeries = require('./someSeries');
var _someSeries2 = _interopRequireDefault(_someSeries);
var _sortBy = require('./sortBy');
var _sortBy2 = _interopRequireDefault(_sortBy);
var _timeout = require('./timeout');
var _timeout2 = _interopRequireDefault(_timeout);
var _times = require('./times');
var _times2 = _interopRequireDefault(_times);
var _timesLimit = require('./timesLimit');
var _timesLimit2 = _interopRequireDefault(_timesLimit);
var _timesSeries = require('./timesSeries');
var _timesSeries2 = _interopRequireDefault(_timesSeries);
var _transform = require('./transform');
var _transform2 = _interopRequireDefault(_transform);
var _tryEach = require('./tryEach');
var _tryEach2 = _interopRequireDefault(_tryEach);
var _unmemoize = require('./unmemoize');
var _unmemoize2 = _interopRequireDefault(_unmemoize);
var _until = require('./until');
var _until2 = _interopRequireDefault(_until);
var _waterfall = require('./waterfall');
var _waterfall2 = _interopRequireDefault(_waterfall);
var _whilst = require('./whilst');
var _whilst2 = _interopRequireDefault(_whilst);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* An "async function" in the context of Async is an asynchronous function with
* a variable number of parameters, with the final parameter being a callback.
* (`function (arg1, arg2, ..., callback) {}`)
* The final callback is of the form `callback(err, results...)`, which must be
* called once the function is completed. The callback should be called with a
* Error as its first argument to signal that an error occurred.
* Otherwise, if no error occurred, it should be called with `null` as the first
* argument, and any additional `result` arguments that may apply, to signal
* successful completion.
* The callback must be called exactly once, ideally on a later tick of the
* JavaScript event loop.
*
* This type of function is also referred to as a "Node-style async function",
* or a "continuation passing-style function" (CPS). Most of the methods of this
* library are themselves CPS/Node-style async functions, or functions that
* return CPS/Node-style async functions.
*
* Wherever we accept a Node-style async function, we also directly accept an
* [ES2017 `async` function]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function}.
* In this case, the `async` function will not be passed a final callback
* argument, and any thrown error will be used as the `err` argument of the
* implicit callback, and the return value will be used as the `result` value.
* (i.e. a `rejected` of the returned Promise becomes the `err` callback
* argument, and a `resolved` value becomes the `result`.)
*
* Note, due to JavaScript limitations, we can only detect native `async`
* functions and not transpilied implementations.
* Your environment must have `async`/`await` support for this to work.
* (e.g. Node > v7.6, or a recent version of a modern browser).
* If you are using `async` functions through a transpiler (e.g. Babel), you
* must still wrap the function with [asyncify]{@link module:Utils.asyncify},
* because the `async function` will be compiled to an ordinary function that
* returns a promise.
*
* @typedef {Function} AsyncFunction
* @static
*/
/**
* Async is a utility module which provides straight-forward, powerful functions
* for working with asynchronous JavaScript. Although originally designed for
* use with [Node.js](http://nodejs.org) and installable via
* `npm install --save async`, it can also be used directly in the browser.
* @module async
* @see AsyncFunction
*/
/**
* A collection of `async` functions for manipulating collections, such as
* arrays and objects.
* @module Collections
*/
/**
* A collection of `async` functions for controlling the flow through a script.
* @module ControlFlow
*/
/**
* A collection of `async` utility functions.
* @module Utils
*/
exports.default = {
apply: _apply2.default,
applyEach: _applyEach2.default,
applyEachSeries: _applyEachSeries2.default,
asyncify: _asyncify2.default,
auto: _auto2.default,
autoInject: _autoInject2.default,
cargo: _cargo2.default,
cargoQueue: _cargoQueue2.default,
compose: _compose2.default,
concat: _concat2.default,
concatLimit: _concatLimit2.default,
concatSeries: _concatSeries2.default,
constant: _constant2.default,
detect: _detect2.default,
detectLimit: _detectLimit2.default,
detectSeries: _detectSeries2.default,
dir: _dir2.default,
doUntil: _doUntil2.default,
doWhilst: _doWhilst2.default,
each: _each2.default,
eachLimit: _eachLimit2.default,
eachOf: _eachOf2.default,
eachOfLimit: _eachOfLimit2.default,
eachOfSeries: _eachOfSeries2.default,
eachSeries: _eachSeries2.default,
ensureAsync: _ensureAsync2.default,
every: _every2.default,
everyLimit: _everyLimit2.default,
everySeries: _everySeries2.default,
filter: _filter2.default,
filterLimit: _filterLimit2.default,
filterSeries: _filterSeries2.default,
forever: _forever2.default,
groupBy: _groupBy2.default,
groupByLimit: _groupByLimit2.default,
groupBySeries: _groupBySeries2.default,
log: _log2.default,
map: _map2.default,
mapLimit: _mapLimit2.default,
mapSeries: _mapSeries2.default,
mapValues: _mapValues2.default,
mapValuesLimit: _mapValuesLimit2.default,
mapValuesSeries: _mapValuesSeries2.default,
memoize: _memoize2.default,
nextTick: _nextTick2.default,
parallel: _parallel2.default,
parallelLimit: _parallelLimit2.default,
priorityQueue: _priorityQueue2.default,
queue: _queue2.default,
race: _race2.default,
reduce: _reduce2.default,
reduceRight: _reduceRight2.default,
reflect: _reflect2.default,
reflectAll: _reflectAll2.default,
reject: _reject2.default,
rejectLimit: _rejectLimit2.default,
rejectSeries: _rejectSeries2.default,
retry: _retry2.default,
retryable: _retryable2.default,
seq: _seq2.default,
series: _series2.default,
setImmediate: _setImmediate2.default,
some: _some2.default,
someLimit: _someLimit2.default,
someSeries: _someSeries2.default,
sortBy: _sortBy2.default,
timeout: _timeout2.default,
times: _times2.default,
timesLimit: _timesLimit2.default,
timesSeries: _timesSeries2.default,
transform: _transform2.default,
tryEach: _tryEach2.default,
unmemoize: _unmemoize2.default,
until: _until2.default,
waterfall: _waterfall2.default,
whilst: _whilst2.default,
// aliases
all: _every2.default,
allLimit: _everyLimit2.default,
allSeries: _everySeries2.default,
any: _some2.default,
anyLimit: _someLimit2.default,
anySeries: _someSeries2.default,
find: _detect2.default,
findLimit: _detectLimit2.default,
findSeries: _detectSeries2.default,
flatMap: _concat2.default,
flatMapLimit: _concatLimit2.default,
flatMapSeries: _concatSeries2.default,
forEach: _each2.default,
forEachSeries: _eachSeries2.default,
forEachLimit: _eachLimit2.default,
forEachOf: _eachOf2.default,
forEachOfSeries: _eachOfSeries2.default,
forEachOfLimit: _eachOfLimit2.default,
inject: _reduce2.default,
foldl: _reduce2.default,
foldr: _reduceRight2.default,
select: _filter2.default,
selectLimit: _filterLimit2.default,
selectSeries: _filterSeries2.default,
wrapSync: _asyncify2.default,
during: _whilst2.default,
doDuring: _doWhilst2.default
};
exports.apply = _apply2.default;
exports.applyEach = _applyEach2.default;
exports.applyEachSeries = _applyEachSeries2.default;
exports.asyncify = _asyncify2.default;
exports.auto = _auto2.default;
exports.autoInject = _autoInject2.default;
exports.cargo = _cargo2.default;
exports.cargoQueue = _cargoQueue2.default;
exports.compose = _compose2.default;
exports.concat = _concat2.default;
exports.concatLimit = _concatLimit2.default;
exports.concatSeries = _concatSeries2.default;
exports.constant = _constant2.default;
exports.detect = _detect2.default;
exports.detectLimit = _detectLimit2.default;
exports.detectSeries = _detectSeries2.default;
exports.dir = _dir2.default;
exports.doUntil = _doUntil2.default;
exports.doWhilst = _doWhilst2.default;
exports.each = _each2.default;
exports.eachLimit = _eachLimit2.default;
exports.eachOf = _eachOf2.default;
exports.eachOfLimit = _eachOfLimit2.default;
exports.eachOfSeries = _eachOfSeries2.default;
exports.eachSeries = _eachSeries2.default;
exports.ensureAsync = _ensureAsync2.default;
exports.every = _every2.default;
exports.everyLimit = _everyLimit2.default;
exports.everySeries = _everySeries2.default;
exports.filter = _filter2.default;
exports.filterLimit = _filterLimit2.default;
exports.filterSeries = _filterSeries2.default;
exports.forever = _forever2.default;
exports.groupBy = _groupBy2.default;
exports.groupByLimit = _groupByLimit2.default;
exports.groupBySeries = _groupBySeries2.default;
exports.log = _log2.default;
exports.map = _map2.default;
exports.mapLimit = _mapLimit2.default;
exports.mapSeries = _mapSeries2.default;
exports.mapValues = _mapValues2.default;
exports.mapValuesLimit = _mapValuesLimit2.default;
exports.mapValuesSeries = _mapValuesSeries2.default;
exports.memoize = _memoize2.default;
exports.nextTick = _nextTick2.default;
exports.parallel = _parallel2.default;
exports.parallelLimit = _parallelLimit2.default;
exports.priorityQueue = _priorityQueue2.default;
exports.queue = _queue2.default;
exports.race = _race2.default;
exports.reduce = _reduce2.default;
exports.reduceRight = _reduceRight2.default;
exports.reflect = _reflect2.default;
exports.reflectAll = _reflectAll2.default;
exports.reject = _reject2.default;
exports.rejectLimit = _rejectLimit2.default;
exports.rejectSeries = _rejectSeries2.default;
exports.retry = _retry2.default;
exports.retryable = _retryable2.default;
exports.seq = _seq2.default;
exports.series = _series2.default;
exports.setImmediate = _setImmediate2.default;
exports.some = _some2.default;
exports.someLimit = _someLimit2.default;
exports.someSeries = _someSeries2.default;
exports.sortBy = _sortBy2.default;
exports.timeout = _timeout2.default;
exports.times = _times2.default;
exports.timesLimit = _timesLimit2.default;
exports.timesSeries = _timesSeries2.default;
exports.transform = _transform2.default;
exports.tryEach = _tryEach2.default;
exports.unmemoize = _unmemoize2.default;
exports.until = _until2.default;
exports.waterfall = _waterfall2.default;
exports.whilst = _whilst2.default;
exports.all = _every2.default;
exports.allLimit = _everyLimit2.default;
exports.allSeries = _everySeries2.default;
exports.any = _some2.default;
exports.anyLimit = _someLimit2.default;
exports.anySeries = _someSeries2.default;
exports.find = _detect2.default;
exports.findLimit = _detectLimit2.default;
exports.findSeries = _detectSeries2.default;
exports.flatMap = _concat2.default;
exports.flatMapLimit = _concatLimit2.default;
exports.flatMapSeries = _concatSeries2.default;
exports.forEach = _each2.default;
exports.forEachSeries = _eachSeries2.default;
exports.forEachLimit = _eachLimit2.default;
exports.forEachOf = _eachOf2.default;
exports.forEachOfSeries = _eachOfSeries2.default;
exports.forEachOfLimit = _eachOfLimit2.default;
exports.inject = _reduce2.default;
exports.foldl = _reduce2.default;
exports.foldr = _reduceRight2.default;
exports.select = _filter2.default;
exports.selectLimit = _filterLimit2.default;
exports.selectSeries = _filterSeries2.default;
exports.wrapSync = _asyncify2.default;
exports.during = _whilst2.default;
exports.doDuring = _doWhilst2.default;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _eachOfSeries = require('./eachOfSeries.js');
var _eachOfSeries2 = _interopRequireDefault(_eachOfSeries);
var _once = require('./internal/once.js');
var _once2 = _interopRequireDefault(_once);
var _wrapAsync = require('./internal/wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Reduces `coll` into a single value using an async `iteratee` to return each
* successive step. `memo` is the initial state of the reduction. This function
* only operates in series.
*
* For performance reasons, it may make sense to split a call to this function
* into a parallel map, and then use the normal `Array.prototype.reduce` on the
* results. This function is for situations where each step in the reduction
* needs to be async; if you can get the data before reducing it, then it's
* probably a good idea to do so.
*
* @name reduce
* @static
* @memberOf module:Collections
* @method
* @alias inject
* @alias foldl
* @category Collection
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {*} memo - The initial state of the reduction.
* @param {AsyncFunction} iteratee - A function applied to each item in the
* array to produce the next step in the reduction.
* The `iteratee` should complete with the next state of the reduction.
* If the iteratee completes with an error, the reduction is stopped and the
* main `callback` is immediately called with the error.
* Invoked with (memo, item, callback).
* @param {Function} [callback] - A callback which is called after all the
* `iteratee` functions have finished. Result is the reduced value. Invoked with
* (err, result).
* @returns {Promise} a promise, if no callback is passed
* @example
*
* // file1.txt is a file that is 1000 bytes in size
* // file2.txt is a file that is 2000 bytes in size
* // file3.txt is a file that is 3000 bytes in size
* // file4.txt does not exist
*
* const fileList = ['file1.txt','file2.txt','file3.txt'];
* const withMissingFileList = ['file1.txt','file2.txt','file3.txt', 'file4.txt'];
*
* // asynchronous function that computes the file size in bytes
* // file size is added to the memoized value, then returned
* function getFileSizeInBytes(memo, file, callback) {
* fs.stat(file, function(err, stat) {
* if (err) {
* return callback(err);
* }
* callback(null, memo + stat.size);
* });
* }
*
* // Using callbacks
* async.reduce(fileList, 0, getFileSizeInBytes, function(err, result) {
* if (err) {
* console.log(err);
* } else {
* console.log(result);
* // 6000
* // which is the sum of the file sizes of the three files
* }
* });
*
* // Error Handling
* async.reduce(withMissingFileList, 0, getFileSizeInBytes, function(err, result) {
* if (err) {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* } else {
* console.log(result);
* }
* });
*
* // Using Promises
* async.reduce(fileList, 0, getFileSizeInBytes)
* .then( result => {
* console.log(result);
* // 6000
* // which is the sum of the file sizes of the three files
* }).catch( err => {
* console.log(err);
* });
*
* // Error Handling
* async.reduce(withMissingFileList, 0, getFileSizeInBytes)
* .then( result => {
* console.log(result);
* }).catch( err => {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* });
*
* // Using async/await
* async () => {
* try {
* let result = await async.reduce(fileList, 0, getFileSizeInBytes);
* console.log(result);
* // 6000
* // which is the sum of the file sizes of the three files
* }
* catch (err) {
* console.log(err);
* }
* }
*
* // Error Handling
* async () => {
* try {
* let result = await async.reduce(withMissingFileList, 0, getFileSizeInBytes);
* console.log(result);
* }
* catch (err) {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* }
* }
*
*/
function reduce(coll, memo, iteratee, callback) {
callback = (0, _once2.default)(callback);
var _iteratee = (0, _wrapAsync2.default)(iteratee);
return (0, _eachOfSeries2.default)(coll, (x, i, iterCb) => {
_iteratee(memo, x, (err, v) => {
memo = v;
iterCb(err);
});
}, err => callback(err, memo));
}
exports.default = (0, _awaitify2.default)(reduce, 4);
module.exports = exports['default'];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
// used for queues. This implementation assumes that the node provided by the user can be modified
// to adjust the next and last properties. We implement only the minimal functionality
// for queue support.
class DLL {
constructor() {
this.head = this.tail = null;
this.length = 0;
}
removeLink(node) {
if (node.prev) node.prev.next = node.next;else this.head = node.next;
if (node.next) node.next.prev = node.prev;else this.tail = node.prev;
node.prev = node.next = null;
this.length -= 1;
return node;
}
empty() {
while (this.head) this.shift();
return this;
}
insertAfter(node, newNode) {
newNode.prev = node;
newNode.next = node.next;
if (node.next) node.next.prev = newNode;else this.tail = newNode;
node.next = newNode;
this.length += 1;
}
insertBefore(node, newNode) {
newNode.prev = node.prev;
newNode.next = node;
if (node.prev) node.prev.next = newNode;else this.head = newNode;
node.prev = newNode;
this.length += 1;
}
unshift(node) {
if (this.head) this.insertBefore(this.head, node);else setInitial(this, node);
}
push(node) {
if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node);
}
shift() {
return this.head && this.removeLink(this.head);
}
pop() {
return this.tail && this.removeLink(this.tail);
}
toArray() {
return [...this];
}
*[Symbol.iterator]() {
var cur = this.head;
while (cur) {
yield cur.data;
cur = cur.next;
}
}
remove(testFn) {
var curr = this.head;
while (curr) {
var { next } = curr;
if (testFn(curr)) {
this.removeLink(curr);
}
curr = next;
}
return this;
}
}
exports.default = DLL;
function setInitial(dll, node) {
dll.length = 1;
dll.head = dll.tail = node;
}
module.exports = exports["default"];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// Binary min-heap implementation used for priority queue.
// Implementation is stable, i.e. push time is considered for equal priorities
class Heap {
constructor() {
this.heap = [];
this.pushCount = Number.MIN_SAFE_INTEGER;
}
get length() {
return this.heap.length;
}
empty() {
this.heap = [];
return this;
}
percUp(index) {
let p;
while (index > 0 && smaller(this.heap[index], this.heap[p = parent(index)])) {
let t = this.heap[index];
this.heap[index] = this.heap[p];
this.heap[p] = t;
index = p;
}
}
percDown(index) {
let l;
while ((l = leftChi(index)) < this.heap.length) {
if (l + 1 < this.heap.length && smaller(this.heap[l + 1], this.heap[l])) {
l = l + 1;
}
if (smaller(this.heap[index], this.heap[l])) {
break;
}
let t = this.heap[index];
this.heap[index] = this.heap[l];
this.heap[l] = t;
index = l;
}
}
push(node) {
node.pushCount = ++this.pushCount;
this.heap.push(node);
this.percUp(this.heap.length - 1);
}
unshift(node) {
return this.heap.push(node);
}
shift() {
let [top] = this.heap;
this.heap[0] = this.heap[this.heap.length - 1];
this.heap.pop();
this.percDown(0);
return top;
}
toArray() {
return [...this];
}
*[Symbol.iterator]() {
for (let i = 0; i < this.heap.length; i++) {
yield this.heap[i].data;
}
}
remove(testFn) {
let j = 0;
for (let i = 0; i < this.heap.length; i++) {
if (!testFn(this.heap[i])) {
this.heap[j] = this.heap[i];
j++;
}
}
this.heap.splice(j);
for (let i = parent(this.heap.length - 1); i >= 0; i--) {
this.percDown(i);
}
return this;
}
}
exports.default = Heap;
function leftChi(i) {
return (i << 1) + 1;
}
function parent(i) {
return (i + 1 >> 1) - 1;
}
function smaller(x, y) {
if (x.priority !== y.priority) {
return x.priority < y.priority;
} else {
return x.pushCount < y.pushCount;
}
}
module.exports = exports["default"];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (eachfn) {
return function applyEach(fns, ...callArgs) {
const go = (0, _awaitify2.default)(function (callback) {
var that = this;
return eachfn(fns, (fn, cb) => {
(0, _wrapAsync2.default)(fn).apply(that, callArgs.concat(cb));
}, callback);
});
return go;
};
};
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
var _awaitify = require('./awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = asyncEachOfLimit;
var _breakLoop = require('./breakLoop.js');
var _breakLoop2 = _interopRequireDefault(_breakLoop);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// for async generators
function asyncEachOfLimit(generator, limit, iteratee, callback) {
let done = false;
let canceled = false;
let awaiting = false;
let running = 0;
let idx = 0;
function replenish() {
//console.log('replenish')
if (running >= limit || awaiting || done) return;
//console.log('replenish awaiting')
awaiting = true;
generator.next().then(({ value, done: iterDone }) => {
//console.log('got value', value)
if (canceled || done) return;
awaiting = false;
if (iterDone) {
done = true;
if (running <= 0) {
//console.log('done nextCb')
callback(null);
}
return;
}
running++;
iteratee(value, idx, iterateeCallback);
idx++;
replenish();
}).catch(handleError);
}
function iterateeCallback(err, result) {
//console.log('iterateeCallback')
running -= 1;
if (canceled) return;
if (err) return handleError(err);
if (err === false) {
done = true;
canceled = true;
return;
}
if (result === _breakLoop2.default || done && running <= 0) {
done = true;
//console.log('done iterCb')
return callback(null);
}
replenish();
}
function handleError(err) {
if (canceled) return;
awaiting = false;
done = true;
callback(err);
}
replenish();
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = awaitify;
// conditionally promisify a function.
// only return a promise if a callback is omitted
function awaitify(asyncFn, arity = asyncFn.length) {
if (!arity) throw new Error('arity is undefined');
function awaitable(...args) {
if (typeof args[arity - 1] === 'function') {
return asyncFn.apply(this, args);
}
return new Promise((resolve, reject) => {
args[arity - 1] = (err, ...cbArgs) => {
if (err) return reject(err);
resolve(cbArgs.length > 1 ? cbArgs : cbArgs[0]);
};
asyncFn.apply(this, args);
});
}
return awaitable;
}
module.exports = exports['default'];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// A temporary value used to identify if the loop should be broken.
// See #1064, #1293
const breakLoop = {};
exports.default = breakLoop;
module.exports = exports["default"];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = consoleFunc;
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function consoleFunc(name) {
return (fn, ...args) => (0, _wrapAsync2.default)(fn)(...args, (err, ...resultArgs) => {
/* istanbul ignore else */
if (typeof console === 'object') {
/* istanbul ignore else */
if (err) {
/* istanbul ignore else */
if (console.error) {
console.error(err);
}
} else if (console[name]) {
/* istanbul ignore else */
resultArgs.forEach(x => console[name](x));
}
}
});
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _createTester;
var _breakLoop = require('./breakLoop.js');
var _breakLoop2 = _interopRequireDefault(_breakLoop);
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createTester(check, getResult) {
return (eachfn, arr, _iteratee, cb) => {
var testPassed = false;
var testResult;
const iteratee = (0, _wrapAsync2.default)(_iteratee);
eachfn(arr, (value, _, callback) => {
iteratee(value, (err, result) => {
if (err || err === false) return callback(err);
if (check(result) && !testResult) {
testPassed = true;
testResult = getResult(true, value);
return callback(null, _breakLoop2.default);
}
callback();
});
}, err => {
if (err) return cb(err);
cb(null, testPassed ? testResult : getResult(false));
});
};
}
module.exports = exports['default'];
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment