lodash.union
Advanced tools
Comparing version 4.4.0 to 4.5.0
990
index.js
@@ -9,24 +9,169 @@ /** | ||
*/ | ||
var baseFlatten = require('lodash._baseflatten'), | ||
baseUniq = require('lodash._baseuniq'), | ||
rest = require('lodash.rest'); | ||
/** Used as the size to enable large array optimizations. */ | ||
var LARGE_ARRAY_SIZE = 200; | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED = '__lodash_hash_undefined__'; | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
var INFINITY = 1 / 0, | ||
MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
var argsTag = '[object Arguments]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
/** Used for built-in method references. */ | ||
var objectProto = Object.prototype; | ||
/** | ||
* Used to match `RegExp` | ||
* [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). | ||
*/ | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
/** Used to detect host constructors (Safari). */ | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; | ||
/** Detect free variable `self`. */ | ||
var freeSelf = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Used as a reference to the global object. */ | ||
var root = freeGlobal || freeSelf || Function('return this')(); | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
* A faster alternative to `Function#apply`, this function invokes `func` | ||
* with the `this` binding of `thisArg` and the arguments of `args`. | ||
* | ||
* @private | ||
* @param {Function} func The function to invoke. | ||
* @param {*} thisArg The `this` binding of `func`. | ||
* @param {Array} args The arguments to invoke `func` with. | ||
* @returns {*} Returns the result of `func`. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
function apply(func, thisArg, args) { | ||
switch (args.length) { | ||
case 0: return func.call(thisArg); | ||
case 1: return func.call(thisArg, args[0]); | ||
case 2: return func.call(thisArg, args[0], args[1]); | ||
case 3: return func.call(thisArg, args[0], args[1], args[2]); | ||
} | ||
return func.apply(thisArg, args); | ||
} | ||
/** | ||
* A specialized version of `_.includes` for arrays without support for | ||
* specifying an index to search from. | ||
* | ||
* @private | ||
* @param {Array} [array] The array to search. | ||
* @param {*} target The value to search for. | ||
* @returns {boolean} Returns `true` if `target` is found, else `false`. | ||
*/ | ||
function arrayIncludes(array, value) { | ||
var length = array ? array.length : 0; | ||
return !!length && baseIndexOf(array, value, 0) > -1; | ||
} | ||
/** | ||
* This function is like `arrayIncludes` except that it accepts a comparator. | ||
* | ||
* @private | ||
* @param {Array} [array] The array to search. | ||
* @param {*} target The value to search for. | ||
* @param {Function} comparator The comparator invoked per element. | ||
* @returns {boolean} Returns `true` if `target` is found, else `false`. | ||
*/ | ||
function arrayIncludesWith(array, value, comparator) { | ||
var index = -1, | ||
length = array ? array.length : 0; | ||
while (++index < length) { | ||
if (comparator(value, array[index])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Appends the elements of `values` to `array`. | ||
* | ||
* @private | ||
* @param {Array} array The array to modify. | ||
* @param {Array} values The values to append. | ||
* @returns {Array} Returns `array`. | ||
*/ | ||
function arrayPush(array, values) { | ||
var index = -1, | ||
length = values.length, | ||
offset = array.length; | ||
while (++index < length) { | ||
array[offset + index] = values[index]; | ||
} | ||
return array; | ||
} | ||
/** | ||
* The base implementation of `_.findIndex` and `_.findLastIndex` without | ||
* support for iteratee shorthands. | ||
* | ||
* @private | ||
* @param {Array} array The array to search. | ||
* @param {Function} predicate The function invoked per iteration. | ||
* @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 value, else `-1`. | ||
*/ | ||
function baseFindIndex(array, predicate, fromIndex, fromRight) { | ||
var length = array.length, | ||
index = fromIndex + (fromRight ? 1 : -1); | ||
while ((fromRight ? index-- : ++index < length)) { | ||
if (predicate(array[index], index, array)) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
} | ||
/** | ||
* 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 baseFindIndex(array, baseIsNaN, fromIndex); | ||
} | ||
var index = fromIndex - 1, | ||
length = array.length; | ||
while (++index < length) { | ||
if (array[index] === value) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
} | ||
/** | ||
* The base implementation of `_.isNaN` without support for number objects. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. | ||
*/ | ||
function baseIsNaN(value) { | ||
return value !== value; | ||
} | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
@@ -45,2 +190,631 @@ * | ||
/** | ||
* Checks if a cache value for `key` exists. | ||
* | ||
* @private | ||
* @param {Object} cache The cache to query. | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function cacheHas(cache, key) { | ||
return cache.has(key); | ||
} | ||
/** | ||
* Gets the value at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} [object] The object to query. | ||
* @param {string} key The key of the property to get. | ||
* @returns {*} Returns the property value. | ||
*/ | ||
function getValue(object, key) { | ||
return object == null ? undefined : object[key]; | ||
} | ||
/** | ||
* Checks if `value` is a host object in IE < 9. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a host object, else `false`. | ||
*/ | ||
function isHostObject(value) { | ||
// Many host objects are `Object` objects that can coerce to strings | ||
// despite having improperly defined `toString` methods. | ||
var result = false; | ||
if (value != null && typeof value.toString != 'function') { | ||
try { | ||
result = !!(value + ''); | ||
} catch (e) {} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Converts `set` to an array of its values. | ||
* | ||
* @private | ||
* @param {Object} set The set to convert. | ||
* @returns {Array} Returns the values. | ||
*/ | ||
function setToArray(set) { | ||
var index = -1, | ||
result = Array(set.size); | ||
set.forEach(function(value) { | ||
result[++index] = value; | ||
}); | ||
return result; | ||
} | ||
/** Used for built-in method references. */ | ||
var arrayProto = Array.prototype, | ||
objectProto = Object.prototype; | ||
/** Used to detect overreaching core-js shims. */ | ||
var coreJsData = root['__core-js_shared__']; | ||
/** Used to detect methods masquerading as native. */ | ||
var maskSrcKey = (function() { | ||
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); | ||
return uid ? ('Symbol(src)_1.' + uid) : ''; | ||
}()); | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString = Function.prototype.toString; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/** Used to detect if a method is native. */ | ||
var reIsNative = RegExp('^' + | ||
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') | ||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' | ||
); | ||
/** Built-in value references. */ | ||
var Symbol = root.Symbol, | ||
propertyIsEnumerable = objectProto.propertyIsEnumerable, | ||
splice = arrayProto.splice, | ||
spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax = Math.max; | ||
/* Built-in method references that are verified to be native. */ | ||
var Map = getNative(root, 'Map'), | ||
Set = getNative(root, 'Set'), | ||
nativeCreate = getNative(Object, 'create'); | ||
/** | ||
* Creates a hash object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function Hash(entries) { | ||
var index = -1, | ||
length = entries ? entries.length : 0; | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
} | ||
/** | ||
* Removes all key-value entries from the hash. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf Hash | ||
*/ | ||
function hashClear() { | ||
this.__data__ = nativeCreate ? nativeCreate(null) : {}; | ||
} | ||
/** | ||
* Removes `key` and its value from the hash. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf Hash | ||
* @param {Object} hash The hash to modify. | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function hashDelete(key) { | ||
return this.has(key) && delete this.__data__[key]; | ||
} | ||
/** | ||
* Gets the hash value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function hashGet(key) { | ||
var data = this.__data__; | ||
if (nativeCreate) { | ||
var result = data[key]; | ||
return result === HASH_UNDEFINED ? undefined : result; | ||
} | ||
return hasOwnProperty.call(data, key) ? data[key] : undefined; | ||
} | ||
/** | ||
* Checks if a hash value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf Hash | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function hashHas(key) { | ||
var data = this.__data__; | ||
return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key); | ||
} | ||
/** | ||
* Sets the hash `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the hash instance. | ||
*/ | ||
function hashSet(key, value) { | ||
var data = this.__data__; | ||
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; | ||
return this; | ||
} | ||
// Add methods to `Hash`. | ||
Hash.prototype.clear = hashClear; | ||
Hash.prototype['delete'] = hashDelete; | ||
Hash.prototype.get = hashGet; | ||
Hash.prototype.has = hashHas; | ||
Hash.prototype.set = hashSet; | ||
/** | ||
* Creates an list cache object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function ListCache(entries) { | ||
var index = -1, | ||
length = entries ? entries.length : 0; | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
} | ||
/** | ||
* Removes all key-value entries from the list cache. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf ListCache | ||
*/ | ||
function listCacheClear() { | ||
this.__data__ = []; | ||
} | ||
/** | ||
* Removes `key` and its value from the list cache. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function listCacheDelete(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
if (index < 0) { | ||
return false; | ||
} | ||
var lastIndex = data.length - 1; | ||
if (index == lastIndex) { | ||
data.pop(); | ||
} else { | ||
splice.call(data, index, 1); | ||
} | ||
return true; | ||
} | ||
/** | ||
* Gets the list cache value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function listCacheGet(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
return index < 0 ? undefined : data[index][1]; | ||
} | ||
/** | ||
* Checks if a list cache value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf ListCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function listCacheHas(key) { | ||
return assocIndexOf(this.__data__, key) > -1; | ||
} | ||
/** | ||
* Sets the list cache `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the list cache instance. | ||
*/ | ||
function listCacheSet(key, value) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
if (index < 0) { | ||
data.push([key, value]); | ||
} else { | ||
data[index][1] = value; | ||
} | ||
return this; | ||
} | ||
// Add methods to `ListCache`. | ||
ListCache.prototype.clear = listCacheClear; | ||
ListCache.prototype['delete'] = listCacheDelete; | ||
ListCache.prototype.get = listCacheGet; | ||
ListCache.prototype.has = listCacheHas; | ||
ListCache.prototype.set = listCacheSet; | ||
/** | ||
* Creates a map cache object to store key-value pairs. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function MapCache(entries) { | ||
var index = -1, | ||
length = entries ? entries.length : 0; | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
} | ||
/** | ||
* Removes all key-value entries from the map. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf MapCache | ||
*/ | ||
function mapCacheClear() { | ||
this.__data__ = { | ||
'hash': new Hash, | ||
'map': new (Map || ListCache), | ||
'string': new Hash | ||
}; | ||
} | ||
/** | ||
* Removes `key` and its value from the map. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function mapCacheDelete(key) { | ||
return getMapData(this, key)['delete'](key); | ||
} | ||
/** | ||
* Gets the map value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function mapCacheGet(key) { | ||
return getMapData(this, key).get(key); | ||
} | ||
/** | ||
* Checks if a map value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf MapCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function mapCacheHas(key) { | ||
return getMapData(this, key).has(key); | ||
} | ||
/** | ||
* Sets the map `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the map cache instance. | ||
*/ | ||
function mapCacheSet(key, value) { | ||
getMapData(this, key).set(key, value); | ||
return this; | ||
} | ||
// Add methods to `MapCache`. | ||
MapCache.prototype.clear = mapCacheClear; | ||
MapCache.prototype['delete'] = mapCacheDelete; | ||
MapCache.prototype.get = mapCacheGet; | ||
MapCache.prototype.has = mapCacheHas; | ||
MapCache.prototype.set = mapCacheSet; | ||
/** | ||
* | ||
* Creates an array cache object to store unique values. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [values] The values to cache. | ||
*/ | ||
function SetCache(values) { | ||
var index = -1, | ||
length = values ? values.length : 0; | ||
this.__data__ = new MapCache; | ||
while (++index < length) { | ||
this.add(values[index]); | ||
} | ||
} | ||
/** | ||
* Adds `value` to the array cache. | ||
* | ||
* @private | ||
* @name add | ||
* @memberOf SetCache | ||
* @alias push | ||
* @param {*} value The value to cache. | ||
* @returns {Object} Returns the cache instance. | ||
*/ | ||
function setCacheAdd(value) { | ||
this.__data__.set(value, HASH_UNDEFINED); | ||
return this; | ||
} | ||
/** | ||
* Checks if `value` is in the array cache. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf SetCache | ||
* @param {*} value The value to search for. | ||
* @returns {number} Returns `true` if `value` is found, else `false`. | ||
*/ | ||
function setCacheHas(value) { | ||
return this.__data__.has(value); | ||
} | ||
// Add methods to `SetCache`. | ||
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; | ||
SetCache.prototype.has = setCacheHas; | ||
/** | ||
* Gets the index at which the `key` is found in `array` of key-value pairs. | ||
* | ||
* @private | ||
* @param {Array} array The array to search. | ||
* @param {*} key The key to search for. | ||
* @returns {number} Returns the index of the matched value, else `-1`. | ||
*/ | ||
function assocIndexOf(array, key) { | ||
var length = array.length; | ||
while (length--) { | ||
if (eq(array[length][0], key)) { | ||
return length; | ||
} | ||
} | ||
return -1; | ||
} | ||
/** | ||
* The base implementation of `_.flatten` with support for restricting flattening. | ||
* | ||
* @private | ||
* @param {Array} array The array to flatten. | ||
* @param {number} depth The maximum recursion depth. | ||
* @param {boolean} [predicate=isFlattenable] The function invoked per iteration. | ||
* @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. | ||
* @param {Array} [result=[]] The initial result value. | ||
* @returns {Array} Returns the new flattened array. | ||
*/ | ||
function baseFlatten(array, depth, predicate, isStrict, result) { | ||
var index = -1, | ||
length = array.length; | ||
predicate || (predicate = isFlattenable); | ||
result || (result = []); | ||
while (++index < length) { | ||
var value = array[index]; | ||
if (depth > 0 && predicate(value)) { | ||
if (depth > 1) { | ||
// Recursively flatten arrays (susceptible to call stack limits). | ||
baseFlatten(value, depth - 1, predicate, isStrict, result); | ||
} else { | ||
arrayPush(result, value); | ||
} | ||
} else if (!isStrict) { | ||
result[result.length] = value; | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* The base implementation of `_.isNative` without bad shim checks. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a native function, | ||
* else `false`. | ||
*/ | ||
function baseIsNative(value) { | ||
if (!isObject(value) || isMasked(value)) { | ||
return false; | ||
} | ||
var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor; | ||
return pattern.test(toSource(value)); | ||
} | ||
/** | ||
* The base implementation of `_.rest` which doesn't validate or coerce arguments. | ||
* | ||
* @private | ||
* @param {Function} func The function to apply a rest parameter to. | ||
* @param {number} [start=func.length-1] The start position of the rest parameter. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function baseRest(func, start) { | ||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0); | ||
return function() { | ||
var args = arguments, | ||
index = -1, | ||
length = nativeMax(args.length - start, 0), | ||
array = Array(length); | ||
while (++index < length) { | ||
array[index] = args[start + index]; | ||
} | ||
index = -1; | ||
var otherArgs = Array(start + 1); | ||
while (++index < start) { | ||
otherArgs[index] = args[index]; | ||
} | ||
otherArgs[start] = array; | ||
return apply(func, this, otherArgs); | ||
}; | ||
} | ||
/** | ||
* The base implementation of `_.uniqBy` without support for iteratee shorthands. | ||
* | ||
* @private | ||
* @param {Array} array The array to inspect. | ||
* @param {Function} [iteratee] The iteratee invoked per element. | ||
* @param {Function} [comparator] The comparator invoked per element. | ||
* @returns {Array} Returns the new duplicate free array. | ||
*/ | ||
function baseUniq(array, iteratee, comparator) { | ||
var index = -1, | ||
includes = arrayIncludes, | ||
length = array.length, | ||
isCommon = true, | ||
result = [], | ||
seen = result; | ||
if (comparator) { | ||
isCommon = false; | ||
includes = arrayIncludesWith; | ||
} | ||
else if (length >= LARGE_ARRAY_SIZE) { | ||
var set = iteratee ? null : createSet(array); | ||
if (set) { | ||
return setToArray(set); | ||
} | ||
isCommon = false; | ||
includes = cacheHas; | ||
seen = new SetCache; | ||
} | ||
else { | ||
seen = iteratee ? [] : result; | ||
} | ||
outer: | ||
while (++index < length) { | ||
var value = array[index], | ||
computed = iteratee ? iteratee(value) : value; | ||
value = (comparator || value !== 0) ? value : 0; | ||
if (isCommon && computed === computed) { | ||
var seenIndex = seen.length; | ||
while (seenIndex--) { | ||
if (seen[seenIndex] === computed) { | ||
continue outer; | ||
} | ||
} | ||
if (iteratee) { | ||
seen.push(computed); | ||
} | ||
result.push(value); | ||
} | ||
else if (!includes(seen, computed, comparator)) { | ||
if (seen !== result) { | ||
seen.push(computed); | ||
} | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Creates a set object of `values`. | ||
* | ||
* @private | ||
* @param {Array} values The values to add to the set. | ||
* @returns {Object} Returns the new set. | ||
*/ | ||
var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { | ||
return new Set(values); | ||
}; | ||
/** | ||
* Gets the "length" property value of `object`. | ||
@@ -59,2 +833,86 @@ * | ||
/** | ||
* Gets the data for `map`. | ||
* | ||
* @private | ||
* @param {Object} map The map to query. | ||
* @param {string} key The reference key. | ||
* @returns {*} Returns the map data. | ||
*/ | ||
function getMapData(map, key) { | ||
var data = map.__data__; | ||
return isKeyable(key) | ||
? data[typeof key == 'string' ? 'string' : 'hash'] | ||
: data.map; | ||
} | ||
/** | ||
* Gets the native function at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {string} key The key of the method to get. | ||
* @returns {*} Returns the function if it's native, else `undefined`. | ||
*/ | ||
function getNative(object, key) { | ||
var value = getValue(object, key); | ||
return baseIsNative(value) ? value : undefined; | ||
} | ||
/** | ||
* Checks if `value` is a flattenable `arguments` object or array. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is flattenable, else `false`. | ||
*/ | ||
function isFlattenable(value) { | ||
return isArray(value) || isArguments(value) || | ||
!!(spreadableSymbol && value && value[spreadableSymbol]) | ||
} | ||
/** | ||
* Checks if `value` is suitable for use as unique object key. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is suitable, else `false`. | ||
*/ | ||
function isKeyable(value) { | ||
var type = typeof value; | ||
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') | ||
? (value !== '__proto__') | ||
: (value === null); | ||
} | ||
/** | ||
* Checks if `func` has its source masked. | ||
* | ||
* @private | ||
* @param {Function} func The function to check. | ||
* @returns {boolean} Returns `true` if `func` is masked, else `false`. | ||
*/ | ||
function isMasked(func) { | ||
return !!maskSrcKey && (maskSrcKey in func); | ||
} | ||
/** | ||
* Converts `func` to its source code. | ||
* | ||
* @private | ||
* @param {Function} func The function to process. | ||
* @returns {string} Returns the source code. | ||
*/ | ||
function toSource(func) { | ||
if (func != null) { | ||
try { | ||
return funcToString.call(func); | ||
} catch (e) {} | ||
try { | ||
return (func + ''); | ||
} catch (e) {} | ||
} | ||
return ''; | ||
} | ||
/** | ||
* Creates an array of unique values, in order, from all given arrays using | ||
@@ -72,6 +930,6 @@ * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | ||
* | ||
* _.union([2, 1], [4, 2], [1, 2]); | ||
* // => [2, 1, 4] | ||
* _.union([2], [1, 2]); | ||
* // => [2, 1] | ||
*/ | ||
var union = rest(function(arrays) { | ||
var union = baseRest(function(arrays) { | ||
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); | ||
@@ -81,2 +939,87 @@ }); | ||
/** | ||
* Performs a | ||
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | ||
* comparison between two values to determine if they are equivalent. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to compare. | ||
* @param {*} other The other value to compare. | ||
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. | ||
* @example | ||
* | ||
* var object = { 'a': 1 }; | ||
* var other = { 'a': 1 }; | ||
* | ||
* _.eq(object, object); | ||
* // => true | ||
* | ||
* _.eq(object, other); | ||
* // => false | ||
* | ||
* _.eq('a', 'a'); | ||
* // => true | ||
* | ||
* _.eq('a', Object('a')); | ||
* // => false | ||
* | ||
* _.eq(NaN, NaN); | ||
* // => true | ||
*/ | ||
function eq(value, other) { | ||
return value === other || (value !== value && other !== other); | ||
} | ||
/** | ||
* Checks if `value` is likely an `arguments` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an `arguments` object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArguments(function() { return arguments; }()); | ||
* // => true | ||
* | ||
* _.isArguments([1, 2, 3]); | ||
* // => false | ||
*/ | ||
function isArguments(value) { | ||
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. | ||
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && | ||
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); | ||
} | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
var isArray = Array.isArray; | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
@@ -147,4 +1090,3 @@ * not a function and has a `value.length` that's an integer greater than or | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, | ||
* else `false`. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
@@ -256,2 +1198,18 @@ * | ||
/** | ||
* This method returns `undefined`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 2.3.0 | ||
* @category Util | ||
* @example | ||
* | ||
* _.times(2, _.noop); | ||
* // => [undefined, undefined] | ||
*/ | ||
function noop() { | ||
// No operation performed. | ||
} | ||
module.exports = union; |
{ | ||
"name": "lodash.union", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"description": "The lodash method `_.union` exported as a module.", | ||
@@ -16,8 +16,3 @@ "homepage": "https://lodash.com/", | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash._baseflatten": "~4.2.0", | ||
"lodash._baseuniq": "~4.6.0", | ||
"lodash.rest": "^4.0.0" | ||
} | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.union v4.4.0 | ||
# lodash.union v4.5.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.union` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#union) or [package source](https://github.com/lodash/lodash/blob/4.4.0-npm-packages/lodash.union) for more details. | ||
See the [documentation](https://lodash.com/docs#union) or [package source](https://github.com/lodash/lodash/blob/4.5.0-npm-packages/lodash.union) 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
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
33218
0
1110
1
- Removedlodash._baseflatten@~4.2.0
- Removedlodash._baseuniq@~4.6.0
- Removedlodash.rest@^4.0.0
- Removedlodash._baseflatten@4.2.1(transitive)
- Removedlodash._baseuniq@4.6.0(transitive)
- Removedlodash._createset@4.0.3(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.rest@4.0.5(transitive)