PageSourceSearch

https://shc.co.jp/assets/libs/kuromoji/kuromoji.js

js shc.co.jp collected 2026-10-02 10:25:53 UTC 326,094 bytes, 9,060 lines download raw bytes

vendor: 14,799 bytes, lines 1-485
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.kuromoji = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
2  (function (process,global){
3  (function (global, factory) {
4    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5    typeof define === 'function' && define.amd ? define(['exports'], factory) :
6    (factory((global.async = global.async || {})));
7  }(this, (function (exports) { 'use strict';
8  
9  function slice(arrayLike, start) {
10      start = start|0;
11      var newLen = Math.max(arrayLike.length - start, 0);
12      var newArr = Array(newLen);
13      for(var idx = 0; idx < newLen; idx++)  {
14          newArr[idx] = arrayLike[start + idx];
15      }
16      return newArr;
17  }
18  
19  /**
20   * Creates a continuation function with some arguments already applied.
21   *
22   * Useful as a shorthand when combined with other control flow functions. Any
23   * arguments passed to the returned function are added to the arguments
24   * originally passed to apply.
25   *
26   * @name apply
27   * @static
28   * @memberOf module:Utils
29   * @method
30   * @category Util
31   * @param {Function} fn - The function you want to eventually apply all
32   * arguments to. Invokes with (arguments...).
33   * @param {...*} arguments... - Any number of arguments to automatically apply
34   * when the continuation is called.
35   * @returns {Function} the partially-applied function
36   * @example
37   *
38   * // using apply
39   * async.parallel([
40   *     async.apply(fs.writeFile, 'testfile1', 'test1'),
41   *     async.apply(fs.writeFile, 'testfile2', 'test2')
42   * ]);
43   *
44   *
45   * // the same process without using apply
46   * async.parallel([
47   *     function(callback) {
48   *         fs.writeFile('testfile1', 'test1', callback);
49   *     },
50   *     function(callback) {
51   *         fs.writeFile('testfile2', 'test2', callback);
52   *     }
53   * ]);
54   *
55   * // It's possible to pass any number of additional arguments when calling the
56   * // continuation:
57   *
58   * node> var fn = async.apply(sys.puts, 'one');
59   * node> fn('two', 'three');
60   * one
61   * two
62   * three
63   */
64  var apply = function(fn/*, ...args*/) {
65      var args = slice(arguments, 1);
66      return function(/*callArgs*/) {
67          var callArgs = slice(arguments);
68          return fn.apply(null, args.concat(callArgs));
69      };
70  };
71  
72  var initialParams = function (fn) {
73      return function (/*...args, callback*/) {
74          var args = slice(arguments);
75          var callback = args.pop();
76          fn.call(this, args, callback);
77      };
78  };
79  
80  /**
81   * Checks if `value` is the
82   * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
83   * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
84   *
85   * @static
86   * @memberOf _
87   * @since 0.1.0
88   * @category Lang
89   * @param {*} value The value to check.
90   * @returns {boolean} Returns `true` if `value` is an object, else `false`.
91   * @example
92   *
93   * _.isObject({});
94   * // => true
95   *
96   * _.isObject([1, 2, 3]);
97   * // => true
98   *
99   * _.isObject(_.noop);
100   * // => true
101   *
102   * _.isObject(null);
103   * // => false
104   */
105  function isObject(value) {
106    var type = typeof value;
107    return value != null && (type == 'object' || type == 'function');
108  }
109  
110  var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
111  var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
112  
113  function fallback(fn) {
114      setTimeout(fn, 0);
115  }
116  
117  function wrap(defer) {
118      return function (fn/*, ...args*/) {
119          var args = slice(arguments, 1);
120          defer(function () {
121              fn.apply(null, args);
122          });
123      };
124  }
125  
126  var _defer;
127  
128  if (hasSetImmediate) {
129      _defer = setImmediate;
130  } else if (hasNextTick) {
131      _defer = process.nextTick;
132  } else {
133      _defer = fallback;
134  }
135  
136  var setImmediate$1 = wrap(_defer);
137  
138  /**
139   * Take a sync function and make it async, passing its return value to a
140   * callback. This is useful for plugging sync functions into a waterfall,
141   * series, or other async functions. Any arguments passed to the generated
142   * function will be passed to the wrapped function (except for the final
143   * callback argument). Errors thrown will be passed to the callback.
144   *
145   * If the function passed to `asyncify` returns a Promise, that promises's
146   * resolved/rejected state will be used to call the callback, rather than simply
147   * the synchronous return value.
148   *
149   * This also means you can asyncify ES2017 `async` functions.
150   *
151   * @name asyncify
152   * @static
153   * @memberOf module:Utils
154   * @method
155   * @alias wrapSync
156   * @category Util
157   * @param {Function} func - The synchronous function, or Promise-returning
158   * function to convert to an {@link AsyncFunction}.
159   * @returns {AsyncFunction} An asynchronous wrapper of the `func`. To be
160   * invoked with `(args..., callback)`.
161   * @example
162   *
163   * // passing a regular synchronous function
164   * async.waterfall([
165   *     async.apply(fs.readFile, filename, "utf8"),
166   *     async.asyncify(JSON.parse),
167   *     function (data, next) {
168   *         // data is the result of parsing the text.
169   *         // If there was a parsing error, it would have been caught.
170   *     }
171   * ], callback);
172   *
173   * // passing a function returning a promise
174   * async.waterfall([
175   *     async.apply(fs.readFile, filename, "utf8"),
176   *     async.asyncify(function (contents) {
177   *         return db.model.create(contents);
178   *     }),
179   *     function (model, next) {
180   *         // `model` is the instantiated model object.
181   *         // If there was an error, this function would be skipped.
182   *     }
183   * ], callback);
184   *
185   * // es2017 example, though `asyncify` is not needed if your JS environment
186   * // supports async functions out of the box
187   * var q = async.queue(async.asyncify(async function(file) {
188   *     var intermediateStep = await processFile(file);
189   *     return await somePromise(intermediateStep)
190   * }));
191   *
192   * q.push(files);
193   */
194  function asyncify(func) {
195      return initialParams(function (args, callback) {
196          var result;
197          try {
198              result = func.apply(this, args);
199          } catch (e) {
200              return callback(e);
201          }
202          // if result is Promise object
203          if (isObject(result) && typeof result.then === 'function') {
204              result.then(function(value) {
205                  invokeCallback(callback, null, value);
206              }, function(err) {
207                  invokeCallback(callback, err.message ? err : new Error(err));
208              });
209          } else {
210              callback(null, result);
211          }
212      });
213  }
214  
215  function invokeCallback(callback, error, value) {
216      try {
217          callback(error, value);
218      } catch (e) {
219          setImmediate$1(rethrow, e);
220      }
221  }
222  
223  function rethrow(error) {
224      throw error;
225  }
226  
227  var supportsSymbol = typeof Symbol === 'function';
228  
229  function isAsync(fn) {
230      return supportsSymbol && fn[Symbol.toStringTag] === 'AsyncFunction';
231  }
232  
233  function wrapAsync(asyncFn) {
234      return isAsync(asyncFn) ? asyncify(asyncFn) : asyncFn;
235  }
236  
237  function applyEach$1(eachfn) {
238      return function(fns/*, ...args*/) {
239          var args = slice(arguments, 1);
240          var go = initialParams(function(args, callback) {
241              var that = this;
242              return eachfn(fns, function (fn, cb) {
243                  wrapAsync(fn).apply(that, args.concat(cb));
244              }, callback);
245          });
246          if (args.length) {
247              return go.apply(this, args);
248          }
249          else {
250              return go;
251          }
252      };
253  }
254  
255  /** Detect free variable `global` from Node.js. */
256  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
257  
258  /** Detect free variable `self`. */
259  var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
260  
261  /** Used as a reference to the global object. */
262  var root = freeGlobal || freeSelf || Function('return this')();
263  
264  /** Built-in value references. */
265  var Symbol$1 = root.Symbol;
266  
267  /** Used for built-in method references. */
268  var objectProto = Object.prototype;
269  
270  /** Used to check objects for own properties. */
271  var hasOwnProperty = objectProto.hasOwnProperty;
272  
273  /**
274   * Used to resolve the
275   * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
276   * of values.
277   */
278  var nativeObjectToString = objectProto.toString;
279  
280  /** Built-in value references. */
281  var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
282  
283  /**
284   * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
285   *
286   * @private
287   * @param {*} value The value to query.
288   * @returns {string} Returns the raw `toStringTag`.
289   */
290  function getRawTag(value) {
291    var isOwn = hasOwnProperty.call(value, symToStringTag$1),
292        tag = value[symToStringTag$1];
293  
294    try {
295      value[symToStringTag$1] = undefined;
296      var unmasked = true;
297    } catch (e) {}
298  
299    var result = nativeObjectToString.call(value);
300    if (unmasked) {
301      if (isOwn) {
302        value[symToStringTag$1] = tag;
303      } else {
304        delete value[symToStringTag$1];
305      }
306    }
307    return result;
308  }
309  
310  /** Used for built-in method references. */
311  var objectProto$1 = Object.prototype;
312  
313  /**
314   * Used to resolve the
315   * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
316   * of values.
317   */
318  var nativeObjectToString$1 = objectProto$1.toString;
319  
320  /**
321   * Converts `value` to a string using `Object.prototype.toString`.
322   *
323   * @private
324   * @param {*} value The value to convert.
325   * @returns {string} Returns the converted string.
326   */
327  function objectToString(value) {
328    return nativeObjectToString$1.call(value);
329  }
330  
331  /** `Object#toString` result references. */
332  var nullTag = '[object Null]';
333  var undefinedTag = '[object Undefined]';
334  
335  /** Built-in value references. */
336  var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
337  
338  /**
339   * The base implementation of `getTag` without fallbacks for buggy environments.
340   *
341   * @private
342   * @param {*} value The value to query.
343   * @returns {string} Returns the `toStringTag`.
344   */
345  function baseGetTag(value) {
346    if (value == null) {
347      return value === undefined ? undefinedTag : nullTag;
348    }
349    return (symToStringTag && symToStringTag in Object(value))
350      ? getRawTag(value)
351      : objectToString(value);
352  }
353  
354  /** `Object#toString` result references. */
355  var asyncTag = '[object AsyncFunction]';
356  var funcTag = '[object Function]';
357  var genTag = '[object GeneratorFunction]';
358  var proxyTag = '[object Proxy]';
359  
360  /**
361   * Checks if `value` is classified as a `Function` object.
362   *
363   * @static
364   * @memberOf _
365   * @since 0.1.0
366   * @category Lang
367   * @param {*} value The value to check.
368   * @returns {boolean} Returns `true` if `value` is a function, else `false`.
369   * @example
370   *
371   * _.isFunction(_);
372   * // => true
373   *
374   * _.isFunction(/abc/);
375   * // => false
376   */
377  function isFunction(value) {
378    if (!isObject(value)) {
379      return false;
380    }
381    // The use of `Object#toString` avoids issues with the `typeof` operator
382    // in Safari 9 which returns 'object' for typed arrays and other constructors.
383    var tag = baseGetTag(value);
384    return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
385  }
386  
387  /** Used as references for various `Number` constants. */
388  var MAX_SAFE_INTEGER = 9007199254740991;
389  
390  /**
391   * Checks if `value` is a valid array-like length.
392   *
393   * **Note:** This method is loosely based on
394   * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
395   *
396   * @static
397   * @memberOf _
398   * @since 4.0.0
399   * @category Lang
400   * @param {*} value The value to check.
401   * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
402   * @example
403   *
404   * _.isLength(3);
405   * // => true
406   *
407   * _.isLength(Number.MIN_VALUE);
408   * // => false
409   *
410   * _.isLength(Infinity);
411   * // => false
412   *
413   * _.isLength('3');
414   * // => false
415   */
416  function isLength(value) {
417    return typeof value == 'number' &&
418      value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
419  }
420  
421  /**
422   * Checks if `value` is array-like. A value is considered array-like if it's
423   * not a function and has a `value.length` that's an integer greater than or
424   * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
425   *
426   * @static
427   * @memberOf _
428   * @since 4.0.0
429   * @category Lang
430   * @param {*} value The value to check.
431   * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
432   * @example
433   *
434   * _.isArrayLike([1, 2, 3]);
435   * // => true
436   *
437   * _.isArrayLike(document.body.children);
438   * // => true
439   *
440   * _.isArrayLike('abc');
441   * // => true
442   *
443   * _.isArrayLike(_.noop);
444   * // => false
445   */
446  function isArrayLike(value) {
447    return value != null && isLength(value.length) && !isFunction(value);
448  }
449  
450  // A temporary value used to identify if the loop should be broken.
451  // See #1064, #1293
452  var breakLoop = {};
453  
454  /**
455   * This method returns `undefined`.
456   *
457   * @static
458   * @memberOf _
459   * @since 2.3.0
460   * @category Util
461   * @example
462   *
463   * _.times(2, _.noop);
464   * // => [undefined, undefined]
465   */
466  function noop() {
467    // No operation performed.
468  }
469  
470  function once(fn) {
471      return function () {
472          if (fn === null) return;
473          var callFn = fn;
474          fn = null;
475          callFn.apply(this, arguments);
476      };
477  }
478  
479  var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator;
480  
481  var getIterator = function (coll) {
482      return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol]();
483  };
484  
485  /**
486   * The base implementation of `_.times` without support for iteratee shorthands
487   * or max array length checks.
488   *
489   * @private
490   * @param {number} n The number of times to invoke `iteratee`.
491   * @param {Function} iteratee The function invoked per iteration.
492   * @returns {Array} Returns the array of results.
493   */
494  function baseTimes(n, iteratee) {
495    var index = -1,
496        result = Array(n);
497  
498    while (++index < n) {
499      result[index] = iteratee(index);
500    }
501    return result;
502  }
503  
504  /**
505   * Checks if `value` is object-like. A value is object-like if it's not `null`
506   * and has a `typeof` result of "object".
507   *
508   * @static
509   * @memberOf _
510   * @since 4.0.0
511   * @category Lang
512   * @param {*} value The value to check.
513   * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
514   * @example
515   *
516   * _.isObjectLike({});
517   * // => true
518   *
519   * _.isObjectLike([1, 2, 3]);
520   * // => true
521   *
522   * _.isObjectLike(_.noop);
523   * // => false
524   *
525   * _.isObjectLike(null);
526   * // => false
527   */
528  function isObjectLike(value) {
529    return value != null && typeof value == 'object';
530  }
531  
532  /** `Object#toString` result references. */
533  var argsTag = '[object Arguments]';
534  
535  /**
536   * The base implementation of `_.isArguments`.
537   *
538   * @private
539   * @param {*} value The value to check.
540   * @returns {boolean} Returns `true` if `value` is an `arguments` object,
541   */
542  function baseIsArguments(value) {
543    return isObjectLike(value) && baseGetTag(value) == argsTag;
544  }
545  
546  /** Used for built-in method references. */
547  var objectProto$3 = Object.prototype;
548  
549  /** Used to check objects for own properties. */
550  var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
551  
552  /** Built-in value references. */
553  var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
554  
555  /**
556   * Checks if `value` is likely an `arguments` object.
557   *
558   * @static
559   * @memberOf _
560   * @since 0.1.0
561   * @category Lang
562   * @param {*} value The value to check.
563   * @returns {boolean} Returns `true` if `value` is an `arguments` object,
564   *  else `false`.
565   * @example
566   *
567   * _.isArguments(function() { return arguments; }());
568   * // => true
569   *
570   * _.isArguments([1, 2, 3]);
571   * // => false
572   */
573  var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
574    return isObjectLike(value) && hasOwnProperty$2.call(value, 'callee') &&
575      !propertyIsEnumerable.call(value, 'callee');
576  };
577  
578  /**
579   * Checks if `value` is classified as an `Array` object.
580   *
581   * @static
582   * @memberOf _
583   * @since 0.1.0
584   * @category Lang
585   * @param {*} value The value to check.
586   * @returns {boolean} Returns `true` if `value` is an array, else `false`.
587   * @example
588   *
589   * _.isArray([1, 2, 3]);
590   * // => true
591   *
592   * _.isArray(document.body.children);
593   * // => false
594   *
595   * _.isArray('abc');
596   * // => false
597   *
598   * _.isArray(_.noop);
599   * // => false
600   */
601  var isArray = Array.isArray;
602  
603  /**
604   * This method returns `false`.
605   *
606   * @static
607   * @memberOf _
608   * @since 4.13.0
609   * @category Util
610   * @returns {boolean} Returns `false`.
611   * @example
612   *
613   * _.times(2, _.stubFalse);
614   * // => [false, false]
615   */
616  function stubFalse() {
617    return false;
618  }
619  
620  /** Detect free variable `exports`. */
621  var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
622  
623  /** Detect free variable `module`. */
624  var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
625  
626  /** Detect the popular CommonJS extension `module.exports`. */
627  var moduleExports = freeModule && freeModule.exports === freeExports;
628  
629  /** Built-in value references. */
630  var Buffer = moduleExports ? root.Buffer : undefined;
631  
632  /* Built-in method references for those with the same name as other `lodash` methods. */
633  var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
634  
635  /**
636   * Checks if `value` is a buffer.
637   *
638   * @static
639   * @memberOf _
640   * @since 4.3.0
641   * @category Lang
642   * @param {*} value The value to check.
643   * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
644   * @example
645   *
646   * _.isBuffer(new Buffer(2));
647   * // => true
648   *
649   * _.isBuffer(new Uint8Array(2));
650   * // => false
651   */
652  var isBuffer = nativeIsBuffer || stubFalse;
653  
654  /** Used as references for various `Number` constants. */
655  var MAX_SAFE_INTEGER$1 = 9007199254740991;
656  
657  /** Used to detect unsigned integer values. */
658  var reIsUint = /^(?:0|[1-9]\d*)$/;
659  
660  /**
661   * Checks if `value` is a valid array-like index.
662   *
663   * @private
664   * @param {*} value The value to check.
665   * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
666   * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
667   */
668  function isIndex(value, length) {
669    length = length == null ? MAX_SAFE_INTEGER$1 : length;
670    return !!length &&
671      (typeof value == 'number' || reIsUint.test(value)) &&
672      (value > -1 && value % 1 == 0 && value < length);
673  }
674  
675  /** `Object#toString` result references. */
676  var argsTag$1 = '[object Arguments]';
677  var arrayTag = '[object Array]';
678  var boolTag = '[object Boolean]';
679  var dateTag = '[object Date]';
680  var errorTag = '[object Error]';
681  var funcTag$1 = '[object Function]';
682  var mapTag = '[object Map]';
683  var numberTag = '[object Number]';
684  var objectTag = '[object Object]';
685  var regexpTag = '[object RegExp]';
686  var setTag = '[object Set]';
687  var stringTag = '[object String]';
688  var weakMapTag = '[object WeakMap]';
689  
690  var arrayBufferTag = '[object ArrayBuffer]';
691  var dataViewTag = '[object DataView]';
692  var float32Tag = '[object Float32Array]';
vendor: 24,130 bytes, lines 693-1409
693  var float64Tag = '[object Float64Array]';
694  var int8Tag = '[object Int8Array]';
695  var int16Tag = '[object Int16Array]';
696  var int32Tag = '[object Int32Array]';
697  var uint8Tag = '[object Uint8Array]';
698  var uint8ClampedTag = '[object Uint8ClampedArray]';
699  var uint16Tag = '[object Uint16Array]';
700  var uint32Tag = '[object Uint32Array]';
701  
702  /** Used to identify `toStringTag` values of typed arrays. */
703  var typedArrayTags = {};
704  typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
705  typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
706  typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
707  typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
708  typedArrayTags[uint32Tag] = true;
709  typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] =
710  typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
711  typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
712  typedArrayTags[errorTag] = typedArrayTags[funcTag$1] =
713  typedArrayTags[mapTag] = typedArrayTags[numberTag] =
714  typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
715  typedArrayTags[setTag] = typedArrayTags[stringTag] =
716  typedArrayTags[weakMapTag] = false;
717  
718  /**
719   * The base implementation of `_.isTypedArray` without Node.js optimizations.
720   *
721   * @private
722   * @param {*} value The value to check.
723   * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
724   */
725  function baseIsTypedArray(value) {
726    return isObjectLike(value) &&
727      isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
728  }
729  
730  /**
731   * The base implementation of `_.unary` without support for storing metadata.
732   *
733   * @private
734   * @param {Function} func The function to cap arguments for.
735   * @returns {Function} Returns the new capped function.
736   */
737  function baseUnary(func) {
738    return function(value) {
739      return func(value);
740    };
741  }
742  
743  /** Detect free variable `exports`. */
744  var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports;
745  
746  /** Detect free variable `module`. */
747  var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module;
748  
749  /** Detect the popular CommonJS extension `module.exports`. */
750  var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1;
751  
752  /** Detect free variable `process` from Node.js. */
753  var freeProcess = moduleExports$1 && freeGlobal.process;
754  
755  /** Used to access faster Node.js helpers. */
756  var nodeUtil = (function() {
757    try {
758      return freeProcess && freeProcess.binding && freeProcess.binding('util');
759    } catch (e) {}
760  }());
761  
762  /* Node.js helper references. */
763  var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
764  
765  /**
766   * Checks if `value` is classified as a typed array.
767   *
768   * @static
769   * @memberOf _
770   * @since 3.0.0
771   * @category Lang
772   * @param {*} value The value to check.
773   * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
774   * @example
775   *
776   * _.isTypedArray(new Uint8Array);
777   * // => true
778   *
779   * _.isTypedArray([]);
780   * // => false
781   */
782  var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
783  
784  /** Used for built-in method references. */
785  var objectProto$2 = Object.prototype;
786  
787  /** Used to check objects for own properties. */
788  var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
789  
790  /**
791   * Creates an array of the enumerable property names of the array-like `value`.
792   *
793   * @private
794   * @param {*} value The value to query.
795   * @param {boolean} inherited Specify returning inherited property names.
796   * @returns {Array} Returns the array of property names.
797   */
798  function arrayLikeKeys(value, inherited) {
799    var isArr = isArray(value),
800        isArg = !isArr && isArguments(value),
801        isBuff = !isArr && !isArg && isBuffer(value),
802        isType = !isArr && !isArg && !isBuff && isTypedArray(value),
803        skipIndexes = isArr || isArg || isBuff || isType,
804        result = skipIndexes ? baseTimes(value.length, String) : [],
805        length = result.length;
806  
807    for (var key in value) {
808      if ((inherited || hasOwnProperty$1.call(value, key)) &&
809          !(skipIndexes && (
810             // Safari 9 has enumerable `arguments.length` in strict mode.
811             key == 'length' ||
812             // Node.js 0.10 has enumerable non-index properties on buffers.
813             (isBuff && (key == 'offset' || key == 'parent')) ||
814             // PhantomJS 2 has enumerable non-index properties on typed arrays.
815             (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
816             // Skip index properties.
817             isIndex(key, length)
818          ))) {
819        result.push(key);
820      }
821    }
822    return result;
823  }
824  
825  /** Used for built-in method references. */
826  var objectProto$5 = Object.prototype;
827  
828  /**
829   * Checks if `value` is likely a prototype object.
830   *
831   * @private
832   * @param {*} value The value to check.
833   * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
834   */
835  function isPrototype(value) {
836    var Ctor = value && value.constructor,
837        proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5;
838  
839    return value === proto;
840  }
841  
842  /**
843   * Creates a unary function that invokes `func` with its argument transformed.
844   *
845   * @private
846   * @param {Function} func The function to wrap.
847   * @param {Function} transform The argument transform.
848   * @returns {Function} Returns the new function.
849   */
850  function overArg(func, transform) {
851    return function(arg) {
852      return func(transform(arg));
853    };
854  }
855  
856  /* Built-in method references for those with the same name as other `lodash` methods. */
857  var nativeKeys = overArg(Object.keys, Object);
858  
859  /** Used for built-in method references. */
860  var objectProto$4 = Object.prototype;
861  
862  /** Used to check objects for own properties. */
863  var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
864  
865  /**
866   * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
867   *
868   * @private
869   * @param {Object} object The object to query.
870   * @returns {Array} Returns the array of property names.
871   */
872  function baseKeys(object) {
873    if (!isPrototype(object)) {
874      return nativeKeys(object);
875    }
876    var result = [];
877    for (var key in Object(object)) {
878      if (hasOwnProperty$3.call(object, key) && key != 'constructor') {
879        result.push(key);
880      }
881    }
882    return result;
883  }
884  
885  /**
886   * Creates an array of the own enumerable property names of `object`.
887   *
888   * **Note:** Non-object values are coerced to objects. See the
889   * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
890   * for more details.
891   *
892   * @static
893   * @since 0.1.0
894   * @memberOf _
895   * @category Object
896   * @param {Object} object The object to query.
897   * @returns {Array} Returns the array of property names.
898   * @example
899   *
900   * function Foo() {
901   *   this.a = 1;
902   *   this.b = 2;
903   * }
904   *
905   * Foo.prototype.c = 3;
906   *
907   * _.keys(new Foo);
908   * // => ['a', 'b'] (iteration order is not guaranteed)
909   *
910   * _.keys('hi');
911   * // => ['0', '1']
912   */
913  function keys(object) {
914    return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
915  }
916  
917  function createArrayIterator(coll) {
918      var i = -1;
919      var len = coll.length;
920      return function next() {
921          return ++i < len ? {value: coll[i], key: i} : null;
922      }
923  }
924  
925  function createES2015Iterator(iterator) {
926      var i = -1;
927      return function next() {
928          var item = iterator.next();
929          if (item.done)
930              return null;
931          i++;
932          return {value: item.value, key: i};
933      }
934  }
935  
936  function createObjectIterator(obj) {
937      var okeys = keys(obj);
938      var i = -1;
939      var len = okeys.length;
940      return function next() {
941          var key = okeys[++i];
942          return i < len ? {value: obj[key], key: key} : null;
943      };
944  }
945  
946  function iterator(coll) {
947      if (isArrayLike(coll)) {
948          return createArrayIterator(coll);
949      }
950  
951      var iterator = getIterator(coll);
952      return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
953  }
954  
955  function onlyOnce(fn) {
956      return function() {
957          if (fn === null) throw new Error("Callback was already called.");
958          var callFn = fn;
959          fn = null;
960          callFn.apply(this, arguments);
961      };
962  }
963  
964  function _eachOfLimit(limit) {
965      return function (obj, iteratee, callback) {
966          callback = once(callback || noop);
967          if (limit <= 0 || !obj) {
968              return callback(null);
969          }
970          var nextElem = iterator(obj);
971          var done = false;
972          var running = 0;
973  
974          function iterateeCallback(err, value) {
975              running -= 1;
976              if (err) {
977                  done = true;
978                  callback(err);
979              }
980              else if (value === breakLoop || (done && running <= 0)) {
981                  done = true;
982                  return callback(null);
983              }
984              else {
985                  replenish();
986              }
987          }
988  
989          function replenish () {
990              while (running < limit && !done) {
991                  var elem = nextElem();
992                  if (elem === null) {
993                      done = true;
994                      if (running <= 0) {
995                          callback(null);
996                      }
997                      return;
998                  }
999                  running += 1;
1000                  iteratee(elem.value, elem.key, onlyOnce(iterateeCallback));
1001              }
1002          }
1003  
1004          replenish();
1005      };
1006  }
1007  
1008  /**
1009   * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
1010   * time.
1011   *
1012   * @name eachOfLimit
1013   * @static
1014   * @memberOf module:Collections
1015   * @method
1016   * @see [async.eachOf]{@link module:Collections.eachOf}
1017   * @alias forEachOfLimit
1018   * @category Collection
1019   * @param {Array|Iterable|Object} coll - A collection to iterate over.
1020   * @param {number} limit - The maximum number of async operations at a time.
1021   * @param {AsyncFunction} iteratee - An async function to apply to each
1022   * item in `coll`. The `key` is the item's key, or index in the case of an
1023   * array.
1024   * Invoked with (item, key, callback).
1025   * @param {Function} [callback] - A callback which is called when all
1026   * `iteratee` functions have finished, or an error occurs. Invoked with (err).
1027   */
1028  function eachOfLimit(coll, limit, iteratee, callback) {
1029      _eachOfLimit(limit)(coll, wrapAsync(iteratee), callback);
1030  }
1031  
1032  function doLimit(fn, limit) {
1033      return function (iterable, iteratee, callback) {
1034          return fn(iterable, limit, iteratee, callback);
1035      };
1036  }
1037  
1038  // eachOf implementation optimized for array-likes
1039  function eachOfArrayLike(coll, iteratee, callback) {
1040      callback = once(callback || noop);
1041      var index = 0,
1042          completed = 0,
1043          length = coll.length;
1044      if (length === 0) {
1045          callback(null);
1046      }
1047  
1048      function iteratorCallback(err, value) {
1049          if (err) {
1050              callback(err);
1051          } else if ((++completed === length) || value === breakLoop) {
1052              callback(null);
1053          }
1054      }
1055  
1056      for (; index < length; index++) {
1057          iteratee(coll[index], index, onlyOnce(iteratorCallback));
1058      }
1059  }
1060  
1061  // a generic version of eachOf which can handle array, object, and iterator cases.
1062  var eachOfGeneric = doLimit(eachOfLimit, Infinity);
1063  
1064  /**
1065   * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
1066   * to the iteratee.
1067   *
1068   * @name eachOf
1069   * @static
1070   * @memberOf module:Collections
1071   * @method
1072   * @alias forEachOf
1073   * @category Collection
1074   * @see [async.each]{@link module:Collections.each}
1075   * @param {Array|Iterable|Object} coll - A collection to iterate over.
1076   * @param {AsyncFunction} iteratee - A function to apply to each
1077   * item in `coll`.
1078   * The `key` is the item's key, or index in the case of an array.
1079   * Invoked with (item, key, callback).
1080   * @param {Function} [callback] - A callback which is called when all
1081   * `iteratee` functions have finished, or an error occurs. Invoked with (err).
1082   * @example
1083   *
1084   * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
1085   * var configs = {};
1086   *
1087   * async.forEachOf(obj, function (value, key, callback) {
1088   *     fs.readFile(__dirname + value, "utf8", function (err, data) {
1089   *         if (err) return callback(err);
1090   *         try {
1091   *             configs[key] = JSON.parse(data);
1092   *         } catch (e) {
1093   *             return callback(e);
1094   *         }
1095   *         callback();
1096   *     });
1097   * }, function (err) {
1098   *     if (err) console.error(err.message);
1099   *     // configs is now a map of JSON data
1100   *     doSomethingWith(configs);
1101   * });
1102   */
1103  var eachOf = function(coll, iteratee, callback) {
1104      var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
1105      eachOfImplementation(coll, wrapAsync(iteratee), callback);
1106  };
1107  
1108  function doParallel(fn) {
1109      return function (obj, iteratee, callback) {
1110          return fn(eachOf, obj, wrapAsync(iteratee), callback);
1111      };
1112  }
1113  
1114  function _asyncMap(eachfn, arr, iteratee, callback) {
1115      callback = callback || noop;
1116      arr = arr || [];
1117      var results = [];
1118      var counter = 0;
1119      var _iteratee = wrapAsync(iteratee);
1120  
1121      eachfn(arr, function (value, _, callback) {
1122          var index = counter++;
1123          _iteratee(value, function (err, v) {
1124              results[index] = v;
1125              callback(err);
1126          });
1127      }, function (err) {
1128          callback(err, results);
1129      });
1130  }
1131  
1132  /**
1133   * Produces a new collection of values by mapping each value in `coll` through
1134   * the `iteratee` function. The `iteratee` is called with an item from `coll`
1135   * and a callback for when it has finished processing. Each of these callback
1136   * takes 2 arguments: an `error`, and the transformed item from `coll`. If
1137   * `iteratee` passes an error to its callback, the main `callback` (for the
1138   * `map` function) is immediately called with the error.
1139   *
1140   * Note, that since this function applies the `iteratee` to each item in
1141   * parallel, there is no guarantee that the `iteratee` functions will complete
1142   * in order. However, the results array will be in the same order as the
1143   * original `coll`.
1144   *
1145   * If `map` is passed an Object, the results will be an Array.  The results
1146   * will roughly be in the order of the original Objects' keys (but this can
1147   * vary across JavaScript engines).
1148   *
1149   * @name map
1150   * @static
1151   * @memberOf module:Collections
1152   * @method
1153   * @category Collection
1154   * @param {Array|Iterable|Object} coll - A collection to iterate over.
1155   * @param {AsyncFunction} iteratee - An async function to apply to each item in
1156   * `coll`.
1157   * The iteratee should complete with the transformed item.
1158   * Invoked with (item, callback).
1159   * @param {Function} [callback] - A callback which is called when all `iteratee`
1160   * functions have finished, or an error occurs. Results is an Array of the
1161   * transformed items from the `coll`. Invoked with (err, results).
1162   * @example
1163   *
1164   * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
1165   *     // results is now an array of stats for each file
1166   * });
1167   */
1168  var map = doParallel(_asyncMap);
1169  
1170  /**
1171   * Applies the provided arguments to each function in the array, calling
1172   * `callback` after all functions have completed. If you only provide the first
1173   * argument, `fns`, then it will return a function which lets you pass in the
1174   * arguments as if it were a single function call. If more arguments are
1175   * provided, `callback` is required while `args` is still optional.
1176   *
1177   * @name applyEach
1178   * @static
1179   * @memberOf module:ControlFlow
1180   * @method
1181   * @category Control Flow
1182   * @param {Array|Iterable|Object} fns - A collection of {@link AsyncFunction}s
1183   * to all call with the same arguments
1184   * @param {...*} [args] - any number of separate arguments to pass to the
1185   * function.
1186   * @param {Function} [callback] - the final argument should be the callback,
1187   * called when all functions have completed processing.
1188   * @returns {Function} - If only the first argument, `fns`, is provided, it will
1189   * return a function which lets you pass in the arguments as if it were a single
1190   * function call. The signature is `(..args, callback)`. If invoked with any
1191   * arguments, `callback` is required.
1192   * @example
1193   *
1194   * async.applyEach([enableSearch, updateSchema], 'bucket', callback);
1195   *
1196   * // partial application example:
1197   * async.each(
1198   *     buckets,
1199   *     async.applyEach([enableSearch, updateSchema]),
1200   *     callback
1201   * );
1202   */
1203  var applyEach = applyEach$1(map);
1204  
1205  function doParallelLimit(fn) {
1206      return function (obj, limit, iteratee, callback) {
1207          return fn(_eachOfLimit(limit), obj, wrapAsync(iteratee), callback);
1208      };
1209  }
1210  
1211  /**
1212   * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
1213   *
1214   * @name mapLimit
1215   * @static
1216   * @memberOf module:Collections
1217   * @method
1218   * @see [async.map]{@link module:Collections.map}
1219   * @category Collection
1220   * @param {Array|Iterable|Object} coll - A collection to iterate over.
1221   * @param {number} limit - The maximum number of async operations at a time.
1222   * @param {AsyncFunction} iteratee - An async function to apply to each item in
1223   * `coll`.
1224   * The iteratee should complete with the transformed item.
1225   * Invoked with (item, callback).
1226   * @param {Function} [callback] - A callback which is called when all `iteratee`
1227   * functions have finished, or an error occurs. Results is an array of the
1228   * transformed items from the `coll`. Invoked with (err, results).
1229   */
1230  var mapLimit = doParallelLimit(_asyncMap);
1231  
1232  /**
1233   * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time.
1234   *
1235   * @name mapSeries
1236   * @static
1237   * @memberOf module:Collections
1238   * @method
1239   * @see [async.map]{@link module:Collections.map}
1240   * @category Collection
1241   * @param {Array|Iterable|Object} coll - A collection to iterate over.
1242   * @param {AsyncFunction} iteratee - An async function to apply to each item in
1243   * `coll`.
1244   * The iteratee should complete with the transformed item.
1245   * Invoked with (item, callback).
1246   * @param {Function} [callback] - A callback which is called when all `iteratee`
1247   * functions have finished, or an error occurs. Results is an array of the
1248   * transformed items from the `coll`. Invoked with (err, results).
1249   */
1250  var mapSeries = doLimit(mapLimit, 1);
1251  
1252  /**
1253   * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time.
1254   *
1255   * @name applyEachSeries
1256   * @static
1257   * @memberOf module:ControlFlow
1258   * @method
1259   * @see [async.applyEach]{@link module:ControlFlow.applyEach}
1260   * @category Control Flow
1261   * @param {Array|Iterable|Object} fns - A collection of {@link AsyncFunction}s to all
1262   * call with the same arguments
1263   * @param {...*} [args] - any number of separate arguments to pass to the
1264   * function.
1265   * @param {Function} [callback] - the final argument should be the callback,
1266   * called when all functions have completed processing.
1267   * @returns {Function} - If only the first argument is provided, it will return
1268   * a function which lets you pass in the arguments as if it were a single
1269   * function call.
1270   */
1271  var applyEachSeries = applyEach$1(mapSeries);
1272  
1273  /**
1274   * A specialized version of `_.forEach` for arrays without support for
1275   * iteratee shorthands.
1276   *
1277   * @private
1278   * @param {Array} [array] The array to iterate over.
1279   * @param {Function} iteratee The function invoked per iteration.
1280   * @returns {Array} Returns `array`.
1281   */
1282  function arrayEach(array, iteratee) {
1283    var index = -1,
1284        length = array == null ? 0 : array.length;
1285  
1286    while (++index < length) {
1287      if (iteratee(array[index], index, array) === false) {
1288        break;
1289      }
1290    }
1291    return array;
1292  }
1293  
1294  /**
1295   * Creates a base function for methods like `_.forIn` and `_.forOwn`.
1296   *
1297   * @private
1298   * @param {boolean} [fromRight] Specify iterating from right to left.
1299   * @returns {Function} Returns the new base function.
1300   */
1301  function createBaseFor(fromRight) {
1302    return function(object, iteratee, keysFunc) {
1303      var index = -1,
1304          iterable = Object(object),
1305          props = keysFunc(object),
1306          length = props.length;
1307  
1308      while (length--) {
1309        var key = props[fromRight ? length : ++index];
1310        if (iteratee(iterable[key], key, iterable) === false) {
1311          break;
1312        }
1313      }
1314      return object;
1315    };
1316  }
1317  
1318  /**
1319   * The base implementation of `baseForOwn` which iterates over `object`
1320   * properties returned by `keysFunc` and invokes `iteratee` for each property.
1321   * Iteratee functions may exit iteration early by explicitly returning `false`.
1322   *
1323   * @private
1324   * @param {Object} object The object to iterate over.
1325   * @param {Function} iteratee The function invoked per iteration.
1326   * @param {Function} keysFunc The function to get the keys of `object`.
1327   * @returns {Object} Returns `object`.
1328   */
1329  var baseFor = createBaseFor();
1330  
1331  /**
1332   * The base implementation of `_.forOwn` without support for iteratee shorthands.
1333   *
1334   * @private
1335   * @param {Object} object The object to iterate over.
1336   * @param {Function} iteratee The function invoked per iteration.
1337   * @returns {Object} Returns `object`.
1338   */
1339  function baseForOwn(object, iteratee) {
1340    return object && baseFor(object, iteratee, keys);
1341  }
1342  
1343  /**
1344   * The base implementation of `_.findIndex` and `_.findLastIndex` without
1345   * support for iteratee shorthands.
1346   *
1347   * @private
1348   * @param {Array} array The array to inspect.
1349   * @param {Function} predicate The function invoked per iteration.
1350   * @param {number} fromIndex The index to search from.
1351   * @param {boolean} [fromRight] Specify iterating from right to left.
1352   * @returns {number} Returns the index of the matched value, else `-1`.
1353   */
1354  function baseFindIndex(array, predicate, fromIndex, fromRight) {
1355    var length = array.length,
1356        index = fromIndex + (fromRight ? 1 : -1);
1357  
1358    while ((fromRight ? index-- : ++index < length)) {
1359      if (predicate(array[index], index, array)) {
1360        return index;
1361      }
1362    }
1363    return -1;
1364  }
1365  
1366  /**
1367   * The base implementation of `_.isNaN` without support for number objects.
1368   *
1369   * @private
1370   * @param {*} value The value to check.
1371   * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
1372   */
1373  function baseIsNaN(value) {
1374    return value !== value;
1375  }
1376  
1377  /**
1378   * A specialized version of `_.indexOf` which performs strict equality
1379   * comparisons of values, i.e. `===`.
1380   *
1381   * @private
1382   * @param {Array} array The array to inspect.
1383   * @param {*} value The value to search for.
1384   * @param {number} fromIndex The index to search from.
1385   * @returns {number} Returns the index of the matched value, else `-1`.
1386   */
1387  function strictIndexOf(array, value, fromIndex) {
1388    var index = fromIndex - 1,
1389        length = array.length;
1390  
1391    while (++index < length) {
1392      if (array[index] === value) {
1393        return index;
1394      }
1395    }
1396    return -1;
1397  }
1398  
1399  /**
1400   * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
1401   *
1402   * @private
1403   * @param {Array} array The array to inspect.
1404   * @param {*} value The value to search for.
1405   * @param {number} fromIndex The index to search from.
1406   * @returns {number} Returns the index of the matched value, else `-1`.
1407   */
1408  function baseIndexOf(array, value, fromIndex) {
1409    return value === value
1410      ? strictIndexOf(array, value, fromIndex)
1411      : baseFindIndex(array, baseIsNaN, fromIndex);
1412  }
1413  
1414  /**
1415   * Determines the best order for running the {@link AsyncFunction}s in `tasks`, based on
1416   * their requirements. Each function can optionally depend on other functions
1417   * being completed first, and each function is run as soon as its requirements
1418   * are satisfied.
1419   *
1420   * If any of the {@link AsyncFunction}s pass an error to their callback, the `auto` sequence
1421   * will stop. Further tasks will not execute (so any other functions depending
1422   * on it will not run), and the main `callback` is immediately called with the
1423   * error.
1424   *
1425   * {@link AsyncFunction}s also receive an object containing the results of functions which
1426   * have completed so far as the first argument, if they have dependencies. If a
1427   * task function has no dependencies, it will only be passed a callback.
1428   *
1429   * @name auto
1430   * @static
1431   * @memberOf module:ControlFlow
1432   * @method
1433   * @category Control Flow
1434   * @param {Object} tasks - An object. Each of its properties is either a
1435   * function or an array of requirements, with the {@link AsyncFunction} itself the last item
1436   * in the array. The object's key of a property serves as the name of the task
1437   * defined by that property, i.e. can be used when specifying requirements for
1438   * other tasks. The function receives one or two arguments:
1439   * * a `results` object, containing the results of the previously executed
1440   *   functions, only passed if the task has any dependencies,
1441   * * a `callback(err, result)` function, which must be called when finished,
1442   *   passing an `error` (which can be `null`) and the result of the function's
1443   *   execution.
1444   * @param {number} [concurrency=Infinity] - An optional `integer` for
1445   * determining the maximum number of tasks that can be run in parallel. By
1446   * default, as many as possible.
1447   * @param {Function} [callback] - An optional callback which is called when all
1448   * the tasks have been completed. It receives the `err` argument if any `tasks`
1449   * pass an error to their callback. Results are always returned; however, if an
1450   * error occurs, no further `tasks` will be performed, and the results object
1451   * will only contain partial results. Invoked with (err, results).
1452   * @returns undefined
1453   * @example
1454   *
1455   * async.auto({
1456   *     // this function will just be passed a callback
1457   *     readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
1458   *     showData: ['readData', function(results, cb) {
1459   *         // results.readData is the file's contents
1460   *         // ...
1461   *     }]
1462   * }, callback);
1463   *
1464   * async.auto({
1465   *     get_data: function(callback) {
1466   *         console.log('in get_data');
1467   *         // async code to get some data
1468   *         callback(null, 'data', 'converted to array');
1469   *     },
1470   *     make_folder: function(callback) {
1471   *         console.log('in make_folder');
1472   *         // async code to create a directory to store a file in
1473   *         // this is run at the same time as getting the data
1474   *         callback(null, 'folder');
1475   *     },
1476   *     write_file: ['get_data', 'make_folder', function(results, callback) {
1477   *         console.log('in write_file', JSON.stringify(results));
1478   *         // once there is some data and the directory exists,
1479   *         // write the data to a file in the directory
1480   *         callback(null, 'filename');
1481   *     }],
1482   *     email_link: ['write_file', function(results, callback) {
1483   *         console.log('in email_link', JSON.stringify(results));
1484   *         // once the file is written let's email a link to it...
1485   *         // results.write_file contains the filename returned by write_file.
1486   *         callback(null, {'file':results.write_file, 'email':'[email protected]'});
1487   *     }]
1488   * }, function(err, results) {
1489   *     console.log('err = ', err);
1490   *     console.log('results = ', results);
1491   * });
1492   */
1493  var auto = function (tasks, concurrency, callback) {
1494      if (typeof concurrency === 'function') {
1495          // concurrency is optional, shift the args.
1496          callback = concurrency;
1497          concurrency = null;
1498      }
1499      callback = once(callback || noop);
1500      var keys$$1 = keys(tasks);
1501      var numTasks = keys$$1.length;
1502      if (!numTasks) {
1503          return callback(null);
1504      }
1505      if (!concurrency) {
1506          concurrency = numTasks;
1507      }
1508  
1509      var results = {};
1510      var runningTasks = 0;
1511      var hasError = false;
vendor: 4,883 bytes, lines 1512-1667
1512  
1513      var listeners = Object.create(null);
1514  
1515      var readyTasks = [];
1516  
1517      // for cycle detection:
1518      var readyToCheck = []; // tasks that have been identified as reachable
1519      // without the possibility of returning to an ancestor task
1520      var uncheckedDependencies = {};
1521  
1522      baseForOwn(tasks, function (task, key) {
1523          if (!isArray(task)) {
1524              // no dependencies
1525              enqueueTask(key, [task]);
1526              readyToCheck.push(key);
1527              return;
1528          }
1529  
1530          var dependencies = task.slice(0, task.length - 1);
1531          var remainingDependencies = dependencies.length;
1532          if (remainingDependencies === 0) {
1533              enqueueTask(key, task);
1534              readyToCheck.push(key);
1535              return;
1536          }
1537          uncheckedDependencies[key] = remainingDependencies;
1538  
1539          arrayEach(dependencies, function (dependencyName) {
1540              if (!tasks[dependencyName]) {
1541                  throw new Error('async.auto task `' + key +
1542                      '` has a non-existent dependency `' +
1543                      dependencyName + '` in ' +
1544                      dependencies.join(', '));
1545              }
1546              addListener(dependencyName, function () {
1547                  remainingDependencies--;
1548                  if (remainingDependencies === 0) {
1549                      enqueueTask(key, task);
1550                  }
1551              });
1552          });
1553      });
1554  
1555      checkForDeadlocks();
1556      processQueue();
1557  
1558      function enqueueTask(key, task) {
1559          readyTasks.push(function () {
1560              runTask(key, task);
1561          });
1562      }
1563  
1564      function processQueue() {
1565          if (readyTasks.length === 0 && runningTasks === 0) {
1566              return callback(null, results);
1567          }
1568          while(readyTasks.length && runningTasks < concurrency) {
1569              var run = readyTasks.shift();
1570              run();
1571          }
1572  
1573      }
1574  
1575      function addListener(taskName, fn) {
1576          var taskListeners = listeners[taskName];
1577          if (!taskListeners) {
1578              taskListeners = listeners[taskName] = [];
1579          }
1580  
1581          taskListeners.push(fn);
1582      }
1583  
1584      function taskComplete(taskName) {
1585          var taskListeners = listeners[taskName] || [];
1586          arrayEach(taskListeners, function (fn) {
1587              fn();
1588          });
1589          processQueue();
1590      }
1591  
1592  
1593      function runTask(key, task) {
1594          if (hasError) return;
1595  
1596          var taskCallback = onlyOnce(function(err, result) {
1597              runningTasks--;
1598              if (arguments.length > 2) {
1599                  result = slice(arguments, 1);
1600              }
1601              if (err) {
1602                  var safeResults = {};
1603                  baseForOwn(results, function(val, rkey) {
1604                      safeResults[rkey] = val;
1605                  });
1606                  safeResults[key] = result;
1607                  hasError = true;
1608                  listeners = Object.create(null);
1609  
1610                  callback(err, safeResults);
1611              } else {
1612                  results[key] = result;
1613                  taskComplete(key);
1614              }
1615          });
1616  
1617          runningTasks++;
1618          var taskFn = wrapAsync(task[task.length - 1]);
1619          if (task.length > 1) {
1620              taskFn(results, taskCallback);
1621          } else {
1622              taskFn(taskCallback);
1623          }
1624      }
1625  
1626      function checkForDeadlocks() {
1627          // Kahn's algorithm
1628          // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
1629          // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
1630          var currentTask;
1631          var counter = 0;
1632          while (readyToCheck.length) {
1633              currentTask = readyToCheck.pop();
1634              counter++;
1635              arrayEach(getDependents(currentTask), function (dependent) {
1636                  if (--uncheckedDependencies[dependent] === 0) {
1637                      readyToCheck.push(dependent);
1638                  }
1639              });
1640          }
1641  
1642          if (counter !== numTasks) {
1643              throw new Error(
1644                  'async.auto cannot execute tasks due to a recursive dependency'
1645              );
1646          }
1647      }
1648  
1649      function getDependents(taskName) {
1650          var result = [];
1651          baseForOwn(tasks, function (task, key) {
1652              if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) {
1653                  result.push(key);
1654              }
1655          });
1656          return result;
1657      }
1658  };
1659  
1660  /**
1661   * A specialized version of `_.map` for arrays without support for iteratee
1662   * shorthands.
1663   *
1664   * @private
1665   * @param {Array} [array] The array to iterate over.
1666   * @param {Function} iteratee The function invoked per iteration.
1667   * @returns {Array} Returns the new mapped array.
vendor: 4,302 bytes, lines 1668-1810
1668   */
1669  function arrayMap(array, iteratee) {
1670    var index = -1,
1671        length = array == null ? 0 : array.length,
1672        result = Array(length);
1673  
1674    while (++index < length) {
1675      result[index] = iteratee(array[index], index, array);
1676    }
1677    return result;
1678  }
1679  
1680  /** `Object#toString` result references. */
1681  var symbolTag = '[object Symbol]';
1682  
1683  /**
1684   * Checks if `value` is classified as a `Symbol` primitive or object.
1685   *
1686   * @static
1687   * @memberOf _
1688   * @since 4.0.0
1689   * @category Lang
1690   * @param {*} value The value to check.
1691   * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
1692   * @example
1693   *
1694   * _.isSymbol(Symbol.iterator);
1695   * // => true
1696   *
1697   * _.isSymbol('abc');
1698   * // => false
1699   */
1700  function isSymbol(value) {
1701    return typeof value == 'symbol' ||
1702      (isObjectLike(value) && baseGetTag(value) == symbolTag);
1703  }
1704  
1705  /** Used as references for various `Number` constants. */
1706  var INFINITY = 1 / 0;
1707  
1708  /** Used to convert symbols to primitives and strings. */
1709  var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined;
1710  var symbolToString = symbolProto ? symbolProto.toString : undefined;
1711  
1712  /**
1713   * The base implementation of `_.toString` which doesn't convert nullish
1714   * values to empty strings.
1715   *
1716   * @private
1717   * @param {*} value The value to process.
1718   * @returns {string} Returns the string.
1719   */
1720  function baseToString(value) {
1721    // Exit early for strings to avoid a performance hit in some environments.
1722    if (typeof value == 'string') {
1723      return value;
1724    }
1725    if (isArray(value)) {
1726      // Recursively convert values (susceptible to call stack limits).
1727      return arrayMap(value, baseToString) + '';
1728    }
1729    if (isSymbol(value)) {
1730      return symbolToString ? symbolToString.call(value) : '';
1731    }
1732    var result = (value + '');
1733    return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
1734  }
1735  
1736  /**
1737   * The base implementation of `_.slice` without an iteratee call guard.
1738   *
1739   * @private
1740   * @param {Array} array The array to slice.
1741   * @param {number} [start=0] The start position.
1742   * @param {number} [end=array.length] The end position.
1743   * @returns {Array} Returns the slice of `array`.
1744   */
1745  function baseSlice(array, start, end) {
1746    var index = -1,
1747        length = array.length;
1748  
1749    if (start < 0) {
1750      start = -start > length ? 0 : (length + start);
1751    }
1752    end = end > length ? length : end;
1753    if (end < 0) {
1754      end += length;
1755    }
1756    length = start > end ? 0 : ((end - start) >>> 0);
1757    start >>>= 0;
1758  
1759    var result = Array(length);
1760    while (++index < length) {
1761      result[index] = array[index + start];
1762    }
1763    return result;
1764  }
1765  
1766  /**
1767   * Casts `array` to a slice if it's needed.
1768   *
1769   * @private
1770   * @param {Array} array The array to inspect.
1771   * @param {number} start The start position.
1772   * @param {number} [end=array.length] The end position.
1773   * @returns {Array} Returns the cast slice.
1774   */
1775  function castSlice(array, start, end) {
1776    var length = array.length;
1777    end = end === undefined ? length : end;
1778    return (!start && end >= length) ? array : baseSlice(array, start, end);
1779  }
1780  
1781  /**
1782   * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1783   * that is not found in the character symbols.
1784   *
1785   * @private
1786   * @param {Array} strSymbols The string symbols to inspect.
1787   * @param {Array} chrSymbols The character symbols to find.
1788   * @returns {number} Returns the index of the last unmatched string symbol.
1789   */
1790  function charsEndIndex(strSymbols, chrSymbols) {
1791    var index = strSymbols.length;
1792  
1793    while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1794    return index;
1795  }
1796  
1797  /**
1798   * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1799   * that is not found in the character symbols.
1800   *
1801   * @private
1802   * @param {Array} strSymbols The string symbols to inspect.
1803   * @param {Array} chrSymbols The character symbols to find.
1804   * @returns {number} Returns the index of the first unmatched string symbol.
1805   */
1806  function charsStartIndex(strSymbols, chrSymbols) {
1807    var index = -1,
1808        length = strSymbols.length;
1809  
1810    while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0
vendor: 20,586 bytes, lines 1810-2395
1810) > -1) {}
1811    return index;
1812  }
1813  
1814  /**
1815   * Converts an ASCII `string` to an array.
1816   *
1817   * @private
1818   * @param {string} string The string to convert.
1819   * @returns {Array} Returns the converted array.
1820   */
1821  function asciiToArray(string) {
1822    return string.split('');
1823  }
1824  
1825  /** Used to compose unicode character classes. */
1826  var rsAstralRange = '\\ud800-\\udfff';
1827  var rsComboMarksRange = '\\u0300-\\u036f';
1828  var reComboHalfMarksRange = '\\ufe20-\\ufe2f';
1829  var rsComboSymbolsRange = '\\u20d0-\\u20ff';
1830  var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
1831  var rsVarRange = '\\ufe0e\\ufe0f';
1832  
1833  /** Used to compose unicode capture groups. */
1834  var rsZWJ = '\\u200d';
1835  
1836  /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
1837  var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange  + rsComboRange + rsVarRange + ']');
1838  
1839  /**
1840   * Checks if `string` contains Unicode symbols.
1841   *
1842   * @private
1843   * @param {string} string The string to inspect.
1844   * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1845   */
1846  function hasUnicode(string) {
1847    return reHasUnicode.test(string);
1848  }
1849  
1850  /** Used to compose unicode character classes. */
1851  var rsAstralRange$1 = '\\ud800-\\udfff';
1852  var rsComboMarksRange$1 = '\\u0300-\\u036f';
1853  var reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f';
1854  var rsComboSymbolsRange$1 = '\\u20d0-\\u20ff';
1855  var rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1;
1856  var rsVarRange$1 = '\\ufe0e\\ufe0f';
1857  
1858  /** Used to compose unicode capture groups. */
1859  var rsAstral = '[' + rsAstralRange$1 + ']';
1860  var rsCombo = '[' + rsComboRange$1 + ']';
1861  var rsFitz = '\\ud83c[\\udffb-\\udfff]';
1862  var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')';
1863  var rsNonAstral = '[^' + rsAstralRange$1 + ']';
1864  var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
1865  var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
1866  var rsZWJ$1 = '\\u200d';
1867  
1868  /** Used to compose unicode regexes. */
1869  var reOptMod = rsModifier + '?';
1870  var rsOptVar = '[' + rsVarRange$1 + ']?';
1871  var rsOptJoin = '(?:' + rsZWJ$1 + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*';
1872  var rsSeq = rsOptVar + reOptMod + rsOptJoin;
1873  var rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
1874  
1875  /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
1876  var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
1877  
1878  /**
1879   * Converts a Unicode `string` to an array.
1880   *
1881   * @private
1882   * @param {string} string The string to convert.
1883   * @returns {Array} Returns the converted array.
1884   */
1885  function unicodeToArray(string) {
1886    return string.match(reUnicode) || [];
1887  }
1888  
1889  /**
1890   * Converts `string` to an array.
1891   *
1892   * @private
1893   * @param {string} string The string to convert.
1894   * @returns {Array} Returns the converted array.
1895   */
1896  function stringToArray(string) {
1897    return hasUnicode(string)
1898      ? unicodeToArray(string)
1899      : asciiToArray(string);
1900  }
1901  
1902  /**
1903   * Converts `value` to a string. An empty string is returned for `null`
1904   * and `undefined` values. The sign of `-0` is preserved.
1905   *
1906   * @static
1907   * @memberOf _
1908   * @since 4.0.0
1909   * @category Lang
1910   * @param {*} value The value to convert.
1911   * @returns {string} Returns the converted string.
1912   * @example
1913   *
1914   * _.toString(null);
1915   * // => ''
1916   *
1917   * _.toString(-0);
1918   * // => '-0'
1919   *
1920   * _.toString([1, 2, 3]);
1921   * // => '1,2,3'
1922   */
1923  function toString(value) {
1924    return value == null ? '' : baseToString(value);
1925  }
1926  
1927  /** Used to match leading and trailing whitespace. */
1928  var reTrim = /^\s+|\s+$/g;
1929  
1930  /**
1931   * Removes leading and trailing whitespace or specified characters from `string`.
1932   *
1933   * @static
1934   * @memberOf _
1935   * @since 3.0.0
1936   * @category String
1937   * @param {string} [string=''] The string to trim.
1938   * @param {string} [chars=whitespace] The characters to trim.
1939   * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
1940   * @returns {string} Returns the trimmed string.
1941   * @example
1942   *
1943   * _.trim('  abc  ');
1944   * // => 'abc'
1945   *
1946   * _.trim('-_-abc-_-', '_-');
1947   * // => 'abc'
1948   *
1949   * _.map(['  foo  ', '  bar  '], _.trim);
1950   * // => ['foo', 'bar']
1951   */
1952  function trim(string, chars, guard) {
1953    string = toString(string);
1954    if (string && (guard || chars === undefined)) {
1955      return string.replace(reTrim, '');
1956    }
1957    if (!string || !(chars = baseToString(chars))) {
1958      return string;
1959    }
1960    var strSymbols = stringToArray(string),
1961        chrSymbols = stringToArray(chars),
1962        start = charsStartIndex(strSymbols, chrSymbols),
1963        end = charsEndIndex(strSymbols, chrSymbols) + 1;
1964  
1965    return castSlice(strSymbols, start, end).join('');
1966  }
1967  
1968  var FN_ARGS = /^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
1969  var FN_ARG_SPLIT = /,/;
1970  var FN_ARG = /(=.+)?(\s*)$/;
1971  var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
1972  
1973  function parseParams(func) {
1974      func = func.toString().replace(STRIP_COMMENTS, '');
1975      func = func.match(FN_ARGS)[2].replace(' ', '');
1976      func = func ? func.split(FN_ARG_SPLIT) : [];
1977      func = func.map(function (arg){
1978          return trim(arg.replace(FN_ARG, ''));
1979      });
1980      return func;
1981  }
1982  
1983  /**
1984   * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
1985   * tasks are specified as parameters to the function, after the usual callback
1986   * parameter, with the parameter names matching the names of the tasks it
1987   * depends on. This can provide even more readable task graphs which can be
1988   * easier to maintain.
1989   *
1990   * If a final callback is specified, the task results are similarly injected,
1991   * specified as named parameters after the initial error parameter.
1992   *
1993   * The autoInject function is purely syntactic sugar and its semantics are
1994   * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
1995   *
1996   * @name autoInject
1997   * @static
1998   * @memberOf module:ControlFlow
1999   * @method
2000   * @see [async.auto]{@link module:ControlFlow.auto}
2001   * @category Control Flow
2002   * @param {Object} tasks - An object, each of whose properties is an {@link AsyncFunction} of
2003   * the form 'func([dependencies...], callback). The object's key of a property
2004   * serves as the name of the task defined by that property, i.e. can be used
2005   * when specifying requirements for other tasks.
2006   * * The `callback` parameter is a `callback(err, result)` which must be called
2007   *   when finished, passing an `error` (which can be `null`) and the result of
2008   *   the function's execution. The remaining parameters name other tasks on
2009   *   which the task is dependent, and the results from those tasks are the
2010   *   arguments of those parameters.
2011   * @param {Function} [callback] - An optional callback which is called when all
2012   * the tasks have been completed. It receives the `err` argument if any `tasks`
2013   * pass an error to their callback, and a `results` object with any completed
2014   * task results, similar to `auto`.
2015   * @example
2016   *
2017   * //  The example from `auto` can be rewritten as follows:
2018   * async.autoInject({
2019   *     get_data: function(callback) {
2020   *         // async code to get some data
2021   *         callback(null, 'data', 'converted to array');
2022   *     },
2023   *     make_folder: function(callback) {
2024   *         // async code to create a directory to store a file in
2025   *         // this is run at the same time as getting the data
2026   *         callback(null, 'folder');
2027   *     },
2028   *     write_file: function(get_data, make_folder, callback) {
2029   *         // once there is some data and the directory exists,
2030   *         // write the data to a file in the directory
2031   *         callback(null, 'filename');
2032   *     },
2033   *     email_link: function(write_file, callback) {
2034   *         // once the file is written let's email a link to it...
2035   *         // write_file contains the filename returned by write_file.
2036   *         callback(null, {'file':write_file, 'email':'[email protected]'});
2037   *     }
2038   * }, function(err, results) {
2039   *     console.log('err = ', err);
2040   *     console.log('email_link = ', results.email_link);
2041   * });
2042   *
2043   * // If you are using a JS minifier that mangles parameter names, `autoInject`
2044   * // will not work with plain functions, since the parameter names will be
2045   * // collapsed to a single letter identifier.  To work around this, you can
2046   * // explicitly specify the names of the parameters your task function needs
2047   * // in an array, similar to Angular.js dependency injection.
2048   *
2049   * // This still has an advantage over plain `auto`, since the results a task
2050   * // depends on are still spread into arguments.
2051   * async.autoInject({
2052   *     //...
2053   *     write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
2054   *         callback(null, 'filename');
2055   *     }],
2056   *     email_link: ['write_file', function(write_file, callback) {
2057   *         callback(null, {'file':write_file, 'email':'[email protected]'});
2058   *     }]
2059   *     //...
2060   * }, function(err, results) {
2061   *     console.log('err = ', err);
2062   *     console.log('email_link = ', results.email_link);
2063   * });
2064   */
2065  function autoInject(tasks, callback) {
2066      var newTasks = {};
2067  
2068      baseForOwn(tasks, function (taskFn, key) {
2069          var params;
2070          var fnIsAsync = isAsync(taskFn);
2071          var hasNoDeps =
2072              (!fnIsAsync && taskFn.length === 1) ||
2073              (fnIsAsync && taskFn.length === 0);
2074  
2075          if (isArray(taskFn)) {
2076              params = taskFn.slice(0, -1);
2077              taskFn = taskFn[taskFn.length - 1];
2078  
2079              newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
2080          } else if (hasNoDeps) {
2081              // no dependencies, use the function as-is
2082              newTasks[key] = taskFn;
2083          } else {
2084              params = parseParams(taskFn);
2085              if (taskFn.length === 0 && !fnIsAsync && params.length === 0) {
2086                  throw new Error("autoInject task functions require explicit parameters.");
2087              }
2088  
2089              // remove callback param
2090              if (!fnIsAsync) params.pop();
2091  
2092              newTasks[key] = params.concat(newTask);
2093          }
2094  
2095          function newTask(results, taskCb) {
2096              var newArgs = arrayMap(params, function (name) {
2097                  return results[name];
2098              });
2099              newArgs.push(taskCb);
2100              wrapAsync(taskFn).apply(null, newArgs);
2101          }
2102      });
2103  
2104      auto(newTasks, callback);
2105  }
2106  
2107  // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
2108  // used for queues. This implementation assumes that the node provided by the user can be modified
2109  // to adjust the next and last properties. We implement only the minimal functionality
2110  // for queue support.
2111  function DLL() {
2112      this.head = this.tail = null;
2113      this.length = 0;
2114  }
2115  
2116  function setInitial(dll, node) {
2117      dll.length = 1;
2118      dll.head = dll.tail = node;
2119  }
2120  
2121  DLL.prototype.removeLink = function(node) {
2122      if (node.prev) node.prev.next = node.next;
2123      else this.head = node.next;
2124      if (node.next) node.next.prev = node.prev;
2125      else this.tail = node.prev;
2126  
2127      node.prev = node.next = null;
2128      this.length -= 1;
2129      return node;
2130  };
2131  
2132  DLL.prototype.empty = function () {
2133      while(this.head) this.shift();
2134      return this;
2135  };
2136  
2137  DLL.prototype.insertAfter = function(node, newNode) {
2138      newNode.prev = node;
2139      newNode.next = node.next;
2140      if (node.next) node.next.prev = newNode;
2141      else this.tail = newNode;
2142      node.next = newNode;
2143      this.length += 1;
2144  };
2145  
2146  DLL.prototype.insertBefore = function(node, newNode) {
2147      newNode.prev = node.prev;
2148      newNode.next = node;
2149      if (node.prev) node.prev.next = newNode;
2150      else this.head = newNode;
2151      node.prev = newNode;
2152      this.length += 1;
2153  };
2154  
2155  DLL.prototype.unshift = function(node) {
2156      if (this.head) this.insertBefore(this.head, node);
2157      else setInitial(this, node);
2158  };
2159  
2160  DLL.prototype.push = function(node) {
2161      if (this.tail) this.insertAfter(this.tail, node);
2162      else setInitial(this, node);
2163  };
2164  
2165  DLL.prototype.shift = function() {
2166      return this.head && this.removeLink(this.head);
2167  };
2168  
2169  DLL.prototype.pop = function() {
2170      return this.tail && this.removeLink(this.tail);
2171  };
2172  
2173  DLL.prototype.toArray = function () {
2174      var arr = Array(this.length);
2175      var curr = this.head;
2176      for(var idx = 0; idx < this.length; idx++) {
2177          arr[idx] = curr.data;
2178          curr = curr.next;
2179      }
2180      return arr;
2181  };
2182  
2183  DLL.prototype.remove = function (testFn) {
2184      var curr = this.head;
2185      while(!!curr) {
2186          var next = curr.next;
2187          if (testFn(curr)) {
2188              this.removeLink(curr);
2189          }
2190          curr = next;
2191      }
2192      return this;
2193  };
2194  
2195  function queue(worker, concurrency, payload) {
2196      if (concurrency == null) {
2197          concurrency = 1;
2198      }
2199      else if(concurrency === 0) {
2200          throw new Error('Concurrency must not be zero');
2201      }
2202  
2203      var _worker = wrapAsync(worker);
2204      var numRunning = 0;
2205      var workersList = [];
2206  
2207      var processingScheduled = false;
2208      function _insert(data, insertAtFront, callback) {
2209          if (callback != null && typeof callback !== 'function') {
2210              throw new Error('task callback must be a function');
2211          }
2212          q.started = true;
2213          if (!isArray(data)) {
2214              data = [data];
2215          }
2216          if (data.length === 0 && q.idle()) {
2217              // call drain immediately if there are no tasks
2218              return setImmediate$1(function() {
2219                  q.drain();
2220              });
2221          }
2222  
2223          for (var i = 0, l = data.length; i < l; i++) {
2224              var item = {
2225                  data: data[i],
2226                  callback: callback || noop
2227              };
2228  
2229              if (insertAtFront) {
2230                  q._tasks.unshift(item);
2231              } else {
2232                  q._tasks.push(item);
2233              }
2234          }
2235  
2236          if (!processingScheduled) {
2237              processingScheduled = true;
2238              setImmediate$1(function() {
2239                  processingScheduled = false;
2240                  q.process();
2241              });
2242          }
2243      }
2244  
2245      function _next(tasks) {
2246          return function(err){
2247              numRunning -= 1;
2248  
2249              for (var i = 0, l = tasks.length; i < l; i++) {
2250                  var task = tasks[i];
2251  
2252                  var index = baseIndexOf(workersList, task, 0);
2253                  if (index === 0) {
2254                      workersList.shift();
2255                  } else if (index > 0) {
2256                      workersList.splice(index, 1);
2257                  }
2258  
2259                  task.callback.apply(task, arguments);
2260  
2261                  if (err != null) {
2262                      q.error(err, task.data);
2263                  }
2264              }
2265  
2266              if (numRunning <= (q.concurrency - q.buffer) ) {
2267                  q.unsaturated();
2268              }
2269  
2270              if (q.idle()) {
2271                  q.drain();
2272              }
2273              q.process();
2274          };
2275      }
2276  
2277      var isProcessing = false;
2278      var q = {
2279          _tasks: new DLL(),
2280          concurrency: concurrency,
2281          payload: payload,
2282          saturated: noop,
2283          unsaturated:noop,
2284          buffer: concurrency / 4,
2285          empty: noop,
2286          drain: noop,
2287          error: noop,
2288          started: false,
2289          paused: false,
2290          push: function (data, callback) {
2291              _insert(data, false, callback);
2292          },
2293          kill: function () {
2294              q.drain = noop;
2295              q._tasks.empty();
2296          },
2297          unshift: function (data, callback) {
2298              _insert(data, true, callback);
2299          },
2300          remove: function (testFn) {
2301              q._tasks.remove(testFn);
2302          },
2303          process: function () {
2304              // Avoid trying to start too many processing operations. This can occur
2305              // when callbacks resolve synchronously (#1267).
2306              if (isProcessing) {
2307                  return;
2308              }
2309              isProcessing = true;
2310              while(!q.paused && numRunning < q.concurrency && q._tasks.length){
2311                  var tasks = [], data = [];
2312                  var l = q._tasks.length;
2313                  if (q.payload) l = Math.min(l, q.payload);
2314                  for (var i = 0; i < l; i++) {
2315                      var node = q._tasks.shift();
2316                      tasks.push(node);
2317                      workersList.push(node);
2318                      data.push(node.data);
2319                  }
2320  
2321                  numRunning += 1;
2322  
2323                  if (q._tasks.length === 0) {
2324                      q.empty();
2325                  }
2326  
2327                  if (numRunning === q.concurrency) {
2328                      q.saturated();
2329                  }
2330  
2331                  var cb = onlyOnce(_next(tasks));
2332                  _worker(data, cb);
2333              }
2334              isProcessing = false;
2335          },
2336          length: function () {
2337              return q._tasks.length;
2338          },
2339          running: function () {
2340              return numRunning;
2341          },
2342          workersList: function () {
2343              return workersList;
2344          },
2345          idle: function() {
2346              return q._tasks.length + numRunning === 0;
2347          },
2348          pause: function () {
2349              q.paused = true;
2350          },
2351          resume: function () {
2352              if (q.paused === false) { return; }
2353              q.paused = false;
2354              setImmediate$1(q.process);
2355          }
2356      };
2357      return q;
2358  }
2359  
2360  /**
2361   * A cargo of tasks for the worker function to complete. Cargo inherits all of
2362   * the same methods and event callbacks as [`queue`]{@link module:ControlFlow.queue}.
2363   * @typedef {Object} CargoObject
2364   * @memberOf module:ControlFlow
2365   * @property {Function} length - A function returning the number of items
2366   * waiting to be processed. Invoke like `cargo.length()`.
2367   * @property {number} payload - An `integer` for determining how many tasks
2368   * should be process per round. This property can be changed after a `cargo` is
2369   * created to alter the payload on-the-fly.
2370   * @property {Function} push - Adds `task` to the `queue`. The callback is
2371   * called once the `worker` has finished processing the task. Instead of a
2372   * single task, an array of `tasks` can be submitted. The respective callback is
2373   * used for every task in the list. Invoke like `cargo.push(task, [callback])`.
2374   * @property {Function} saturated - A callback that is called when the
2375   * `queue.length()` hits the concurrency and further tasks will be queued.
2376   * @property {Function} empty - A callback that is called when the last item
2377   * from the `queue` is given to a `worker`.
2378   * @property {Function} drain - A callback that is called when the last item
2379   * from the `queue` has returned from the `worker`.
2380   * @property {Function} idle - a function returning false if there are items
2381   * waiting or being processed, or true if not. Invoke like `cargo.idle()`.
2382   * @property {Function} pause - a function that pauses the processing of tasks
2383   * until `resume()` is called. Invoke like `cargo.pause()`.
2384   * @property {Function} resume - a function that resumes the processing of
2385   * queued tasks when the queue is paused. Invoke like `cargo.resume()`.
2386   * @property {Function} kill - a function that removes the `drain` callback and
2387   * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`.
2388   */
2389  
2390  /**
2391   * Creates a `cargo` object with the specified payload. Tasks added to the
2392   * cargo will be processed altogether (up to the `payload` limit). If the
2393   * `worker` is in progress, the task is queued until it becomes available. Once
2394   * the `worker` has completed some tasks, each callback of those tasks is
2395   * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e676974687
23955622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
2396   * for how `cargo` and `queue` work.
2397   *
2398   * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
2399   * at a time, cargo passes an array of tasks to a single worker, repeating
2400   * when the worker is finished.
2401   *
2402   * @name cargo
2403   * @static
2404   * @memberOf module:ControlFlow
2405   * @method
2406   * @see [async.queue]{@link module:ControlFlow.queue}
2407   * @category Control Flow
2408   * @param {AsyncFunction} worker - An asynchronous function for processing an array
2409   * of queued tasks. Invoked with `(tasks, callback)`.
2410   * @param {number} [payload=Infinity] - An optional `integer` for determining
2411   * how many tasks should be processed per round; if omitted, the default is
2412   * unlimited.
2413   * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can
2414   * attached as certain properties to listen for specific events during the
2415   * lifecycle of the cargo and inner queue.
2416   * @example
2417   *
2418   * // create a cargo object with payload 2
2419   * var cargo = async.cargo(function(tasks, callback) {
2420   *     for (var i=0; i<tasks.length; i++) {
2421   *         console.log('hello ' + tasks[i].name);
2422   *     }
2423   *     callback();
2424   * }, 2);
2425   *
2426   * // add some items
2427   * cargo.push({name: 'foo'}, function(err) {
2428   *     console.log('finished processing foo');
2429   * });
2430   * cargo.push({name: 'bar'}, function(err) {
2431   *     console.log('finished processing bar');
2432   * });
2433   * cargo.push({name: 'baz'}, function(err) {
2434   *     console.log('finished processing baz');
2435   * });
2436   */
2437  function cargo(worker, payload) {
2438      return queue(worker, 1, payload);
2439  }
2440  
2441  /**
2442   * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
2443   *
2444   * @name eachOfSeries
2445   * @static
2446   * @memberOf module:Collections
2447   * @method
2448   * @see [async.eachOf]{@link module:Collections.eachOf}
2449   * @alias forEachOfSeries
2450   * @category Collection
2451   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2452   * @param {AsyncFunction} iteratee - An async function to apply to each item in
2453   * `coll`.
2454   * Invoked with (item, key, callback).
2455   * @param {Function} [callback] - A callback which is called when all `iteratee`
2456   * functions have finished, or an error occurs. Invoked with (err).
2457   */
2458  var eachOfSeries = doLimit(eachOfLimit, 1);
2459  
2460  /**
2461   * Reduces `coll` into a single value using an async `iteratee` to return each
2462   * successive step. `memo` is the initial state of the reduction. This function
2463   * only operates in series.
2464   *
2465   * For performance reasons, it may make sense to split a call to this function
2466   * into a parallel map, and then use the normal `Array.prototype.reduce` on the
2467   * results. This function is for situations where each step in the reduction
2468   * needs to be async; if you can get the data before reducing it, then it's
2469   * probably a good idea to do so.
2470   *
2471   * @name reduce
2472   * @static
2473   * @memberOf module:Collections
2474   * @method
2475   * @alias inject
2476   * @alias foldl
2477   * @category Collection
2478   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2479   * @param {*} memo - The initial state of the reduction.
2480   * @param {AsyncFunction} iteratee - A function applied to each item in the
2481   * array to produce the next step in the reduction.
2482   * The `iteratee` should complete with the next state of the reduction.
2483   * If the iteratee complete with an error, the reduction is stopped and the
2484   * main `callback` is immediately called with the error.
2485   * Invoked with (memo, item, callback).
2486   * @param {Function} [callback] - A callback which is called after all the
2487   * `iteratee` functions have finished. Result is the reduced value. Invoked with
2488   * (err, result).
2489   * @example
2490   *
2491   * async.reduce([1,2,3], 0, function(memo, item, callback) {
2492   *     // pointless async:
2493   *     process.nextTick(function() {
2494   *         callback(null, memo + item)
2495   *     });
2496   * }, function(err, result) {
2497   *     // result is now equal to the last value of memo, which is 6
2498   * });
2499   */
2500  function reduce(coll, memo, iteratee, callback) {
2501      callback = once(callback || noop);
2502      var _iteratee = wrapAsync(iteratee);
vendor: 22,661 bytes, lines 2503-3124
2503      eachOfSeries(coll, function(x, i, callback) {
2504          _iteratee(memo, x, function(err, v) {
2505              memo = v;
2506              callback(err);
2507          });
2508      }, function(err) {
2509          callback(err, memo);
2510      });
2511  }
2512  
2513  /**
2514   * Version of the compose function that is more natural to read. Each function
2515   * consumes the return value of the previous function. It is the equivalent of
2516   * [compose]{@link module:ControlFlow.compose} with the arguments reversed.
2517   *
2518   * Each function is executed with the `this` binding of the composed function.
2519   *
2520   * @name seq
2521   * @static
2522   * @memberOf module:ControlFlow
2523   * @method
2524   * @see [async.compose]{@link module:ControlFlow.compose}
2525   * @category Control Flow
2526   * @param {...AsyncFunction} functions - the asynchronous functions to compose
2527   * @returns {Function} a function that composes the `functions` in order
2528   * @example
2529   *
2530   * // Requires lodash (or underscore), express3 and dresende's orm2.
2531   * // Part of an app, that fetches cats of the logged user.
2532   * // This example uses `seq` function to avoid overnesting and error
2533   * // handling clutter.
2534   * app.get('/cats', function(request, response) {
2535   *     var User = request.models.User;
2536   *     async.seq(
2537   *         _.bind(User.get, User),  // 'User.get' has signature (id, callback(err, data))
2538   *         function(user, fn) {
2539   *             user.getCats(fn);      // 'getCats' has signature (callback(err, data))
2540   *         }
2541   *     )(req.session.user_id, function (err, cats) {
2542   *         if (err) {
2543   *             console.error(err);
2544   *             response.json({ status: 'error', message: err.message });
2545   *         } else {
2546   *             response.json({ status: 'ok', message: 'Cats found', data: cats });
2547   *         }
2548   *     });
2549   * });
2550   */
2551  function seq(/*...functions*/) {
2552      var _functions = arrayMap(arguments, wrapAsync);
2553      return function(/*...args*/) {
2554          var args = slice(arguments);
2555          var that = this;
2556  
2557          var cb = args[args.length - 1];
2558          if (typeof cb == 'function') {
2559              args.pop();
2560          } else {
2561              cb = noop;
2562          }
2563  
2564          reduce(_functions, args, function(newargs, fn, cb) {
2565              fn.apply(that, newargs.concat(function(err/*, ...nextargs*/) {
2566                  var nextargs = slice(arguments, 1);
2567                  cb(err, nextargs);
2568              }));
2569          },
2570          function(err, results) {
2571              cb.apply(that, [err].concat(results));
2572          });
2573      };
2574  }
2575  
2576  /**
2577   * Creates a function which is a composition of the passed asynchronous
2578   * functions. Each function consumes the return value of the function that
2579   * follows. Composing functions `f()`, `g()`, and `h()` would produce the result
2580   * of `f(g(h()))`, only this version uses callbacks to obtain the return values.
2581   *
2582   * Each function is executed with the `this` binding of the composed function.
2583   *
2584   * @name compose
2585   * @static
2586   * @memberOf module:ControlFlow
2587   * @method
2588   * @category Control Flow
2589   * @param {...AsyncFunction} functions - the asynchronous functions to compose
2590   * @returns {Function} an asynchronous function that is the composed
2591   * asynchronous `functions`
2592   * @example
2593   *
2594   * function add1(n, callback) {
2595   *     setTimeout(function () {
2596   *         callback(null, n + 1);
2597   *     }, 10);
2598   * }
2599   *
2600   * function mul3(n, callback) {
2601   *     setTimeout(function () {
2602   *         callback(null, n * 3);
2603   *     }, 10);
2604   * }
2605   *
2606   * var add1mul3 = async.compose(mul3, add1);
2607   * add1mul3(4, function (err, result) {
2608   *     // result now equals 15
2609   * });
2610   */
2611  var compose = function(/*...args*/) {
2612      return seq.apply(null, slice(arguments).reverse());
2613  };
2614  
2615  var _concat = Array.prototype.concat;
2616  
2617  /**
2618   * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.
2619   *
2620   * @name concatLimit
2621   * @static
2622   * @memberOf module:Collections
2623   * @method
2624   * @see [async.concat]{@link module:Collections.concat}
2625   * @category Collection
2626   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2627   * @param {number} limit - The maximum number of async operations at a time.
2628   * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,
2629   * which should use an array as its result. Invoked with (item, callback).
2630   * @param {Function} [callback] - A callback which is called after all the
2631   * `iteratee` functions have finished, or an error occurs. Results is an array
2632   * containing the concatenated results of the `iteratee` function. Invoked with
2633   * (err, results).
2634   */
2635  var concatLimit = function(coll, limit, iteratee, callback) {
2636      callback = callback || noop;
2637      var _iteratee = wrapAsync(iteratee);
2638      mapLimit(coll, limit, function(val, callback) {
2639          _iteratee(val, function(err /*, ...args*/) {
2640              if (err) return callback(err);
2641              return callback(null, slice(arguments, 1));
2642          });
2643      }, function(err, mapResults) {
2644          var result = [];
2645          for (var i = 0; i < mapResults.length; i++) {
2646              if (mapResults[i]) {
2647                  result = _concat.apply(result, mapResults[i]);
2648              }
2649          }
2650  
2651          return callback(err, result);
2652      });
2653  };
2654  
2655  /**
2656   * Applies `iteratee` to each item in `coll`, concatenating the results. Returns
2657   * the concatenated list. The `iteratee`s are called in parallel, and the
2658   * results are concatenated as they return. There is no guarantee that the
2659   * results array will be returned in the original order of `coll` passed to the
2660   * `iteratee` function.
2661   *
2662   * @name concat
2663   * @static
2664   * @memberOf module:Collections
2665   * @method
2666   * @category Collection
2667   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2668   * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,
2669   * which should use an array as its result. Invoked with (item, callback).
2670   * @param {Function} [callback(err)] - A callback which is called after all the
2671   * `iteratee` functions have finished, or an error occurs. Results is an array
2672   * containing the concatenated results of the `iteratee` function. Invoked with
2673   * (err, results).
2674   * @example
2675   *
2676   * async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files) {
2677   *     // files is now a list of filenames that exist in the 3 directories
2678   * });
2679   */
2680  var concat = doLimit(concatLimit, Infinity);
2681  
2682  /**
2683   * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
2684   *
2685   * @name concatSeries
2686   * @static
2687   * @memberOf module:Collections
2688   * @method
2689   * @see [async.concat]{@link module:Collections.concat}
2690   * @category Collection
2691   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2692   * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`.
2693   * The iteratee should complete with an array an array of results.
2694   * Invoked with (item, callback).
2695   * @param {Function} [callback(err)] - A callback which is called after all the
2696   * `iteratee` functions have finished, or an error occurs. Results is an array
2697   * containing the concatenated results of the `iteratee` function. Invoked with
2698   * (err, results).
2699   */
2700  var concatSeries = doLimit(concatLimit, 1);
2701  
2702  /**
2703   * Returns a function that when called, calls-back with the values provided.
2704   * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
2705   * [`auto`]{@link module:ControlFlow.auto}.
2706   *
2707   * @name constant
2708   * @static
2709   * @memberOf module:Utils
2710   * @method
2711   * @category Util
2712   * @param {...*} arguments... - Any number of arguments to automatically invoke
2713   * callback with.
2714   * @returns {AsyncFunction} Returns a function that when invoked, automatically
2715   * invokes the callback with the previous given arguments.
2716   * @example
2717   *
2718   * async.waterfall([
2719   *     async.constant(42),
2720   *     function (value, next) {
2721   *         // value === 42
2722   *     },
2723   *     //...
2724   * ], callback);
2725   *
2726   * async.waterfall([
2727   *     async.constant(filename, "utf8"),
2728   *     fs.readFile,
2729   *     function (fileData, next) {
2730   *         //...
2731   *     }
2732   *     //...
2733   * ], callback);
2734   *
2735   * async.auto({
2736   *     hostname: async.constant("https://server.net/"),
2737   *     port: findFreePort,
2738   *     launchServer: ["hostname", "port", function (options, cb) {
2739   *         startServer(options, cb);
2740   *     }],
2741   *     //...
2742   * }, callback);
2743   */
2744  var constant = function(/*...values*/) {
2745      var values = slice(arguments);
2746      var args = [null].concat(values);
2747      return function (/*...ignoredArgs, callback*/) {
2748          var callback = arguments[arguments.length - 1];
2749          return callback.apply(this, args);
2750      };
2751  };
2752  
2753  /**
2754   * This method returns the first argument it receives.
2755   *
2756   * @static
2757   * @since 0.1.0
2758   * @memberOf _
2759   * @category Util
2760   * @param {*} value Any value.
2761   * @returns {*} Returns `value`.
2762   * @example
2763   *
2764   * var object = { 'a': 1 };
2765   *
2766   * console.log(_.identity(object) === object);
2767   * // => true
2768   */
2769  function identity(value) {
2770    return value;
2771  }
2772  
2773  function _createTester(check, getResult) {
2774      return function(eachfn, arr, iteratee, cb) {
2775          cb = cb || noop;
2776          var testPassed = false;
2777          var testResult;
2778          eachfn(arr, function(value, _, callback) {
2779              iteratee(value, function(err, result) {
2780                  if (err) {
2781                      callback(err);
2782                  } else if (check(result) && !testResult) {
2783                      testPassed = true;
2784                      testResult = getResult(true, value);
2785                      callback(null, breakLoop);
2786                  } else {
2787                      callback();
2788                  }
2789              });
2790          }, function(err) {
2791              if (err) {
2792                  cb(err);
2793              } else {
2794                  cb(null, testPassed ? testResult : getResult(false));
2795              }
2796          });
2797      };
2798  }
2799  
2800  function _findGetResult(v, x) {
2801      return x;
2802  }
2803  
2804  /**
2805   * Returns the first value in `coll` that passes an async truth test. The
2806   * `iteratee` is applied in parallel, meaning the first iteratee to return
2807   * `true` will fire the detect `callback` with that result. That means the
2808   * result might not be the first item in the original `coll` (in terms of order)
2809   * that passes the test.
2810  
2811   * If order within the original `coll` is important, then look at
2812   * [`detectSeries`]{@link module:Collections.detectSeries}.
2813   *
2814   * @name detect
2815   * @static
2816   * @memberOf module:Collections
2817   * @method
2818   * @alias find
2819   * @category Collections
2820   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2821   * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
2822   * The iteratee must complete with a boolean value as its result.
2823   * Invoked with (item, callback).
2824   * @param {Function} [callback] - A callback which is called as soon as any
2825   * iteratee returns `true`, or after all the `iteratee` functions have finished.
2826   * Result will be the first item in the array that passes the truth test
2827   * (iteratee) or the value `undefined` if none passed. Invoked with
2828   * (err, result).
2829   * @example
2830   *
2831   * async.detect(['file1','file2','file3'], function(filePath, callback) {
2832   *     fs.access(filePath, function(err) {
2833   *         callback(null, !err)
2834   *     });
2835   * }, function(err, result) {
2836   *     // result now equals the first file in the list that exists
2837   * });
2838   */
2839  var detect = doParallel(_createTester(identity, _findGetResult));
2840  
2841  /**
2842   * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
2843   * time.
2844   *
2845   * @name detectLimit
2846   * @static
2847   * @memberOf module:Collections
2848   * @method
2849   * @see [async.detect]{@link module:Collections.detect}
2850   * @alias findLimit
2851   * @category Collections
2852   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2853   * @param {number} limit - The maximum number of async operations at a time.
2854   * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
2855   * The iteratee must complete with a boolean value as its result.
2856   * Invoked with (item, callback).
2857   * @param {Function} [callback] - A callback which is called as soon as any
2858   * iteratee returns `true`, or after all the `iteratee` functions have finished.
2859   * Result will be the first item in the array that passes the truth test
2860   * (iteratee) or the value `undefined` if none passed. Invoked with
2861   * (err, result).
2862   */
2863  var detectLimit = doParallelLimit(_createTester(identity, _findGetResult));
2864  
2865  /**
2866   * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
2867   *
2868   * @name detectSeries
2869   * @static
2870   * @memberOf module:Collections
2871   * @method
2872   * @see [async.detect]{@link module:Collections.detect}
2873   * @alias findSeries
2874   * @category Collections
2875   * @param {Array|Iterable|Object} coll - A collection to iterate over.
2876   * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
2877   * The iteratee must complete with a boolean value as its result.
2878   * Invoked with (item, callback).
2879   * @param {Function} [callback] - A callback which is called as soon as any
2880   * iteratee returns `true`, or after all the `iteratee` functions have finished.
2881   * Result will be the first item in the array that passes the truth test
2882   * (iteratee) or the value `undefined` if none passed. Invoked with
2883   * (err, result).
2884   */
2885  var detectSeries = doLimit(detectLimit, 1);
2886  
2887  function consoleFunc(name) {
2888      return function (fn/*, ...args*/) {
2889          var args = slice(arguments, 1);
2890          args.push(function (err/*, ...args*/) {
2891              var args = slice(arguments, 1);
2892              if (typeof console === 'object') {
2893                  if (err) {
2894                      if (console.error) {
2895                          console.error(err);
2896                      }
2897                  } else if (console[name]) {
2898                      arrayEach(args, function (x) {
2899                          console[name](x);
2900                      });
2901                  }
2902              }
2903          });
2904          wrapAsync(fn).apply(null, args);
2905      };
2906  }
2907  
2908  /**
2909   * Logs the result of an [`async` function]{@link AsyncFunction} to the
2910   * `console` using `console.dir` to display the properties of the resulting object.
2911   * Only works in Node.js or in browsers that support `console.dir` and
2912   * `console.error` (such as FF and Chrome).
2913   * If multiple arguments are returned from the async function,
2914   * `console.dir` is called on each argument in order.
2915   *
2916   * @name dir
2917   * @static
2918   * @memberOf module:Utils
2919   * @method
2920   * @category Util
2921   * @param {AsyncFunction} function - The function you want to eventually apply
2922   * all arguments to.
2923   * @param {...*} arguments... - Any number of arguments to apply to the function.
2924   * @example
2925   *
2926   * // in a module
2927   * var hello = function(name, callback) {
2928   *     setTimeout(function() {
2929   *         callback(null, {hello: name});
2930   *     }, 1000);
2931   * };
2932   *
2933   * // in the node repl
2934   * node> async.dir(hello, 'world');
2935   * {hello: 'world'}
2936   */
2937  var dir = consoleFunc('dir');
2938  
2939  /**
2940   * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
2941   * the order of operations, the arguments `test` and `fn` are switched.
2942   *
2943   * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
2944   * @name doDuring
2945   * @static
2946   * @memberOf module:ControlFlow
2947   * @method
2948   * @see [async.during]{@link module:ControlFlow.during}
2949   * @category Control Flow
2950   * @param {AsyncFunction} fn - An async function which is called each time
2951   * `test` passes. Invoked with (callback).
2952   * @param {AsyncFunction} test - asynchronous truth test to perform before each
2953   * execution of `fn`. Invoked with (...args, callback), where `...args` are the
2954   * non-error args from the previous callback of `fn`.
2955   * @param {Function} [callback] - A callback which is called after the test
2956   * function has failed and repeated execution of `fn` has stopped. `callback`
2957   * will be passed an error if one occurred, otherwise `null`.
2958   */
2959  function doDuring(fn, test, callback) {
2960      callback = onlyOnce(callback || noop);
2961      var _fn = wrapAsync(fn);
2962      var _test = wrapAsync(test);
2963  
2964      function next(err/*, ...args*/) {
2965          if (err) return callback(err);
2966          var args = slice(arguments, 1);
2967          args.push(check);
2968          _test.apply(this, args);
2969      }
2970  
2971      function check(err, truth) {
2972          if (err) return callback(err);
2973          if (!truth) return callback(null);
2974          _fn(next);
2975      }
2976  
2977      check(null, true);
2978  
2979  }
2980  
2981  /**
2982   * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
2983   * the order of operations, the arguments `test` and `iteratee` are switched.
2984   *
2985   * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
2986   *
2987   * @name doWhilst
2988   * @static
2989   * @memberOf module:ControlFlow
2990   * @method
2991   * @see [async.whilst]{@link module:ControlFlow.whilst}
2992   * @category Control Flow
2993   * @param {AsyncFunction} iteratee - A function which is called each time `test`
2994   * passes. Invoked with (callback).
2995   * @param {Function} test - synchronous truth test to perform after each
2996   * execution of `iteratee`. Invoked with any non-error callback results of
2997   * `iteratee`.
2998   * @param {Function} [callback] - A callback which is called after the test
2999   * function has failed and repeated execution of `iteratee` has stopped.
3000   * `callback` will be passed an error and any arguments passed to the final
3001   * `iteratee`'s callback. Invoked with (err, [results]);
3002   */
3003  function doWhilst(iteratee, test, callback) {
3004      callback = onlyOnce(callback || noop);
3005      var _iteratee = wrapAsync(iteratee);
3006      var next = function(err/*, ...args*/) {
3007          if (err) return callback(err);
3008          var args = slice(arguments, 1);
3009          if (test.apply(this, args)) return _iteratee(next);
3010          callback.apply(null, [null].concat(args));
3011      };
3012      _iteratee(next);
3013  }
3014  
3015  /**
3016   * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
3017   * argument ordering differs from `until`.
3018   *
3019   * @name doUntil
3020   * @static
3021   * @memberOf module:ControlFlow
3022   * @method
3023   * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
3024   * @category Control Flow
3025   * @param {AsyncFunction} iteratee - An async function which is called each time
3026   * `test` fails. Invoked with (callback).
3027   * @param {Function} test - synchronous truth test to perform after each
3028   * execution of `iteratee`. Invoked with any non-error callback results of
3029   * `iteratee`.
3030   * @param {Function} [callback] - A callback which is called after the test
3031   * function has passed and repeated execution of `iteratee` has stopped. `callback`
3032   * will be passed an error and any arguments passed to the final `iteratee`'s
3033   * callback. Invoked with (err, [results]);
3034   */
3035  function doUntil(iteratee, test, callback) {
3036      doWhilst(iteratee, function() {
3037          return !test.apply(this, arguments);
3038      }, callback);
3039  }
3040  
3041  /**
3042   * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
3043   * is passed a callback in the form of `function (err, truth)`. If error is
3044   * passed to `test` or `fn`, the main callback is immediately called with the
3045   * value of the error.
3046   *
3047   * @name during
3048   * @static
3049   * @memberOf module:ControlFlow
3050   * @method
3051   * @see [async.whilst]{@link module:ControlFlow.whilst}
3052   * @category Control Flow
3053   * @param {AsyncFunction} test - asynchronous truth test to perform before each
3054   * execution of `fn`. Invoked with (callback).
3055   * @param {AsyncFunction} fn - An async function which is called each time
3056   * `test` passes. Invoked with (callback).
3057   * @param {Function} [callback] - A callback which is called after the test
3058   * function has failed and repeated execution of `fn` has stopped. `callback`
3059   * will be passed an error, if one occurred, otherwise `null`.
3060   * @example
3061   *
3062   * var count = 0;
3063   *
3064   * async.during(
3065   *     function (callback) {
3066   *         return callback(null, count < 5);
3067   *     },
3068   *     function (callback) {
3069   *         count++;
3070   *         setTimeout(callback, 1000);
3071   *     },
3072   *     function (err) {
3073   *         // 5 seconds have passed
3074   *     }
3075   * );
3076   */
3077  function during(test, fn, callback) {
3078      callback = onlyOnce(callback || noop);
3079      var _fn = wrapAsync(fn);
3080      var _test = wrapAsync(test);
3081  
3082      function next(err) {
3083          if (err) return callback(err);
3084          _test(check);
3085      }
3086  
3087      function check(err, truth) {
3088          if (err) return callback(err);
3089          if (!truth) return callback(null);
3090          _fn(next);
3091      }
3092  
3093      _test(check);
3094  }
3095  
3096  function _withoutIndex(iteratee) {
3097      return function (value, index, callback) {
3098          return iteratee(value, callback);
3099      };
3100  }
3101  
3102  /**
3103   * Applies the function `iteratee` to each item in `coll`, in parallel.
3104   * The `iteratee` is called with an item from the list, and a callback for when
3105   * it has finished. If the `iteratee` passes an error to its `callback`, the
3106   * main `callback` (for the `each` function) is immediately called with the
3107   * error.
3108   *
3109   * Note, that since this function applies `iteratee` to each item in parallel,
3110   * there is no guarantee that the iteratee functions will complete in order.
3111   *
3112   * @name each
3113   * @static
3114   * @memberOf module:Collections
3115   * @method
3116   * @alias forEach
3117   * @category Collection
3118   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3119   * @param {AsyncFunction} iteratee - An async function to apply to
3120   * each item in `coll`. Invoked with (item, callback).
3121   * The array index is not passed to the iteratee.
3122   * If you need the index, use `eachOf`.
3123   * @param {Function} [callback] - A callback which is called when all
3124   * `iteratee` functions have finished, or an error occurs. Invoked with (err).
3125   * @example
3126   *
3127   * // assuming openFiles is an array of file names and saveFile is a function
3128   * // to save the modified contents of that file:
3129   *
3130   * async.each(openFiles, saveFile, function(err){
3131   *   // if any of the saves produced an error, err would equal that error
3132   * });
3133   *
3134   * // assuming openFiles is an array of file names
3135   * async.each(openFiles, function(file, callback) {
3136   *
3137   *     // Perform operation on file here.
3138   *     console.log('Processing file ' + file);
3139   *
3140   *     if( file.length > 32 ) {
3141   *       console.log('This file name is too long');
3142   *       callback('File name too long');
3143   *     } else {
3144   *       // Do work to process file here
3145   *       console.log('File processed');
3146   *       callback();
3147   *     }
3148   * }, function(err) {
3149   *     // if any of the file processing produced an error, err would equal that error
3150   *     if( err ) {
3151   *       // One of the iterations produced an error.
3152   *       // All processing will now stop.
3153   *       console.log('A file failed to process');
3154   *     } else {
3155   *       console.log('All files have been processed successfully');
3156   *     }
3157   * });
3158   */
3159  function eachLimit(coll, iteratee, callback) {
3160      eachOf(coll, _withoutIndex(wrapAsync(iteratee)), callback);
3161  }
3162  
3163  /**
3164   * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
3165   *
3166   * @name eachLimit
3167   * @static
3168   * @memberOf module:Collections
3169   * @method
3170   * @see [async.each]{@link module:Collections.each}
3171   * @alias forEachLimit
3172   * @category Collection
3173   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3174   * @param {number} limit - The maximum number of async operations at a time.
3175   * @param {AsyncFunction} iteratee - An async function to apply to each item in
3176   * `coll`.
3177   * The array index is not passed to the iteratee.
3178   * If you need the index, use `eachOfLimit`.
3179   * Invoked with (item, callback).
3180   * @param {Function} [callback] - A callback which is called when all
3181   * `iteratee` functions have finished, or an error occurs. Invoked with (err).
3182   */
3183  function eachLimit$1(coll, limit, iteratee, callback) {
3184      _eachOfLimit(limit)(coll, _withoutIndex(wrapAsync(iteratee)), callback);
3185  }
3186  
3187  /**
3188   * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
3189   *
3190   * @name eachSeries
3191   * @static
3192   * @memberOf module:Collections
3193   * @method
3194   * @see [async.each]{@link module:Collections.each}
3195   * @alias forEachSeries
3196   * @category Collection
3197   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3198   * @param {AsyncFunction} iteratee - An async function to apply to each
3199   * item in `coll`.
3200   * The array index is not passed to the iteratee.
3201   * If you need the index, use `eachOfSeries`.
3202   * Invoked with (item, callback).
3203   * @param {Function} [callback] - A callback which is called when all
3204   * `iteratee` functions have finished, or an error occurs. Invoked with (err).
3205   */
3206  var eachSeries = doLimit(eachLimit$1, 1);
3207  
3208  /**
3209   * Wrap an async function and ensure it calls its callback on a later tick of
3210   * the event loop.  If the function already calls its callback on a next tick,
3211   * no extra deferral is added. This is useful for preventing stack overflows
3212   * (`RangeError: Maximum call stack size exceeded`) and generally keeping
3213   * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)
3214   * contained. ES2017 `async` functions are returned as-is -- they are immune
3215   * to Zalgo's corrupting influences, as they always resolve on a later tick.
3216   *
3217   * @name ensureAsync
3218   * @static
3219   * @memberOf module:Utils
3220   * @method
3221   * @category Util
3222   * @param {AsyncFunction}
3222 fn - an async function, one that expects a node-style
3223   * callback as its last argument.
3224   * @returns {AsyncFunction} Returns a wrapped function with the exact same call
3225   * signature as the function passed in.
3226   * @example
3227   *
3228   * function sometimesAsync(arg, callback) {
3229   *     if (cache[arg]) {
3230   *         return callback(null, cache[arg]); // this would be synchronous!!
3231   *     } else {
3232   *         doSomeIO(arg, callback); // this IO would be asynchronous
3233   *     }
3234   * }
3235   *
3236   * // this has a risk of stack overflows if many results are cached in a row
3237   * async.mapSeries(args, sometimesAsync, done);
3238   *
3239   * // this will defer sometimesAsync's callback if necessary,
3240   * // preventing stack overflows
3241   * async.mapSeries(args, async.ensureAsync(sometimesAsync), done);
3242   */
3243  function ensureAsync(fn) {
3244      if (isAsync(fn)) return fn;
3245      return initialParams(function (args, callback) {
3246          var sync = true;
3247          args.push(function () {
3248              var innerArgs = arguments;
3249              if (sync) {
3250                  setImmediate$1(function () {
3251                      callback.apply(null, innerArgs);
3252                  });
3253              } else {
3254                  callback.apply(null, innerArgs);
3255              }
3256          });
3257          fn.apply(this, args);
3258          sync = false;
3259      });
3260  }
3261  
3262  function notId(v) {
3263      return !v;
3264  }
3265  
3266  /**
3267   * Returns `true` if every element in `coll` satisfies an async test. If any
3268   * iteratee call returns `false`, the main `callback` is immediately called.
3269   *
3270   * @name every
3271   * @static
3272   * @memberOf module:Collections
3273   * @method
3274   * @alias all
3275   * @category Collection
3276   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3277   * @param {AsyncFunction} iteratee - An async truth test to apply to each item
3278   * in the collection in parallel.
3279   * The iteratee must complete with a boolean result value.
3280   * Invoked with (item, callback).
3281   * @param {Function} [callback] - A callback which is called after all the
3282   * `iteratee` functions have finished. Result will be either `true` or `false`
3283   * depending on the values of the async tests. Invoked with (err, result).
3284   * @example
3285   *
3286   * async.every(['file1','file2','file3'], function(filePath, callback) {
3287   *     fs.access(filePath, function(err) {
3288   *         callback(null, !err)
3289   *     });
3290   * }, function(err, result) {
3291   *     // if result is true then every file exists
3292   * });
3293   */
3294  var every = doParallel(_createTester(notId, notId));
3295  
3296  /**
3297   * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
3298   *
3299   * @name everyLimit
3300   * @static
3301   * @memberOf module:Collections
3302   * @method
3303   * @see [async.every]{@link module:Collections.every}
3304   * @alias allLimit
3305   * @category Collection
3306   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3307   * @param {number} limit - The maximum number of async operations at a time.
3308   * @param {AsyncFunction} iteratee - An async truth test to apply to each item
3309   * in the collection in parallel.
3310   * The iteratee must complete with a boolean result value.
3311   * Invoked with (item, callback).
3312   * @param {Function} [callback] - A callback which is called after all the
3313   * `iteratee` functions have finished. Result will be either `true` or `false`
3314   * depending on the values of the async tests. Invoked with (err, result).
3315   */
3316  var everyLimit = doParallelLimit(_createTester(notId, notId));
3317  
3318  /**
3319   * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
3320   *
3321   * @name everySeries
3322   * @static
3323   * @memberOf module:Collections
3324   * @method
3325   * @see [async.every]{@link module:Collections.every}
3326   * @alias allSeries
3327   * @category Collection
3328   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3329   * @param {AsyncFunction} iteratee - An async truth test to apply to each item
3330   * in the collection in series.
3331   * The iteratee must complete with a boolean result value.
3332   * Invoked with (item, callback).
3333   * @param {Function} [callback] - A callback which is called after all the
3334   * `iteratee` functions have finished. Result will be either `true` or `false`
3335   * depending on the values of the async tests. Invoked with (err, result).
3336   */
3337  var everySeries = doLimit(everyLimit, 1);
3338  
3339  /**
3340   * The base implementation of `_.property` without support for deep paths.
3341   *
3342   * @private
3343   * @param {string} key The key of the property to get.
3344   * @returns {Function} Returns the new accessor function.
3345   */
3346  function baseProperty(key) {
3347    return function(object) {
3348      return object == null ? undefined : object[key];
3349    };
3350  }
3351  
3352  function filterArray(eachfn, arr, iteratee, callback) {
3353      var truthValues = new Array(arr.length);
3354      eachfn(arr, function (x, index, callback) {
3355          iteratee(x, function (err, v) {
3356              truthValues[index] = !!v;
3357              callback(err);
3358          });
3359      }, function (err) {
3360          if (err) return callback(err);
3361          var results = [];
3362          for (var i = 0; i < arr.length; i++) {
3363              if (truthValues[i]) results.push(arr[i]);
3364          }
3365          callback(null, results);
3366      });
3367  }
3368  
3369  function filterGeneric(eachfn, coll, iteratee, callback) {
3370      var results = [];
3371      eachfn(coll, function (x, index, callback) {
3372          iteratee(x, function (err, v) {
3373              if (err) {
3374                  callback(err);
3375              } else {
3376                  if (v) {
3377                      results.push({index: index, value: x});
3378                  }
3379                  callback();
3380              }
3381          });
3382      }, function (err) {
3383          if (err) {
3384              callback(err);
3385          } else {
3386              callback(null, arrayMap(results.sort(function (a, b) {
3387                  return a.index - b.index;
3388              }), baseProperty('value')));
3389          }
3390      });
3391  }
3392  
3393  function _filter(eachfn, coll, iteratee, callback) {
3394      var filter = isArrayLike(coll) ? filterArray : filterGeneric;
3395      filter(eachfn, coll, wrapAsync(iteratee), callback || noop);
3396  }
3397  
3398  /**
3399   * Returns a new array of all the values in `coll` which pass an async truth
3400   * test. This operation is performed in parallel, but the results array will be
3401   * in the same order as the original.
3402   *
3403   * @name filter
3404   * @static
3405   * @memberOf module:Collections
3406   * @method
3407   * @alias select
3408   * @category Collection
3409   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3410   * @param {Function} iteratee - A truth test to apply to each item in `coll`.
3411   * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
3412   * with a boolean argument once it has completed. Invoked with (item, callback).
3413   * @param {Function} [callback] - A callback which is called after all the
3414   * `iteratee` functions have finished. Invoked with (err, results).
3415   * @example
3416   *
3417   * async.filter(['file1','file2','file3'], function(filePath, callback) {
3418   *     fs.access(filePath, function(err) {
3419   *         callback(null, !err)
3420   *     });
3421   * }, function(err, results) {
3422   *     // results now equals an array of the existing files
3423   * });
3424   */
3425  var filter = doParallel(_filter);
3426  
3427  /**
3428   * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a
3429   * time.
3430   *
3431   * @name filterLimit
3432   * @static
3433   * @memberOf module:Collections
3434   * @method
3435   * @see [async.filter]{@link module:Collections.filter}
3436   * @alias selectLimit
3437   * @category Collection
3438   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3439   * @param {number} limit - The maximum number of async operations at a time.
3440   * @param {Function} iteratee - A truth test to apply to each item in `coll`.
3441   * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
3442   * with a boolean argument once it has completed. Invoked with (item, callback).
3443   * @param {Function} [callback] - A callback which is called after all the
3444   * `iteratee` functions have finished. Invoked with (err, results).
3445   */
3446  var filterLimit = doParallelLimit(_filter);
3447  
3448  /**
3449   * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time.
3450   *
3451   * @name filterSeries
3452   * @static
3453   * @memberOf module:Collections
3454   * @method
3455   * @see [async.filter]{@link module:Collections.filter}
3456   * @alias selectSeries
3457   * @category Collection
3458   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3459   * @param {Function} iteratee - A truth test to apply to each item in `coll`.
3460   * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
3461   * with a boolean argument once it has completed. Invoked with (item, callback).
3462   * @param {Function} [callback] - A callback which is called after all the
3463   * `iteratee` functions have finished. Invoked with (err, results)
3464   */
3465  var filterSeries = doLimit(filterLimit, 1);
3466  
3467  /**
3468   * Calls the asynchronous function `fn` with a callback parameter that allows it
3469   * to call itself again, in series, indefinitely.
3470  
3471   * If an error is passed to the callback then `errback` is called with the
3472   * error, and execution stops, otherwise it will never be called.
3473   *
3474   * @name forever
3475   * @static
3476   * @memberOf module:ControlFlow
3477   * @method
3478   * @category Control Flow
3479   * @param {AsyncFunction} fn - an async function to call repeatedly.
3480   * Invoked with (next).
3481   * @param {Function} [errback] - when `fn` passes an error to it's callback,
3482   * this function will be called, and execution stops. Invoked with (err).
3483   * @example
3484   *
3485   * async.forever(
3486   *     function(next) {
3487   *         // next is suitable for passing to things that need a callback(err [, whatever]);
3488   *         // it will result in this function being called again.
3489   *     },
3490   *     function(err) {
3491   *         // if next is called with a value in its first parameter, it will appear
3492   *         // in here as 'err', and execution will stop.
3493   *     }
3494   * );
3495   */
3496  function forever(fn, errback) {
3497      var done = onlyOnce(errback || noop);
3498      var task = wrapAsync(ensureAsync(fn));
3499  
3500      function next(err) {
3501          if (err) return done(err);
3502          task(next);
3503      }
3504      next();
3505  }
3506  
3507  /**
3508   * The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.
3509   *
3510   * @name groupByLimit
3511   * @static
3512   * @memberOf module:Collections
3513   * @method
3514   * @see [async.groupBy]{@link module:Collections.groupBy}
3515   * @category Collection
3516   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3517   * @param {number} limit - The maximum number of async operations at a time.
3518   * @param {AsyncFunction} iteratee - An async function to apply to each item in
3519   * `coll`.
3520   * The iteratee should complete with a `key` to group the value under.
3521   * Invoked with (value, callback).
3522   * @param {Function} [callback] - A callback which is called when all `iteratee`
3523   * functions have finished, or an error occurs. Result is an `Object` whoses
3524   * properties are arrays of values which returned the corresponding key.
3525   */
3526  var groupByLimit = function(coll, limit, iteratee, callback) {
3527      callback = callback || noop;
3528      var _iteratee = wrapAsync(iteratee);
3529      mapLimit(coll, limit, function(val, callback) {
3530          _iteratee(val, function(err, key) {
3531              if (err) return callback(err);
3532              return callback(null, {key: key, val: val});
3533          });
3534      }, function(err, mapResults) {
3535          var result = {};
3536          // from MDN, handle object having an `hasOwnProperty` prop
3537          var hasOwnProperty = Object.prototype.hasOwnProperty;
3538  
3539          for (var i = 0; i < mapResults.length; i++) {
3540              if (mapResults[i]) {
3541                  var key = mapResults[i].key;
3542                  var val = mapResults[i].val;
3543  
3544                  if (hasOwnProperty.call(result, key)) {
3545                      result[key].push(val);
3546                  } else {
3547                      result[key] = [val];
3548                  }
3549              }
3550          }
3551  
3552          return callback(err, result);
3553      });
3554  };
3555  
3556  /**
3557   * Returns a new object, where each value corresponds to an array of items, from
3558   * `coll`, that returned the corresponding key. That is, the keys of the object
3559   * correspond to the values passed to the `iteratee` callback.
3560   *
3561   * Note: Since this function applies the `iteratee` to each item in parallel,
3562   * there is no guarantee that the `iteratee` functions will complete in order.
3563   * However, the values for each key in the `result` will be in the same order as
3564   * the original `coll`. For Objects, the values will roughly be in the order of
3565   * the original Objects' keys (but this can vary across JavaScript engines).
3566   *
3567   * @name groupBy
3568   * @static
3569   * @memberOf module:Collections
3570   * @method
3571   * @category Collection
3572   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3573   * @param {AsyncFunction} iteratee - An async function to apply to each item in
3574   * `coll`.
3575   * The iteratee should complete with a `key` to group the value under.
3576   * Invoked with (value, callback).
3577   * @param {Function} [callback] - A callback which is called when all `iteratee`
3578   * functions have finished, or an error occurs. Result is an `Object` whoses
3579   * properties are arrays of values which returned the corresponding key.
3580   * @example
3581   *
3582   * async.groupBy(['userId1', 'userId2', 'userId3'], function(userId, callback) {
3583   *     db.findById(userId, function(err, user) {
3584   *         if (err) return callback(err);
3585   *         return callback(null, user.age);
3586   *     });
3587   * }, function(err, result) {
3588   *     // result is object containing the userIds grouped by age
3589   *     // e.g. { 30: ['userId1', 'userId3'], 42: ['userId2']};
3590   * });
3591   */
3592  var groupBy = doLimit(groupByLimit, Infinity);
3593  
3594  /**
3595   * The same as [`groupBy`]{@link module:Collections.groupBy} but runs only a single async operation at a time.
3596   *
3597   * @name groupBySeries
3598   * @static
3599   * @memberOf module:Collections
3600   * @method
3601   * @see [async.groupBy]{@link module:Collections.groupBy}
3602   * @category Collection
3603   * @param {Array|Iterable|Object} coll - A collection to iterate over.
3604   * @param {number} limit - The maximum number of async operations at a time.
3605   * @param {AsyncFunction} iteratee - An async function to apply to each item in
3606   * `coll`.
3607   * The iteratee should complete with a `key` to group the value under.
3608   * Invoked with (value, callback).
3609   * @param {Function} [callback] - A callback which is called when all `iteratee`
3610   * functions have finished, or an error occurs. Result is an `Object` whoses
3611   * properties are arrays of values which returned the corresponding key.
3612   */
3613  var groupBySeries = doLimit(groupByLimit, 1);
3614  
3615  /**
3616   * Logs the result of an `async` function to the `console`. Only works in
3617   * Node.js or in browsers that support `console.log` and `console.error` (such
3618   * as FF and Chrome). If multiple arguments are returned from the async
3619   * function, `console.log` is called on each argument in order.
3620   *
3621   * @name log
3622   * @static
3623   * @memberOf module:Utils
3624   * @method
3625   * @category Util
3626   * @param {AsyncFunction} function - The function you want to eventually apply
3627   * all arguments to.
3628   * @param {...*} arguments... - Any number of arguments to apply to the function.
3629   * @example
3630   *
3631   * // in a module
3632   * var hello = function(name, callback) {
3633   *     setTimeout(function() {
3634   *         callback(null, 'hello ' + name);
3635   *     }, 1000);
3636   * };
3637   *
3638   * // in the node repl
3639   * node> async.log(hello, 'world');
3640   * 'hello world'
3641   */
3642  var log = consoleFunc('log');
3643  
3644  /**
3645   * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
3646   * time.
3647   *
3648   * @name mapValuesLimit
3649   * @static
3650   * @memberOf module:Collections
3651   * @method
3652   * @see [async.mapValues]{@link module:Collections.mapValues}
3653   * @category Collection
3654   * @param {Object} obj - A collection to iterate over.
3655   * @param {number} limit - The maximum number of async operations at a time.
3656   * @param {AsyncFunction} iteratee - A function to apply to each value and key
3657   * in `coll`.
3658   * The iteratee should complete with the transformed value as its result.
3659   * Invoked with (value, key, callback).
3660   * @param {Function} [callback] - A callback which is called when all `iteratee`
3661   * functions have finished, or an error occurs. `result` is a new object c
3661onsisting
3662   * of each key from `obj`, with each transformed value on the right-hand side.
3663   * Invoked with (err, result).
3664   */
3665  function mapValuesLimit(obj, limit, iteratee, callback) {
3666      callback = once(callback || noop);
3667      var newObj = {};
3668      var _iteratee = wrapAsync(iteratee);
3669      eachOfLimit(obj, limit, function(val, key, next) {
3670          _iteratee(val, key, function (err, result) {
3671              if (err) return next(err);
3672              newObj[key] = result;
3673              next();
3674          });
3675      }, function (err) {
3676          callback(err, newObj);
3677      });
3678  }
3679  
3680  /**
3681   * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
3682   *
3683   * Produces a new Object by mapping each value of `obj` through the `iteratee`
3684   * function. The `iteratee` is called each `value` and `key` from `obj` and a
3685   * callback for when it has finished processing. Each of these callbacks takes
3686   * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
3687   * passes an error to its callback, the main `callback` (for the `mapValues`
3688   * function) is immediately called with the error.
3689   *
3690   * Note, the order of the keys in the result is not guaranteed.  The keys will
3691   * be roughly in the order they complete, (but this is very engine-specific)
3692   *
3693   * @name mapValues
3694   * @static
3695   * @memberOf module:Collections
3696   * @method
3697   * @category Collection
3698   * @param {Object} obj - A collection to iterate over.
3699   * @param {AsyncFunction} iteratee - A function to apply to each value and key
3700   * in `coll`.
3701   * The iteratee should complete with the transformed value as its result.
3702   * Invoked with (value, key, callback).
3703   * @param {Function} [callback] - A callback which is called when all `iteratee`
3704   * functions have finished, or an error occurs. `result` is a new object consisting
3705   * of each key from `obj`, with each transformed value on the right-hand side.
3706   * Invoked with (err, result).
3707   * @example
3708   *
3709   * async.mapValues({
3710   *     f1: 'file1',
3711   *     f2: 'file2',
3712   *     f3: 'file3'
3713   * }, function (file, key, callback) {
3714   *   fs.stat(file, callback);
3715   * }, function(err, result) {
3716   *     // result is now a map of stats for each file, e.g.
3717   *     // {
3718   *     //     f1: [stats for file1],
3719   *     //     f2: [stats for file2],
3720   *     //     f3: [stats for file3]
3721   *     // }
3722   * });
3723   */
3724  
3725  var mapValues = doLimit(mapValuesLimit, Infinity);
3726  
3727  /**
3728   * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time.
3729   *
3730   * @name mapValuesSeries
3731   * @static
3732   * @memberOf module:Collections
3733   * @method
3734   * @see [async.mapValues]{@link module:Collections.mapValues}
3735   * @category Collection
3736   * @param {Object} obj - A collection to iterate over.
3737   * @param {AsyncFunction} iteratee - A function to apply to each value and key
3738   * in `coll`.
3739   * The iteratee should complete with the transformed value as its result.
3740   * Invoked with (value, key, callback).
3741   * @param {Function} [callback] - A callback which is called when all `iteratee`
3742   * functions have finished, or an error occurs. `result` is a new object consisting
3743   * of each key from `obj`, with each transformed value on the right-hand side.
3744   * Invoked with (err, result).
3745   */
3746  var mapValuesSeries = doLimit(mapValuesLimit, 1);
3747  
3748  function has(obj, key) {
3749      return key in obj;
3750  }
3751  
3752  /**
3753   * Caches the results of an async function. When creating a hash to store
3754   * function results against, the callback is omitted from the hash and an
3755   * optional hash function can be used.
3756   *
3757   * If no hash function is specified, the first argument is used as a hash key,
3758   * which may work reasonably if it is a string or a data type that converts to a
3759   * distinct string. Note that objects and arrays will not behave reasonably.
3760   * Neither will cases where the other arguments are significant. In such cases,
3761   * specify your own hash function.
3762   *
3763   * The cache of results is exposed as the `memo` property of the function
3764   * returned by `memoize`.
3765   *
3766   * @name memoize
3767   * @static
3768   * @memberOf module:Utils
3769   * @method
3770   * @category Util
3771   * @param {AsyncFunction} fn - The async function to proxy and cache results from.
3772   * @param {Function} hasher - An optional function for generating a custom hash
3773   * for storing results. It has all the arguments applied to it apart from the
3774   * callback, and must be synchronous.
3775   * @returns {AsyncFunction}
3775 a memoized version of `fn`
3776   * @example
3777   *
3778   * var slow_fn = function(name, callback) {
3779   *     // do something
3780   *     callback(null, result);
3781   * };
3782   * var fn = async.memoize(slow_fn);
3783   *
3784   * // fn can now be used as if it were slow_fn
3785   * fn('some name', function() {
3786   *     // callback
3787   * });
3788   */
3789  function memoize(fn, hasher) {
3790      var memo = Object.create(null);
3791      var queues = Object.create(null);
3792      hasher = hasher || identity;
3793      var _fn = wrapAsync(fn);
3794      var memoized = initialParams(function memoized(args, callback) {
3795          var key = hasher.apply(null, args);
3796          if (has(memo, key)) {
3797              setImmediate$1(function() {
3798                  callback.apply(null, memo[key]);
3799              });
3800          } else if (has(queues, key)) {
3801              queues[key].push(callback);
3802          } else {
3803              queues[key] = [callback];
3804              _fn.apply(null, args.concat(function(/*args*/) {
3805                  var args = slice(arguments);
3806                  memo[key] = args;
3807                  var q = queues[key];
3808                  delete queues[key];
3809                  for (var i = 0, l = q.length; i < l; i++) {
3810                      q[i].apply(null, args);
3811                  }
3812              }));
3813          }
3814      });
3815      memoized.memo = memo;
3816      memoized.unmemoized = fn;
3817      return memoized;
3818  }
3819  
3820  /**
3821   * Calls `callback` on a later loop around the event loop. In Node.js this just
3822   * calls `process.nextTicl`.  In the browser it will use `setImmediate` if
3823   * available, otherwise `setTimeout(callback, 0)`, which means other higher
3824   * priority events may precede the execution of `callback`.
3825   *
3826   * This is used internally for browser-compatibility purposes.
3827   *
3828   * @name nextTick
3829   * @static
3830   * @memberOf module:Utils
3831   * @method
3832   * @see [async.setImmediate]{@link module:Utils.setImmediate}
3833   * @category Util
3834   * @param {Function} callback - The function to call on a later loop around
3835   * the event loop. Invoked with (args...).
3836   * @param {...*} args... - any number of additional arguments to pass to the
3837   * callback on the next tick.
3838   * @example
3839   *
3840   * var call_order = [];
3841   * async.nextTick(function() {
3842   *     call_order.push('two');
3843   *     // call_order now equals ['one','two']
3844   * });
3845   * call_order.push('one');
3846   *
3847   * async.setImmediate(function (a, b, c) {
3848   *     // a, b, and c equal 1, 2, and 3
3849   * }, 1, 2, 3);
3850   */
3851  var _defer$1;
3852  
3853  if (hasNextTick) {
3854      _defer$1 = process.nextTick;
3855  } else if (hasSetImmediate) {
3856      _defer$1 = setImmediate;
3857  } else {
3858      _defer$1 = fallback;
3859  }
3860  
3861  var nextTick = wrap(_defer$1);
3862  
3863  function _parallel(eachfn, tasks, callback) {
3864      callback = callback || noop;
3865      var results = isArrayLike(tasks) ? [] : {};
3866  
3867      eachfn(tasks, function (task, key, callback) {
3868          wrapAsync(task)(function (err, result) {
3869              if (arguments.length > 2) {
3870                  result = slice(arguments, 1);
3871              }
3872              results[key] = result;
3873              callback(err);
3874          });
3875      }, function (err) {
3876          callback(err, results);
3877      });
3878  }
3879  
3880  /**
3881   * Run the `tasks` collection of functions in parallel, without waiting until
3882   * the previous function has completed. If any of the functions pass an error to
3883   * its callback, the main `callback` is immediately called with the value of the
3884   * error. Once the `tasks` have completed, the results are passed to the final
3885   * `callback` as an array.
3886   *
3887   * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
3888   * parallel execution of code.  If your tasks do not use any timers or perform
3889   * any I/O, they will actually be executed in series.  Any synchronous setup
3890   * sections for each task will happen one after the other.  JavaScript remains
3891   * single-threaded.
3892   *
3893   * **Hint:** Use [`reflect`]{@link module:Utils.reflect} to continue the
3894   * execution of other tasks when a task fails.
3895   *
3896   * It is also possible to use an object instead of an array. Each property will
3897   * be run as a function and the results will be passed to the final `callback`
3898   * as an object instead of an array. This can be a more readable way of handling
3899   * results from {@link async.parallel}.
3900   *
3901   * @name parallel
3902   * @static
3903   * @memberOf module:ControlFlow
3904   * @method
3905   * @category Control Flow
3906   * @param {Array|Iterable|Object}
3906 tasks - A collection of
3907   * [async functions]{@link AsyncFunction} to run.
3908   * Each async function can complete with any number of optional `result` values.
3909   * @param {Function} [callback] - An optional callback to run once all the
3910   * functions have completed successfully. This function gets a results array
3911   * (or object) containing all the result arguments passed to the task callbacks.
3912   * Invoked with (err, results).
3913   *
3914   * @example
3915   * async.parallel([
3916   *     function(callback) {
3917   *         setTimeout(function() {
3918   *             callback(null, 'one');
3919   *         }, 200);
3920   *     },
3921   *     function(callback) {
3922   *         setTimeout(function() {
3923   *             callback(null, 'two');
3924   *         }, 100);
3925   *     }
3926   * ],
3927   * // optional callback
3928   * function(err, results) {
3929   *     // the results array will equal ['one','two'] even though
3930   *     // the second function had a shorter timeout.
3931   * });
3932   *
3933   * // an example using an object instead of an array
3934   * async.parallel({
3935   *     one: function(callback) {
3936   *         setTimeout(function() {
3937   *             callback(null, 1);
3938   *         }, 200);
3939   *     },
3940   *     two: function(callback) {
3941   *         setTimeout(function() {
3942   *             callback(null, 2);
3943   *         }, 100);
3944   *     }
3945   * }, function(err, results) {
3946   *     // results is now equals to: {one: 1, two: 2}
3947   * });
3948   */
3949  function parallelLimit(tasks, callback) {
3950      _parallel(eachOf, tasks, callback);
3951  }
3952  
3953  /**
3954   * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
3955   * time.
3956   *
3957   * @name parallelLimit
3958   * @static
3959   * @memberOf module:ControlFlow
3960   * @method
3961   * @see [async.parallel]{@link module:ControlFlow.parallel}
3962   * @category Control Flow
3963   * @param {Array|Iterable|Object} tasks - A collection of
3964   * [async functions]{@link AsyncFunction} to run.
3965   * Each async function can complete with any number of optional `result` values.
3966   * @param {number} limit - The maximum number of async operations at a time.
3967   * @param {Function} [callback] - An optional callback to run once all the
3968   * functions have completed successfully. This function gets a results array
3969   * (or object) containing all the result arguments passed to the task callbacks.
3970   * Invoked with (err, results).
3971   */
3972  function parallelLimit$1(tasks, limit, callback) {
3973      _parallel(_eachOfLimit(limit), tasks, callback);
3974  }
3975  
3976  /**
3977   * A queue of tasks for the worker function to complete.
3978   * @typedef {Object} QueueObject
3979   * @memberOf module:ControlFlow
3980   * @property {Function} length - a function returning the number of items
3981   * waiting to be processed. Invoke with `queue.length()`.
3982   * @property {boolean} started - a boolean indicating whether or not any
3983   * items have been pushed and processed by the queue.
3984   * @property {Function} running - a function returning the number of items
3985   * currently being processed. Invoke with `queue.running()`.
3986   * @property {Function} workersList - a function returning the array of items
3987   * currently being processed. Invoke with `queue.workersList()`.
3988   * @property {Function} idle - a function returning false if there are items
3989   * waiting or being processed, or true if not. Invoke with `queue.idle()`.
3990   * @property {number} concurrency - an integer for determining how many `worker`
3991   * functions should be run in parallel. This property can be changed after a
3992   * `queue` is created to alter the concurrency on-the-fly.
3993   * @property {Function} push - add a new task to the `queue`. Calls `callback`
3994   * once the `worker` has finished processing the task. Instead of a single task,
3995   * a `tasks` array can be submitted. The respective callback is used for every
3996   * task in the list. Invoke with `queue.push(task, [callback])`,
3997   * @property {Function} unshift - add a new task to the front of the `queue`.
3998   * Invoke with `queue.unshift(task, [callback])`.
3999   * @property {Function} remove - remove items from the queue that match a test
4000   * function.  The test function will be passed an object with a `data` property,
4001   * and a `priority` property, if this is a
4002   * [priorityQueue]{@link module:ControlFlow.priorityQueue} object.
4003   * Invoked with `queue.remove(testFn)`, where `testFn` is of the form
4004   * `function ({data, priority}) {}` and returns a Boolean.
4005   * @property {Function} saturated - a callback that is called when the number of
4006   * running workers hits the `concurrency` limit, and further tasks will be
4007   * queued.
4008   * @property {Function} unsaturated - a callback that is called when the number
4009   * of running workers is less than the `concurrency` & `buffer` limits, and
4010   * further tasks will not be queued.
4011   * @property {number} buffer - A minimum threshold buffer in order to say that
4012   * the `queue` is `unsaturated`.
4013   * @property {Function} empty - a callback that is called when the last item
4014   * from the `queue` is given to a `worker`.
4015   * @property {Function} drain - a callback that is called when the last item
4016   * from the `queue` has returned from the `worker`.
4017   * @property {Function} error - a callback that is called when a task errors.
4018   * Has the signature `function(error, task)`.
4019   * @property {boolean} paused - a boolean for determining whether the queue is
4020   * in a paused state.
4021   * @property {Function} pause - a function that pauses the processing of tasks
4022   * until `resume()` is called. Invoke with `queue.pause()`.
4023   * @property {Function} resume - a function that resumes the processing of
4024   * queued tasks when the queue is paused. Invoke with `queue.resume()`.
4025   * @property {Function} kill - a function that removes the `drain` callback and
4026   * empties remaining tasks from the queue forcing it to go idle. No more tasks
4027   * should be pushed to the queue after calling this function. Invoke with `queue.kill()`.
4028   */
4029  
4030  /**
4031   * Creates a `queue` object with the specified `concurrency`. Tasks added to the
4032   * `queue` are processed in parallel (up to the `concurrency` limit). If all
4033   * `worker`s are in progress, the task is queued until one becomes available.
4034   * Once a `worker` completes a `task`, that `task`'s callback is called.
4035   *
4036   * @name queue
4037   * @static
4038   * @memberOf module:ControlFlow
4039   * @method
4040   * @category Control Flow
4041   * @param {AsyncFunction} worker - An async function for processing a queued task.
4042   * If you want to handle errors from an individual task, pass a callback to
4043   * `q.push()`. Invoked with (task, callback).
4044   * @param {number} [concurrency=1] - An `integer` for determining how many
4045   * `worker` functions should be run in parallel.  If omitted, the concurrency
4046   * defaults to `1`.  If the concurrency is `0`, an error is thrown.
4047   * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
4048   * attached as certain properties to listen for specific events during the
4049   * lifecycle of the queue.
4050   * @example
4051   *
4052   * // create a queue object with concurrency 2
4053   * var q = async.queue(function(task, callback) {
4054   *     console.log('hello ' + task.name);
4055   *     callback();
4056   * }, 2);
4057   *
4058   * // assign a callback
4059   * q.drain = function() {
4060   *     console.log('all items have been processed');
4061   * };
4062   *
4063   * // add some items to the queue
4064   * q.push({name: 'foo'}, function(err) {
4065   *     console.log('finished processing foo');
4066   * });
4067   * q.push({name: 'bar'}, function (err) {
4068   *     console.log('finished processing bar');
4069   * });
4070   *
4071   * // add some items to the queue (batch-wise)
4072   * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
4073   *     console.log('finished processing item');
4074   * });
4075   *
4076   * // add some items to the front of the queue
4077   * q.unshift({name: 'bar'}, function (err) {
4078   *     console.log('finished processing bar');
4079   * });
4080   */
4081  var queue$1 = function (worker, concurrency) {
4082      var _worker = wrapAsync(worker);
4083      return queue(function (items, cb) {
4084          _worker(items[0], cb);
4085      }, concurrency, 1);
4086  };
4087  
4088  /**
4089   * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
4090   * completed in ascending priority order.
4091   *
4092   * @name priorityQueue
4093   * @static
4094   * @memberOf module:ControlFlow
4095   * @method
4096   * @see [async.queue]{@link module:ControlFlow.queue}
4097   * @category Control Flow
4098   * @param {AsyncFunction} worker - An async function for processing a queued task.
4099   * If you want to handle errors from an individual task, pass a callback to
4100   * `q.push()`.
4101   * Invoked with (task, callback).
4102   * @param {number} concurrency - An `integer` for determining how many `worker`
4103   * functions should be run in parallel.  If omitted, the concurrency defaults to
4104   * `1`.  If the concurrency is `0`, an error is thrown.
4105   * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two
4106   * differences between `queue` and `priorityQueue` objects:
4107   * * `push(task, priority, [callback])` - `priority` should be a number. If an
4108   *   array of `tasks` is given, all tasks will be assigned the same priority.
4109   * * The `unshift` method was removed.
4110   */
4111  var priorityQueue = function(worker, concurrency) {
4112      // Start with a normal queue
4113      var q = queue$1(worker, concurrency);
4114  
4115      // Override push to accept second parameter representing priority
vendor: 4,643 bytes, lines 4116-4250
4116      q.push = function(data, priority, callback) {
4117          if (callback == null) callback = noop;
4118          if (typeof callback !== 'function') {
4119              throw new Error('task callback must be a function');
4120          }
4121          q.started = true;
4122          if (!isArray(data)) {
4123              data = [data];
4124          }
4125          if (data.length === 0) {
4126              // call drain immediately if there are no tasks
4127              return setImmediate$1(function() {
4128                  q.drain();
4129              });
4130          }
4131  
4132          priority = priority || 0;
4133          var nextNode = q._tasks.head;
4134          while (nextNode && priority >= nextNode.priority) {
4135              nextNode = nextNode.next;
4136          }
4137  
4138          for (var i = 0, l = data.length; i < l; i++) {
4139              var item = {
4140                  data: data[i],
4141                  priority: priority,
4142                  callback: callback
4143              };
4144  
4145              if (nextNode) {
4146                  q._tasks.insertBefore(nextNode, item);
4147              } else {
4148                  q._tasks.push(item);
4149              }
4150          }
4151          setImmediate$1(q.process);
4152      };
4153  
4154      // Remove unshift function
4155      delete q.unshift;
4156  
4157      return q;
4158  };
4159  
4160  /**
4161   * Runs the `tasks` array of functions in parallel, without waiting until the
4162   * previous function has completed. Once any of the `tasks` complete or pass an
4163   * error to its callback, the main `callback` is immediately called. It's
4164   * equivalent to `Promise.race()`.
4165   *
4166   * @name race
4167   * @static
4168   * @memberOf module:ControlFlow
4169   * @method
4170   * @category Control Flow
4171   * @param {Array} tasks - An array containing [async functions]{@link AsyncFunction}
4172   * to run. Each function can complete with an optional `result` value.
4173   * @param {Function} callback - A callback to run once any of the functions have
4174   * completed. This function gets an error or result from the first function that
4175   * completed. Invoked with (err, result).
4176   * @returns undefined
4177   * @example
4178   *
4179   * async.race([
4180   *     function(callback) {
4181   *         setTimeout(function() {
4182   *             callback(null, 'one');
4183   *         }, 200);
4184   *     },
4185   *     function(callback) {
4186   *         setTimeout(function() {
4187   *             callback(null, 'two');
4188   *         }, 100);
4189   *     }
4190   * ],
4191   * // main callback
4192   * function(err, result) {
4193   *     // the result will be equal to 'two' as it finishes earlier
4194   * });
4195   */
4196  function race(tasks, callback) {
4197      callback = once(callback || noop);
4198      if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
4199      if (!tasks.length) return callback();
4200      for (var i = 0, l = tasks.length; i < l; i++) {
4201          wrapAsync(tasks[i])(callback);
4202      }
4203  }
4204  
4205  /**
4206   * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
4207   *
4208   * @name reduceRight
4209   * @static
4210   * @memberOf module:Collections
4211   * @method
4212   * @see [async.reduce]{@link module:Collections.reduce}
4213   * @alias foldr
4214   * @category Collection
4215   * @param {Array} array - A collection to iterate over.
4216   * @param {*} memo - The initial state of the reduction.
4217   * @param {AsyncFunction} iteratee - A function applied to each item in the
4218   * array to produce the next step in the reduction.
4219   * The `iteratee` should complete with the next state of the reduction.
4220   * If the iteratee complete with an error, the reduction is stopped and the
4221   * main `callback` is immediately called with the error.
4222   * Invoked with (memo, item, callback).
4223   * @param {Function} [callback] - A callback which is called after all the
4224   * `iteratee` functions have finished. Result is the reduced value. Invoked with
4225   * (err, result).
4226   */
4227  function reduceRight (array, memo, iteratee, callback) {
4228      var reversed = slice(array).reverse();
4229      reduce(reversed, memo, iteratee, callback);
4230  }
4231  
4232  /**
4233   * Wraps the async function in another function that always completes with a
4234   * result object, even when it errors.
4235   *
4236   * The result object has either the property `error` or `value`.
4237   *
4238   * @name reflect
4239   * @static
4240   * @memberOf module:Utils
4241   * @method
4242   * @category Util
4243   * @param {AsyncFunction} fn - The async function you want to wrap
4244   * @returns {Function} - A function that always passes null to it's callback as
4245   * the error. The second argument to the callback will be an `object` with
4246   * either an `error` or a `value` property.
4247   * @example
4248   *
4249   * async.parallel([
4250   *     async.reflect(function(callback) {
4251   *         // do some stuff ...
4252   *         callback(null, 'one');
4253   *     }),
4254   *     async.reflect(function(callback) {
4255   *         // do some more stuff but error ...
4256   *         callback('bad stuff happened');
4257   *     }),
4258   *     async.reflect(function(callback) {
4259   *         // do some more stuff ...
4260   *         callback(null, 'two');
4261   *     })
4262   * ],
4263   * // optional callback
4264   * function(err, results) {
4265   *     // values
4266   *     // results[0].value = 'one'
4267   *     // results[1].error = 'bad stuff happened'
4268   *     // results[2].value = 'two'
4269   * });
4270   */
4271  function reflect(fn) {
4272      var _fn = wrapAsync(fn);
4273      return initialParams(function reflectOn(args, reflectCallback) {
4274          args.push(function callback(error, cbArg) {
4275              if (error) {
4276                  reflectCallback(null, { error: error });
4277              } else {
4278                  var value;
4279                  if (arguments.length <= 2) {
4280                      value = cbArg;
4281                  } else {
4282                      value = slice(arguments, 1);
4283                  }
4284                  reflectCallback(null, { value: value });
4285              }
4286          });
4287  
4288          return _fn.apply(this, args);
4289      });
4290  }
4291  
4292  /**
4293   * A helper function that wraps an array or an object of functions with `reflect`.
4294   *
4295   * @name reflectAll
4296   * @static
4297   * @memberOf module:Utils
4298   * @method
4299   * @see [async.reflect]{@link module:Utils.reflect}
4300   * @category Util
4301   * @param {Array|Object|Iterable} tasks - The collection of
4302   * [async functions]{@link AsyncFunction} to wrap in `async.reflect`.
4303   * @returns {Array} Returns an array of async functions, each wrapped in
4304   * `async.reflect`
4305   * @example
4306   *
4307   * let tasks = [
4308   *     function(callback) {
4309   *         setTimeout(function() {
4310   *             callback(null, 'one');
4311   *         }, 200);
4312   *     },
4313   *     function(callback) {
4314   *         // do some more stuff but error ...
4315   *         callback(new Error('bad stuff happened'));
4316   *     },
4317   *     function(callback) {
4318   *         setTimeout(function() {
4319   *             callback(null, 'two');
4320   *         }, 100);
4321   *     }
4322   * ];
4323   *
4324   * async.parallel(async.reflectAll(tasks),
4325   * // optional callback
4326   * function(err, results) {
4327   *     // values
4328   *     // results[0].value = 'one'
4329   *     // results[1].error = Error('bad stuff happened')
4330   *     // results[2].value = 'two'
4331   * });
4332   *
4333   * // an example using an object instead of an array
4334   * let tasks = {
4335   *     one: function(callback) {
4336   *         setTimeout(function() {
4337   *             callback(null, 'one');
4338   *         }, 200);
4339   *     },
4340   *     two: function(callback) {
4341   *         callback('two');
4342   *     },
4343   *     three: function(callback) {
4344   *         setTimeout(function() {
4345   *             callback(null, 'three');
4346   *         }, 100);
4347   *     }
4348   * };
4349   *
4350   * async.parallel(async.reflectAll(tasks),
4351   * // optional callback
4352   * function(err, results) {
4353   *     // values
4354   *     // results.one.value = 'one'
4355   *     // results.two.error = 'two'
4356   *     // results.three.value = 'three'
4357   * });
4358   */
4359  function reflectAll(tasks) {
4360      var results;
4361      if (isArray(tasks)) {
4362          results = arrayMap(tasks, reflect);
4363      } else {
4364          results = {};
4365          baseForOwn(tasks, function(task, key) {
4366              results[key] = reflect.call(this, task);
4367          });
4368      }
4369      return results;
4370  }
4371  
4372  function reject$1(eachfn, arr, iteratee, callback) {
4373      _filter(eachfn, arr, function(value, cb) {
4374          iteratee(value, function(err, v) {
4375              cb(err, !v);
4376          });
4377      }, callback);
4378  }
4379  
4380  /**
4381   * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
4382   *
4383   * @name reject
4384   * @static
4385   * @memberOf module:Collections
4386   * @method
4387   * @see [async.filter]{@link module:Collections.filter}
4388   * @category Collection
4389   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4390   * @param {Function} iteratee - An async truth test to apply to each item in
4391   * `coll`.
4392   * The should complete with a boolean value as its `result`.
4393   * Invoked with (item, callback).
4394   * @param {Function} [callback] - A callback which is called after all the
4395   * `iteratee` functions have finished. Invoked with (err, results).
4396   * @example
4397   *
4398   * async.reject(['file1','file2','file3'], function(filePath, callback) {
4399   *     fs.access(filePath, function(err) {
4400   *         callback(null, !err)
4401   *     });
4402   * }, function(err, results) {
4403   *     // results now equals an array of missing files
4404   *     createFiles(results);
4405   * });
4406   */
4407  var reject = doParallel(reject$1);
4408  
4409  /**
4410   * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
4411   * time.
4412   *
4413   * @name rejectLimit
4414   * @static
4415   * @memberOf module:Collections
4416   * @method
4417   * @see [async.reject]{@link module:Collections.reject}
4418   * @category Collection
4419   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4420   * @param {number} limit - The maximum number of async operations at a time.
4421   * @param {Function} iteratee - An async truth test to apply to each item in
4422   * `coll`.
4423   * The should complete with a boolean value as its `result`.
4424   * Invoked with (item, callback).
4425   * @param {Function} [callback] - A callback which is called after all the
4426   * `iteratee` functions have finished. Invoked with (err, results).
4427   */
4428  var rejectLimit = doParallelLimit(reject$1);
4429  
4430  /**
4431   * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time.
4432   *
4433   * @name rejectSeries
4434   * @static
4435   * @memberOf module:Collections
4436   * @method
4437   * @see [async.reject]{@link module:Collections.reject}
4438   * @category Collection
4439   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4440   * @param {Function} iteratee - An async truth test to apply to each item in
4441   * `coll`.
4442   * The should complete with a boolean value as its `result`.
4443   * Invoked with (item, callback).
4444   * @param {Function} [callback] - A callback which is called after all the
4445   * `iteratee` functions have finished. Invoked with (err, results).
4446   */
4447  var rejectSeries = doLimit(rejectLimit, 1);
4448  
4449  /**
4450   * Creates a function that returns `value`.
4451   *
4452   * @static
4453   * @memberOf _
4454   * @since 2.4.0
4455   * @category Util
4456   * @param {*} value The value to return from the new function.
4457   * @returns {Function} Returns the new constant function.
4458   * @example
4459   *
4460   * var objects = _.times(2, _.constant({ 'a': 1 }));
4461   *
4462   * console.log(objects);
4463   * // => [{ 'a': 1 }, { 'a': 1 }]
4464   *
4465   * console.log(objects[0] === objects[1]);
4466   * // => true
4467   */
4468  function constant$1(value) {
4469    return function() {
4470      return value;
4471    };
4472  }
4473  
4474  /**
4475   * Attempts to get a successful response from `task` no more than `times` times
4476   * before returning an error. If the task is successful, the `callback` will be
4477   * passed the result of the successful task. If all attempts fail, the callback
4478   * will be passed the error and result (if any) of the final attempt.
4479   *
4480   * @name retry
4481   * @static
4482   * @memberOf module:ControlFlow
4483   * @method
4484   * @category Control Flow
4485   * @see [async.retryable]{@link module:ControlFlow.retryable}
4486   * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
4487   * object with `times` and `interval` or a number.
4488   * * `times` - The number of attempts to make before giving up.  The default
4489   *   is `5`.
4490   * * `interval` - The time to wait between retries, in milliseconds.  The
4491   *   default is `0`. The interval may also be specified as a function of the
4492   *   retry count (see example).
4493   * * `errorFilter` - An optional synchronous function that is invoked on
4494   *   erroneous result. If it returns `true` the retry attempts will continue;
4495   *   if the function returns `false` the retry flow is aborted with the current
4496   *   attempt's error and result being returned to the final callback.
4497   *   Invoked with (err).
4498   * * If `opts` is a number, the number specifies the number of times to retry,
4499   *   with the default interval of `0`.
4500   * @param {AsyncFunction} task - An async function to retry.
4501   * Invoked with (callback).
4502   * @param {Function} [callback] - An optional callback which is called when the
4503   * task has succeeded, or after the final failed attempt. It receives the `err`
4504   * and `result` arguments of the last attempt at completing the `task`. Invoked
4505   * with (err, results).
4506   *
4507   * @example
4508   *
4509   * // The `retry` function can be used as a stand-alone control flow by passing
4510   * // a callback, as shown below:
4511   *
4512   * // try calling apiMethod 3 times
4513   * async.retry(3, apiMethod, function(err, result) {
4514   *     // do something with the result
4515   * });
4516   *
4517   * // try calling apiMethod 3 times, waiting 200 ms between each retry
4518   * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
4519   *     // do something with the result
4520   * });
4521   *
4522   * // try calling apiMethod 10 times with exponential backoff
4523   * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
4524   * async.retry({
4525   *   times: 10,
4526   *   interval: function(retryCount) {
4527   *     return 50 * Math.pow(2, retryCount);
4528   *   }
4529   * }, apiMethod, function(err, result) {
4530   *     // do something with the result
4531   * });
4532   *
4533   * // try calling apiMethod the default 5 times no delay between each retry
4534   * async.retry(apiMethod, function(err, result) {
4535   *     // do something with the result
4536   * });
4537   *
4538   * // try calling apiMethod only when error condition satisfies, all other
4539   * // errors will abort the retry control flow and return to final callback
4540   * async.retry({
4541   *   errorFilter: function(err) {
4542   *     return err.message === 'Temporary error'; // only retry on a specific error
4543   *   }
4544   * }, apiMethod, function(err, result) {
4545   *     // do something with the result
4546   * });
4547   *
4548   * // to retry individual methods that are not as reliable within other
4549   * // control flow functions, use the `retryable` wrapper:
4550   * async.auto({
4551   *     users: api.getUsers.bind(api),
4552   *     payments: async.retryable(3, api.getPayments.bind(api))
4553   * }, function(err, results) {
4554   *     // do something with the results
4555   * });
4556   *
4557   */
4558  function retry(opts, task, callback) {
4559      var DEFAULT_TIMES = 5;
4560      var DEFAULT_INTERVAL = 0;
4561  
4562      var options = {
4563          times: DEFAULT_TIMES,
4564          intervalFunc: constant$1(DEFAULT_INTERVAL)
4565      };
4566  
4567      function parseTimes(acc, t) {
4568          if (typeof t === 'object') {
4569              acc.times = +t.times || DEFAULT_TIMES;
4570  
4571              acc.intervalFunc = typeof t.interval === 'function' ?
4572                  t.interval :
4573                  constant$1(+t.interval || DEFAULT_INTERVAL);
4574  
4575              acc.errorFilter = t.errorFilter;
4576          } else if (typeof t === 'number' || typeof t === 'string') {
4577              acc.times = +t || DEFAULT_TIMES;
4578          } else {
4579              throw new Error("Invalid arguments for async.retry");
4580          }
4581      }
4582  
4583      if (arguments.length < 3 && typeof opts === 'function') {
4584          callback = task || noop;
4585          task = opts;
4586      } else {
4587          parseTimes(options, opts);
4588          callback = callback || noop;
4589      }
4590  
4591      if (typeof task !== 'function') {
4592          throw new Error("Invalid arguments for async.retry");
4593      }
4594  
4595      var _task = wrapAsync(task);
4596  
4597      var attempt = 1;
4598      function retryAttempt() {
4599          _task(function(err) {
4600              if (err && attempt++ < options.times &&
4601                  (typeof options.errorFilter != 'function' ||
4602                      options.errorFilter(err))) {
4603                  setTimeout(retryAttempt, options.intervalFunc(attempt));
4604              } else {
4605                  callback.apply(null, arguments);
4606              }
4607          });
4608      }
4609  
4610      retryAttempt();
4611  }
4612  
4613  /**
4614   * A close relative of [`retry`]{@link module:ControlFlow.retry}.  This method
4615   * wraps a task and makes it retryable, rather than immediately calling it
4616   * with retries.
4617   *
4618   * @name retryable
4619   * @static
4620   * @memberOf module:ControlFlow
4621   * @method
4622   * @see [async.retry]{@link module:ControlFlow.retry}
4623   * @category Control Flow
4624   * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
4625   * options, exactly the same as from `retry`
4626   * @param {AsyncFunction} task - the asynchronous function to wrap.
4627   * This function will be passed any arguments passed to the returned wrapper.
4628   * Invoked with (...args, callback).
4629   * @returns {AsyncFunction} The wrapped function, which when invoked, will
4630   * retry on an error, based on the parameters specified in `opts`.
4631   * This function will accept the same parameters as `task`.
4632   * @example
4633   *
4634   * async.auto({
4635   *     dep1: async.retryable(3, getFromFlakyService),
4636   *     process: ["dep1", async.retryable(3, function (results, cb) {
4637   *         maybeProcessData(results.dep1, cb);
4638   *     })]
4639   * }, callback);
4640   */
4641  var retryable = function (opts, task) {
4642      if (!task) {
4643          task = opts;
4644          opts = null;
4645      }
4646      var _task = wrapAsync(task);
4647      return initialParams(function (args, callback) {
4648          function taskFn(cb) {
4649              _task.apply(null, args.concat(cb));
4650          }
4651  
4652          if (opts) retry(opts, taskFn, callback);
4653          else retry(taskFn, callback);
4654  
4655      });
4656  };
4657  
4658  /**
4659   * Run the functions in the `tasks` collection in series, each one running once
4660   * the previous function has completed. If any functions in the series pass an
4661   * error to its callback, no more functions are run, and `callback` is
4662   * immediately called with the value of the error. Otherwise, `callback`
4663   * receives an array of results when `tasks` have completed.
4664   *
4665   * It is also possible to use an object instead of an array. Each property will
4666   * be run as a function, and the results will be passed to the final `callback`
4667   * as an object instead of an array. This can be a more readable way of handling
4668   *  results from {@link async.series}.
4669   *
4670   * **Note** that while many implementations preserve the order of object
4671   * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
4672   * explicitly states that
4673   *
4674   * > The mechanics and order of enumerating the properties is not specified.
4675   *
4676   * So if you rely on the order in which your series of functions are executed,
4677   * and want this to work on all platforms, consider using an array.
4678   *
4679   * @name series
4680   * @static
4681   * @memberOf module:ControlFlow
4682   * @method
4683   * @category Control Flow
4684   * @param {Array|Iterable|Object} tasks - A collection containing
4685   * [async functions]{@link AsyncFunction} to run in series.
4686   * Each function can complete with any number of optional `result` values.
4687   * @param {Function} [callback] - An optional callback to run once all the
4688   * functions have completed. This function gets a results array (or object)
4689   * containing all the result arguments passed to the `task` callbacks. Invoked
4690   * with (err, result).
4691   * @example
4692   * async.series([
4693   *     function(callback) {
4694   *         // do some stuff ...
4695   *         callback(null, 'one');
4696   *     },
4697   *     function(callback) {
4698   *         // do some more stuff ...
4699   *         callback(null, 'two');
4700   *     }
4701   * ],
4702   * // optional callback
4703   * function(err, results) {
4704   *     // results is now equal to ['one', 'two']
4705   * });
4706   *
4707   * async.series({
4708   *     one: function(callback) {
4709   *         setTimeout(function() {
4710   *             callback(null, 1);
4711   *         }, 200);
4712   *     },
4713   *     two: function(callback){
4714   *         setTimeout(function() {
4715   *             callback(null, 2);
4716   *         }, 100);
4717   *     }
4718   * }, function(err, results) {
4719   *     // results is now equal to: {one: 1, two: 2}
4720   * });
4721   */
4722  function series(tasks, callback) {
4723      _parallel(eachOfSeries, tasks, callback);
4724  }
4725  
4726  /**
4727   * Returns `true` if at least one element in the `coll` satisfies an async test.
4728   * If any iteratee call returns `true`, the main `callback` is immediately
4729   * called.
4730   *
4731   * @name some
4732   * @static
4733   * @memberOf module:Collections
4734   * @method
4735   * @alias any
4736   * @category Collection
4737   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4738   * @param {AsyncFunction} iteratee - An async truth test to apply to each item
4739   * in the collections in parallel.
4740   * The iteratee should complete with a boolean `result` value.
4741   * Invoked with (item, callback).
4742   * @param {Function} [callback] - A callback which is called as soon as any
4743   * iteratee returns `true`, or after all the iteratee functions have finished.
4744   * Result will be either `true` or `false` depending on the values of the async
4745   * tests. Invoked with (err, result).
4746   * @example
4747   *
4748   * async.some(['file1','file2','file3'], function(filePath, callback) {
4749   *     fs.access(filePath, function(err) {
4750   *         callback(null, !err)
4751   *     });
4752   * }, function(err, result) {
4753   *     // if result is true then at least one of the files exists
4754   * });
4755   */
4756  var some = doParallel(_createTester(Boolean, identity));
4757  
4758  /**
4759   * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
4760   *
4761   * @name someLimit
4762   * @static
4763   * @memberOf module:Collections
4764   * @method
4765   * @see [async.some]{@link module:Collections.some}
4766   * @alias anyLimit
4767   * @category Collection
4768   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4769   * @param {number} limit - The maximum number of async operations at a time.
4770   * @param {AsyncFunction} iteratee - An async truth test to apply to each item
4771   * in the collections in parallel.
4772   * The iteratee should complete with a boolean `result` value.
4773   * Invoked with (item, callback).
4774   * @param {Function} [callback] - A callback which is called as soon as any
4775   * iteratee returns `true`, or after all the iteratee functions have finished.
4776   * Result will be either `true` or `false` depending on the values of the async
4777   * tests. Invoked with (err, result).
4778   */
4779  var someLimit = doParallelLimit(_createTester(Boolean, identity));
4780  
4781  /**
4782   * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
4783   *
4784   * @name someSeries
4785   * @static
4786   * @memberOf module:Collections
4787   * @method
4788   * @see [async.some]{@link module:Collections.some}
4789   * @alias anySeries
4790   * @category Collection
4791   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4792   * @param {AsyncFunction} iteratee - An async truth test to apply to each item
4793   * in the collections in series.
4794   * The iteratee should complete with a boolean `result` value.
4795   * Invoked with (item, callback).
4796   * @param {Function} [callback] - A callback which is called as soon as any
4797   * iteratee returns `true`, or after all the iteratee functions have finished.
4798   * Result will be either `true` or `false` depending on the values of the async
4799   * tests. Invoked with (err, result).
4800   */
4801  var someSeries = doLimit(someLimit, 1);
4802  
4803  /**
4804   * Sorts a list by the results of running each `coll` value through an async
4805   * `iteratee`.
4806   *
4807   * @name sortBy
4808   * @static
4809   * @memberOf module:Collections
4810   * @method
4811   * @category Collection
4812   * @param {Array|Iterable|Object} coll - A collection to iterate over.
4813   * @param {AsyncFunction} iteratee - An async function to apply to each item in
4814   * `coll`.
4815   * The iteratee should complete with a value to use as the sort criteria as
4816   * its `result`.
4817   * Invoked with (item, callback).
4818   * @param {Function} callback - A callback which is called after all the
4819   * `iteratee` functions have finished, or an error occurs. Results is the items
4820   * from the original `coll` sorted by the values returned by the `iteratee`
4821   * calls. Invoked with (err, results).
4822   * @example
4823   *
4824   * async.sortBy(['file1','file2','file3'], function(file, callback) {
4825   *     fs.stat(file, function(err, stats) {
4826   *         callback(err, stats.mtime);
4827   *     });
4828   * }, function(err, results) {
4829   *     // results is now the original array of files sorted by
4830   *     // modified date
4831   * });
4832   *
4833   * // By modifying the callback parameter the
4834   * // sorting order can be influenced:
4835   *
4836   * // ascending order
4837   * async.sortBy([1,9,3,5], function(x, callback) {
4838   *     callback(null, x);
4839   * }, function(err,result) {
4840   *     // result callback
4841   * });
4842   *
4843   * // descending order
4844   * async.sortBy([1,9,3,5], function(x, callback) {
4845   *     callback(null, x*-1);    //<- x*-1 instead of x, turns the order around
4846   * }, function(err,result) {
4847   *     // result callback
4848   * });
4849   */
4850  function sortBy (coll, iteratee, callback) {
4851      var _iteratee = wrapAsync(iteratee);
4852      map(coll, function (x, callback) {
4853          _iteratee(x, function (err, criteria) {
4854              if (err) return callback(err);
4855              callback(null, {value: x, criteria: criteria});
4856          });
4857      }, function (err, results) {
4858          if (err) return callback(err);
4859          callback(null, arrayMap(results.sort(comparator), baseProperty('value')));
4860      });
4861  
4862      function comparator(left, right) {
4863          var a = left.criteria, b = right.criteria;
4864          return a < b ? -1 : a > b ? 1 : 0;
4865      }
4866  }
4867  
4868  /**
4869   * Sets a time limit on an asynchronous function. If the function does not call
4870   * its callback within the specified milliseconds, it will be called with a
4871   * timeout error. The code property for the error object will be `'ETIMEDOUT'`.
4872   *
4873   * @name timeout
4874   * @static
4875   * @memberOf module:Utils
4876   * @method
4877   * @category Util
4878   * @param {AsyncFunction} asyncFn - The async function to limit in time.
4879   * @param {number} milliseconds - The specified time limit.
4880   * @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
4881   * to timeout Error for more information..
4882   * @returns {AsyncFunction} Returns a wrapped function that can be used with any
4883   * of the control flow functions.
4884   * Invoke this function with the same parameters as you would `asyncFunc`.
4885   * @example
4886   *
4887   * function myFunction(foo, callback) {
4888   *     doAsyncTask(foo, function(err, data) {
4889   *         // handle errors
4890   *         if (err) return callback(err);
4891   *
4892   *         // do some stuff ...
4893   *
4894   *         // return processed data
4895   *         return callback(null, data);
4896   *     });
4897   * }
4898   *
4899   * var wrapped = async.timeout(myFunction, 1000);
4900   *
4901   * // call `wrapped` as you would `myFunction`
4902   * wrapped({ bar: 'bar' }, function(err, data) {
4903   *     // if `myFunction` takes < 1000 ms to execute, `err`
4904   *     // and `data` will have their expected values
4905   *
4906   *     // else `err` will be an Error with the code 'ETIMEDOUT'
4907   * });
4908   */
4909  function timeout(asyncFn, milliseconds, info) {
4910      var fn = wrapAsync(asyncFn);
4911  
4912      return initialParams(function (args, callback) {
4913          var timedOut = false;
4914          var timer;
4915  
4916          function timeoutCallback() {
4917              var name = asyncFn.name || 'anonymous';
4918              var error  = new Error('Callback function "' + name + '" timed out.');
4919              error.code = 'ETIMEDOUT';
4920              if (info) {
4921                  error.info = info;
4922              }
4923              timedOut = true;
4924              callback(error);
4925          }
4926  
4927          args.push(function () {
4928              if (!timedOut) {
4929                  callback.apply(null, arguments);
4930                  clearTimeout(timer);
4931              }
4932          });
4933  
4934          // setup timer and call original function
4935          timer = setTimeout(timeoutCallback, milliseconds);
4936          fn.apply(null, args);
4937      });
4938  }
4939  
4940  /* Built-in method references for those with the same name as other `lodash` methods. */
4941  var nativeCeil = Math.ceil;
4942  var nativeMax = Math.max;
4943  
4944  /**
4945   * The base implementation of `_.range` and `_.rangeRight` which doesn't
4946   * coerce arguments.
4947   *
4948   * @private
4949   * @param {number} start The start of the range.
4950   * @param {number} end The end of the range.
4951   * @param {number} step The value to increment or decrement by.
4952   * @param {boolean} [fromRight] Specify iterating from right to left.
4953   * @returns {Array} Returns the range of numbers.
4954   */
4955  function baseRange(start, end, step, fromRight) {
4956    var index = -1,
4957        length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
4958        result = Array(length);
4959  
4960    while (length--) {
4961      result[fromRight ? length : ++index] = start;
4962      start += step;
4963    }
4964    return result;
4965  }
4966  
4967  /**
4968   * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
4969   * time.
4970   *
4971   * @name timesLimit
4972   * @static
4973   * @memberOf module:ControlFlow
4974   * @method
4975   * @see [async.times]{@link module:ControlFlow.times}
4976   * @category Control Flow
4977   * @param {number} count - The number of times to run the function.
4978   * @param {number} limit - The maximum number of async operations at a time.
4979   * @param {AsyncFunction} iteratee - The async function to call `n` times.
4980   * Invoked with the iteration index and a callback: (n, next).
4981   * @param {Function} callback - see [async.map]{@link module:Collections.map}.
4982   */
4983  function timeLimit(count, limit, iteratee, callback) {
4984      var _iteratee = wrapAsync(iteratee);
4985      mapLimit(baseRange(0, count, 1), limit, _iteratee, callback);
4986  }
4987  
4988  /**
4989   * Calls the `iteratee` function `n` times, and accumulates results in the same
4990   * manner you would use with [map]{@link module:Collections.map}.
4991   *
4992   * @name times
4993   * @static
4994   * @memberOf module:ControlFlow
4995   * @method
4996   * @see [async.map]{@link module:Collections.map}
4997   * @category Control Flow
4998   * @param {number} n - The number of times to run the function.
4999   * @param {AsyncFunction} iteratee - The async function to call `n` times.
5000   * Invoked with the iteration index and a callback: (n, next).
5001   * @param {Function} callback - see {@link module:Collections.map}.
5002   * @example
5003   *
5004   * // Pretend this is some complicated async factory
5005   * var createUser = function(id, callback) {
5006   *     callback(null, {
5007   *         id: 'user' + id
5008   *     });
5009   * };
5010   *
5011   * // generate 5 users
5012   * async.times(5, function(n, next) {
5013   *     createUser(n, function(err, user) {
5014   *         next(err, user);
5015   *     });
5016   * }, function(err, users) {
5017   *     // we should now have 5 users
5018   * });
5019   */
5020  var times = doLimit(timeLimit, Infinity);
5021  
5022  /**
5023   * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time.
5024   *
5025   * @name timesSeries
5026   * @static
5027   * @memberOf module:ControlFlow
5028   * @method
5029   * @see [async.times]{@link module:ControlFlow.times}
5030   * @category Control Flow
5031   * @param {number} n - The number of times to run the function.
5032   * @param {AsyncFunction} iteratee - The async function to call `n` times.
5033   * Invoked with the iteration index and a callback: (n, next).
5034   * @param {Function} callback - see {@link module:Collections.map}.
5035   */
5036  var timesSeries = doLimit(timeLimit, 1);
5037  
5038  /**
5039   * A relative of `reduce`.  Takes an Object or Array, and iterates over each
5040   * element in series, each step potentially mutating an `accumulator` value.
5041   * The type of the accumulator defaults to the type of collection passed in.
5042   *
5043   * @name transform
5044   * @static
5045   * @memberOf module:Collections
5046   * @method
5047   * @category Collection
5048   * @param {Array|Iterable|Object} coll - A collection to iterate over.
5049   * @param {*} [accumulator] - The initial state of the transform.  If omitted,
5050   * it will default to an empty Object or Array, depending on the type of `coll`
5051   * @param {AsyncFunction} iteratee - A function applied to each item in the
5052   * collection that potentially modifies the accumulator.
5053   * Invoked with (accumulator, item, key, callback).
5054   * @param {Function} [callback] - A callback which is called after all the
5055   * `iteratee` functions have finished. Result is the transformed accumulator.
5056   * Invoked with (err, result).
5057   * @example
5058   *
5059   * async.transform([1,2,3], function(acc, item, index, callback) {
5060   *     // pointless async:
5061   *     process.nextTick(function() {
5062   *         acc.push(item * 2)
5063   *         callback(null)
5064   *     });
5065   * }, function(err, result) {
5066   *     // result is now equal to [2, 4, 6]
5067   * });
5068   *
5069   * @example
5070   *
5071   * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) {
5072   *     setImmediate(function () {
5073   *         obj[key] = val * 2;
5074   *         callback();
5075   *     })
5076   * }, function (err, result) {
5077   *     // result is equal to {a: 2, b: 4, c: 6}
5078   * })
5079   */
5080  function transform (coll, accumulator, iteratee, callback) {
5081      if (arguments.length <= 3) {
5082          callback = iteratee;
5083          iteratee = accumulator;
5084          accumulator = isArray(coll) ? [] : {};
5085      }
5086      callback = once(callback || noop);
5087      var _iteratee = wrapAsync(iteratee);
5088  
5089      eachOf(coll, function(v, k, cb) {
5090          _iteratee(accumulator, v, k, cb);
5091      }, function(err) {
5092          callback(err, accumulator);
5093      });
5094  }
5095  
5096  /**
5097   * It runs each task in series but stops whenever any of the functions were
5098   * successful. If one of the tasks were successful, the `callback` will be
5099   * passed the result of the successful task. If all tasks fail, the callback
5100   * will be passed the error and result (if any) of the final attempt.
5101   *
5102   * @name tryEach
5103   * @static
5104   * @memberOf module:ControlFlow
5105   * @method
5106   * @category Control Flow
5107   * @param {Array|Iterable|Object}
5107 tasks - A collection containing functions to
5108   * run, each function is passed a `callback(err, result)` it must call on
5109   * completion with an error `err` (which can be `null`) and an optional `result`
5110   * value.
5111   * @param {Function} [callback] - An optional callback which is called when one
5112   * of the tasks has succeeded, or all have failed. It receives the `err` and
5113   * `result` arguments of the last attempt at completing the `task`. Invoked with
5114   * (err, results).
5115   * @example
5116   * async.tryEach([
5117   *     function getDataFromFirstWebsite(callback) {
5118   *         // Try getting the data from the first website
5119   *         callback(err, data);
5120   *     },
5121   *     function getDataFromSecondWebsite(callback) {
5122   *         // First website failed,
5123   *         // Try getting the data from the backup website
5124   *         callback(err, data);
5125   *     }
5126   * ],
5127   * // optional callback
5128   * function(err, results) {
5129   *     Now do something with the data.
5130   * });
5131   *
5132   */
5133  function tryEach(tasks, callback) {
5134      var error = null;
5135      var result;
5136      callback = callback || noop;
5137      eachSeries(tasks, function(task, callback) {
5138          wrapAsync(task)(function (err, res/*, ...args*/) {
5139              if (arguments.length > 2) {
5140                  result = slice(arguments, 1);
5141              } else {
5142                  result = res;
5143              }
5144              error = err;
5145              callback(!err);
5146          });
5147      }, function () {
5148          callback(error, result);
5149      });
5150  }
5151  
5152  /**
5153   * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original,
5154   * unmemoized form. Handy for testing.
5155   *
5156   * @name unmemoize
5157   * @static
5158   * @memberOf module:Utils
5159   * @method
5160   * @see [async.memoize]{@link module:Utils.memoize}
5161   * @category Util
5162   * @param {AsyncFunction} fn - the memoized function
5163   * @returns {AsyncFunction} a function that calls the original unmemoized function
5164   */
5165  function unmemoize(fn) {
5166      return function () {
5167          return (fn.unmemoized || fn).apply(null, arguments);
5168      };
5169  }
5170  
5171  /**
5172   * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
5173   * stopped, or an error occurs.
5174   *
5175   * @name whilst
5176   * @static
5177   * @memberOf module:ControlFlow
5178   * @method
5179   * @category Control Flow
5180   * @param {Function} test - synchronous truth test to perform before each
5181   * execution of `iteratee`. Invoked with ().
5182   * @param {AsyncFunction} iteratee - An async function which is called each time
5183   * `test` passes. Invoked with (callback).
5184   * @param {Function} [callback] - A callback which is called after the test
5185   * function has failed and repeated execution of `iteratee` has stopped. `callback`
5186   * will be passed an error and any arguments passed to the final `iteratee`'s
5187   * callback. Invoked with (err, [results]);
5188   * @returns undefined
5189   * @example
5190   *
5191   * var count = 0;
5192   * async.whilst(
5193   *     function() { return count < 5; },
5194   *     function(callback) {
5195   *         count++;
5196   *         setTimeout(function() {
5197   *             callback(null, count);
5198   *         }, 1000);
5199   *     },
5200   *     function (err, n) {
5201   *         // 5 seconds have passed, n = 5
5202   *     }
5203   * );
5204   */
5205  function whilst(test, iteratee, callback) {
5206      callback = onlyOnce(callback || noop);
5207      var _iteratee = wrapAsync(iteratee);
5208      if (!test()) return callback(null);
5209      var next = function(err/*, ...args*/) {
5210          if (err) return callback(err);
5211          if (test()) return _iteratee(next);
5212          var args = slice(arguments, 1);
5213          callback.apply(null, [null].concat(args));
5214      };
5215      _iteratee(next);
5216  }
5217  
5218  /**
5219   * Repeatedly call `iteratee` until `test` returns `true`. Calls `callback` when
5220   * stopped, or an error occurs. `callback` will be passed an error and any
5221   * arguments passed to the final `iteratee`'s callback.
5222   *
5223   * The inverse of [whilst]{@link module:ControlFlow.whilst}.
5224   *
5225   * @name until
5226   * @static
5227   * @memberOf module:ControlFlow
5228   * @method
5229   * @see [async.whilst]{@link module:ControlFlow.whilst}
5230   * @category Control Flow
5231   * @param {Function} test - synchronous truth test to perform before each
5232   * execution of `iteratee`. Invoked with ().
5233   * @param {AsyncFunction} iteratee - An async function which is called each time
5234   * `test` fails. Invoked with (callback).
5235   * @param {Function} [callback] - A callback which is called after the test
5236   * function has passed and repeated execution of `iteratee` has stopped. `callback`
5237   * will be passed an error and any arguments passed to the final `iteratee`'s
5238   * callback. Invoked with (err, [results]);
5239   */
5240  function until(test, iteratee, callback) {
5241      whilst(function() {
5242          return !test.apply(this, arguments);
5243      }, iteratee, callback);
5244  }
5245  
5246  /**
5247   * Runs the `tasks` array of functions in series, each passing their results to
5248   * the next in the array. However, if any of the `tasks` pass an error to their
5249   * own callback, the next function is not executed, and the main `callback` is
5250   * immediately called with the error.
5251   *
5252   * @name waterfall
5253   * @static
5254   * @memberOf module:ControlFlow
5255   * @method
5256   * @category Control Flow
5257   * @param {Array} tasks - An array of [async functions]{@link AsyncFunction}
5258   * to run.
5259   * Each function should complete with any number of `result` values.
5260   * The `result` values will be passed as arguments, in order, to the next task.
5261   * @param {Function} [callback] - An optional callback to run once all the
5262   * functions have completed. This will be passed the results of the last task's
5263   * callback. Invoked with (err, [results]).
5264   * @returns undefined
5265   * @example
5266   *
5267   * async.waterfall([
5268   *     function(callback) {
5269   *         callback(null, 'one', 'two');
5270   *     },
5271   *     function(arg1, arg2, callback) {
5272   *         // arg1 now equals 'one' and arg2 now equals 'two'
5273   *         callback(null, 'three');
5274   *     },
5275   *     function(arg1, callback) {
5276   *         // arg1 now equals 'three'
5277   *         callback(null, 'done');
5278   *     }
5279   * ], function (err, result) {
5280   *     // result now equals 'done'
5281   * });
5282   *
5283   * // Or, with named functions:
5284   * async.waterfall([
5285   *     myFirstFunction,
5286   *     mySecondFunction,
5287   *     myLastFunction,
5288   * ], function (err, result) {
5289   *     // result now equals 'done'
5290   * });
5291   * function myFirstFunction(callback) {
5292   *     callback(null, 'one', 'two');
5293   * }
5294   * function mySecondFunction(arg1, arg2, callback) {
5295   *     // arg1 now equals 'one' and arg2 now equals 'two'
5296   *     callback(null, 'three');
5297   * }
5298   * function myLastFunction(arg1, callback) {
5299   *     // arg1 now equals 'three'
5300   *     callback(null, 'done');
5301   * }
5302   */
5303  var waterfall = function(tasks, callback) {
5304      callback = once(callback || noop);
5305      if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
5306      if (!tasks.length) return callback();
5307      var taskIndex = 0;
5308  
5309      function nextTask(args) {
5310          var task = wrapAsync(tasks[taskIndex++]);
5311          args.push(onlyOnce(next));
5312          task.apply(null, args);
5313      }
5314  
5315      function next(err/*, ...args*/) {
5316          if (err || taskIndex === tasks.length) {
5317              return callback.apply(null, arguments);
5318          }
5319          nextTask(slice(arguments, 1));
5320      }
5321  
5322      nextTask([]);
5323  };
5324  
5325  /**
5326   * An "async function" in the context of Async is an asynchronous function with
5327   * a variable number of parameters, with the final parameter being a callback.
5328   * (`function (arg1, arg2, ..., callback) {}`)
5329   * The final callback is of the form `callback(err, results...)`, which must be
5330   * called once the function is completed.  The callback should be called with a
5331   * Error as its first argument to signal that an error occurred.
5332   * Otherwise, if no error occurred, it should be called with `null` as the first
5333   * argument, and any additional `result` arguments that may apply, to signal
5334   * successful completion.
5335   * The callback must be called exactly once, ideally on a later tick of the
5336   * JavaScript event loop.
5337   *
5338   * This type of function is also referred to as a "Node-style async function",
5339   * or a "continuation passing-style function" (CPS). Most of the methods of this
5340   * library are themselves CPS/Node-style async functions, or functions that
5341   * return CPS/Node-style async functions.
5342   *
5343   * Wherever we accept a Node-style async function, we also directly accept an
5344   * [ES2017 `async` function]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function}.
5345   * In this case, the `async` function will not be passed a final callback
5346   * argument, and any thrown error will be used as the `err` argument of the
5347   * implicit callback, and the return value will be used as the `result` value.
5348   * (i.e. a `rejected` of the returned Promise becomes the `err` callback
5349   * argument, and a `resolved` value becomes the `result`.)
5350   *
5351   * Note, due to JavaScript limitations, we can only detect native `async`
5352   * functions and not transpilied implementations.
5353   * Your environment must have `async`/`await` support for this to work.
5354   * (e.g. Node > v7.6, or a recent version of a modern browser).
5355   * If you are using `async` functions through a transpiler (e.g. Babel), you
5356   * must still wrap the function with [asyncify]{@link module:Utils.asyncify},
5357   * because the `async function` will be compiled to an ordinary function that
5358   * returns a promise.
5359   *
5360   * @typedef {Function} AsyncFunction
5361   * @static
5362   */
5363  
5364  /**
5365   * Async is a utility module which provides straight-forward, powerful functions
5366   * for working with asynchronous JavaScript. Although originally designed for
5367   * use with [Node.js](http://nodejs.org) and installable via
5368   * `npm install --save async`, it can also be used directly in the browser.
5369   * @module async
5370   * @see AsyncFunction
5371   */
5372  
5373  
5374  /**
5375   * A collection of `async` functions for manipulating collections, such as
5376   * arrays and objects.
5377   * @module Collections
5378   */
5379  
5380  /**
5381   * A collection of `async` functions for controlling the flow through a script.
5382   * @module ControlFlow
5383   */
5384  
5385  /**
5386   * A collection of `async` utility functions.
5387   * @module Utils
5388   */
5389  
5390  var index = {
5391      apply: apply,
5392      applyEach: applyEach,
5393      applyEachSeries: applyEachSeries,
5394      asyncify: asyncify,
5395      auto: auto,
5396      autoInject: autoInject,
5397      cargo: cargo,
5398      compose: compose,
5399      concat: concat,
5400      concatLimit: concatLimit,
5401      concatSeries: concatSeries,
5402      constant: constant,
5403      detect: detect,
5404      detectLimit: detectLimit,
5405      detectSeries: detectSeries,
5406      dir: dir,
5407      doDuring: doDuring,
5408      doUntil: doUntil,
5409      doWhilst: doWhilst,
5410      during: during,
5411      each: eachLimit,
5412      eachLimit: eachLimit$1,
5413      eachOf: eachOf,
5414      eachOfLimit: eachOfLimit,
5415      eachOfSeries: eachOfSeries,
5416      eachSeries: eachSeries,
5417      ensureAsync: ensureAsync,
5418      every: every,
5419      everyLimit: everyLimit,
5420      everySeries: everySeries,
5421      filter: filter,
5422      filterLimit: filterLimit,
5423      filterSeries: filterSeries,
5424      forever: forever,
5425      groupBy: groupBy,
5426      groupByLimit: groupByLimit,
5427      groupBySeries: groupBySeries,
5428      log: log,
5429      map: map,
5430      mapLimit: mapLimit,
5431      mapSeries: mapSeries,
5432      mapValues: mapValues,
5433      mapValuesLimit: mapValuesLimit,
5434      mapValuesSeries: mapValuesSeries,
5435      memoize: memoize,
5436      nextTick: nextTick,
5437      parallel: parallelLimit,
5438      parallelLimit: parallelLimit$1,
5439      priorityQueue: priorityQueue,
5440      queue: queue$1,
5441      race: race,
5442      reduce: reduce,
5443      reduceRight: reduceRight,
5444      reflect: reflect,
5445      reflectAll: reflectAll,
5446      reject: reject,
5447      rejectLimit: rejectLimit,
5448      rejectSeries: rejectSeries,
5449      retry: retry,
5450      retryable: retryable,
5451      seq: seq,
5452      series: series,
5453      setImmediate: setImmediate$1,
5454      some: some,
5455      someLimit: someLimit,
5456      someSeries: someSeries,
5457      sortBy: sortBy,
5458      timeout: timeout,
5459      times: times,
5460      timesLimit: timeLimit,
5461      timesSeries: timesSeries,
5462      transform: transform,
vendor: 60,163 bytes, lines 5463-6971
5463      tryEach: tryEach,
5464      unmemoize: unmemoize,
5465      until: until,
5466      waterfall: waterfall,
5467      whilst: whilst,
5468  
5469      // aliases
5470      all: every,
5471      allLimit: everyLimit,
5472      allSeries: everySeries,
5473      any: some,
5474      anyLimit: someLimit,
5475      anySeries: someSeries,
5476      find: detect,
5477      findLimit: detectLimit,
5478      findSeries: detectSeries,
5479      forEach: eachLimit,
5480      forEachSeries: eachSeries,
5481      forEachLimit: eachLimit$1,
5482      forEachOf: eachOf,
5483      forEachOfSeries: eachOfSeries,
5484      forEachOfLimit: eachOfLimit,
5485      inject: reduce,
5486      foldl: reduce,
5487      foldr: reduceRight,
5488      select: filter,
5489      selectLimit: filterLimit,
5490      selectSeries: filterSeries,
5491      wrapSync: asyncify
5492  };
5493  
5494  exports['default'] = index;
5495  exports.apply = apply;
5496  exports.applyEach = applyEach;
5497  exports.applyEachSeries = applyEachSeries;
5498  exports.asyncify = asyncify;
5499  exports.auto = auto;
5500  exports.autoInject = autoInject;
5501  exports.cargo = cargo;
5502  exports.compose = compose;
5503  exports.concat = concat;
5504  exports.concatLimit = concatLimit;
5505  exports.concatSeries = concatSeries;
5506  exports.constant = constant;
5507  exports.detect = detect;
5508  exports.detectLimit = detectLimit;
5509  exports.detectSeries = detectSeries;
5510  exports.dir = dir;
5511  exports.doDuring = doDuring;
5512  exports.doUntil = doUntil;
5513  exports.doWhilst = doWhilst;
5514  exports.during = during;
5515  exports.each = eachLimit;
5516  exports.eachLimit = eachLimit$1;
5517  exports.eachOf = eachOf;
5518  exports.eachOfLimit = eachOfLimit;
5519  exports.eachOfSeries = eachOfSeries;
5520  exports.eachSeries = eachSeries;
5521  exports.ensureAsync = ensureAsync;
5522  exports.every = every;
5523  exports.everyLimit = everyLimit;
5524  exports.everySeries = everySeries;
5525  exports.filter = filter;
5526  exports.filterLimit = filterLimit;
5527  exports.filterSeries = filterSeries;
5528  exports.forever = forever;
5529  exports.groupBy = groupBy;
5530  exports.groupByLimit = groupByLimit;
5531  exports.groupBySeries = groupBySeries;
5532  exports.log = log;
5533  exports.map = map;
5534  exports.mapLimit = mapLimit;
5535  exports.mapSeries = mapSeries;
5536  exports.mapValues = mapValues;
5537  exports.mapValuesLimit = mapValuesLimit;
5538  exports.mapValuesSeries = mapValuesSeries;
5539  exports.memoize = memoize;
5540  exports.nextTick = nextTick;
5541  exports.parallel = parallelLimit;
5542  exports.parallelLimit = parallelLimit$1;
5543  exports.priorityQueue = priorityQueue;
5544  exports.queue = queue$1;
5545  exports.race = race;
5546  exports.reduce = reduce;
5547  exports.reduceRight = reduceRight;
5548  exports.reflect = reflect;
5549  exports.reflectAll = reflectAll;
5550  exports.reject = reject;
5551  exports.rejectLimit = rejectLimit;
5552  exports.rejectSeries = rejectSeries;
5553  exports.retry = retry;
5554  exports.retryable = retryable;
5555  exports.seq = seq;
5556  exports.series = series;
5557  exports.setImmediate = setImmediate$1;
5558  exports.some = some;
5559  exports.someLimit = someLimit;
5560  exports.someSeries = someSeries;
5561  exports.sortBy = sortBy;
5562  exports.timeout = timeout;
5563  exports.times = times;
5564  exports.timesLimit = timeLimit;
5565  exports.timesSeries = timesSeries;
5566  exports.transform = transform;
5567  exports.tryEach = tryEach;
5568  exports.unmemoize = unmemoize;
5569  exports.until = until;
5570  exports.waterfall = waterfall;
5571  exports.whilst = whilst;
5572  exports.all = every;
5573  exports.allLimit = everyLimit;
5574  exports.allSeries = everySeries;
5575  exports.any = some;
5576  exports.anyLimit = someLimit;
5577  exports.anySeries = someSeries;
5578  exports.find = detect;
5579  exports.findLimit = detectLimit;
5580  exports.findSeries = detectSeries;
5581  exports.forEach = eachLimit;
5582  exports.forEachSeries = eachSeries;
5583  exports.forEachLimit = eachLimit$1;
5584  exports.forEachOf = eachOf;
5585  exports.forEachOfSeries = eachOfSeries;
5586  exports.forEachOfLimit = eachOfLimit;
5587  exports.inject = reduce;
5588  exports.foldl = reduce;
5589  exports.foldr = reduceRight;
5590  exports.select = filter;
5591  exports.selectLimit = filterLimit;
5592  exports.selectSeries = filterSeries;
5593  exports.wrapSync = asyncify;
5594  
5595  Object.defineProperty(exports, '__esModule', { value: true });
5596  
5597  })));
5598  
5599  }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
5600  },{"_process":4}],2:[function(require,module,exports){
5601  // Copyright (c) 2014 Takuya Asano All Rights Reserved.
5602  
5603  (function () {
5604  
5605      "use strict";
5606  
5607      var TERM_CHAR = "\u0000", // terminal character
5608          TERM_CODE = 0,        // terminal character code
5609          ROOT_ID = 0,          // index of root node
5610          NOT_FOUND = -1,       // traverse() returns if no nodes found
5611          BASE_SIGNED = true,
5612          CHECK_SIGNED = true,
5613          BASE_BYTES = 4,
5614          CHECK_BYTES = 4,
5615          MEMORY_EXPAND_RATIO = 2;
5616  
5617  
5618      var newBC = function (initial_size) {
5619  
5620          if (initial_size == null) {
5621              initial_size = 1024;
5622          }
5623  
5624          var initBase = function (_base, start, end) {  // 'end' index does not include
5625              for (var i = start; i < end; i++) {
5626                  _base[i] = - i + 1;  // inversed previous empty node index
5627              }
5628              if (0 < check.array[check.array.length - 1]) {
5629                  var last_used_id = check.array.length - 2;
5630                  while (0 < check.array[last_used_id]) {
5631                      last_used_id--;
5632                  }
5633                  _base[start] = - last_used_id;
5634              }
5635          };
5636  
5637          var initCheck = function (_check, start, end) {
5638              for (var i = start; i < end; i++) {
5639                  _check[i] = - i - 1;  // inversed next empty node index
5640              }
5641          };
5642  
5643          var realloc = function (min_size) {
5644              // expand arrays size by given ratio
5645              var new_size = min_size * MEMORY_EXPAND_RATIO;
5646              // console.log('re-allocate memory to ' + new_size);
5647  
5648              var base_new_array = newArrayBuffer(base.signed, base.bytes, new_size);
5649              initBase(base_new_array, base.array.length, new_size);  // init BASE in new range
5650              base_new_array.set(base.array);
5651              base.array = null;  // explicit GC
5652              base.array = base_new_array;
5653  
5654              var check_new_array = newArrayBuffer(check.signed, check.bytes, new_size);
5655              initCheck(check_new_array, check.array.length, new_size);  // init CHECK in new range
5656              check_new_array.set(check.array);
5657              check.array = null;  // explicit GC
5658              check.array = check_new_array;
5659          };
5660  
5661          var first_unused_node = ROOT_ID + 1;
5662  
5663          var base = {
5664              signed: BASE_SIGNED,
5665              bytes: BASE_BYTES,
5666              array: newArrayBuffer(BASE_SIGNED, BASE_BYTES, initial_size)
5667          };
5668  
5669          var check = {
5670              signed: CHECK_SIGNED,
5671              bytes: CHECK_BYTES,
5672              array: newArrayBuffer(CHECK_SIGNED, CHECK_BYTES, initial_size)
5673          };
5674  
5675          // init root node
5676          base.array[ROOT_ID] = 1;
5677          check.array[ROOT_ID] = ROOT_ID;
5678  
5679          // init BASE
5680          initBase(base.array, ROOT_ID + 1, base.array.length);
5681  
5682          // init CHECK
5683          initCheck(check.array, ROOT_ID + 1, check.array.length);
5684  
5685          return {
5686              getBaseBuffer: function () {
5687                  return base.array;
5688              },
5689              getCheckBuffer: function () {
5690                  return check.array;
5691              },
5692              loadBaseBuffer: function (base_buffer) {
5693                  base.array = base_buffer;
5694                  return this;
5695              },
5696              loadCheckBuffer: function (check_buffer) {
5697                  check.array = check_buffer;
5698                  return this;
5699              },
5700              size: function () {
5701                  return Math.max(base.array.length, check.array.length);
5702              },
5703              getBase: function (index) {
5704                  if (base.array.length - 1 < index) {
5705                      return - index + 1;
5706                      // realloc(index);
5707                  }
5708                  // if (!Number.isFinite(base.array[index])) {
5709                  //     console.log('getBase:' + index);
5710                  //     throw 'getBase' + index;
5711                  // }
5712                  return base.array[index];
5713              },
5714              getCheck: function (index) {
5715                  if (check.array.length - 1 < index) {
5716                      return - index - 1;
5717                      // realloc(index);
5718                  }
5719                  // if (!Number.isFinite(check.array[index])) {
5720                  //     console.log('getCheck:' + index);
5721                  //     throw 'getCheck' + index;
5722                  // }
5723                  return check.array[index];
5724              },
5725              setBase: function (index, base_value) {
5726                  if (base.array.length - 1 < index) {
5727                      realloc(index);
5728                  }
5729                  base.array[index] = base_value;
5730              },
5731              setCheck: function (index, check_value) {
5732                  if (check.array.length - 1 < index) {
5733                      realloc(index);
5734                  }
5735                  check.array[index] = check_value;
5736              },
5737              setFirstUnusedNode: function (index) {
5738                  // if (!Number.isFinite(index)) {
5739                  //     throw 'assertion error: setFirstUnusedNode ' + index + ' is not finite number';
5740                  // }
5741                  first_unused_node = index;
5742              },
5743              getFirstUnusedNode: function () {
5744                  // if (!Number.isFinite(first_unused_node)) {
5745                  //     throw 'assertion error: getFirstUnusedNode ' + first_unused_node + ' is not finite number';
5746                  // }
5747                  return first_unused_node;
5748              },
5749              shrink: function () {
5750                  var last_index = this.size() - 1;
5751                  while (true) {
5752                      if (0 <= check.array[last_index]) {
5753                          break;
5754                      }
5755                      last_index--;
5756                  }
5757                  base.array = base.array.subarray(0, last_index + 2);   // keep last unused node
5758                  check.array = check.array.subarray(0, last_index + 2); // keep last unused node
5759              },
5760              calc: function () {
5761                  var unused_count = 0;
5762                  var size = check.array.length;
5763                  for (var i = 0; i < size; i++) {
5764                      if (check.array[i] < 0) {
5765                          unused_count++;
5766                      }
5767                  }
5768                  return {
5769                      all: size,
5770                      unused: unused_count,
5771                      efficiency: (size - unused_count) / size
5772                  };
5773              },
5774              dump: function () {
5775                  // for debug
5776                  var dump_base = "";
5777                  var dump_check = "";
5778  
5779                  var i;
5780                  for (i = 0; i < base.array.length; i++) {
5781                      dump_base = dump_base + " " + this.getBase(i);
5782                  }
5783                  for (i = 0; i < check.array.length; i++) {
5784                      dump_check = dump_check + " " + this.getCheck(i);
5785                  }
5786  
5787                  console.log("base:" + dump_base);
5788                  console.log("chck:" + dump_check);
5789  
5790                  return "base:" + dump_base + " chck:" + dump_check;
5791              }
5792          };
5793      };
5794  
5795  
5796      /**
5797       * Factory method of double array
5798       */
5799      function DoubleArrayBuilder(initial_size) {
5800          this.bc = newBC(initial_size);  // BASE and CHECK
5801          this.keys = [];
5802      }
5803  
5804  
5805      /**
5806       * Append a key to initialize set
5807       * (This method should be called by dictionary ordered key)
5808       *
5809       * @param {String} key
5810       * @param {Number} value Integer value from 0 to max signed integer number - 1
5811       */
5812      DoubleArrayBuilder.prototype.append = function (key, record) {
5813          this.keys.push({ k: key, v: record });
5814          return this;
5815      };
5816  
5817      /**
5818       * Build double array for given keys
5819       *
5820       * @param {Array} keys Array of keys. A key is a Object which has properties 'k', 'v'.
5821       * 'k' is a key string, 'v' is a record assigned to that key.
5822       * @return {DoubleArray} Compiled double array
5823       */
5824      DoubleArrayBuilder.prototype.build = function (keys, sorted) {
5825  
5826          if (keys == null) {
5827              keys = this.keys;
5828          }
5829  
5830          if (keys == null) {
5831              return new DoubleArray(this.bc);
5832          }
5833  
5834          if (sorted == null) {
5835              sorted = false;
5836          }
5837  
5838          // Convert key string to ArrayBuffer
5839          var buff_keys =
5840              keys.map(function (k) {
5841                  return {
5842                      k: stringToUtf8Bytes(k.k + TERM_CHAR),
5843                      v: k.v
5844                  };
5845              });
5846  
5847          // Sort keys by byte order
5848          if (sorted) {
5849              this.keys = buff_keys;
5850          } else {
5851              this.keys =
5852                  buff_keys.sort(function (k1, k2) {
5853                      var b1 = k1.k;
5854                      var b2 = k2.k;
5855                      var min_length = Math.min(b1.length, b2.length);
5856                      for (var pos = 0; pos < min_length; pos++) {
5857                          if (b1[pos] === b2[pos]) {
5858                              continue;
5859                          }
5860                          return b1[pos] - b2[pos];
5861                      }
5862                      return b1.length - b2.length;
5863                  });
5864          }
5865  
5866          buff_keys = null;  // explicit GC
5867  
5868          this._build(ROOT_ID, 0, 0, this.keys.length);
5869          return new DoubleArray(this.bc);
5870      };
5871  
5872      /**
5873       * Append nodes to BASE and CHECK array recursively
5874       */
5875      DoubleArrayBuilder.prototype._build = function (parent_index, position, start, length) {
5876  
5877          var children_info = this.getChildrenInfo(position, start, length);
5878          var _base = this.findAllocatableBase(children_info);
5879  
5880          this.setBC(parent_index, children_info, _base);
5881  
5882          for (var i = 0; i < children_info.length; i = i + 3) {
5883              var child_code = children_info[i];
5884              if (child_code === TERM_CODE) {
5885                  continue;
5886              }
5887              var child_start = children_info[i + 1];
5888              var child_len = children_info[i + 2];
5889              var child_index = _base + child_code;
5890              this._build(child_index, position + 1, child_start, child_len);
5891          }
5892      };
5893  
5894      DoubleArrayBuilder.prototype.getChildrenInfo = function (position, start, length) {
5895          var current_char = this.keys[start].k[position];
5896          var i = 0;
5897          var children_info = new Int32Array(length * 3);
5898  
5899          children_info[i++] = current_char;  // char (current)
5900          children_info[i++] = start;         // start index (current)
5901  
5902          var next_pos = start;
5903          var start_pos = start;
5904          for (; next_pos < start + length; next_pos++) {
5905              var next_char = this.keys[next_pos].k[position];
5906              if (current_char !== next_char) {
5907                  children_info[i++] = next_pos - start_pos;  // length (current)
5908  
5909                  children_info[i++] = next_char;             // char (next)
5910                  children_info[i++] = next_pos;              // start index (next)
5911                  current_char = next_char;
5912                  start_pos = next_pos;
5913              }
5914          }
5915          children_info[i++] = next_pos - start_pos;
5916          children_info = children_info.subarray(0, i);
5917  
5918          return children_info;
5919      };
5920  
5921      DoubleArrayBuilder.prototype.setBC = function (parent_id, children_info, _base) {
5922  
5923          var bc = this.bc;
5924  
5925          bc.setBase(parent_id, _base);  // Update BASE of parent node
5926  
5927          var i;
5928          for (i = 0; i < children_info.length; i = i + 3) {
5929              var code = children_info[i];
5930              var child_id = _base + code;
5931  
5932              // Update linked list of unused nodes
5933  
5934              // Assertion
5935              // if (child_id < 0) {
5936              //     throw 'assertion error: child_id is negative'
5937              // }
5938  
5939              var prev_unused_id = - bc.getBase(child_id);
5940              var next_unused_id = - bc.getCheck(child_id);
5941              // if (prev_unused_id < 0) {
5942              //     throw 'assertion error: setBC'
5943              // }
5944              // if (next_unused_id < 0) {
5945              //     throw 'assertion error: setBC'
5946              // }
5947              if (child_id !== bc.getFirstUnusedNode()) {
5948                  bc.setCheck(prev_unused_id, - next_unused_id);
5949              } else {
5950                  // Update first_unused_node
5951                  bc.setFirstUnusedNode(next_unused_id);
5952              }
5953              bc.setBase(next_unused_id, - prev_unused_id);
5954  
5955              var check = parent_id;         // CHECK is parent node index
5956              bc.setCheck(child_id, check);  // Update CHECK of child node
5957  
5958              // Update record
5959              if (code === TERM_CODE) {
5960                  var start_pos = children_info[i + 1];
5961                  // var len = children_info[i + 2];
5962                  // if (len != 1) {
5963                  //     throw 'assertion error: there are multiple terminal nodes. len:' + len;
5964                  // }
5965                  var value = this.keys[start_pos].v;
5966  
5967                  if (value == null) {
5968                      value = 0;
5969                  }
5970  
5971                  var base = - value - 1;       // BASE is inverted record value
5972                  bc.setBase(child_id, base);  // Update BASE of child(leaf) node
5973              }
5974          }
5975      };
5976  
5977  
5978      /**
5979       * Find BASE value that all children are allocatable in double array's region
5980       */
5981      DoubleArrayBuilder.prototype.findAllocatableBase = function (children_info) {
5982  
5983          var bc = this.bc;
5984  
5985          // Assertion: keys are sorted by byte order
5986          // var c = -1;
5987          // for (var i = 0; i < children_info.length; i = i + 3) {
5988          //     if (children_info[i] < c) {
5989          //         throw 'assertion error: not sort key'
5990          //     }
5991          //     c = children_info[i];
5992          // }
5993  
5994          // iterate linked list of unused nodes
5995          var _base;
5996          var curr = bc.getFirstUnusedNode();  // current index
5997          // if (curr < 0) {
5998          //     throw 'assertion error: getFirstUnusedNode returns negative value'
5999          // }
6000  
6001          while (true) {
6002              _base = curr - children_info[0];
6003  
6004              if (_base < 0) {
6005                  curr = - bc.getCheck(curr);  // next
6006  
6007                  // if (curr < 0) {
6008                  //     throw 'assertion error: getCheck returns negative value'
6009                  // }
6010  
6011                  continue;
6012              }
6013  
6014              var empty_area_found = true;
6015              for (var i = 0; i < children_info.length; i = i + 3) {
6016                  var code = children_info[i];
6017                  var candidate_id = _base + code;
6018  
6019                  if (!this.isUnusedNode(candidate_id)) {
6020                      // candidate_id is used node
6021                      // next
6022                      curr = - bc.getCheck(curr);
6023                      // if (curr < 0) {
6024                      //     throw 'assertion error: getCheck returns negative value'
6025                      // }
6026  
6027                      empty_area_found = false;
6028                      break;
6029                  }
6030              }
6031              if (empty_area_found) {
6032                  // Area is free
6033                  return _base;
6034              }
6035          }
6036      };
6037  
6038      /**
6039       * Check this double array index is unused or not
6040       */
6041      DoubleArrayBuilder.prototype.isUnusedNode = function (index) {
6042          var bc = this.bc;
6043          var check = bc.getCheck(index);
6044  
6045          // if (index < 0) {
6046          //     throw 'assertion error: isUnusedNode index:' + index;
6047          // }
6048  
6049          if (index === ROOT_ID) {
6050              // root node
6051              return false;
6052          }
6053          if (check < 0) {
6054              // unused
6055              return true;
6056          }
6057  
6058          // used node (incl. leaf)
6059          return false;
6060      };
6061  
6062  
6063      /**
6064       * Factory method of double array
6065       */
6066      function DoubleArray(bc) {
6067          this.bc = bc;       // BASE and CHECK
6068          this.bc.shrink();
6069      }
6070  
6071  
6072      /**
6073       * Look up a given key in this trie
6074       *
6075       * @param {String} key
6076       * @return {Boolean} True if this trie contains a given key
6077       */
6078      DoubleArray.prototype.contain = function (key) {
6079  
6080          var bc = this.bc;
6081  
6082          key += TERM_CHAR;
6083          var buffer = stringToUtf8Bytes(key);
6084  
6085          var parent = ROOT_ID;
6086          var child = NOT_FOUND;
6087  
6088          for (var i = 0; i < buffer.length; i++) {
6089              var code = buffer[i];
6090  
6091              child = this.traverse(parent, code);
6092              if (child === NOT_FOUND) {
6093                  return false;
6094              }
6095  
6096              if (bc.getBase(child) <= 0) {
6097                  // leaf node
6098                  return true;
6099              } else {
6100                  // not leaf
6101                  parent = child;
6102                  continue;
6103              }
6104          }
6105          return false;
6106      };
6107  
6108  
6109      /**
6110       * Look up a given key in this trie
6111       *
6112       * @param {String} key
6113       * @return {Number} Record value assgned to this key, -1 if this key does not contain
6114       */
6115      DoubleArray.prototype.lookup = function (key) {
6116  
6117          key += TERM_CHAR;
6118          var buffer = stringToUtf8Bytes(key);
6119  
6120          var parent = ROOT_ID;
6121          var child = NOT_FOUND;
6122  
6123          for (var i = 0; i < buffer.length; i++) {
6124              var code = buffer[i];
6125              child = this.traverse(parent, code);
6126              if (child === NOT_FOUND) {
6127                  return NOT_FOUND;
6128              }
6129              parent = child;
6130          }
6131  
6132          var base = this.bc.getBase(child);
6133          if (base <= 0) {
6134              // leaf node
6135              return - base - 1;
6136          } else {
6137              // not leaf
6138              return NOT_FOUND;
6139          }
6140      };
6141  
6142  
6143      /**
6144       * Common prefix search
6145       *
6146       * @param {String} key
6147       * @return {Array} Each result object has 'k' and 'v' (key and record,
6148       * respectively) properties assigned to matched string
6149       */
6150      DoubleArray.prototype.commonPrefixSearch = function (key) {
6151  
6152          var buffer = stringToUtf8Bytes(key);
6153  
6154          var parent = ROOT_ID;
6155          var child = NOT_FOUND;
6156  
6157          var result = [];
6158  
6159          for (var i = 0; i < buffer.length; i++) {
6160              var code = buffer[i];
6161  
6162              child = this.traverse(parent, code);
6163  
6164              if (child !== NOT_FOUND) {
6165                  parent = child;
6166  
6167                  // look forward by terminal character code to check this node is a leaf or not
6168                  var grand_child = this.traverse(child, TERM_CODE);
6169  
6170                  if (grand_child !== NOT_FOUND) {
6171                      var base = this.bc.getBase(grand_child);
6172  
6173                      var r = {};
6174  
6175                      if (base <= 0) {
6176                          // If child is a leaf node, add record to result
6177                          r.v = - base - 1;
6178                      }
6179  
6180                      // If child is a leaf node, add word to result
6181                      r.k = utf8BytesToString(arrayCopy(buffer, 0, i + 1));
6182  
6183                      result.push(r);
6184                  }
6185                  continue;
6186              } else {
6187                  break;
6188              }
6189          }
6190  
6191          return result;
6192      };
6193  
6194      DoubleArray.prototype.traverse = function (parent, code) {
6195          var child = this.bc.getBase(parent) + code;
6196          if (this.bc.getCheck(child) === parent) {
6197              return child;
6198          } else {
6199              return NOT_FOUND;
6200          }
6201      };
6202  
6203      DoubleArray.prototype.size = function () {
6204          return this.bc.size();
6205      };
6206  
6207      DoubleArray.prototype.calc = function () {
6208          return this.bc.calc();
6209      };
6210  
6211      DoubleArray.prototype.dump = function () {
6212          return this.bc.dump();
6213      };
6214  
6215  
6216      // Array utility functions
6217  
6218      var newArrayBuffer = function (signed, bytes, size) {
6219          if (signed) {
6220              switch(bytes) {
6221                  case 1:
6222                  return new Int8Array(size);
6223                  case 2:
6224                  return new Int16Array(size);
6225                  case 4:
6226                  return new Int32Array(size);
6227                  default:
6228                  throw new RangeError("Invalid newArray parameter element_bytes:" + bytes);
6229              }
6230          } else {
6231              switch(bytes) {
6232                  case 1:
6233                  return new Uint8Array(size);
6234                  case 2:
6235                  return new Uint16Array(size);
6236                  case 4:
6237                  return new Uint32Array(size);
6238                  default:
6239                  throw new RangeError("Invalid newArray parameter element_bytes:" + bytes);
6240              }
6241          }
6242      };
6243  
6244      var arrayCopy = function (src, src_offset, length) {
6245          var buffer = new ArrayBuffer(length);
6246          var dstU8 = new Uint8Array(buffer, 0, length);
6247          var srcU8 = src.subarray(src_offset, length);
6248          dstU8.set(srcU8);
6249          return dstU8;
6250      };
6251  
6252  
6253      /**
6254       * Convert String (UTF-16) to UTF-8 ArrayBuffer
6255       *
6256       * @param {String} str UTF-16 string to convert
6257       * @return {Uint8Array} Byte sequence encoded by UTF-8
6258       */
6259      var stringToUtf8Bytes = function (str) {
6260  
6261          // Max size of 1 character is 4 bytes
6262          var bytes = new Uint8Array(new ArrayBuffer(str.length * 4));
6263  
6264          var i = 0, j = 0;
6265  
6266          while (i < str.length) {
6267              var unicode_code;
6268  
6269              var utf16_code = str.charCodeAt(i++);
6270              if (utf16_code >= 0xD800 && utf16_code <= 0xDBFF) {
6271                  // surrogate pair
6272                  var upper = utf16_code;           // high surrogate
6273                  var lower = str.charCodeAt(i++);  // low surrogate
6274  
6275                  if (lower >= 0xDC00 && lower <= 0xDFFF) {
6276                      unicode_code =
6277                          (upper - 0xD800) * (1 << 10) + (1 << 16) +
6278                          (lower - 0xDC00);
6279                  } else {
6280                      // malformed surrogate pair
6281                      return null;
6282                  }
6283              } else {
6284                  // not surrogate code
6285                  unicode_code = utf16_code;
6286              }
6287  
6288              if (unicode_code < 0x80) {
6289                  // 1-byte
6290                  bytes[j++] = unicode_code;
6291  
6292              } else if (unicode_code < (1 << 11)) {
6293                  // 2-byte
6294                  bytes[j++] = (unicode_code >>> 6) | 0xC0;
6295                  bytes[j++] = (unicode_code & 0x3F) | 0x80;
6296  
6297              } else if (unicode_code < (1 << 16)) {
6298                  // 3-byte
6299                  bytes[j++] = (unicode_code >>> 12) | 0xE0;
6300                  bytes[j++] = ((unicode_code >> 6) & 0x3f) | 0x80;
6301                  bytes[j++] = (unicode_code & 0x3F) | 0x80;
6302  
6303              } else if (unicode_code < (1 << 21)) {
6304                  // 4-byte
6305                  bytes[j++] = (unicode_code >>> 18) | 0xF0;
6306                  bytes[j++] = ((unicode_code >> 12) & 0x3F) | 0x80;
6307                  bytes[j++] = ((unicode_code >> 6) & 0x3F) | 0x80;
6308                  bytes[j++] = (unicode_code & 0x3F) | 0x80;
6309  
6310              } else {
6311                  // malformed UCS4 code
6312              }
6313          }
6314  
6315          return bytes.subarray(0, j);
6316      };
6317  
6318  
6319      /**
6320       * Convert UTF-8 ArrayBuffer to String (UTF-16)
6321       *
6322       * @param {Uint8Array} bytes UTF-8 byte sequence to convert
6323       * @return {String} String encoded by UTF-16
6324       */
6325      var utf8BytesToString = function (bytes) {
6326  
6327          var str = "";
6328          var code, b1, b2, b3, b4, upper, lower;
6329          var i = 0;
6330  
6331          while (i < bytes.length) {
6332  
6333              b1 = bytes[i++];
6334  
6335              if (b1 < 0x80) {
6336                  // 1 byte
6337                  code = b1;
6338              } else if ((b1 >> 5) === 0x06) {
6339                  // 2 bytes
6340                  b2 = bytes[i++];
6341                  code = ((b1 & 0x1f) << 6) | (b2 & 0x3f);
6342              } else if ((b1 >> 4) === 0x0e) {
6343                  // 3 bytes
6344                  b2 = bytes[i++];
6345                  b3 = bytes[i++];
6346                  code = ((b1 & 0x0f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f);
6347              } else {
6348                  // 4 bytes
6349                  b2 = bytes[i++];
6350                  b3 = bytes[i++];
6351                  b4 = bytes[i++];
6352                  code = ((b1 & 0x07) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x3f) << 6) | (b4 & 0x3f);
6353              }
6354  
6355              if (code < 0x10000) {
6356                str += String.fromCharCode(code);
6357              } else {
6358                // surrogate pair
6359                code -= 0x10000;
6360                upper = (0xD800 | (code >> 10));
6361                lower = (0xDC00 | (code & 0x3FF));
6362                str += String.fromCharCode(upper, lower);
6363              }
6364          }
6365  
6366          return str;
6367      };
6368  
6369  
6370      // public methods
6371      var doublearray = {
6372          builder: function (initial_size) {
6373              return new DoubleArrayBuilder(initial_size);
6374          },
6375          load: function (base_buffer, check_buffer) {
6376              var bc = newBC(0);
6377              bc.loadBaseBuffer(base_buffer);
6378              bc.loadCheckBuffer(check_buffer);
6379              return new DoubleArray(bc);
6380          }
6381      };
6382  
6383      if ("undefined" === typeof module) {
6384        // In browser
6385          window.doublearray = doublearray;
6386      } else {
6387        // In node
6388          module.exports = doublearray;
6389      }
6390  
6391  })();
6392  
6393  },{}],3:[function(require,module,exports){
6394  (function (process){
6395  // Copyright Joyent, Inc. and other Node contributors.
6396  //
6397  // Permission is hereby granted, free of charge, to any person obtaining a
6398  // copy of this software and associated documentation files (the
6399  // "Software"), to deal in the Software without restriction, including
6400  // without limitation the rights to use, copy, modify, merge, publish,
6401  // distribute, sublicense, and/or sell copies of the Software, and to permit
6402  // persons to whom the Software is furnished to do so, subject to the
6403  // following conditions:
6404  //
6405  // The above copyright notice and this permission notice shall be included
6406  // in all copies or substantial portions of the Software.
6407  //
6408  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
6409  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
6410  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
6411  // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
6412  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
6413  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
6414  // USE OR OTHER DEALINGS IN THE SOFTWARE.
6415  
6416  // resolves . and .. elements in a path array with directory names there
6417  // must be no slashes, empty elements, or device names (c:\) in the array
6418  // (so also no leading and trailing slashes - it does not distinguish
6419  // relative and absolute paths)
6420  function normalizeArray(parts, allowAboveRoot) {
6421    // if the path tries to go above the root, `up` ends up > 0
6422    var up = 0;
6423    for (var i = parts.length - 1; i >= 0; i--) {
6424      var last = parts[i];
6425      if (last === '.') {
6426        parts.splice(i, 1);
6427      } else if (last === '..') {
6428        parts.splice(i, 1);
6429        up++;
6430      } else if (up) {
6431        parts.splice(i, 1);
6432        up--;
6433      }
6434    }
6435  
6436    // if the path is allowed to go above the root, restore leading ..s
6437    if (allowAboveRoot) {
6438      for (; up--; up) {
6439        parts.unshift('..');
6440      }
6441    }
6442  
6443    return parts;
6444  }
6445  
6446  // Split a filename into [root, dir, basename, ext], unix version
6447  // 'root' is just a slash, or nothing.
6448  var splitPathRe =
6449      /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
6450  var splitPath = function(filename) {
6451    return splitPathRe.exec(filename).slice(1);
6452  };
6453  
6454  // path.resolve([from ...], to)
6455  // posix version
6456  exports.resolve = function() {
6457    var resolvedPath = '',
6458        resolvedAbsolute = false;
6459  
6460    for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
6461      var path = (i >= 0) ? arguments[i] : process.cwd();
6462  
6463      // Skip empty and invalid entries
6464      if (typeof path !== 'string') {
6465        throw new TypeError('Arguments to path.resolve must be strings');
6466      } else if (!path) {
6467        continue;
6468      }
6469  
6470      resolvedPath = path + '/' + resolvedPath;
6471      resolvedAbsolute = path.charAt(0) === '/';
6472    }
6473  
6474    // At this point the path should be resolved to a full absolute path, but
6475    // handle relative paths to be safe (might happen when process.cwd() fails)
6476  
6477    // Normalize the path
6478    resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
6479      return !!p;
6480    }), !resolvedAbsolute).join('/');
6481  
6482    return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
6483  };
6484  
6485  // path.normalize(path)
6486  // posix version
6487  exports.normalize = function(path) {
6488    var isAbsolute = exports.isAbsolute(path),
6489        trailingSlash = substr(path, -1) === '/';
6490  
6491    // Normalize the path
6492    path = normalizeArray(filter(path.split('/'), function(p) {
6493      return !!p;
6494    }), !isAbsolute).join('/');
6495  
6496    if (!path && !isAbsolute) {
6497      path = '.';
6498    }
6499    if (path && trailingSlash) {
6500      path += '/';
6501    }
6502  
6503    return (isAbsolute ? '/' : '') + path;
6504  };
6505  
6506  // posix version
6507  exports.isAbsolute = function(path) {
6508    return path.charAt(0) === '/';
6509  };
6510  
6511  // posix version
6512  exports.join = function() {
6513    var paths = Array.prototype.slice.call(arguments, 0);
6514    return exports.normalize(filter(paths, function(p, index) {
6515      if (typeof p !== 'string') {
6516        throw new TypeError('Arguments to path.join must be strings');
6517      }
6518      return p;
6519    }).join('/'));
6520  };
6521  
6522  
6523  // path.relative(from, to)
6524  // posix version
6525  exports.relative = function(from, to) {
6526    from = exports.resolve(from).substr(1);
6527    to = exports.resolve(to).substr(1);
6528  
6529    function trim(arr) {
6530      var start = 0;
6531      for (; start < arr.length; start++) {
6532        if (arr[start] !== '') break;
6533      }
6534  
6535      var end = arr.length - 1;
6536      for (; end >= 0; end--) {
6537        if (arr[end] !== '') break;
6538      }
6539  
6540      if (start > end) return [];
6541      return arr.slice(start, end - start + 1);
6542    }
6543  
6544    var fromParts = trim(from.split('/'));
6545    var toParts = trim(to.split('/'));
6546  
6547    var length = Math.min(fromParts.length, toParts.length);
6548    var samePartsLength = length;
6549    for (var i = 0; i < length; i++) {
6550      if (fromParts[i] !== toParts[i]) {
6551        samePartsLength = i;
6552        break;
6553      }
6554    }
6555  
6556    var outputParts = [];
6557    for (var i = samePartsLength; i < fromParts.length; i++) {
6558      outputParts.push('..');
6559    }
6560  
6561    outputParts = outputParts.concat(toParts.slice(samePartsLength));
6562  
6563    return outputParts.join('/');
6564  };
6565  
6566  exports.sep = '/';
6567  exports.delimiter = ':';
6568  
6569  exports.dirname = function(path) {
6570    var result = splitPath(path),
6571        root = result[0],
6572        dir = result[1];
6573  
6574    if (!root && !dir) {
6575      // No dirname whatsoever
6576      return '.';
6577    }
6578  
6579    if (dir) {
6580      // It has a dirname, strip trailing slash
6581      dir = dir.substr(0, dir.length - 1);
6582    }
6583  
6584    return root + dir;
6585  };
6586  
6587  
6588  exports.basename = function(path, ext) {
6589    var f = splitPath(path)[2];
6590    // TODO: make this comparison case-insensitive on windows?
6591    if (ext && f.substr(-1 * ext.length) === ext) {
6592      f = f.substr(0, f.length - ext.length);
6593    }
6594    return f;
6595  };
6596  
6597  
6598  exports.extname = function(path) {
6599    return splitPath(path)[3];
6600  };
6601  
6602  function filter (xs, f) {
6603      if (xs.filter) return xs.filter(f);
6604      var res = [];
6605      for (var i = 0; i < xs.length; i++) {
6606          if (f(xs[i], i, xs)) res.push(xs[i]);
6607      }
6608      return res;
6609  }
6610  
6611  // String.prototype.substr - negative index don't work in IE8
6612  var substr = 'ab'.substr(-1) === 'b'
6613      ? function (str, start, len) { return str.substr(start, len) }
6614      : function (str, start, len) {
6615          if (start < 0) start = str.length + start;
6616          return str.substr(start, len);
6617      }
6618  ;
6619  
6620  }).call(this,require('_process'))
6621  },{"_process":4}],4:[function(require,module,exports){
6622  // shim for using process in browser
6623  var process = module.exports = {};
6624  
6625  // cached from whatever global is present so that test runners that stub it
6626  // don't break things.  But we need to wrap it in a try catch in case it is
6627  // wrapped in strict mode code which doesn't define any globals.  It's inside a
6628  // function because try/catches deoptimize in certain engines.
6629  
6630  var cachedSetTimeout;
6631  var cachedClearTimeout;
6632  
6633  function defaultSetTimout() {
6634      throw new Error('setTimeout has not been defined');
6635  }
6636  function defaultClearTimeout () {
6637      throw new Error('clearTimeout has not been defined');
6638  }
6639  (function () {
6640      try {
6641          if (typeof setTimeout === 'function') {
6642              cachedSetTimeout = setTimeout;
6643          } else {
6644              cachedSetTimeout = defaultSetTimout;
6645          }
6646      } catch (e) {
6647          cachedSetTimeout = defaultSetTimout;
6648      }
6649      try {
6650          if (typeof clearTimeout === 'function') {
6651              cachedClearTimeout = clearTimeout;
6652          } else {
6653              cachedClearTimeout = defaultClearTimeout;
6654          }
6655      } catch (e) {
6656          cachedClearTimeout = defaultClearTimeout;
6657      }
6658  } ())
6659  function runTimeout(fun) {
6660      if (cachedSetTimeout === setTimeout) {
6661          //normal enviroments in sane situations
6662          return setTimeout(fun, 0);
6663      }
6664      // if setTimeout wasn't available but was latter defined
6665      if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
6666          cachedSetTimeout = setTimeout;
6667          return setTimeout(fun, 0);
6668      }
6669      try {
6670          // when when somebody has screwed with setTimeout but no I.E. maddness
6671          return cachedSetTimeout(fun, 0);
6672      } catch(e){
6673          try {
6674              // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
6675              return cachedSetTimeout.call(null, fun, 0);
6676          } catch(e){
6677              // 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
6678              return cachedSetTimeout.call(this, fun, 0);
6679          }
6680      }
6681  
6682  
6683  }
6684  function runClearTimeout(marker) {
6685      if (cachedClearTimeout === clearTimeout) {
6686          //normal enviroments in sane situations
6687          return clearTimeout(marker);
6688      }
6689      // if clearTimeout wasn't available but was latter defined
6690      if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
6691          cachedClearTimeout = clearTimeout;
6692          return clearTimeout(marker);
6693      }
6694      try {
6695          // when when somebody has screwed with setTimeout but no I.E. maddness
6696          return cachedClearTimeout(marker);
6697      } catch (e){
6698          try {
6699              // When we are in I.E. but the script has been evaled so I.E. doesn't  trust the global object when called normally
6700              return cachedClearTimeout.call(null, marker);
6701          } catch (e){
6702              // 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.
6703              // Some versions of I.E. have different rules for clearTimeout vs setTimeout
6704              return cachedClearTimeout.call(this, marker);
6705          }
6706      }
6707  
6708  
6709  
6710  }
6711  var queue = [];
6712  var draining = false;
6713  var currentQueue;
6714  var queueIndex = -1;
6715  
6716  function cleanUpNextTick() {
6717      if (!draining || !currentQueue) {
6718          return;
6719      }
6720      draining = false;
6721      if (currentQueue.length) {
6722          queue = currentQueue.concat(queue);
6723      } else {
6724          queueIndex = -1;
6725      }
6726      if (queue.length) {
6727          drainQueue();
6728      }
6729  }
6730  
6731  function drainQueue() {
6732      if (draining) {
6733          return;
6734      }
6735      var timeout = runTimeout(cleanUpNextTick);
6736      draining = true;
6737  
6738      var len = queue.length;
6739      while(len) {
6740          currentQueue = queue;
6741          queue = [];
6742          while (++queueIndex < len) {
6743              if (currentQueue) {
6744                  currentQueue[queueIndex].run();
6745              }
6746          }
6747          queueIndex = -1;
6748          len = queue.length;
6749      }
6750      currentQueue = null;
6751      draining = false;
6752      runClearTimeout(timeout);
6753  }
6754  
6755  process.nextTick = function (fun) {
6756      var args = new Array(arguments.length - 1);
6757      if (arguments.length > 1) {
6758          for (var i = 1; i < arguments.length; i++) {
6759              args[i - 1] = arguments[i];
6760          }
6761      }
6762      queue.push(new Item(fun, args));
6763      if (queue.length === 1 && !draining) {
6764          runTimeout(drainQueue);
6765      }
6766  };
6767  
6768  // v8 likes predictible objects
6769  function Item(fun, array) {
6770      this.fun = fun;
6771      this.array = array;
6772  }
6773  Item.prototype.run = function () {
6774      this.fun.apply(null, this.array);
6775  };
6776  process.title = 'browser';
6777  process.browser = true;
6778  process.env = {};
6779  process.argv = [];
6780  process.version = ''; // empty string to avoid regexp issues
6781  process.versions = {};
6782  
6783  function noop() {}
6784  
6785  process.on = noop;
6786  process.addListener = noop;
6787  process.once = noop;
6788  process.off = noop;
6789  process.removeListener = noop;
6790  process.removeAllListeners = noop;
6791  process.emit = noop;
6792  process.prependListener = noop;
6793  process.prependOnceListener = noop;
6794  
6795  process.listeners = function (name) { return [] }
6796  
6797  process.binding = function (name) {
6798      throw new Error('process.binding is not supported');
6799  };
6800  
6801  process.cwd = function () { return '/' };
6802  process.chdir = function (dir) {
6803      throw new Error('process.chdir is not supported');
6804  };
6805  process.umask = function() { return 0; };
6806  
6807  },{}],5:[function(require,module,exports){
6808  /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';function n(e){throw e;}var p=void 0,aa=this;function t(e,b){var d=e.split("."),c=aa;!(d[0]in c)&&c.execScript&&c.execScript("var "+d[0]);for(var a;d.length&&(a=d.shift());)!d.length&&b!==p?c[a]=b:c=c[a]?c[a]:c[a]={}};var x="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;new (x?Uint8Array:Array)(256);var y;for(y=0;256>y;++y)for(var A=y,ba=7,A=A>>>1;A;A>>>=1)--ba;function B(e,b,d){var c,a="number"===typeof b?b:b=0,f="number"===typeof d?d:e.length;c=-1;for(a=f&7;a--;++b)c=c>>>8^C[(c^e[b])&255];for(a=f>>3;a--;b+=8)c=c>>>8^C[(c^e[b])&255],c=c>>>8^C[(c^e[b+1])&255],c=c>>>8^C[(c^e[b+2])&255],c=c>>>8^C[(c^e[b+3])&255],c=c>>>8^C[(c^e[b+4])&255],c=c>>>8^C[(c^e[b+5])&255],c=c>>>8^C[(c^e[b+6])&255],c=c>>>8^C[(c^e[b+7])&255];return(c^4294967295)>>>0}
6809  var D=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
6810  2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
6811  2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
6812  2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
6813  3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
6814  936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],C=x?new Uint32Array(D):D;function E(){}E.prototype.getName=function(){return this.name};E.prototype.getData=function(){return this.data};E.prototype.G=function(){return this.H};function G(e){var b=e.length,d=0,c=Number.POSITIVE_INFINITY,a,f,k,l,m,r,q,g,h,v;for(g=0;g<b;++g)e[g]>d&&(d=e[g]),e[g]<c&&(c=e[g]);a=1<<d;f=new (x?Uint32Array:Array)(a);k=1;l=0;for(m=2;k<=d;){for(g=0;g<b;++g)if(e[g]===k){r=0;q=l;for(h=0;h<k;++h)r=r<<1|q&1,q>>=1;v=k<<16|g;for(h=r;h<a;h+=m)f[h]=v;++l}++k;l<<=1;m<<=1}return[f,d,c]};var J=[],K;for(K=0;288>K;K++)switch(!0){case 143>=K:J.push([K+48,8]);break;case 255>=K:J.push([K-144+400,9]);break;case 279>=K:J.push([K-256+0,7]);break;case 287>=K:J.push([K-280+192,8]);break;default:n("invalid literal: "+K)}
6815  var ca=function(){function e(a){switch(!0){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
6816  a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:n("invalid length: "+a)}}var b=[],d,c;for(d=3;258>=d;d++)c=e(d),b[d]=c[2]<<24|c[1]<<
6817  16|c[0];return b}();x&&new Uint32Array(ca);function L(e,b){this.i=[];this.j=32768;this.d=this.f=this.c=this.n=0;this.input=x?new Uint8Array(e):e;this.o=!1;this.k=M;this.w=!1;if(b||!(b={}))b.index&&(this.c=b.index),b.bufferSize&&(this.j=b.bufferSize),b.bufferType&&(this.k=b.bufferType),b.resize&&(this.w=b.resize);switch(this.k){case N:this.a=32768;this.b=new (x?Uint8Array:Array)(32768+this.j+258);break;case M:this.a=0;this.b=new (x?Uint8Array:Array)(this.j);this.e=this.D;this.q=this.A;this.l=this.C;break;default:n(Error("invalid inflate mode"))}}
6818  var N=0,M=1;
6819  L.prototype.g=function(){for(;!this.o;){var e=P(this,3);e&1&&(this.o=!0);e>>>=1;switch(e){case 0:var b=this.input,d=this.c,c=this.b,a=this.a,f=b.length,k=p,l=p,m=c.length,r=p;this.d=this.f=0;d+1>=f&&n(Error("invalid uncompressed block header: LEN"));k=b[d++]|b[d++]<<8;d+1>=f&&n(Error("invalid uncompressed block header: NLEN"));l=b[d++]|b[d++]<<8;k===~l&&n(Error("invalid uncompressed block header: length verify"));d+k>b.length&&n(Error("input buffer is broken"));switch(this.k){case N:for(;a+k>c.length;){r=
6820  m-a;k-=r;if(x)c.set(b.subarray(d,d+r),a),a+=r,d+=r;else for(;r--;)c[a++]=b[d++];this.a=a;c=this.e();a=this.a}break;case M:for(;a+k>c.length;)c=this.e({t:2});break;default:n(Error("invalid inflate mode"))}if(x)c.set(b.subarray(d,d+k),a),a+=k,d+=k;else for(;k--;)c[a++]=b[d++];this.c=d;this.a=a;this.b=c;break;case 1:this.l(da,ea);break;case 2:for(var q=P(this,5)+257,g=P(this,5)+1,h=P(this,4)+4,v=new (x?Uint8Array:Array)(Q.length),s=p,F=p,H=p,w=p,z=p,O=p,I=p,u=p,Z=p,u=0;u<h;++u)v[Q[u]]=P(this,3);if(!x){u=
6821  h;for(h=v.length;u<h;++u)v[Q[u]]=0}s=G(v);w=new (x?Uint8Array:Array)(q+g);u=0;for(Z=q+g;u<Z;)switch(z=R(this,s),z){case 16:for(I=3+P(this,2);I--;)w[u++]=O;break;case 17:for(I=3+P(this,3);I--;)w[u++]=0;O=0;break;case 18:for(I=11+P(this,7);I--;)w[u++]=0;O=0;break;default:O=w[u++]=z}F=x?G(w.subarray(0,q)):G(w.slice(0,q));H=x?G(w.subarray(q)):G(w.slice(q));this.l(F,H);break;default:n(Error("unknown BTYPE: "+e))}}return this.q()};
6822  var S=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Q=x?new Uint16Array(S):S,fa=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],ga=x?new Uint16Array(fa):fa,ha=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],T=x?new Uint8Array(ha):ha,ia=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],ja=x?new Uint16Array(ia):ia,ka=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,
6823  11,12,12,13,13],U=x?new Uint8Array(ka):ka,V=new (x?Uint8Array:Array)(288),W,la;W=0;for(la=V.length;W<la;++W)V[W]=143>=W?8:255>=W?9:279>=W?7:8;var da=G(V),X=new (x?Uint8Array:Array)(30),Y,ma;Y=0;for(ma=X.length;Y<ma;++Y)X[Y]=5;var ea=G(X);function P(e,b){for(var d=e.f,c=e.d,a=e.input,f=e.c,k=a.length,l;c<b;)f>=k&&n(Error("input buffer is broken")),d|=a[f++]<<c,c+=8;l=d&(1<<b)-1;e.f=d>>>b;e.d=c-b;e.c=f;return l}
6824  function R(e,b){for(var d=e.f,c=e.d,a=e.input,f=e.c,k=a.length,l=b[0],m=b[1],r,q;c<m&&!(f>=k);)d|=a[f++]<<c,c+=8;r=l[d&(1<<m)-1];q=r>>>16;q>c&&n(Error("invalid code length: "+q));e.f=d>>q;e.d=c-q;e.c=f;return r&65535}
6825  L.prototype.l=function(e,b){var d=this.b,c=this.a;this.r=e;for(var a=d.length-258,f,k,l,m;256!==(f=R(this,e));)if(256>f)c>=a&&(this.a=c,d=this.e(),c=this.a),d[c++]=f;else{k=f-257;m=ga[k];0<T[k]&&(m+=P(this,T[k]));f=R(this,b);l=ja[f];0<U[f]&&(l+=P(this,U[f]));c>=a&&(this.a=c,d=this.e(),c=this.a);for(;m--;)d[c]=d[c++-l]}for(;8<=this.d;)this.d-=8,this.c--;this.a=c};
6826  L.prototype.C=function(e,b){var d=this.b,c=this.a;this.r=e;for(var a=d.length,f,k,l,m;256!==(f=R(this,e));)if(256>f)c>=a&&(d=this.e(),a=d.length),d[c++]=f;else{k=f-257;m=ga[k];0<T[k]&&(m+=P(this,T[k]));f=R(this,b);l=ja[f];0<U[f]&&(l+=P(this,U[f]));c+m>a&&(d=this.e(),a=d.length);for(;m--;)d[c]=d[c++-l]}for(;8<=this.d;)this.d-=8,this.c--;this.a=c};
6827  L.prototype.e=function(){var e=new (x?Uint8Array:Array)(this.a-32768),b=this.a-32768,d,c,a=this.b;if(x)e.set(a.subarray(32768,e.length));else{d=0;for(c=e.length;d<c;++d)e[d]=a[d+32768]}this.i.push(e);this.n+=e.length;if(x)a.set(a.subarray(b,b+32768));else for(d=0;32768>d;++d)a[d]=a[b+d];this.a=32768;return a};
6828  L.prototype.D=function(e){var b,d=this.input.length/this.c+1|0,c,a,f,k=this.input,l=this.b;e&&("number"===typeof e.t&&(d=e.t),"number"===typeof e.z&&(d+=e.z));2>d?(c=(k.length-this.c)/this.r[2],f=258*(c/2)|0,a=f<l.length?l.length+f:l.length<<1):a=l.length*d;x?(b=new Uint8Array(a),b.set(l)):b=l;return this.b=b};
6829  L.prototype.q=function(){var e=0,b=this.b,d=this.i,c,a=new (x?Uint8Array:Array)(this.n+(this.a-32768)),f,k,l,m;if(0===d.length)return x?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);f=0;for(k=d.length;f<k;++f){c=d[f];l=0;for(m=c.length;l<m;++l)a[e++]=c[l]}f=32768;for(k=this.a;f<k;++f)a[e++]=b[f];this.i=[];return this.buffer=a};
6830  L.prototype.A=function(){var e,b=this.a;x?this.w?(e=new Uint8Array(b),e.set(this.b.subarray(0,b))):e=this.b.subarray(0,b):(this.b.length>b&&(this.b.length=b),e=this.b);return this.buffer=e};function $(e){this.input=e;this.c=0;this.m=[];this.s=!1}$.prototype.F=function(){this.s||this.g();return this.m.slice()};
6831  $.prototype.g=function(){for(var e=this.input.length;this.c<e;){var b=new E,d=p,c=p,a=p,f=p,k=p,l=p,m=p,r=p,q=p,g=this.input,h=this.c;b.u=g[h++];b.v=g[h++];(31!==b.u||139!==b.v)&&n(Error("invalid file signature:"+b.u+","+b.v));b.p=g[h++];switch(b.p){case 8:break;default:n(Error("unknown compression method: "+b.p))}b.h=g[h++];r=g[h++]|g[h++]<<8|g[h++]<<16|g[h++]<<24;b.H=new Date(1E3*r);b.N=g[h++];b.M=g[h++];0<(b.h&4)&&(b.I=g[h++]|g[h++]<<8,h+=b.I);if(0<(b.h&8)){m=[];for(l=0;0<(k=g[h++]);)m[l++]=String.fromCharCode(k);
6832  b.name=m.join("")}if(0<(b.h&16)){m=[];for(l=0;0<(k=g[h++]);)m[l++]=String.fromCharCode(k);b.J=m.join("")}0<(b.h&2)&&(b.B=B(g,0,h)&65535,b.B!==(g[h++]|g[h++]<<8)&&n(Error("invalid header crc16")));d=g[g.length-4]|g[g.length-3]<<8|g[g.length-2]<<16|g[g.length-1]<<24;g.length-h-4-4<512*d&&(f=d);c=new L(g,{index:h,bufferSize:f});b.data=a=c.g();h=c.c;b.K=q=(g[h++]|g[h++]<<8|g[h++]<<16|g[h++]<<24)>>>0;B(a,p,p)!==q&&n(Error("invalid CRC-32 checksum: 0x"+B(a,p,p).toString(16)+" / 0x"+q.toString(16)));b.L=
6833  d=(g[h++]|g[h++]<<8|g[h++]<<16|g[h++]<<24)>>>0;(a.length&4294967295)!==d&&n(Error("invalid input size: "+(a.length&4294967295)+" / "+d));this.m.push(b);this.c=h}this.s=!0;var v=this.m,s,F,H=0,w=0,z;s=0;for(F=v.length;s<F;++s)w+=v[s].data.length;if(x){z=new Uint8Array(w);for(s=0;s<F;++s)z.set(v[s].data,H),H+=v[s].data.length}else{z=[];for(s=0;s<F;++s)z[s]=v[s].data;z=Array.prototype.concat.apply([],z)}return z};t("Zlib.Gunzip",$);t("Zlib.Gunzip.prototype.decompress",$.prototype.g);t("Zlib.Gunzip.prototype.getMembers",$.prototype.F);t("Zlib.GunzipMember",E);t("Zlib.GunzipMember.prototype.getName",E.prototype.getName);t("Zlib.GunzipMember.prototype.getData",E.prototype.getData);t("Zlib.GunzipMember.prototype.getMtime",E.prototype.G);}).call(this);
6834  
6835  },{}],6:[function(require,module,exports){
6836  /*
6837   * Copyright 2014 Takuya Asano
6838   * Copyright 2010-2014 Atilika Inc. and contributors
6839   *
6840   * Licensed under the Apache License, Version 2.0 (the "License");
6841   * you may not use this file except in compliance with the License.
6842   * You may obtain a copy of the License at
6843   *
6844   *     http://www.apache.org/licenses/LICENSE-2.0
6845   *
6846   * Unless required by applicable law or agreed to in writing, software
6847   * distributed under the License is distributed on an "AS IS" BASIS,
6848   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6849   * See the License for the specific language governing permissions and
6850   * limitations under the License.
6851   */
6852  
6853  "use strict";
6854  
6855  var ViterbiBuilder = require("./viterbi/ViterbiBuilder");
6856  var ViterbiSearcher = require("./viterbi/ViterbiSearcher");
6857  var IpadicFormatter = require("./util/IpadicFormatter");
6858  
6859  var PUNCTUATION = /、|。/;
6860  
6861  /**
6862   * Tokenizer
6863   * @param {DynamicDictionaries} dic Dictionaries used by this tokenizer
6864   * @constructor
6865   */
6866  function Tokenizer(dic) {
6867      this.token_info_dictionary = dic.token_info_dictionary;
6868      this.unknown_dictionary = dic.unknown_dictionary;
6869      this.viterbi_builder = new ViterbiBuilder(dic);
6870      this.viterbi_searcher = new ViterbiSearcher(dic.connection_costs);
6871      this.formatter = new IpadicFormatter();  // TODO Other dictionaries
6872  }
6873  
6874  /**
6875   * Split into sentence by punctuation
6876   * @param {string} input Input text
6877   * @returns {Array.<string>} Sentences end with punctuation
6878   */
6879  Tokenizer.splitByPunctuation = function (input) {
6880      var sentences = [];
6881      var tail = input;
6882      while (true) {
6883          if (tail === "") {
6884              break;
6885          }
6886          var index = tail.search(PUNCTUATION);
6887          if (index < 0) {
6888              sentences.push(tail);
6889              break;
6890          }
6891          sentences.push(tail.substring(0, index + 1));
6892          tail = tail.substring(index + 1);
6893      }
6894      return sentences;
6895  };
6896  
6897  /**
6898   * Tokenize text
6899   * @param {string} text Input text to analyze
6900   * @returns {Array} Tokens
6901   */
6902  Tokenizer.prototype.tokenize = function (text) {
6903      var sentences = Tokenizer.splitByPunctuation(text);
6904      var tokens = [];
6905      for (var i = 0; i < sentences.length; i++) {
6906          var sentence = sentences[i];
6907          this.tokenizeForSentence(sentence, tokens);
6908      }
6909      return tokens;
6910  };
6911  
6912  Tokenizer.prototype.tokenizeForSentence = function (sentence, tokens) {
6913      if (tokens == null) {
6914          tokens = [];
6915      }
6916      var lattice = this.getLattice(sentence);
6917      var best_path = this.viterbi_searcher.search(lattice);
6918      var last_pos = 0;
6919      if (tokens.length > 0) {
6920          last_pos = tokens[tokens.length - 1].word_position;
6921      }
6922  
6923      for (var j = 0; j < best_path.length; j++) {
6924          var node = best_path[j];
6925  
6926          var token, features, features_line;
6927          if (node.type === "KNOWN") {
6928              features_line = this.token_info_dictionary.getFeatures(node.name);
6929              if (features_line == null) {
6930                  features = [];
6931              } else {
6932                  features = features_line.split(",");
6933              }
6934              token = this.formatter.formatEntry(node.name, last_pos + node.start_pos, node.type, features);
6935          } else if (node.type === "UNKNOWN") {
6936              // Unknown word
6937              features_line = this.unknown_dictionary.getFeatures(node.name);
6938              if (features_line == null) {
6939                  features = [];
6940              } else {
6941                  features = features_line.split(",");
6942              }
6943              token = this.formatter.formatUnknownEntry(node.name, last_pos + node.start_pos, node.type, features, node.surface_form);
6944          } else {
6945              // TODO User dictionary
6946              token = this.formatter.formatEntry(node.name, last_pos + node.start_pos, node.type, []);
6947          }
6948  
6949          tokens.push(token);
6950      }
6951  
6952      return tokens;
6953  };
6954  
6955  /**
6956   * Build word lattice
6957   * @param {string} text Input text to analyze
6958   * @returns {ViterbiLattice} Word lattice
6959   */
6960  Tokenizer.prototype.getLattice = function (text) {
6961      return this.viterbi_builder.build(text);
6962  };
6963  
6964  module.exports = Tokenizer;
6965  
6966  },{"./util/IpadicFormatter":22,"./viterbi/ViterbiBuilder":24,"./viterbi/ViterbiSearcher":27}],7:[function(require,module,exports){
6967  /*
6968   * Copyright 2014 Takuya Asano
6969   * Copyright 2010-2014 Atilika Inc. and contributors
6970   *
6971   * Licensed under the Apache License, Version 2.0 (the "License");
6972   * you may not use this file except in compliance with the License.
6973   * You may obtain a copy of the License at
6974   *
6975   *     http://www.apache.org/licenses/LICENSE-2.0
6976   *
6977   * Unless required by applicable law or agreed to in writing, software
6978   * distributed under the License is distributed on an "AS IS" BASIS,
6979   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6980   * See the License for the specific language governing permissions and
6981   * limitations under the License.
6982   */
6983  
6984  "use strict";
6985  
6986  var Tokenizer = require("./Tokenizer");
6987  var DictionaryLoader = require("./loader/NodeDictionaryLoader");
6988  
6989  /**
6990   * TokenizerBuilder create Tokenizer instance.
6991   * @param {Object} option JSON object which have key-value pairs settings
6992   * @param {string} option.dicPath Dictionary directory path (or URL using in browser)
6993   * @constructor
6994   */
6995  function TokenizerBuilder(option) {
6996      if (option.dicPath == null) {
6997          this.dic_path = "dict/";
6998      } else {
6999          this.dic_path = option.dicPath;
7000      }
7001  }
7002  
7003  /**
7004   * Build Tokenizer instance by asynchronous manner
7005   * @param {TokenizerBuilder~onLoad} callback Callback function
7006   */
7007  TokenizerBuilder.prototype.build = function (callback) {
7008      var loader = new DictionaryLoader(this.dic_path);
7009      loader.load(function (err, dic) {
7010          callback(err, new Tokenizer(dic));
7011      });
7012  };
7013  
7014  /**
7015   * Callback used by build
7016   * @callback TokenizerBuilder~onLoad
7017   * @param {Object} err Error object
7018   * @param {Tokenizer} tokenizer Prepared Tokenizer
7019   */
7020  
7021  module.exports = TokenizerBuilder;
7022  
7023  },{"./Tokenizer":6,"./loader/NodeDictionaryLoader":19}],8:[function(require,module,exports){
7024  /*
7025   * Copyright 2014 Takuya Asano
7026   * Copyright 2010-2014 Atilika Inc. and contributors
7027   *
7028   * Licensed under the Apache License, Version 2.0 (the "License");
7029   * you may not use this file except in compliance with the License.
7030   * You may obtain a copy of the License at
7031   *
7032   *     http://www.apache.org/licenses/LICENSE-2.0
7033   *
7034   * Unless required by applicable law or agreed to in writing, software
7035   * distributed under the License is distributed on an "AS IS" BASIS,
7036   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7037   * See the License for the specific language governing permissions and
7038   * limitations under the License.
7039   */
7040  
7041  "use strict";
7042  
7043  /**
7044   * CharacterClass
7045   * @param {number} class_id
7046   * @param {string} class_name
7047   * @param {boolean} is_always_invoke
7048   * @param {boolean} is_grouping
7049   * @param {number} max_length
7050   * @constructor
7051   */
7052  function CharacterClass(class_id, class_name, is_always_invoke, is_grouping, max_length) {
7053      this.class_id = class_id;
7054      this.class_name = class_name;
7055      this.is_always_invoke = is_always_invoke;
7056      this.is_grouping = is_grouping;
7057      this.max_length = max_length;
7058  }
7059  
7060  module.exports = CharacterClass;
7061  
7062  },{}],9:[function(require,module,exports){
7063  /*
7064   * Copyright 2014 Takuya Asano
7065   * Copyright 2010-2014 Atilika Inc. and contributors
7066   *
7067   * Licensed under the Apache License, Version 2.0 (the "License");
7068   * you may not use this file except in compliance with the License.
7069   * You may obtain a copy of the License at
7070   *
7071   *     http://www.apache.org/licenses/LICENSE-2.0
7072   *
7073   * Unless required by applicable law or agreed to in writing, software
7074   * distributed under the License is distributed on an "AS IS" BASIS,
7075   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7076   * See the License for the specific language governing permissions and
7077   * limitations under the License.
7078   */
7079  
7080  "use strict";
7081  
7082  var InvokeDefinitionMap = require("./InvokeDefinitionMap");
7083  var CharacterClass = require("./CharacterClass");
7084  var SurrogateAwareString = require("../util/SurrogateAwareString");
7085  
7086  var DEFAULT_CATEGORY = "DEFAULT";
7087  
7088  /**
7089   * CharacterDefinition represents char.def file and
7090   * defines behavior of unknown word processing
7091   * @constructor
7092   */
7093  function CharacterDefinition() {
7094      this.character_category_map = new Uint8Array(65536);  // for all UCS2 code points
7095      this.compatible_category_map = new Uint32Array(65536);  // for all UCS2 code points
7096      this.invoke_definition_map = null;
7097  }
7098  
7099  /**
7100   * Load CharacterDefinition
7101   * @param {Uint8Array} cat_map_buffer
7102   * @param {Uint32Array} compat_cat_map_buffer
7103   * @param {InvokeDefinitionMap} invoke_def_buffer
7104   * @returns {CharacterDefinition}
7105   */
7106  CharacterDefinition.load = function (cat_map_buffer, compat_cat_map_buffer, invoke_def_buffer) {
7107      var char_def = new CharacterDefinition();
7108      char_def.character_category_map = cat_map_buffer;
7109      char_def.compatible_category_map = compat_cat_map_buffer;
7110      char_def.invoke_definition_map = InvokeDefinitionMap.load(invoke_def_buffer);
7111      return char_def;
7112  };
7113  
7114  CharacterDefinition.parseCharCategory = function (class_id, parsed_category_def) {
7115      var category = parsed_category_def[1];
7116      var invoke = parseInt(parsed_category_def[2]);
7117      var grouping = parseInt(parsed_category_def[3]);
7118      var max_length = parseInt(parsed_category_def[4]);
7119      if (!isFinite(invoke) || (invoke !== 0 && invoke !== 1)) {
7120          console.log("char.def parse error. INVOKE is 0 or 1 in:" + invoke);
7121          return null;
7122      }
7123      if (!isFinite(grouping) || (grouping !== 0 && grouping !== 1)) {
7124          console.log("char.def parse error. GROUP is 0 or 1 in:" + grouping);
7125          return null;
7126      }
7127      if (!isFinite(max_length) || max_length < 0) {
7128          console.log("char.def parse error. LENGTH is 1 to n:" + max_length);
7129          return null;
7130      }
7131      var is_invoke = (invoke === 1);
7132      var is_grouping = (grouping === 1);
7133  
7134      return new CharacterClass(class_id, category, is_invoke, is_grouping, max_length);
7135  };
7136  
7137  CharacterDefinition.parseCategoryMapping = function (parsed_category_mapping) {
7138      var start = parseInt(parsed_category_mapping[1]);
7139      var default_category = parsed_category_mapping[2];
7140      var compatible_category = (3 < parsed_category_mapping.length) ? parsed_category_mapping.slice(3) : [];
7141      if (!isFinite(start) || start < 0 || start > 0xFFFF) {
vendor: 19,784 bytes, lines 7142-7685
7142          console.log("char.def parse error. CODE is invalid:" + start);
7143      }
7144      return { start: start, default: default_category, compatible: compatible_category};
7145  };
7146  
7147  CharacterDefinition.parseRangeCategoryMapping = function (parsed_category_mapping) {
7148      var start = parseInt(parsed_category_mapping[1]);
7149      var end = parseInt(parsed_category_mapping[2]);
7150      var default_category = parsed_category_mapping[3];
7151      var compatible_category = (4 < parsed_category_mapping.length) ? parsed_category_mapping.slice(4) : [];
7152      if (!isFinite(start) || start < 0 || start > 0xFFFF) {
7153          console.log("char.def parse error. CODE is invalid:" + start);
7154      }
7155      if (!isFinite(end) || end < 0 || end > 0xFFFF) {
7156          console.log("char.def parse error. CODE is invalid:" + end);
7157      }
7158      return { start: start, end: end, default: default_category, compatible: compatible_category};
7159  };
7160  
7161  /**
7162   * Initializing method
7163   * @param {Array} category_mapping Array of category mapping
7164   */
7165  CharacterDefinition.prototype.initCategoryMappings = function (category_mapping) {
7166      // Initialize map by DEFAULT class
7167      var code_point;
7168      if (category_mapping != null) {
7169          for (var i = 0; i < category_mapping.length; i++) {
7170              var mapping = category_mapping[i];
7171              var end = mapping.end || mapping.start;
7172              for (code_point = mapping.start; code_point <= end; code_point++) {
7173  
7174                  // Default Category class ID
7175                  this.character_category_map[code_point] = this.invoke_definition_map.lookup(mapping.default);
7176  
7177                  for (var j = 0; j < mapping.compatible.length; j++) {
7178                      var bitset = this.compatible_category_map[code_point];
7179                      var compatible_category = mapping.compatible[j];
7180                      if (compatible_category == null) {
7181                          continue;
7182                      }
7183                      var class_id = this.invoke_definition_map.lookup(compatible_category);  // Default Category
7184                      if (class_id == null) {
7185                          continue;
7186                      }
7187                      var class_id_bit = 1 << class_id;
7188                      bitset = bitset | class_id_bit;  // Set a bit of class ID 例えば、class_idが3のとき、3ビット目に1を立てる
7189                      this.compatible_category_map[code_point] = bitset;
7190                  }
7191              }
7192          }
7193      }
7194      var default_id = this.invoke_definition_map.lookup(DEFAULT_CATEGORY);
7195      if (default_id == null) {
7196          return;
7197      }
7198      for (code_point = 0; code_point < this.character_category_map.length; code_point++) {
7199          // 他に何のクラスも定義されていなかったときだけ DEFAULT
7200          if (this.character_category_map[code_point] === 0) {
7201              // DEFAULT class ID に対応するビットだけ1を立てる
7202              this.character_category_map[code_point] = 1 << default_id;
7203          }
7204      }
7205  };
7206  
7207  /**
7208   * Lookup compatible categories for a character (not included 1st category)
7209   * @param {string} ch UCS2 character (just 1st character is effective)
7210   * @returns {Array.<CharacterClass>} character classes
7211   */
7212  CharacterDefinition.prototype.lookupCompatibleCategory = function (ch) {
7213      var classes = [];
7214  
7215      /*
7216       if (SurrogateAwareString.isSurrogatePair(ch)) {
7217       // Surrogate pair character codes can not be defined by char.def
7218       return classes;
7219       }*/
7220      var code = ch.charCodeAt(0);
7221      var integer;
7222      if (code < this.compatible_category_map.length) {
7223          integer = this.compatible_category_map[code];  // Bitset
7224      }
7225  
7226      if (integer == null || integer === 0) {
7227          return classes;
7228      }
7229  
7230      for (var bit = 0; bit < 32; bit++) {  // Treat "bit" as a class ID
7231          if (((integer << (31 - bit)) >>> 31) === 1) {
7232              var character_class = this.invoke_definition_map.getCharacterClass(bit);
7233              if (character_class == null) {
7234                  continue;
7235              }
7236              classes.push(character_class);
7237          }
7238      }
7239      return classes;
7240  };
7241  
7242  
7243  /**
7244   * Lookup category for a character
7245   * @param {string} ch UCS2 character (just 1st character is effective)
7246   * @returns {CharacterClass} character class
7247   */
7248  CharacterDefinition.prototype.lookup = function (ch) {
7249  
7250      var class_id;
7251  
7252      var code = ch.charCodeAt(0);
7253      if (SurrogateAwareString.isSurrogatePair(ch)) {
7254          // Surrogate pair character codes can not be defined by char.def, so set DEFAULT category
7255          class_id = this.invoke_definition_map.lookup(DEFAULT_CATEGORY);
7256      } else if (code < this.character_category_map.length) {
7257          class_id = this.character_category_map[code];  // Read as integer value
7258      }
7259  
7260      if (class_id == null) {
7261          class_id = this.invoke_definition_map.lookup(DEFAULT_CATEGORY);
7262      }
7263  
7264      return this.invoke_definition_map.getCharacterClass(class_id);
7265  };
7266  
7267  module.exports = CharacterDefinition;
7268  
7269  },{"../util/SurrogateAwareString":23,"./CharacterClass":8,"./InvokeDefinitionMap":12}],10:[function(require,module,exports){
7270  /*
7271   * Copyright 2014 Takuya Asano
7272   * Copyright 2010-2014 Atilika Inc. and contributors
7273   *
7274   * Licensed under the Apache License, Version 2.0 (the "License");
7275   * you may not use this file except in compliance with the License.
7276   * You may obtain a copy of the License at
7277   *
7278   *     http://www.apache.org/licenses/LICENSE-2.0
7279   *
7280   * Unless required by applicable law or agreed to in writing, software
7281   * distributed under the License is distributed on an "AS IS" BASIS,
7282   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7283   * See the License for the specific language governing permissions and
7284   * limitations under the License.
7285   */
7286  
7287  "use strict";
7288  
7289  /**
7290   * Connection costs matrix from cc.dat file.
7291   * 2 dimension matrix [forward_id][backward_id] -> cost
7292   * @constructor
7293   * @param {number} forward_dimension
7294   * @param {number} backward_dimension
7295   */
7296  function ConnectionCosts(forward_dimension, backward_dimension) {
7297      this.forward_dimension = forward_dimension;
7298      this.backward_dimension = backward_dimension;
7299  
7300      // leading 2 integers for forward_dimension, backward_dimension, respectively
7301      this.buffer = new Int16Array(forward_dimension * backward_dimension + 2);
7302      this.buffer[0] = forward_dimension;
7303      this.buffer[1] = backward_dimension;
7304  }
7305  
7306  ConnectionCosts.prototype.put = function (forward_id, backward_id, cost) {
7307      var index = forward_id * this.backward_dimension + backward_id + 2;
7308      if (this.buffer.length < index + 1) {
7309          throw "ConnectionCosts buffer overflow";
7310      }
7311      this.buffer[index] = cost;
7312  };
7313  
7314  ConnectionCosts.prototype.get = function (forward_id, backward_id) {
7315      var index = forward_id * this.backward_dimension + backward_id + 2;
7316      if (this.buffer.length < index + 1) {
7317          throw "ConnectionCosts buffer overflow";
7318      }
7319      return this.buffer[index];
7320  };
7321  
7322  ConnectionCosts.prototype.loadConnectionCosts = function (connection_costs_buffer) {
7323      this.forward_dimension = connection_costs_buffer[0];
7324      this.backward_dimension = connection_costs_buffer[1];
7325      this.buffer = connection_costs_buffer;
7326  };
7327  
7328  module.exports = ConnectionCosts;
7329  
7330  },{}],11:[function(require,module,exports){
7331  /*
7332   * Copyright 2014 Takuya Asano
7333   * Copyright 2010-2014 Atilika Inc. and contributors
7334   *
7335   * Licensed under the Apache License, Version 2.0 (the "License");
7336   * you may not use this file except in compliance with the License.
7337   * You may obtain a copy of the License at
7338   *
7339   *     http://www.apache.org/licenses/LICENSE-2.0
7340   *
7341   * Unless required by applicable law or agreed to in writing, software
7342   * distributed under the License is distributed on an "AS IS" BASIS,
7343   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7344   * See the License for the specific language governing permissions and
7345   * limitations under the License.
7346   */
7347  
7348  "use strict";
7349  
7350  var doublearray = require("doublearray");
7351  var TokenInfoDictionary = require("./TokenInfoDictionary");
7352  var ConnectionCosts = require("./ConnectionCosts");
7353  var UnknownDictionary = require("./UnknownDictionary");
7354  
7355  /**
7356   * Dictionaries container for Tokenizer
7357   * @param {DoubleArray} trie
7358   * @param {TokenInfoDictionary} token_info_dictionary
7359   * @param {ConnectionCosts} connection_costs
7360   * @param {UnknownDictionary} unknown_dictionary
7361   * @constructor
7362   */
7363  function DynamicDictionaries(trie, token_info_dictionary, connection_costs, unknown_dictionary) {
7364      if (trie != null) {
7365          this.trie = trie;
7366      } else {
7367          this.trie = doublearray.builder(0).build([
7368              {k: "", v: 1}
7369          ]);
7370      }
7371      if (token_info_dictionary != null) {
7372          this.token_info_dictionary = token_info_dictionary;
7373      } else {
7374          this.token_info_dictionary = new TokenInfoDictionary();
7375      }
7376      if (connection_costs != null) {
7377          this.connection_costs = connection_costs;
7378      } else {
7379          // backward_size * backward_size
7380          this.connection_costs = new ConnectionCosts(0, 0);
7381      }
7382      if (unknown_dictionary != null) {
7383          this.unknown_dictionary = unknown_dictionary;
7384      } else {
7385          this.unknown_dictionary = new UnknownDictionary();
7386      }
7387  }
7388  
7389  // from base.dat & check.dat
7390  DynamicDictionaries.prototype.loadTrie = function (base_buffer, check_buffer) {
7391      this.trie = doublearray.load(base_buffer, check_buffer);
7392      return this;
7393  };
7394  
7395  DynamicDictionaries.prototype.loadTokenInfoDictionaries = function (token_info_buffer, pos_buffer, target_map_buffer) {
7396      this.token_info_dictionary.loadDictionary(token_info_buffer);
7397      this.token_info_dictionary.loadPosVector(pos_buffer);
7398      this.token_info_dictionary.loadTargetMap(target_map_buffer);
7399      return this;
7400  };
7401  
7402  DynamicDictionaries.prototype.loadConnectionCosts = function (cc_buffer) {
7403      this.connection_costs.loadConnectionCosts(cc_buffer);
7404      return this;
7405  };
7406  
7407  DynamicDictionaries.prototype.loadUnknownDictionaries = function (unk_buffer, unk_pos_buffer, unk_map_buffer, cat_map_buffer, compat_cat_map_buffer, invoke_def_buffer) {
7408      this.unknown_dictionary.loadUnknownDictionaries(unk_buffer, unk_pos_buffer, unk_map_buffer, cat_map_buffer, compat_cat_map_buffer, invoke_def_buffer);
7409      return this;
7410  };
7411  
7412  module.exports = DynamicDictionaries;
7413  
7414  },{"./ConnectionCosts":10,"./TokenInfoDictionary":13,"./UnknownDictionary":14,"doublearray":2}],12:[function(require,module,exports){
7415  /*
7416   * Copyright 2014 Takuya Asano
7417   * Copyright 2010-2014 Atilika Inc. and contributors
7418   *
7419   * Licensed under the Apache License, Version 2.0 (the "License");
7420   * you may not use this file except in compliance with the License.
7421   * You may obtain a copy of the License at
7422   *
7423   *     http://www.apache.org/licenses/LICENSE-2.0
7424   *
7425   * Unless required by applicable law or agreed to in writing, software
7426   * distributed under the License is distributed on an "AS IS" BASIS,
7427   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7428   * See the License for the specific language governing permissions and
7429   * limitations under the License.
7430   */
7431  
7432  "use strict";
7433  
7434  var ByteBuffer = require("../util/ByteBuffer");
7435  var CharacterClass = require("./CharacterClass");
7436  
7437  /**
7438   * InvokeDefinitionMap represents invoke definition a part of char.def
7439   * @constructor
7440   */
7441  function InvokeDefinitionMap() {
7442      this.map = [];
7443      this.lookup_table = {};  // Just for building dictionary
7444  }
7445  
7446  /**
7447   * Load InvokeDefinitionMap from buffer
7448   * @param {Uint8Array} invoke_def_buffer
7449   * @returns {InvokeDefinitionMap}
7450   */
7451  InvokeDefinitionMap.load = function (invoke_def_buffer) {
7452      var invoke_def = new InvokeDefinitionMap();
7453      var character_category_definition = [];
7454  
7455      var buffer = new ByteBuffer(invoke_def_buffer);
7456      while (buffer.position + 1 < buffer.size()) {
7457          var class_id = character_category_definition.length;
7458          var is_always_invoke = buffer.get();
7459          var is_grouping = buffer.get();
7460          var max_length = buffer.getInt();
7461          var class_name = buffer.getString();
7462          character_category_definition.push(new CharacterClass(class_id, class_name, is_always_invoke, is_grouping, max_length));
7463      }
7464  
7465      invoke_def.init(character_category_definition);
7466  
7467      return invoke_def;
7468  };
7469  
7470  /**
7471   * Initializing method
7472   * @param {Array.<CharacterClass>} character_category_definition Array of CharacterClass
7473   */
7474  InvokeDefinitionMap.prototype.init = function (character_category_definition) {
7475      if (character_category_definition == null) {
7476          return;
7477      }
7478      for (var i = 0; i < character_category_definition.length; i++) {
7479          var character_class = character_category_definition[i];
7480          this.map[i] = character_class;
7481          this.lookup_table[character_class.class_name] = i;
7482      }
7483  };
7484  
7485  /**
7486   * Get class information by class ID
7487   * @param {number} class_id
7488   * @returns {CharacterClass}
7489   */
7490  InvokeDefinitionMap.prototype.getCharacterClass = function (class_id) {
7491      return this.map[class_id];
7492  };
7493  
7494  /**
7495   * For building character definition dictionary
7496   * @param {string} class_name character
7497   * @returns {number} class_id
7498   */
7499  InvokeDefinitionMap.prototype.lookup = function (class_name) {
7500      var class_id = this.lookup_table[class_name];
7501      if (class_id == null) {
7502          return null;
7503      }
7504      return class_id;
7505  };
7506  
7507  /**
7508   * Transform from map to binary buffer
7509   * @returns {Uint8Array}
7510   */
7511  InvokeDefinitionMap.prototype.toBuffer = function () {
7512      var buffer = new ByteBuffer();
7513      for (var i = 0; i < this.map.length; i++) {
7514          var char_class = this.map[i];
7515          buffer.put(char_class.is_always_invoke);
7516          buffer.put(char_class.is_grouping);
7517          buffer.putInt(char_class.max_length);
7518          buffer.putString(char_class.class_name);
7519      }
7520      buffer.shrink();
7521      return buffer.buffer;
7522  };
7523  
7524  module.exports = InvokeDefinitionMap;
7525  
7526  },{"../util/ByteBuffer":21,"./CharacterClass":8}],13:[function(require,module,exports){
7527  /*
7528   * Copyright 2014 Takuya Asano
7529   * Copyright 2010-2014 Atilika Inc. and contributors
7530   *
7531   * Licensed under the Apache License, Version 2.0 (the "License");
7532   * you may not use this file except in compliance with the License.
7533   * You may obtain a copy of the License at
7534   *
7535   *     http://www.apache.org/licenses/LICENSE-2.0
7536   *
7537   * Unless required by applicable law or agreed to in writing, software
7538   * distributed under the License is distributed on an "AS IS" BASIS,
7539   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7540   * See the License for the specific language governing permissions and
7541   * limitations under the License.
7542   */
7543  
7544  "use strict";
7545  
7546  var ByteBuffer = require("../util/ByteBuffer");
7547  
7548  /**
7549   * TokenInfoDictionary
7550   * @constructor
7551   */
7552  function TokenInfoDictionary() {
7553      this.dictionary = new ByteBuffer(10 * 1024 * 1024);
7554      this.target_map = {};  // trie_id (of surface form) -> token_info_id (of token)
7555      this.pos_buffer = new ByteBuffer(10 * 1024 * 1024);
7556  }
7557  
7558  // left_id right_id word_cost ...
7559  // ^ this position is token_info_id
7560  TokenInfoDictionary.prototype.buildDictionary = function (entries) {
7561      var dictionary_entries = {};  // using as hashmap, string -> string (word_id -> surface_form) to build dictionary
7562  
7563      for (var i = 0; i < entries.length; i++) {
7564          var entry = entries[i];
7565  
7566          if (entry.length < 4) {
7567              continue;
7568          }
7569  
7570          var surface_form = entry[0];
7571          var left_id = entry[1];
7572          var right_id = entry[2];
7573          var word_cost = entry[3];
7574          var feature = entry.slice(4).join(",");  // TODO Optimize
7575  
7576          // Assertion
7577          if (!isFinite(left_id) || !isFinite(right_id) || !isFinite(word_cost)) {
7578              console.log(entry);
7579          }
7580  
7581          var token_info_id = this.put(left_id, right_id, word_cost, surface_form, feature);
7582          dictionary_entries[token_info_id] = surface_form;
7583      }
7584  
7585      // Remove last unused area
7586      this.dictionary.shrink();
7587      this.pos_buffer.shrink();
7588  
7589      return dictionary_entries;
7590  };
7591  
7592  TokenInfoDictionary.prototype.put = function (left_id, right_id, word_cost, surface_form, feature) {
7593      var token_info_id = this.dictionary.position;
7594      var pos_id = this.pos_buffer.position;
7595  
7596      this.dictionary.putShort(left_id);
7597      this.dictionary.putShort(right_id);
7598      this.dictionary.putShort(word_cost);
7599      this.dictionary.putInt(pos_id);
7600      this.pos_buffer.putString(surface_form + "," + feature);
7601  
7602      return token_info_id;
7603  };
7604  
7605  TokenInfoDictionary.prototype.addMapping = function (source, target) {
7606      var mapping = this.target_map[source];
7607      if (mapping == null) {
7608          mapping = [];
7609      }
7610      mapping.push(target);
7611  
7612      this.target_map[source] = mapping;
7613  };
7614  
7615  TokenInfoDictionary.prototype.targetMapToBuffer = function () {
7616      var buffer = new ByteBuffer();
7617      var map_keys_size = Object.keys(this.target_map).length;
7618      buffer.putInt(map_keys_size);
7619      for (var key in this.target_map) {
7620          var values = this.target_map[key];  // Array
7621          var map_values_size = values.length;
7622          buffer.putInt(parseInt(key));
7623          buffer.putInt(map_values_size);
7624          for (var i = 0; i < values.length; i++) {
7625              buffer.putInt(values[i]);
7626          }
7627      }
7628      return buffer.shrink();  // Shrink-ed Typed Array
7629  };
7630  
7631  // from tid.dat
7632  TokenInfoDictionary.prototype.loadDictionary = function (array_buffer) {
7633      this.dictionary = new ByteBuffer(array_buffer);
7634      return this;
7635  };
7636  
7637  // from tid_pos.dat
7638  TokenInfoDictionary.prototype.loadPosVector = function (array_buffer) {
7639      this.pos_buffer = new ByteBuffer(array_buffer);
7640      return this;
7641  };
7642  
7643  // from tid_map.dat
7644  TokenInfoDictionary.prototype.loadTargetMap = function (array_buffer) {
7645      var buffer = new ByteBuffer(array_buffer);
7646      buffer.position = 0;
7647      this.target_map = {};
7648      buffer.readInt();  // map_keys_size
7649      while (true) {
7650          if (buffer.buffer.length < buffer.position + 1) {
7651              break;
7652          }
7653          var key = buffer.readInt();
7654          var map_values_size = buffer.readInt();
7655          for (var i = 0; i < map_values_size; i++) {
7656              var value = buffer.readInt();
7657              this.addMapping(key, value);
7658          }
7659      }
7660      return this;
7661  };
7662  
7663  /**
7664   * Look up features in the dictionary
7665   * @param {string} token_info_id_str Word ID to look up
7666   * @returns {string} Features string concatenated by ","
7667   */
7668  TokenInfoDictionary.prototype.getFeatures = function (token_info_id_str) {
7669      var token_info_id = parseInt(token_info_id_str);
7670      if (isNaN(token_info_id)) {
7671          // TODO throw error
7672          return "";
7673      }
7674      var pos_id = this.dictionary.getInt(token_info_id + 6);
7675      return this.pos_buffer.getString(pos_id);
7676  };
7677  
7678  module.exports = TokenInfoDictionary;
7679  
7680  },{"../util/ByteBuffer":21}],14:[function(require,module,exports){
7681  /*
7682   * Copyright 2014 Takuya Asano
7683   * Copyright 2010-2014 Atilika Inc. and contributors
7684   *
7685   * Licensed under the Apache License, Version 2.0 (the "License");
7686   * you may not use this file except in compliance with the License.
7687   * You may obtain a copy of the License at
7688   *
7689   *     http://www.apache.org/licenses/LICENSE-2.0
7690   *
7691   * Unless required by applicable law or agreed to in writing, software
7692   * distributed under the License is distributed on an "AS IS" BASIS,
7693   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7694   * See the License for the specific language governing permissions and
7695   * limitations under the License.
7696   */
7697  
7698  "use strict";
7699  
7700  var TokenInfoDictionary = require("./TokenInfoDictionary");
7701  var CharacterDefinition = require("./CharacterDefinition");
7702  var ByteBuffer = require("../util/ByteBuffer");
7703  
7704  /**
7705   * UnknownDictionary
7706   * @constructor
7707   */
7708  function UnknownDictionary() {
7709      this.dictionary = new ByteBuffer(10 * 1024 * 1024);
7710      this.target_map = {};  // class_id (of CharacterClass) -> token_info_id (of unknown class)
7711      this.pos_buffer = new ByteBuffer(10 * 1024 * 1024);
7712      this.character_definition = null;
7713  }
7714  
7715  // Inherit from TokenInfoDictionary as a super class
7716  UnknownDictionary.prototype = Object.create(TokenInfoDictionary.prototype);
7717  
7718  UnknownDictionary.prototype.characterDefinition = function (character_definition) {
7719      this.character_definition = character_definition;
7720      return this;
7721  };
7722  
7723  UnknownDictionary.prototype.lookup = function (ch) {
7724      return this.character_definition.lookup(ch);
7725  };
7726  
7727  UnknownDictionary.prototype.lookupCompatibleCategory = function (ch) {
7728      return this.character_definition.lookupCompatibleCategory(ch);
7729  };
7730  
7731  UnknownDictionary.prototype.loadUnknownDictionaries = function (unk_buffer, unk_pos_buffer, unk_map_buffer, cat_map_buffer, compat_cat_map_buffer, invoke_def_buffer) {
7732      this.loadDictionary(unk_buffer);
7733      this.loadPosVector(unk_pos_buffer);
7734      this.loadTargetMap(unk_map_buffer);
7735      this.character_definition = CharacterDefinition.load(cat_map_buffer, compat_cat_map_buffer, invoke_def_buffer);
7736  };
7737  
7738  module.exports = UnknownDictionary;
7739  
7740  },{"../util/ByteBuffer":21,"./CharacterDefinition":9,"./TokenInfoDictionary":13}],15:[function(require,module,exports){
7741  /*
7742   * Copyright 2014 Takuya Asano
7743   * Copyright 2010-2014 Atilika Inc. and contributors
7744   *
7745   * Licensed under the Apache License, Version 2.0 (the "License");
7746   * you may not use this file except in compliance with the License.
7747   * You may obtain a copy of the License at
7748   *
7749   *     http://www.apache.org/licenses/LICENSE-2.0
7750   *
7751   * Unless required by applicable law or agreed to in writing, software
7752   * distributed under the License is distributed on an "AS IS" BASIS,
7753   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7754   * See the License for the specific language governing permissions and
7755   * limitations under the License.
7756   */
7757  
7758  "use strict";
7759  
7760  var CharacterDefinition = require("../CharacterDefinition");
7761  var InvokeDefinitionMap = require("../InvokeDefinitionMap");
7762  
7763  var CATEGORY_DEF_PATTERN = /^(\w+)\s+(\d)\s+(\d)\s+(\d)/;
7764  var CATEGORY_MAPPING_PATTERN = /^(0x[0-9A-F]{4})(?:\s+([^#\s]+))(?:\s+([^#\s]+))*/;
7765  var RANGE_CATEGORY_MAPPING_PATTERN = /^(0x[0-9A-F]{4})\.\.(0x[0-9A-F]{4})(?:\s+([^#\s]+))(?:\s+([^#\s]+))*/;
7766  
7767  /**
7768   * CharacterDefinitionBuilder
7769   * @constructor
7770   */
7771  function CharacterDefinitionBuilder() {
7772      this.char_def = new CharacterDefinition();
7773      this.char_def.invoke_definition_map = new InvokeDefinitionMap();
7774      this.character_category_definition = [];
7775      this.category_mapping = [];
7776  }
7777  
7778  CharacterDefinitionBuilder.prototype.putLine = function (line) {
7779      var parsed_category_def = CATEGORY_DEF_PATTERN.exec(line);
7780      if (parsed_category_def != null) {
7781          var class_id = this.character_category_definition.length;
7782          var char_class = CharacterDefinition.parseCharCategory(class_id, parsed_category_def);
7783          if (char_class == null) {
7784              return;
7785          }
7786          this.character_category_definition.push(char_class);
7787          return;
7788      }
7789      var parsed_category_mapping = CATEGORY_MAPPING_PATTERN.exec(line);
7790      if (parsed_category_mapping != null) {
7791          var mapping = CharacterDefinition.parseCategoryMapping(parsed_category_mapping);
7792          this.category_mapping.push(mapping);
7793      }
7794      var parsed_range_category_mapping = RANGE_CATEGORY_MAPPING_PATTERN.exec(line);
7795      if (parsed_range_category_mapping != null) {
7796          var range_mapping = CharacterDefinition.parseRangeCategoryMapping(parsed_range_category_mapping);
7797          this.category_mapping.push(range_mapping);
7798      }
7799  };
7800  
7801  CharacterDefinitionBuilder.prototype.build = function () {
7802      // TODO If DEFAULT category does not exist, throw error
7803      this.char_def.invoke_definition_map.init(this.character_category_definition);
7804      this.char_def.initCategoryMappings(this.category_mapping);
7805      return this.char_def;
7806  };
7807  
7808  module.exports = CharacterDefinitionBuilder;
7809  
7810  },{"../CharacterDefinition":9,"../InvokeDefinitionMap":12}],16:[function(require,module,exports){
7811  /*
7812   * Copyright 2014 Takuya Asano
7813   * Copyright 2010-2014 Atilika Inc. and contributors
7814   *
7815   * Licensed under the Apache License, Version 2.0 (the "License");
7816   * you may not use this file except in compliance with the License.
7817   * You may obtain a copy of the License at
7818   *
7819   *     http://www.apache.org/licenses/LICENSE-2.0
7820   *
7821   * Unless required by applicable law or agreed to in writing, software
7822   * distributed under the License is distributed on an "AS IS" BASIS,
7823   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7824   * See the License for the specific language governing permissions and
7825   * limitations under the License.
7826   */
7827  
7828  "use strict";
7829  
7830  var ConnectionCosts = require("../ConnectionCosts");
7831  
7832  /**
7833   * Builder class for constructing ConnectionCosts object
7834   * @constructor
7835   */
7836  function ConnectionCostsBuilder() {
7837      this.lines = 0;
7838      this.connection_cost = null;
7839  }
7840  
7841  ConnectionCostsBuilder.prototype.putLine = function (line) {
7842      if (this.lines === 0) {
7843          var dimensions = line.split(" ");
7844          var forward_dimension = dimensions[0];
7845          var backward_dimension = dimensions[1];
7846  
7847          if (forward_dimension < 0 || backward_dimension < 0) {
7848              throw "Parse error of matrix.def";
7849          }
7850  
7851          this.connection_cost = new ConnectionCosts(forward_dimension, backward_dimension);
7852          this.lines++;
7853          return this;
7854      }
7855  
7856      var costs = line.split(" ");
7857  
7858      if (costs.length !== 3) {
7859          return this;
7860      }
7861  
7862      var forward_id = parseInt(costs[0]);
7863      var backward_id = parseInt(costs[1]);
7864      var cost = parseInt(costs[2]);
7865  
7866      if (forward_id < 0 || backward_id < 0 || !isFinite(forward_id) || !isFinite(backward_id) ||
7867          this.connection_cost.forward_dimension <= forward_id || this.connection_cost.backward_dimension <= backward_id) {
7868          throw "Parse error of matrix.def";
7869      }
7870  
7871      this.connection_cost.put(forward_id, backward_id, cost);
7872      this.lines++;
7873      return this;
7874  };
7875  
7876  ConnectionCostsBuilder.prototype.build = function () {
7877      return this.connection_cost;
7878  };
7879  
7880  module.exports = ConnectionCostsBuilder;
7881  
7882  },{"../ConnectionCosts":10}],17:[function(require,module,exports){
7883  /*
7884   * Copyright 2014 Takuya Asano
7885   * Copyright 2010-2014 Atilika Inc. and contributors
7886   *
7887   * Licensed under the Apache License, Version 2.0 (the "License");
7888   * you may not use this file except in compliance with the License.
7889   * You may obtain a copy of the License at
7890   *
7891   *     http://www.apache.org/licenses/LICENSE-2.0
7892   *
7893   * Unless required by applicable law or agreed to in writing, software
7894   * distributed under the License is distributed on an "AS IS" BASIS,
7895   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7896   * See the License for the specific language governing permissions and
7897   * limitations under the License.
7898   */
7899  
7900  "use strict";
7901  
7902  var doublearray = require("doublearray");
7903  var DynamicDictionaries = require("../DynamicDictionaries");
7904  var TokenInfoDictionary = require("../TokenInfoDictionary");
7905  var ConnectionCostsBuilder = require("./ConnectionCostsBuilder");
7906  var CharacterDefinitionBuilder = require("./CharacterDefinitionBuilder");
7907  var UnknownDictionary = require("../UnknownDictionary");
7908  
7909  /**
7910   * Build dictionaries (token info, connection costs)
7911   *
7912   * Generates from matrix.def
7913   * cc.dat: Connection costs
7914   *
7915   * Generates from *.csv
7916   * dat.dat: Double array
7917   * tid.dat: Token info dictionary
7918   * tid_map.dat: targetMap
7919   * tid_pos.dat: posList (part of speech)
7920   */
7921  function DictionaryBuilder() {
7922      // Array of entries, each entry in Mecab form
7923      // (0: surface form, 1: left id, 2: right id, 3: word cost, 4: part of speech id, 5-: other features)
7924      this.tid_entries = [];
7925      this.unk_entries = [];
7926      this.cc_builder = new ConnectionCostsBuilder();
7927      this.cd_builder = new CharacterDefinitionBuilder();
7928  }
7929  
7930  DictionaryBuilder.prototype.addTokenInfoDictionary = function (line) {
7931      var new_entry = line.split(",");
7932      this.tid_entries.push(new_entry);
7933      return this;
7934  };
7935  
7936  /**
7937   * Put one line of "matrix.def" file for building ConnectionCosts object
7938   * @param {string} line is a line of "matrix.def"
7939   */
7940  DictionaryBuilder.prototype.putCostMatrixLine = function (line) {
7941      this.cc_builder.putLine(line);
7942      return this;
7943  };
7944  
7945  DictionaryBuilder.prototype.putCharDefLine = function (line) {
7946      this.cd_builder.putLine(line);
7947      return this;
7948  };
7949  
7950  /**
7951   * Put one line of "unk.def" file for building UnknownDictionary object
7952   * @param {string} line is a line of "unk.def"
7953   */
7954  DictionaryBuilder.prototype.putUnkDefLine = function (line) {
7955      this.unk_entries.push(line.split(","));
7956      return this;
7957  };
7958  
7959  DictionaryBuilder.prototype.build = function () {
7960      var dictionaries = this.buildTokenInfoDictionary();
7961      var unknown_dictionary = this.buildUnknownDictionary();
7962  
7963      return new DynamicDictionaries(dictionaries.trie, dictionaries.token_info_dictionary, this.cc_builder.build(), unknown_dictionary);
7964  };
7965  
7966  /**
7967   * Build TokenInfoDictionary
7968   *
7969   * @returns {{trie: *, token_info_dictionary: *}}
7970   */
7971  DictionaryBuilder.prototype.buildTokenInfoDictionary = function () {
7972  
7973      var token_info_dictionary = new TokenInfoDictionary();
7974  
7975      // using as hashmap, string -> string (word_id -> surface_form) to build dictionary
7976      var dictionary_entries = token_info_dictionary.buildDictionary(this.tid_entries);
7977  
7978      var trie = this.buildDoubleArray();
7979  
7980      for (var token_info_id in dictionary_entries) {
7981          var surface_form = dictionary_entries[token_info_id];
7982          var trie_id = trie.lookup(surface_form);
7983  
7984          // Assertion
7985          // if (trie_id < 0) {
7986          //     console.log("Not Found:" + surface_form);
7987          // }
7988  
7989          token_info_dictionary.addMapping(trie_id, token_info_id);
7990      }
7991  
7992      return {
7993          trie: trie,
7994          token_info_dictionary: token_info_dictionary
7995      };
7996  };
7997  
7998  DictionaryBuilder.prototype.buildUnknownDictionary = function () {
7999  
8000      var unk_dictionary = new UnknownDictionary();
8001  
8002      // using as hashmap, string -> string (word_id -> surface_form) to build dictionary
8003      var dictionary_entries = unk_dictionary.buildDictionary(this.unk_entries);
8004  
8005      var char_def = this.cd_builder.build(); // Create CharacterDefinition
8006  
vendor: 4,860 bytes, lines 8007-8151
8007      unk_dictionary.characterDefinition(char_def);
8008  
8009      for (var token_info_id in dictionary_entries) {
8010          var class_name = dictionary_entries[token_info_id];
8011          var class_id = char_def.invoke_definition_map.lookup(class_name);
8012  
8013          // Assertion
8014          // if (trie_id < 0) {
8015          //     console.log("Not Found:" + surface_form);
8016          // }
8017  
8018          unk_dictionary.addMapping(class_id, token_info_id);
8019      }
8020  
8021      return unk_dictionary;
8022  };
8023  
8024  /**
8025   * Build double array trie
8026   *
8027   * @returns {DoubleArray} Double-Array trie
8028   */
8029  DictionaryBuilder.prototype.buildDoubleArray = function () {
8030      var trie_id = 0;
8031      var words = this.tid_entries.map(function (entry) {
8032          var surface_form = entry[0];
8033          return { k: surface_form, v: trie_id++ };
8034      });
8035  
8036      var builder = doublearray.builder(1024 * 1024);
8037      return builder.build(words);
8038  };
8039  
8040  module.exports = DictionaryBuilder;
8041  
8042  },{"../DynamicDictionaries":11,"../TokenInfoDictionary":13,"../UnknownDictionary":14,"./CharacterDefinitionBuilder":15,"./ConnectionCostsBuilder":16,"doublearray":2}],18:[function(require,module,exports){
8043  /*
8044   * Copyright 2014 Takuya Asano
8045   * Copyright 2010-2014 Atilika Inc. and contributors
8046   *
8047   * Licensed under the Apache License, Version 2.0 (the "License");
8048   * you may not use this file except in compliance with the License.
8049   * You may obtain a copy of the License at
8050   *
8051   *     http://www.apache.org/licenses/LICENSE-2.0
8052   *
8053   * Unless required by applicable law or agreed to in writing, software
8054   * distributed under the License is distributed on an "AS IS" BASIS,
8055   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8056   * See the License for the specific language governing permissions and
8057   * limitations under the License.
8058   */
8059  
8060  "use strict";
8061  
8062  var TokenizerBuilder = require("./TokenizerBuilder");
8063  var DictionaryBuilder = require("./dict/builder/DictionaryBuilder");
8064  
8065  // Public methods
8066  var kuromoji = {
8067      builder: function (option) {
8068          return new TokenizerBuilder(option);
8069      },
8070      dictionaryBuilder: function () {
8071          return new DictionaryBuilder();
8072      }
8073  };
8074  
8075  module.exports = kuromoji;
8076  
8077  },{"./TokenizerBuilder":7,"./dict/builder/DictionaryBuilder":17}],19:[function(require,module,exports){
8078  /*
8079   * Copyright 2014 Takuya Asano
8080   * Copyright 2010-2014 Atilika Inc. and contributors
8081   *
8082   * Licensed under the Apache License, Version 2.0 (the "License");
8083   * you may not use this file except in compliance with the License.
8084   * You may obtain a copy of the License at
8085   *
8086   *     http://www.apache.org/licenses/LICENSE-2.0
8087   *
8088   * Unless required by applicable law or agreed to in writing, software
8089   * distributed under the License is distributed on an "AS IS" BASIS,
8090   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8091   * See the License for the specific language governing permissions and
8092   * limitations under the License.
8093   */
8094  
8095  "use strict";
8096  
8097  var zlib = require("zlibjs/bin/gunzip.min.js");
8098  var DictionaryLoader = require("./DictionaryLoader");
8099  
8100  /**
8101   * BrowserDictionaryLoader inherits DictionaryLoader, using jQuery XHR for download
8102   * @param {string} dic_path Dictionary path
8103   * @constructor
8104   */
8105  function BrowserDictionaryLoader(dic_path) {
8106      DictionaryLoader.apply(this, [dic_path]);
8107  }
8108  
8109  BrowserDictionaryLoader.prototype = Object.create(DictionaryLoader.prototype);
8110  
8111  /**
8112   * Utility function to load gzipped dictionary
8113   * @param {string} url Dictionary URL
8114   * @param {BrowserDictionaryLoader~onLoad} callback Callback function
8115   */
8116  BrowserDictionaryLoader.prototype.loadArrayBuffer = function (url, callback) {
8117      var xhr = new XMLHttpRequest();
8118      xhr.open("GET", url, true);
8119      xhr.responseType = "arraybuffer";
8120      xhr.onload = function () {
8121          if (this.status > 0 && this.status !== 200) {
8122              callback(xhr.statusText, null);
8123              return;
8124          }
8125          var arraybuffer = this.response;
8126  
8127          var gz = new zlib.Zlib.Gunzip(new Uint8Array(arraybuffer));
8128          var typed_array = gz.decompress();
8129          callback(null, typed_array.buffer);
8130      };
8131      xhr.onerror = function (err) {
8132          callback(err, null);
8133      };
8134      xhr.send();
8135  };
8136  
8137  /**
8138   * Callback
8139   * @callback BrowserDictionaryLoader~onLoad
8140   * @param {Object} err Error object
8141   * @param {Uint8Array} buffer Loaded buffer
8142   */
8143  
8144  module.exports = BrowserDictionaryLoader;
8145  
8146  },{"./DictionaryLoader":20,"zlibjs/bin/gunzip.min.js":5}],20:[function(require,module,exports){
8147  /*
8148   * Copyright 2014 Takuya Asano
8149   * Copyright 2010-2014 Atilika Inc. and contributors
8150   *
8151   * Licensed under the Apache License, Version 2.0 (the "License");
8152   * you may not use this file except in compliance with the License.
8153   * You may obtain a copy of the License at
8154   *
8155   *     http://www.apache.org/licenses/LICENSE-2.0
8156   *
8157   * Unless required by applicable law or agreed to in writing, software
8158   * distributed under the License is distributed on an "AS IS" BASIS,
8159   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8160   * See the License for the specific language governing permissions and
8161   * limitations under the License.
8162   */
8163  
8164  "use strict";
8165  
8166  var path = require("path");
8167  var async = require("async");
8168  var DynamicDictionaries = require("../dict/DynamicDictionaries");
8169  
8170  /**
8171   * DictionaryLoader base constructor
8172   * @param {string} dic_path Dictionary path
8173   * @constructor
8174   */
8175  function DictionaryLoader(dic_path) {
8176      this.dic = new DynamicDictionaries();
8177      this.dic_path = dic_path;
8178  }
8179  
8180  DictionaryLoader.prototype.loadArrayBuffer = function (file, callback) {
8181      throw new Error("DictionaryLoader#loadArrayBuffer should be overwrite");
8182  };
8183  
8184  /**
8185   * Load dictionary files
8186   * @param {DictionaryLoader~onLoad} load_callback Callback function called after loaded
8187   */
8188  DictionaryLoader.prototype.load = function (load_callback) {
8189      var dic = this.dic;
8190      var dic_path = this.dic_path;
8191      var loadArrayBuffer = this.loadArrayBuffer;
8192  
8193      async.parallel([
8194          // Trie
8195          function (callback) {
8196              async.map([ "base.dat.gz", "check.dat.gz" ], function (filename, _callback) {
8197                  loadArrayBuffer(path.join(dic_path, filename), function (err, buffer) {
8198                      if(err) {
8199                          return _callback(err);
8200                      }
8201                      _callback(null, buffer);
8202                  });
8203              }, function (err, buffers) {
8204                  if(err) {
8205                      return callback(err);
8206                  }
8207                  var base_buffer = new Int32Array(buffers[0]);
8208                  var check_buffer = new Int32Array(buffers[1]);
8209  
8210                  dic.loadTrie(base_buffer, check_buffer);
8211                  callback(null);
8212              });
8213          },
8214          // Token info dictionaries
8215          function (callback) {
8216              async.map([ "tid.dat.gz", "tid_pos.dat.gz", "tid_map.dat.gz" ], function (filename, _callback) {
8217                  loadArrayBuffer(path.join(dic_path, filename), function (err, buffer) {
8218                      if(err) {
8219                          return _callback(err);
8220                      }
8221                      _callback(null, buffer);
8222                  });
8223              }, function (err, buffers) {
8224                  if(err) {
8225                      return callback(err);
8226                  }
8227                  var token_info_buffer = new Uint8Array(buffers[0]);
8228                  var pos_buffer = new Uint8Array(buffers[1]);
8229                  var target_map_buffer = new Uint8Array(buffers[2]);
8230  
8231                  dic.loadTokenInfoDictionaries(token_info_buffer, pos_buffer, target_map_buffer);
8232                  callback(null);
8233              });
8234          },
8235          // Connection cost matrix
8236          function (callback) {
8237              loadArrayBuffer(path.join(dic_path, "cc.dat.gz"), function (err, buffer) {
8238                  if(err) {
8239                      return callback(err);
8240                  }
8241                  var cc_buffer = new Int16Array(buffer);
8242                  dic.loadConnectionCosts(cc_buffer);
8243                  callback(null);
8244              });
8245          },
8246          // Unknown dictionaries
8247          function (callback) {
8248              async.map([ "unk.dat.gz", "unk_pos.dat.gz", "unk_map.dat.gz", "unk_char.dat.gz", "unk_compat.dat.gz", "unk_invoke.dat.gz" ], function (filename, _callback) {
8249                  loadArrayBuffer(path.join(dic_path, filename), function (err, buffer) {
8250                      if(err) {
8251                          return _callback(err);
8252                      }
8253                      _callback(null, buffer);
8254                  });
8255              }, function (err, buffers) {
8256                  if(err) {
8257                      return callback(err);
8258                  }
8259                  var unk_buffer = new Uint8Array(buffers[0]);
8260                  var unk_pos_buffer = new Uint8Array(buffers[1]);
8261                  var unk_map_buffer = new Uint8Array(buffers[2]);
8262                  var cat_map_buffer = new Uint8Array(buffers[3]);
8263                  var compat_cat_map_buffer = new Uint32Array(buffers[4]);
8264                  var invoke_def_buffer = new Uint8Array(buffers[5]);
8265  
8266                  dic.loadUnknownDictionaries(unk_buffer, unk_pos_buffer, unk_map_buffer, cat_map_buffer, compat_cat_map_buffer, invoke_def_buffer);
8267                  // dic.loadUnknownDictionaries(char_buffer, unk_buffer);
8268                  callback(null);
8269              });
8270          }
8271      ], function (err) {
8272          load_callback(err, dic);
8273      });
8274  };
8275  
8276  /**
8277   * Callback
8278   * @callback DictionaryLoader~onLoad
8279   * @param {Object} err Error object
8280   * @param {DynamicDictionaries} dic Loaded dictionary
8281   */
8282  
8283  module.exports = DictionaryLoader;
8284  
8285  },{"../dict/DynamicDictionaries":11,"async":1,"path":3}],21:[function(require,module,exports){
8286  /*
8287   * Copyright 2014 Takuya Asano
8288   * Copyright 2010-2014 Atilika Inc. and contributors
8289   *
8290   * Licensed under the Apache License, Version 2.0 (the "License");
8291   * you may not use this file except in compliance with the License.
8292   * You may obtain a copy of the License at
8293   *
8294   *     http://www.apache.org/licenses/LICENSE-2.0
8295   *
8296   * Unless required by applicable law or agreed to in writing, software
8297   * distributed under the License is distributed on an "AS IS" BASIS,
8298   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8299   * See the License for the specific language governing permissions and
8300   * limitations under the License.
8301   */
8302  
8303  "use strict";
8304  
8305  /**
8306   * Convert String (UTF-16) to UTF-8 ArrayBuffer
8307   *
8308   * @param {String} str UTF-16 string to convert
8309   * @return {Uint8Array} Byte sequence encoded by UTF-8
8310   */
8311  var stringToUtf8Bytes = function (str) {
8312  
8313      // Max size of 1 character is 4 bytes
8314      var bytes = new Uint8Array(str.length * 4);
8315  
8316      var i = 0, j = 0;
8317  
8318      while (i < str.length) {
8319          var unicode_code;
8320  
8321          var utf16_code = str.charCodeAt(i++);
8322          if (utf16_code >= 0xD800 && utf16_code <= 0xDBFF) {
8323              // surrogate pair
8324              var upper = utf16_code;           // high surrogate
8325              var lower = str.charCodeAt(i++);  // low surrogate
8326  
8327              if (lower >= 0xDC00 && lower <= 0xDFFF) {
8328                  unicode_code =
8329                      (upper - 0xD800) * (1 << 10) + (1 << 16) +
8330                      (lower - 0xDC00);
8331              } else {
8332                  // malformed surrogate pair
8333                  return null;
8334              }
8335          } else {
8336              // not surrogate code
8337              unicode_code = utf16_code;
8338          }
8339  
8340          if (unicode_code < 0x80) {
8341              // 1-byte
8342              bytes[j++] = unicode_code;
8343  
8344          } else if (unicode_code < (1 << 11)) {
8345              // 2-byte
8346              bytes[j++] = (unicode_code >>> 6) | 0xC0;
8347              bytes[j++] = (unicode_code & 0x3F) | 0x80;
8348  
8349          } else if (unicode_code < (1 << 16)) {
8350              // 3-byte
8351              bytes[j++] = (unicode_code >>> 12) | 0xE0;
8352              bytes[j++] = ((unicode_code >> 6) & 0x3f) | 0x80;
8353              bytes[j++] = (unicode_code & 0x3F) | 0x80;
8354  
8355          } else if (unicode_code < (1 << 21)) {
8356              // 4-byte
8357              bytes[j++] = (unicode_code >>> 18) | 0xF0;
8358              bytes[j++] = ((unicode_code >> 12) & 0x3F) | 0x80;
8359              bytes[j++] = ((unicode_code >> 6) & 0x3F) | 0x80;
8360              bytes[j++] = (unicode_code & 0x3F) | 0x80;
8361  
8362          } else {
8363              // malformed UCS4 code
8364          }
8365      }
8366  
8367      return bytes.subarray(0, j);
8368  };
8369  
8370  /**
8371   * Convert UTF-8 ArrayBuffer to String (UTF-16)
8372   *
8373   * @param {Array} bytes UTF-8 byte sequence to convert
8374   * @return {String} String encoded by UTF-16
8375   */
8376  var utf8BytesToString = function (bytes) {
8377  
8378      var str = "";
8379      var code, b1, b2, b3, b4, upper, lower;
8380      var i = 0;
8381  
8382      while (i < bytes.length) {
8383  
8384          b1 = bytes[i++];
8385  
8386          if (b1 < 0x80) {
8387              // 1 byte
8388              code = b1;
8389          } else if ((b1 >> 5) === 0x06) {
8390              // 2 bytes
8391              b2 = bytes[i++];
8392              code = ((b1 & 0x1f) << 6) | (b2 & 0x3f);
8393          } else if ((b1 >> 4) === 0x0e) {
8394              // 3 bytes
8395              b2 = bytes[i++];
8396              b3 = bytes[i++];
8397              code = ((b1 & 0x0f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f);
8398          } else {
8399              // 4 bytes
8400              b2 = bytes[i++];
8401              b3 = bytes[i++];
8402              b4 = bytes[i++];
8403              code = ((b1 & 0x07) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x3f) << 6) | (b4 & 0x3f);
8404          }
8405  
8406          if (code < 0x10000) {
8407              str += String.fromCharCode(code);
8408          } else {
8409              // surrogate pair
8410              code -= 0x10000;
8411              upper = (0xD800 | (code >> 10));
8412              lower = (0xDC00 | (code & 0x3FF));
8413              str += String.fromCharCode(upper, lower);
8414          }
8415      }
8416  
8417      return str;
8418  };
8419  
8420  /**
8421   * Utilities to manipulate byte sequence
8422   * @param {(number|Uint8Array)} arg Initial size of this buffer (number), or buffer to set (Uint8Array)
8423   * @constructor
8424   */
8425  function ByteBuffer(arg) {
8426      var initial_size;
8427      if (arg == null) {
8428          initial_size = 1024 * 1024;
8429      } else if (typeof arg === "number") {
8430          initial_size = arg;
8431      } else if (arg instanceof Uint8Array) {
8432          this.buffer = arg;
8433          this.position = 0;  // Overwrite
8434          return;
8435      } else {
8436          // typeof arg -> String
vendor: 20,655 bytes, lines 8437-9060
8437          throw typeof arg + " is invalid parameter type for ByteBuffer constructor";
8438      }
8439      // arg is null or number
8440      this.buffer = new Uint8Array(initial_size);
8441      this.position = 0;
8442  }
8443  
8444  ByteBuffer.prototype.size = function () {
8445      return this.buffer.length;
8446  };
8447  
8448  ByteBuffer.prototype.reallocate = function () {
8449      var new_array = new Uint8Array(this.buffer.length * 2);
8450      new_array.set(this.buffer);
8451      this.buffer = new_array;
8452  };
8453  
8454  ByteBuffer.prototype.shrink = function () {
8455      this.buffer = this.buffer.subarray(0, this.position);
8456      return this.buffer;
8457  };
8458  
8459  ByteBuffer.prototype.put = function (b) {
8460      if (this.buffer.length < this.position + 1) {
8461          this.reallocate();
8462      }
8463      this.buffer[this.position++] = b;
8464  };
8465  
8466  ByteBuffer.prototype.get = function (index) {
8467      if (index == null) {
8468          index = this.position;
8469          this.position += 1;
8470      }
8471      if (this.buffer.length < index + 1) {
8472          return 0;
8473      }
8474      return this.buffer[index];
8475  };
8476  
8477  // Write short to buffer by little endian
8478  ByteBuffer.prototype.putShort = function (num) {
8479      if (0xFFFF < num) {
8480          throw num + " is over short value";
8481      }
8482      var lower = (0x00FF & num);
8483      var upper = (0xFF00 & num) >> 8;
8484      this.put(lower);
8485      this.put(upper);
8486  };
8487  
8488  // Read short from buffer by little endian
8489  ByteBuffer.prototype.getShort = function (index) {
8490      if (index == null) {
8491          index = this.position;
8492          this.position += 2;
8493      }
8494      if (this.buffer.length < index + 2) {
8495          return 0;
8496      }
8497      var lower = this.buffer[index];
8498      var upper = this.buffer[index + 1];
8499      var value = (upper << 8) + lower;
8500      if (value & 0x8000) {
8501    value = -((value - 1) ^ 0xFFFF);
8502      }
8503      return value;
8504  };
8505  
8506  // Write integer to buffer by little endian
8507  ByteBuffer.prototype.putInt = function (num) {
8508      if (0xFFFFFFFF < num) {
8509          throw num + " is over integer value";
8510      }
8511      var b0 = (0x000000FF & num);
8512      var b1 = (0x0000FF00 & num) >> 8;
8513      var b2 = (0x00FF0000 & num) >> 16;
8514      var b3 = (0xFF000000 & num) >> 24;
8515      this.put(b0);
8516      this.put(b1);
8517      this.put(b2);
8518      this.put(b3);
8519  };
8520  
8521  // Read integer from buffer by little endian
8522  ByteBuffer.prototype.getInt = function (index) {
8523      if (index == null) {
8524          index = this.position;
8525          this.position += 4;
8526      }
8527      if (this.buffer.length < index + 4) {
8528          return 0;
8529      }
8530      var b0 = this.buffer[index];
8531      var b1 = this.buffer[index + 1];
8532      var b2 = this.buffer[index + 2];
8533      var b3 = this.buffer[index + 3];
8534  
8535      return (b3 << 24) + (b2 << 16) + (b1 << 8) + b0;
8536  };
8537  
8538  ByteBuffer.prototype.readInt = function () {
8539      var pos = this.position;
8540      this.position += 4;
8541      return this.getInt(pos);
8542  };
8543  
8544  ByteBuffer.prototype.putString = function (str) {
8545      var bytes = stringToUtf8Bytes(str);
8546      for (var i = 0; i < bytes.length; i++) {
8547          this.put(bytes[i]);
8548      }
8549      // put null character as terminal character
8550      this.put(0);
8551  };
8552  
8553  ByteBuffer.prototype.getString = function (index) {
8554      var buf = [],
8555          ch;
8556      if (index == null) {
8557          index = this.position;
8558      }
8559      while (true) {
8560          if (this.buffer.length < index + 1) {
8561              break;
8562          }
8563          ch = this.get(index++);
8564          if (ch === 0) {
8565              break;
8566          } else {
8567              buf.push(ch);
8568          }
8569      }
8570      this.position = index;
8571      return utf8BytesToString(buf);
8572  };
8573  
8574  module.exports = ByteBuffer;
8575  
8576  },{}],22:[function(require,module,exports){
8577  /*
8578   * Copyright 2014 Takuya Asano
8579   * Copyright 2010-2014 Atilika Inc. and contributors
8580   *
8581   * Licensed under the Apache License, Version 2.0 (the "License");
8582   * you may not use this file except in compliance with the License.
8583   * You may obtain a copy of the License at
8584   *
8585   *     http://www.apache.org/licenses/LICENSE-2.0
8586   *
8587   * Unless required by applicable law or agreed to in writing, software
8588   * distributed under the License is distributed on an "AS IS" BASIS,
8589   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8590   * See the License for the specific language governing permissions and
8591   * limitations under the License.
8592   */
8593  
8594  "use strict";
8595  
8596  /**
8597   * Mappings between IPADIC dictionary features and tokenized results
8598   * @constructor
8599   */
8600  function IpadicFormatter() {
8601  }
8602  
8603  IpadicFormatter.prototype.formatEntry = function (word_id, position, type, features) {
8604      var token = {};
8605      token.word_id = word_id;
8606      token.word_type = type;
8607      token.word_position = position;
8608  
8609      token.surface_form = features[0];
8610      token.pos = features[1];
8611      token.pos_detail_1 = features[2];
8612      token.pos_detail_2 = features[3];
8613      token.pos_detail_3 = features[4];
8614      token.conjugated_type = features[5];
8615      token.conjugated_form = features[6];
8616      token.basic_form = features[7];
8617      token.reading = features[8];
8618      token.pronunciation = features[9];
8619  
8620      return token;
8621  };
8622  
8623  IpadicFormatter.prototype.formatUnknownEntry = function (word_id, position, type, features, surface_form) {
8624      var token = {};
8625      token.word_id = word_id;
8626      token.word_type = type;
8627      token.word_position = position;
8628  
8629      token.surface_form = surface_form;
8630      token.pos = features[1];
8631      token.pos_detail_1 = features[2];
8632      token.pos_detail_2 = features[3];
8633      token.pos_detail_3 = features[4];
8634      token.conjugated_type = features[5];
8635      token.conjugated_form = features[6];
8636      token.basic_form = features[7];
8637      // token.reading = features[8];
8638      // token.pronunciation = features[9];
8639  
8640      return token;
8641  };
8642  
8643  module.exports = IpadicFormatter;
8644  
8645  },{}],23:[function(require,module,exports){
8646  /*
8647   * Copyright 2014 Takuya Asano
8648   * Copyright 2010-2014 Atilika Inc. and contributors
8649   *
8650   * Licensed under the Apache License, Version 2.0 (the "License");
8651   * you may not use this file except in compliance with the License.
8652   * You may obtain a copy of the License at
8653   *
8654   *     http://www.apache.org/licenses/LICENSE-2.0
8655   *
8656   * Unless required by applicable law or agreed to in writing, software
8657   * distributed under the License is distributed on an "AS IS" BASIS,
8658   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8659   * See the License for the specific language governing permissions and
8660   * limitations under the License.
8661   */
8662  
8663  "use strict";
8664  
8665  /**
8666   * String wrapper for UTF-16 surrogate pair (4 bytes)
8667   * @param {string} str String to wrap
8668   * @constructor
8669   */
8670  function SurrogateAwareString(str) {
8671      this.str = str;
8672      this.index_mapping = [];
8673  
8674      for (var pos = 0; pos < str.length; pos++) {
8675          var ch = str.charAt(pos);
8676          this.index_mapping.push(pos);
8677          if (SurrogateAwareString.isSurrogatePair(ch)) {
8678              pos++;
8679          }
8680      }
8681      // Surrogate aware length
8682      this.length = this.index_mapping.length;
8683  }
8684  
8685  SurrogateAwareString.prototype.slice = function (index) {
8686      if (this.index_mapping.length <= index) {
8687          return "";
8688      }
8689      var surrogate_aware_index = this.index_mapping[index];
8690      return this.str.slice(surrogate_aware_index);
8691  };
8692  
8693  SurrogateAwareString.prototype.charAt = function (index) {
8694      if (this.str.length <= index) {
8695          return "";
8696      }
8697      var surrogate_aware_start_index = this.index_mapping[index];
8698      var surrogate_aware_end_index = this.index_mapping[index + 1];
8699  
8700      if (surrogate_aware_end_index == null) {
8701          return this.str.slice(surrogate_aware_start_index);
8702      }
8703      return this.str.slice(surrogate_aware_start_index, surrogate_aware_end_index);
8704  };
8705  
8706  SurrogateAwareString.prototype.charCodeAt = function (index) {
8707      if (this.index_mapping.length <= index) {
8708          return NaN;
8709      }
8710      var surrogate_aware_index = this.index_mapping[index];
8711      var upper = this.str.charCodeAt(surrogate_aware_index);
8712      var lower;
8713      if (upper >= 0xD800 && upper <= 0xDBFF && surrogate_aware_index < this.str.length) {
8714          lower = this.str.charCodeAt(surrogate_aware_index + 1);
8715          if (lower >= 0xDC00 && lower <= 0xDFFF) {
8716              return (upper - 0xD800) * 0x400 + lower - 0xDC00 + 0x10000;
8717          }
8718      }
8719      return upper;
8720  };
8721  
8722  SurrogateAwareString.prototype.toString = function () {
8723      return this.str;
8724  };
8725  
8726  SurrogateAwareString.isSurrogatePair = function (ch) {
8727      var utf16_code = ch.charCodeAt(0);
8728      if (utf16_code >= 0xD800 && utf16_code <= 0xDBFF) {
8729          // surrogate pair
8730          return true;
8731      } else {
8732          return false;
8733      }
8734  };
8735  
8736  module.exports = SurrogateAwareString;
8737  
8738  },{}],24:[function(require,module,exports){
8739  /*
8740   * Copyright 2014 Takuya Asano
8741   * Copyright 2010-2014 Atilika Inc. and contributors
8742   *
8743   * Licensed under the Apache License, Version 2.0 (the "License");
8744   * you may not use this file except in compliance with the License.
8745   * You may obtain a copy of the License at
8746   *
8747   *     http://www.apache.org/licenses/LICENSE-2.0
8748   *
8749   * Unless required by applicable law or agreed to in writing, software
8750   * distributed under the License is distributed on an "AS IS" BASIS,
8751   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8752   * See the License for the specific language governing permissions and
8753   * limitations under the License.
8754   */
8755  
8756  "use strict";
8757  
8758  var ViterbiNode = require("./ViterbiNode");
8759  var ViterbiLattice = require("./ViterbiLattice");
8760  var SurrogateAwareString = require("../util/SurrogateAwareString");
8761  
8762  /**
8763   * ViterbiBuilder builds word lattice (ViterbiLattice)
8764   * @param {DynamicDictionaries} dic dictionary
8765   * @constructor
8766   */
8767  function ViterbiBuilder(dic) {
8768      this.trie = dic.trie;
8769      this.token_info_dictionary = dic.token_info_dictionary;
8770      this.unknown_dictionary = dic.unknown_dictionary;
8771  }
8772  
8773  /**
8774   * Build word lattice
8775   * @param {string} sentence_str Input text
8776   * @returns {ViterbiLattice} Word lattice
8777   */
8778  ViterbiBuilder.prototype.build = function (sentence_str) {
8779      var lattice = new ViterbiLattice();
8780      var sentence = new SurrogateAwareString(sentence_str);
8781  
8782      var key, trie_id, left_id, right_id, word_cost;
8783      for (var pos = 0; pos < sentence.length; pos++) {
8784          var tail = sentence.slice(pos);
8785          var vocabulary = this.trie.commonPrefixSearch(tail);
8786          for (var n = 0; n < vocabulary.length; n++) {  // Words in dictionary do not have surrogate pair (only UCS2 set)
8787              trie_id = vocabulary[n].v;
8788              key = vocabulary[n].k;
8789  
8790              var token_info_ids = this.token_info_dictionary.target_map[trie_id];
8791              for (var i = 0; i < token_info_ids.length; i++) {
8792                  var token_info_id = parseInt(token_info_ids[i]);
8793  
8794                  left_id = this.token_info_dictionary.dictionary.getShort(token_info_id);
8795                  right_id = this.token_info_dictionary.dictionary.getShort(token_info_id + 2);
8796                  word_cost = this.token_info_dictionary.dictionary.getShort(token_info_id + 4);
8797  
8798                  // node_name, cost, start_index, length, type, left_id, right_id, surface_form
8799                  lattice.append(new ViterbiNode(token_info_id, word_cost, pos + 1, key.length, "KNOWN", left_id, right_id, key));
8800              }
8801          }
8802  
8803          // Unknown word processing
8804          var surrogate_aware_tail = new SurrogateAwareString(tail);
8805          var head_char = new SurrogateAwareString(surrogate_aware_tail.charAt(0));
8806          var head_char_class = this.unknown_dictionary.lookup(head_char.toString());
8807          if (vocabulary == null || vocabulary.length === 0 || head_char_class.is_always_invoke === 1) {
8808              // Process unknown word
8809              key = head_char;
8810              if (head_char_class.is_grouping === 1 && 1 < surrogate_aware_tail.length) {
8811                  for (var k = 1; k < surrogate_aware_tail.length; k++) {
8812                      var next_char = surrogate_aware_tail.charAt(k);
8813                      var next_char_class = this.unknown_dictionary.lookup(next_char);
8814                      if (head_char_class.class_name !== next_char_class.class_name) {
8815                          break;
8816                      }
8817                      key += next_char;
8818                  }
8819              }
8820  
8821              var unk_ids = this.unknown_dictionary.target_map[head_char_class.class_id];
8822              for (var j = 0; j < unk_ids.length; j++) {
8823                  var unk_id = parseInt(unk_ids[j]);
8824  
8825                  left_id = this.unknown_dictionary.dictionary.getShort(unk_id);
8826                  right_id = this.unknown_dictionary.dictionary.getShort(unk_id + 2);
8827                  word_cost = this.unknown_dictionary.dictionary.getShort(unk_id + 4);
8828  
8829                  // node_name, cost, start_index, length, type, left_id, right_id, surface_form
8830                  lattice.append(new ViterbiNode(unk_id, word_cost, pos + 1, key.length, "UNKNOWN", left_id, right_id, key.toString()));
8831              }
8832          }
8833      }
8834      lattice.appendEos();
8835  
8836      return lattice;
8837  };
8838  
8839  module.exports = ViterbiBuilder;
8840  
8841  },{"../util/SurrogateAwareString":23,"./ViterbiLattice":25,"./ViterbiNode":26}],25:[function(require,module,exports){
8842  /*
8843   * Copyright 2014 Takuya Asano
8844   * Copyright 2010-2014 Atilika Inc. and contributors
8845   *
8846   * Licensed under the Apache License, Version 2.0 (the "License");
8847   * you may not use this file except in compliance with the License.
8848   * You may obtain a copy of the License at
8849   *
8850   *     http://www.apache.org/licenses/LICENSE-2.0
8851   *
8852   * Unless required by applicable law or agreed to in writing, software
8853   * distributed under the License is distributed on an "AS IS" BASIS,
8854   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8855   * See the License for the specific language governing permissions and
8856   * limitations under the License.
8857   */
8858  
8859  "use strict";
8860  
8861  var ViterbiNode = require("./ViterbiNode");
8862  
8863  /**
8864   * ViterbiLattice is a lattice in Viterbi algorithm
8865   * @constructor
8866   */
8867  function ViterbiLattice() {
8868      this.nodes_end_at = [];
8869      this.nodes_end_at[0] = [ new ViterbiNode(-1, 0, 0, 0, "BOS", 0, 0, "") ];
8870      this.eos_pos = 1;
8871  }
8872  
8873  /**
8874   * Append node to ViterbiLattice
8875   * @param {ViterbiNode} node
8876   */
8877  ViterbiLattice.prototype.append = function (node) {
8878      var last_pos = node.start_pos + node.length - 1;
8879      if (this.eos_pos < last_pos) {
8880          this.eos_pos = last_pos;
8881      }
8882  
8883      var prev_nodes = this.nodes_end_at[last_pos];
8884      if (prev_nodes == null) {
8885          prev_nodes = [];
8886      }
8887      prev_nodes.push(node);
8888  
8889      this.nodes_end_at[last_pos] = prev_nodes;
8890  };
8891  
8892  /**
8893   * Set ends with EOS (End of Statement)
8894   */
8895  ViterbiLattice.prototype.appendEos = function () {
8896      var last_index = this.nodes_end_at.length;
8897      this.eos_pos++;
8898      this.nodes_end_at[last_index] = [ new ViterbiNode(-1, 0, this.eos_pos, 0, "EOS", 0, 0, "") ];
8899  };
8900  
8901  module.exports = ViterbiLattice;
8902  
8903  },{"./ViterbiNode":26}],26:[function(require,module,exports){
8904  /*
8905   * Copyright 2014 Takuya Asano
8906   * Copyright 2010-2014 Atilika Inc. and contributors
8907   *
8908   * Licensed under the Apache License, Version 2.0 (the "License");
8909   * you may not use this file except in compliance with the License.
8910   * You may obtain a copy of the License at
8911   *
8912   *     http://www.apache.org/licenses/LICENSE-2.0
8913   *
8914   * Unless required by applicable law or agreed to in writing, software
8915   * distributed under the License is distributed on an "AS IS" BASIS,
8916   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8917   * See the License for the specific language governing permissions and
8918   * limitations under the License.
8919   */
8920  
8921  "use strict";
8922  
8923  /**
8924   * ViterbiNode is a node of ViterbiLattice
8925   * @param {number} node_name Word ID
8926   * @param {number} node_cost Word cost to generate
8927   * @param {number} start_pos Start position from 1
8928   * @param {number} length Word length
8929   * @param {string} type Node type (KNOWN, UNKNOWN, BOS, EOS, ...)
8930   * @param {number} left_id Left context ID
8931   * @param {number} right_id Right context ID
8932   * @param {string} surface_form Surface form of this word
8933   * @constructor
8934   */
8935  function ViterbiNode(node_name, node_cost, start_pos, length, type, left_id, right_id, surface_form) {
8936      this.name = node_name;
8937      this.cost = node_cost;
8938      this.start_pos = start_pos;
8939      this.length = length;
8940      this.left_id = left_id;
8941      this.right_id = right_id;
8942      this.prev = null;
8943      this.surface_form = surface_form;
8944      if (type === "BOS") {
8945          this.shortest_cost = 0;
8946      } else {
8947          this.shortest_cost = Number.MAX_VALUE;
8948      }
8949      this.type = type;
8950  }
8951  
8952  module.exports = ViterbiNode;
8953  
8954  },{}],27:[function(require,module,exports){
8955  /*
8956   * Copyright 2014 Takuya Asano
8957   * Copyright 2010-2014 Atilika Inc. and contributors
8958   *
8959   * Licensed under the Apache License, Version 2.0 (the "License");
8960   * you may not use this file except in compliance with the License.
8961   * You may obtain a copy of the License at
8962   *
8963   *     http://www.apache.org/licenses/LICENSE-2.0
8964   *
8965   * Unless required by applicable law or agreed to in writing, software
8966   * distributed under the License is distributed on an "AS IS" BASIS,
8967   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8968   * See the License for the specific language governing permissions and
8969   * limitations under the License.
8970   */
8971  
8972  "use strict";
8973  
8974  /**
8975   * ViterbiSearcher is for searching best Viterbi path
8976   * @param {ConnectionCosts} connection_costs Connection costs matrix
8977   * @constructor
8978   */
8979  function ViterbiSearcher(connection_costs) {
8980      this.connection_costs = connection_costs;
8981  }
8982  
8983  /**
8984   * Search best path by forward-backward algorithm
8985   * @param {ViterbiLattice} lattice Viterbi lattice to search
8986   * @returns {Array} Shortest path
8987   */
8988  ViterbiSearcher.prototype.search = function (lattice) {
8989      lattice = this.forward(lattice);
8990      return this.backward(lattice);
8991  };
8992  
8993  ViterbiSearcher.prototype.forward = function (lattice) {
8994      var i, j, k;
8995      for (i = 1; i <= lattice.eos_pos; i++) {
8996          var nodes = lattice.nodes_end_at[i];
8997          if (nodes == null) {
8998              continue;
8999          }
9000          for (j = 0; j < nodes.length; j++) {
9001              var node = nodes[j];
9002              var cost = Number.MAX_VALUE;
9003              var shortest_prev_node;
9004  
9005              var prev_nodes = lattice.nodes_end_at[node.start_pos - 1];
9006              if (prev_nodes == null) {
9007                  // TODO process unknown words (repair word lattice)
9008                  continue;
9009              }
9010              for (k = 0; k < prev_nodes.length; k++) {
9011                  var prev_node = prev_nodes[k];
9012  
9013                  var edge_cost;
9014                  if (node.left_id == null || prev_node.right_id == null) {
9015                      // TODO assert
9016                      console.log("Left or right is null");
9017                      edge_cost = 0;
9018                  } else {
9019                      edge_cost = this.connection_costs.get(prev_node.right_id, node.left_id);
9020                  }
9021  
9022                  var _cost = prev_node.shortest_cost + edge_cost + node.cost;
9023                  if (_cost < cost) {
9024                      shortest_prev_node = prev_node;
9025                      cost = _cost;
9026                  }
9027              }
9028  
9029              node.prev = shortest_prev_node;
9030              node.shortest_cost = cost;
9031          }
9032      }
9033      return lattice;
9034  };
9035  
9036  ViterbiSearcher.prototype.backward = function (lattice) {
9037      var shortest_path = [];
9038      var eos = lattice.nodes_end_at[lattice.nodes_end_at.length - 1][0];
9039  
9040      var node_back = eos.prev;
9041      if (node_back == null) {
9042          return [];
9043      }
9044      while (node_back.type !== "BOS") {
9045          shortest_path.push(node_back);
9046          if (node_back.prev == null) {
9047              // TODO Failed to back. Process unknown words?
9048              return [];
9049          }
9050          node_back = node_back.prev;
9051      }
9052  
9053      return shortest_path.reverse();
9054  };
9055  
9056  module.exports = ViterbiSearcher;
9057  
9058  },{}]},{},[18])(18)
9059  });
9060  

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.