lodash.sortby
Advanced tools
Comparing version 2.3.0 to 2.4.0
40
index.js
/** | ||
* Lo-Dash 2.3.0 (Custom Build) <http://lodash.com/> | ||
* Lo-Dash 2.4.0 (Custom Build) <http://lodash.com/> | ||
* Build: `lodash modularize modern exports="npm" -o ./npm/` | ||
@@ -12,3 +12,7 @@ * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> | ||
forEach = require('lodash.foreach'), | ||
getArray = require('lodash._getarray'), | ||
getObject = require('lodash._getobject'), | ||
isArray = require('lodash.isarray'), | ||
map = require('lodash.map'), | ||
releaseArray = require('lodash._releasearray'), | ||
releaseObject = require('lodash._releaseobject'); | ||
@@ -26,2 +30,5 @@ | ||
* | ||
* If an array of property names is provided for `callback` the collection | ||
* will be sorted by each property value. | ||
* | ||
* If an object is provided for `callback` the created "_.where" style callback | ||
@@ -35,3 +42,3 @@ * will return `true` for elements that have the properties of the given object, | ||
* @param {Array|Object|string} collection The collection to iterate over. | ||
* @param {Function|Object|string} [callback=identity] The function called | ||
* @param {Array|Function|Object|string} [callback=identity] The function called | ||
* per iteration. If a property name or object is provided it will be used | ||
@@ -49,15 +56,33 @@ * to create a "_.pluck" or "_.where" style callback, respectively. | ||
* | ||
* var characters = [ | ||
* { 'name': 'barney', 'age': 36 }, | ||
* { 'name': 'fred', 'age': 40 }, | ||
* { 'name': 'barney', 'age': 26 }, | ||
* { 'name': 'fred', 'age': 30 } | ||
* ]; | ||
* | ||
* // using "_.pluck" callback shorthand | ||
* _.sortBy(['banana', 'strawberry', 'apple'], 'length'); | ||
* // => ['apple', 'banana', 'strawberry'] | ||
* _.map(_.sortBy(characters, 'age'), _.values); | ||
* // => [['barney', 26], ['fred', 30], ['barney', 36], ['fred', 40]] | ||
* | ||
* // sorting by multiple properties | ||
* _.map(_.sortBy(characters, ['name', 'age']), _.values); | ||
* // = > [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]] | ||
*/ | ||
function sortBy(collection, callback, thisArg) { | ||
var index = -1, | ||
isArr = isArray(callback), | ||
length = collection ? collection.length : 0, | ||
result = Array(typeof length == 'number' ? length : 0); | ||
callback = createCallback(callback, thisArg, 3); | ||
if (!isArr) { | ||
callback = createCallback(callback, thisArg, 3); | ||
} | ||
forEach(collection, function(value, key, collection) { | ||
var object = result[++index] = getObject(); | ||
object.criteria = callback(value, key, collection); | ||
if (isArr) { | ||
object.criteria = map(callback, function(key) { return value[key]; }); | ||
} else { | ||
(object.criteria = getArray())[0] = callback(value, key, collection); | ||
} | ||
object.index = index; | ||
@@ -72,2 +97,5 @@ object.value = value; | ||
result[length] = object.value; | ||
if (!isArr) { | ||
releaseArray(object.criteria); | ||
} | ||
releaseObject(object); | ||
@@ -74,0 +102,0 @@ } |
{ | ||
"name": "lodash.sortby", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "The Lo-Dash function `_.sortBy` as a Node.js module generated by lodash-cli.", | ||
@@ -18,8 +18,12 @@ "homepage": "http://lodash.com/custom-builds", | ||
"dependencies": { | ||
"lodash._compareascending": "~2.3.0", | ||
"lodash.createcallback": "~2.3.0", | ||
"lodash.foreach": "~2.3.0", | ||
"lodash._getobject": "~2.3.0", | ||
"lodash._releaseobject": "~2.3.0" | ||
"lodash._compareascending": "~2.4.0", | ||
"lodash.createcallback": "~2.4.0", | ||
"lodash.foreach": "~2.4.0", | ||
"lodash._getarray": "~2.4.0", | ||
"lodash._getobject": "~2.4.0", | ||
"lodash.isarray": "~2.4.0", | ||
"lodash.map": "~2.4.0", | ||
"lodash._releasearray": "~2.4.0", | ||
"lodash._releaseobject": "~2.4.0" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.sortby v2.3.0 | ||
# lodash.sortby v2.4.0 | ||
@@ -3,0 +3,0 @@ The [Lo-Dash](http://lodash.com/) function [`_.sortBy`](http://lodash.com/docs#sortBy) as a [Node.js](http://nodejs.org/) module generated by [lodash-cli](https://npmjs.org/package/lodash-cli). |
7261
97
9
+ Addedlodash._getarray@~2.4.0
+ Addedlodash._releasearray@~2.4.0
+ Addedlodash.isarray@~2.4.0
+ Addedlodash.map@~2.4.0
+ Addedlodash._arraypool@2.4.1(transitive)
+ Addedlodash._basebind@2.4.1(transitive)
+ Addedlodash._basecreate@2.4.1(transitive)
+ Addedlodash._basecreatecallback@2.4.1(transitive)
+ Addedlodash._basecreatewrapper@2.4.1(transitive)
+ Addedlodash._baseisequal@2.4.1(transitive)
+ Addedlodash._compareascending@2.4.1(transitive)
+ Addedlodash._createwrapper@2.4.1(transitive)
+ Addedlodash._getarray@2.4.1(transitive)
+ Addedlodash._getobject@2.4.1(transitive)
+ Addedlodash._isnative@2.4.1(transitive)
+ Addedlodash._maxpoolsize@2.4.1(transitive)
+ Addedlodash._objectpool@2.4.1(transitive)
+ Addedlodash._objecttypes@2.4.1(transitive)
+ Addedlodash._releasearray@2.4.1(transitive)
+ Addedlodash._releaseobject@2.4.1(transitive)
+ Addedlodash._setbinddata@2.4.1(transitive)
+ Addedlodash._shimkeys@2.4.1(transitive)
+ Addedlodash._slice@2.4.1(transitive)
+ Addedlodash.bind@2.4.1(transitive)
+ Addedlodash.createcallback@2.4.4(transitive)
+ Addedlodash.foreach@2.4.1(transitive)
+ Addedlodash.forin@2.4.1(transitive)
+ Addedlodash.forown@2.4.1(transitive)
+ Addedlodash.identity@2.4.1(transitive)
+ Addedlodash.isarray@2.4.1(transitive)
+ Addedlodash.isfunction@2.4.1(transitive)
+ Addedlodash.isobject@2.4.1(transitive)
+ Addedlodash.keys@2.4.1(transitive)
+ Addedlodash.map@2.4.1(transitive)
+ Addedlodash.noop@2.4.1(transitive)
+ Addedlodash.property@2.4.1(transitive)
+ Addedlodash.support@2.4.1(transitive)
- Removedlodash._arraypool@2.3.0(transitive)
- Removedlodash._basebind@2.3.0(transitive)
- Removedlodash._basecreate@2.3.0(transitive)
- Removedlodash._basecreatecallback@2.3.0(transitive)
- Removedlodash._basecreatewrapper@2.3.0(transitive)
- Removedlodash._baseisequal@2.3.0(transitive)
- Removedlodash._compareascending@2.3.0(transitive)
- Removedlodash._createwrapper@2.3.0(transitive)
- Removedlodash._getarray@2.3.0(transitive)
- Removedlodash._getobject@2.3.0(transitive)
- Removedlodash._maxpoolsize@2.3.0(transitive)
- Removedlodash._objectpool@2.3.0(transitive)
- Removedlodash._objecttypes@2.3.0(transitive)
- Removedlodash._releasearray@2.3.0(transitive)
- Removedlodash._releaseobject@2.3.0(transitive)
- Removedlodash._renative@2.3.0(transitive)
- Removedlodash._setbinddata@2.3.0(transitive)
- Removedlodash._shimkeys@2.3.0(transitive)
- Removedlodash._slice@2.3.0(transitive)
- Removedlodash.bind@2.3.0(transitive)
- Removedlodash.createcallback@2.3.0(transitive)
- Removedlodash.foreach@2.3.0(transitive)
- Removedlodash.forin@2.3.0(transitive)
- Removedlodash.forown@2.3.0(transitive)
- Removedlodash.identity@2.3.0(transitive)
- Removedlodash.isfunction@2.3.0(transitive)
- Removedlodash.isobject@2.3.0(transitive)
- Removedlodash.keys@2.3.0(transitive)
- Removedlodash.noop@2.3.0(transitive)
- Removedlodash.support@2.3.0(transitive)
Updatedlodash._getobject@~2.4.0
Updatedlodash._releaseobject@~2.4.0
Updatedlodash.createcallback@~2.4.0
Updatedlodash.foreach@~2.4.0