PluginProbe
Force Refresh / 2.0.0
Force Refresh v2.0.0
3.2.1 3.2.0 3.1.2 3.1.1 3.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.12.0 All 54 releases
force-refresh / node_modules / handlebars / node_modules / async / groupByLimit.js

groupByLimit.js in Force Refresh 2.0.0, at node_modules/handlebars/node_modules/async/groupByLimit.js

71 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4 value: true
5 });
6
7 exports.default = function (coll, limit, iteratee, callback) {
8 callback = callback || _noop2.default;
9 var _iteratee = (0, _wrapAsync2.default)(iteratee);
10 (0, _mapLimit2.default)(coll, limit, function (val, callback) {
11 _iteratee(val, function (err, key) {
12 if (err) return callback(err);
13 return callback(null, { key: key, val: val });
14 });
15 }, function (err, mapResults) {
16 var result = {};
17 // from MDN, handle object having an `hasOwnProperty` prop
18 var hasOwnProperty = Object.prototype.hasOwnProperty;
19
20 for (var i = 0; i < mapResults.length; i++) {
21 if (mapResults[i]) {
22 var key = mapResults[i].key;
23 var val = mapResults[i].val;
24
25 if (hasOwnProperty.call(result, key)) {
26 result[key].push(val);
27 } else {
28 result[key] = [val];
29 }
30 }
31 }
32
33 return callback(err, result);
34 });
35 };
36
37 var _noop = require('lodash/noop');
38
39 var _noop2 = _interopRequireDefault(_noop);
40
41 var _mapLimit = require('./mapLimit');
42
43 var _mapLimit2 = _interopRequireDefault(_mapLimit);
44
45 var _wrapAsync = require('./internal/wrapAsync');
46
47 var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
48
49 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50
51 ;
52 /**
53 * The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.
54 *
55 * @name groupByLimit
56 * @static
57 * @memberOf module:Collections
58 * @method
59 * @see [async.groupBy]{@link module:Collections.groupBy}
60 * @category Collection
61 * @param {Array|Iterable|Object} coll - A collection to iterate over.
62 * @param {number} limit - The maximum number of async operations at a time.
63 * @param {AsyncFunction} iteratee - An async function to apply to each item in
64 * `coll`.
65 * The iteratee should complete with a `key` to group the value under.
66 * Invoked with (value, callback).
67 * @param {Function} [callback] - A callback which is called when all `iteratee`
68 * functions have finished, or an error occurs. Result is an `Object` whoses
69 * properties are arrays of values which returned the corresponding key.
70 */
71 module.exports = exports['default'];