lodash.sortedindex
Advanced tools
Comparing version 3.1.1 to 4.0.0
104
index.js
/** | ||
* lodash 3.1.1 (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 baseCallback = require('lodash._basecallback'), | ||
binaryIndex = require('lodash._binaryindex'), | ||
binaryIndexBy = require('lodash._binaryindexby'); | ||
var baseSortedIndexBy = require('lodash._basesortedindexby'); | ||
/** Used as references for the maximum length and index of an array. */ | ||
var MAX_ARRAY_LENGTH = 4294967295, | ||
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; | ||
/** | ||
* Creates a `_.sortedIndex` or `_.sortedLastIndex` function. | ||
* The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which | ||
* performs a binary search of `array` to determine the index at which `value` | ||
* should be inserted into `array` in order to maintain its sort order. | ||
* | ||
* @private | ||
* @param {Array} array The sorted array to inspect. | ||
* @param {*} value The value to evaluate. | ||
* @param {boolean} [retHighest] Specify returning the highest qualified index. | ||
* @returns {Function} Returns the new index function. | ||
* @returns {number} Returns the index at which `value` should be inserted | ||
* into `array`. | ||
*/ | ||
function createSortedIndex(retHighest) { | ||
return function(array, value, iteratee, thisArg) { | ||
return iteratee == null | ||
? binaryIndex(array, value, retHighest) | ||
: binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1), retHighest); | ||
}; | ||
function baseSortedIndex(array, value, retHighest) { | ||
var low = 0, | ||
high = array ? array.length : low; | ||
if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { | ||
while (low < high) { | ||
var mid = (low + high) >>> 1, | ||
computed = array[mid]; | ||
if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) { | ||
low = mid + 1; | ||
} else { | ||
high = mid; | ||
} | ||
} | ||
return high; | ||
} | ||
return baseSortedIndexBy(array, value, identity, retHighest); | ||
} | ||
@@ -30,18 +49,4 @@ | ||
* Uses a binary search to determine the lowest index at which `value` should | ||
* be inserted into `array` in order to maintain its sort order. If an iteratee | ||
* function is provided it is invoked for `value` and each element of `array` | ||
* to compute their sort ranking. The iteratee is bound to `thisArg` and | ||
* invoked with one argument; (value). | ||
* be inserted into `array` in order to maintain its sort order. | ||
* | ||
* If a property name is provided for `iteratee` the created `_.property` | ||
* style callback returns the property value of the given element. | ||
* | ||
* 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 `iteratee` the created `_.matches` style | ||
* callback returns `true` for elements that have the properties of the given | ||
* object, else `false`. | ||
* | ||
* @static | ||
@@ -52,7 +57,3 @@ * @memberOf _ | ||
* @param {*} value The value to evaluate. | ||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked | ||
* per iteration. | ||
* @param {*} [thisArg] The `this` binding of `iteratee`. | ||
* @returns {number} Returns the index at which `value` should be inserted | ||
* into `array`. | ||
* @returns {number} Returns the index at which `value` should be inserted into `array`. | ||
* @example | ||
@@ -63,19 +64,28 @@ * | ||
* | ||
* _.sortedIndex([4, 4, 5, 5], 5); | ||
* // => 2 | ||
* _.sortedIndex([4, 5], 4); | ||
* // => 0 | ||
*/ | ||
function sortedIndex(array, value) { | ||
return baseSortedIndex(array, value); | ||
} | ||
/** | ||
* This method returns the first argument provided to it. | ||
* | ||
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; | ||
* @static | ||
* @memberOf _ | ||
* @category Util | ||
* @param {*} value Any value. | ||
* @returns {*} Returns `value`. | ||
* @example | ||
* | ||
* // using an iteratee function | ||
* _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) { | ||
* return this.data[word]; | ||
* }, dict); | ||
* // => 1 | ||
* var object = { 'user': 'fred' }; | ||
* | ||
* // using the `_.property` callback shorthand | ||
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); | ||
* // => 1 | ||
* _.identity(object) === object; | ||
* // => true | ||
*/ | ||
var sortedIndex = createSortedIndex(); | ||
function identity(value) { | ||
return value; | ||
} | ||
module.exports = sortedIndex; |
{ | ||
"name": "lodash.sortedindex", | ||
"version": "3.1.1", | ||
"description": "The modern build of lodash’s `_.sortedIndex` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.sortedIndex` 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, sortedindex", | ||
"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/)" | ||
@@ -20,7 +18,4 @@ ], | ||
"dependencies": { | ||
"lodash._basecallback": "^3.0.0", | ||
"lodash._binaryindex": "^3.0.0", | ||
"lodash._binaryindexby": "^3.0.0", | ||
"lodash.isarray": "^3.0.0" | ||
"lodash._basesortedindexby": "^3.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.sortedindex v3.1.1 | ||
# lodash.sortedindex v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.sortedIndex` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.sortedIndex` 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 sortedIndex = require('lodash.sortedindex'); | ||
See the [documentation](https://lodash.com/docs#sortedIndex) or [package source](https://github.com/lodash/lodash/blob/3.1.1-npm-packages/lodash.sortedindex) for more details. | ||
See the [documentation](https://lodash.com/docs#sortedIndex) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.sortedindex) 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
1
81
5166
19
- Removedlodash._basecallback@^3.0.0
- Removedlodash._binaryindex@^3.0.0
- Removedlodash._binaryindexby@^3.0.0
- Removedlodash.isarray@^3.0.0
- Removedlodash._basecallback@3.3.1(transitive)
- Removedlodash._baseisequal@3.0.7(transitive)
- Removedlodash._binaryindex@3.0.1(transitive)
- Removedlodash._binaryindexby@3.0.3(transitive)
- Removedlodash._bindcallback@3.0.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.istypedarray@3.0.6(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.pairs@3.0.1(transitive)