lodash.findindex
Advanced tools
Comparing version 3.0.0 to 3.1.0
74
index.js
/** | ||
* lodash 3.0.0 (Custom Build) <https://lodash.com/> | ||
* lodash 3.1.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE> | ||
* Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var baseCallback = require('lodash._basecallback'); | ||
var baseCallback = require('lodash._basecallback'), | ||
baseFindIndex = require('lodash._basefindindex'); | ||
/** | ||
* Creates a `_.findIndex` or `_.findLastIndex` function. | ||
* | ||
* @private | ||
* @param {boolean} [fromRight] Specify iterating from right to left. | ||
* @returns {Function} Returns the new find function. | ||
*/ | ||
function createFindIndex(fromRight) { | ||
return function(array, predicate, thisArg) { | ||
if (!(array && array.length)) { | ||
return -1; | ||
} | ||
predicate = baseCallback(predicate, thisArg, 3); | ||
return baseFindIndex(array, predicate, fromRight); | ||
}; | ||
} | ||
/** | ||
* This method is like `_.find` except that it returns the index of the first | ||
* element `predicate` returns truthy for, instead of the element itself. | ||
* element `predicate` returns truthy for instead of the element itself. | ||
* | ||
* If a property name is provided for `predicate` the created "_.property" | ||
* If a property name is provided for `predicate` the created `_.property` | ||
* style callback returns the property value of the given element. | ||
* | ||
* If an object is provided for `predicate` the created "_.matches" style | ||
* If a value is also provided for `thisArg` the created `_.matchesProperty` | ||
* style callback returns `true` for elements that have a matching property | ||
* value, else `false`. | ||
* | ||
* If an object is provided for `predicate` the created `_.matches` style | ||
* callback returns `true` for elements that have the properties of the given | ||
@@ -27,4 +49,3 @@ * object, else `false`. | ||
* @param {Function|Object|string} [predicate=_.identity] The function invoked | ||
* per iteration. If a property name or object is provided it is used to | ||
* create a "_.property" or "_.matches" style callback respectively. | ||
* per iteration. | ||
* @param {*} [thisArg] The `this` binding of `predicate`. | ||
@@ -35,31 +56,26 @@ * @returns {number} Returns the index of the found element, else `-1`. | ||
* var users = [ | ||
* { 'user': 'barney', 'age': 36, 'active': false }, | ||
* { 'user': 'fred', 'age': 40, 'active': true }, | ||
* { 'user': 'pebbles', 'age': 1, 'active': false } | ||
* { 'user': 'barney', 'active': false }, | ||
* { 'user': 'fred', 'active': false }, | ||
* { 'user': 'pebbles', 'active': true } | ||
* ]; | ||
* | ||
* _.findIndex(users, function(chr) { return chr.age < 40; }); | ||
* _.findIndex(users, function(chr) { | ||
* return chr.user == 'barney'; | ||
* }); | ||
* // => 0 | ||
* | ||
* // using the "_.matches" callback shorthand | ||
* _.findIndex(users, { 'age': 1 }); | ||
* // => 2 | ||
* // using the `_.matches` callback shorthand | ||
* _.findIndex(users, { 'user': 'fred', 'active': false }); | ||
* // => 1 | ||
* | ||
* // using the "_.property" callback shorthand | ||
* // using the `_.matchesProperty` callback shorthand | ||
* _.findIndex(users, 'active', false); | ||
* // => 0 | ||
* | ||
* // using the `_.property` callback shorthand | ||
* _.findIndex(users, 'active'); | ||
* // => 1 | ||
* // => 2 | ||
*/ | ||
function findIndex(array, predicate, thisArg) { | ||
var index = -1, | ||
length = array ? array.length : 0; | ||
var findIndex = createFindIndex(); | ||
predicate = baseCallback(predicate, thisArg, 3); | ||
while (++index < length) { | ||
if (predicate(array[index], index, array)) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
} | ||
module.exports = findIndex; |
Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
Based on Underscore.js 1.7.0, copyright 2009-2015 Jeremy Ashkenas, | ||
Based on Underscore.js, copyright 2009-2015 Jeremy Ashkenas, | ||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> | ||
@@ -4,0 +4,0 @@ |
{ | ||
"name": "lodash.findindex", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "The modern build of lodash’s `_.findIndex` as a module.", | ||
@@ -20,4 +20,5 @@ "homepage": "https://lodash.com/", | ||
"dependencies": { | ||
"lodash._basecallback": "^3.0.0" | ||
"lodash._basecallback": "^3.0.0", | ||
"lodash._basefindindex": "^3.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.findindex v3.0.0 | ||
# lodash.findindex v3.1.0 | ||
@@ -20,2 +20,2 @@ The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.findIndex` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
See the [documentation](https://lodash.com/docs#findIndex) or [package source](https://github.com/lodash/lodash/blob/3.0.0-npm-packages/lodash.findindex) for more details. | ||
See the [documentation](https://lodash.com/docs#findIndex) or [package source](https://github.com/lodash/lodash/blob/3.1.0-npm-packages/lodash.findindex) for more details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5431
76
2
+ Addedlodash._basefindindex@^3.0.0
+ Addedlodash._basefindindex@3.6.0(transitive)