f331fa01c4555dc220666191903baadef84ffb86
[yaffs-website] / node_modules / grunt-uncss / node_modules / async / mapValuesLimit.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4     value: true
5 });
6 exports.default = mapValuesLimit;
7
8 var _eachOfLimit = require('./eachOfLimit');
9
10 var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
11
12 var _noop = require('lodash/noop');
13
14 var _noop2 = _interopRequireDefault(_noop);
15
16 var _once = require('./internal/once');
17
18 var _once2 = _interopRequireDefault(_once);
19
20 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22 /**
23  * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
24  * time.
25  *
26  * @name mapValuesLimit
27  * @static
28  * @memberOf module:Collections
29  * @method
30  * @see [async.mapValues]{@link module:Collections.mapValues}
31  * @category Collection
32  * @param {Object} obj - A collection to iterate over.
33  * @param {number} limit - The maximum number of async operations at a time.
34  * @param {Function} iteratee - A function to apply to each value in `obj`.
35  * The iteratee is passed a `callback(err, transformed)` which must be called
36  * once it has completed with an error (which can be `null`) and a
37  * transformed value. Invoked with (value, key, callback).
38  * @param {Function} [callback] - A callback which is called when all `iteratee`
39  * functions have finished, or an error occurs. `result` is a new object consisting
40  * of each key from `obj`, with each transformed value on the right-hand side.
41  * Invoked with (err, result).
42  */
43 function mapValuesLimit(obj, limit, iteratee, callback) {
44     callback = (0, _once2.default)(callback || _noop2.default);
45     var newObj = {};
46     (0, _eachOfLimit2.default)(obj, limit, function (val, key, next) {
47         iteratee(val, key, function (err, result) {
48             if (err) return next(err);
49             newObj[key] = result;
50             next();
51         });
52     }, function (err) {
53         callback(err, newObj);
54     });
55 }
56 module.exports = exports['default'];