1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _mapLimit = require('./mapLimit.js');
|
8 |
|
9 | var _mapLimit2 = _interopRequireDefault(_mapLimit);
|
10 |
|
11 | var _wrapAsync = require('./internal/wrapAsync.js');
|
12 |
|
13 | var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
14 |
|
15 | var _awaitify = require('./internal/awaitify.js');
|
16 |
|
17 | var _awaitify2 = _interopRequireDefault(_awaitify);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function groupByLimit(coll, limit, iteratee, callback) {
|
42 | var _iteratee = (0, _wrapAsync2.default)(iteratee);
|
43 | return (0, _mapLimit2.default)(coll, limit, (val, iterCb) => {
|
44 | _iteratee(val, (err, key) => {
|
45 | if (err) return iterCb(err);
|
46 | return iterCb(err, { key, val });
|
47 | });
|
48 | }, (err, mapResults) => {
|
49 | var result = {};
|
50 |
|
51 | var { hasOwnProperty } = Object.prototype;
|
52 |
|
53 | for (var i = 0; i < mapResults.length; i++) {
|
54 | if (mapResults[i]) {
|
55 | var { key } = mapResults[i];
|
56 | var { val } = mapResults[i];
|
57 |
|
58 | if (hasOwnProperty.call(result, key)) {
|
59 | result[key].push(val);
|
60 | } else {
|
61 | result[key] = [val];
|
62 | }
|
63 | }
|
64 | }
|
65 |
|
66 | return callback(err, result);
|
67 | });
|
68 | }
|
69 |
|
70 | exports.default = (0, _awaitify2.default)(groupByLimit, 4);
|
71 | module.exports = exports.default; |
\ | No newline at end of file |