precedent 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,318 +1,3978 @@
1
- (function (f) {
2
- if (typeof exports === "object" && typeof module !== "undefined") {
3
- module.exports = f();
4
- } else if (typeof define === "function" && define.amd) {
5
- define([], f);
6
- } else {
7
- var g;
8
- if (typeof window !== "undefined") {
9
- g = window;
10
- } else if (typeof global !== "undefined") {
11
- g = global;
12
- } else if (typeof self !== "undefined") {
13
- g = self;
14
- } else {
15
- g = this;
16
- }
17
- g.Precedent = f();
18
- }
19
- })(function () {
20
- var define, module, exports;
21
- return function () {
22
- function r(e, n, t) {
23
- function o(i, f) {
24
- if (!n[i]) {
25
- if (!e[i]) {
26
- var c = "function" == typeof require && require;
27
- if (!f && c) return c(i, !0);
28
- if (u) return u(i, !0);
29
- var a = new Error("Cannot find module '" + i + "'");
30
- throw a.code = "MODULE_NOT_FOUND", a;
31
- }
32
- var p = n[i] = {
33
- exports: {}
34
- };
35
- e[i][0].call(p.exports, function (r) {
36
- var n = e[i][1][r];
37
- return o(n || r);
38
- }, p, p.exports, r, e, n, t);
39
- }
40
- return n[i].exports;
41
- }
42
- for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
43
- return o;
44
- }
45
- return r;
46
- }()({
47
- 1: [function (require, module, exports) {
48
- /**
49
- * Simple browser shim loader - assign the npm module to a window global automatically
50
- *
51
- * @author <steven@velozo.com>
52
- */
53
- var libNPMModuleWrapper = require('./Precedent.js');
54
- if (typeof window == 'object' && !window.hasOwnProperty('Precedent')) {
55
- window.Precedent = libNPMModuleWrapper;
56
- }
57
- module.exports = libNPMModuleWrapper;
58
- }, {
59
- "./Precedent.js": 2
60
- }],
61
- 2: [function (require, module, exports) {
62
- /**
63
- * Precedent Meta-Templating
64
- *
65
- * @license MIT
66
- *
67
- * @author Steven Velozo <steven@velozo.com>
68
- *
69
- * @description Process text streams, parsing out meta-template expressions.
70
- */
71
- var libWordTree = require(`./WordTree.js`);
72
- var libStringParser = require(`./StringParser.js`);
73
- class Precedent {
74
- /**
75
- * Precedent Constructor
76
- */
77
- constructor() {
78
- this.WordTree = new libWordTree();
79
- this.StringParser = new libStringParser();
80
- this.ParseTree = this.WordTree.ParseTree;
81
- }
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f();}else if(typeof define==="function"&&define.amd){define([],f);}else{var g;if(typeof window!=="undefined"){g=window;}else if(typeof global!=="undefined"){g=global;}else if(typeof self!=="undefined"){g=self;}else{g=this;}g.Precedent=f();}})(function(){var define,module,exports;return 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,setImmediate){(function(){(function(global,factory){typeof exports==='object'&&typeof module!=='undefined'?factory(exports):typeof define==='function'&&define.amd?define(['exports'],factory):factory(global.async={});})(this,function(exports){'use strict';/**
2
+ * Creates a continuation function with some arguments already applied.
3
+ *
4
+ * Useful as a shorthand when combined with other control flow functions. Any
5
+ * arguments passed to the returned function are added to the arguments
6
+ * originally passed to apply.
7
+ *
8
+ * @name apply
9
+ * @static
10
+ * @memberOf module:Utils
11
+ * @method
12
+ * @category Util
13
+ * @param {Function} fn - The function you want to eventually apply all
14
+ * arguments to. Invokes with (arguments...).
15
+ * @param {...*} arguments... - Any number of arguments to automatically apply
16
+ * when the continuation is called.
17
+ * @returns {Function} the partially-applied function
18
+ * @example
19
+ *
20
+ * // using apply
21
+ * async.parallel([
22
+ * async.apply(fs.writeFile, 'testfile1', 'test1'),
23
+ * async.apply(fs.writeFile, 'testfile2', 'test2')
24
+ * ]);
25
+ *
26
+ *
27
+ * // the same process without using apply
28
+ * async.parallel([
29
+ * function(callback) {
30
+ * fs.writeFile('testfile1', 'test1', callback);
31
+ * },
32
+ * function(callback) {
33
+ * fs.writeFile('testfile2', 'test2', callback);
34
+ * }
35
+ * ]);
36
+ *
37
+ * // It's possible to pass any number of additional arguments when calling the
38
+ * // continuation:
39
+ *
40
+ * node> var fn = async.apply(sys.puts, 'one');
41
+ * node> fn('two', 'three');
42
+ * one
43
+ * two
44
+ * three
45
+ */function apply(fn,...args){return(...callArgs)=>fn(...args,...callArgs);}function initialParams(fn){return function(...args/*, callback*/){var callback=args.pop();return fn.call(this,args,callback);};}/* istanbul ignore file */var hasQueueMicrotask=typeof queueMicrotask==='function'&&queueMicrotask;var hasSetImmediate=typeof setImmediate==='function'&&setImmediate;var 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;}var setImmediate$1=wrap(_defer);/**
46
+ * Take a sync function and make it async, passing its return value to a
47
+ * callback. This is useful for plugging sync functions into a waterfall,
48
+ * series, or other async functions. Any arguments passed to the generated
49
+ * function will be passed to the wrapped function (except for the final
50
+ * callback argument). Errors thrown will be passed to the callback.
51
+ *
52
+ * If the function passed to `asyncify` returns a Promise, that promises's
53
+ * resolved/rejected state will be used to call the callback, rather than simply
54
+ * the synchronous return value.
55
+ *
56
+ * This also means you can asyncify ES2017 `async` functions.
57
+ *
58
+ * @name asyncify
59
+ * @static
60
+ * @memberOf module:Utils
61
+ * @method
62
+ * @alias wrapSync
63
+ * @category Util
64
+ * @param {Function} func - The synchronous function, or Promise-returning
65
+ * function to convert to an {@link AsyncFunction}.
66
+ * @returns {AsyncFunction} An asynchronous wrapper of the `func`. To be
67
+ * invoked with `(args..., callback)`.
68
+ * @example
69
+ *
70
+ * // passing a regular synchronous function
71
+ * async.waterfall([
72
+ * async.apply(fs.readFile, filename, "utf8"),
73
+ * async.asyncify(JSON.parse),
74
+ * function (data, next) {
75
+ * // data is the result of parsing the text.
76
+ * // If there was a parsing error, it would have been caught.
77
+ * }
78
+ * ], callback);
79
+ *
80
+ * // passing a function returning a promise
81
+ * async.waterfall([
82
+ * async.apply(fs.readFile, filename, "utf8"),
83
+ * async.asyncify(function (contents) {
84
+ * return db.model.create(contents);
85
+ * }),
86
+ * function (model, next) {
87
+ * // `model` is the instantiated model object.
88
+ * // If there was an error, this function would be skipped.
89
+ * }
90
+ * ], callback);
91
+ *
92
+ * // es2017 example, though `asyncify` is not needed if your JS environment
93
+ * // supports async functions out of the box
94
+ * var q = async.queue(async.asyncify(async function(file) {
95
+ * var intermediateStep = await processFile(file);
96
+ * return await somePromise(intermediateStep)
97
+ * }));
98
+ *
99
+ * q.push(files);
100
+ */function asyncify(func){if(isAsync(func)){return function(...args/*, callback*/){const callback=args.pop();const promise=func.apply(this,args);return handlePromise(promise,callback);};}return initialParams(function(args,callback){var result;try{result=func.apply(this,args);}catch(e){return callback(e);}// if result is Promise object
101
+ if(result&&typeof result.then==='function'){return handlePromise(result,callback);}else{callback(null,result);}});}function handlePromise(promise,callback){return promise.then(value=>{invokeCallback(callback,null,value);},err=>{invokeCallback(callback,err&&err.message?err:new Error(err));});}function invokeCallback(callback,error,value){try{callback(error,value);}catch(err){setImmediate$1(e=>{throw e;},err);}}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)?asyncify(asyncFn):asyncFn;}// conditionally promisify a function.
102
+ // only return a promise if a callback is omitted
103
+ 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;}function applyEach(eachfn){return function applyEach(fns,...callArgs){const go=awaitify(function(callback){var that=this;return eachfn(fns,(fn,cb)=>{wrapAsync(fn).apply(that,callArgs.concat(cb));},callback);});return go;};}function _asyncMap(eachfn,arr,iteratee,callback){arr=arr||[];var results=[];var counter=0;var _iteratee=wrapAsync(iteratee);return eachfn(arr,(value,_,iterCb)=>{var index=counter++;_iteratee(value,(err,v)=>{results[index]=v;iterCb(err);});},err=>{callback(err,results);});}function isArrayLike(value){return value&&typeof value.length==='number'&&value.length>=0&&value.length%1===0;}// A temporary value used to identify if the loop should be broken.
104
+ // See #1064, #1293
105
+ const breakLoop={};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;}function getIterator(coll){return coll[Symbol.iterator]&&coll[Symbol.iterator]();}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(isArrayLike(coll)){return createArrayIterator(coll);}var iterator=getIterator(coll);return iterator?createES2015Iterator(iterator):createObjectIterator(coll);}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);};}// for async generators
106
+ 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')
107
+ if(running>=limit||awaiting||done)return;//console.log('replenish awaiting')
108
+ awaiting=true;generator.next().then(({value,done:iterDone})=>{//console.log('got value', value)
109
+ if(canceled||done)return;awaiting=false;if(iterDone){done=true;if(running<=0){//console.log('done nextCb')
110
+ callback(null);}return;}running++;iteratee(value,idx,iterateeCallback);idx++;replenish();}).catch(handleError);}function iterateeCallback(err,result){//console.log('iterateeCallback')
111
+ running-=1;if(canceled)return;if(err)return handleError(err);if(err===false){done=true;canceled=true;return;}if(result===breakLoop||done&&running<=0){done=true;//console.log('done iterCb')
112
+ return callback(null);}replenish();}function handleError(err){if(canceled)return;awaiting=false;done=true;callback(err);}replenish();}var eachOfLimit=limit=>{return(obj,iteratee,callback)=>{callback=once(callback);if(limit<=0){throw new RangeError('concurrency limit cannot be less than 1');}if(!obj){return callback(null);}if(isAsyncGenerator(obj)){return asyncEachOfLimit(obj,limit,iteratee,callback);}if(isAsyncIterable(obj)){return asyncEachOfLimit(obj[Symbol.asyncIterator](),limit,iteratee,callback);}var nextElem=createIterator(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===breakLoop||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,onlyOnce(iterateeCallback));}looping=false;}replenish();};};/**
113
+ * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
114
+ * time.
115
+ *
116
+ * @name eachOfLimit
117
+ * @static
118
+ * @memberOf module:Collections
119
+ * @method
120
+ * @see [async.eachOf]{@link module:Collections.eachOf}
121
+ * @alias forEachOfLimit
122
+ * @category Collection
123
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
124
+ * @param {number} limit - The maximum number of async operations at a time.
125
+ * @param {AsyncFunction} iteratee - An async function to apply to each
126
+ * item in `coll`. The `key` is the item's key, or index in the case of an
127
+ * array.
128
+ * Invoked with (item, key, callback).
129
+ * @param {Function} [callback] - A callback which is called when all
130
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
131
+ * @returns {Promise} a promise, if a callback is omitted
132
+ */function eachOfLimit$1(coll,limit,iteratee,callback){return eachOfLimit(limit)(coll,wrapAsync(iteratee),callback);}var eachOfLimit$2=awaitify(eachOfLimit$1,4);// eachOf implementation optimized for array-likes
133
+ function eachOfArrayLike(coll,iteratee,callback){callback=once(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===breakLoop){callback(null);}}for(;index<length;index++){iteratee(coll[index],index,onlyOnce(iteratorCallback));}}// a generic version of eachOf which can handle array, object, and iterator cases.
134
+ function eachOfGeneric(coll,iteratee,callback){return eachOfLimit$2(coll,Infinity,iteratee,callback);}/**
135
+ * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
136
+ * to the iteratee.
137
+ *
138
+ * @name eachOf
139
+ * @static
140
+ * @memberOf module:Collections
141
+ * @method
142
+ * @alias forEachOf
143
+ * @category Collection
144
+ * @see [async.each]{@link module:Collections.each}
145
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
146
+ * @param {AsyncFunction} iteratee - A function to apply to each
147
+ * item in `coll`.
148
+ * The `key` is the item's key, or index in the case of an array.
149
+ * Invoked with (item, key, callback).
150
+ * @param {Function} [callback] - A callback which is called when all
151
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
152
+ * @returns {Promise} a promise, if a callback is omitted
153
+ * @example
154
+ *
155
+ * // dev.json is a file containing a valid json object config for dev environment
156
+ * // dev.json is a file containing a valid json object config for test environment
157
+ * // prod.json is a file containing a valid json object config for prod environment
158
+ * // invalid.json is a file with a malformed json object
159
+ *
160
+ * let configs = {}; //global variable
161
+ * let validConfigFileMap = {dev: 'dev.json', test: 'test.json', prod: 'prod.json'};
162
+ * let invalidConfigFileMap = {dev: 'dev.json', test: 'test.json', invalid: 'invalid.json'};
163
+ *
164
+ * // asynchronous function that reads a json file and parses the contents as json object
165
+ * function parseFile(file, key, callback) {
166
+ * fs.readFile(file, "utf8", function(err, data) {
167
+ * if (err) return calback(err);
168
+ * try {
169
+ * configs[key] = JSON.parse(data);
170
+ * } catch (e) {
171
+ * return callback(e);
172
+ * }
173
+ * callback();
174
+ * });
175
+ * }
176
+ *
177
+ * // Using callbacks
178
+ * async.forEachOf(validConfigFileMap, parseFile, function (err) {
179
+ * if (err) {
180
+ * console.error(err);
181
+ * } else {
182
+ * console.log(configs);
183
+ * // configs is now a map of JSON data, e.g.
184
+ * // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
185
+ * }
186
+ * });
187
+ *
188
+ * //Error handing
189
+ * async.forEachOf(invalidConfigFileMap, parseFile, function (err) {
190
+ * if (err) {
191
+ * console.error(err);
192
+ * // JSON parse error exception
193
+ * } else {
194
+ * console.log(configs);
195
+ * }
196
+ * });
197
+ *
198
+ * // Using Promises
199
+ * async.forEachOf(validConfigFileMap, parseFile)
200
+ * .then( () => {
201
+ * console.log(configs);
202
+ * // configs is now a map of JSON data, e.g.
203
+ * // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
204
+ * }).catch( err => {
205
+ * console.error(err);
206
+ * });
207
+ *
208
+ * //Error handing
209
+ * async.forEachOf(invalidConfigFileMap, parseFile)
210
+ * .then( () => {
211
+ * console.log(configs);
212
+ * }).catch( err => {
213
+ * console.error(err);
214
+ * // JSON parse error exception
215
+ * });
216
+ *
217
+ * // Using async/await
218
+ * async () => {
219
+ * try {
220
+ * let result = await async.forEachOf(validConfigFileMap, parseFile);
221
+ * console.log(configs);
222
+ * // configs is now a map of JSON data, e.g.
223
+ * // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
224
+ * }
225
+ * catch (err) {
226
+ * console.log(err);
227
+ * }
228
+ * }
229
+ *
230
+ * //Error handing
231
+ * async () => {
232
+ * try {
233
+ * let result = await async.forEachOf(invalidConfigFileMap, parseFile);
234
+ * console.log(configs);
235
+ * }
236
+ * catch (err) {
237
+ * console.log(err);
238
+ * // JSON parse error exception
239
+ * }
240
+ * }
241
+ *
242
+ */function eachOf(coll,iteratee,callback){var eachOfImplementation=isArrayLike(coll)?eachOfArrayLike:eachOfGeneric;return eachOfImplementation(coll,wrapAsync(iteratee),callback);}var eachOf$1=awaitify(eachOf,3);/**
243
+ * Produces a new collection of values by mapping each value in `coll` through
244
+ * the `iteratee` function. The `iteratee` is called with an item from `coll`
245
+ * and a callback for when it has finished processing. Each of these callbacks
246
+ * takes 2 arguments: an `error`, and the transformed item from `coll`. If
247
+ * `iteratee` passes an error to its callback, the main `callback` (for the
248
+ * `map` function) is immediately called with the error.
249
+ *
250
+ * Note, that since this function applies the `iteratee` to each item in
251
+ * parallel, there is no guarantee that the `iteratee` functions will complete
252
+ * in order. However, the results array will be in the same order as the
253
+ * original `coll`.
254
+ *
255
+ * If `map` is passed an Object, the results will be an Array. The results
256
+ * will roughly be in the order of the original Objects' keys (but this can
257
+ * vary across JavaScript engines).
258
+ *
259
+ * @name map
260
+ * @static
261
+ * @memberOf module:Collections
262
+ * @method
263
+ * @category Collection
264
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
265
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
266
+ * `coll`.
267
+ * The iteratee should complete with the transformed item.
268
+ * Invoked with (item, callback).
269
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
270
+ * functions have finished, or an error occurs. Results is an Array of the
271
+ * transformed items from the `coll`. Invoked with (err, results).
272
+ * @returns {Promise} a promise, if no callback is passed
273
+ * @example
274
+ *
275
+ * // file1.txt is a file that is 1000 bytes in size
276
+ * // file2.txt is a file that is 2000 bytes in size
277
+ * // file3.txt is a file that is 3000 bytes in size
278
+ * // file4.txt does not exist
279
+ *
280
+ * const fileList = ['file1.txt','file2.txt','file3.txt'];
281
+ * const withMissingFileList = ['file1.txt','file2.txt','file4.txt'];
282
+ *
283
+ * // asynchronous function that returns the file size in bytes
284
+ * function getFileSizeInBytes(file, callback) {
285
+ * fs.stat(file, function(err, stat) {
286
+ * if (err) {
287
+ * return callback(err);
288
+ * }
289
+ * callback(null, stat.size);
290
+ * });
291
+ * }
292
+ *
293
+ * // Using callbacks
294
+ * async.map(fileList, getFileSizeInBytes, function(err, results) {
295
+ * if (err) {
296
+ * console.log(err);
297
+ * } else {
298
+ * console.log(results);
299
+ * // results is now an array of the file size in bytes for each file, e.g.
300
+ * // [ 1000, 2000, 3000]
301
+ * }
302
+ * });
303
+ *
304
+ * // Error Handling
305
+ * async.map(withMissingFileList, getFileSizeInBytes, function(err, results) {
306
+ * if (err) {
307
+ * console.log(err);
308
+ * // [ Error: ENOENT: no such file or directory ]
309
+ * } else {
310
+ * console.log(results);
311
+ * }
312
+ * });
313
+ *
314
+ * // Using Promises
315
+ * async.map(fileList, getFileSizeInBytes)
316
+ * .then( results => {
317
+ * console.log(results);
318
+ * // results is now an array of the file size in bytes for each file, e.g.
319
+ * // [ 1000, 2000, 3000]
320
+ * }).catch( err => {
321
+ * console.log(err);
322
+ * });
323
+ *
324
+ * // Error Handling
325
+ * async.map(withMissingFileList, getFileSizeInBytes)
326
+ * .then( results => {
327
+ * console.log(results);
328
+ * }).catch( err => {
329
+ * console.log(err);
330
+ * // [ Error: ENOENT: no such file or directory ]
331
+ * });
332
+ *
333
+ * // Using async/await
334
+ * async () => {
335
+ * try {
336
+ * let results = await async.map(fileList, getFileSizeInBytes);
337
+ * console.log(results);
338
+ * // results is now an array of the file size in bytes for each file, e.g.
339
+ * // [ 1000, 2000, 3000]
340
+ * }
341
+ * catch (err) {
342
+ * console.log(err);
343
+ * }
344
+ * }
345
+ *
346
+ * // Error Handling
347
+ * async () => {
348
+ * try {
349
+ * let results = await async.map(withMissingFileList, getFileSizeInBytes);
350
+ * console.log(results);
351
+ * }
352
+ * catch (err) {
353
+ * console.log(err);
354
+ * // [ Error: ENOENT: no such file or directory ]
355
+ * }
356
+ * }
357
+ *
358
+ */function map(coll,iteratee,callback){return _asyncMap(eachOf$1,coll,iteratee,callback);}var map$1=awaitify(map,3);/**
359
+ * Applies the provided arguments to each function in the array, calling
360
+ * `callback` after all functions have completed. If you only provide the first
361
+ * argument, `fns`, then it will return a function which lets you pass in the
362
+ * arguments as if it were a single function call. If more arguments are
363
+ * provided, `callback` is required while `args` is still optional. The results
364
+ * for each of the applied async functions are passed to the final callback
365
+ * as an array.
366
+ *
367
+ * @name applyEach
368
+ * @static
369
+ * @memberOf module:ControlFlow
370
+ * @method
371
+ * @category Control Flow
372
+ * @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s
373
+ * to all call with the same arguments
374
+ * @param {...*} [args] - any number of separate arguments to pass to the
375
+ * function.
376
+ * @param {Function} [callback] - the final argument should be the callback,
377
+ * called when all functions have completed processing.
378
+ * @returns {AsyncFunction} - Returns a function that takes no args other than
379
+ * an optional callback, that is the result of applying the `args` to each
380
+ * of the functions.
381
+ * @example
382
+ *
383
+ * const appliedFn = async.applyEach([enableSearch, updateSchema], 'bucket')
384
+ *
385
+ * appliedFn((err, results) => {
386
+ * // results[0] is the results for `enableSearch`
387
+ * // results[1] is the results for `updateSchema`
388
+ * });
389
+ *
390
+ * // partial application example:
391
+ * async.each(
392
+ * buckets,
393
+ * async (bucket) => async.applyEach([enableSearch, updateSchema], bucket)(),
394
+ * callback
395
+ * );
396
+ */var applyEach$1=applyEach(map$1);/**
397
+ * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
398
+ *
399
+ * @name eachOfSeries
400
+ * @static
401
+ * @memberOf module:Collections
402
+ * @method
403
+ * @see [async.eachOf]{@link module:Collections.eachOf}
404
+ * @alias forEachOfSeries
405
+ * @category Collection
406
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
407
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
408
+ * `coll`.
409
+ * Invoked with (item, key, callback).
410
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
411
+ * functions have finished, or an error occurs. Invoked with (err).
412
+ * @returns {Promise} a promise, if a callback is omitted
413
+ */function eachOfSeries(coll,iteratee,callback){return eachOfLimit$2(coll,1,iteratee,callback);}var eachOfSeries$1=awaitify(eachOfSeries,3);/**
414
+ * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time.
415
+ *
416
+ * @name mapSeries
417
+ * @static
418
+ * @memberOf module:Collections
419
+ * @method
420
+ * @see [async.map]{@link module:Collections.map}
421
+ * @category Collection
422
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
423
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
424
+ * `coll`.
425
+ * The iteratee should complete with the transformed item.
426
+ * Invoked with (item, callback).
427
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
428
+ * functions have finished, or an error occurs. Results is an array of the
429
+ * transformed items from the `coll`. Invoked with (err, results).
430
+ * @returns {Promise} a promise, if no callback is passed
431
+ */function mapSeries(coll,iteratee,callback){return _asyncMap(eachOfSeries$1,coll,iteratee,callback);}var mapSeries$1=awaitify(mapSeries,3);/**
432
+ * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time.
433
+ *
434
+ * @name applyEachSeries
435
+ * @static
436
+ * @memberOf module:ControlFlow
437
+ * @method
438
+ * @see [async.applyEach]{@link module:ControlFlow.applyEach}
439
+ * @category Control Flow
440
+ * @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s to all
441
+ * call with the same arguments
442
+ * @param {...*} [args] - any number of separate arguments to pass to the
443
+ * function.
444
+ * @param {Function} [callback] - the final argument should be the callback,
445
+ * called when all functions have completed processing.
446
+ * @returns {AsyncFunction} - A function, that when called, is the result of
447
+ * appling the `args` to the list of functions. It takes no args, other than
448
+ * a callback.
449
+ */var applyEachSeries=applyEach(mapSeries$1);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;}/**
450
+ * Determines the best order for running the {@link AsyncFunction}s in `tasks`, based on
451
+ * their requirements. Each function can optionally depend on other functions
452
+ * being completed first, and each function is run as soon as its requirements
453
+ * are satisfied.
454
+ *
455
+ * If any of the {@link AsyncFunction}s pass an error to their callback, the `auto` sequence
456
+ * will stop. Further tasks will not execute (so any other functions depending
457
+ * on it will not run), and the main `callback` is immediately called with the
458
+ * error.
459
+ *
460
+ * {@link AsyncFunction}s also receive an object containing the results of functions which
461
+ * have completed so far as the first argument, if they have dependencies. If a
462
+ * task function has no dependencies, it will only be passed a callback.
463
+ *
464
+ * @name auto
465
+ * @static
466
+ * @memberOf module:ControlFlow
467
+ * @method
468
+ * @category Control Flow
469
+ * @param {Object} tasks - An object. Each of its properties is either a
470
+ * function or an array of requirements, with the {@link AsyncFunction} itself the last item
471
+ * in the array. The object's key of a property serves as the name of the task
472
+ * defined by that property, i.e. can be used when specifying requirements for
473
+ * other tasks. The function receives one or two arguments:
474
+ * * a `results` object, containing the results of the previously executed
475
+ * functions, only passed if the task has any dependencies,
476
+ * * a `callback(err, result)` function, which must be called when finished,
477
+ * passing an `error` (which can be `null`) and the result of the function's
478
+ * execution.
479
+ * @param {number} [concurrency=Infinity] - An optional `integer` for
480
+ * determining the maximum number of tasks that can be run in parallel. By
481
+ * default, as many as possible.
482
+ * @param {Function} [callback] - An optional callback which is called when all
483
+ * the tasks have been completed. It receives the `err` argument if any `tasks`
484
+ * pass an error to their callback. Results are always returned; however, if an
485
+ * error occurs, no further `tasks` will be performed, and the results object
486
+ * will only contain partial results. Invoked with (err, results).
487
+ * @returns {Promise} a promise, if a callback is not passed
488
+ * @example
489
+ *
490
+ * //Using Callbacks
491
+ * async.auto({
492
+ * get_data: function(callback) {
493
+ * // async code to get some data
494
+ * callback(null, 'data', 'converted to array');
495
+ * },
496
+ * make_folder: function(callback) {
497
+ * // async code to create a directory to store a file in
498
+ * // this is run at the same time as getting the data
499
+ * callback(null, 'folder');
500
+ * },
501
+ * write_file: ['get_data', 'make_folder', function(results, callback) {
502
+ * // once there is some data and the directory exists,
503
+ * // write the data to a file in the directory
504
+ * callback(null, 'filename');
505
+ * }],
506
+ * email_link: ['write_file', function(results, callback) {
507
+ * // once the file is written let's email a link to it...
508
+ * callback(null, {'file':results.write_file, 'email':'user@example.com'});
509
+ * }]
510
+ * }, function(err, results) {
511
+ * if (err) {
512
+ * console.log('err = ', err);
513
+ * }
514
+ * console.log('results = ', results);
515
+ * // results = {
516
+ * // get_data: ['data', 'converted to array']
517
+ * // make_folder; 'folder',
518
+ * // write_file: 'filename'
519
+ * // email_link: { file: 'filename', email: 'user@example.com' }
520
+ * // }
521
+ * });
522
+ *
523
+ * //Using Promises
524
+ * async.auto({
525
+ * get_data: function(callback) {
526
+ * console.log('in get_data');
527
+ * // async code to get some data
528
+ * callback(null, 'data', 'converted to array');
529
+ * },
530
+ * make_folder: function(callback) {
531
+ * console.log('in make_folder');
532
+ * // async code to create a directory to store a file in
533
+ * // this is run at the same time as getting the data
534
+ * callback(null, 'folder');
535
+ * },
536
+ * write_file: ['get_data', 'make_folder', function(results, callback) {
537
+ * // once there is some data and the directory exists,
538
+ * // write the data to a file in the directory
539
+ * callback(null, 'filename');
540
+ * }],
541
+ * email_link: ['write_file', function(results, callback) {
542
+ * // once the file is written let's email a link to it...
543
+ * callback(null, {'file':results.write_file, 'email':'user@example.com'});
544
+ * }]
545
+ * }).then(results => {
546
+ * console.log('results = ', results);
547
+ * // results = {
548
+ * // get_data: ['data', 'converted to array']
549
+ * // make_folder; 'folder',
550
+ * // write_file: 'filename'
551
+ * // email_link: { file: 'filename', email: 'user@example.com' }
552
+ * // }
553
+ * }).catch(err => {
554
+ * console.log('err = ', err);
555
+ * });
556
+ *
557
+ * //Using async/await
558
+ * async () => {
559
+ * try {
560
+ * let results = await async.auto({
561
+ * get_data: function(callback) {
562
+ * // async code to get some data
563
+ * callback(null, 'data', 'converted to array');
564
+ * },
565
+ * make_folder: function(callback) {
566
+ * // async code to create a directory to store a file in
567
+ * // this is run at the same time as getting the data
568
+ * callback(null, 'folder');
569
+ * },
570
+ * write_file: ['get_data', 'make_folder', function(results, callback) {
571
+ * // once there is some data and the directory exists,
572
+ * // write the data to a file in the directory
573
+ * callback(null, 'filename');
574
+ * }],
575
+ * email_link: ['write_file', function(results, callback) {
576
+ * // once the file is written let's email a link to it...
577
+ * callback(null, {'file':results.write_file, 'email':'user@example.com'});
578
+ * }]
579
+ * });
580
+ * console.log('results = ', results);
581
+ * // results = {
582
+ * // get_data: ['data', 'converted to array']
583
+ * // make_folder; 'folder',
584
+ * // write_file: 'filename'
585
+ * // email_link: { file: 'filename', email: 'user@example.com' }
586
+ * // }
587
+ * }
588
+ * catch (err) {
589
+ * console.log(err);
590
+ * }
591
+ * }
592
+ *
593
+ */function auto(tasks,concurrency,callback){if(typeof concurrency!=='number'){// concurrency is optional, shift the args.
594
+ callback=concurrency;concurrency=null;}callback=once(callback||promiseCallback());var numTasks=Object.keys(tasks).length;if(!numTasks){return callback(null);}if(!concurrency){concurrency=numTasks;}var results={};var runningTasks=0;var canceled=false;var hasError=false;var listeners=Object.create(null);var readyTasks=[];// for cycle detection:
595
+ var readyToCheck=[];// tasks that have been identified as reachable
596
+ // without the possibility of returning to an ancestor task
597
+ var uncheckedDependencies={};Object.keys(tasks).forEach(key=>{var task=tasks[key];if(!Array.isArray(task)){// no dependencies
598
+ enqueueTask(key,[task]);readyToCheck.push(key);return;}var dependencies=task.slice(0,task.length-1);var remainingDependencies=dependencies.length;if(remainingDependencies===0){enqueueTask(key,task);readyToCheck.push(key);return;}uncheckedDependencies[key]=remainingDependencies;dependencies.forEach(dependencyName=>{if(!tasks[dependencyName]){throw new Error('async.auto task `'+key+'` has a non-existent dependency `'+dependencyName+'` in '+dependencies.join(', '));}addListener(dependencyName,()=>{remainingDependencies--;if(remainingDependencies===0){enqueueTask(key,task);}});});});checkForDeadlocks();processQueue();function enqueueTask(key,task){readyTasks.push(()=>runTask(key,task));}function processQueue(){if(canceled)return;if(readyTasks.length===0&&runningTasks===0){return callback(null,results);}while(readyTasks.length&&runningTasks<concurrency){var run=readyTasks.shift();run();}}function addListener(taskName,fn){var taskListeners=listeners[taskName];if(!taskListeners){taskListeners=listeners[taskName]=[];}taskListeners.push(fn);}function taskComplete(taskName){var taskListeners=listeners[taskName]||[];taskListeners.forEach(fn=>fn());processQueue();}function runTask(key,task){if(hasError)return;var taskCallback=onlyOnce((err,...result)=>{runningTasks--;if(err===false){canceled=true;return;}if(result.length<2){[result]=result;}if(err){var safeResults={};Object.keys(results).forEach(rkey=>{safeResults[rkey]=results[rkey];});safeResults[key]=result;hasError=true;listeners=Object.create(null);if(canceled)return;callback(err,safeResults);}else{results[key]=result;taskComplete(key);}});runningTasks++;var taskFn=wrapAsync(task[task.length-1]);if(task.length>1){taskFn(results,taskCallback);}else{taskFn(taskCallback);}}function checkForDeadlocks(){// Kahn's algorithm
599
+ // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
600
+ // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
601
+ var currentTask;var counter=0;while(readyToCheck.length){currentTask=readyToCheck.pop();counter++;getDependents(currentTask).forEach(dependent=>{if(--uncheckedDependencies[dependent]===0){readyToCheck.push(dependent);}});}if(counter!==numTasks){throw new Error('async.auto cannot execute tasks due to a recursive dependency');}}function getDependents(taskName){var result=[];Object.keys(tasks).forEach(key=>{const task=tasks[key];if(Array.isArray(task)&&task.indexOf(taskName)>=0){result.push(key);}});return result;}return callback[PROMISE_SYMBOL];}var FN_ARGS=/^(?:async\s+)?(?:function)?\s*\w*\s*\(\s*([^)]+)\s*\)(?:\s*{)/;var ARROW_FN_ARGS=/^(?:async\s+)?\(?\s*([^)=]+)\s*\)?(?:\s*=>)/;var FN_ARG_SPLIT=/,/;var FN_ARG=/(=.+)?(\s*)$/;function stripComments(string){let stripped='';let index=0;let endBlockComment=string.indexOf('*/');while(index<string.length){if(string[index]==='/'&&string[index+1]==='/'){// inline comment
602
+ let endIndex=string.indexOf('\n',index);index=endIndex===-1?string.length:endIndex;}else if(endBlockComment!==-1&&string[index]==='/'&&string[index+1]==='*'){// block comment
603
+ let endIndex=string.indexOf('*/',index);if(endIndex!==-1){index=endIndex+2;endBlockComment=string.indexOf('*/',index);}else{stripped+=string[index];index++;}}else{stripped+=string[index];index++;}}return stripped;}function parseParams(func){const src=stripComments(func.toString());let match=src.match(FN_ARGS);if(!match){match=src.match(ARROW_FN_ARGS);}if(!match)throw new Error('could not parse args in autoInject\nSource:\n'+src);let[,args]=match;return args.replace(/\s/g,'').split(FN_ARG_SPLIT).map(arg=>arg.replace(FN_ARG,'').trim());}/**
604
+ * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
605
+ * tasks are specified as parameters to the function, after the usual callback
606
+ * parameter, with the parameter names matching the names of the tasks it
607
+ * depends on. This can provide even more readable task graphs which can be
608
+ * easier to maintain.
609
+ *
610
+ * If a final callback is specified, the task results are similarly injected,
611
+ * specified as named parameters after the initial error parameter.
612
+ *
613
+ * The autoInject function is purely syntactic sugar and its semantics are
614
+ * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
615
+ *
616
+ * @name autoInject
617
+ * @static
618
+ * @memberOf module:ControlFlow
619
+ * @method
620
+ * @see [async.auto]{@link module:ControlFlow.auto}
621
+ * @category Control Flow
622
+ * @param {Object} tasks - An object, each of whose properties is an {@link AsyncFunction} of
623
+ * the form 'func([dependencies...], callback). The object's key of a property
624
+ * serves as the name of the task defined by that property, i.e. can be used
625
+ * when specifying requirements for other tasks.
626
+ * * The `callback` parameter is a `callback(err, result)` which must be called
627
+ * when finished, passing an `error` (which can be `null`) and the result of
628
+ * the function's execution. The remaining parameters name other tasks on
629
+ * which the task is dependent, and the results from those tasks are the
630
+ * arguments of those parameters.
631
+ * @param {Function} [callback] - An optional callback which is called when all
632
+ * the tasks have been completed. It receives the `err` argument if any `tasks`
633
+ * pass an error to their callback, and a `results` object with any completed
634
+ * task results, similar to `auto`.
635
+ * @returns {Promise} a promise, if no callback is passed
636
+ * @example
637
+ *
638
+ * // The example from `auto` can be rewritten as follows:
639
+ * async.autoInject({
640
+ * get_data: function(callback) {
641
+ * // async code to get some data
642
+ * callback(null, 'data', 'converted to array');
643
+ * },
644
+ * make_folder: function(callback) {
645
+ * // async code to create a directory to store a file in
646
+ * // this is run at the same time as getting the data
647
+ * callback(null, 'folder');
648
+ * },
649
+ * write_file: function(get_data, make_folder, callback) {
650
+ * // once there is some data and the directory exists,
651
+ * // write the data to a file in the directory
652
+ * callback(null, 'filename');
653
+ * },
654
+ * email_link: function(write_file, callback) {
655
+ * // once the file is written let's email a link to it...
656
+ * // write_file contains the filename returned by write_file.
657
+ * callback(null, {'file':write_file, 'email':'user@example.com'});
658
+ * }
659
+ * }, function(err, results) {
660
+ * console.log('err = ', err);
661
+ * console.log('email_link = ', results.email_link);
662
+ * });
663
+ *
664
+ * // If you are using a JS minifier that mangles parameter names, `autoInject`
665
+ * // will not work with plain functions, since the parameter names will be
666
+ * // collapsed to a single letter identifier. To work around this, you can
667
+ * // explicitly specify the names of the parameters your task function needs
668
+ * // in an array, similar to Angular.js dependency injection.
669
+ *
670
+ * // This still has an advantage over plain `auto`, since the results a task
671
+ * // depends on are still spread into arguments.
672
+ * async.autoInject({
673
+ * //...
674
+ * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
675
+ * callback(null, 'filename');
676
+ * }],
677
+ * email_link: ['write_file', function(write_file, callback) {
678
+ * callback(null, {'file':write_file, 'email':'user@example.com'});
679
+ * }]
680
+ * //...
681
+ * }, function(err, results) {
682
+ * console.log('err = ', err);
683
+ * console.log('email_link = ', results.email_link);
684
+ * });
685
+ */function autoInject(tasks,callback){var newTasks={};Object.keys(tasks).forEach(key=>{var taskFn=tasks[key];var params;var fnIsAsync=isAsync(taskFn);var hasNoDeps=!fnIsAsync&&taskFn.length===1||fnIsAsync&&taskFn.length===0;if(Array.isArray(taskFn)){params=[...taskFn];taskFn=params.pop();newTasks[key]=params.concat(params.length>0?newTask:taskFn);}else if(hasNoDeps){// no dependencies, use the function as-is
686
+ newTasks[key]=taskFn;}else{params=parseParams(taskFn);if(taskFn.length===0&&!fnIsAsync&&params.length===0){throw new Error("autoInject task functions require explicit parameters.");}// remove callback param
687
+ if(!fnIsAsync)params.pop();newTasks[key]=params.concat(newTask);}function newTask(results,taskCb){var newArgs=params.map(name=>results[name]);newArgs.push(taskCb);wrapAsync(taskFn)(...newArgs);}});return auto(newTasks,callback);}// Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
688
+ // used for queues. This implementation assumes that the node provided by the user can be modified
689
+ // to adjust the next and last properties. We implement only the minimal functionality
690
+ // for queue support.
691
+ 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;}}function setInitial(dll,node){dll.length=1;dll.head=dll.tail=node;}function queue(worker,concurrency,payload){if(concurrency==null){concurrency=1;}else if(concurrency===0){throw new RangeError('Concurrency must not be zero');}var _worker=wrapAsync(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
692
+ // deal with it
693
+ 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;setImmediate$1(()=>{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
694
+ setImmediate$1(()=>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 DLL(),_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
695
+ // when callbacks resolve synchronously (#1267).
696
+ 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=onlyOnce(_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;setImmediate$1(q.process);}};// define these as fixed properties, so people get useful errors when updating
697
+ 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;}/**
698
+ * Creates a `cargo` object with the specified payload. Tasks added to the
699
+ * cargo will be processed altogether (up to the `payload` limit). If the
700
+ * `worker` is in progress, the task is queued until it becomes available. Once
701
+ * the `worker` has completed some tasks, each callback of those tasks is
702
+ * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
703
+ * for how `cargo` and `queue` work.
704
+ *
705
+ * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
706
+ * at a time, cargo passes an array of tasks to a single worker, repeating
707
+ * when the worker is finished.
708
+ *
709
+ * @name cargo
710
+ * @static
711
+ * @memberOf module:ControlFlow
712
+ * @method
713
+ * @see [async.queue]{@link module:ControlFlow.queue}
714
+ * @category Control Flow
715
+ * @param {AsyncFunction} worker - An asynchronous function for processing an array
716
+ * of queued tasks. Invoked with `(tasks, callback)`.
717
+ * @param {number} [payload=Infinity] - An optional `integer` for determining
718
+ * how many tasks should be processed per round; if omitted, the default is
719
+ * unlimited.
720
+ * @returns {module:ControlFlow.QueueObject} A cargo object to manage the tasks. Callbacks can
721
+ * attached as certain properties to listen for specific events during the
722
+ * lifecycle of the cargo and inner queue.
723
+ * @example
724
+ *
725
+ * // create a cargo object with payload 2
726
+ * var cargo = async.cargo(function(tasks, callback) {
727
+ * for (var i=0; i<tasks.length; i++) {
728
+ * console.log('hello ' + tasks[i].name);
729
+ * }
730
+ * callback();
731
+ * }, 2);
732
+ *
733
+ * // add some items
734
+ * cargo.push({name: 'foo'}, function(err) {
735
+ * console.log('finished processing foo');
736
+ * });
737
+ * cargo.push({name: 'bar'}, function(err) {
738
+ * console.log('finished processing bar');
739
+ * });
740
+ * await cargo.push({name: 'baz'});
741
+ * console.log('finished processing baz');
742
+ */function cargo(worker,payload){return queue(worker,1,payload);}/**
743
+ * Creates a `cargoQueue` object with the specified payload. Tasks added to the
744
+ * cargoQueue will be processed together (up to the `payload` limit) in `concurrency` parallel workers.
745
+ * If the all `workers` are in progress, the task is queued until one becomes available. Once
746
+ * a `worker` has completed some tasks, each callback of those tasks is
747
+ * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
748
+ * for how `cargo` and `queue` work.
749
+ *
750
+ * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
751
+ * at a time, and [`cargo`]{@link module:ControlFlow.cargo} passes an array of tasks to a single worker,
752
+ * the cargoQueue passes an array of tasks to multiple parallel workers.
753
+ *
754
+ * @name cargoQueue
755
+ * @static
756
+ * @memberOf module:ControlFlow
757
+ * @method
758
+ * @see [async.queue]{@link module:ControlFlow.queue}
759
+ * @see [async.cargo]{@link module:ControlFLow.cargo}
760
+ * @category Control Flow
761
+ * @param {AsyncFunction} worker - An asynchronous function for processing an array
762
+ * of queued tasks. Invoked with `(tasks, callback)`.
763
+ * @param {number} [concurrency=1] - An `integer` for determining how many
764
+ * `worker` functions should be run in parallel. If omitted, the concurrency
765
+ * defaults to `1`. If the concurrency is `0`, an error is thrown.
766
+ * @param {number} [payload=Infinity] - An optional `integer` for determining
767
+ * how many tasks should be processed per round; if omitted, the default is
768
+ * unlimited.
769
+ * @returns {module:ControlFlow.QueueObject} A cargoQueue object to manage the tasks. Callbacks can
770
+ * attached as certain properties to listen for specific events during the
771
+ * lifecycle of the cargoQueue and inner queue.
772
+ * @example
773
+ *
774
+ * // create a cargoQueue object with payload 2 and concurrency 2
775
+ * var cargoQueue = async.cargoQueue(function(tasks, callback) {
776
+ * for (var i=0; i<tasks.length; i++) {
777
+ * console.log('hello ' + tasks[i].name);
778
+ * }
779
+ * callback();
780
+ * }, 2, 2);
781
+ *
782
+ * // add some items
783
+ * cargoQueue.push({name: 'foo'}, function(err) {
784
+ * console.log('finished processing foo');
785
+ * });
786
+ * cargoQueue.push({name: 'bar'}, function(err) {
787
+ * console.log('finished processing bar');
788
+ * });
789
+ * cargoQueue.push({name: 'baz'}, function(err) {
790
+ * console.log('finished processing baz');
791
+ * });
792
+ * cargoQueue.push({name: 'boo'}, function(err) {
793
+ * console.log('finished processing boo');
794
+ * });
795
+ */function cargo$1(worker,concurrency,payload){return queue(worker,concurrency,payload);}/**
796
+ * Reduces `coll` into a single value using an async `iteratee` to return each
797
+ * successive step. `memo` is the initial state of the reduction. This function
798
+ * only operates in series.
799
+ *
800
+ * For performance reasons, it may make sense to split a call to this function
801
+ * into a parallel map, and then use the normal `Array.prototype.reduce` on the
802
+ * results. This function is for situations where each step in the reduction
803
+ * needs to be async; if you can get the data before reducing it, then it's
804
+ * probably a good idea to do so.
805
+ *
806
+ * @name reduce
807
+ * @static
808
+ * @memberOf module:Collections
809
+ * @method
810
+ * @alias inject
811
+ * @alias foldl
812
+ * @category Collection
813
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
814
+ * @param {*} memo - The initial state of the reduction.
815
+ * @param {AsyncFunction} iteratee - A function applied to each item in the
816
+ * array to produce the next step in the reduction.
817
+ * The `iteratee` should complete with the next state of the reduction.
818
+ * If the iteratee completes with an error, the reduction is stopped and the
819
+ * main `callback` is immediately called with the error.
820
+ * Invoked with (memo, item, callback).
821
+ * @param {Function} [callback] - A callback which is called after all the
822
+ * `iteratee` functions have finished. Result is the reduced value. Invoked with
823
+ * (err, result).
824
+ * @returns {Promise} a promise, if no callback is passed
825
+ * @example
826
+ *
827
+ * // file1.txt is a file that is 1000 bytes in size
828
+ * // file2.txt is a file that is 2000 bytes in size
829
+ * // file3.txt is a file that is 3000 bytes in size
830
+ * // file4.txt does not exist
831
+ *
832
+ * const fileList = ['file1.txt','file2.txt','file3.txt'];
833
+ * const withMissingFileList = ['file1.txt','file2.txt','file3.txt', 'file4.txt'];
834
+ *
835
+ * // asynchronous function that computes the file size in bytes
836
+ * // file size is added to the memoized value, then returned
837
+ * function getFileSizeInBytes(memo, file, callback) {
838
+ * fs.stat(file, function(err, stat) {
839
+ * if (err) {
840
+ * return callback(err);
841
+ * }
842
+ * callback(null, memo + stat.size);
843
+ * });
844
+ * }
845
+ *
846
+ * // Using callbacks
847
+ * async.reduce(fileList, 0, getFileSizeInBytes, function(err, result) {
848
+ * if (err) {
849
+ * console.log(err);
850
+ * } else {
851
+ * console.log(result);
852
+ * // 6000
853
+ * // which is the sum of the file sizes of the three files
854
+ * }
855
+ * });
856
+ *
857
+ * // Error Handling
858
+ * async.reduce(withMissingFileList, 0, getFileSizeInBytes, function(err, result) {
859
+ * if (err) {
860
+ * console.log(err);
861
+ * // [ Error: ENOENT: no such file or directory ]
862
+ * } else {
863
+ * console.log(result);
864
+ * }
865
+ * });
866
+ *
867
+ * // Using Promises
868
+ * async.reduce(fileList, 0, getFileSizeInBytes)
869
+ * .then( result => {
870
+ * console.log(result);
871
+ * // 6000
872
+ * // which is the sum of the file sizes of the three files
873
+ * }).catch( err => {
874
+ * console.log(err);
875
+ * });
876
+ *
877
+ * // Error Handling
878
+ * async.reduce(withMissingFileList, 0, getFileSizeInBytes)
879
+ * .then( result => {
880
+ * console.log(result);
881
+ * }).catch( err => {
882
+ * console.log(err);
883
+ * // [ Error: ENOENT: no such file or directory ]
884
+ * });
885
+ *
886
+ * // Using async/await
887
+ * async () => {
888
+ * try {
889
+ * let result = await async.reduce(fileList, 0, getFileSizeInBytes);
890
+ * console.log(result);
891
+ * // 6000
892
+ * // which is the sum of the file sizes of the three files
893
+ * }
894
+ * catch (err) {
895
+ * console.log(err);
896
+ * }
897
+ * }
898
+ *
899
+ * // Error Handling
900
+ * async () => {
901
+ * try {
902
+ * let result = await async.reduce(withMissingFileList, 0, getFileSizeInBytes);
903
+ * console.log(result);
904
+ * }
905
+ * catch (err) {
906
+ * console.log(err);
907
+ * // [ Error: ENOENT: no such file or directory ]
908
+ * }
909
+ * }
910
+ *
911
+ */function reduce(coll,memo,iteratee,callback){callback=once(callback);var _iteratee=wrapAsync(iteratee);return eachOfSeries$1(coll,(x,i,iterCb)=>{_iteratee(memo,x,(err,v)=>{memo=v;iterCb(err);});},err=>callback(err,memo));}var reduce$1=awaitify(reduce,4);/**
912
+ * Version of the compose function that is more natural to read. Each function
913
+ * consumes the return value of the previous function. It is the equivalent of
914
+ * [compose]{@link module:ControlFlow.compose} with the arguments reversed.
915
+ *
916
+ * Each function is executed with the `this` binding of the composed function.
917
+ *
918
+ * @name seq
919
+ * @static
920
+ * @memberOf module:ControlFlow
921
+ * @method
922
+ * @see [async.compose]{@link module:ControlFlow.compose}
923
+ * @category Control Flow
924
+ * @param {...AsyncFunction} functions - the asynchronous functions to compose
925
+ * @returns {Function} a function that composes the `functions` in order
926
+ * @example
927
+ *
928
+ * // Requires lodash (or underscore), express3 and dresende's orm2.
929
+ * // Part of an app, that fetches cats of the logged user.
930
+ * // This example uses `seq` function to avoid overnesting and error
931
+ * // handling clutter.
932
+ * app.get('/cats', function(request, response) {
933
+ * var User = request.models.User;
934
+ * async.seq(
935
+ * User.get.bind(User), // 'User.get' has signature (id, callback(err, data))
936
+ * function(user, fn) {
937
+ * user.getCats(fn); // 'getCats' has signature (callback(err, data))
938
+ * }
939
+ * )(req.session.user_id, function (err, cats) {
940
+ * if (err) {
941
+ * console.error(err);
942
+ * response.json({ status: 'error', message: err.message });
943
+ * } else {
944
+ * response.json({ status: 'ok', message: 'Cats found', data: cats });
945
+ * }
946
+ * });
947
+ * });
948
+ */function seq(...functions){var _functions=functions.map(wrapAsync);return function(...args){var that=this;var cb=args[args.length-1];if(typeof cb=='function'){args.pop();}else{cb=promiseCallback();}reduce$1(_functions,args,(newargs,fn,iterCb)=>{fn.apply(that,newargs.concat((err,...nextargs)=>{iterCb(err,nextargs);}));},(err,results)=>cb(err,...results));return cb[PROMISE_SYMBOL];};}/**
949
+ * Creates a function which is a composition of the passed asynchronous
950
+ * functions. Each function consumes the return value of the function that
951
+ * follows. Composing functions `f()`, `g()`, and `h()` would produce the result
952
+ * of `f(g(h()))`, only this version uses callbacks to obtain the return values.
953
+ *
954
+ * If the last argument to the composed function is not a function, a promise
955
+ * is returned when you call it.
956
+ *
957
+ * Each function is executed with the `this` binding of the composed function.
958
+ *
959
+ * @name compose
960
+ * @static
961
+ * @memberOf module:ControlFlow
962
+ * @method
963
+ * @category Control Flow
964
+ * @param {...AsyncFunction} functions - the asynchronous functions to compose
965
+ * @returns {Function} an asynchronous function that is the composed
966
+ * asynchronous `functions`
967
+ * @example
968
+ *
969
+ * function add1(n, callback) {
970
+ * setTimeout(function () {
971
+ * callback(null, n + 1);
972
+ * }, 10);
973
+ * }
974
+ *
975
+ * function mul3(n, callback) {
976
+ * setTimeout(function () {
977
+ * callback(null, n * 3);
978
+ * }, 10);
979
+ * }
980
+ *
981
+ * var add1mul3 = async.compose(mul3, add1);
982
+ * add1mul3(4, function (err, result) {
983
+ * // result now equals 15
984
+ * });
985
+ */function compose(...args){return seq(...args.reverse());}/**
986
+ * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
987
+ *
988
+ * @name mapLimit
989
+ * @static
990
+ * @memberOf module:Collections
991
+ * @method
992
+ * @see [async.map]{@link module:Collections.map}
993
+ * @category Collection
994
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
995
+ * @param {number} limit - The maximum number of async operations at a time.
996
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
997
+ * `coll`.
998
+ * The iteratee should complete with the transformed item.
999
+ * Invoked with (item, callback).
1000
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
1001
+ * functions have finished, or an error occurs. Results is an array of the
1002
+ * transformed items from the `coll`. Invoked with (err, results).
1003
+ * @returns {Promise} a promise, if no callback is passed
1004
+ */function mapLimit(coll,limit,iteratee,callback){return _asyncMap(eachOfLimit(limit),coll,iteratee,callback);}var mapLimit$1=awaitify(mapLimit,4);/**
1005
+ * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.
1006
+ *
1007
+ * @name concatLimit
1008
+ * @static
1009
+ * @memberOf module:Collections
1010
+ * @method
1011
+ * @see [async.concat]{@link module:Collections.concat}
1012
+ * @category Collection
1013
+ * @alias flatMapLimit
1014
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1015
+ * @param {number} limit - The maximum number of async operations at a time.
1016
+ * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,
1017
+ * which should use an array as its result. Invoked with (item, callback).
1018
+ * @param {Function} [callback] - A callback which is called after all the
1019
+ * `iteratee` functions have finished, or an error occurs. Results is an array
1020
+ * containing the concatenated results of the `iteratee` function. Invoked with
1021
+ * (err, results).
1022
+ * @returns A Promise, if no callback is passed
1023
+ */function concatLimit(coll,limit,iteratee,callback){var _iteratee=wrapAsync(iteratee);return mapLimit$1(coll,limit,(val,iterCb)=>{_iteratee(val,(err,...args)=>{if(err)return iterCb(err);return iterCb(err,args);});},(err,mapResults)=>{var result=[];for(var i=0;i<mapResults.length;i++){if(mapResults[i]){result=result.concat(...mapResults[i]);}}return callback(err,result);});}var concatLimit$1=awaitify(concatLimit,4);/**
1024
+ * Applies `iteratee` to each item in `coll`, concatenating the results. Returns
1025
+ * the concatenated list. The `iteratee`s are called in parallel, and the
1026
+ * results are concatenated as they return. The results array will be returned in
1027
+ * the original order of `coll` passed to the `iteratee` function.
1028
+ *
1029
+ * @name concat
1030
+ * @static
1031
+ * @memberOf module:Collections
1032
+ * @method
1033
+ * @category Collection
1034
+ * @alias flatMap
1035
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1036
+ * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,
1037
+ * which should use an array as its result. Invoked with (item, callback).
1038
+ * @param {Function} [callback] - A callback which is called after all the
1039
+ * `iteratee` functions have finished, or an error occurs. Results is an array
1040
+ * containing the concatenated results of the `iteratee` function. Invoked with
1041
+ * (err, results).
1042
+ * @returns A Promise, if no callback is passed
1043
+ * @example
1044
+ *
1045
+ * // dir1 is a directory that contains file1.txt, file2.txt
1046
+ * // dir2 is a directory that contains file3.txt, file4.txt
1047
+ * // dir3 is a directory that contains file5.txt
1048
+ * // dir4 does not exist
1049
+ *
1050
+ * let directoryList = ['dir1','dir2','dir3'];
1051
+ * let withMissingDirectoryList = ['dir1','dir2','dir3', 'dir4'];
1052
+ *
1053
+ * // Using callbacks
1054
+ * async.concat(directoryList, fs.readdir, function(err, results) {
1055
+ * if (err) {
1056
+ * console.log(err);
1057
+ * } else {
1058
+ * console.log(results);
1059
+ * // [ 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', file5.txt ]
1060
+ * }
1061
+ * });
1062
+ *
1063
+ * // Error Handling
1064
+ * async.concat(withMissingDirectoryList, fs.readdir, function(err, results) {
1065
+ * if (err) {
1066
+ * console.log(err);
1067
+ * // [ Error: ENOENT: no such file or directory ]
1068
+ * // since dir4 does not exist
1069
+ * } else {
1070
+ * console.log(results);
1071
+ * }
1072
+ * });
1073
+ *
1074
+ * // Using Promises
1075
+ * async.concat(directoryList, fs.readdir)
1076
+ * .then(results => {
1077
+ * console.log(results);
1078
+ * // [ 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', file5.txt ]
1079
+ * }).catch(err => {
1080
+ * console.log(err);
1081
+ * });
1082
+ *
1083
+ * // Error Handling
1084
+ * async.concat(withMissingDirectoryList, fs.readdir)
1085
+ * .then(results => {
1086
+ * console.log(results);
1087
+ * }).catch(err => {
1088
+ * console.log(err);
1089
+ * // [ Error: ENOENT: no such file or directory ]
1090
+ * // since dir4 does not exist
1091
+ * });
1092
+ *
1093
+ * // Using async/await
1094
+ * async () => {
1095
+ * try {
1096
+ * let results = await async.concat(directoryList, fs.readdir);
1097
+ * console.log(results);
1098
+ * // [ 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', file5.txt ]
1099
+ * } catch (err) {
1100
+ * console.log(err);
1101
+ * }
1102
+ * }
1103
+ *
1104
+ * // Error Handling
1105
+ * async () => {
1106
+ * try {
1107
+ * let results = await async.concat(withMissingDirectoryList, fs.readdir);
1108
+ * console.log(results);
1109
+ * } catch (err) {
1110
+ * console.log(err);
1111
+ * // [ Error: ENOENT: no such file or directory ]
1112
+ * // since dir4 does not exist
1113
+ * }
1114
+ * }
1115
+ *
1116
+ */function concat(coll,iteratee,callback){return concatLimit$1(coll,Infinity,iteratee,callback);}var concat$1=awaitify(concat,3);/**
1117
+ * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
1118
+ *
1119
+ * @name concatSeries
1120
+ * @static
1121
+ * @memberOf module:Collections
1122
+ * @method
1123
+ * @see [async.concat]{@link module:Collections.concat}
1124
+ * @category Collection
1125
+ * @alias flatMapSeries
1126
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1127
+ * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`.
1128
+ * The iteratee should complete with an array an array of results.
1129
+ * Invoked with (item, callback).
1130
+ * @param {Function} [callback] - A callback which is called after all the
1131
+ * `iteratee` functions have finished, or an error occurs. Results is an array
1132
+ * containing the concatenated results of the `iteratee` function. Invoked with
1133
+ * (err, results).
1134
+ * @returns A Promise, if no callback is passed
1135
+ */function concatSeries(coll,iteratee,callback){return concatLimit$1(coll,1,iteratee,callback);}var concatSeries$1=awaitify(concatSeries,3);/**
1136
+ * Returns a function that when called, calls-back with the values provided.
1137
+ * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
1138
+ * [`auto`]{@link module:ControlFlow.auto}.
1139
+ *
1140
+ * @name constant
1141
+ * @static
1142
+ * @memberOf module:Utils
1143
+ * @method
1144
+ * @category Util
1145
+ * @param {...*} arguments... - Any number of arguments to automatically invoke
1146
+ * callback with.
1147
+ * @returns {AsyncFunction} Returns a function that when invoked, automatically
1148
+ * invokes the callback with the previous given arguments.
1149
+ * @example
1150
+ *
1151
+ * async.waterfall([
1152
+ * async.constant(42),
1153
+ * function (value, next) {
1154
+ * // value === 42
1155
+ * },
1156
+ * //...
1157
+ * ], callback);
1158
+ *
1159
+ * async.waterfall([
1160
+ * async.constant(filename, "utf8"),
1161
+ * fs.readFile,
1162
+ * function (fileData, next) {
1163
+ * //...
1164
+ * }
1165
+ * //...
1166
+ * ], callback);
1167
+ *
1168
+ * async.auto({
1169
+ * hostname: async.constant("https://server.net/"),
1170
+ * port: findFreePort,
1171
+ * launchServer: ["hostname", "port", function (options, cb) {
1172
+ * startServer(options, cb);
1173
+ * }],
1174
+ * //...
1175
+ * }, callback);
1176
+ */function constant(...args){return function(...ignoredArgs/*, callback*/){var callback=ignoredArgs.pop();return callback(null,...args);};}function _createTester(check,getResult){return(eachfn,arr,_iteratee,cb)=>{var testPassed=false;var testResult;const iteratee=wrapAsync(_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,breakLoop);}callback();});},err=>{if(err)return cb(err);cb(null,testPassed?testResult:getResult(false));});};}/**
1177
+ * Returns the first value in `coll` that passes an async truth test. The
1178
+ * `iteratee` is applied in parallel, meaning the first iteratee to return
1179
+ * `true` will fire the detect `callback` with that result. That means the
1180
+ * result might not be the first item in the original `coll` (in terms of order)
1181
+ * that passes the test.
82
1182
 
83
- /**
84
- * Add a Pattern to the Parse Tree
85
- * @method addPattern
86
- * @param {Object} pTree - A node on the parse tree to push the characters into
87
- * @param {string} pPattern - The string to add to the tree
88
- * @param {number} pIndex - callback function
89
- * @return {bool} True if adding the pattern was successful
90
- */
91
- addPattern(pPatternStart, pPatternEnd, pParser) {
92
- return this.WordTree.addPattern(pPatternStart, pPatternEnd, pParser);
93
- }
1183
+ * If order within the original `coll` is important, then look at
1184
+ * [`detectSeries`]{@link module:Collections.detectSeries}.
1185
+ *
1186
+ * @name detect
1187
+ * @static
1188
+ * @memberOf module:Collections
1189
+ * @method
1190
+ * @alias find
1191
+ * @category Collections
1192
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1193
+ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
1194
+ * The iteratee must complete with a boolean value as its result.
1195
+ * Invoked with (item, callback).
1196
+ * @param {Function} [callback] - A callback which is called as soon as any
1197
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
1198
+ * Result will be the first item in the array that passes the truth test
1199
+ * (iteratee) or the value `undefined` if none passed. Invoked with
1200
+ * (err, result).
1201
+ * @returns {Promise} a promise, if a callback is omitted
1202
+ * @example
1203
+ *
1204
+ * // dir1 is a directory that contains file1.txt, file2.txt
1205
+ * // dir2 is a directory that contains file3.txt, file4.txt
1206
+ * // dir3 is a directory that contains file5.txt
1207
+ *
1208
+ * // asynchronous function that checks if a file exists
1209
+ * function fileExists(file, callback) {
1210
+ * fs.access(file, fs.constants.F_OK, (err) => {
1211
+ * callback(null, !err);
1212
+ * });
1213
+ * }
1214
+ *
1215
+ * async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists,
1216
+ * function(err, result) {
1217
+ * console.log(result);
1218
+ * // dir1/file1.txt
1219
+ * // result now equals the first file in the list that exists
1220
+ * }
1221
+ *);
1222
+ *
1223
+ * // Using Promises
1224
+ * async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists)
1225
+ * .then(result => {
1226
+ * console.log(result);
1227
+ * // dir1/file1.txt
1228
+ * // result now equals the first file in the list that exists
1229
+ * }).catch(err => {
1230
+ * console.log(err);
1231
+ * });
1232
+ *
1233
+ * // Using async/await
1234
+ * async () => {
1235
+ * try {
1236
+ * let result = await async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists);
1237
+ * console.log(result);
1238
+ * // dir1/file1.txt
1239
+ * // result now equals the file in the list that exists
1240
+ * }
1241
+ * catch (err) {
1242
+ * console.log(err);
1243
+ * }
1244
+ * }
1245
+ *
1246
+ */function detect(coll,iteratee,callback){return _createTester(bool=>bool,(res,item)=>item)(eachOf$1,coll,iteratee,callback);}var detect$1=awaitify(detect,3);/**
1247
+ * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
1248
+ * time.
1249
+ *
1250
+ * @name detectLimit
1251
+ * @static
1252
+ * @memberOf module:Collections
1253
+ * @method
1254
+ * @see [async.detect]{@link module:Collections.detect}
1255
+ * @alias findLimit
1256
+ * @category Collections
1257
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1258
+ * @param {number} limit - The maximum number of async operations at a time.
1259
+ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
1260
+ * The iteratee must complete with a boolean value as its result.
1261
+ * Invoked with (item, callback).
1262
+ * @param {Function} [callback] - A callback which is called as soon as any
1263
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
1264
+ * Result will be the first item in the array that passes the truth test
1265
+ * (iteratee) or the value `undefined` if none passed. Invoked with
1266
+ * (err, result).
1267
+ * @returns {Promise} a promise, if a callback is omitted
1268
+ */function detectLimit(coll,limit,iteratee,callback){return _createTester(bool=>bool,(res,item)=>item)(eachOfLimit(limit),coll,iteratee,callback);}var detectLimit$1=awaitify(detectLimit,4);/**
1269
+ * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
1270
+ *
1271
+ * @name detectSeries
1272
+ * @static
1273
+ * @memberOf module:Collections
1274
+ * @method
1275
+ * @see [async.detect]{@link module:Collections.detect}
1276
+ * @alias findSeries
1277
+ * @category Collections
1278
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1279
+ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
1280
+ * The iteratee must complete with a boolean value as its result.
1281
+ * Invoked with (item, callback).
1282
+ * @param {Function} [callback] - A callback which is called as soon as any
1283
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
1284
+ * Result will be the first item in the array that passes the truth test
1285
+ * (iteratee) or the value `undefined` if none passed. Invoked with
1286
+ * (err, result).
1287
+ * @returns {Promise} a promise, if a callback is omitted
1288
+ */function detectSeries(coll,iteratee,callback){return _createTester(bool=>bool,(res,item)=>item)(eachOfLimit(1),coll,iteratee,callback);}var detectSeries$1=awaitify(detectSeries,3);function consoleFunc(name){return(fn,...args)=>wrapAsync(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));}}});}/**
1289
+ * Logs the result of an [`async` function]{@link AsyncFunction} to the
1290
+ * `console` using `console.dir` to display the properties of the resulting object.
1291
+ * Only works in Node.js or in browsers that support `console.dir` and
1292
+ * `console.error` (such as FF and Chrome).
1293
+ * If multiple arguments are returned from the async function,
1294
+ * `console.dir` is called on each argument in order.
1295
+ *
1296
+ * @name dir
1297
+ * @static
1298
+ * @memberOf module:Utils
1299
+ * @method
1300
+ * @category Util
1301
+ * @param {AsyncFunction} function - The function you want to eventually apply
1302
+ * all arguments to.
1303
+ * @param {...*} arguments... - Any number of arguments to apply to the function.
1304
+ * @example
1305
+ *
1306
+ * // in a module
1307
+ * var hello = function(name, callback) {
1308
+ * setTimeout(function() {
1309
+ * callback(null, {hello: name});
1310
+ * }, 1000);
1311
+ * };
1312
+ *
1313
+ * // in the node repl
1314
+ * node> async.dir(hello, 'world');
1315
+ * {hello: 'world'}
1316
+ */var dir=consoleFunc('dir');/**
1317
+ * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
1318
+ * the order of operations, the arguments `test` and `iteratee` are switched.
1319
+ *
1320
+ * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
1321
+ *
1322
+ * @name doWhilst
1323
+ * @static
1324
+ * @memberOf module:ControlFlow
1325
+ * @method
1326
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
1327
+ * @category Control Flow
1328
+ * @param {AsyncFunction} iteratee - A function which is called each time `test`
1329
+ * passes. Invoked with (callback).
1330
+ * @param {AsyncFunction} test - asynchronous truth test to perform after each
1331
+ * execution of `iteratee`. Invoked with (...args, callback), where `...args` are the
1332
+ * non-error args from the previous callback of `iteratee`.
1333
+ * @param {Function} [callback] - A callback which is called after the test
1334
+ * function has failed and repeated execution of `iteratee` has stopped.
1335
+ * `callback` will be passed an error and any arguments passed to the final
1336
+ * `iteratee`'s callback. Invoked with (err, [results]);
1337
+ * @returns {Promise} a promise, if no callback is passed
1338
+ */function doWhilst(iteratee,test,callback){callback=onlyOnce(callback);var _fn=wrapAsync(iteratee);var _test=wrapAsync(test);var results;function next(err,...args){if(err)return callback(err);if(err===false)return;results=args;_test(...args,check);}function check(err,truth){if(err)return callback(err);if(err===false)return;if(!truth)return callback(null,...results);_fn(next);}return check(null,true);}var doWhilst$1=awaitify(doWhilst,3);/**
1339
+ * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
1340
+ * argument ordering differs from `until`.
1341
+ *
1342
+ * @name doUntil
1343
+ * @static
1344
+ * @memberOf module:ControlFlow
1345
+ * @method
1346
+ * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
1347
+ * @category Control Flow
1348
+ * @param {AsyncFunction} iteratee - An async function which is called each time
1349
+ * `test` fails. Invoked with (callback).
1350
+ * @param {AsyncFunction} test - asynchronous truth test to perform after each
1351
+ * execution of `iteratee`. Invoked with (...args, callback), where `...args` are the
1352
+ * non-error args from the previous callback of `iteratee`
1353
+ * @param {Function} [callback] - A callback which is called after the test
1354
+ * function has passed and repeated execution of `iteratee` has stopped. `callback`
1355
+ * will be passed an error and any arguments passed to the final `iteratee`'s
1356
+ * callback. Invoked with (err, [results]);
1357
+ * @returns {Promise} a promise, if no callback is passed
1358
+ */function doUntil(iteratee,test,callback){const _test=wrapAsync(test);return doWhilst$1(iteratee,(...args)=>{const cb=args.pop();_test(...args,(err,truth)=>cb(err,!truth));},callback);}function _withoutIndex(iteratee){return(value,index,callback)=>iteratee(value,callback);}/**
1359
+ * Applies the function `iteratee` to each item in `coll`, in parallel.
1360
+ * The `iteratee` is called with an item from the list, and a callback for when
1361
+ * it has finished. If the `iteratee` passes an error to its `callback`, the
1362
+ * main `callback` (for the `each` function) is immediately called with the
1363
+ * error.
1364
+ *
1365
+ * Note, that since this function applies `iteratee` to each item in parallel,
1366
+ * there is no guarantee that the iteratee functions will complete in order.
1367
+ *
1368
+ * @name each
1369
+ * @static
1370
+ * @memberOf module:Collections
1371
+ * @method
1372
+ * @alias forEach
1373
+ * @category Collection
1374
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1375
+ * @param {AsyncFunction} iteratee - An async function to apply to
1376
+ * each item in `coll`. Invoked with (item, callback).
1377
+ * The array index is not passed to the iteratee.
1378
+ * If you need the index, use `eachOf`.
1379
+ * @param {Function} [callback] - A callback which is called when all
1380
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
1381
+ * @returns {Promise} a promise, if a callback is omitted
1382
+ * @example
1383
+ *
1384
+ * // dir1 is a directory that contains file1.txt, file2.txt
1385
+ * // dir2 is a directory that contains file3.txt, file4.txt
1386
+ * // dir3 is a directory that contains file5.txt
1387
+ * // dir4 does not exist
1388
+ *
1389
+ * const fileList = [ 'dir1/file2.txt', 'dir2/file3.txt', 'dir/file5.txt'];
1390
+ * const withMissingFileList = ['dir1/file1.txt', 'dir4/file2.txt'];
1391
+ *
1392
+ * // asynchronous function that deletes a file
1393
+ * const deleteFile = function(file, callback) {
1394
+ * fs.unlink(file, callback);
1395
+ * };
1396
+ *
1397
+ * // Using callbacks
1398
+ * async.each(fileList, deleteFile, function(err) {
1399
+ * if( err ) {
1400
+ * console.log(err);
1401
+ * } else {
1402
+ * console.log('All files have been deleted successfully');
1403
+ * }
1404
+ * });
1405
+ *
1406
+ * // Error Handling
1407
+ * async.each(withMissingFileList, deleteFile, function(err){
1408
+ * console.log(err);
1409
+ * // [ Error: ENOENT: no such file or directory ]
1410
+ * // since dir4/file2.txt does not exist
1411
+ * // dir1/file1.txt could have been deleted
1412
+ * });
1413
+ *
1414
+ * // Using Promises
1415
+ * async.each(fileList, deleteFile)
1416
+ * .then( () => {
1417
+ * console.log('All files have been deleted successfully');
1418
+ * }).catch( err => {
1419
+ * console.log(err);
1420
+ * });
1421
+ *
1422
+ * // Error Handling
1423
+ * async.each(fileList, deleteFile)
1424
+ * .then( () => {
1425
+ * console.log('All files have been deleted successfully');
1426
+ * }).catch( err => {
1427
+ * console.log(err);
1428
+ * // [ Error: ENOENT: no such file or directory ]
1429
+ * // since dir4/file2.txt does not exist
1430
+ * // dir1/file1.txt could have been deleted
1431
+ * });
1432
+ *
1433
+ * // Using async/await
1434
+ * async () => {
1435
+ * try {
1436
+ * await async.each(files, deleteFile);
1437
+ * }
1438
+ * catch (err) {
1439
+ * console.log(err);
1440
+ * }
1441
+ * }
1442
+ *
1443
+ * // Error Handling
1444
+ * async () => {
1445
+ * try {
1446
+ * await async.each(withMissingFileList, deleteFile);
1447
+ * }
1448
+ * catch (err) {
1449
+ * console.log(err);
1450
+ * // [ Error: ENOENT: no such file or directory ]
1451
+ * // since dir4/file2.txt does not exist
1452
+ * // dir1/file1.txt could have been deleted
1453
+ * }
1454
+ * }
1455
+ *
1456
+ */function eachLimit(coll,iteratee,callback){return eachOf$1(coll,_withoutIndex(wrapAsync(iteratee)),callback);}var each=awaitify(eachLimit,3);/**
1457
+ * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
1458
+ *
1459
+ * @name eachLimit
1460
+ * @static
1461
+ * @memberOf module:Collections
1462
+ * @method
1463
+ * @see [async.each]{@link module:Collections.each}
1464
+ * @alias forEachLimit
1465
+ * @category Collection
1466
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1467
+ * @param {number} limit - The maximum number of async operations at a time.
1468
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
1469
+ * `coll`.
1470
+ * The array index is not passed to the iteratee.
1471
+ * If you need the index, use `eachOfLimit`.
1472
+ * Invoked with (item, callback).
1473
+ * @param {Function} [callback] - A callback which is called when all
1474
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
1475
+ * @returns {Promise} a promise, if a callback is omitted
1476
+ */function eachLimit$1(coll,limit,iteratee,callback){return eachOfLimit(limit)(coll,_withoutIndex(wrapAsync(iteratee)),callback);}var eachLimit$2=awaitify(eachLimit$1,4);/**
1477
+ * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
1478
+ *
1479
+ * Note, that unlike [`each`]{@link module:Collections.each}, this function applies iteratee to each item
1480
+ * in series and therefore the iteratee functions will complete in order.
94
1481
 
95
- /**
96
- * Parse a string with the existing parse tree
97
- * @method parseString
98
- * @param {string} pString - The string to parse
99
- * @param {object} pData - Data to pass in as the second argument
100
- * @return {string} The result from the parser
101
- */
102
- parseString(pString, pData) {
103
- return this.StringParser.parseString(pString, this.ParseTree, pData);
104
- }
105
- }
106
- module.exports = Precedent;
107
- }, {
108
- "./StringParser.js": 3,
109
- "./WordTree.js": 4
110
- }],
111
- 3: [function (require, module, exports) {
112
- /**
113
- * String Parser
114
- *
115
- * @license MIT
116
- *
117
- * @author Steven Velozo <steven@velozo.com>
118
- *
119
- * @description Parse a string, properly processing each matched token in the word tree.
120
- */
1482
+ * @name eachSeries
1483
+ * @static
1484
+ * @memberOf module:Collections
1485
+ * @method
1486
+ * @see [async.each]{@link module:Collections.each}
1487
+ * @alias forEachSeries
1488
+ * @category Collection
1489
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1490
+ * @param {AsyncFunction} iteratee - An async function to apply to each
1491
+ * item in `coll`.
1492
+ * The array index is not passed to the iteratee.
1493
+ * If you need the index, use `eachOfSeries`.
1494
+ * Invoked with (item, callback).
1495
+ * @param {Function} [callback] - A callback which is called when all
1496
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
1497
+ * @returns {Promise} a promise, if a callback is omitted
1498
+ */function eachSeries(coll,iteratee,callback){return eachLimit$2(coll,1,iteratee,callback);}var eachSeries$1=awaitify(eachSeries,3);/**
1499
+ * Wrap an async function and ensure it calls its callback on a later tick of
1500
+ * the event loop. If the function already calls its callback on a next tick,
1501
+ * no extra deferral is added. This is useful for preventing stack overflows
1502
+ * (`RangeError: Maximum call stack size exceeded`) and generally keeping
1503
+ * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)
1504
+ * contained. ES2017 `async` functions are returned as-is -- they are immune
1505
+ * to Zalgo's corrupting influences, as they always resolve on a later tick.
1506
+ *
1507
+ * @name ensureAsync
1508
+ * @static
1509
+ * @memberOf module:Utils
1510
+ * @method
1511
+ * @category Util
1512
+ * @param {AsyncFunction} fn - an async function, one that expects a node-style
1513
+ * callback as its last argument.
1514
+ * @returns {AsyncFunction} Returns a wrapped function with the exact same call
1515
+ * signature as the function passed in.
1516
+ * @example
1517
+ *
1518
+ * function sometimesAsync(arg, callback) {
1519
+ * if (cache[arg]) {
1520
+ * return callback(null, cache[arg]); // this would be synchronous!!
1521
+ * } else {
1522
+ * doSomeIO(arg, callback); // this IO would be asynchronous
1523
+ * }
1524
+ * }
1525
+ *
1526
+ * // this has a risk of stack overflows if many results are cached in a row
1527
+ * async.mapSeries(args, sometimesAsync, done);
1528
+ *
1529
+ * // this will defer sometimesAsync's callback if necessary,
1530
+ * // preventing stack overflows
1531
+ * async.mapSeries(args, async.ensureAsync(sometimesAsync), done);
1532
+ */function ensureAsync(fn){if(isAsync(fn))return fn;return function(...args/*, callback*/){var callback=args.pop();var sync=true;args.push((...innerArgs)=>{if(sync){setImmediate$1(()=>callback(...innerArgs));}else{callback(...innerArgs);}});fn.apply(this,args);sync=false;};}/**
1533
+ * Returns `true` if every element in `coll` satisfies an async test. If any
1534
+ * iteratee call returns `false`, the main `callback` is immediately called.
1535
+ *
1536
+ * @name every
1537
+ * @static
1538
+ * @memberOf module:Collections
1539
+ * @method
1540
+ * @alias all
1541
+ * @category Collection
1542
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1543
+ * @param {AsyncFunction} iteratee - An async truth test to apply to each item
1544
+ * in the collection in parallel.
1545
+ * The iteratee must complete with a boolean result value.
1546
+ * Invoked with (item, callback).
1547
+ * @param {Function} [callback] - A callback which is called after all the
1548
+ * `iteratee` functions have finished. Result will be either `true` or `false`
1549
+ * depending on the values of the async tests. Invoked with (err, result).
1550
+ * @returns {Promise} a promise, if no callback provided
1551
+ * @example
1552
+ *
1553
+ * // dir1 is a directory that contains file1.txt, file2.txt
1554
+ * // dir2 is a directory that contains file3.txt, file4.txt
1555
+ * // dir3 is a directory that contains file5.txt
1556
+ * // dir4 does not exist
1557
+ *
1558
+ * const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file5.txt'];
1559
+ * const withMissingFileList = ['file1.txt','file2.txt','file4.txt'];
1560
+ *
1561
+ * // asynchronous function that checks if a file exists
1562
+ * function fileExists(file, callback) {
1563
+ * fs.access(file, fs.constants.F_OK, (err) => {
1564
+ * callback(null, !err);
1565
+ * });
1566
+ * }
1567
+ *
1568
+ * // Using callbacks
1569
+ * async.every(fileList, fileExists, function(err, result) {
1570
+ * console.log(result);
1571
+ * // true
1572
+ * // result is true since every file exists
1573
+ * });
1574
+ *
1575
+ * async.every(withMissingFileList, fileExists, function(err, result) {
1576
+ * console.log(result);
1577
+ * // false
1578
+ * // result is false since NOT every file exists
1579
+ * });
1580
+ *
1581
+ * // Using Promises
1582
+ * async.every(fileList, fileExists)
1583
+ * .then( result => {
1584
+ * console.log(result);
1585
+ * // true
1586
+ * // result is true since every file exists
1587
+ * }).catch( err => {
1588
+ * console.log(err);
1589
+ * });
1590
+ *
1591
+ * async.every(withMissingFileList, fileExists)
1592
+ * .then( result => {
1593
+ * console.log(result);
1594
+ * // false
1595
+ * // result is false since NOT every file exists
1596
+ * }).catch( err => {
1597
+ * console.log(err);
1598
+ * });
1599
+ *
1600
+ * // Using async/await
1601
+ * async () => {
1602
+ * try {
1603
+ * let result = await async.every(fileList, fileExists);
1604
+ * console.log(result);
1605
+ * // true
1606
+ * // result is true since every file exists
1607
+ * }
1608
+ * catch (err) {
1609
+ * console.log(err);
1610
+ * }
1611
+ * }
1612
+ *
1613
+ * async () => {
1614
+ * try {
1615
+ * let result = await async.every(withMissingFileList, fileExists);
1616
+ * console.log(result);
1617
+ * // false
1618
+ * // result is false since NOT every file exists
1619
+ * }
1620
+ * catch (err) {
1621
+ * console.log(err);
1622
+ * }
1623
+ * }
1624
+ *
1625
+ */function every(coll,iteratee,callback){return _createTester(bool=>!bool,res=>!res)(eachOf$1,coll,iteratee,callback);}var every$1=awaitify(every,3);/**
1626
+ * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
1627
+ *
1628
+ * @name everyLimit
1629
+ * @static
1630
+ * @memberOf module:Collections
1631
+ * @method
1632
+ * @see [async.every]{@link module:Collections.every}
1633
+ * @alias allLimit
1634
+ * @category Collection
1635
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1636
+ * @param {number} limit - The maximum number of async operations at a time.
1637
+ * @param {AsyncFunction} iteratee - An async truth test to apply to each item
1638
+ * in the collection in parallel.
1639
+ * The iteratee must complete with a boolean result value.
1640
+ * Invoked with (item, callback).
1641
+ * @param {Function} [callback] - A callback which is called after all the
1642
+ * `iteratee` functions have finished. Result will be either `true` or `false`
1643
+ * depending on the values of the async tests. Invoked with (err, result).
1644
+ * @returns {Promise} a promise, if no callback provided
1645
+ */function everyLimit(coll,limit,iteratee,callback){return _createTester(bool=>!bool,res=>!res)(eachOfLimit(limit),coll,iteratee,callback);}var everyLimit$1=awaitify(everyLimit,4);/**
1646
+ * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
1647
+ *
1648
+ * @name everySeries
1649
+ * @static
1650
+ * @memberOf module:Collections
1651
+ * @method
1652
+ * @see [async.every]{@link module:Collections.every}
1653
+ * @alias allSeries
1654
+ * @category Collection
1655
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1656
+ * @param {AsyncFunction} iteratee - An async truth test to apply to each item
1657
+ * in the collection in series.
1658
+ * The iteratee must complete with a boolean result value.
1659
+ * Invoked with (item, callback).
1660
+ * @param {Function} [callback] - A callback which is called after all the
1661
+ * `iteratee` functions have finished. Result will be either `true` or `false`
1662
+ * depending on the values of the async tests. Invoked with (err, result).
1663
+ * @returns {Promise} a promise, if no callback provided
1664
+ */function everySeries(coll,iteratee,callback){return _createTester(bool=>!bool,res=>!res)(eachOfSeries$1,coll,iteratee,callback);}var everySeries$1=awaitify(everySeries,3);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=isArrayLike(coll)?filterArray:filterGeneric;return filter(eachfn,coll,wrapAsync(iteratee),callback);}/**
1665
+ * Returns a new array of all the values in `coll` which pass an async truth
1666
+ * test. This operation is performed in parallel, but the results array will be
1667
+ * in the same order as the original.
1668
+ *
1669
+ * @name filter
1670
+ * @static
1671
+ * @memberOf module:Collections
1672
+ * @method
1673
+ * @alias select
1674
+ * @category Collection
1675
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1676
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
1677
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
1678
+ * with a boolean argument once it has completed. Invoked with (item, callback).
1679
+ * @param {Function} [callback] - A callback which is called after all the
1680
+ * `iteratee` functions have finished. Invoked with (err, results).
1681
+ * @returns {Promise} a promise, if no callback provided
1682
+ * @example
1683
+ *
1684
+ * // dir1 is a directory that contains file1.txt, file2.txt
1685
+ * // dir2 is a directory that contains file3.txt, file4.txt
1686
+ * // dir3 is a directory that contains file5.txt
1687
+ *
1688
+ * const files = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];
1689
+ *
1690
+ * // asynchronous function that checks if a file exists
1691
+ * function fileExists(file, callback) {
1692
+ * fs.access(file, fs.constants.F_OK, (err) => {
1693
+ * callback(null, !err);
1694
+ * });
1695
+ * }
1696
+ *
1697
+ * // Using callbacks
1698
+ * async.filter(files, fileExists, function(err, results) {
1699
+ * if(err) {
1700
+ * console.log(err);
1701
+ * } else {
1702
+ * console.log(results);
1703
+ * // [ 'dir1/file1.txt', 'dir2/file3.txt' ]
1704
+ * // results is now an array of the existing files
1705
+ * }
1706
+ * });
1707
+ *
1708
+ * // Using Promises
1709
+ * async.filter(files, fileExists)
1710
+ * .then(results => {
1711
+ * console.log(results);
1712
+ * // [ 'dir1/file1.txt', 'dir2/file3.txt' ]
1713
+ * // results is now an array of the existing files
1714
+ * }).catch(err => {
1715
+ * console.log(err);
1716
+ * });
1717
+ *
1718
+ * // Using async/await
1719
+ * async () => {
1720
+ * try {
1721
+ * let results = await async.filter(files, fileExists);
1722
+ * console.log(results);
1723
+ * // [ 'dir1/file1.txt', 'dir2/file3.txt' ]
1724
+ * // results is now an array of the existing files
1725
+ * }
1726
+ * catch (err) {
1727
+ * console.log(err);
1728
+ * }
1729
+ * }
1730
+ *
1731
+ */function filter(coll,iteratee,callback){return _filter(eachOf$1,coll,iteratee,callback);}var filter$1=awaitify(filter,3);/**
1732
+ * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a
1733
+ * time.
1734
+ *
1735
+ * @name filterLimit
1736
+ * @static
1737
+ * @memberOf module:Collections
1738
+ * @method
1739
+ * @see [async.filter]{@link module:Collections.filter}
1740
+ * @alias selectLimit
1741
+ * @category Collection
1742
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1743
+ * @param {number} limit - The maximum number of async operations at a time.
1744
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
1745
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
1746
+ * with a boolean argument once it has completed. Invoked with (item, callback).
1747
+ * @param {Function} [callback] - A callback which is called after all the
1748
+ * `iteratee` functions have finished. Invoked with (err, results).
1749
+ * @returns {Promise} a promise, if no callback provided
1750
+ */function filterLimit(coll,limit,iteratee,callback){return _filter(eachOfLimit(limit),coll,iteratee,callback);}var filterLimit$1=awaitify(filterLimit,4);/**
1751
+ * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time.
1752
+ *
1753
+ * @name filterSeries
1754
+ * @static
1755
+ * @memberOf module:Collections
1756
+ * @method
1757
+ * @see [async.filter]{@link module:Collections.filter}
1758
+ * @alias selectSeries
1759
+ * @category Collection
1760
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1761
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
1762
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
1763
+ * with a boolean argument once it has completed. Invoked with (item, callback).
1764
+ * @param {Function} [callback] - A callback which is called after all the
1765
+ * `iteratee` functions have finished. Invoked with (err, results)
1766
+ * @returns {Promise} a promise, if no callback provided
1767
+ */function filterSeries(coll,iteratee,callback){return _filter(eachOfSeries$1,coll,iteratee,callback);}var filterSeries$1=awaitify(filterSeries,3);/**
1768
+ * Calls the asynchronous function `fn` with a callback parameter that allows it
1769
+ * to call itself again, in series, indefinitely.
121
1770
 
122
- class StringParser {
123
- /**
124
- * StringParser Constructor
125
- */
126
- constructor() {}
127
-
128
- /**
129
- * Create a fresh parsing state object to work with.
130
- * @method newParserState
131
- * @param {Object} pParseTree - A node on the parse tree to begin parsing from (usually root)
132
- * @return {Object} A new parser state object for running a character parser on
133
- * @private
134
- */
135
- newParserState(pParseTree) {
136
- return {
137
- ParseTree: pParseTree,
138
- Output: '',
139
- OutputBuffer: '',
140
- Pattern: false,
141
- PatternMatch: false,
142
- PatternMatchOutputBuffer: ''
143
- };
144
- }
145
-
146
- /**
147
- * Assign a node of the parser tree to be the next potential match.
148
- * If the node has a PatternEnd property, it is a valid match and supercedes the last valid match (or becomes the initial match).
149
- * @method assignNode
150
- * @param {Object} pNode - A node on the parse tree to assign
151
- * @param {Object} pParserState - The state object for the current parsing task
152
- * @private
153
- */
154
- assignNode(pNode, pParserState) {
155
- pParserState.PatternMatch = pNode;
156
-
157
- // If the pattern has a END we can assume it has a parse function...
158
- if (pParserState.PatternMatch.hasOwnProperty('PatternEnd')) {
159
- // ... this is the legitimate start of a pattern.
160
- pParserState.Pattern = pParserState.PatternMatch;
161
- }
162
- }
163
-
164
- /**
165
- * Append a character to the output buffer in the parser state.
166
- * This output buffer is used when a potential match is being explored, or a match is being explored.
167
- * @method appendOutputBuffer
168
- * @param {string} pCharacter - The character to append
169
- * @param {Object} pParserState - The state object for the current parsing task
170
- * @private
171
- */
172
- appendOutputBuffer(pCharacter, pParserState) {
173
- pParserState.OutputBuffer += pCharacter;
174
- }
175
-
176
- /**
177
- * Flush the output buffer to the output and clear it.
178
- * @method flushOutputBuffer
179
- * @param {Object} pParserState - The state object for the current parsing task
180
- * @private
181
- */
182
- flushOutputBuffer(pParserState) {
183
- pParserState.Output += pParserState.OutputBuffer;
184
- pParserState.OutputBuffer = '';
185
- }
186
-
187
- /**
188
- * Check if the pattern has ended. If it has, properly flush the buffer and start looking for new patterns.
189
- * @method checkPatternEnd
190
- * @param {Object} pParserState - The state object for the current parsing task
191
- * @private
192
- */
193
- checkPatternEnd(pParserState, pData) {
194
- if (pParserState.OutputBuffer.length >= pParserState.Pattern.PatternEnd.length + pParserState.Pattern.PatternStart.length && pParserState.OutputBuffer.substr(-pParserState.Pattern.PatternEnd.length) === pParserState.Pattern.PatternEnd) {
195
- // ... this is the end of a pattern, cut off the end tag and parse it.
196
- // Trim the start and end tags off the output buffer now
197
- pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStart.length + pParserState.Pattern.PatternEnd.length)), pData);
198
- // Flush the output buffer.
199
- this.flushOutputBuffer(pParserState);
200
- // End pattern mode
201
- pParserState.Pattern = false;
202
- pParserState.PatternMatch = false;
203
- }
204
- }
205
-
206
- /**
207
- * Parse a character in the buffer.
208
- * @method parseCharacter
209
- * @param {string} pCharacter - The character to append
210
- * @param {Object} pParserState - The state object for the current parsing task
211
- * @private
212
- */
213
- parseCharacter(pCharacter, pParserState, pData) {
214
- // (1) If we aren't in a pattern match, and we aren't potentially matching, and this may be the start of a new pattern....
215
- if (!pParserState.PatternMatch && pParserState.ParseTree.hasOwnProperty(pCharacter)) {
216
- // ... assign the node as the matched node.
217
- this.assignNode(pParserState.ParseTree[pCharacter], pParserState);
218
- this.appendOutputBuffer(pCharacter, pParserState);
219
- }
220
- // (2) If we are in a pattern match (actively seeing if this is part of a new pattern token)
221
- else if (pParserState.PatternMatch) {
222
- // If the pattern has a subpattern with this key
223
- if (pParserState.PatternMatch.hasOwnProperty(pCharacter)) {
224
- // Continue matching patterns.
225
- this.assignNode(pParserState.PatternMatch[pCharacter], pParserState);
226
- }
227
- this.appendOutputBuffer(pCharacter, pParserState);
228
- if (pParserState.Pattern) {
229
- // ... Check if this is the end of the pattern (if we are matching a valid pattern)...
230
- this.checkPatternEnd(pParserState, pData);
231
- }
232
- }
233
- // (3) If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
234
- else {
235
- pParserState.Output += pCharacter;
236
- }
237
- }
238
-
239
- /**
240
- * Parse a string for matches, and process any template segments that occur.
241
- * @method parseString
242
- * @param {string} pString - The string to parse.
243
- * @param {Object} pParseTree - The parse tree to begin parsing from (usually root)
244
- * @param {Object} pData - The data to pass to the function as a second paramter
245
- */
246
- parseString(pString, pParseTree, pData) {
247
- let tmpParserState = this.newParserState(pParseTree);
248
- for (var i = 0; i < pString.length; i++) {
249
- // TODO: This is not fast.
250
- this.parseCharacter(pString[i], tmpParserState, pData);
251
- }
252
- this.flushOutputBuffer(tmpParserState);
253
- return tmpParserState.Output;
254
- }
255
- }
256
- module.exports = StringParser;
257
- }, {}],
258
- 4: [function (require, module, exports) {
259
- /**
260
- * Word Tree
261
- *
262
- * @license MIT
263
- *
264
- * @author Steven Velozo <steven@velozo.com>
265
- *
266
- * @description Create a tree (directed graph) of Javascript objects, one character per object.
267
- */
268
-
269
- class WordTree {
270
- /**
271
- * WordTree Constructor
272
- */
273
- constructor() {
274
- this.ParseTree = {};
275
- }
276
-
277
- /**
278
- * Add a child character to a Parse Tree node
279
- * @method addChild
280
- * @param {Object} pTree - A parse tree to push the characters into
281
- * @param {string} pPattern - The string to add to the tree
282
- * @param {number} pIndex - The index of the character in the pattern
283
- * @returns {Object} The resulting leaf node that was added (or found)
284
- * @private
285
- */
286
- addChild(pTree, pPattern, pIndex) {
287
- if (!pTree.hasOwnProperty(pPattern[pIndex])) pTree[pPattern[pIndex]] = {};
288
- return pTree[pPattern[pIndex]];
289
- }
290
-
291
- /** Add a Pattern to the Parse Tree
292
- * @method addPattern
293
- * @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
294
- * @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
295
- * @param {number} pParser - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
296
- * @return {bool} True if adding the pattern was successful
297
- */
298
- addPattern(pPatternStart, pPatternEnd, pParser) {
299
- if (pPatternStart.length < 1) return false;
300
- if (typeof pPatternEnd === 'string' && pPatternEnd.length < 1) return false;
301
- let tmpLeaf = this.ParseTree;
302
-
303
- // Add the tree of leaves iteratively
304
- for (var i = 0; i < pPatternStart.length; i++) tmpLeaf = this.addChild(tmpLeaf, pPatternStart, i);
305
- tmpLeaf.PatternStart = pPatternStart;
306
- tmpLeaf.PatternEnd = typeof pPatternEnd === 'string' && pPatternEnd.length > 0 ? pPatternEnd : pPatternStart;
307
- tmpLeaf.Parse = typeof pParser === 'function' ? pParser : typeof pParser === 'string' ? () => {
308
- return pParser;
309
- } : pData => {
310
- return pData;
311
- };
312
- return true;
313
- }
314
- }
315
- module.exports = WordTree;
316
- }, {}]
317
- }, {}, [1])(1);
318
- });
1771
+ * If an error is passed to the callback then `errback` is called with the
1772
+ * error, and execution stops, otherwise it will never be called.
1773
+ *
1774
+ * @name forever
1775
+ * @static
1776
+ * @memberOf module:ControlFlow
1777
+ * @method
1778
+ * @category Control Flow
1779
+ * @param {AsyncFunction} fn - an async function to call repeatedly.
1780
+ * Invoked with (next).
1781
+ * @param {Function} [errback] - when `fn` passes an error to it's callback,
1782
+ * this function will be called, and execution stops. Invoked with (err).
1783
+ * @returns {Promise} a promise that rejects if an error occurs and an errback
1784
+ * is not passed
1785
+ * @example
1786
+ *
1787
+ * async.forever(
1788
+ * function(next) {
1789
+ * // next is suitable for passing to things that need a callback(err [, whatever]);
1790
+ * // it will result in this function being called again.
1791
+ * },
1792
+ * function(err) {
1793
+ * // if next is called with a value in its first parameter, it will appear
1794
+ * // in here as 'err', and execution will stop.
1795
+ * }
1796
+ * );
1797
+ */function forever(fn,errback){var done=onlyOnce(errback);var task=wrapAsync(ensureAsync(fn));function next(err){if(err)return done(err);if(err===false)return;task(next);}return next();}var forever$1=awaitify(forever,2);/**
1798
+ * The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.
1799
+ *
1800
+ * @name groupByLimit
1801
+ * @static
1802
+ * @memberOf module:Collections
1803
+ * @method
1804
+ * @see [async.groupBy]{@link module:Collections.groupBy}
1805
+ * @category Collection
1806
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1807
+ * @param {number} limit - The maximum number of async operations at a time.
1808
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
1809
+ * `coll`.
1810
+ * The iteratee should complete with a `key` to group the value under.
1811
+ * Invoked with (value, callback).
1812
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
1813
+ * functions have finished, or an error occurs. Result is an `Object` whoses
1814
+ * properties are arrays of values which returned the corresponding key.
1815
+ * @returns {Promise} a promise, if no callback is passed
1816
+ */function groupByLimit(coll,limit,iteratee,callback){var _iteratee=wrapAsync(iteratee);return mapLimit$1(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
1817
+ 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);});}var groupByLimit$1=awaitify(groupByLimit,4);/**
1818
+ * Returns a new object, where each value corresponds to an array of items, from
1819
+ * `coll`, that returned the corresponding key. That is, the keys of the object
1820
+ * correspond to the values passed to the `iteratee` callback.
1821
+ *
1822
+ * Note: Since this function applies the `iteratee` to each item in parallel,
1823
+ * there is no guarantee that the `iteratee` functions will complete in order.
1824
+ * However, the values for each key in the `result` will be in the same order as
1825
+ * the original `coll`. For Objects, the values will roughly be in the order of
1826
+ * the original Objects' keys (but this can vary across JavaScript engines).
1827
+ *
1828
+ * @name groupBy
1829
+ * @static
1830
+ * @memberOf module:Collections
1831
+ * @method
1832
+ * @category Collection
1833
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1834
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
1835
+ * `coll`.
1836
+ * The iteratee should complete with a `key` to group the value under.
1837
+ * Invoked with (value, callback).
1838
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
1839
+ * functions have finished, or an error occurs. Result is an `Object` whoses
1840
+ * properties are arrays of values which returned the corresponding key.
1841
+ * @returns {Promise} a promise, if no callback is passed
1842
+ * @example
1843
+ *
1844
+ * // dir1 is a directory that contains file1.txt, file2.txt
1845
+ * // dir2 is a directory that contains file3.txt, file4.txt
1846
+ * // dir3 is a directory that contains file5.txt
1847
+ * // dir4 does not exist
1848
+ *
1849
+ * const files = ['dir1/file1.txt','dir2','dir4']
1850
+ *
1851
+ * // asynchronous function that detects file type as none, file, or directory
1852
+ * function detectFile(file, callback) {
1853
+ * fs.stat(file, function(err, stat) {
1854
+ * if (err) {
1855
+ * return callback(null, 'none');
1856
+ * }
1857
+ * callback(null, stat.isDirectory() ? 'directory' : 'file');
1858
+ * });
1859
+ * }
1860
+ *
1861
+ * //Using callbacks
1862
+ * async.groupBy(files, detectFile, function(err, result) {
1863
+ * if(err) {
1864
+ * console.log(err);
1865
+ * } else {
1866
+ * console.log(result);
1867
+ * // {
1868
+ * // file: [ 'dir1/file1.txt' ],
1869
+ * // none: [ 'dir4' ],
1870
+ * // directory: [ 'dir2']
1871
+ * // }
1872
+ * // result is object containing the files grouped by type
1873
+ * }
1874
+ * });
1875
+ *
1876
+ * // Using Promises
1877
+ * async.groupBy(files, detectFile)
1878
+ * .then( result => {
1879
+ * console.log(result);
1880
+ * // {
1881
+ * // file: [ 'dir1/file1.txt' ],
1882
+ * // none: [ 'dir4' ],
1883
+ * // directory: [ 'dir2']
1884
+ * // }
1885
+ * // result is object containing the files grouped by type
1886
+ * }).catch( err => {
1887
+ * console.log(err);
1888
+ * });
1889
+ *
1890
+ * // Using async/await
1891
+ * async () => {
1892
+ * try {
1893
+ * let result = await async.groupBy(files, detectFile);
1894
+ * console.log(result);
1895
+ * // {
1896
+ * // file: [ 'dir1/file1.txt' ],
1897
+ * // none: [ 'dir4' ],
1898
+ * // directory: [ 'dir2']
1899
+ * // }
1900
+ * // result is object containing the files grouped by type
1901
+ * }
1902
+ * catch (err) {
1903
+ * console.log(err);
1904
+ * }
1905
+ * }
1906
+ *
1907
+ */function groupBy(coll,iteratee,callback){return groupByLimit$1(coll,Infinity,iteratee,callback);}/**
1908
+ * The same as [`groupBy`]{@link module:Collections.groupBy} but runs only a single async operation at a time.
1909
+ *
1910
+ * @name groupBySeries
1911
+ * @static
1912
+ * @memberOf module:Collections
1913
+ * @method
1914
+ * @see [async.groupBy]{@link module:Collections.groupBy}
1915
+ * @category Collection
1916
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
1917
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
1918
+ * `coll`.
1919
+ * The iteratee should complete with a `key` to group the value under.
1920
+ * Invoked with (value, callback).
1921
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
1922
+ * functions have finished, or an error occurs. Result is an `Object` whose
1923
+ * properties are arrays of values which returned the corresponding key.
1924
+ * @returns {Promise} a promise, if no callback is passed
1925
+ */function groupBySeries(coll,iteratee,callback){return groupByLimit$1(coll,1,iteratee,callback);}/**
1926
+ * Logs the result of an `async` function to the `console`. Only works in
1927
+ * Node.js or in browsers that support `console.log` and `console.error` (such
1928
+ * as FF and Chrome). If multiple arguments are returned from the async
1929
+ * function, `console.log` is called on each argument in order.
1930
+ *
1931
+ * @name log
1932
+ * @static
1933
+ * @memberOf module:Utils
1934
+ * @method
1935
+ * @category Util
1936
+ * @param {AsyncFunction} function - The function you want to eventually apply
1937
+ * all arguments to.
1938
+ * @param {...*} arguments... - Any number of arguments to apply to the function.
1939
+ * @example
1940
+ *
1941
+ * // in a module
1942
+ * var hello = function(name, callback) {
1943
+ * setTimeout(function() {
1944
+ * callback(null, 'hello ' + name);
1945
+ * }, 1000);
1946
+ * };
1947
+ *
1948
+ * // in the node repl
1949
+ * node> async.log(hello, 'world');
1950
+ * 'hello world'
1951
+ */var log=consoleFunc('log');/**
1952
+ * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
1953
+ * time.
1954
+ *
1955
+ * @name mapValuesLimit
1956
+ * @static
1957
+ * @memberOf module:Collections
1958
+ * @method
1959
+ * @see [async.mapValues]{@link module:Collections.mapValues}
1960
+ * @category Collection
1961
+ * @param {Object} obj - A collection to iterate over.
1962
+ * @param {number} limit - The maximum number of async operations at a time.
1963
+ * @param {AsyncFunction} iteratee - A function to apply to each value and key
1964
+ * in `coll`.
1965
+ * The iteratee should complete with the transformed value as its result.
1966
+ * Invoked with (value, key, callback).
1967
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
1968
+ * functions have finished, or an error occurs. `result` is a new object consisting
1969
+ * of each key from `obj`, with each transformed value on the right-hand side.
1970
+ * Invoked with (err, result).
1971
+ * @returns {Promise} a promise, if no callback is passed
1972
+ */function mapValuesLimit(obj,limit,iteratee,callback){callback=once(callback);var newObj={};var _iteratee=wrapAsync(iteratee);return eachOfLimit(limit)(obj,(val,key,next)=>{_iteratee(val,key,(err,result)=>{if(err)return next(err);newObj[key]=result;next(err);});},err=>callback(err,newObj));}var mapValuesLimit$1=awaitify(mapValuesLimit,4);/**
1973
+ * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
1974
+ *
1975
+ * Produces a new Object by mapping each value of `obj` through the `iteratee`
1976
+ * function. The `iteratee` is called each `value` and `key` from `obj` and a
1977
+ * callback for when it has finished processing. Each of these callbacks takes
1978
+ * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
1979
+ * passes an error to its callback, the main `callback` (for the `mapValues`
1980
+ * function) is immediately called with the error.
1981
+ *
1982
+ * Note, the order of the keys in the result is not guaranteed. The keys will
1983
+ * be roughly in the order they complete, (but this is very engine-specific)
1984
+ *
1985
+ * @name mapValues
1986
+ * @static
1987
+ * @memberOf module:Collections
1988
+ * @method
1989
+ * @category Collection
1990
+ * @param {Object} obj - A collection to iterate over.
1991
+ * @param {AsyncFunction} iteratee - A function to apply to each value and key
1992
+ * in `coll`.
1993
+ * The iteratee should complete with the transformed value as its result.
1994
+ * Invoked with (value, key, callback).
1995
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
1996
+ * functions have finished, or an error occurs. `result` is a new object consisting
1997
+ * of each key from `obj`, with each transformed value on the right-hand side.
1998
+ * Invoked with (err, result).
1999
+ * @returns {Promise} a promise, if no callback is passed
2000
+ * @example
2001
+ *
2002
+ * // file1.txt is a file that is 1000 bytes in size
2003
+ * // file2.txt is a file that is 2000 bytes in size
2004
+ * // file3.txt is a file that is 3000 bytes in size
2005
+ * // file4.txt does not exist
2006
+ *
2007
+ * const fileMap = {
2008
+ * f1: 'file1.txt',
2009
+ * f2: 'file2.txt',
2010
+ * f3: 'file3.txt'
2011
+ * };
2012
+ *
2013
+ * const withMissingFileMap = {
2014
+ * f1: 'file1.txt',
2015
+ * f2: 'file2.txt',
2016
+ * f3: 'file4.txt'
2017
+ * };
2018
+ *
2019
+ * // asynchronous function that returns the file size in bytes
2020
+ * function getFileSizeInBytes(file, key, callback) {
2021
+ * fs.stat(file, function(err, stat) {
2022
+ * if (err) {
2023
+ * return callback(err);
2024
+ * }
2025
+ * callback(null, stat.size);
2026
+ * });
2027
+ * }
2028
+ *
2029
+ * // Using callbacks
2030
+ * async.mapValues(fileMap, getFileSizeInBytes, function(err, result) {
2031
+ * if (err) {
2032
+ * console.log(err);
2033
+ * } else {
2034
+ * console.log(result);
2035
+ * // result is now a map of file size in bytes for each file, e.g.
2036
+ * // {
2037
+ * // f1: 1000,
2038
+ * // f2: 2000,
2039
+ * // f3: 3000
2040
+ * // }
2041
+ * }
2042
+ * });
2043
+ *
2044
+ * // Error handling
2045
+ * async.mapValues(withMissingFileMap, getFileSizeInBytes, function(err, result) {
2046
+ * if (err) {
2047
+ * console.log(err);
2048
+ * // [ Error: ENOENT: no such file or directory ]
2049
+ * } else {
2050
+ * console.log(result);
2051
+ * }
2052
+ * });
2053
+ *
2054
+ * // Using Promises
2055
+ * async.mapValues(fileMap, getFileSizeInBytes)
2056
+ * .then( result => {
2057
+ * console.log(result);
2058
+ * // result is now a map of file size in bytes for each file, e.g.
2059
+ * // {
2060
+ * // f1: 1000,
2061
+ * // f2: 2000,
2062
+ * // f3: 3000
2063
+ * // }
2064
+ * }).catch (err => {
2065
+ * console.log(err);
2066
+ * });
2067
+ *
2068
+ * // Error Handling
2069
+ * async.mapValues(withMissingFileMap, getFileSizeInBytes)
2070
+ * .then( result => {
2071
+ * console.log(result);
2072
+ * }).catch (err => {
2073
+ * console.log(err);
2074
+ * // [ Error: ENOENT: no such file or directory ]
2075
+ * });
2076
+ *
2077
+ * // Using async/await
2078
+ * async () => {
2079
+ * try {
2080
+ * let result = await async.mapValues(fileMap, getFileSizeInBytes);
2081
+ * console.log(result);
2082
+ * // result is now a map of file size in bytes for each file, e.g.
2083
+ * // {
2084
+ * // f1: 1000,
2085
+ * // f2: 2000,
2086
+ * // f3: 3000
2087
+ * // }
2088
+ * }
2089
+ * catch (err) {
2090
+ * console.log(err);
2091
+ * }
2092
+ * }
2093
+ *
2094
+ * // Error Handling
2095
+ * async () => {
2096
+ * try {
2097
+ * let result = await async.mapValues(withMissingFileMap, getFileSizeInBytes);
2098
+ * console.log(result);
2099
+ * }
2100
+ * catch (err) {
2101
+ * console.log(err);
2102
+ * // [ Error: ENOENT: no such file or directory ]
2103
+ * }
2104
+ * }
2105
+ *
2106
+ */function mapValues(obj,iteratee,callback){return mapValuesLimit$1(obj,Infinity,iteratee,callback);}/**
2107
+ * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time.
2108
+ *
2109
+ * @name mapValuesSeries
2110
+ * @static
2111
+ * @memberOf module:Collections
2112
+ * @method
2113
+ * @see [async.mapValues]{@link module:Collections.mapValues}
2114
+ * @category Collection
2115
+ * @param {Object} obj - A collection to iterate over.
2116
+ * @param {AsyncFunction} iteratee - A function to apply to each value and key
2117
+ * in `coll`.
2118
+ * The iteratee should complete with the transformed value as its result.
2119
+ * Invoked with (value, key, callback).
2120
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
2121
+ * functions have finished, or an error occurs. `result` is a new object consisting
2122
+ * of each key from `obj`, with each transformed value on the right-hand side.
2123
+ * Invoked with (err, result).
2124
+ * @returns {Promise} a promise, if no callback is passed
2125
+ */function mapValuesSeries(obj,iteratee,callback){return mapValuesLimit$1(obj,1,iteratee,callback);}/**
2126
+ * Caches the results of an async function. When creating a hash to store
2127
+ * function results against, the callback is omitted from the hash and an
2128
+ * optional hash function can be used.
2129
+ *
2130
+ * **Note: if the async function errs, the result will not be cached and
2131
+ * subsequent calls will call the wrapped function.**
2132
+ *
2133
+ * If no hash function is specified, the first argument is used as a hash key,
2134
+ * which may work reasonably if it is a string or a data type that converts to a
2135
+ * distinct string. Note that objects and arrays will not behave reasonably.
2136
+ * Neither will cases where the other arguments are significant. In such cases,
2137
+ * specify your own hash function.
2138
+ *
2139
+ * The cache of results is exposed as the `memo` property of the function
2140
+ * returned by `memoize`.
2141
+ *
2142
+ * @name memoize
2143
+ * @static
2144
+ * @memberOf module:Utils
2145
+ * @method
2146
+ * @category Util
2147
+ * @param {AsyncFunction} fn - The async function to proxy and cache results from.
2148
+ * @param {Function} hasher - An optional function for generating a custom hash
2149
+ * for storing results. It has all the arguments applied to it apart from the
2150
+ * callback, and must be synchronous.
2151
+ * @returns {AsyncFunction} a memoized version of `fn`
2152
+ * @example
2153
+ *
2154
+ * var slow_fn = function(name, callback) {
2155
+ * // do something
2156
+ * callback(null, result);
2157
+ * };
2158
+ * var fn = async.memoize(slow_fn);
2159
+ *
2160
+ * // fn can now be used as if it were slow_fn
2161
+ * fn('some name', function() {
2162
+ * // callback
2163
+ * });
2164
+ */function memoize(fn,hasher=v=>v){var memo=Object.create(null);var queues=Object.create(null);var _fn=wrapAsync(fn);var memoized=initialParams((args,callback)=>{var key=hasher(...args);if(key in memo){setImmediate$1(()=>callback(null,...memo[key]));}else if(key in queues){queues[key].push(callback);}else{queues[key]=[callback];_fn(...args,(err,...resultArgs)=>{// #1465 don't memoize if an error occurred
2165
+ if(!err){memo[key]=resultArgs;}var q=queues[key];delete queues[key];for(var i=0,l=q.length;i<l;i++){q[i](err,...resultArgs);}});}});memoized.memo=memo;memoized.unmemoized=fn;return memoized;}/* istanbul ignore file */ /**
2166
+ * Calls `callback` on a later loop around the event loop. In Node.js this just
2167
+ * calls `process.nextTick`. In the browser it will use `setImmediate` if
2168
+ * available, otherwise `setTimeout(callback, 0)`, which means other higher
2169
+ * priority events may precede the execution of `callback`.
2170
+ *
2171
+ * This is used internally for browser-compatibility purposes.
2172
+ *
2173
+ * @name nextTick
2174
+ * @static
2175
+ * @memberOf module:Utils
2176
+ * @method
2177
+ * @see [async.setImmediate]{@link module:Utils.setImmediate}
2178
+ * @category Util
2179
+ * @param {Function} callback - The function to call on a later loop around
2180
+ * the event loop. Invoked with (args...).
2181
+ * @param {...*} args... - any number of additional arguments to pass to the
2182
+ * callback on the next tick.
2183
+ * @example
2184
+ *
2185
+ * var call_order = [];
2186
+ * async.nextTick(function() {
2187
+ * call_order.push('two');
2188
+ * // call_order now equals ['one','two']
2189
+ * });
2190
+ * call_order.push('one');
2191
+ *
2192
+ * async.setImmediate(function (a, b, c) {
2193
+ * // a, b, and c equal 1, 2, and 3
2194
+ * }, 1, 2, 3);
2195
+ */var _defer$1;if(hasNextTick){_defer$1=process.nextTick;}else if(hasSetImmediate){_defer$1=setImmediate;}else{_defer$1=fallback;}var nextTick=wrap(_defer$1);var parallel=awaitify((eachfn,tasks,callback)=>{var results=isArrayLike(tasks)?[]:{};eachfn(tasks,(task,key,taskCb)=>{wrapAsync(task)((err,...result)=>{if(result.length<2){[result]=result;}results[key]=result;taskCb(err);});},err=>callback(err,results));},3);/**
2196
+ * Run the `tasks` collection of functions in parallel, without waiting until
2197
+ * the previous function has completed. If any of the functions pass an error to
2198
+ * its callback, the main `callback` is immediately called with the value of the
2199
+ * error. Once the `tasks` have completed, the results are passed to the final
2200
+ * `callback` as an array.
2201
+ *
2202
+ * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
2203
+ * parallel execution of code. If your tasks do not use any timers or perform
2204
+ * any I/O, they will actually be executed in series. Any synchronous setup
2205
+ * sections for each task will happen one after the other. JavaScript remains
2206
+ * single-threaded.
2207
+ *
2208
+ * **Hint:** Use [`reflect`]{@link module:Utils.reflect} to continue the
2209
+ * execution of other tasks when a task fails.
2210
+ *
2211
+ * It is also possible to use an object instead of an array. Each property will
2212
+ * be run as a function and the results will be passed to the final `callback`
2213
+ * as an object instead of an array. This can be a more readable way of handling
2214
+ * results from {@link async.parallel}.
2215
+ *
2216
+ * @name parallel
2217
+ * @static
2218
+ * @memberOf module:ControlFlow
2219
+ * @method
2220
+ * @category Control Flow
2221
+ * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of
2222
+ * [async functions]{@link AsyncFunction} to run.
2223
+ * Each async function can complete with any number of optional `result` values.
2224
+ * @param {Function} [callback] - An optional callback to run once all the
2225
+ * functions have completed successfully. This function gets a results array
2226
+ * (or object) containing all the result arguments passed to the task callbacks.
2227
+ * Invoked with (err, results).
2228
+ * @returns {Promise} a promise, if a callback is not passed
2229
+ *
2230
+ * @example
2231
+ *
2232
+ * //Using Callbacks
2233
+ * async.parallel([
2234
+ * function(callback) {
2235
+ * setTimeout(function() {
2236
+ * callback(null, 'one');
2237
+ * }, 200);
2238
+ * },
2239
+ * function(callback) {
2240
+ * setTimeout(function() {
2241
+ * callback(null, 'two');
2242
+ * }, 100);
2243
+ * }
2244
+ * ], function(err, results) {
2245
+ * console.log(results);
2246
+ * // results is equal to ['one','two'] even though
2247
+ * // the second function had a shorter timeout.
2248
+ * });
2249
+ *
2250
+ * // an example using an object instead of an array
2251
+ * async.parallel({
2252
+ * one: function(callback) {
2253
+ * setTimeout(function() {
2254
+ * callback(null, 1);
2255
+ * }, 200);
2256
+ * },
2257
+ * two: function(callback) {
2258
+ * setTimeout(function() {
2259
+ * callback(null, 2);
2260
+ * }, 100);
2261
+ * }
2262
+ * }, function(err, results) {
2263
+ * console.log(results);
2264
+ * // results is equal to: { one: 1, two: 2 }
2265
+ * });
2266
+ *
2267
+ * //Using Promises
2268
+ * async.parallel([
2269
+ * function(callback) {
2270
+ * setTimeout(function() {
2271
+ * callback(null, 'one');
2272
+ * }, 200);
2273
+ * },
2274
+ * function(callback) {
2275
+ * setTimeout(function() {
2276
+ * callback(null, 'two');
2277
+ * }, 100);
2278
+ * }
2279
+ * ]).then(results => {
2280
+ * console.log(results);
2281
+ * // results is equal to ['one','two'] even though
2282
+ * // the second function had a shorter timeout.
2283
+ * }).catch(err => {
2284
+ * console.log(err);
2285
+ * });
2286
+ *
2287
+ * // an example using an object instead of an array
2288
+ * async.parallel({
2289
+ * one: function(callback) {
2290
+ * setTimeout(function() {
2291
+ * callback(null, 1);
2292
+ * }, 200);
2293
+ * },
2294
+ * two: function(callback) {
2295
+ * setTimeout(function() {
2296
+ * callback(null, 2);
2297
+ * }, 100);
2298
+ * }
2299
+ * }).then(results => {
2300
+ * console.log(results);
2301
+ * // results is equal to: { one: 1, two: 2 }
2302
+ * }).catch(err => {
2303
+ * console.log(err);
2304
+ * });
2305
+ *
2306
+ * //Using async/await
2307
+ * async () => {
2308
+ * try {
2309
+ * let results = await async.parallel([
2310
+ * function(callback) {
2311
+ * setTimeout(function() {
2312
+ * callback(null, 'one');
2313
+ * }, 200);
2314
+ * },
2315
+ * function(callback) {
2316
+ * setTimeout(function() {
2317
+ * callback(null, 'two');
2318
+ * }, 100);
2319
+ * }
2320
+ * ]);
2321
+ * console.log(results);
2322
+ * // results is equal to ['one','two'] even though
2323
+ * // the second function had a shorter timeout.
2324
+ * }
2325
+ * catch (err) {
2326
+ * console.log(err);
2327
+ * }
2328
+ * }
2329
+ *
2330
+ * // an example using an object instead of an array
2331
+ * async () => {
2332
+ * try {
2333
+ * let results = await async.parallel({
2334
+ * one: function(callback) {
2335
+ * setTimeout(function() {
2336
+ * callback(null, 1);
2337
+ * }, 200);
2338
+ * },
2339
+ * two: function(callback) {
2340
+ * setTimeout(function() {
2341
+ * callback(null, 2);
2342
+ * }, 100);
2343
+ * }
2344
+ * });
2345
+ * console.log(results);
2346
+ * // results is equal to: { one: 1, two: 2 }
2347
+ * }
2348
+ * catch (err) {
2349
+ * console.log(err);
2350
+ * }
2351
+ * }
2352
+ *
2353
+ */function parallel$1(tasks,callback){return parallel(eachOf$1,tasks,callback);}/**
2354
+ * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
2355
+ * time.
2356
+ *
2357
+ * @name parallelLimit
2358
+ * @static
2359
+ * @memberOf module:ControlFlow
2360
+ * @method
2361
+ * @see [async.parallel]{@link module:ControlFlow.parallel}
2362
+ * @category Control Flow
2363
+ * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of
2364
+ * [async functions]{@link AsyncFunction} to run.
2365
+ * Each async function can complete with any number of optional `result` values.
2366
+ * @param {number} limit - The maximum number of async operations at a time.
2367
+ * @param {Function} [callback] - An optional callback to run once all the
2368
+ * functions have completed successfully. This function gets a results array
2369
+ * (or object) containing all the result arguments passed to the task callbacks.
2370
+ * Invoked with (err, results).
2371
+ * @returns {Promise} a promise, if a callback is not passed
2372
+ */function parallelLimit(tasks,limit,callback){return parallel(eachOfLimit(limit),tasks,callback);}/**
2373
+ * A queue of tasks for the worker function to complete.
2374
+ * @typedef {Iterable} QueueObject
2375
+ * @memberOf module:ControlFlow
2376
+ * @property {Function} length - a function returning the number of items
2377
+ * waiting to be processed. Invoke with `queue.length()`.
2378
+ * @property {boolean} started - a boolean indicating whether or not any
2379
+ * items have been pushed and processed by the queue.
2380
+ * @property {Function} running - a function returning the number of items
2381
+ * currently being processed. Invoke with `queue.running()`.
2382
+ * @property {Function} workersList - a function returning the array of items
2383
+ * currently being processed. Invoke with `queue.workersList()`.
2384
+ * @property {Function} idle - a function returning false if there are items
2385
+ * waiting or being processed, or true if not. Invoke with `queue.idle()`.
2386
+ * @property {number} concurrency - an integer for determining how many `worker`
2387
+ * functions should be run in parallel. This property can be changed after a
2388
+ * `queue` is created to alter the concurrency on-the-fly.
2389
+ * @property {number} payload - an integer that specifies how many items are
2390
+ * passed to the worker function at a time. only applies if this is a
2391
+ * [cargo]{@link module:ControlFlow.cargo} object
2392
+ * @property {AsyncFunction} push - add a new task to the `queue`. Calls `callback`
2393
+ * once the `worker` has finished processing the task. Instead of a single task,
2394
+ * a `tasks` array can be submitted. The respective callback is used for every
2395
+ * task in the list. Invoke with `queue.push(task, [callback])`,
2396
+ * @property {AsyncFunction} unshift - add a new task to the front of the `queue`.
2397
+ * Invoke with `queue.unshift(task, [callback])`.
2398
+ * @property {AsyncFunction} pushAsync - the same as `q.push`, except this returns
2399
+ * a promise that rejects if an error occurs.
2400
+ * @property {AsyncFunction} unshiftAsync - the same as `q.unshift`, except this returns
2401
+ * a promise that rejects if an error occurs.
2402
+ * @property {Function} remove - remove items from the queue that match a test
2403
+ * function. The test function will be passed an object with a `data` property,
2404
+ * and a `priority` property, if this is a
2405
+ * [priorityQueue]{@link module:ControlFlow.priorityQueue} object.
2406
+ * Invoked with `queue.remove(testFn)`, where `testFn` is of the form
2407
+ * `function ({data, priority}) {}` and returns a Boolean.
2408
+ * @property {Function} saturated - a function that sets a callback that is
2409
+ * called when the number of running workers hits the `concurrency` limit, and
2410
+ * further tasks will be queued. If the callback is omitted, `q.saturated()`
2411
+ * returns a promise for the next occurrence.
2412
+ * @property {Function} unsaturated - a function that sets a callback that is
2413
+ * called when the number of running workers is less than the `concurrency` &
2414
+ * `buffer` limits, and further tasks will not be queued. If the callback is
2415
+ * omitted, `q.unsaturated()` returns a promise for the next occurrence.
2416
+ * @property {number} buffer - A minimum threshold buffer in order to say that
2417
+ * the `queue` is `unsaturated`.
2418
+ * @property {Function} empty - a function that sets a callback that is called
2419
+ * when the last item from the `queue` is given to a `worker`. If the callback
2420
+ * is omitted, `q.empty()` returns a promise for the next occurrence.
2421
+ * @property {Function} drain - a function that sets a callback that is called
2422
+ * when the last item from the `queue` has returned from the `worker`. If the
2423
+ * callback is omitted, `q.drain()` returns a promise for the next occurrence.
2424
+ * @property {Function} error - a function that sets a callback that is called
2425
+ * when a task errors. Has the signature `function(error, task)`. If the
2426
+ * callback is omitted, `error()` returns a promise that rejects on the next
2427
+ * error.
2428
+ * @property {boolean} paused - a boolean for determining whether the queue is
2429
+ * in a paused state.
2430
+ * @property {Function} pause - a function that pauses the processing of tasks
2431
+ * until `resume()` is called. Invoke with `queue.pause()`.
2432
+ * @property {Function} resume - a function that resumes the processing of
2433
+ * queued tasks when the queue is paused. Invoke with `queue.resume()`.
2434
+ * @property {Function} kill - a function that removes the `drain` callback and
2435
+ * empties remaining tasks from the queue forcing it to go idle. No more tasks
2436
+ * should be pushed to the queue after calling this function. Invoke with `queue.kill()`.
2437
+ *
2438
+ * @example
2439
+ * const q = async.queue(worker, 2)
2440
+ * q.push(item1)
2441
+ * q.push(item2)
2442
+ * q.push(item3)
2443
+ * // queues are iterable, spread into an array to inspect
2444
+ * const items = [...q] // [item1, item2, item3]
2445
+ * // or use for of
2446
+ * for (let item of q) {
2447
+ * console.log(item)
2448
+ * }
2449
+ *
2450
+ * q.drain(() => {
2451
+ * console.log('all done')
2452
+ * })
2453
+ * // or
2454
+ * await q.drain()
2455
+ */ /**
2456
+ * Creates a `queue` object with the specified `concurrency`. Tasks added to the
2457
+ * `queue` are processed in parallel (up to the `concurrency` limit). If all
2458
+ * `worker`s are in progress, the task is queued until one becomes available.
2459
+ * Once a `worker` completes a `task`, that `task`'s callback is called.
2460
+ *
2461
+ * @name queue
2462
+ * @static
2463
+ * @memberOf module:ControlFlow
2464
+ * @method
2465
+ * @category Control Flow
2466
+ * @param {AsyncFunction} worker - An async function for processing a queued task.
2467
+ * If you want to handle errors from an individual task, pass a callback to
2468
+ * `q.push()`. Invoked with (task, callback).
2469
+ * @param {number} [concurrency=1] - An `integer` for determining how many
2470
+ * `worker` functions should be run in parallel. If omitted, the concurrency
2471
+ * defaults to `1`. If the concurrency is `0`, an error is thrown.
2472
+ * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can be
2473
+ * attached as certain properties to listen for specific events during the
2474
+ * lifecycle of the queue.
2475
+ * @example
2476
+ *
2477
+ * // create a queue object with concurrency 2
2478
+ * var q = async.queue(function(task, callback) {
2479
+ * console.log('hello ' + task.name);
2480
+ * callback();
2481
+ * }, 2);
2482
+ *
2483
+ * // assign a callback
2484
+ * q.drain(function() {
2485
+ * console.log('all items have been processed');
2486
+ * });
2487
+ * // or await the end
2488
+ * await q.drain()
2489
+ *
2490
+ * // assign an error callback
2491
+ * q.error(function(err, task) {
2492
+ * console.error('task experienced an error');
2493
+ * });
2494
+ *
2495
+ * // add some items to the queue
2496
+ * q.push({name: 'foo'}, function(err) {
2497
+ * console.log('finished processing foo');
2498
+ * });
2499
+ * // callback is optional
2500
+ * q.push({name: 'bar'});
2501
+ *
2502
+ * // add some items to the queue (batch-wise)
2503
+ * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
2504
+ * console.log('finished processing item');
2505
+ * });
2506
+ *
2507
+ * // add some items to the front of the queue
2508
+ * q.unshift({name: 'bar'}, function (err) {
2509
+ * console.log('finished processing bar');
2510
+ * });
2511
+ */function queue$1(worker,concurrency){var _worker=wrapAsync(worker);return queue((items,cb)=>{_worker(items[0],cb);},concurrency,1);}// Binary min-heap implementation used for priority queue.
2512
+ // Implementation is stable, i.e. push time is considered for equal priorities
2513
+ 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;}}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;}}/**
2514
+ * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
2515
+ * completed in ascending priority order.
2516
+ *
2517
+ * @name priorityQueue
2518
+ * @static
2519
+ * @memberOf module:ControlFlow
2520
+ * @method
2521
+ * @see [async.queue]{@link module:ControlFlow.queue}
2522
+ * @category Control Flow
2523
+ * @param {AsyncFunction} worker - An async function for processing a queued task.
2524
+ * If you want to handle errors from an individual task, pass a callback to
2525
+ * `q.push()`.
2526
+ * Invoked with (task, callback).
2527
+ * @param {number} concurrency - An `integer` for determining how many `worker`
2528
+ * functions should be run in parallel. If omitted, the concurrency defaults to
2529
+ * `1`. If the concurrency is `0`, an error is thrown.
2530
+ * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are three
2531
+ * differences between `queue` and `priorityQueue` objects:
2532
+ * * `push(task, priority, [callback])` - `priority` should be a number. If an
2533
+ * array of `tasks` is given, all tasks will be assigned the same priority.
2534
+ * * `pushAsync(task, priority, [callback])` - the same as `priorityQueue.push`,
2535
+ * except this returns a promise that rejects if an error occurs.
2536
+ * * The `unshift` and `unshiftAsync` methods were removed.
2537
+ */function priorityQueue(worker,concurrency){// Start with a normal queue
2538
+ var q=queue$1(worker,concurrency);var{push,pushAsync}=q;q._tasks=new Heap();q._createTaskItem=({data,priority},callback)=>{return{data,priority,callback};};function createDataItems(tasks,priority){if(!Array.isArray(tasks)){return{data:tasks,priority};}return tasks.map(data=>{return{data,priority};});}// Override push to accept second parameter representing priority
2539
+ q.push=function(data,priority=0,callback){return push(createDataItems(data,priority),callback);};q.pushAsync=function(data,priority=0,callback){return pushAsync(createDataItems(data,priority),callback);};// Remove unshift functions
2540
+ delete q.unshift;delete q.unshiftAsync;return q;}/**
2541
+ * Runs the `tasks` array of functions in parallel, without waiting until the
2542
+ * previous function has completed. Once any of the `tasks` complete or pass an
2543
+ * error to its callback, the main `callback` is immediately called. It's
2544
+ * equivalent to `Promise.race()`.
2545
+ *
2546
+ * @name race
2547
+ * @static
2548
+ * @memberOf module:ControlFlow
2549
+ * @method
2550
+ * @category Control Flow
2551
+ * @param {Array} tasks - An array containing [async functions]{@link AsyncFunction}
2552
+ * to run. Each function can complete with an optional `result` value.
2553
+ * @param {Function} callback - A callback to run once any of the functions have
2554
+ * completed. This function gets an error or result from the first function that
2555
+ * completed. Invoked with (err, result).
2556
+ * @returns {Promise} a promise, if a callback is omitted
2557
+ * @example
2558
+ *
2559
+ * async.race([
2560
+ * function(callback) {
2561
+ * setTimeout(function() {
2562
+ * callback(null, 'one');
2563
+ * }, 200);
2564
+ * },
2565
+ * function(callback) {
2566
+ * setTimeout(function() {
2567
+ * callback(null, 'two');
2568
+ * }, 100);
2569
+ * }
2570
+ * ],
2571
+ * // main callback
2572
+ * function(err, result) {
2573
+ * // the result will be equal to 'two' as it finishes earlier
2574
+ * });
2575
+ */function race(tasks,callback){callback=once(callback);if(!Array.isArray(tasks))return callback(new TypeError('First argument to race must be an array of functions'));if(!tasks.length)return callback();for(var i=0,l=tasks.length;i<l;i++){wrapAsync(tasks[i])(callback);}}var race$1=awaitify(race,2);/**
2576
+ * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
2577
+ *
2578
+ * @name reduceRight
2579
+ * @static
2580
+ * @memberOf module:Collections
2581
+ * @method
2582
+ * @see [async.reduce]{@link module:Collections.reduce}
2583
+ * @alias foldr
2584
+ * @category Collection
2585
+ * @param {Array} array - A collection to iterate over.
2586
+ * @param {*} memo - The initial state of the reduction.
2587
+ * @param {AsyncFunction} iteratee - A function applied to each item in the
2588
+ * array to produce the next step in the reduction.
2589
+ * The `iteratee` should complete with the next state of the reduction.
2590
+ * If the iteratee completes with an error, the reduction is stopped and the
2591
+ * main `callback` is immediately called with the error.
2592
+ * Invoked with (memo, item, callback).
2593
+ * @param {Function} [callback] - A callback which is called after all the
2594
+ * `iteratee` functions have finished. Result is the reduced value. Invoked with
2595
+ * (err, result).
2596
+ * @returns {Promise} a promise, if no callback is passed
2597
+ */function reduceRight(array,memo,iteratee,callback){var reversed=[...array].reverse();return reduce$1(reversed,memo,iteratee,callback);}/**
2598
+ * Wraps the async function in another function that always completes with a
2599
+ * result object, even when it errors.
2600
+ *
2601
+ * The result object has either the property `error` or `value`.
2602
+ *
2603
+ * @name reflect
2604
+ * @static
2605
+ * @memberOf module:Utils
2606
+ * @method
2607
+ * @category Util
2608
+ * @param {AsyncFunction} fn - The async function you want to wrap
2609
+ * @returns {Function} - A function that always passes null to it's callback as
2610
+ * the error. The second argument to the callback will be an `object` with
2611
+ * either an `error` or a `value` property.
2612
+ * @example
2613
+ *
2614
+ * async.parallel([
2615
+ * async.reflect(function(callback) {
2616
+ * // do some stuff ...
2617
+ * callback(null, 'one');
2618
+ * }),
2619
+ * async.reflect(function(callback) {
2620
+ * // do some more stuff but error ...
2621
+ * callback('bad stuff happened');
2622
+ * }),
2623
+ * async.reflect(function(callback) {
2624
+ * // do some more stuff ...
2625
+ * callback(null, 'two');
2626
+ * })
2627
+ * ],
2628
+ * // optional callback
2629
+ * function(err, results) {
2630
+ * // values
2631
+ * // results[0].value = 'one'
2632
+ * // results[1].error = 'bad stuff happened'
2633
+ * // results[2].value = 'two'
2634
+ * });
2635
+ */function reflect(fn){var _fn=wrapAsync(fn);return initialParams(function reflectOn(args,reflectCallback){args.push((error,...cbArgs)=>{let retVal={};if(error){retVal.error=error;}if(cbArgs.length>0){var value=cbArgs;if(cbArgs.length<=1){[value]=cbArgs;}retVal.value=value;}reflectCallback(null,retVal);});return _fn.apply(this,args);});}/**
2636
+ * A helper function that wraps an array or an object of functions with `reflect`.
2637
+ *
2638
+ * @name reflectAll
2639
+ * @static
2640
+ * @memberOf module:Utils
2641
+ * @method
2642
+ * @see [async.reflect]{@link module:Utils.reflect}
2643
+ * @category Util
2644
+ * @param {Array|Object|Iterable} tasks - The collection of
2645
+ * [async functions]{@link AsyncFunction} to wrap in `async.reflect`.
2646
+ * @returns {Array} Returns an array of async functions, each wrapped in
2647
+ * `async.reflect`
2648
+ * @example
2649
+ *
2650
+ * let tasks = [
2651
+ * function(callback) {
2652
+ * setTimeout(function() {
2653
+ * callback(null, 'one');
2654
+ * }, 200);
2655
+ * },
2656
+ * function(callback) {
2657
+ * // do some more stuff but error ...
2658
+ * callback(new Error('bad stuff happened'));
2659
+ * },
2660
+ * function(callback) {
2661
+ * setTimeout(function() {
2662
+ * callback(null, 'two');
2663
+ * }, 100);
2664
+ * }
2665
+ * ];
2666
+ *
2667
+ * async.parallel(async.reflectAll(tasks),
2668
+ * // optional callback
2669
+ * function(err, results) {
2670
+ * // values
2671
+ * // results[0].value = 'one'
2672
+ * // results[1].error = Error('bad stuff happened')
2673
+ * // results[2].value = 'two'
2674
+ * });
2675
+ *
2676
+ * // an example using an object instead of an array
2677
+ * let tasks = {
2678
+ * one: function(callback) {
2679
+ * setTimeout(function() {
2680
+ * callback(null, 'one');
2681
+ * }, 200);
2682
+ * },
2683
+ * two: function(callback) {
2684
+ * callback('two');
2685
+ * },
2686
+ * three: function(callback) {
2687
+ * setTimeout(function() {
2688
+ * callback(null, 'three');
2689
+ * }, 100);
2690
+ * }
2691
+ * };
2692
+ *
2693
+ * async.parallel(async.reflectAll(tasks),
2694
+ * // optional callback
2695
+ * function(err, results) {
2696
+ * // values
2697
+ * // results.one.value = 'one'
2698
+ * // results.two.error = 'two'
2699
+ * // results.three.value = 'three'
2700
+ * });
2701
+ */function reflectAll(tasks){var results;if(Array.isArray(tasks)){results=tasks.map(reflect);}else{results={};Object.keys(tasks).forEach(key=>{results[key]=reflect.call(this,tasks[key]);});}return results;}function reject(eachfn,arr,_iteratee,callback){const iteratee=wrapAsync(_iteratee);return _filter(eachfn,arr,(value,cb)=>{iteratee(value,(err,v)=>{cb(err,!v);});},callback);}/**
2702
+ * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
2703
+ *
2704
+ * @name reject
2705
+ * @static
2706
+ * @memberOf module:Collections
2707
+ * @method
2708
+ * @see [async.filter]{@link module:Collections.filter}
2709
+ * @category Collection
2710
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
2711
+ * @param {Function} iteratee - An async truth test to apply to each item in
2712
+ * `coll`.
2713
+ * The should complete with a boolean value as its `result`.
2714
+ * Invoked with (item, callback).
2715
+ * @param {Function} [callback] - A callback which is called after all the
2716
+ * `iteratee` functions have finished. Invoked with (err, results).
2717
+ * @returns {Promise} a promise, if no callback is passed
2718
+ * @example
2719
+ *
2720
+ * // dir1 is a directory that contains file1.txt, file2.txt
2721
+ * // dir2 is a directory that contains file3.txt, file4.txt
2722
+ * // dir3 is a directory that contains file5.txt
2723
+ *
2724
+ * const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];
2725
+ *
2726
+ * // asynchronous function that checks if a file exists
2727
+ * function fileExists(file, callback) {
2728
+ * fs.access(file, fs.constants.F_OK, (err) => {
2729
+ * callback(null, !err);
2730
+ * });
2731
+ * }
2732
+ *
2733
+ * // Using callbacks
2734
+ * async.reject(fileList, fileExists, function(err, results) {
2735
+ * // [ 'dir3/file6.txt' ]
2736
+ * // results now equals an array of the non-existing files
2737
+ * });
2738
+ *
2739
+ * // Using Promises
2740
+ * async.reject(fileList, fileExists)
2741
+ * .then( results => {
2742
+ * console.log(results);
2743
+ * // [ 'dir3/file6.txt' ]
2744
+ * // results now equals an array of the non-existing files
2745
+ * }).catch( err => {
2746
+ * console.log(err);
2747
+ * });
2748
+ *
2749
+ * // Using async/await
2750
+ * async () => {
2751
+ * try {
2752
+ * let results = await async.reject(fileList, fileExists);
2753
+ * console.log(results);
2754
+ * // [ 'dir3/file6.txt' ]
2755
+ * // results now equals an array of the non-existing files
2756
+ * }
2757
+ * catch (err) {
2758
+ * console.log(err);
2759
+ * }
2760
+ * }
2761
+ *
2762
+ */function reject$1(coll,iteratee,callback){return reject(eachOf$1,coll,iteratee,callback);}var reject$2=awaitify(reject$1,3);/**
2763
+ * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
2764
+ * time.
2765
+ *
2766
+ * @name rejectLimit
2767
+ * @static
2768
+ * @memberOf module:Collections
2769
+ * @method
2770
+ * @see [async.reject]{@link module:Collections.reject}
2771
+ * @category Collection
2772
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
2773
+ * @param {number} limit - The maximum number of async operations at a time.
2774
+ * @param {Function} iteratee - An async truth test to apply to each item in
2775
+ * `coll`.
2776
+ * The should complete with a boolean value as its `result`.
2777
+ * Invoked with (item, callback).
2778
+ * @param {Function} [callback] - A callback which is called after all the
2779
+ * `iteratee` functions have finished. Invoked with (err, results).
2780
+ * @returns {Promise} a promise, if no callback is passed
2781
+ */function rejectLimit(coll,limit,iteratee,callback){return reject(eachOfLimit(limit),coll,iteratee,callback);}var rejectLimit$1=awaitify(rejectLimit,4);/**
2782
+ * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time.
2783
+ *
2784
+ * @name rejectSeries
2785
+ * @static
2786
+ * @memberOf module:Collections
2787
+ * @method
2788
+ * @see [async.reject]{@link module:Collections.reject}
2789
+ * @category Collection
2790
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
2791
+ * @param {Function} iteratee - An async truth test to apply to each item in
2792
+ * `coll`.
2793
+ * The should complete with a boolean value as its `result`.
2794
+ * Invoked with (item, callback).
2795
+ * @param {Function} [callback] - A callback which is called after all the
2796
+ * `iteratee` functions have finished. Invoked with (err, results).
2797
+ * @returns {Promise} a promise, if no callback is passed
2798
+ */function rejectSeries(coll,iteratee,callback){return reject(eachOfSeries$1,coll,iteratee,callback);}var rejectSeries$1=awaitify(rejectSeries,3);function constant$1(value){return function(){return value;};}/**
2799
+ * Attempts to get a successful response from `task` no more than `times` times
2800
+ * before returning an error. If the task is successful, the `callback` will be
2801
+ * passed the result of the successful task. If all attempts fail, the callback
2802
+ * will be passed the error and result (if any) of the final attempt.
2803
+ *
2804
+ * @name retry
2805
+ * @static
2806
+ * @memberOf module:ControlFlow
2807
+ * @method
2808
+ * @category Control Flow
2809
+ * @see [async.retryable]{@link module:ControlFlow.retryable}
2810
+ * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
2811
+ * object with `times` and `interval` or a number.
2812
+ * * `times` - The number of attempts to make before giving up. The default
2813
+ * is `5`.
2814
+ * * `interval` - The time to wait between retries, in milliseconds. The
2815
+ * default is `0`. The interval may also be specified as a function of the
2816
+ * retry count (see example).
2817
+ * * `errorFilter` - An optional synchronous function that is invoked on
2818
+ * erroneous result. If it returns `true` the retry attempts will continue;
2819
+ * if the function returns `false` the retry flow is aborted with the current
2820
+ * attempt's error and result being returned to the final callback.
2821
+ * Invoked with (err).
2822
+ * * If `opts` is a number, the number specifies the number of times to retry,
2823
+ * with the default interval of `0`.
2824
+ * @param {AsyncFunction} task - An async function to retry.
2825
+ * Invoked with (callback).
2826
+ * @param {Function} [callback] - An optional callback which is called when the
2827
+ * task has succeeded, or after the final failed attempt. It receives the `err`
2828
+ * and `result` arguments of the last attempt at completing the `task`. Invoked
2829
+ * with (err, results).
2830
+ * @returns {Promise} a promise if no callback provided
2831
+ *
2832
+ * @example
2833
+ *
2834
+ * // The `retry` function can be used as a stand-alone control flow by passing
2835
+ * // a callback, as shown below:
2836
+ *
2837
+ * // try calling apiMethod 3 times
2838
+ * async.retry(3, apiMethod, function(err, result) {
2839
+ * // do something with the result
2840
+ * });
2841
+ *
2842
+ * // try calling apiMethod 3 times, waiting 200 ms between each retry
2843
+ * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
2844
+ * // do something with the result
2845
+ * });
2846
+ *
2847
+ * // try calling apiMethod 10 times with exponential backoff
2848
+ * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
2849
+ * async.retry({
2850
+ * times: 10,
2851
+ * interval: function(retryCount) {
2852
+ * return 50 * Math.pow(2, retryCount);
2853
+ * }
2854
+ * }, apiMethod, function(err, result) {
2855
+ * // do something with the result
2856
+ * });
2857
+ *
2858
+ * // try calling apiMethod the default 5 times no delay between each retry
2859
+ * async.retry(apiMethod, function(err, result) {
2860
+ * // do something with the result
2861
+ * });
2862
+ *
2863
+ * // try calling apiMethod only when error condition satisfies, all other
2864
+ * // errors will abort the retry control flow and return to final callback
2865
+ * async.retry({
2866
+ * errorFilter: function(err) {
2867
+ * return err.message === 'Temporary error'; // only retry on a specific error
2868
+ * }
2869
+ * }, apiMethod, function(err, result) {
2870
+ * // do something with the result
2871
+ * });
2872
+ *
2873
+ * // to retry individual methods that are not as reliable within other
2874
+ * // control flow functions, use the `retryable` wrapper:
2875
+ * async.auto({
2876
+ * users: api.getUsers.bind(api),
2877
+ * payments: async.retryable(3, api.getPayments.bind(api))
2878
+ * }, function(err, results) {
2879
+ * // do something with the results
2880
+ * });
2881
+ *
2882
+ */const DEFAULT_TIMES=5;const DEFAULT_INTERVAL=0;function retry(opts,task,callback){var options={times:DEFAULT_TIMES,intervalFunc:constant$1(DEFAULT_INTERVAL)};if(arguments.length<3&&typeof opts==='function'){callback=task||promiseCallback();task=opts;}else{parseTimes(options,opts);callback=callback||promiseCallback();}if(typeof task!=='function'){throw new Error("Invalid arguments for async.retry");}var _task=wrapAsync(task);var attempt=1;function retryAttempt(){_task((err,...args)=>{if(err===false)return;if(err&&attempt++<options.times&&(typeof options.errorFilter!='function'||options.errorFilter(err))){setTimeout(retryAttempt,options.intervalFunc(attempt-1));}else{callback(err,...args);}});}retryAttempt();return callback[PROMISE_SYMBOL];}function parseTimes(acc,t){if(typeof t==='object'){acc.times=+t.times||DEFAULT_TIMES;acc.intervalFunc=typeof t.interval==='function'?t.interval:constant$1(+t.interval||DEFAULT_INTERVAL);acc.errorFilter=t.errorFilter;}else if(typeof t==='number'||typeof t==='string'){acc.times=+t||DEFAULT_TIMES;}else{throw new Error("Invalid arguments for async.retry");}}/**
2883
+ * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method
2884
+ * wraps a task and makes it retryable, rather than immediately calling it
2885
+ * with retries.
2886
+ *
2887
+ * @name retryable
2888
+ * @static
2889
+ * @memberOf module:ControlFlow
2890
+ * @method
2891
+ * @see [async.retry]{@link module:ControlFlow.retry}
2892
+ * @category Control Flow
2893
+ * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
2894
+ * options, exactly the same as from `retry`, except for a `opts.arity` that
2895
+ * is the arity of the `task` function, defaulting to `task.length`
2896
+ * @param {AsyncFunction} task - the asynchronous function to wrap.
2897
+ * This function will be passed any arguments passed to the returned wrapper.
2898
+ * Invoked with (...args, callback).
2899
+ * @returns {AsyncFunction} The wrapped function, which when invoked, will
2900
+ * retry on an error, based on the parameters specified in `opts`.
2901
+ * This function will accept the same parameters as `task`.
2902
+ * @example
2903
+ *
2904
+ * async.auto({
2905
+ * dep1: async.retryable(3, getFromFlakyService),
2906
+ * process: ["dep1", async.retryable(3, function (results, cb) {
2907
+ * maybeProcessData(results.dep1, cb);
2908
+ * })]
2909
+ * }, callback);
2910
+ */function retryable(opts,task){if(!task){task=opts;opts=null;}let arity=opts&&opts.arity||task.length;if(isAsync(task)){arity+=1;}var _task=wrapAsync(task);return initialParams((args,callback)=>{if(args.length<arity-1||callback==null){args.push(callback);callback=promiseCallback();}function taskFn(cb){_task(...args,cb);}if(opts)retry(opts,taskFn,callback);else retry(taskFn,callback);return callback[PROMISE_SYMBOL];});}/**
2911
+ * Run the functions in the `tasks` collection in series, each one running once
2912
+ * the previous function has completed. If any functions in the series pass an
2913
+ * error to its callback, no more functions are run, and `callback` is
2914
+ * immediately called with the value of the error. Otherwise, `callback`
2915
+ * receives an array of results when `tasks` have completed.
2916
+ *
2917
+ * It is also possible to use an object instead of an array. Each property will
2918
+ * be run as a function, and the results will be passed to the final `callback`
2919
+ * as an object instead of an array. This can be a more readable way of handling
2920
+ * results from {@link async.series}.
2921
+ *
2922
+ * **Note** that while many implementations preserve the order of object
2923
+ * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
2924
+ * explicitly states that
2925
+ *
2926
+ * > The mechanics and order of enumerating the properties is not specified.
2927
+ *
2928
+ * So if you rely on the order in which your series of functions are executed,
2929
+ * and want this to work on all platforms, consider using an array.
2930
+ *
2931
+ * @name series
2932
+ * @static
2933
+ * @memberOf module:ControlFlow
2934
+ * @method
2935
+ * @category Control Flow
2936
+ * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection containing
2937
+ * [async functions]{@link AsyncFunction} to run in series.
2938
+ * Each function can complete with any number of optional `result` values.
2939
+ * @param {Function} [callback] - An optional callback to run once all the
2940
+ * functions have completed. This function gets a results array (or object)
2941
+ * containing all the result arguments passed to the `task` callbacks. Invoked
2942
+ * with (err, result).
2943
+ * @return {Promise} a promise, if no callback is passed
2944
+ * @example
2945
+ *
2946
+ * //Using Callbacks
2947
+ * async.series([
2948
+ * function(callback) {
2949
+ * setTimeout(function() {
2950
+ * // do some async task
2951
+ * callback(null, 'one');
2952
+ * }, 200);
2953
+ * },
2954
+ * function(callback) {
2955
+ * setTimeout(function() {
2956
+ * // then do another async task
2957
+ * callback(null, 'two');
2958
+ * }, 100);
2959
+ * }
2960
+ * ], function(err, results) {
2961
+ * console.log(results);
2962
+ * // results is equal to ['one','two']
2963
+ * });
2964
+ *
2965
+ * // an example using objects instead of arrays
2966
+ * async.series({
2967
+ * one: function(callback) {
2968
+ * setTimeout(function() {
2969
+ * // do some async task
2970
+ * callback(null, 1);
2971
+ * }, 200);
2972
+ * },
2973
+ * two: function(callback) {
2974
+ * setTimeout(function() {
2975
+ * // then do another async task
2976
+ * callback(null, 2);
2977
+ * }, 100);
2978
+ * }
2979
+ * }, function(err, results) {
2980
+ * console.log(results);
2981
+ * // results is equal to: { one: 1, two: 2 }
2982
+ * });
2983
+ *
2984
+ * //Using Promises
2985
+ * async.series([
2986
+ * function(callback) {
2987
+ * setTimeout(function() {
2988
+ * callback(null, 'one');
2989
+ * }, 200);
2990
+ * },
2991
+ * function(callback) {
2992
+ * setTimeout(function() {
2993
+ * callback(null, 'two');
2994
+ * }, 100);
2995
+ * }
2996
+ * ]).then(results => {
2997
+ * console.log(results);
2998
+ * // results is equal to ['one','two']
2999
+ * }).catch(err => {
3000
+ * console.log(err);
3001
+ * });
3002
+ *
3003
+ * // an example using an object instead of an array
3004
+ * async.series({
3005
+ * one: function(callback) {
3006
+ * setTimeout(function() {
3007
+ * // do some async task
3008
+ * callback(null, 1);
3009
+ * }, 200);
3010
+ * },
3011
+ * two: function(callback) {
3012
+ * setTimeout(function() {
3013
+ * // then do another async task
3014
+ * callback(null, 2);
3015
+ * }, 100);
3016
+ * }
3017
+ * }).then(results => {
3018
+ * console.log(results);
3019
+ * // results is equal to: { one: 1, two: 2 }
3020
+ * }).catch(err => {
3021
+ * console.log(err);
3022
+ * });
3023
+ *
3024
+ * //Using async/await
3025
+ * async () => {
3026
+ * try {
3027
+ * let results = await async.series([
3028
+ * function(callback) {
3029
+ * setTimeout(function() {
3030
+ * // do some async task
3031
+ * callback(null, 'one');
3032
+ * }, 200);
3033
+ * },
3034
+ * function(callback) {
3035
+ * setTimeout(function() {
3036
+ * // then do another async task
3037
+ * callback(null, 'two');
3038
+ * }, 100);
3039
+ * }
3040
+ * ]);
3041
+ * console.log(results);
3042
+ * // results is equal to ['one','two']
3043
+ * }
3044
+ * catch (err) {
3045
+ * console.log(err);
3046
+ * }
3047
+ * }
3048
+ *
3049
+ * // an example using an object instead of an array
3050
+ * async () => {
3051
+ * try {
3052
+ * let results = await async.parallel({
3053
+ * one: function(callback) {
3054
+ * setTimeout(function() {
3055
+ * // do some async task
3056
+ * callback(null, 1);
3057
+ * }, 200);
3058
+ * },
3059
+ * two: function(callback) {
3060
+ * setTimeout(function() {
3061
+ * // then do another async task
3062
+ * callback(null, 2);
3063
+ * }, 100);
3064
+ * }
3065
+ * });
3066
+ * console.log(results);
3067
+ * // results is equal to: { one: 1, two: 2 }
3068
+ * }
3069
+ * catch (err) {
3070
+ * console.log(err);
3071
+ * }
3072
+ * }
3073
+ *
3074
+ */function series(tasks,callback){return parallel(eachOfSeries$1,tasks,callback);}/**
3075
+ * Returns `true` if at least one element in the `coll` satisfies an async test.
3076
+ * If any iteratee call returns `true`, the main `callback` is immediately
3077
+ * called.
3078
+ *
3079
+ * @name some
3080
+ * @static
3081
+ * @memberOf module:Collections
3082
+ * @method
3083
+ * @alias any
3084
+ * @category Collection
3085
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
3086
+ * @param {AsyncFunction} iteratee - An async truth test to apply to each item
3087
+ * in the collections in parallel.
3088
+ * The iteratee should complete with a boolean `result` value.
3089
+ * Invoked with (item, callback).
3090
+ * @param {Function} [callback] - A callback which is called as soon as any
3091
+ * iteratee returns `true`, or after all the iteratee functions have finished.
3092
+ * Result will be either `true` or `false` depending on the values of the async
3093
+ * tests. Invoked with (err, result).
3094
+ * @returns {Promise} a promise, if no callback provided
3095
+ * @example
3096
+ *
3097
+ * // dir1 is a directory that contains file1.txt, file2.txt
3098
+ * // dir2 is a directory that contains file3.txt, file4.txt
3099
+ * // dir3 is a directory that contains file5.txt
3100
+ * // dir4 does not exist
3101
+ *
3102
+ * // asynchronous function that checks if a file exists
3103
+ * function fileExists(file, callback) {
3104
+ * fs.access(file, fs.constants.F_OK, (err) => {
3105
+ * callback(null, !err);
3106
+ * });
3107
+ * }
3108
+ *
3109
+ * // Using callbacks
3110
+ * async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists,
3111
+ * function(err, result) {
3112
+ * console.log(result);
3113
+ * // true
3114
+ * // result is true since some file in the list exists
3115
+ * }
3116
+ *);
3117
+ *
3118
+ * async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists,
3119
+ * function(err, result) {
3120
+ * console.log(result);
3121
+ * // false
3122
+ * // result is false since none of the files exists
3123
+ * }
3124
+ *);
3125
+ *
3126
+ * // Using Promises
3127
+ * async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists)
3128
+ * .then( result => {
3129
+ * console.log(result);
3130
+ * // true
3131
+ * // result is true since some file in the list exists
3132
+ * }).catch( err => {
3133
+ * console.log(err);
3134
+ * });
3135
+ *
3136
+ * async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists)
3137
+ * .then( result => {
3138
+ * console.log(result);
3139
+ * // false
3140
+ * // result is false since none of the files exists
3141
+ * }).catch( err => {
3142
+ * console.log(err);
3143
+ * });
3144
+ *
3145
+ * // Using async/await
3146
+ * async () => {
3147
+ * try {
3148
+ * let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists);
3149
+ * console.log(result);
3150
+ * // true
3151
+ * // result is true since some file in the list exists
3152
+ * }
3153
+ * catch (err) {
3154
+ * console.log(err);
3155
+ * }
3156
+ * }
3157
+ *
3158
+ * async () => {
3159
+ * try {
3160
+ * let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists);
3161
+ * console.log(result);
3162
+ * // false
3163
+ * // result is false since none of the files exists
3164
+ * }
3165
+ * catch (err) {
3166
+ * console.log(err);
3167
+ * }
3168
+ * }
3169
+ *
3170
+ */function some(coll,iteratee,callback){return _createTester(Boolean,res=>res)(eachOf$1,coll,iteratee,callback);}var some$1=awaitify(some,3);/**
3171
+ * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
3172
+ *
3173
+ * @name someLimit
3174
+ * @static
3175
+ * @memberOf module:Collections
3176
+ * @method
3177
+ * @see [async.some]{@link module:Collections.some}
3178
+ * @alias anyLimit
3179
+ * @category Collection
3180
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
3181
+ * @param {number} limit - The maximum number of async operations at a time.
3182
+ * @param {AsyncFunction} iteratee - An async truth test to apply to each item
3183
+ * in the collections in parallel.
3184
+ * The iteratee should complete with a boolean `result` value.
3185
+ * Invoked with (item, callback).
3186
+ * @param {Function} [callback] - A callback which is called as soon as any
3187
+ * iteratee returns `true`, or after all the iteratee functions have finished.
3188
+ * Result will be either `true` or `false` depending on the values of the async
3189
+ * tests. Invoked with (err, result).
3190
+ * @returns {Promise} a promise, if no callback provided
3191
+ */function someLimit(coll,limit,iteratee,callback){return _createTester(Boolean,res=>res)(eachOfLimit(limit),coll,iteratee,callback);}var someLimit$1=awaitify(someLimit,4);/**
3192
+ * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
3193
+ *
3194
+ * @name someSeries
3195
+ * @static
3196
+ * @memberOf module:Collections
3197
+ * @method
3198
+ * @see [async.some]{@link module:Collections.some}
3199
+ * @alias anySeries
3200
+ * @category Collection
3201
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
3202
+ * @param {AsyncFunction} iteratee - An async truth test to apply to each item
3203
+ * in the collections in series.
3204
+ * The iteratee should complete with a boolean `result` value.
3205
+ * Invoked with (item, callback).
3206
+ * @param {Function} [callback] - A callback which is called as soon as any
3207
+ * iteratee returns `true`, or after all the iteratee functions have finished.
3208
+ * Result will be either `true` or `false` depending on the values of the async
3209
+ * tests. Invoked with (err, result).
3210
+ * @returns {Promise} a promise, if no callback provided
3211
+ */function someSeries(coll,iteratee,callback){return _createTester(Boolean,res=>res)(eachOfSeries$1,coll,iteratee,callback);}var someSeries$1=awaitify(someSeries,3);/**
3212
+ * Sorts a list by the results of running each `coll` value through an async
3213
+ * `iteratee`.
3214
+ *
3215
+ * @name sortBy
3216
+ * @static
3217
+ * @memberOf module:Collections
3218
+ * @method
3219
+ * @category Collection
3220
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
3221
+ * @param {AsyncFunction} iteratee - An async function to apply to each item in
3222
+ * `coll`.
3223
+ * The iteratee should complete with a value to use as the sort criteria as
3224
+ * its `result`.
3225
+ * Invoked with (item, callback).
3226
+ * @param {Function} callback - A callback which is called after all the
3227
+ * `iteratee` functions have finished, or an error occurs. Results is the items
3228
+ * from the original `coll` sorted by the values returned by the `iteratee`
3229
+ * calls. Invoked with (err, results).
3230
+ * @returns {Promise} a promise, if no callback passed
3231
+ * @example
3232
+ *
3233
+ * // bigfile.txt is a file that is 251100 bytes in size
3234
+ * // mediumfile.txt is a file that is 11000 bytes in size
3235
+ * // smallfile.txt is a file that is 121 bytes in size
3236
+ *
3237
+ * // asynchronous function that returns the file size in bytes
3238
+ * function getFileSizeInBytes(file, callback) {
3239
+ * fs.stat(file, function(err, stat) {
3240
+ * if (err) {
3241
+ * return callback(err);
3242
+ * }
3243
+ * callback(null, stat.size);
3244
+ * });
3245
+ * }
3246
+ *
3247
+ * // Using callbacks
3248
+ * async.sortBy(['mediumfile.txt','smallfile.txt','bigfile.txt'], getFileSizeInBytes,
3249
+ * function(err, results) {
3250
+ * if (err) {
3251
+ * console.log(err);
3252
+ * } else {
3253
+ * console.log(results);
3254
+ * // results is now the original array of files sorted by
3255
+ * // file size (ascending by default), e.g.
3256
+ * // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
3257
+ * }
3258
+ * }
3259
+ * );
3260
+ *
3261
+ * // By modifying the callback parameter the
3262
+ * // sorting order can be influenced:
3263
+ *
3264
+ * // ascending order
3265
+ * async.sortBy(['mediumfile.txt','smallfile.txt','bigfile.txt'], function(file, callback) {
3266
+ * getFileSizeInBytes(file, function(getFileSizeErr, fileSize) {
3267
+ * if (getFileSizeErr) return callback(getFileSizeErr);
3268
+ * callback(null, fileSize);
3269
+ * });
3270
+ * }, function(err, results) {
3271
+ * if (err) {
3272
+ * console.log(err);
3273
+ * } else {
3274
+ * console.log(results);
3275
+ * // results is now the original array of files sorted by
3276
+ * // file size (ascending by default), e.g.
3277
+ * // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
3278
+ * }
3279
+ * }
3280
+ * );
3281
+ *
3282
+ * // descending order
3283
+ * async.sortBy(['bigfile.txt','mediumfile.txt','smallfile.txt'], function(file, callback) {
3284
+ * getFileSizeInBytes(file, function(getFileSizeErr, fileSize) {
3285
+ * if (getFileSizeErr) {
3286
+ * return callback(getFileSizeErr);
3287
+ * }
3288
+ * callback(null, fileSize * -1);
3289
+ * });
3290
+ * }, function(err, results) {
3291
+ * if (err) {
3292
+ * console.log(err);
3293
+ * } else {
3294
+ * console.log(results);
3295
+ * // results is now the original array of files sorted by
3296
+ * // file size (ascending by default), e.g.
3297
+ * // [ 'bigfile.txt', 'mediumfile.txt', 'smallfile.txt']
3298
+ * }
3299
+ * }
3300
+ * );
3301
+ *
3302
+ * // Error handling
3303
+ * async.sortBy(['mediumfile.txt','smallfile.txt','missingfile.txt'], getFileSizeInBytes,
3304
+ * function(err, results) {
3305
+ * if (err) {
3306
+ * console.log(err);
3307
+ * // [ Error: ENOENT: no such file or directory ]
3308
+ * } else {
3309
+ * console.log(results);
3310
+ * }
3311
+ * }
3312
+ * );
3313
+ *
3314
+ * // Using Promises
3315
+ * async.sortBy(['mediumfile.txt','smallfile.txt','bigfile.txt'], getFileSizeInBytes)
3316
+ * .then( results => {
3317
+ * console.log(results);
3318
+ * // results is now the original array of files sorted by
3319
+ * // file size (ascending by default), e.g.
3320
+ * // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
3321
+ * }).catch( err => {
3322
+ * console.log(err);
3323
+ * });
3324
+ *
3325
+ * // Error handling
3326
+ * async.sortBy(['mediumfile.txt','smallfile.txt','missingfile.txt'], getFileSizeInBytes)
3327
+ * .then( results => {
3328
+ * console.log(results);
3329
+ * }).catch( err => {
3330
+ * console.log(err);
3331
+ * // [ Error: ENOENT: no such file or directory ]
3332
+ * });
3333
+ *
3334
+ * // Using async/await
3335
+ * (async () => {
3336
+ * try {
3337
+ * let results = await async.sortBy(['bigfile.txt','mediumfile.txt','smallfile.txt'], getFileSizeInBytes);
3338
+ * console.log(results);
3339
+ * // results is now the original array of files sorted by
3340
+ * // file size (ascending by default), e.g.
3341
+ * // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
3342
+ * }
3343
+ * catch (err) {
3344
+ * console.log(err);
3345
+ * }
3346
+ * })();
3347
+ *
3348
+ * // Error handling
3349
+ * async () => {
3350
+ * try {
3351
+ * let results = await async.sortBy(['missingfile.txt','mediumfile.txt','smallfile.txt'], getFileSizeInBytes);
3352
+ * console.log(results);
3353
+ * }
3354
+ * catch (err) {
3355
+ * console.log(err);
3356
+ * // [ Error: ENOENT: no such file or directory ]
3357
+ * }
3358
+ * }
3359
+ *
3360
+ */function sortBy(coll,iteratee,callback){var _iteratee=wrapAsync(iteratee);return map$1(coll,(x,iterCb)=>{_iteratee(x,(err,criteria)=>{if(err)return iterCb(err);iterCb(err,{value:x,criteria});});},(err,results)=>{if(err)return callback(err);callback(null,results.sort(comparator).map(v=>v.value));});function comparator(left,right){var a=left.criteria,b=right.criteria;return a<b?-1:a>b?1:0;}}var sortBy$1=awaitify(sortBy,3);/**
3361
+ * Sets a time limit on an asynchronous function. If the function does not call
3362
+ * its callback within the specified milliseconds, it will be called with a
3363
+ * timeout error. The code property for the error object will be `'ETIMEDOUT'`.
3364
+ *
3365
+ * @name timeout
3366
+ * @static
3367
+ * @memberOf module:Utils
3368
+ * @method
3369
+ * @category Util
3370
+ * @param {AsyncFunction} asyncFn - The async function to limit in time.
3371
+ * @param {number} milliseconds - The specified time limit.
3372
+ * @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
3373
+ * to timeout Error for more information..
3374
+ * @returns {AsyncFunction} Returns a wrapped function that can be used with any
3375
+ * of the control flow functions.
3376
+ * Invoke this function with the same parameters as you would `asyncFunc`.
3377
+ * @example
3378
+ *
3379
+ * function myFunction(foo, callback) {
3380
+ * doAsyncTask(foo, function(err, data) {
3381
+ * // handle errors
3382
+ * if (err) return callback(err);
3383
+ *
3384
+ * // do some stuff ...
3385
+ *
3386
+ * // return processed data
3387
+ * return callback(null, data);
3388
+ * });
3389
+ * }
3390
+ *
3391
+ * var wrapped = async.timeout(myFunction, 1000);
3392
+ *
3393
+ * // call `wrapped` as you would `myFunction`
3394
+ * wrapped({ bar: 'bar' }, function(err, data) {
3395
+ * // if `myFunction` takes < 1000 ms to execute, `err`
3396
+ * // and `data` will have their expected values
3397
+ *
3398
+ * // else `err` will be an Error with the code 'ETIMEDOUT'
3399
+ * });
3400
+ */function timeout(asyncFn,milliseconds,info){var fn=wrapAsync(asyncFn);return initialParams((args,callback)=>{var timedOut=false;var timer;function timeoutCallback(){var name=asyncFn.name||'anonymous';var error=new Error('Callback function "'+name+'" timed out.');error.code='ETIMEDOUT';if(info){error.info=info;}timedOut=true;callback(error);}args.push((...cbArgs)=>{if(!timedOut){callback(...cbArgs);clearTimeout(timer);}});// setup timer and call original function
3401
+ timer=setTimeout(timeoutCallback,milliseconds);fn(...args);});}function range(size){var result=Array(size);while(size--){result[size]=size;}return result;}/**
3402
+ * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
3403
+ * time.
3404
+ *
3405
+ * @name timesLimit
3406
+ * @static
3407
+ * @memberOf module:ControlFlow
3408
+ * @method
3409
+ * @see [async.times]{@link module:ControlFlow.times}
3410
+ * @category Control Flow
3411
+ * @param {number} count - The number of times to run the function.
3412
+ * @param {number} limit - The maximum number of async operations at a time.
3413
+ * @param {AsyncFunction} iteratee - The async function to call `n` times.
3414
+ * Invoked with the iteration index and a callback: (n, next).
3415
+ * @param {Function} callback - see [async.map]{@link module:Collections.map}.
3416
+ * @returns {Promise} a promise, if no callback is provided
3417
+ */function timesLimit(count,limit,iteratee,callback){var _iteratee=wrapAsync(iteratee);return mapLimit$1(range(count),limit,_iteratee,callback);}/**
3418
+ * Calls the `iteratee` function `n` times, and accumulates results in the same
3419
+ * manner you would use with [map]{@link module:Collections.map}.
3420
+ *
3421
+ * @name times
3422
+ * @static
3423
+ * @memberOf module:ControlFlow
3424
+ * @method
3425
+ * @see [async.map]{@link module:Collections.map}
3426
+ * @category Control Flow
3427
+ * @param {number} n - The number of times to run the function.
3428
+ * @param {AsyncFunction} iteratee - The async function to call `n` times.
3429
+ * Invoked with the iteration index and a callback: (n, next).
3430
+ * @param {Function} callback - see {@link module:Collections.map}.
3431
+ * @returns {Promise} a promise, if no callback is provided
3432
+ * @example
3433
+ *
3434
+ * // Pretend this is some complicated async factory
3435
+ * var createUser = function(id, callback) {
3436
+ * callback(null, {
3437
+ * id: 'user' + id
3438
+ * });
3439
+ * };
3440
+ *
3441
+ * // generate 5 users
3442
+ * async.times(5, function(n, next) {
3443
+ * createUser(n, function(err, user) {
3444
+ * next(err, user);
3445
+ * });
3446
+ * }, function(err, users) {
3447
+ * // we should now have 5 users
3448
+ * });
3449
+ */function times(n,iteratee,callback){return timesLimit(n,Infinity,iteratee,callback);}/**
3450
+ * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time.
3451
+ *
3452
+ * @name timesSeries
3453
+ * @static
3454
+ * @memberOf module:ControlFlow
3455
+ * @method
3456
+ * @see [async.times]{@link module:ControlFlow.times}
3457
+ * @category Control Flow
3458
+ * @param {number} n - The number of times to run the function.
3459
+ * @param {AsyncFunction} iteratee - The async function to call `n` times.
3460
+ * Invoked with the iteration index and a callback: (n, next).
3461
+ * @param {Function} callback - see {@link module:Collections.map}.
3462
+ * @returns {Promise} a promise, if no callback is provided
3463
+ */function timesSeries(n,iteratee,callback){return timesLimit(n,1,iteratee,callback);}/**
3464
+ * A relative of `reduce`. Takes an Object or Array, and iterates over each
3465
+ * element in parallel, each step potentially mutating an `accumulator` value.
3466
+ * The type of the accumulator defaults to the type of collection passed in.
3467
+ *
3468
+ * @name transform
3469
+ * @static
3470
+ * @memberOf module:Collections
3471
+ * @method
3472
+ * @category Collection
3473
+ * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
3474
+ * @param {*} [accumulator] - The initial state of the transform. If omitted,
3475
+ * it will default to an empty Object or Array, depending on the type of `coll`
3476
+ * @param {AsyncFunction} iteratee - A function applied to each item in the
3477
+ * collection that potentially modifies the accumulator.
3478
+ * Invoked with (accumulator, item, key, callback).
3479
+ * @param {Function} [callback] - A callback which is called after all the
3480
+ * `iteratee` functions have finished. Result is the transformed accumulator.
3481
+ * Invoked with (err, result).
3482
+ * @returns {Promise} a promise, if no callback provided
3483
+ * @example
3484
+ *
3485
+ * // file1.txt is a file that is 1000 bytes in size
3486
+ * // file2.txt is a file that is 2000 bytes in size
3487
+ * // file3.txt is a file that is 3000 bytes in size
3488
+ *
3489
+ * // helper function that returns human-readable size format from bytes
3490
+ * function formatBytes(bytes, decimals = 2) {
3491
+ * // implementation not included for brevity
3492
+ * return humanReadbleFilesize;
3493
+ * }
3494
+ *
3495
+ * const fileList = ['file1.txt','file2.txt','file3.txt'];
3496
+ *
3497
+ * // asynchronous function that returns the file size, transformed to human-readable format
3498
+ * // e.g. 1024 bytes = 1KB, 1234 bytes = 1.21 KB, 1048576 bytes = 1MB, etc.
3499
+ * function transformFileSize(acc, value, key, callback) {
3500
+ * fs.stat(value, function(err, stat) {
3501
+ * if (err) {
3502
+ * return callback(err);
3503
+ * }
3504
+ * acc[key] = formatBytes(stat.size);
3505
+ * callback(null);
3506
+ * });
3507
+ * }
3508
+ *
3509
+ * // Using callbacks
3510
+ * async.transform(fileList, transformFileSize, function(err, result) {
3511
+ * if(err) {
3512
+ * console.log(err);
3513
+ * } else {
3514
+ * console.log(result);
3515
+ * // [ '1000 Bytes', '1.95 KB', '2.93 KB' ]
3516
+ * }
3517
+ * });
3518
+ *
3519
+ * // Using Promises
3520
+ * async.transform(fileList, transformFileSize)
3521
+ * .then(result => {
3522
+ * console.log(result);
3523
+ * // [ '1000 Bytes', '1.95 KB', '2.93 KB' ]
3524
+ * }).catch(err => {
3525
+ * console.log(err);
3526
+ * });
3527
+ *
3528
+ * // Using async/await
3529
+ * (async () => {
3530
+ * try {
3531
+ * let result = await async.transform(fileList, transformFileSize);
3532
+ * console.log(result);
3533
+ * // [ '1000 Bytes', '1.95 KB', '2.93 KB' ]
3534
+ * }
3535
+ * catch (err) {
3536
+ * console.log(err);
3537
+ * }
3538
+ * })();
3539
+ *
3540
+ * @example
3541
+ *
3542
+ * // file1.txt is a file that is 1000 bytes in size
3543
+ * // file2.txt is a file that is 2000 bytes in size
3544
+ * // file3.txt is a file that is 3000 bytes in size
3545
+ *
3546
+ * // helper function that returns human-readable size format from bytes
3547
+ * function formatBytes(bytes, decimals = 2) {
3548
+ * // implementation not included for brevity
3549
+ * return humanReadbleFilesize;
3550
+ * }
3551
+ *
3552
+ * const fileMap = { f1: 'file1.txt', f2: 'file2.txt', f3: 'file3.txt' };
3553
+ *
3554
+ * // asynchronous function that returns the file size, transformed to human-readable format
3555
+ * // e.g. 1024 bytes = 1KB, 1234 bytes = 1.21 KB, 1048576 bytes = 1MB, etc.
3556
+ * function transformFileSize(acc, value, key, callback) {
3557
+ * fs.stat(value, function(err, stat) {
3558
+ * if (err) {
3559
+ * return callback(err);
3560
+ * }
3561
+ * acc[key] = formatBytes(stat.size);
3562
+ * callback(null);
3563
+ * });
3564
+ * }
3565
+ *
3566
+ * // Using callbacks
3567
+ * async.transform(fileMap, transformFileSize, function(err, result) {
3568
+ * if(err) {
3569
+ * console.log(err);
3570
+ * } else {
3571
+ * console.log(result);
3572
+ * // { f1: '1000 Bytes', f2: '1.95 KB', f3: '2.93 KB' }
3573
+ * }
3574
+ * });
3575
+ *
3576
+ * // Using Promises
3577
+ * async.transform(fileMap, transformFileSize)
3578
+ * .then(result => {
3579
+ * console.log(result);
3580
+ * // { f1: '1000 Bytes', f2: '1.95 KB', f3: '2.93 KB' }
3581
+ * }).catch(err => {
3582
+ * console.log(err);
3583
+ * });
3584
+ *
3585
+ * // Using async/await
3586
+ * async () => {
3587
+ * try {
3588
+ * let result = await async.transform(fileMap, transformFileSize);
3589
+ * console.log(result);
3590
+ * // { f1: '1000 Bytes', f2: '1.95 KB', f3: '2.93 KB' }
3591
+ * }
3592
+ * catch (err) {
3593
+ * console.log(err);
3594
+ * }
3595
+ * }
3596
+ *
3597
+ */function transform(coll,accumulator,iteratee,callback){if(arguments.length<=3&&typeof accumulator==='function'){callback=iteratee;iteratee=accumulator;accumulator=Array.isArray(coll)?[]:{};}callback=once(callback||promiseCallback());var _iteratee=wrapAsync(iteratee);eachOf$1(coll,(v,k,cb)=>{_iteratee(accumulator,v,k,cb);},err=>callback(err,accumulator));return callback[PROMISE_SYMBOL];}/**
3598
+ * It runs each task in series but stops whenever any of the functions were
3599
+ * successful. If one of the tasks were successful, the `callback` will be
3600
+ * passed the result of the successful task. If all tasks fail, the callback
3601
+ * will be passed the error and result (if any) of the final attempt.
3602
+ *
3603
+ * @name tryEach
3604
+ * @static
3605
+ * @memberOf module:ControlFlow
3606
+ * @method
3607
+ * @category Control Flow
3608
+ * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection containing functions to
3609
+ * run, each function is passed a `callback(err, result)` it must call on
3610
+ * completion with an error `err` (which can be `null`) and an optional `result`
3611
+ * value.
3612
+ * @param {Function} [callback] - An optional callback which is called when one
3613
+ * of the tasks has succeeded, or all have failed. It receives the `err` and
3614
+ * `result` arguments of the last attempt at completing the `task`. Invoked with
3615
+ * (err, results).
3616
+ * @returns {Promise} a promise, if no callback is passed
3617
+ * @example
3618
+ * async.tryEach([
3619
+ * function getDataFromFirstWebsite(callback) {
3620
+ * // Try getting the data from the first website
3621
+ * callback(err, data);
3622
+ * },
3623
+ * function getDataFromSecondWebsite(callback) {
3624
+ * // First website failed,
3625
+ * // Try getting the data from the backup website
3626
+ * callback(err, data);
3627
+ * }
3628
+ * ],
3629
+ * // optional callback
3630
+ * function(err, results) {
3631
+ * Now do something with the data.
3632
+ * });
3633
+ *
3634
+ */function tryEach(tasks,callback){var error=null;var result;return eachSeries$1(tasks,(task,taskCb)=>{wrapAsync(task)((err,...args)=>{if(err===false)return taskCb(err);if(args.length<2){[result]=args;}else{result=args;}error=err;taskCb(err?null:{});});},()=>callback(error,result));}var tryEach$1=awaitify(tryEach);/**
3635
+ * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original,
3636
+ * unmemoized form. Handy for testing.
3637
+ *
3638
+ * @name unmemoize
3639
+ * @static
3640
+ * @memberOf module:Utils
3641
+ * @method
3642
+ * @see [async.memoize]{@link module:Utils.memoize}
3643
+ * @category Util
3644
+ * @param {AsyncFunction} fn - the memoized function
3645
+ * @returns {AsyncFunction} a function that calls the original unmemoized function
3646
+ */function unmemoize(fn){return(...args)=>{return(fn.unmemoized||fn)(...args);};}/**
3647
+ * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
3648
+ * stopped, or an error occurs.
3649
+ *
3650
+ * @name whilst
3651
+ * @static
3652
+ * @memberOf module:ControlFlow
3653
+ * @method
3654
+ * @category Control Flow
3655
+ * @param {AsyncFunction} test - asynchronous truth test to perform before each
3656
+ * execution of `iteratee`. Invoked with ().
3657
+ * @param {AsyncFunction} iteratee - An async function which is called each time
3658
+ * `test` passes. Invoked with (callback).
3659
+ * @param {Function} [callback] - A callback which is called after the test
3660
+ * function has failed and repeated execution of `iteratee` has stopped. `callback`
3661
+ * will be passed an error and any arguments passed to the final `iteratee`'s
3662
+ * callback. Invoked with (err, [results]);
3663
+ * @returns {Promise} a promise, if no callback is passed
3664
+ * @example
3665
+ *
3666
+ * var count = 0;
3667
+ * async.whilst(
3668
+ * function test(cb) { cb(null, count < 5); },
3669
+ * function iter(callback) {
3670
+ * count++;
3671
+ * setTimeout(function() {
3672
+ * callback(null, count);
3673
+ * }, 1000);
3674
+ * },
3675
+ * function (err, n) {
3676
+ * // 5 seconds have passed, n = 5
3677
+ * }
3678
+ * );
3679
+ */function whilst(test,iteratee,callback){callback=onlyOnce(callback);var _fn=wrapAsync(iteratee);var _test=wrapAsync(test);var results=[];function next(err,...rest){if(err)return callback(err);results=rest;if(err===false)return;_test(check);}function check(err,truth){if(err)return callback(err);if(err===false)return;if(!truth)return callback(null,...results);_fn(next);}return _test(check);}var whilst$1=awaitify(whilst,3);/**
3680
+ * Repeatedly call `iteratee` until `test` returns `true`. Calls `callback` when
3681
+ * stopped, or an error occurs. `callback` will be passed an error and any
3682
+ * arguments passed to the final `iteratee`'s callback.
3683
+ *
3684
+ * The inverse of [whilst]{@link module:ControlFlow.whilst}.
3685
+ *
3686
+ * @name until
3687
+ * @static
3688
+ * @memberOf module:ControlFlow
3689
+ * @method
3690
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
3691
+ * @category Control Flow
3692
+ * @param {AsyncFunction} test - asynchronous truth test to perform before each
3693
+ * execution of `iteratee`. Invoked with (callback).
3694
+ * @param {AsyncFunction} iteratee - An async function which is called each time
3695
+ * `test` fails. Invoked with (callback).
3696
+ * @param {Function} [callback] - A callback which is called after the test
3697
+ * function has passed and repeated execution of `iteratee` has stopped. `callback`
3698
+ * will be passed an error and any arguments passed to the final `iteratee`'s
3699
+ * callback. Invoked with (err, [results]);
3700
+ * @returns {Promise} a promise, if a callback is not passed
3701
+ *
3702
+ * @example
3703
+ * const results = []
3704
+ * let finished = false
3705
+ * async.until(function test(cb) {
3706
+ * cb(null, finished)
3707
+ * }, function iter(next) {
3708
+ * fetchPage(url, (err, body) => {
3709
+ * if (err) return next(err)
3710
+ * results = results.concat(body.objects)
3711
+ * finished = !!body.next
3712
+ * next(err)
3713
+ * })
3714
+ * }, function done (err) {
3715
+ * // all pages have been fetched
3716
+ * })
3717
+ */function until(test,iteratee,callback){const _test=wrapAsync(test);return whilst$1(cb=>_test((err,truth)=>cb(err,!truth)),iteratee,callback);}/**
3718
+ * Runs the `tasks` array of functions in series, each passing their results to
3719
+ * the next in the array. However, if any of the `tasks` pass an error to their
3720
+ * own callback, the next function is not executed, and the main `callback` is
3721
+ * immediately called with the error.
3722
+ *
3723
+ * @name waterfall
3724
+ * @static
3725
+ * @memberOf module:ControlFlow
3726
+ * @method
3727
+ * @category Control Flow
3728
+ * @param {Array} tasks - An array of [async functions]{@link AsyncFunction}
3729
+ * to run.
3730
+ * Each function should complete with any number of `result` values.
3731
+ * The `result` values will be passed as arguments, in order, to the next task.
3732
+ * @param {Function} [callback] - An optional callback to run once all the
3733
+ * functions have completed. This will be passed the results of the last task's
3734
+ * callback. Invoked with (err, [results]).
3735
+ * @returns {Promise} a promise, if a callback is omitted
3736
+ * @example
3737
+ *
3738
+ * async.waterfall([
3739
+ * function(callback) {
3740
+ * callback(null, 'one', 'two');
3741
+ * },
3742
+ * function(arg1, arg2, callback) {
3743
+ * // arg1 now equals 'one' and arg2 now equals 'two'
3744
+ * callback(null, 'three');
3745
+ * },
3746
+ * function(arg1, callback) {
3747
+ * // arg1 now equals 'three'
3748
+ * callback(null, 'done');
3749
+ * }
3750
+ * ], function (err, result) {
3751
+ * // result now equals 'done'
3752
+ * });
3753
+ *
3754
+ * // Or, with named functions:
3755
+ * async.waterfall([
3756
+ * myFirstFunction,
3757
+ * mySecondFunction,
3758
+ * myLastFunction,
3759
+ * ], function (err, result) {
3760
+ * // result now equals 'done'
3761
+ * });
3762
+ * function myFirstFunction(callback) {
3763
+ * callback(null, 'one', 'two');
3764
+ * }
3765
+ * function mySecondFunction(arg1, arg2, callback) {
3766
+ * // arg1 now equals 'one' and arg2 now equals 'two'
3767
+ * callback(null, 'three');
3768
+ * }
3769
+ * function myLastFunction(arg1, callback) {
3770
+ * // arg1 now equals 'three'
3771
+ * callback(null, 'done');
3772
+ * }
3773
+ */function waterfall(tasks,callback){callback=once(callback);if(!Array.isArray(tasks))return callback(new Error('First argument to waterfall must be an array of functions'));if(!tasks.length)return callback();var taskIndex=0;function nextTask(args){var task=wrapAsync(tasks[taskIndex++]);task(...args,onlyOnce(next));}function next(err,...args){if(err===false)return;if(err||taskIndex===tasks.length){return callback(err,...args);}nextTask(args);}nextTask([]);}var waterfall$1=awaitify(waterfall);/**
3774
+ * An "async function" in the context of Async is an asynchronous function with
3775
+ * a variable number of parameters, with the final parameter being a callback.
3776
+ * (`function (arg1, arg2, ..., callback) {}`)
3777
+ * The final callback is of the form `callback(err, results...)`, which must be
3778
+ * called once the function is completed. The callback should be called with a
3779
+ * Error as its first argument to signal that an error occurred.
3780
+ * Otherwise, if no error occurred, it should be called with `null` as the first
3781
+ * argument, and any additional `result` arguments that may apply, to signal
3782
+ * successful completion.
3783
+ * The callback must be called exactly once, ideally on a later tick of the
3784
+ * JavaScript event loop.
3785
+ *
3786
+ * This type of function is also referred to as a "Node-style async function",
3787
+ * or a "continuation passing-style function" (CPS). Most of the methods of this
3788
+ * library are themselves CPS/Node-style async functions, or functions that
3789
+ * return CPS/Node-style async functions.
3790
+ *
3791
+ * Wherever we accept a Node-style async function, we also directly accept an
3792
+ * [ES2017 `async` function]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function}.
3793
+ * In this case, the `async` function will not be passed a final callback
3794
+ * argument, and any thrown error will be used as the `err` argument of the
3795
+ * implicit callback, and the return value will be used as the `result` value.
3796
+ * (i.e. a `rejected` of the returned Promise becomes the `err` callback
3797
+ * argument, and a `resolved` value becomes the `result`.)
3798
+ *
3799
+ * Note, due to JavaScript limitations, we can only detect native `async`
3800
+ * functions and not transpilied implementations.
3801
+ * Your environment must have `async`/`await` support for this to work.
3802
+ * (e.g. Node > v7.6, or a recent version of a modern browser).
3803
+ * If you are using `async` functions through a transpiler (e.g. Babel), you
3804
+ * must still wrap the function with [asyncify]{@link module:Utils.asyncify},
3805
+ * because the `async function` will be compiled to an ordinary function that
3806
+ * returns a promise.
3807
+ *
3808
+ * @typedef {Function} AsyncFunction
3809
+ * @static
3810
+ */var index={apply,applyEach:applyEach$1,applyEachSeries,asyncify,auto,autoInject,cargo,cargoQueue:cargo$1,compose,concat:concat$1,concatLimit:concatLimit$1,concatSeries:concatSeries$1,constant,detect:detect$1,detectLimit:detectLimit$1,detectSeries:detectSeries$1,dir,doUntil,doWhilst:doWhilst$1,each,eachLimit:eachLimit$2,eachOf:eachOf$1,eachOfLimit:eachOfLimit$2,eachOfSeries:eachOfSeries$1,eachSeries:eachSeries$1,ensureAsync,every:every$1,everyLimit:everyLimit$1,everySeries:everySeries$1,filter:filter$1,filterLimit:filterLimit$1,filterSeries:filterSeries$1,forever:forever$1,groupBy,groupByLimit:groupByLimit$1,groupBySeries,log,map:map$1,mapLimit:mapLimit$1,mapSeries:mapSeries$1,mapValues,mapValuesLimit:mapValuesLimit$1,mapValuesSeries,memoize,nextTick,parallel:parallel$1,parallelLimit,priorityQueue,queue:queue$1,race:race$1,reduce:reduce$1,reduceRight,reflect,reflectAll,reject:reject$2,rejectLimit:rejectLimit$1,rejectSeries:rejectSeries$1,retry,retryable,seq,series,setImmediate:setImmediate$1,some:some$1,someLimit:someLimit$1,someSeries:someSeries$1,sortBy:sortBy$1,timeout,times,timesLimit,timesSeries,transform,tryEach:tryEach$1,unmemoize,until,waterfall:waterfall$1,whilst:whilst$1,// aliases
3811
+ all:every$1,allLimit:everyLimit$1,allSeries:everySeries$1,any:some$1,anyLimit:someLimit$1,anySeries:someSeries$1,find:detect$1,findLimit:detectLimit$1,findSeries:detectSeries$1,flatMap:concat$1,flatMapLimit:concatLimit$1,flatMapSeries:concatSeries$1,forEach:each,forEachSeries:eachSeries$1,forEachLimit:eachLimit$2,forEachOf:eachOf$1,forEachOfSeries:eachOfSeries$1,forEachOfLimit:eachOfLimit$2,inject:reduce$1,foldl:reduce$1,foldr:reduceRight,select:filter$1,selectLimit:filterLimit$1,selectSeries:filterSeries$1,wrapSync:asyncify,during:whilst$1,doDuring:doWhilst$1};exports.default=index;exports.apply=apply;exports.applyEach=applyEach$1;exports.applyEachSeries=applyEachSeries;exports.asyncify=asyncify;exports.auto=auto;exports.autoInject=autoInject;exports.cargo=cargo;exports.cargoQueue=cargo$1;exports.compose=compose;exports.concat=concat$1;exports.concatLimit=concatLimit$1;exports.concatSeries=concatSeries$1;exports.constant=constant;exports.detect=detect$1;exports.detectLimit=detectLimit$1;exports.detectSeries=detectSeries$1;exports.dir=dir;exports.doUntil=doUntil;exports.doWhilst=doWhilst$1;exports.each=each;exports.eachLimit=eachLimit$2;exports.eachOf=eachOf$1;exports.eachOfLimit=eachOfLimit$2;exports.eachOfSeries=eachOfSeries$1;exports.eachSeries=eachSeries$1;exports.ensureAsync=ensureAsync;exports.every=every$1;exports.everyLimit=everyLimit$1;exports.everySeries=everySeries$1;exports.filter=filter$1;exports.filterLimit=filterLimit$1;exports.filterSeries=filterSeries$1;exports.forever=forever$1;exports.groupBy=groupBy;exports.groupByLimit=groupByLimit$1;exports.groupBySeries=groupBySeries;exports.log=log;exports.map=map$1;exports.mapLimit=mapLimit$1;exports.mapSeries=mapSeries$1;exports.mapValues=mapValues;exports.mapValuesLimit=mapValuesLimit$1;exports.mapValuesSeries=mapValuesSeries;exports.memoize=memoize;exports.nextTick=nextTick;exports.parallel=parallel$1;exports.parallelLimit=parallelLimit;exports.priorityQueue=priorityQueue;exports.queue=queue$1;exports.race=race$1;exports.reduce=reduce$1;exports.reduceRight=reduceRight;exports.reflect=reflect;exports.reflectAll=reflectAll;exports.reject=reject$2;exports.rejectLimit=rejectLimit$1;exports.rejectSeries=rejectSeries$1;exports.retry=retry;exports.retryable=retryable;exports.seq=seq;exports.series=series;exports.setImmediate=setImmediate$1;exports.some=some$1;exports.someLimit=someLimit$1;exports.someSeries=someSeries$1;exports.sortBy=sortBy$1;exports.timeout=timeout;exports.times=times;exports.timesLimit=timesLimit;exports.timesSeries=timesSeries;exports.transform=transform;exports.tryEach=tryEach$1;exports.unmemoize=unmemoize;exports.until=until;exports.waterfall=waterfall$1;exports.whilst=whilst$1;exports.all=every$1;exports.allLimit=everyLimit$1;exports.allSeries=everySeries$1;exports.any=some$1;exports.anyLimit=someLimit$1;exports.anySeries=someSeries$1;exports.find=detect$1;exports.findLimit=detectLimit$1;exports.findSeries=detectSeries$1;exports.flatMap=concat$1;exports.flatMapLimit=concatLimit$1;exports.flatMapSeries=concatSeries$1;exports.forEach=each;exports.forEachSeries=eachSeries$1;exports.forEachLimit=eachLimit$2;exports.forEachOf=eachOf$1;exports.forEachOfSeries=eachOfSeries$1;exports.forEachOfLimit=eachOfLimit$2;exports.inject=reduce$1;exports.foldl=reduce$1;exports.foldr=reduceRight;exports.select=filter$1;exports.selectLimit=filterLimit$1;exports.selectSeries=filterSeries$1;exports.wrapSync=asyncify;exports.during=whilst$1;exports.doDuring=doWhilst$1;Object.defineProperty(exports,'__esModule',{value:true});});}).call(this);}).call(this,require('_process'),require("timers").setImmediate);},{"_process":2,"timers":3}],2:[function(require,module,exports){// shim for using process in browser
3812
+ var process=module.exports={};// cached from whatever global is present so that test runners that stub it
3813
+ // don't break things. But we need to wrap it in a try catch in case it is
3814
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
3815
+ // function because try/catches deoptimize in certain engines.
3816
+ 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
3817
+ return setTimeout(fun,0);}// if setTimeout wasn't available but was latter defined
3818
+ if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout){cachedSetTimeout=setTimeout;return setTimeout(fun,0);}try{// when when somebody has screwed with setTimeout but no I.E. maddness
3819
+ 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
3820
+ 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
3821
+ return cachedSetTimeout.call(this,fun,0);}}}function runClearTimeout(marker){if(cachedClearTimeout===clearTimeout){//normal enviroments in sane situations
3822
+ return clearTimeout(marker);}// if clearTimeout wasn't available but was latter defined
3823
+ if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout){cachedClearTimeout=clearTimeout;return clearTimeout(marker);}try{// when when somebody has screwed with setTimeout but no I.E. maddness
3824
+ 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
3825
+ 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.
3826
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
3827
+ 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
3828
+ 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
3829
+ 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;};},{}],3:[function(require,module,exports){(function(setImmediate,clearImmediate){(function(){var nextTick=require('process/browser.js').nextTick;var apply=Function.prototype.apply;var slice=Array.prototype.slice;var immediateIds={};var nextImmediateId=0;// DOM APIs, for completeness
3830
+ exports.setTimeout=function(){return new Timeout(apply.call(setTimeout,window,arguments),clearTimeout);};exports.setInterval=function(){return new Timeout(apply.call(setInterval,window,arguments),clearInterval);};exports.clearTimeout=exports.clearInterval=function(timeout){timeout.close();};function Timeout(id,clearFn){this._id=id;this._clearFn=clearFn;}Timeout.prototype.unref=Timeout.prototype.ref=function(){};Timeout.prototype.close=function(){this._clearFn.call(window,this._id);};// Does not start the time, just sets up the members needed.
3831
+ exports.enroll=function(item,msecs){clearTimeout(item._idleTimeoutId);item._idleTimeout=msecs;};exports.unenroll=function(item){clearTimeout(item._idleTimeoutId);item._idleTimeout=-1;};exports._unrefActive=exports.active=function(item){clearTimeout(item._idleTimeoutId);var msecs=item._idleTimeout;if(msecs>=0){item._idleTimeoutId=setTimeout(function onTimeout(){if(item._onTimeout)item._onTimeout();},msecs);}};// That's not how node.js implements it but the exposed api is the same.
3832
+ exports.setImmediate=typeof setImmediate==="function"?setImmediate:function(fn){var id=nextImmediateId++;var args=arguments.length<2?false:slice.call(arguments,1);immediateIds[id]=true;nextTick(function onNextTick(){if(immediateIds[id]){// fn.call() is faster so we optimize for the common use-case
3833
+ // @see http://jsperf.com/call-apply-segu
3834
+ if(args){fn.apply(null,args);}else{fn.call(null);}// Prevent ids from leaking
3835
+ exports.clearImmediate(id);}});return id;};exports.clearImmediate=typeof clearImmediate==="function"?clearImmediate:function(id){delete immediateIds[id];};}).call(this);}).call(this,require("timers").setImmediate,require("timers").clearImmediate);},{"process/browser.js":2,"timers":3}],4:[function(require,module,exports){/**
3836
+ * Simple browser shim loader - assign the npm module to a window global automatically
3837
+ *
3838
+ * @author <steven@velozo.com>
3839
+ */var libNPMModuleWrapper=require('./Precedent.js');if(typeof window=='object'&&!window.hasOwnProperty('Precedent')){window.Precedent=libNPMModuleWrapper;}module.exports=libNPMModuleWrapper;},{"./Precedent.js":5}],5:[function(require,module,exports){/**
3840
+ * Precedent Meta-Templating
3841
+ *
3842
+ * @license MIT
3843
+ *
3844
+ * @author Steven Velozo <steven@velozo.com>
3845
+ *
3846
+ * @description Process text streams, parsing out meta-template expressions.
3847
+ */var libWordTree=require(`./WordTree.js`);var libStringParser=require(`./StringParser.js`);class Precedent{/**
3848
+ * Precedent Constructor
3849
+ */constructor(){this.WordTree=new libWordTree();this.StringParser=new libStringParser();this.ParseTree=this.WordTree.ParseTree;}/**
3850
+ * Add a Pattern to the Parse Tree
3851
+ * @method addPattern
3852
+ * @param {Object} pTree - A node on the parse tree to push the characters into
3853
+ * @param {string} pPattern - The string to add to the tree
3854
+ * @param {number} pIndex - callback function
3855
+ * @return {bool} True if adding the pattern was successful
3856
+ */addPattern(pPatternStart,pPatternEnd,pParser){return this.WordTree.addPattern(pPatternStart,pPatternEnd,pParser);}addPatternAsync(pPatternStart,pPatternEnd,pParserPromise){return this.WordTree.addPatternAsync(pPatternStart,pPatternEnd,pParserPromise);}/**
3857
+ * Parse a string with the existing parse tree
3858
+ * @method parseString
3859
+ * @param {string} pString - The string to parse
3860
+ * @param {object} pData - Data to pass in as the second argument
3861
+ * @return {string} The result from the parser
3862
+ */parseString(pString,pData,fCallback){return this.StringParser.parseString(pString,this.ParseTree,pData,fCallback);}}module.exports=Precedent;},{"./StringParser.js":6,"./WordTree.js":7}],6:[function(require,module,exports){/**
3863
+ * String Parser
3864
+ *
3865
+ * @license MIT
3866
+ *
3867
+ * @author Steven Velozo <steven@velozo.com>
3868
+ *
3869
+ * @description Parse a string, properly processing each matched token in the word tree.
3870
+ */let libAsync=require('async');class StringParser{/**
3871
+ * StringParser Constructor
3872
+ */constructor(){}/**
3873
+ * Create a fresh parsing state object to work with.
3874
+ * @method newParserState
3875
+ * @param {Object} pParseTree - A node on the parse tree to begin parsing from (usually root)
3876
+ * @return {Object} A new parser state object for running a character parser on
3877
+ * @private
3878
+ */newParserState(pParseTree){return{ParseTree:pParseTree,Asynchronous:false,Output:'',OutputBuffer:'',Pattern:false,PatternMatch:false,PatternMatchOutputBuffer:''};}/**
3879
+ * Assign a node of the parser tree to be the next potential match.
3880
+ * If the node has a PatternEnd property, it is a valid match and supercedes the last valid match (or becomes the initial match).
3881
+ * @method assignNode
3882
+ * @param {Object} pNode - A node on the parse tree to assign
3883
+ * @param {Object} pParserState - The state object for the current parsing task
3884
+ * @private
3885
+ */assignNode(pNode,pParserState){pParserState.PatternMatch=pNode;// If the pattern has a END we can assume it has a parse function...
3886
+ if(pParserState.PatternMatch.hasOwnProperty('PatternEnd')){// ... this is the legitimate start of a pattern.
3887
+ pParserState.Pattern=pParserState.PatternMatch;}}/**
3888
+ * Append a character to the output buffer in the parser state.
3889
+ * This output buffer is used when a potential match is being explored, or a match is being explored.
3890
+ * @method appendOutputBuffer
3891
+ * @param {string} pCharacter - The character to append
3892
+ * @param {Object} pParserState - The state object for the current parsing task
3893
+ * @private
3894
+ */appendOutputBuffer(pCharacter,pParserState){pParserState.OutputBuffer+=pCharacter;}/**
3895
+ * Flush the output buffer to the output and clear it.
3896
+ * @method flushOutputBuffer
3897
+ * @param {Object} pParserState - The state object for the current parsing task
3898
+ * @private
3899
+ */flushOutputBuffer(pParserState){pParserState.Output+=pParserState.OutputBuffer;pParserState.OutputBuffer='';}/**
3900
+ * Check if the pattern has ended. If it has, properly flush the buffer and start looking for new patterns.
3901
+ * @method checkPatternEnd
3902
+ * @param {Object} pParserState - The state object for the current parsing task
3903
+ * @private
3904
+ */checkPatternEnd(pParserState,pData){if(pParserState.OutputBuffer.length>=pParserState.Pattern.PatternEnd.length+pParserState.Pattern.PatternStart.length&&pParserState.OutputBuffer.substr(-pParserState.Pattern.PatternEnd.length)===pParserState.Pattern.PatternEnd){// ... this is the end of a pattern, cut off the end tag and parse it.
3905
+ // Trim the start and end tags off the output buffer now
3906
+ if(pParserState.Pattern.isAsync){console.log(`Precedent ERROR: Async template detected for pattern ${pParserState.Pattern.PatternStart} ... ${pParserState.Pattern.PatternEnd} but the template engine is being run in non-async mode.`);this.OutputBuffer='';// Flush the output buffer.
3907
+ this.flushOutputBuffer(pParserState);// End pattern mode
3908
+ pParserState.Pattern=false;pParserState.PatternMatch=false;}else{pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStart.length+pParserState.Pattern.PatternEnd.length)),pData);// Flush the output buffer.
3909
+ this.flushOutputBuffer(pParserState);// End pattern mode
3910
+ pParserState.Pattern=false;pParserState.PatternMatch=false;}}}checkPatternEndAsync(pParserState,pData,fCallback){if(pParserState.OutputBuffer.length>=pParserState.Pattern.PatternEnd.length+pParserState.Pattern.PatternStart.length&&pParserState.OutputBuffer.substr(-pParserState.Pattern.PatternEnd.length)===pParserState.Pattern.PatternEnd){// ... this is the end of a pattern, cut off the end tag and parse it.
3911
+ // Trim the start and end tags off the output buffer now
3912
+ if(pParserState.Pattern.isAsync){return pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStart.length+pParserState.Pattern.PatternEnd.length)),pData,(pError,pAsyncOutput)=>{if(pError){console.log(`Precedent ERROR: Async template error happened parsing ${pParserState.Pattern.PatternStart} ... ${pParserState.Pattern.PatternEnd}: ${pError}`);}pParserState.OutputBuffer=pAsyncOutput;// Flush the output buffer.
3913
+ this.flushOutputBuffer(pParserState);// End pattern mode
3914
+ pParserState.Pattern=false;pParserState.PatternMatch=false;return fCallback();});}else{pParserState.OutputBuffer=pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length,pParserState.OutputBuffer.length-(pParserState.Pattern.PatternStart.length+pParserState.Pattern.PatternEnd.length)),pData);// Flush the output buffer.
3915
+ this.flushOutputBuffer(pParserState);// End pattern mode
3916
+ pParserState.Pattern=false;pParserState.PatternMatch=false;}}return fCallback();}/**
3917
+ * Parse a character in the buffer.
3918
+ * @method parseCharacter
3919
+ * @param {string} pCharacter - The character to append
3920
+ * @param {Object} pParserState - The state object for the current parsing task
3921
+ * @private
3922
+ */parseCharacter(pCharacter,pParserState,pData){// (1) If we aren't in a pattern match, and we aren't potentially matching, and this may be the start of a new pattern....
3923
+ if(!pParserState.PatternMatch&&pParserState.ParseTree.hasOwnProperty(pCharacter)){// ... assign the node as the matched node.
3924
+ this.assignNode(pParserState.ParseTree[pCharacter],pParserState);this.appendOutputBuffer(pCharacter,pParserState);}// (2) If we are in a pattern match (actively seeing if this is part of a new pattern token)
3925
+ else if(pParserState.PatternMatch){// If the pattern has a subpattern with this key
3926
+ if(pParserState.PatternMatch.hasOwnProperty(pCharacter)){// Continue matching patterns.
3927
+ this.assignNode(pParserState.PatternMatch[pCharacter],pParserState);}this.appendOutputBuffer(pCharacter,pParserState);if(pParserState.Pattern){// ... Check if this is the end of the pattern (if we are matching a valid pattern)...
3928
+ this.checkPatternEnd(pParserState,pData);}}// (3) If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
3929
+ else{pParserState.Output+=pCharacter;}}parseCharacterAsync(pCharacter,pParserState,pData,fCallback){// (1) If we aren't in a pattern match, and we aren't potentially matching, and this may be the start of a new pattern....
3930
+ if(!pParserState.PatternMatch&&pParserState.ParseTree.hasOwnProperty(pCharacter)){// ... assign the node as the matched node.
3931
+ this.assignNode(pParserState.ParseTree[pCharacter],pParserState);this.appendOutputBuffer(pCharacter,pParserState);}// (2) If we are in a pattern match (actively seeing if this is part of a new pattern token)
3932
+ else if(pParserState.PatternMatch){// If the pattern has a subpattern with this key
3933
+ if(pParserState.PatternMatch.hasOwnProperty(pCharacter)){// Continue matching patterns.
3934
+ this.assignNode(pParserState.PatternMatch[pCharacter],pParserState);}this.appendOutputBuffer(pCharacter,pParserState);if(pParserState.Pattern){// ... Check if this is the end of the pattern (if we are matching a valid pattern)...
3935
+ return this.checkPatternEndAsync(pParserState,pData,fCallback);}}// (3) If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
3936
+ else{pParserState.Output+=pCharacter;}return fCallback(null);}/**
3937
+ * Parse a string for matches, and process any template segments that occur.
3938
+ * @method parseString
3939
+ * @param {string} pString - The string to parse.
3940
+ * @param {Object} pParseTree - The parse tree to begin parsing from (usually root)
3941
+ * @param {Object} pData - The data to pass to the function as a second parameter
3942
+ * @param {function} fCallback - The callback function to call when the parse is complete
3943
+ */parseString(pString,pParseTree,pData,fCallback){if(typeof fCallback!=='function'){let tmpParserState=this.newParserState(pParseTree);for(var i=0;i<pString.length;i++){// TODO: This is not fast.
3944
+ this.parseCharacter(pString[i],tmpParserState,pData,fCallback);}this.flushOutputBuffer(tmpParserState);return tmpParserState.Output;}else{// This is the async mode
3945
+ let tmpParserState=this.newParserState(pParseTree);libAsync.eachSeries(pString,(pCharacter,fCharacterCallback)=>{this.parseCharacterAsync(pCharacter,tmpParserState,pData,fCharacterCallback);},pError=>{// Flush the remaining data
3946
+ this.flushOutputBuffer(tmpParserState);fCallback(pError,tmpParserState.Output);});}}}module.exports=StringParser;},{"async":1}],7:[function(require,module,exports){/**
3947
+ * Word Tree
3948
+ *
3949
+ * @license MIT
3950
+ *
3951
+ * @author Steven Velozo <steven@velozo.com>
3952
+ *
3953
+ * @description Create a tree (directed graph) of Javascript objects, one character per object.
3954
+ */class WordTree{/**
3955
+ * WordTree Constructor
3956
+ */constructor(){this.ParseTree={};}/**
3957
+ * Add a child character to a Parse Tree node
3958
+ * @method addChild
3959
+ * @param {Object} pTree - A parse tree to push the characters into
3960
+ * @param {string} pPattern - The string to add to the tree
3961
+ * @param {number} pIndex - The index of the character in the pattern
3962
+ * @returns {Object} The resulting leaf node that was added (or found)
3963
+ * @private
3964
+ */addChild(pTree,pPattern,pIndex){if(!pTree.hasOwnProperty(pPattern[pIndex]))pTree[pPattern[pIndex]]={};return pTree[pPattern[pIndex]];}/** Add a Pattern to the Parse Tree
3965
+ * @method addPattern
3966
+ * @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
3967
+ * @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
3968
+ * @param {number} pParser - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
3969
+ * @return {bool} True if adding the pattern was successful
3970
+ */addPattern(pPatternStart,pPatternEnd,pParser){if(pPatternStart.length<1)return false;if(typeof pPatternEnd==='string'&&pPatternEnd.length<1)return false;let tmpLeaf=this.ParseTree;// Add the tree of leaves iteratively
3971
+ for(var i=0;i<pPatternStart.length;i++)tmpLeaf=this.addChild(tmpLeaf,pPatternStart,i);tmpLeaf.PatternStart=pPatternStart;tmpLeaf.PatternEnd=typeof pPatternEnd==='string'&&pPatternEnd.length>0?pPatternEnd:pPatternStart;tmpLeaf.Parse=typeof pParser==='function'?pParser:typeof pParser==='string'?()=>{return pParser;}:pData=>{return pData;};tmpLeaf.isPromise=false;return true;}/** Add a Pattern to the Parse Tree (asynchronous)
3972
+ * @method addPattern
3973
+ * @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
3974
+ * @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
3975
+ * @param {number} pParserAsync - The function (with an asynchronous callback) to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
3976
+ * @return {bool} True if adding the pattern was successful
3977
+ */addPatternAsync(pPatternStart,pPatternEnd,pParserAsync){if(pPatternStart.length<1)return false;if(typeof pPatternEnd==='string'&&pPatternEnd.length<1)return false;let tmpLeaf=this.ParseTree;// Add the tree of leaves iteratively
3978
+ for(var i=0;i<pPatternStart.length;i++)tmpLeaf=this.addChild(tmpLeaf,pPatternStart,i);tmpLeaf.PatternStart=pPatternStart;tmpLeaf.PatternEnd=typeof pPatternEnd==='string'&&pPatternEnd.length>0?pPatternEnd:pPatternStart;tmpLeaf.Parse=typeof pParserAsync==='function'?pParserAsync:typeof pParserAsync==='string'?(pHash,pData,fCallback)=>{fCallback(pParserPromise);}:(pHash,pData,fCallback)=>{return fCallback(pHash);};tmpLeaf.isAsync=true;return true;}}module.exports=WordTree;},{}]},{},[4])(4);});