lodash.intersection
Advanced tools
Comparing version 3.2.0 to 4.0.0
319
index.js
/** | ||
* lodash 3.2.0 (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'), | ||
cacheIndexOf = require('lodash._cacheindexof'), | ||
createCache = require('lodash._createcache'), | ||
restParam = require('lodash.restparam'); | ||
var SetCache = require('lodash._setcache'), | ||
arrayIncludes = require('lodash._arrayincludes'), | ||
arrayIncludesWith = require('lodash._arrayincludeswith'), | ||
arrayMap = require('lodash._arraymap'), | ||
cacheHas = require('lodash._cachehas'), | ||
rest = require('lodash.rest'); | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
/** | ||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) | ||
* of an array-like value. | ||
* The base implementation of `_.unary` without support for storing wrapper metadata. | ||
* | ||
* @private | ||
* @param {Function} func The function to cap arguments for. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
function baseUnary(func) { | ||
return function(value) { | ||
return func(value); | ||
}; | ||
} | ||
/** 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; | ||
/** | ||
* The base implementation of methods like `_.intersection`, without support | ||
* for iteratee shorthands, that accepts an array of arrays to inspect. | ||
* | ||
* @private | ||
* @param {Array} arrays The arrays to inspect. | ||
* @param {Function} [iteratee] The iteratee invoked per element. | ||
* @param {Function} [comparator] The comparator invoked per element. | ||
* @returns {Array} Returns the new array of shared values. | ||
*/ | ||
function baseIntersection(arrays, iteratee, comparator) { | ||
var includes = comparator ? arrayIncludesWith : arrayIncludes, | ||
othLength = arrays.length, | ||
othIndex = othLength, | ||
caches = Array(othLength), | ||
result = []; | ||
while (othIndex--) { | ||
var array = arrays[othIndex]; | ||
if (othIndex && iteratee) { | ||
array = arrayMap(array, baseUnary(iteratee)); | ||
} | ||
caches[othIndex] = !comparator && (iteratee || array.length >= 120) | ||
? new SetCache(othIndex && array) | ||
: undefined; | ||
} | ||
array = arrays[0]; | ||
var index = -1, | ||
length = array.length, | ||
seen = caches[0]; | ||
outer: | ||
while (++index < length) { | ||
var value = array[index], | ||
computed = iteratee ? iteratee(value) : value; | ||
if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator))) { | ||
var othIndex = othLength; | ||
while (--othIndex) { | ||
var cache = caches[othIndex]; | ||
if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator))) { | ||
continue outer; | ||
} | ||
} | ||
if (seen) { | ||
seen.push(computed); | ||
} | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
@@ -46,20 +125,138 @@ * | ||
/** | ||
* Checks if `value` is array-like. | ||
* Converts `value` to an array-like object if it's not one. | ||
* | ||
* @private | ||
* @param {*} value The value to process. | ||
* @returns {Array} Returns the array-like object. | ||
*/ | ||
function toArrayLikeObject(value) { | ||
return isArrayLikeObject(value) ? value : []; | ||
} | ||
/** | ||
* Creates an array of unique values that are included in all of the provided | ||
* arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | ||
* for equality comparisons. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Array | ||
* @param {...Array} [arrays] The arrays to inspect. | ||
* @returns {Array} Returns the new array of shared values. | ||
* @example | ||
* _.intersection([2, 1], [4, 2], [1, 2]); | ||
* // => [2] | ||
*/ | ||
var intersection = rest(function(arrays) { | ||
var mapped = arrayMap(arrays, toArrayLikeObject); | ||
return (mapped.length && mapped[0] === arrays[0]) | ||
? baseIntersection(mapped) | ||
: []; | ||
}); | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
* not a function and has a `value.length` that's an integer greater than or | ||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLike(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLike('abc'); | ||
* // => true | ||
* | ||
* _.isArrayLike(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && isLength(getLength(value)); | ||
return value != null && | ||
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value)); | ||
} | ||
/** | ||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||
* is an object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLikeObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject('abc'); | ||
* // => false | ||
* | ||
* _.isArrayLikeObject(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLikeObject(value) { | ||
return isObjectLike(value) && isArrayLike(value); | ||
} | ||
/** | ||
* 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 a valid array-like length. | ||
* | ||
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength). | ||
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* | ||
* @private | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @example | ||
* | ||
* _.isLength(3); | ||
* // => true | ||
* | ||
* _.isLength(Number.MIN_VALUE); | ||
* // => false | ||
* | ||
* _.isLength(Infinity); | ||
* // => false | ||
* | ||
* _.isLength('3'); | ||
* // => false | ||
*/ | ||
@@ -71,52 +268,58 @@ function isLength(value) { | ||
/** | ||
* Creates an array of unique values in all provided arrays using | ||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) | ||
* for equality comparisons. | ||
* 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 Array | ||
* @param {...Array} [arrays] The arrays to inspect. | ||
* @returns {Array} Returns the new array of shared values. | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* _.intersection([1, 2], [4, 2], [2, 1]); | ||
* // => [2] | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
var intersection = restParam(function(arrays) { | ||
var othLength = arrays.length, | ||
othIndex = othLength, | ||
caches = Array(length), | ||
indexOf = baseIndexOf, | ||
isCommon = true, | ||
result = []; | ||
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'); | ||
} | ||
while (othIndex--) { | ||
var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : []; | ||
caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null; | ||
} | ||
var array = arrays[0], | ||
index = -1, | ||
length = array ? array.length : 0, | ||
seen = caches[0]; | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
outer: | ||
while (++index < length) { | ||
value = array[index]; | ||
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) { | ||
var othIndex = othLength; | ||
while (--othIndex) { | ||
var cache = caches[othIndex]; | ||
if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) { | ||
continue outer; | ||
} | ||
} | ||
if (seen) { | ||
seen.push(value); | ||
} | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
}); | ||
module.exports = intersection; |
{ | ||
"name": "lodash.intersection", | ||
"version": "3.2.0", | ||
"description": "The modern build of lodash’s `_.intersection` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.intersection` 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, intersection", | ||
"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,9 @@ ], | ||
"dependencies": { | ||
"lodash._baseindexof": "^3.0.0", | ||
"lodash._cacheindexof": "^3.0.0", | ||
"lodash._createcache": "^3.0.0", | ||
"lodash.restparam": "^3.0.0" | ||
"lodash._arrayincludes": "^3.0.0", | ||
"lodash._arrayincludeswith": "^3.0.0", | ||
"lodash._arraymap": "^3.0.0", | ||
"lodash._cachehas": "^3.0.0", | ||
"lodash._setcache": "^3.0.0", | ||
"lodash.rest": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.intersection v3.2.0 | ||
# lodash.intersection v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.intersection` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.intersection` 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 intersection = require('lodash.intersection'); | ||
See the [documentation](https://lodash.com/docs#intersection) or [package source](https://github.com/lodash/lodash/blob/3.2.0-npm-packages/lodash.intersection) for more details. | ||
See the [documentation](https://lodash.com/docs#intersection) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.intersection) for more details. |
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
11457
302
6
19
1
+ Addedlodash._arrayincludes@^3.0.0
+ Addedlodash._arraymap@^3.0.0
+ Addedlodash._cachehas@^3.0.0
+ Addedlodash._setcache@^3.0.0
+ Addedlodash.rest@^4.0.0
+ Addedlodash._arraymap@3.0.0(transitive)
+ Addedlodash.rest@4.0.5(transitive)
- Removedlodash._baseindexof@^3.0.0
- Removedlodash._cacheindexof@^3.0.0
- Removedlodash._createcache@^3.0.0
- Removedlodash.restparam@^3.0.0
- Removedlodash._baseindexof@3.1.0(transitive)
- Removedlodash._cacheindexof@3.0.2(transitive)
- Removedlodash._createcache@3.1.2(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash.restparam@3.6.1(transitive)