react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / collection / sortByAll.js
80742 viewsvar baseFlatten = require('../internal/baseFlatten'),1baseSortByOrder = require('../internal/baseSortByOrder'),2isIterateeCall = require('../internal/isIterateeCall'),3restParam = require('../function/restParam');45/**6* This method is like `_.sortBy` except that it can sort by multiple iteratees7* or property names.8*9* If a property name is provided for an iteratee the created `_.property`10* style callback returns the property value of the given element.11*12* If an object is provided for an iteratee the created `_.matches` style13* callback returns `true` for elements that have the properties of the given14* object, else `false`.15*16* @static17* @memberOf _18* @category Collection19* @param {Array|Object|string} collection The collection to iterate over.20* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees21* The iteratees to sort by, specified as individual values or arrays of values.22* @returns {Array} Returns the new sorted array.23* @example24*25* var users = [26* { 'user': 'fred', 'age': 48 },27* { 'user': 'barney', 'age': 36 },28* { 'user': 'fred', 'age': 42 },29* { 'user': 'barney', 'age': 34 }30* ];31*32* _.map(_.sortByAll(users, ['user', 'age']), _.values);33* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]34*35* _.map(_.sortByAll(users, 'user', function(chr) {36* return Math.floor(chr.age / 10);37* }), _.values);38* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]39*/40var sortByAll = restParam(function(collection, iteratees) {41if (collection == null) {42return [];43}44var guard = iteratees[2];45if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {46iteratees.length = 1;47}48return baseSortByOrder(collection, baseFlatten(iteratees), []);49});5051module.exports = sortByAll;525354