lodash._baseuniq
Advanced tools
Comparing version 3.0.3 to 4.4.0
389
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.4.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'); | ||
var SetCache = require('lodash._setcache'), | ||
root = require('lodash._root'); | ||
@@ -16,25 +15,206 @@ /** Used as the size to enable large array optimizations. */ | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED = '__lodash_hash_undefined__'; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
/** 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 > 5). */ | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
/** | ||
* The base implementation of `_.uniq` without support for callback shorthands | ||
* and `this` binding. | ||
* 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) { | ||
return !!array.length && baseIndexOf(array, value, 0) > -1; | ||
} | ||
/** | ||
* A specialized version of `_.includesWith` 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. | ||
* @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.length; | ||
while (++index < length) { | ||
if (comparator(value, array[index])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* 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; | ||
} | ||
/** | ||
* 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. | ||
* | ||
* @private | ||
* @param {Object} set The set to convert. | ||
* @returns {Array} Returns the converted array. | ||
*/ | ||
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 objectProto = Object.prototype; | ||
/** 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 method references that are verified to be native. */ | ||
var Set = getNative(root, 'Set'); | ||
/** | ||
* Checks if `value` is in `cache`. | ||
* | ||
* @private | ||
* @param {Object} cache The set cache to search. | ||
* @param {*} value The value to search for. | ||
* @returns {number} Returns `true` if `value` is found, else `false`. | ||
*/ | ||
function cacheHas(cache, value) { | ||
var map = cache.__data__; | ||
if (isKeyable(value)) { | ||
var data = map.__data__, | ||
hash = typeof value == 'string' ? data.string : data.hash; | ||
return hash[value] === HASH_UNDEFINED; | ||
} | ||
return map.has(value); | ||
} | ||
/** | ||
* The base implementation of `_.uniqBy` without support for iteratee shorthands. | ||
* | ||
* @private | ||
* @param {Array} array The array to inspect. | ||
* @param {Function} [iteratee] The function invoked per iteration. | ||
* @returns {Array} Returns the new duplicate-value-free array. | ||
* @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) { | ||
function baseUniq(array, iteratee, comparator) { | ||
var index = -1, | ||
indexOf = baseIndexOf, | ||
includes = arrayIncludes, | ||
length = array.length, | ||
isCommon = true, | ||
isLarge = isCommon && length >= LARGE_ARRAY_SIZE, | ||
seen = isLarge ? createCache() : null, | ||
result = []; | ||
result = [], | ||
seen = result; | ||
if (seen) { | ||
indexOf = cacheIndexOf; | ||
if (comparator) { | ||
isCommon = false; | ||
} else { | ||
isLarge = 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; | ||
@@ -45,5 +225,5 @@ } | ||
var value = array[index], | ||
computed = iteratee ? iteratee(value, index, array) : value; | ||
computed = iteratee ? iteratee(value) : value; | ||
if (isCommon && value === value) { | ||
if (isCommon && computed === computed) { | ||
var seenIndex = seen.length; | ||
@@ -60,4 +240,4 @@ while (seenIndex--) { | ||
} | ||
else if (indexOf(seen, computed, 0) < 0) { | ||
if (iteratee || isLarge) { | ||
else if (!includes(seen, computed, comparator)) { | ||
if (seen !== result) { | ||
seen.push(computed); | ||
@@ -71,2 +251,163 @@ } | ||
/** | ||
* Creates a set of `values`. | ||
* | ||
* @private | ||
* @param {Array} values The values to add to the set. | ||
* @returns {Object} Returns the new set. | ||
*/ | ||
var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) { | ||
return new Set(values); | ||
}; | ||
/** | ||
* 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 = object == null ? undefined : object[key]; | ||
return isNative(value) ? value : undefined; | ||
} | ||
/** | ||
* 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 == 'number' || type == 'boolean' || | ||
(type == 'string' && value != '__proto__') || value == null; | ||
} | ||
/** | ||
* 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) { | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* 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'; | ||
} | ||
/** | ||
* Checks if `value` is a native function. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a native function, else `false`. | ||
* @example | ||
* | ||
* _.isNative(Array.prototype.push); | ||
* // => true | ||
* | ||
* _.isNative(_); | ||
* // => false | ||
*/ | ||
function isNative(value) { | ||
if (value == null) { | ||
return false; | ||
} | ||
if (isFunction(value)) { | ||
return reIsNative.test(funcToString.call(value)); | ||
} | ||
return isObjectLike(value) && | ||
(isHostObject(value) ? reIsNative : reIsHostCtor).test(value); | ||
} | ||
/** | ||
* A no-operation function that returns `undefined` regardless of the | ||
* arguments it receives. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Util | ||
* @example | ||
* | ||
* var object = { 'user': 'fred' }; | ||
* | ||
* _.noop(object) === undefined; | ||
* // => true | ||
*/ | ||
function noop() { | ||
// No operation performed. | ||
} | ||
module.exports = baseUniq; |
{ | ||
"name": "lodash._baseuniq", | ||
"version": "3.0.3", | ||
"description": "The modern build of lodash’s internal `baseUniq` as a module.", | ||
"version": "4.4.0", | ||
"description": "The internal lodash function `baseUniq` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
@@ -11,5 +11,3 @@ "icon": "https://lodash.com/icon.svg", | ||
"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,6 +18,5 @@ ], | ||
"dependencies": { | ||
"lodash._baseindexof": "^3.0.0", | ||
"lodash._cacheindexof": "^3.0.0", | ||
"lodash._createcache": "^3.0.0" | ||
"lodash._root": "^3.0.0", | ||
"lodash._setcache": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash._baseuniq v3.0.3 | ||
# lodash._baseuniq v4.4.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) internal `baseUniq` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The internal [lodash](https://lodash.com/) function `baseUniq` 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 baseUniq = require('lodash._baseuniq'); | ||
See the [package source](https://github.com/lodash/lodash/blob/3.0.3-npm-packages/lodash._baseuniq) for more details. | ||
See the [package source](https://github.com/lodash/lodash/blob/4.4.0-npm-packages/lodash._baseuniq) 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
13152
2
374
19
1
+ Addedlodash._root@^3.0.0
+ Addedlodash._setcache@^4.0.0
+ Addedlodash._root@3.0.1(transitive)
+ Addedlodash._setcache@4.1.3(transitive)
- Removedlodash._baseindexof@^3.0.0
- Removedlodash._cacheindexof@^3.0.0
- Removedlodash._createcache@^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)