Security update to Drupal 8.4.6
[yaffs-website] / node_modules / grunt-uncss / node_modules / async / sortBy.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4     value: true
5 });
6 exports.default = sortBy;
7
8 var _arrayMap = require('lodash/_arrayMap');
9
10 var _arrayMap2 = _interopRequireDefault(_arrayMap);
11
12 var _baseProperty = require('lodash/_baseProperty');
13
14 var _baseProperty2 = _interopRequireDefault(_baseProperty);
15
16 var _map = require('./map');
17
18 var _map2 = _interopRequireDefault(_map);
19
20 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22 /**
23  * Sorts a list by the results of running each `coll` value through an async
24  * `iteratee`.
25  *
26  * @name sortBy
27  * @static
28  * @memberOf module:Collections
29  * @method
30  * @category Collection
31  * @param {Array|Iterable|Object} coll - A collection to iterate over.
32  * @param {Function} iteratee - A function to apply to each item in `coll`.
33  * The iteratee is passed a `callback(err, sortValue)` which must be called once
34  * it has completed with an error (which can be `null`) and a value to use as
35  * the sort criteria. Invoked with (item, callback).
36  * @param {Function} callback - A callback which is called after all the
37  * `iteratee` functions have finished, or an error occurs. Results is the items
38  * from the original `coll` sorted by the values returned by the `iteratee`
39  * calls. Invoked with (err, results).
40  * @example
41  *
42  * async.sortBy(['file1','file2','file3'], function(file, callback) {
43  *     fs.stat(file, function(err, stats) {
44  *         callback(err, stats.mtime);
45  *     });
46  * }, function(err, results) {
47  *     // results is now the original array of files sorted by
48  *     // modified date
49  * });
50  *
51  * // By modifying the callback parameter the
52  * // sorting order can be influenced:
53  *
54  * // ascending order
55  * async.sortBy([1,9,3,5], function(x, callback) {
56  *     callback(null, x);
57  * }, function(err,result) {
58  *     // result callback
59  * });
60  *
61  * // descending order
62  * async.sortBy([1,9,3,5], function(x, callback) {
63  *     callback(null, x*-1);    //<- x*-1 instead of x, turns the order around
64  * }, function(err,result) {
65  *     // result callback
66  * });
67  */
68 function sortBy(coll, iteratee, callback) {
69     (0, _map2.default)(coll, function (x, callback) {
70         iteratee(x, function (err, criteria) {
71             if (err) return callback(err);
72             callback(null, { value: x, criteria: criteria });
73         });
74     }, function (err, results) {
75         if (err) return callback(err);
76         callback(null, (0, _arrayMap2.default)(results.sort(comparator), (0, _baseProperty2.default)('value')));
77     });
78
79     function comparator(left, right) {
80         var a = left.criteria,
81             b = right.criteria;
82         return a < b ? -1 : a > b ? 1 : 0;
83     }
84 }
85 module.exports = exports['default'];