'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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _once = require('./once.js');
var _once2 = _interopRequireDefault(_once);
var _iterator = require('./iterator.js');
var _iterator2 = _interopRequireDefault(_iterator);
var _onlyOnce = require('./onlyOnce.js');
var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
var _wrapAsync = require('./wrapAsync.js');
var _asyncEachOfLimit = require('./asyncEachOfLimit.js');
var _asyncEachOfLimit2 = _interopRequireDefault(_asyncEachOfLimit);
var _breakLoop = require('./breakLoop.js');
var _breakLoop2 = _interopRequireDefault(_breakLoop);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = limit => {
return (obj, iteratee, callback) => {
callback = (0, _once2.default)(callback);
if (limit <= 0) {
throw new RangeError('concurrency limit cannot be less than 1');
}
if (!obj) {
return callback(null);
}
if ((0, _wrapAsync.isAsyncGenerator)(obj)) {
return (0, _asyncEachOfLimit2.default)(obj, limit, iteratee, callback);
}
if ((0, _wrapAsync.isAsyncIterable)(obj)) {
return (0, _asyncEachOfLimit2.default)(obj[Symbol.asyncIterator](), limit, iteratee, callback);
}
var nextElem = (0, _iterator2.default)(obj);
var done = false;
var canceled = false;
var running = 0;
var looping = false;
function iterateeCallback(err, value) {
if (canceled) return;
running -= 1;
if (err) {
done = true;
callback(err);
} else if (err === false) {
done = true;
canceled = true;
} else if (value === _breakLoop2.default || done && running <= 0) {
done = true;
return callback(null);
} else if (!looping) {
replenish();
}
}
function replenish() {
looping = true;
while (running < limit && !done) {
var elem = nextElem();
if (elem === null) {
done = true;
if (running <= 0) {
callback(null);
}
return;
}
running += 1;
iteratee(elem.value, elem.key, (0, _onlyOnce2.default)(iterateeCallback));
}
looping = false;
}
replenish();
};
};
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _filter;
var _isArrayLike = require('./isArrayLike.js');
var _isArrayLike2 = _interopRequireDefault(_isArrayLike);
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function filterArray(eachfn, arr, iteratee, callback) {
var truthValues = new Array(arr.length);
eachfn(arr, (x, index, iterCb) => {
iteratee(x, (err, v) => {
truthValues[index] = !!v;
iterCb(err);
});
}, err => {
if (err) return callback(err);
var results = [];
for (var i = 0; i < arr.length; i++) {
if (truthValues[i]) results.push(arr[i]);
}
callback(null, results);
});
}
function filterGeneric(eachfn, coll, iteratee, callback) {
var results = [];
eachfn(coll, (x, index, iterCb) => {
iteratee(x, (err, v) => {
if (err) return iterCb(err);
if (v) {
results.push({ index, value: x });
}
iterCb(err);
});
}, err => {
if (err) return callback(err);
callback(null, results.sort((a, b) => a.index - b.index).map(v => v.value));
});
}
function _filter(eachfn, coll, iteratee, callback) {
var filter = (0, _isArrayLike2.default)(coll) ? filterArray : filterGeneric;
return filter(eachfn, coll, (0, _wrapAsync2.default)(iteratee), callback);
}
module.exports = exports['default'];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (coll) {
return coll[Symbol.iterator] && coll[Symbol.iterator]();
};
module.exports = exports["default"];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (fn) {
return function (...args /*, callback*/) {
var callback = args.pop();
return fn.call(this, args, callback);
};
};
module.exports = exports["default"];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isArrayLike;
function isArrayLike(value) {
return value && typeof value.length === 'number' && value.length >= 0 && value.length % 1 === 0;
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createIterator;
var _isArrayLike = require('./isArrayLike.js');
var _isArrayLike2 = _interopRequireDefault(_isArrayLike);
var _getIterator = require('./getIterator.js');
var _getIterator2 = _interopRequireDefault(_getIterator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createArrayIterator(coll) {
var i = -1;
var len = coll.length;
return function next() {
return ++i < len ? { value: coll[i], key: i } : null;
};
}
function createES2015Iterator(iterator) {
var i = -1;
return function next() {
var item = iterator.next();
if (item.done) return null;
i++;
return { value: item.value, key: i };
};
}
function createObjectIterator(obj) {
var okeys = obj ? Object.keys(obj) : [];
var i = -1;
var len = okeys.length;
return function next() {
var key = okeys[++i];
if (key === '__proto__') {
return next();
}
return i < len ? { value: obj[key], key } : null;
};
}
function createIterator(coll) {
if ((0, _isArrayLike2.default)(coll)) {
return createArrayIterator(coll);
}
var iterator = (0, _getIterator2.default)(coll);
return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _asyncMap;
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncMap(eachfn, arr, iteratee, callback) {
arr = arr || [];
var results = [];
var counter = 0;
var _iteratee = (0, _wrapAsync2.default)(iteratee);
return eachfn(arr, (value, _, iterCb) => {
var index = counter++;
_iteratee(value, (err, v) => {
results[index] = v;
iterCb(err);
});
}, err => {
callback(err, results);
});
}
module.exports = exports['default'];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = once;
function once(fn) {
function wrapper(...args) {
if (fn === null) return;
var callFn = fn;
fn = null;
callFn.apply(this, args);
}
Object.assign(wrapper, fn);
return wrapper;
}
module.exports = exports["default"];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = onlyOnce;
function onlyOnce(fn) {
return function (...args) {
if (fn === null) throw new Error("Callback was already called.");
var callFn = fn;
fn = null;
callFn.apply(this, args);
};
}
module.exports = exports["default"];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _isArrayLike = require('./isArrayLike.js');
var _isArrayLike2 = _interopRequireDefault(_isArrayLike);
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 }; }
exports.default = (0, _awaitify2.default)((eachfn, tasks, callback) => {
var results = (0, _isArrayLike2.default)(tasks) ? [] : {};
eachfn(tasks, (task, key, taskCb) => {
(0, _wrapAsync2.default)(task)((err, ...result) => {
if (result.length < 2) {
[result] = result;
}
results[key] = result;
taskCb(err);
});
}, err => callback(err, results));
}, 3);
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
const PROMISE_SYMBOL = Symbol('promiseCallback');
function promiseCallback() {
let resolve, reject;
function callback(err, ...args) {
if (err) return reject(err);
resolve(args.length > 1 ? args : args[0]);
}
callback[PROMISE_SYMBOL] = new Promise((res, rej) => {
resolve = res, reject = rej;
});
return callback;
}
exports.promiseCallback = promiseCallback;
exports.PROMISE_SYMBOL = PROMISE_SYMBOL;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = queue;
var _onlyOnce = require('./onlyOnce.js');
var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
var _setImmediate = require('./setImmediate.js');
var _setImmediate2 = _interopRequireDefault(_setImmediate);
var _DoublyLinkedList = require('./DoublyLinkedList.js');
var _DoublyLinkedList2 = _interopRequireDefault(_DoublyLinkedList);
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function queue(worker, concurrency, payload) {
if (concurrency == null) {
concurrency = 1;
} else if (concurrency === 0) {
throw new RangeError('Concurrency must not be zero');
}
var _worker = (0, _wrapAsync2.default)(worker);
var numRunning = 0;
var workersList = [];
const events = {
error: [],
drain: [],
saturated: [],
unsaturated: [],
empty: []
};
function on(event, handler) {
events[event].push(handler);
}
function once(event, handler) {
const handleAndRemove = (...args) => {
off(event, handleAndRemove);
handler(...args);
};
events[event].push(handleAndRemove);
}
function off(event, handler) {
if (!event) return Object.keys(events).forEach(ev => events[ev] = []);
if (!handler) return events[event] = [];
events[event] = events[event].filter(ev => ev !== handler);
}
function trigger(event, ...args) {
events[event].forEach(handler => handler(...args));
}
var processingScheduled = false;
function _insert(data, insertAtFront, rejectOnError, callback) {
if (callback != null && typeof callback !== 'function') {
throw new Error('task callback must be a function');
}
q.started = true;
var res, rej;
function promiseCallback(err, ...args) {
// we don't care about the error, let the global error handler
// deal with it
if (err) return rejectOnError ? rej(err) : res();
if (args.length <= 1) return res(args[0]);
res(args);
}
var item = q._createTaskItem(data, rejectOnError ? promiseCallback : callback || promiseCallback);
if (insertAtFront) {
q._tasks.unshift(item);
} else {
q._tasks.push(item);
}
if (!processingScheduled) {
processingScheduled = true;
(0, _setImmediate2.default)(() => {
processingScheduled = false;
q.process();
});
}
if (rejectOnError || !callback) {
return new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
}
}
function _createCB(tasks) {
return function (err, ...args) {
numRunning -= 1;
for (var i = 0, l = tasks.length; i < l; i++) {
var task = tasks[i];
var index = workersList.indexOf(task);
if (index === 0) {
workersList.shift();
} else if (index > 0) {
workersList.splice(index, 1);
}
task.callback(err, ...args);
if (err != null) {
trigger('error', err, task.data);
}
}
if (numRunning <= q.concurrency - q.buffer) {
trigger('unsaturated');
}
if (q.idle()) {
trigger('drain');
}
q.process();
};
}
function _maybeDrain(data) {
if (data.length === 0 && q.idle()) {
// call drain immediately if there are no tasks
(0, _setImmediate2.default)(() => trigger('drain'));
return true;
}
return false;
}
const eventMethod = name => handler => {
if (!handler) {
return new Promise((resolve, reject) => {
once(name, (err, data) => {
if (err) return reject(err);
resolve(data);
});
});
}
off(name);
on(name, handler);
};
var isProcessing = false;
var q = {
_tasks: new _DoublyLinkedList2.default(),
_createTaskItem(data, callback) {
return {
data,
callback
};
},
*[Symbol.iterator]() {
yield* q._tasks[Symbol.iterator]();
},
concurrency,
payload,
buffer: concurrency / 4,
started: false,
paused: false,
push(data, callback) {
if (Array.isArray(data)) {
if (_maybeDrain(data)) return;
return data.map(datum => _insert(datum, false, false, callback));
}
return _insert(data, false, false, callback);
},
pushAsync(data, callback) {
if (Array.isArray(data)) {
if (_maybeDrain(data)) return;
return data.map(datum => _insert(datum, false, true, callback));
}
return _insert(data, false, true, callback);
},
kill() {
off();
q._tasks.empty();
},
unshift(data, callback) {
if (Array.isArray(data)) {
if (_maybeDrain(data)) return;
return data.map(datum => _insert(datum, true, false, callback));
}
return _insert(data, true, false, callback);
},
unshiftAsync(data, callback) {
if (Array.isArray(data)) {
if (_maybeDrain(data)) return;
return data.map(datum => _insert(datum, true, true, callback));
}
return _insert(data, true, true, callback);
},
remove(testFn) {
q._tasks.remove(testFn);
},
process() {
// Avoid trying to start too many processing operations. This can occur
// when callbacks resolve synchronously (#1267).
if (isProcessing) {
return;
}
isProcessing = true;
while (!q.paused && numRunning < q.concurrency && q._tasks.length) {
var tasks = [],
data = [];
var l = q._tasks.length;
if (q.payload) l = Math.min(l, q.payload);
for (var i = 0; i < l; i++) {
var node = q._tasks.shift();
tasks.push(node);
workersList.push(node);
data.push(node.data);
}
numRunning += 1;
if (q._tasks.length === 0) {
trigger('empty');
}
if (numRunning === q.concurrency) {
trigger('saturated');
}
var cb = (0, _onlyOnce2.default)(_createCB(tasks));
_worker(data, cb);
}
isProcessing = false;
},
length() {
return q._tasks.length;
},
running() {
return numRunning;
},
workersList() {
return workersList;
},
idle() {
return q._tasks.length + numRunning === 0;
},
pause() {
q.paused = true;
},
resume() {
if (q.paused === false) {
return;
}
q.paused = false;
(0, _setImmediate2.default)(q.process);
}
};
// define these as fixed properties, so people get useful errors when updating
Object.defineProperties(q, {
saturated: {
writable: false,
value: eventMethod('saturated')
},
unsaturated: {
writable: false,
value: eventMethod('unsaturated')
},
empty: {
writable: false,
value: eventMethod('empty')
},
drain: {
writable: false,
value: eventMethod('drain')
},
error: {
writable: false,
value: eventMethod('error')
}
});
return q;
}
module.exports = exports['default'];
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = range;
function range(size) {
var result = Array(size);
while (size--) {
result[size] = size;
}
return result;
}
module.exports = exports["default"];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = reject;
var _filter = require('./filter.js');
var _filter2 = _interopRequireDefault(_filter);
var _wrapAsync = require('./wrapAsync.js');
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function reject(eachfn, arr, _iteratee, callback) {
const iteratee = (0, _wrapAsync2.default)(_iteratee);
return (0, _filter2.default)(eachfn, arr, (value, cb) => {
iteratee(value, (err, v) => {
cb(err, !v);
});
}, callback);
}
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fallback = fallback;
exports.wrap = wrap;
/* istanbul ignore file */
var hasQueueMicrotask = exports.hasQueueMicrotask = typeof queueMicrotask === 'function' && queueMicrotask;
var hasSetImmediate = exports.hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
var hasNextTick = exports.hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
function fallback(fn) {
setTimeout(fn, 0);
}
function wrap(defer) {
return (fn, ...args) => defer(() => fn(...args));
}
var _defer;
if (hasQueueMicrotask) {
_defer = queueMicrotask;
} else if (hasSetImmediate) {
_defer = setImmediate;
} else if (hasNextTick) {
_defer = process.nextTick;
} else {
_defer = fallback;
}
exports.default = wrap(_defer);
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _withoutIndex;
function _withoutIndex(iteratee) {
return (value, index, callback) => iteratee(value, callback);
}
module.exports = exports["default"];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isAsyncIterable = exports.isAsyncGenerator = exports.isAsync = undefined;
var _asyncify = require('../asyncify.js');
var _asyncify2 = _interopRequireDefault(_asyncify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isAsync(fn) {
return fn[Symbol.toStringTag] === 'AsyncFunction';
}
function isAsyncGenerator(fn) {
return fn[Symbol.toStringTag] === 'AsyncGenerator';
}
function isAsyncIterable(obj) {
return typeof obj[Symbol.asyncIterator] === 'function';
}
function wrapAsync(asyncFn) {
if (typeof asyncFn !== 'function') throw new Error('expected a function');
return isAsync(asyncFn) ? (0, _asyncify2.default)(asyncFn) : asyncFn;
}
exports.default = wrapAsync;
exports.isAsync = isAsync;
exports.isAsyncGenerator = isAsyncGenerator;
exports.isAsyncIterable = isAsyncIterable;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _consoleFunc = require('./internal/consoleFunc.js');
var _consoleFunc2 = _interopRequireDefault(_consoleFunc);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Logs the result of an `async` function to the `console`. Only works in
* Node.js or in browsers that support `console.log` and `console.error` (such
* as FF and Chrome). If multiple arguments are returned from the async
* function, `console.log` is called on each argument in order.
*
* @name log
* @static
* @memberOf module:Utils
* @method
* @category Util
* @param {AsyncFunction} function - The function you want to eventually apply
* all arguments to.
* @param {...*} arguments... - Any number of arguments to apply to the function.
* @example
*
* // in a module
* var hello = function(name, callback) {
* setTimeout(function() {
* callback(null, 'hello ' + name);
* }, 1000);
* };
*
* // in the node repl
* node> async.log(hello, 'world');
* 'hello world'
*/
exports.default = (0, _consoleFunc2.default)('log');
module.exports = exports['default'];
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _map2 = require('./internal/map.js');
var _map3 = _interopRequireDefault(_map2);
var _eachOf = require('./eachOf.js');
var _eachOf2 = _interopRequireDefault(_eachOf);
var _awaitify = require('./internal/awaitify.js');
var _awaitify2 = _interopRequireDefault(_awaitify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Produces a new collection of values by mapping each value in `coll` through
* the `iteratee` function. The `iteratee` is called with an item from `coll`
* and a callback for when it has finished processing. Each of these callbacks
* takes 2 arguments: an `error`, and the transformed item from `coll`. If
* `iteratee` passes an error to its callback, the main `callback` (for the
* `map` function) is immediately called with the error.
*
* Note, that 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 results array will be in the same order as the
* original `coll`.
*
* If `map` is passed an Object, the results will be an Array. The results
* will roughly be in the order of the original Objects' keys (but this can
* vary across JavaScript engines).
*
* @name map
* @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 the transformed item.
* Invoked with (item, callback).
* @param {Function} [callback] - A callback which is called when all `iteratee`
* functions have finished, or an error occurs. Results is an Array of the
* transformed items from the `coll`. Invoked with (err, results).
* @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','file4.txt'];
*
* // asynchronous function that returns the file size in bytes
* function getFileSizeInBytes(file, callback) {
* fs.stat(file, function(err, stat) {
* if (err) {
* return callback(err);
* }
* callback(null, stat.size);
* });
* }
*
* // Using callbacks
* async.map(fileList, getFileSizeInBytes, function(err, results) {
* if (err) {
* console.log(err);
* } else {
* console.log(results);
* // results is now an array of the file size in bytes for each file, e.g.
* // [ 1000, 2000, 3000]
* }
* });
*
* // Error Handling
* async.map(withMissingFileList, getFileSizeInBytes, function(err, results) {
* if (err) {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* } else {
* console.log(results);
* }
* });
*
* // Using Promises
* async.map(fileList, getFileSizeInBytes)
* .then( results => {
* console.log(results);
* // results is now an array of the file size in bytes for each file, e.g.
* // [ 1000, 2000, 3000]
* }).catch( err => {
* console.log(err);
* });
*
* // Error Handling
* async.map(withMissingFileList, getFileSizeInBytes)
* .then( results => {
* console.log(results);
* }).catch( err => {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* });
*
* // Using async/await
* async () => {
* try {
* let results = await async.map(fileList, getFileSizeInBytes);
* console.log(results);
* // results is now an array of the file size in bytes for each file, e.g.
* // [ 1000, 2000, 3000]
* }
* catch (err) {
* console.log(err);
* }
* }
*
* // Error Handling
* async () => {
* try {
* let results = await async.map(withMissingFileList, getFileSizeInBytes);
* console.log(results);
* }
* catch (err) {
* console.log(err);
* // [ Error: ENOENT: no such file or directory ]
* }
* }
*
*/
function map(coll, iteratee, callback) {
return (0, _map3.default)(_eachOf2.default, coll, iteratee, callback);
}
exports.default = (0, _awaitify2.default)(map, 3);
module.exports = exports['default'];
\ No newline at end of file