lodash.indexof
Advanced tools
Comparing version 3.0.3 to 4.0.0
242
index.js
/** | ||
* lodash 3.0.3 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* lodash 4.0.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var baseIndexOf = require('lodash._baseindexof'), | ||
binaryIndex = require('lodash._binaryindex'); | ||
/* Native method references for those with the same name as other `lodash` methods. */ | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY = 1 / 0, | ||
MAX_INTEGER = 1.7976931348623157e+308, | ||
NAN = 0 / 0; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
/** Used to match leading and trailing whitespace. */ | ||
var reTrim = /^\s+|\s+$/g; | ||
/** Used to detect bad signed hexadecimal string values. */ | ||
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; | ||
/** Used to detect binary string values. */ | ||
var reIsBinary = /^0b[01]+$/i; | ||
/** Used to detect octal string values. */ | ||
var reIsOctal = /^0o[0-7]+$/i; | ||
/** Built-in method references without a dependency on `global`. */ | ||
var freeParseInt = parseInt; | ||
/** | ||
* The base implementation of `_.indexOf` without `fromIndex` bounds checks. | ||
* | ||
* @private | ||
* @param {Array} array The array to search. | ||
* @param {*} value The value to search for. | ||
* @param {number} fromIndex The index to search from. | ||
* @returns {number} Returns the index of the matched value, else `-1`. | ||
*/ | ||
function baseIndexOf(array, value, fromIndex) { | ||
if (value !== value) { | ||
return indexOfNaN(array, fromIndex); | ||
} | ||
var index = fromIndex - 1, | ||
length = array.length; | ||
while (++index < length) { | ||
if (array[index] === value) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
} | ||
/** | ||
* Gets the index at which the first occurrence of `NaN` is found in `array`. | ||
* | ||
* @private | ||
* @param {Array} array The array to search. | ||
* @param {number} fromIndex The index to search from. | ||
* @param {boolean} [fromRight] Specify iterating from right to left. | ||
* @returns {number} Returns the index of the matched `NaN`, else `-1`. | ||
*/ | ||
function indexOfNaN(array, fromIndex, fromRight) { | ||
var length = array.length, | ||
index = fromIndex + (fromRight ? 0 : -1); | ||
while ((fromRight ? index-- : ++index < length)) { | ||
var other = array[index]; | ||
if (other !== other) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** | ||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax = Math.max; | ||
@@ -18,3 +95,3 @@ | ||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | ||
* for equality comparisons. If `fromIndex` is negative, it is used as the offset | ||
* for equality comparisons. If `fromIndex` is negative, it's used as the offset | ||
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex` | ||
@@ -28,4 +105,3 @@ * performs a faster binary search. | ||
* @param {*} value The value to search for. | ||
* @param {boolean|number} [fromIndex=0] The index to search from or `true` | ||
* to perform a binary search on a sorted array. | ||
* @param {number} [fromIndex=0] The index to search from. | ||
* @returns {number} Returns the index of the matched value, else `-1`. | ||
@@ -40,6 +116,2 @@ * @example | ||
* // => 3 | ||
* | ||
* // performing a binary search | ||
* _.indexOf([1, 1, 2, 2], 2, true); | ||
* // => 2 | ||
*/ | ||
@@ -51,15 +123,137 @@ function indexOf(array, value, fromIndex) { | ||
} | ||
if (typeof fromIndex == 'number') { | ||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex; | ||
} else if (fromIndex) { | ||
var index = binaryIndex(array, value); | ||
if (index < length && | ||
(value === value ? (value === array[index]) : (array[index] !== array[index]))) { | ||
return index; | ||
} | ||
return -1; | ||
fromIndex = toInteger(fromIndex); | ||
if (fromIndex < 0) { | ||
fromIndex = nativeMax(length + fromIndex, 0); | ||
} | ||
return baseIndexOf(array, value, fromIndex || 0); | ||
return baseIndexOf(array, value, fromIndex); | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array constructors, and | ||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. | ||
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
// Avoid a V8 JIT bug in Chrome 19-20. | ||
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details. | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Converts `value` to an integer. | ||
* | ||
* **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to convert. | ||
* @returns {number} Returns the converted integer. | ||
* @example | ||
* | ||
* _.toInteger(3); | ||
* // => 3 | ||
* | ||
* _.toInteger(Number.MIN_VALUE); | ||
* // => 0 | ||
* | ||
* _.toInteger(Infinity); | ||
* // => 1.7976931348623157e+308 | ||
* | ||
* _.toInteger('3'); | ||
* // => 3 | ||
*/ | ||
function toInteger(value) { | ||
if (!value) { | ||
return value === 0 ? value : 0; | ||
} | ||
value = toNumber(value); | ||
if (value === INFINITY || value === -INFINITY) { | ||
var sign = (value < 0 ? -1 : 1); | ||
return sign * MAX_INTEGER; | ||
} | ||
var remainder = value % 1; | ||
return value === value ? (remainder ? value - remainder : value) : 0; | ||
} | ||
/** | ||
* Converts `value` to a number. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {number} Returns the number. | ||
* @example | ||
* | ||
* _.toNumber(3); | ||
* // => 3 | ||
* | ||
* _.toNumber(Number.MIN_VALUE); | ||
* // => 5e-324 | ||
* | ||
* _.toNumber(Infinity); | ||
* // => Infinity | ||
* | ||
* _.toNumber('3'); | ||
* // => 3 | ||
*/ | ||
function toNumber(value) { | ||
if (isObject(value)) { | ||
var other = isFunction(value.valueOf) ? value.valueOf() : value; | ||
value = isObject(other) ? (other + '') : other; | ||
} | ||
if (typeof value != 'string') { | ||
return value === 0 ? value : +value; | ||
} | ||
value = value.replace(reTrim, ''); | ||
var isBinary = reIsBinary.test(value); | ||
return (isBinary || reIsOctal.test(value)) | ||
? freeParseInt(value.slice(2), isBinary ? 2 : 8) | ||
: (reIsBadHex.test(value) ? NAN : +value); | ||
} | ||
module.exports = indexOf; |
{ | ||
"name": "lodash.indexof", | ||
"version": "3.0.3", | ||
"description": "The modern build of lodash’s `_.indexOf` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.indexOf` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
"icon": "https://lodash.com/icon.svg", | ||
"license": "MIT", | ||
"keywords": "lodash, lodash-modularized, stdlib, util", | ||
"keywords": "lodash, lodash-modularized, stdlib, util, indexof", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)", | ||
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
], | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash._baseindexof": "^3.0.0", | ||
"lodash._binaryindex": "^3.0.0" | ||
} | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.indexof v3.0.3 | ||
# lodash.indexof v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.indexOf` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.indexOf` exported as a [Node.js](https://nodejs.org/) module. | ||
@@ -8,3 +8,2 @@ ## Installation | ||
Using npm: | ||
```bash | ||
@@ -15,4 +14,3 @@ $ {sudo -H} npm i -g npm | ||
In Node.js/io.js: | ||
In Node.js: | ||
```js | ||
@@ -22,2 +20,2 @@ var indexOf = require('lodash.indexof'); | ||
See the [documentation](https://lodash.com/docs#indexOf) or [package source](https://github.com/lodash/lodash/blob/3.0.3-npm-packages/lodash.indexof) for more details. | ||
See the [documentation](https://lodash.com/docs#indexOf) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.indexof) for more details. |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
9356
0
235
19
1
- Removedlodash._baseindexof@^3.0.0
- Removedlodash._binaryindex@^3.0.0
- Removedlodash._baseindexof@3.1.0(transitive)
- Removedlodash._binaryindex@3.0.1(transitive)
- Removedlodash._binaryindexby@3.0.3(transitive)