diff --git a/LICENSE b/LICENSE index e0c69d560..c6f2f6145 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright jQuery Foundation and other contributors +Copyright JS Foundation and other contributors Based on Underscore.js, copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors diff --git a/README.md b/README.md index e903685e9..7a7191239 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.16.4 +# lodash-amd v4.16.5 The [Lodash](https://lodash.com/) library exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. @@ -27,4 +27,4 @@ require({ }); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.16.4-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.16.5-amd) for more details. diff --git a/_Hash.js b/_Hash.js index 3e07e48c2..1bf2ed26b 100644 --- a/_Hash.js +++ b/_Hash.js @@ -9,7 +9,7 @@ define(['./_hashClear', './_hashDelete', './_hashGet', './_hashHas', './_hashSet */ function Hash(entries) { var index = -1, - length = entries ? entries.length : 0; + length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { diff --git a/_ListCache.js b/_ListCache.js index c41503e89..2a9f4e3cf 100644 --- a/_ListCache.js +++ b/_ListCache.js @@ -9,7 +9,7 @@ define(['./_listCacheClear', './_listCacheDelete', './_listCacheGet', './_listCa */ function ListCache(entries) { var index = -1, - length = entries ? entries.length : 0; + length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { diff --git a/_MapCache.js b/_MapCache.js index 9fc482f98..939a8ccb1 100644 --- a/_MapCache.js +++ b/_MapCache.js @@ -9,7 +9,7 @@ define(['./_mapCacheClear', './_mapCacheDelete', './_mapCacheGet', './_mapCacheH */ function MapCache(entries) { var index = -1, - length = entries ? entries.length : 0; + length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { diff --git a/_SetCache.js b/_SetCache.js index d3bf63bc7..a0940e1b4 100644 --- a/_SetCache.js +++ b/_SetCache.js @@ -10,7 +10,7 @@ define(['./_MapCache', './_setCacheAdd', './_setCacheHas'], function(MapCache, s */ function SetCache(values) { var index = -1, - length = values ? values.length : 0; + length = values == null ? 0 : values.length; this.__data__ = new MapCache; while (++index < length) { diff --git a/_arrayAggregator.js b/_arrayAggregator.js index cda593dcb..06290e2dc 100644 --- a/_arrayAggregator.js +++ b/_arrayAggregator.js @@ -12,7 +12,7 @@ define([], function() { */ function arrayAggregator(array, setter, iteratee, accumulator) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { var value = array[index]; diff --git a/_arrayEach.js b/_arrayEach.js index 32bb1cda9..fdc2aca53 100644 --- a/_arrayEach.js +++ b/_arrayEach.js @@ -11,7 +11,7 @@ define([], function() { */ function arrayEach(array, iteratee) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (iteratee(array[index], index, array) === false) { diff --git a/_arrayEachRight.js b/_arrayEachRight.js index 5a8c2c7ef..86bb009c6 100644 --- a/_arrayEachRight.js +++ b/_arrayEachRight.js @@ -10,7 +10,7 @@ define([], function() { * @returns {Array} Returns `array`. */ function arrayEachRight(array, iteratee) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; while (length--) { if (iteratee(array[length], length, array) === false) { diff --git a/_arrayEvery.js b/_arrayEvery.js index 6521a3fa6..9b3759eff 100644 --- a/_arrayEvery.js +++ b/_arrayEvery.js @@ -12,7 +12,7 @@ define([], function() { */ function arrayEvery(array, predicate) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (!predicate(array[index], index, array)) { diff --git a/_arrayFilter.js b/_arrayFilter.js index 37301eced..fb5e156da 100644 --- a/_arrayFilter.js +++ b/_arrayFilter.js @@ -11,7 +11,7 @@ define([], function() { */ function arrayFilter(array, predicate) { var index = -1, - length = array ? array.length : 0, + length = array == null ? 0 : array.length, resIndex = 0, result = []; diff --git a/_arrayIncludes.js b/_arrayIncludes.js index be652430f..5ca3d5552 100644 --- a/_arrayIncludes.js +++ b/_arrayIncludes.js @@ -10,7 +10,7 @@ define(['./_baseIndexOf'], function(baseIndexOf) { * @returns {boolean} Returns `true` if `target` is found, else `false`. */ function arrayIncludes(array, value) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return !!length && baseIndexOf(array, value, 0) > -1; } diff --git a/_arrayIncludesWith.js b/_arrayIncludesWith.js index 13b8ea55e..226db0eaa 100644 --- a/_arrayIncludesWith.js +++ b/_arrayIncludesWith.js @@ -11,7 +11,7 @@ define([], function() { */ function arrayIncludesWith(array, value, comparator) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (comparator(value, array[index])) { diff --git a/_arrayMap.js b/_arrayMap.js index 4e0e80011..8d2db9206 100644 --- a/_arrayMap.js +++ b/_arrayMap.js @@ -11,7 +11,7 @@ define([], function() { */ function arrayMap(array, iteratee) { var index = -1, - length = array ? array.length : 0, + length = array == null ? 0 : array.length, result = Array(length); while (++index < length) { diff --git a/_arrayReduce.js b/_arrayReduce.js index b06698356..eaa21c57d 100644 --- a/_arrayReduce.js +++ b/_arrayReduce.js @@ -14,7 +14,7 @@ define([], function() { */ function arrayReduce(array, iteratee, accumulator, initAccum) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; if (initAccum && length) { accumulator = array[++index]; diff --git a/_arrayReduceRight.js b/_arrayReduceRight.js index e7520eb6d..9f77c90e9 100644 --- a/_arrayReduceRight.js +++ b/_arrayReduceRight.js @@ -13,7 +13,7 @@ define([], function() { * @returns {*} Returns the accumulated value. */ function arrayReduceRight(array, iteratee, accumulator, initAccum) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (initAccum && length) { accumulator = array[--length]; } diff --git a/_arraySome.js b/_arraySome.js index 8973fbbe5..f003f6091 100644 --- a/_arraySome.js +++ b/_arraySome.js @@ -12,7 +12,7 @@ define([], function() { */ function arraySome(array, predicate) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (predicate(array[index], index, array)) { diff --git a/_baseAt.js b/_baseAt.js index e7a63c103..0bd0c270b 100644 --- a/_baseAt.js +++ b/_baseAt.js @@ -13,12 +13,12 @@ define(['./get'], function(get) { */ function baseAt(object, paths) { var index = -1, - isNil = object == null, length = paths.length, - result = Array(length); + result = Array(length), + skip = object == null; while (++index < length) { - result[index] = isNil ? undefined : get(object, paths[index]); + result[index] = skip ? undefined : get(object, paths[index]); } return result; } diff --git a/_baseDifference.js b/_baseDifference.js index f495160fe..b2505eb4e 100644 --- a/_baseDifference.js +++ b/_baseDifference.js @@ -40,7 +40,7 @@ define(['./_SetCache', './_arrayIncludes', './_arrayIncludesWith', './_arrayMap' outer: while (++index < length) { var value = array[index], - computed = iteratee ? iteratee(value) : value; + computed = iteratee == null ? value : iteratee(value); value = (comparator || value !== 0) ? value : 0; if (isCommon && computed === computed) { diff --git a/_baseGetTag.js b/_baseGetTag.js index 62a8a2477..e75dfd132 100644 --- a/_baseGetTag.js +++ b/_baseGetTag.js @@ -1,24 +1,30 @@ -define([], function() { +define(['./_Symbol', './_getRawTag', './_objectToString'], function(Symbol, getRawTag, objectToString) { - /** Used for built-in method references. */ - var objectProto = Object.prototype; + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** `Object#toString` result references. */ + var nullTag = '[object Null]', + undefinedTag = '[object Undefined]'; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - - /** - * The base implementation of `getTag`. + * The base implementation of `getTag` without fallbacks for buggy environments. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ function baseGetTag(value) { - return objectToString.call(value); + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + value = Object(value); + return (symToStringTag && symToStringTag in value) + ? getRawTag(value) + : objectToString(value); } return baseGetTag; diff --git a/_baseIsArguments.js b/_baseIsArguments.js index 8297e3726..34bb07547 100644 --- a/_baseIsArguments.js +++ b/_baseIsArguments.js @@ -1,18 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var argsTag = '[object Arguments]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * The base implementation of `_.isArguments`. * @@ -21,7 +11,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @returns {boolean} Returns `true` if `value` is an `arguments` object, */ function baseIsArguments(value) { - return isObjectLike(value) && objectToString.call(value) == argsTag; + return isObjectLike(value) && baseGetTag(value) == argsTag; } return baseIsArguments; diff --git a/_baseIsArrayBuffer.js b/_baseIsArrayBuffer.js index 6e6e5caeb..0ba300b0a 100644 --- a/_baseIsArrayBuffer.js +++ b/_baseIsArrayBuffer.js @@ -1,17 +1,7 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { var arrayBufferTag = '[object ArrayBuffer]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * The base implementation of `_.isArrayBuffer` without Node.js optimizations. * @@ -20,7 +10,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. */ function baseIsArrayBuffer(value) { - return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; + return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; } return baseIsArrayBuffer; diff --git a/_baseIsDate.js b/_baseIsDate.js index d7029b98f..9f538e44d 100644 --- a/_baseIsDate.js +++ b/_baseIsDate.js @@ -1,18 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var dateTag = '[object Date]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * The base implementation of `_.isDate` without Node.js optimizations. * @@ -21,7 +11,7 @@ define(['./isObjectLike'], function(isObjectLike) { * @returns {boolean} Returns `true` if `value` is a date object, else `false`. */ function baseIsDate(value) { - return isObjectLike(value) && objectToString.call(value) == dateTag; + return isObjectLike(value) && baseGetTag(value) == dateTag; } return baseIsDate; diff --git a/_baseIsRegExp.js b/_baseIsRegExp.js index 3ccd3d813..792082f7f 100644 --- a/_baseIsRegExp.js +++ b/_baseIsRegExp.js @@ -1,18 +1,8 @@ -define(['./isObject'], function(isObject) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var regexpTag = '[object RegExp]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * The base implementation of `_.isRegExp` without Node.js optimizations. * @@ -21,7 +11,7 @@ define(['./isObject'], function(isObject) { * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. */ function baseIsRegExp(value) { - return isObject(value) && objectToString.call(value) == regexpTag; + return isObjectLike(value) && baseGetTag(value) == regexpTag; } return baseIsRegExp; diff --git a/_baseIsTypedArray.js b/_baseIsTypedArray.js index 0413fbef3..b3f4cdfc1 100644 --- a/_baseIsTypedArray.js +++ b/_baseIsTypedArray.js @@ -1,4 +1,4 @@ -define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { +define(['./_baseGetTag', './isLength', './isObjectLike'], function(baseGetTag, isLength, isObjectLike) { /** `Object#toString` result references. */ var argsTag = '[object Arguments]', @@ -43,16 +43,6 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * The base implementation of `_.isTypedArray` without Node.js optimizations. * @@ -62,7 +52,7 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { */ function baseIsTypedArray(value) { return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; + isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; } return baseIsTypedArray; diff --git a/_baseMean.js b/_baseMean.js index e4d20a303..535fc81dd 100644 --- a/_baseMean.js +++ b/_baseMean.js @@ -13,7 +13,7 @@ define(['./_baseSum'], function(baseSum) { * @returns {number} Returns the mean. */ function baseMean(array, iteratee) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? (baseSum(array, iteratee) / length) : NAN; } diff --git a/_baseSortedIndex.js b/_baseSortedIndex.js index 3c00940f4..86e2c1b0b 100644 --- a/_baseSortedIndex.js +++ b/_baseSortedIndex.js @@ -18,7 +18,7 @@ define(['./_baseSortedIndexBy', './identity', './isSymbol'], function(baseSorted */ function baseSortedIndex(array, value, retHighest) { var low = 0, - high = array ? array.length : low; + high = array == null ? low : array.length; if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { while (low < high) { diff --git a/_baseSortedIndexBy.js b/_baseSortedIndexBy.js index e62accfd7..6d9c3e2ab 100644 --- a/_baseSortedIndexBy.js +++ b/_baseSortedIndexBy.js @@ -28,7 +28,7 @@ define(['./isSymbol'], function(isSymbol) { value = iteratee(value); var low = 0, - high = array ? array.length : 0, + high = array == null ? 0 : array.length, valIsNaN = value !== value, valIsNull = value === null, valIsSymbol = isSymbol(value), diff --git a/_baseXor.js b/_baseXor.js index 25b2e662f..db29f6f8c 100644 --- a/_baseXor.js +++ b/_baseXor.js @@ -1,4 +1,4 @@ -define(['./_arrayPush', './_baseDifference', './_baseUniq'], function(arrayPush, baseDifference, baseUniq) { +define(['./_baseDifference', './_baseFlatten', './_baseUniq'], function(baseDifference, baseFlatten, baseUniq) { /** * The base implementation of methods like `_.xor`, without support for @@ -11,18 +11,25 @@ define(['./_arrayPush', './_baseDifference', './_baseUniq'], function(arrayPush, * @returns {Array} Returns the new array of values. */ function baseXor(arrays, iteratee, comparator) { + var length = arrays.length; + if (length < 2) { + return length ? baseUniq(arrays[0]) : []; + } var index = -1, - length = arrays.length; + result = Array(length); while (++index < length) { - var result = result - ? arrayPush( - baseDifference(result, arrays[index], iteratee, comparator), - baseDifference(arrays[index], result, iteratee, comparator) - ) - : arrays[index]; + var array = arrays[index], + othIndex = -1; + + while (++othIndex < length) { + var othArray = arrays[othIndex]; + if (othArray !== array) { + result[index] = baseDifference(result[index] || array, othArray, iteratee, comparator); + } + } } - return (result && result.length) ? baseUniq(result, iteratee, comparator) : []; + return baseUniq(baseFlatten(result, 1), iteratee, comparator); } return baseXor; diff --git a/_getRawTag.js b/_getRawTag.js new file mode 100644 index 000000000..1cb3e6ab0 --- /dev/null +++ b/_getRawTag.js @@ -0,0 +1,50 @@ +define(['./_Symbol'], function(Symbol) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + + return getRawTag; +}); diff --git a/_getTag.js b/_getTag.js index 8abd7d207..c9654e19f 100644 --- a/_getTag.js +++ b/_getTag.js @@ -12,16 +12,6 @@ define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_baseG var dataViewTag = '[object DataView]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** Used to detect maps, sets, and weakmaps. */ var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map), @@ -45,9 +35,9 @@ define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_baseG (Set && getTag(new Set) != setTag) || (WeakMap && getTag(new WeakMap) != weakMapTag)) { getTag = function(value) { - var result = objectToString.call(value), + var result = baseGetTag(value), Ctor = result == objectTag ? value.constructor : undefined, - ctorString = Ctor ? toSource(Ctor) : undefined; + ctorString = Ctor ? toSource(Ctor) : ''; if (ctorString) { switch (ctorString) { diff --git a/_hasPath.js b/_hasPath.js index c774a6daa..f76bfe504 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -26,7 +26,7 @@ define(['./_castPath', './isArguments', './isArray', './_isIndex', './_isKey', ' if (result || ++index != length) { return result; } - length = object ? object.length : 0; + length = object == null ? 0 : object.length; return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object)); } diff --git a/_objectToString.js b/_objectToString.js new file mode 100644 index 000000000..6411fc0fa --- /dev/null +++ b/_objectToString.js @@ -0,0 +1,25 @@ +define([], function() { + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString.call(value); + } + + return objectToString; +}); diff --git a/_shortOut.js b/_shortOut.js index e02d9ce5a..236786fce 100644 --- a/_shortOut.js +++ b/_shortOut.js @@ -4,7 +4,7 @@ define([], function() { var undefined; /** Used to detect hot functions by number of calls within a span of milliseconds. */ - var HOT_COUNT = 500, + var HOT_COUNT = 800, HOT_SPAN = 16; /* Built-in method references for those with the same name as other `lodash` methods. */ diff --git a/_toSource.js b/_toSource.js index 86e1573ff..2fca8693c 100644 --- a/_toSource.js +++ b/_toSource.js @@ -10,7 +10,7 @@ define([], function() { * Converts `func` to its source code. * * @private - * @param {Function} func The function to process. + * @param {Function} func The function to convert. * @returns {string} Returns the source code. */ function toSource(func) { diff --git a/_unicodeWords.js b/_unicodeWords.js index 7c0143002..0fb4c8f63 100644 --- a/_unicodeWords.js +++ b/_unicodeWords.js @@ -31,22 +31,26 @@ define([], function() { rsZWJ = '\\u200d'; /** Used to compose unicode regexes. */ - var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')', - rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')', - rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', - rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', + var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', + rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', + rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', + rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', reOptMod = rsModifier + '?', rsOptVar = '[' + rsVarRange + ']?', rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', + rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)', + rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)', rsSeq = rsOptVar + reOptMod + rsOptJoin, rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; /** Used to match complex or compound words. */ var reUnicodeWord = RegExp([ - rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', - rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, - rsUpper + '+' + rsOptUpperContr, + rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', + rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, + rsUpper + '+' + rsOptContrUpper, + rsOrdUpper, + rsOrdLower, rsDigits, rsEmoji ].join('|'), 'g'); diff --git a/chunk.js b/chunk.js index ebc749c9d..2718696b1 100644 --- a/chunk.js +++ b/chunk.js @@ -34,7 +34,7 @@ define(['./_baseSlice', './_isIterateeCall', './toInteger'], function(baseSlice, } else { size = nativeMax(toInteger(size), 0); } - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length || size < 1) { return []; } diff --git a/cloneDeepWith.js b/cloneDeepWith.js index 02bb835df..38d53fb70 100644 --- a/cloneDeepWith.js +++ b/cloneDeepWith.js @@ -1,5 +1,8 @@ define(['./_baseClone'], function(baseClone) { + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + /** * This method is like `_.cloneWith` except that it recursively clones `value`. * @@ -29,6 +32,7 @@ define(['./_baseClone'], function(baseClone) { * // => 20 */ function cloneDeepWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; return baseClone(value, true, true, customizer); } diff --git a/cloneWith.js b/cloneWith.js index c0dce3b7c..86cb498ec 100644 --- a/cloneWith.js +++ b/cloneWith.js @@ -1,5 +1,8 @@ define(['./_baseClone'], function(baseClone) { + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + /** * This method is like `_.clone` except that it accepts `customizer` which * is invoked to produce the cloned value. If `customizer` returns `undefined`, @@ -32,6 +35,7 @@ define(['./_baseClone'], function(baseClone) { * // => 0 */ function cloneWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; return baseClone(value, false, true, customizer); } diff --git a/compact.js b/compact.js index 94a3e7557..76e3e3182 100644 --- a/compact.js +++ b/compact.js @@ -17,7 +17,7 @@ define([], function() { */ function compact(array) { var index = -1, - length = array ? array.length : 0, + length = array == null ? 0 : array.length, resIndex = 0, result = []; diff --git a/cond.js b/cond.js index 5a59da2ff..962298dfe 100644 --- a/cond.js +++ b/cond.js @@ -33,7 +33,7 @@ define(['./_apply', './_arrayMap', './_baseIteratee', './_baseRest'], function(a * // => 'no match' */ function cond(pairs) { - var length = pairs ? pairs.length : 0, + var length = pairs == null ? 0 : pairs.length, toIteratee = baseIteratee; pairs = !length ? [] : arrayMap(pairs, function(pair) { diff --git a/countBy.js b/countBy.js index dc0967d5d..f5057fbf7 100644 --- a/countBy.js +++ b/countBy.js @@ -17,8 +17,7 @@ define(['./_baseAssignValue', './_createAggregator'], function(baseAssignValue, * @since 0.5.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The iteratee to transform keys. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * diff --git a/create.js b/create.js index c51eeef74..e1b5f6a48 100644 --- a/create.js +++ b/create.js @@ -36,7 +36,7 @@ define(['./_baseAssign', './_baseCreate'], function(baseAssign, baseCreate) { */ function create(prototype, properties) { var result = baseCreate(prototype); - return properties ? baseAssign(result, properties) : result; + return properties == null ? result : baseAssign(result, properties); } return create; diff --git a/drop.js b/drop.js index 51b61d9f3..22c2507ff 100644 --- a/drop.js +++ b/drop.js @@ -29,7 +29,7 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * // => [1, 2, 3] */ function drop(array, n, guard) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/dropRight.js b/dropRight.js index dbc3c2d94..544e21575 100644 --- a/dropRight.js +++ b/dropRight.js @@ -29,7 +29,7 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * // => [1, 2, 3] */ function dropRight(array, n, guard) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/dropWhile.js b/dropWhile.js index 0d96bde69..e010743d6 100644 --- a/dropWhile.js +++ b/dropWhile.js @@ -10,8 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/every.js b/every.js index b9aeeee9d..bdb013ecb 100644 --- a/every.js +++ b/every.js @@ -18,8 +18,7 @@ define(['./_arrayEvery', './_baseEvery', './_baseIteratee', './isArray', './_isI * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {boolean} Returns `true` if all elements pass the predicate check, * else `false`. diff --git a/fill.js b/fill.js index 1ff0b8d1e..022c86eed 100644 --- a/fill.js +++ b/fill.js @@ -30,7 +30,7 @@ define(['./_baseFill', './_isIterateeCall'], function(baseFill, isIterateeCall) * // => [4, '*', '*', 10] */ function fill(array, value, start, end) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/filter.js b/filter.js index 81f93843a..cde5c742d 100644 --- a/filter.js +++ b/filter.js @@ -12,8 +12,7 @@ define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], func * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @see _.reject * @example diff --git a/find.js b/find.js index b3cd025e2..91109ca3b 100644 --- a/find.js +++ b/find.js @@ -10,8 +10,7 @@ define(['./_createFind', './findIndex'], function(createFind, findIndex) { * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {*} Returns the matched element, else `undefined`. * @example diff --git a/findIndex.js b/findIndex.js index ab971e385..0ca8dfc29 100644 --- a/findIndex.js +++ b/findIndex.js @@ -12,8 +12,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * @since 1.1.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. * @example @@ -40,7 +39,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * // => 2 */ function findIndex(array, predicate, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } diff --git a/findLast.js b/findLast.js index c9970d7a0..b2beec5a4 100644 --- a/findLast.js +++ b/findLast.js @@ -9,8 +9,7 @@ define(['./_createFind', './findLastIndex'], function(createFind, findLastIndex) * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=collection.length-1] The index to search from. * @returns {*} Returns the matched element, else `undefined`. * @example diff --git a/findLastIndex.js b/findLastIndex.js index 3cdd64573..d909d51a5 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -16,8 +16,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * @since 2.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=array.length-1] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. * @example @@ -44,7 +43,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * // => 0 */ function findLastIndex(array, predicate, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } diff --git a/flatMap.js b/flatMap.js index 8ef3a244a..2120827db 100644 --- a/flatMap.js +++ b/flatMap.js @@ -10,8 +10,7 @@ define(['./_baseFlatten', './map'], function(baseFlatten, map) { * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example * diff --git a/flatMapDeep.js b/flatMapDeep.js index 35a866db1..edbd7968d 100644 --- a/flatMapDeep.js +++ b/flatMapDeep.js @@ -12,8 +12,7 @@ define(['./_baseFlatten', './map'], function(baseFlatten, map) { * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example * diff --git a/flatMapDepth.js b/flatMapDepth.js index 278ed7c01..1cb4623db 100644 --- a/flatMapDepth.js +++ b/flatMapDepth.js @@ -12,8 +12,7 @@ define(['./_baseFlatten', './map', './toInteger'], function(baseFlatten, map, to * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @param {number} [depth=1] The maximum recursion depth. * @returns {Array} Returns the new flattened array. * @example diff --git a/flatten.js b/flatten.js index a9edd3ccd..3ab5a3e3d 100644 --- a/flatten.js +++ b/flatten.js @@ -15,7 +15,7 @@ define(['./_baseFlatten'], function(baseFlatten) { * // => [1, 2, [3, [4]], 5] */ function flatten(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseFlatten(array, 1) : []; } diff --git a/flattenDeep.js b/flattenDeep.js index 958d9ffca..1b76fe2b2 100644 --- a/flattenDeep.js +++ b/flattenDeep.js @@ -18,7 +18,7 @@ define(['./_baseFlatten'], function(baseFlatten) { * // => [1, 2, 3, 4, 5] */ function flattenDeep(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseFlatten(array, INFINITY) : []; } diff --git a/flattenDepth.js b/flattenDepth.js index 5538da2f7..54fc30694 100644 --- a/flattenDepth.js +++ b/flattenDepth.js @@ -24,7 +24,7 @@ define(['./_baseFlatten', './toInteger'], function(baseFlatten, toInteger) { * // => [1, 2, 3, [4], 5] */ function flattenDepth(array, depth) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/forEach.js b/forEach.js index 9b9615104..9ccec0d3e 100644 --- a/forEach.js +++ b/forEach.js @@ -1,4 +1,4 @@ -define(['./_arrayEach', './_baseEach', './_baseIteratee', './isArray'], function(arrayEach, baseEach, baseIteratee, isArray) { +define(['./_arrayEach', './_baseEach', './_castFunction', './isArray'], function(arrayEach, baseEach, castFunction, isArray) { /** * Iterates over elements of `collection` and invokes `iteratee` for each element. @@ -32,7 +32,7 @@ define(['./_arrayEach', './_baseEach', './_baseIteratee', './isArray'], function */ function forEach(collection, iteratee) { var func = isArray(collection) ? arrayEach : baseEach; - return func(collection, baseIteratee(iteratee, 3)); + return func(collection, castFunction(iteratee)); } return forEach; diff --git a/forEachRight.js b/forEachRight.js index 98f90885a..d38c338d5 100644 --- a/forEachRight.js +++ b/forEachRight.js @@ -1,4 +1,4 @@ -define(['./_arrayEachRight', './_baseEachRight', './_baseIteratee', './isArray'], function(arrayEachRight, baseEachRight, baseIteratee, isArray) { +define(['./_arrayEachRight', './_baseEachRight', './_castFunction', './isArray'], function(arrayEachRight, baseEachRight, castFunction, isArray) { /** * This method is like `_.forEach` except that it iterates over elements of @@ -22,7 +22,7 @@ define(['./_arrayEachRight', './_baseEachRight', './_baseIteratee', './isArray'] */ function forEachRight(collection, iteratee) { var func = isArray(collection) ? arrayEachRight : baseEachRight; - return func(collection, baseIteratee(iteratee, 3)); + return func(collection, castFunction(iteratee)); } return forEachRight; diff --git a/forIn.js b/forIn.js index ff4e7b434..82fbd6640 100644 --- a/forIn.js +++ b/forIn.js @@ -1,4 +1,4 @@ -define(['./_baseFor', './_baseIteratee', './keysIn'], function(baseFor, baseIteratee, keysIn) { +define(['./_baseFor', './_castFunction', './keysIn'], function(baseFor, castFunction, keysIn) { /** * Iterates over own and inherited enumerable string keyed properties of an @@ -31,7 +31,7 @@ define(['./_baseFor', './_baseIteratee', './keysIn'], function(baseFor, baseIter function forIn(object, iteratee) { return object == null ? object - : baseFor(object, baseIteratee(iteratee, 3), keysIn); + : baseFor(object, castFunction(iteratee), keysIn); } return forIn; diff --git a/forInRight.js b/forInRight.js index c767ee4eb..0d88b2bd2 100644 --- a/forInRight.js +++ b/forInRight.js @@ -1,4 +1,4 @@ -define(['./_baseForRight', './_baseIteratee', './keysIn'], function(baseForRight, baseIteratee, keysIn) { +define(['./_baseForRight', './_castFunction', './keysIn'], function(baseForRight, castFunction, keysIn) { /** * This method is like `_.forIn` except that it iterates over properties of @@ -29,7 +29,7 @@ define(['./_baseForRight', './_baseIteratee', './keysIn'], function(baseForRight function forInRight(object, iteratee) { return object == null ? object - : baseForRight(object, baseIteratee(iteratee, 3), keysIn); + : baseForRight(object, castFunction(iteratee), keysIn); } return forInRight; diff --git a/forOwn.js b/forOwn.js index 274106bb0..e685e22e8 100644 --- a/forOwn.js +++ b/forOwn.js @@ -1,4 +1,4 @@ -define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) { +define(['./_baseForOwn', './_castFunction'], function(baseForOwn, castFunction) { /** * Iterates over own enumerable string keyed properties of an object and @@ -29,7 +29,7 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forOwn(object, iteratee) { - return object && baseForOwn(object, baseIteratee(iteratee, 3)); + return object && baseForOwn(object, castFunction(iteratee)); } return forOwn; diff --git a/forOwnRight.js b/forOwnRight.js index 245ef9b88..07f857072 100644 --- a/forOwnRight.js +++ b/forOwnRight.js @@ -1,4 +1,4 @@ -define(['./_baseForOwnRight', './_baseIteratee'], function(baseForOwnRight, baseIteratee) { +define(['./_baseForOwnRight', './_castFunction'], function(baseForOwnRight, castFunction) { /** * This method is like `_.forOwn` except that it iterates over properties of @@ -27,7 +27,7 @@ define(['./_baseForOwnRight', './_baseIteratee'], function(baseForOwnRight, base * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, baseIteratee(iteratee, 3)); + return object && baseForOwnRight(object, castFunction(iteratee)); } return forOwnRight; diff --git a/fromPairs.js b/fromPairs.js index 822f07ac5..7c7cbc23f 100644 --- a/fromPairs.js +++ b/fromPairs.js @@ -17,7 +17,7 @@ define([], function() { */ function fromPairs(pairs) { var index = -1, - length = pairs ? pairs.length : 0, + length = pairs == null ? 0 : pairs.length, result = {}; while (++index < length) { diff --git a/groupBy.js b/groupBy.js index 89fc80082..4572a268e 100644 --- a/groupBy.js +++ b/groupBy.js @@ -18,8 +18,7 @@ define(['./_baseAssignValue', './_createAggregator'], function(baseAssignValue, * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The iteratee to transform keys. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * diff --git a/indexOf.js b/indexOf.js index 25d69cc3a..176428123 100644 --- a/indexOf.js +++ b/indexOf.js @@ -27,7 +27,7 @@ define(['./_baseIndexOf', './toInteger'], function(baseIndexOf, toInteger) { * // => 3 */ function indexOf(array, value, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } diff --git a/initial.js b/initial.js index 7f68d75c3..c70a213de 100644 --- a/initial.js +++ b/initial.js @@ -15,7 +15,7 @@ define(['./_baseSlice'], function(baseSlice) { * // => [1, 2] */ function initial(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseSlice(array, 0, -1) : []; } diff --git a/intersectionWith.js b/intersectionWith.js index 6b8293631..04412d588 100644 --- a/intersectionWith.js +++ b/intersectionWith.js @@ -28,9 +28,8 @@ define(['./_arrayMap', './_baseIntersection', './_baseRest', './_castArrayLikeOb var comparator = last(arrays), mapped = arrayMap(arrays, castArrayLikeObject); - if (comparator === last(mapped)) { - comparator = undefined; - } else { + comparator = typeof comparator == 'function' ? comparator : undefined; + if (comparator) { mapped.pop(); } return (mapped.length && mapped[0] === arrays[0]) diff --git a/isBoolean.js b/isBoolean.js index 7d95eb023..af82b57f4 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -1,18 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var boolTag = '[object Boolean]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is classified as a boolean primitive or object. * @@ -32,7 +22,7 @@ define(['./isObjectLike'], function(isObjectLike) { */ function isBoolean(value) { return value === true || value === false || - (isObjectLike(value) && objectToString.call(value) == boolTag); + (isObjectLike(value) && baseGetTag(value) == boolTag); } return isBoolean; diff --git a/isElement.js b/isElement.js index 4258d6507..f74a332fd 100644 --- a/isElement.js +++ b/isElement.js @@ -18,7 +18,7 @@ define(['./isObjectLike', './isPlainObject'], function(isObjectLike, isPlainObje * // => false */ function isElement(value) { - return value != null && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value); + return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); } return isElement; diff --git a/isEmpty.js b/isEmpty.js index bdcf5493b..ddf6c2c98 100644 --- a/isEmpty.js +++ b/isEmpty.js @@ -44,6 +44,9 @@ define(['./_baseKeys', './_getTag', './isArguments', './isArray', './isArrayLike * // => false */ function isEmpty(value) { + if (value == null) { + return true; + } if (isArrayLike(value) && (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || isBuffer(value) || isTypedArray(value) || isArguments(value))) { diff --git a/isError.js b/isError.js index 4eb11cee3..27fbdf911 100644 --- a/isError.js +++ b/isError.js @@ -1,17 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike', './isPlainObject'], function(baseGetTag, isObjectLike, isPlainObject) { /** `Object#toString` result references. */ - var errorTag = '[object Error]'; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; + var domExcTag = '[object DOMException]', + errorTag = '[object Error]'; /** * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, @@ -35,8 +26,9 @@ define(['./isObjectLike'], function(isObjectLike) { if (!isObjectLike(value)) { return false; } - return (objectToString.call(value) == errorTag) || - (typeof value.message == 'string' && typeof value.name == 'string'); + var tag = baseGetTag(value); + return tag == errorTag || tag == domExcTag || + (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); } return isError; diff --git a/isFunction.js b/isFunction.js index 468b1ab2b..a1cea00e6 100644 --- a/isFunction.js +++ b/isFunction.js @@ -1,20 +1,11 @@ -define(['./isObject'], function(isObject) { +define(['./_baseGetTag', './isObject'], function(baseGetTag, isObject) { /** `Object#toString` result references. */ - var funcTag = '[object Function]', + var asyncTag = '[object AsyncFunction]', + funcTag = '[object Function]', genTag = '[object GeneratorFunction]', proxyTag = '[object Proxy]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is classified as a `Function` object. * @@ -33,10 +24,13 @@ define(['./isObject'], function(isObject) { * // => false */ function isFunction(value) { + if (!isObject(value)) { + return false; + } // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 9 which returns 'object' for typed array and other constructors. - var tag = isObject(value) ? objectToString.call(value) : ''; - return tag == funcTag || tag == genTag || tag == proxyTag; + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; } return isFunction; diff --git a/isNumber.js b/isNumber.js index 777a8e227..16540d968 100644 --- a/isNumber.js +++ b/isNumber.js @@ -1,18 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var numberTag = '[object Number]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is classified as a `Number` primitive or object. * @@ -41,7 +31,7 @@ define(['./isObjectLike'], function(isObjectLike) { */ function isNumber(value) { return typeof value == 'number' || - (isObjectLike(value) && objectToString.call(value) == numberTag); + (isObjectLike(value) && baseGetTag(value) == numberTag); } return isNumber; diff --git a/isPlainObject.js b/isPlainObject.js index b512bf0ea..dc8f0789a 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -1,4 +1,4 @@ -define(['./_getPrototype', './isObjectLike'], function(getPrototype, isObjectLike) { +define(['./_baseGetTag', './_getPrototype', './isObjectLike'], function(baseGetTag, getPrototype, isObjectLike) { /** `Object#toString` result references. */ var objectTag = '[object Object]'; @@ -16,13 +16,6 @@ define(['./_getPrototype', './isObjectLike'], function(getPrototype, isObjectLik /** Used to infer the `Object` constructor. */ var objectCtorString = funcToString.call(Object); - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is a plain object, that is, an object created by the * `Object` constructor or one with a `[[Prototype]]` of `null`. @@ -52,7 +45,7 @@ define(['./_getPrototype', './isObjectLike'], function(getPrototype, isObjectLik * // => true */ function isPlainObject(value) { - if (!isObjectLike(value) || objectToString.call(value) != objectTag) { + if (!isObjectLike(value) || baseGetTag(value) != objectTag) { return false; } var proto = getPrototype(value); @@ -60,8 +53,8 @@ define(['./_getPrototype', './isObjectLike'], function(getPrototype, isObjectLik return true; } var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; - return (typeof Ctor == 'function' && - Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString); + return typeof Ctor == 'function' && Ctor instanceof Ctor && + funcToString.call(Ctor) == objectCtorString; } return isPlainObject; diff --git a/isString.js b/isString.js index da7c60bc5..d8f6869b6 100644 --- a/isString.js +++ b/isString.js @@ -1,18 +1,8 @@ -define(['./isArray', './isObjectLike'], function(isArray, isObjectLike) { +define(['./_baseGetTag', './isArray', './isObjectLike'], function(baseGetTag, isArray, isObjectLike) { /** `Object#toString` result references. */ var stringTag = '[object String]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is classified as a `String` primitive or object. * @@ -32,7 +22,7 @@ define(['./isArray', './isObjectLike'], function(isArray, isObjectLike) { */ function isString(value) { return typeof value == 'string' || - (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag); + (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); } return isString; diff --git a/isSymbol.js b/isSymbol.js index 0d14ec7b1..c4696bbc6 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -1,18 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var symbolTag = '[object Symbol]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is classified as a `Symbol` primitive or object. * @@ -32,7 +22,7 @@ define(['./isObjectLike'], function(isObjectLike) { */ function isSymbol(value) { return typeof value == 'symbol' || - (isObjectLike(value) && objectToString.call(value) == symbolTag); + (isObjectLike(value) && baseGetTag(value) == symbolTag); } return isSymbol; diff --git a/isWeakSet.js b/isWeakSet.js index cfc56a646..dc70e816e 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -1,18 +1,8 @@ -define(['./isObjectLike'], function(isObjectLike) { +define(['./_baseGetTag', './isObjectLike'], function(baseGetTag, isObjectLike) { /** `Object#toString` result references. */ var weakSetTag = '[object WeakSet]'; - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - /** * Checks if `value` is classified as a `WeakSet` object. * @@ -31,7 +21,7 @@ define(['./isObjectLike'], function(isObjectLike) { * // => false */ function isWeakSet(value) { - return isObjectLike(value) && objectToString.call(value) == weakSetTag; + return isObjectLike(value) && baseGetTag(value) == weakSetTag; } return isWeakSet; diff --git a/join.js b/join.js index faa734fa9..9930bf048 100644 --- a/join.js +++ b/join.js @@ -22,7 +22,7 @@ define([], function() { * // => 'a~b~c' */ function join(array, separator) { - return array ? nativeJoin.call(array, separator) : ''; + return array == null ? '' : nativeJoin.call(array, separator); } return join; diff --git a/keyBy.js b/keyBy.js index e22907a2e..7ac38c6ab 100644 --- a/keyBy.js +++ b/keyBy.js @@ -11,8 +11,7 @@ define(['./_baseAssignValue', './_createAggregator'], function(baseAssignValue, * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The iteratee to transform keys. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * diff --git a/last.js b/last.js index ac5152af0..f0a97e105 100644 --- a/last.js +++ b/last.js @@ -18,7 +18,7 @@ define([], function() { * // => 3 */ function last(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? array[length - 1] : undefined; } diff --git a/lastIndexOf.js b/lastIndexOf.js index a967b20dc..dbd0a594f 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -29,7 +29,7 @@ define(['./_baseFindIndex', './_baseIsNaN', './_strictLastIndexOf', './toInteger * // => 1 */ function lastIndexOf(array, value, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } diff --git a/main.js b/main.js index f00108ba4..814e1d481 100644 --- a/main.js +++ b/main.js @@ -2,7 +2,7 @@ * @license * lodash (Custom Build) * Build: `lodash exports="amd" -d -o ./main.js` - * Copyright jQuery Foundation and other contributors + * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.16.4'; + var VERSION = '4.16.5'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -52,7 +52,7 @@ DEFAULT_TRUNC_OMISSION = '...'; /** Used to detect hot functions by number of calls within a span of milliseconds. */ - var HOT_COUNT = 500, + var HOT_COUNT = 800, HOT_SPAN = 16; /** Used to indicate the type of lazy iteratees. */ @@ -87,13 +87,16 @@ /** `Object#toString` result references. */ var argsTag = '[object Arguments]', arrayTag = '[object Array]', + asyncTag = '[object AsyncFunction]', boolTag = '[object Boolean]', dateTag = '[object Date]', + domExcTag = '[object DOMException]', errorTag = '[object Error]', funcTag = '[object Function]', genTag = '[object GeneratorFunction]', mapTag = '[object Map]', numberTag = '[object Number]', + nullTag = '[object Null]', objectTag = '[object Object]', promiseTag = '[object Promise]', proxyTag = '[object Proxy]', @@ -101,6 +104,7 @@ setTag = '[object Set]', stringTag = '[object String]', symbolTag = '[object Symbol]', + undefinedTag = '[object Undefined]', weakMapTag = '[object WeakMap]', weakSetTag = '[object WeakSet]'; @@ -226,13 +230,15 @@ rsZWJ = '\\u200d'; /** Used to compose unicode regexes. */ - var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')', - rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')', - rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', - rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', + var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', + rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', + rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', + rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', reOptMod = rsModifier + '?', rsOptVar = '[' + rsVarRange + ']?', rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', + rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)', + rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)', rsSeq = rsOptVar + reOptMod + rsOptJoin, rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; @@ -251,10 +257,12 @@ /** Used to match complex or compound words. */ var reUnicodeWord = RegExp([ - rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', - rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, - rsUpper + '+' + rsOptUpperContr, + rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', + rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, + rsUpper + '+' + rsOptContrUpper, + rsOrdUpper, + rsOrdLower, rsDigits, rsEmoji ].join('|'), 'g'); @@ -497,7 +505,7 @@ */ function arrayAggregator(array, setter, iteratee, accumulator) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { var value = array[index]; @@ -517,7 +525,7 @@ */ function arrayEach(array, iteratee) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (iteratee(array[index], index, array) === false) { @@ -537,7 +545,7 @@ * @returns {Array} Returns `array`. */ function arrayEachRight(array, iteratee) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; while (length--) { if (iteratee(array[length], length, array) === false) { @@ -559,7 +567,7 @@ */ function arrayEvery(array, predicate) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (!predicate(array[index], index, array)) { @@ -580,7 +588,7 @@ */ function arrayFilter(array, predicate) { var index = -1, - length = array ? array.length : 0, + length = array == null ? 0 : array.length, resIndex = 0, result = []; @@ -603,7 +611,7 @@ * @returns {boolean} Returns `true` if `target` is found, else `false`. */ function arrayIncludes(array, value) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return !!length && baseIndexOf(array, value, 0) > -1; } @@ -618,7 +626,7 @@ */ function arrayIncludesWith(array, value, comparator) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (comparator(value, array[index])) { @@ -639,7 +647,7 @@ */ function arrayMap(array, iteratee) { var index = -1, - length = array ? array.length : 0, + length = array == null ? 0 : array.length, result = Array(length); while (++index < length) { @@ -681,7 +689,7 @@ */ function arrayReduce(array, iteratee, accumulator, initAccum) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; if (initAccum && length) { accumulator = array[++index]; @@ -705,7 +713,7 @@ * @returns {*} Returns the accumulated value. */ function arrayReduceRight(array, iteratee, accumulator, initAccum) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (initAccum && length) { accumulator = array[--length]; } @@ -727,7 +735,7 @@ */ function arraySome(array, predicate) { var index = -1, - length = array ? array.length : 0; + length = array == null ? 0 : array.length; while (++index < length) { if (predicate(array[index], index, array)) { @@ -871,7 +879,7 @@ * @returns {number} Returns the mean. */ function baseMean(array, iteratee) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? (baseSum(array, iteratee) / length) : NAN; } @@ -1411,7 +1419,7 @@ * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; */ var runInContext = (function runInContext(context) { - context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root; + context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); /** Built-in constructor references. */ var Array = context.Array, @@ -1432,12 +1440,6 @@ /** Used to detect overreaching core-js shims. */ var coreJsData = context['__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 = funcProto.toString; @@ -1447,15 +1449,21 @@ /** Used to generate unique IDs. */ var idCounter = 0; - /** Used to infer the `Object` constructor. */ - var objectCtorString = funcToString.call(Object); + /** 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 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ - var objectToString = objectProto.toString; + var nativeObjectToString = objectProto.toString; + + /** Used to infer the `Object` constructor. */ + var objectCtorString = funcToString.call(Object); /** Used to restore the original `_` reference in `_.noConflict`. */ var oldDash = root._; @@ -1472,11 +1480,12 @@ Uint8Array = context.Uint8Array, allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined, getPrototype = overArg(Object.getPrototypeOf, Object), - iteratorSymbol = Symbol ? Symbol.iterator : undefined, objectCreate = Object.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, - spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; + spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined, + symIterator = Symbol ? Symbol.iterator : undefined, + symToStringTag = Symbol ? Symbol.toStringTag : undefined; var defineProperty = (function() { try { @@ -1910,7 +1919,7 @@ */ function Hash(entries) { var index = -1, - length = entries ? entries.length : 0; + length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { @@ -2014,7 +2023,7 @@ */ function ListCache(entries) { var index = -1, - length = entries ? entries.length : 0; + length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { @@ -2131,7 +2140,7 @@ */ function MapCache(entries) { var index = -1, - length = entries ? entries.length : 0; + length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { @@ -2235,7 +2244,7 @@ */ function SetCache(values) { var index = -1, - length = values ? values.length : 0; + length = values == null ? 0 : values.length; this.__data__ = new MapCache; while (++index < length) { @@ -2582,12 +2591,12 @@ */ function baseAt(object, paths) { var index = -1, - isNil = object == null, length = paths.length, - result = Array(length); + result = Array(length), + skip = object == null; while (++index < length) { - result[index] = isNil ? undefined : get(object, paths[index]); + result[index] = skip ? undefined : get(object, paths[index]); } return result; } @@ -2777,7 +2786,7 @@ outer: while (++index < length) { var value = array[index], - computed = iteratee ? iteratee(value) : value; + computed = iteratee == null ? value : iteratee(value); value = (comparator || value !== 0) ? value : 0; if (isCommon && computed === computed) { @@ -3044,14 +3053,20 @@ } /** - * The base implementation of `getTag`. + * The base implementation of `getTag` without fallbacks for buggy environments. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ function baseGetTag(value) { - return objectToString.call(value); + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + value = Object(value); + return (symToStringTag && symToStringTag in value) + ? getRawTag(value) + : objectToString(value); } /** @@ -3213,7 +3228,7 @@ * @returns {boolean} Returns `true` if `value` is an `arguments` object, */ function baseIsArguments(value) { - return isObjectLike(value) && objectToString.call(value) == argsTag; + return isObjectLike(value) && baseGetTag(value) == argsTag; } /** @@ -3224,7 +3239,7 @@ * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. */ function baseIsArrayBuffer(value) { - return isObjectLike(value) && objectToString.call(value) == arrayBufferTag; + return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; } /** @@ -3235,7 +3250,7 @@ * @returns {boolean} Returns `true` if `value` is a date object, else `false`. */ function baseIsDate(value) { - return isObjectLike(value) && objectToString.call(value) == dateTag; + return isObjectLike(value) && baseGetTag(value) == dateTag; } /** @@ -3417,7 +3432,7 @@ * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. */ function baseIsRegExp(value) { - return isObject(value) && objectToString.call(value) == regexpTag; + return isObjectLike(value) && baseGetTag(value) == regexpTag; } /** @@ -3440,7 +3455,7 @@ */ function baseIsTypedArray(value) { return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; + isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; } /** @@ -4101,7 +4116,7 @@ */ function baseSortedIndex(array, value, retHighest) { var low = 0, - high = array ? array.length : low; + high = array == null ? low : array.length; if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { while (low < high) { @@ -4137,7 +4152,7 @@ value = iteratee(value); var low = 0, - high = array ? array.length : 0, + high = array == null ? 0 : array.length, valIsNaN = value !== value, valIsNull = value === null, valIsSymbol = isSymbol(value), @@ -4387,18 +4402,25 @@ * @returns {Array} Returns the new array of values. */ function baseXor(arrays, iteratee, comparator) { + var length = arrays.length; + if (length < 2) { + return length ? baseUniq(arrays[0]) : []; + } var index = -1, - length = arrays.length; + result = Array(length); while (++index < length) { - var result = result - ? arrayPush( - baseDifference(result, arrays[index], iteratee, comparator), - baseDifference(arrays[index], result, iteratee, comparator) - ) - : arrays[index]; + var array = arrays[index], + othIndex = -1; + + while (++othIndex < length) { + var othArray = arrays[othIndex]; + if (othArray !== array) { + result[index] = baseDifference(result[index] || array, othArray, iteratee, comparator); + } + } } - return (result && result.length) ? baseUniq(result, iteratee, comparator) : []; + return baseUniq(baseFlatten(result, 1), iteratee, comparator); } /** @@ -5935,6 +5957,33 @@ return baseIsNative(value) ? value : undefined; } + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + /** * Creates an array of the own enumerable symbol properties of `object`. * @@ -5977,9 +6026,9 @@ (Set && getTag(new Set) != setTag) || (WeakMap && getTag(new WeakMap) != weakMapTag)) { getTag = function(value) { - var result = objectToString.call(value), + var result = baseGetTag(value), Ctor = result == objectTag ? value.constructor : undefined, - ctorString = Ctor ? toSource(Ctor) : undefined; + ctorString = Ctor ? toSource(Ctor) : ''; if (ctorString) { switch (ctorString) { @@ -6060,7 +6109,7 @@ if (result || ++index != length) { return result; } - length = object ? object.length : 0; + length = object == null ? 0 : object.length; return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object)); } @@ -6471,6 +6520,17 @@ return result; } + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString.call(value); + } + /** * A specialized version of `baseRest` which transforms the rest array. * @@ -6681,7 +6741,7 @@ * Converts `func` to its source code. * * @private - * @param {Function} func The function to process. + * @param {Function} func The function to convert. * @returns {string} Returns the source code. */ function toSource(func) { @@ -6761,7 +6821,7 @@ } else { size = nativeMax(toInteger(size), 0); } - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length || size < 1) { return []; } @@ -6792,7 +6852,7 @@ */ function compact(array) { var index = -1, - length = array ? array.length : 0, + length = array == null ? 0 : array.length, resIndex = 0, result = []; @@ -6964,7 +7024,7 @@ * // => [1, 2, 3] */ function drop(array, n, guard) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } @@ -6998,7 +7058,7 @@ * // => [1, 2, 3] */ function dropRight(array, n, guard) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } @@ -7058,8 +7118,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -7120,7 +7179,7 @@ * // => [4, '*', '*', 10] */ function fill(array, value, start, end) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } @@ -7140,8 +7199,7 @@ * @since 1.1.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. * @example @@ -7168,7 +7226,7 @@ * // => 2 */ function findIndex(array, predicate, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } @@ -7188,8 +7246,7 @@ * @since 2.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=array.length-1] The index to search from. * @returns {number} Returns the index of the found element, else `-1`. * @example @@ -7216,7 +7273,7 @@ * // => 0 */ function findLastIndex(array, predicate, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } @@ -7245,7 +7302,7 @@ * // => [1, 2, [3, [4]], 5] */ function flatten(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseFlatten(array, 1) : []; } @@ -7264,7 +7321,7 @@ * // => [1, 2, 3, 4, 5] */ function flattenDeep(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseFlatten(array, INFINITY) : []; } @@ -7289,7 +7346,7 @@ * // => [1, 2, 3, [4], 5] */ function flattenDepth(array, depth) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } @@ -7314,7 +7371,7 @@ */ function fromPairs(pairs) { var index = -1, - length = pairs ? pairs.length : 0, + length = pairs == null ? 0 : pairs.length, result = {}; while (++index < length) { @@ -7370,7 +7427,7 @@ * // => 3 */ function indexOf(array, value, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } @@ -7396,7 +7453,7 @@ * // => [1, 2] */ function initial(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseSlice(array, 0, -1) : []; } @@ -7486,9 +7543,8 @@ var comparator = last(arrays), mapped = arrayMap(arrays, castArrayLikeObject); - if (comparator === last(mapped)) { - comparator = undefined; - } else { + comparator = typeof comparator == 'function' ? comparator : undefined; + if (comparator) { mapped.pop(); } return (mapped.length && mapped[0] === arrays[0]) @@ -7512,7 +7568,7 @@ * // => 'a~b~c' */ function join(array, separator) { - return array ? nativeJoin.call(array, separator) : ''; + return array == null ? '' : nativeJoin.call(array, separator); } /** @@ -7530,7 +7586,7 @@ * // => 3 */ function last(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? array[length - 1] : undefined; } @@ -7556,7 +7612,7 @@ * // => 1 */ function lastIndexOf(array, value, fromIndex) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return -1; } @@ -7659,8 +7715,7 @@ * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns `array`. * @example * @@ -7730,7 +7785,7 @@ * // => ['b', 'd'] */ var pullAt = flatRest(function(array, indexes) { - var length = array ? array.length : 0, + var length = array == null ? 0 : array.length, result = baseAt(array, indexes); basePullAt(array, arrayMap(indexes, function(index) { @@ -7753,8 +7808,7 @@ * @since 2.0.0 * @category Array * @param {Array} array The array to modify. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the new array of removed elements. * @example * @@ -7814,7 +7868,7 @@ * // => [3, 2, 1] */ function reverse(array) { - return array ? nativeReverse.call(array) : array; + return array == null ? array : nativeReverse.call(array); } /** @@ -7834,7 +7888,7 @@ * @returns {Array} Returns the slice of `array`. */ function slice(array, start, end) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } @@ -7881,8 +7935,7 @@ * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. * @example @@ -7917,7 +7970,7 @@ * // => 1 */ function sortedIndexOf(array, value) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (length) { var index = baseSortedIndex(array, value); if (index < length && eq(array[index], value)) { @@ -7960,8 +8013,7 @@ * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. * @example @@ -7996,7 +8048,7 @@ * // => 3 */ function sortedLastIndexOf(array, value) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (length) { var index = baseSortedIndex(array, value, true) - 1; if (eq(array[index], value)) { @@ -8064,7 +8116,7 @@ * // => [2, 3] */ function tail(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseSlice(array, 1, length) : []; } @@ -8127,7 +8179,7 @@ * // => [] */ function takeRight(array, n, guard) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } @@ -8146,8 +8198,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -8188,8 +8239,7 @@ * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -8252,8 +8302,7 @@ * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of combined values. * @example * @@ -8295,9 +8344,7 @@ */ var unionWith = baseRest(function(arrays) { var comparator = last(arrays); - if (isArrayLikeObject(comparator)) { - comparator = undefined; - } + comparator = typeof comparator == 'function' ? comparator : undefined; return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); }); @@ -8320,9 +8367,7 @@ * // => [2, 1] */ function uniq(array) { - return (array && array.length) - ? baseUniq(array) - : []; + return (array && array.length) ? baseUniq(array) : []; } /** @@ -8337,8 +8382,7 @@ * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. * @example * @@ -8350,9 +8394,7 @@ * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniqBy(array, iteratee) { - return (array && array.length) - ? baseUniq(array, getIteratee(iteratee, 2)) - : []; + return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; } /** @@ -8376,9 +8418,8 @@ * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] */ function uniqWith(array, comparator) { - return (array && array.length) - ? baseUniq(array, undefined, comparator) - : []; + comparator = typeof comparator == 'function' ? comparator : undefined; + return (array && array.length) ? baseUniq(array, undefined, comparator) : []; } /** @@ -8510,8 +8551,7 @@ * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example * @@ -8553,9 +8593,7 @@ */ var xorWith = baseRest(function(arrays) { var comparator = last(arrays); - if (isArrayLikeObject(comparator)) { - comparator = undefined; - } + comparator = typeof comparator == 'function' ? comparator : undefined; return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator); }); @@ -8626,7 +8664,8 @@ * @since 3.8.0 * @category Array * @param {...Array} [arrays] The arrays to process. - * @param {Function} [iteratee=_.identity] The function to combine grouped values. + * @param {Function} [iteratee=_.identity] The function to combine + * grouped values. * @returns {Array} Returns the new array of grouped elements. * @example * @@ -9003,8 +9042,7 @@ * @since 0.5.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The iteratee to transform keys. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * @@ -9038,8 +9076,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {boolean} Returns `true` if all elements pass the predicate check, * else `false`. @@ -9085,8 +9122,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @see _.reject * @example @@ -9126,8 +9162,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. * @returns {*} Returns the matched element, else `undefined`. * @example @@ -9164,8 +9199,7 @@ * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to inspect. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @param {number} [fromIndex=collection.length-1] The index to search from. * @returns {*} Returns the matched element, else `undefined`. * @example @@ -9187,8 +9221,7 @@ * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example * @@ -9212,8 +9245,7 @@ * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example * @@ -9237,8 +9269,7 @@ * @since 4.7.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The function invoked per iteration. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @param {number} [depth=1] The maximum recursion depth. * @returns {Array} Returns the new flattened array. * @example @@ -9327,8 +9358,7 @@ * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The iteratee to transform keys. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * @@ -9437,8 +9467,7 @@ * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [iteratee=_.identity] - * The iteratee to transform keys. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * @@ -10453,7 +10482,7 @@ * function. Its creation may be customized by replacing the `_.memoize.Cache` * constructor with one whose instances implement the * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) - * method interface of `delete`, `get`, `has`, and `set`. + * method interface of `clear`, `delete`, `get`, `has`, and `set`. * * @static * @memberOf _ @@ -10487,7 +10516,7 @@ * _.memoize.Cache = WeakMap; */ function memoize(func, resolver) { - if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { + if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { throw new TypeError(FUNC_ERROR_TEXT); } var memoized = function() { @@ -10903,8 +10932,7 @@ * // => '

fred, barney, & pebbles

' */ function wrap(value, wrapper) { - wrapper = wrapper == null ? identity : wrapper; - return partial(wrapper, value); + return partial(castFunction(wrapper), value); } /*------------------------------------------------------------------------*/ @@ -11012,6 +11040,7 @@ * // => 0 */ function cloneWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; return baseClone(value, false, true, customizer); } @@ -11066,6 +11095,7 @@ * // => 20 */ function cloneDeepWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; return baseClone(value, true, true, customizer); } @@ -11329,7 +11359,7 @@ */ function isBoolean(value) { return value === true || value === false || - (isObjectLike(value) && objectToString.call(value) == boolTag); + (isObjectLike(value) && baseGetTag(value) == boolTag); } /** @@ -11388,7 +11418,7 @@ * // => false */ function isElement(value) { - return value != null && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value); + return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); } /** @@ -11425,6 +11455,9 @@ * // => false */ function isEmpty(value) { + if (value == null) { + return true; + } if (isArrayLike(value) && (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || isBuffer(value) || isTypedArray(value) || isArguments(value))) { @@ -11537,8 +11570,9 @@ if (!isObjectLike(value)) { return false; } - return (objectToString.call(value) == errorTag) || - (typeof value.message == 'string' && typeof value.name == 'string'); + var tag = baseGetTag(value); + return tag == errorTag || tag == domExcTag || + (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); } /** @@ -11589,10 +11623,13 @@ * // => false */ function isFunction(value) { + if (!isObject(value)) { + return false; + } // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 9 which returns 'object' for typed array and other constructors. - var tag = isObject(value) ? objectToString.call(value) : ''; - return tag == funcTag || tag == genTag || tag == proxyTag; + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; } /** @@ -11943,7 +11980,7 @@ */ function isNumber(value) { return typeof value == 'number' || - (isObjectLike(value) && objectToString.call(value) == numberTag); + (isObjectLike(value) && baseGetTag(value) == numberTag); } /** @@ -11975,7 +12012,7 @@ * // => true */ function isPlainObject(value) { - if (!isObjectLike(value) || objectToString.call(value) != objectTag) { + if (!isObjectLike(value) || baseGetTag(value) != objectTag) { return false; } var proto = getPrototype(value); @@ -11983,8 +12020,8 @@ return true; } var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; - return (typeof Ctor == 'function' && - Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString); + return typeof Ctor == 'function' && Ctor instanceof Ctor && + funcToString.call(Ctor) == objectCtorString; } /** @@ -12075,7 +12112,7 @@ */ function isString(value) { return typeof value == 'string' || - (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag); + (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); } /** @@ -12097,7 +12134,7 @@ */ function isSymbol(value) { return typeof value == 'symbol' || - (isObjectLike(value) && objectToString.call(value) == symbolTag); + (isObjectLike(value) && baseGetTag(value) == symbolTag); } /** @@ -12179,7 +12216,7 @@ * // => false */ function isWeakSet(value) { - return isObjectLike(value) && objectToString.call(value) == weakSetTag; + return isObjectLike(value) && baseGetTag(value) == weakSetTag; } /** @@ -12264,8 +12301,8 @@ if (isArrayLike(value)) { return isString(value) ? stringToArray(value) : copyArray(value); } - if (iteratorSymbol && value[iteratorSymbol]) { - return iteratorToArray(value[iteratorSymbol]()); + if (symIterator && value[symIterator]) { + return iteratorToArray(value[symIterator]()); } var tag = getTag(value), func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); @@ -12698,7 +12735,7 @@ */ function create(prototype, properties) { var result = baseCreate(prototype); - return properties ? baseAssign(result, properties) : result; + return properties == null ? result : baseAssign(result, properties); } /** @@ -13805,7 +13842,7 @@ * // => ['h', 'i'] */ function values(object) { - return object ? baseValues(object, keys(object)) : []; + return object == null ? [] : baseValues(object, keys(object)); } /** @@ -15192,7 +15229,7 @@ * // => 'no match' */ function cond(pairs) { - var length = pairs ? pairs.length : 0, + var length = pairs == null ? 0 : pairs.length, toIteratee = getIteratee(); pairs = !length ? [] : arrayMap(pairs, function(pair) { @@ -16944,8 +16981,8 @@ // Add lazy aliases. lodash.prototype.first = lodash.prototype.head; - if (iteratorSymbol) { - lodash.prototype[iteratorSymbol] = wrapperToIterator; + if (symIterator) { + lodash.prototype[symIterator] = wrapperToIterator; } return lodash; }); diff --git a/memoize.js b/memoize.js index bd2c0cbe8..bbb380a1c 100644 --- a/memoize.js +++ b/memoize.js @@ -14,7 +14,7 @@ define(['./_MapCache'], function(MapCache) { * function. Its creation may be customized by replacing the `_.memoize.Cache` * constructor with one whose instances implement the * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) - * method interface of `delete`, `get`, `has`, and `set`. + * method interface of `clear`, `delete`, `get`, `has`, and `set`. * * @static * @memberOf _ @@ -48,7 +48,7 @@ define(['./_MapCache'], function(MapCache) { * _.memoize.Cache = WeakMap; */ function memoize(func, resolver) { - if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { + if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { throw new TypeError(FUNC_ERROR_TEXT); } var memoized = function() { diff --git a/package.json b/package.json index b4438d9dd..4e92c04ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-amd", - "version": "4.16.4", + "version": "4.16.5", "description": "Lodash exported as AMD modules.", "keywords": "amd, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/pullAllBy.js b/pullAllBy.js index 1d60da248..a25f30f5a 100644 --- a/pullAllBy.js +++ b/pullAllBy.js @@ -13,8 +13,7 @@ define(['./_baseIteratee', './_basePullAll'], function(baseIteratee, basePullAll * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns `array`. * @example * diff --git a/pullAt.js b/pullAt.js index 19444d17d..5357c16e1 100644 --- a/pullAt.js +++ b/pullAt.js @@ -25,7 +25,7 @@ define(['./_arrayMap', './_baseAt', './_basePullAt', './_compareAscending', './_ * // => ['b', 'd'] */ var pullAt = flatRest(function(array, indexes) { - var length = array ? array.length : 0, + var length = array == null ? 0 : array.length, result = baseAt(array, indexes); basePullAt(array, arrayMap(indexes, function(index) { diff --git a/remove.js b/remove.js index f136e43ab..b97b11714 100644 --- a/remove.js +++ b/remove.js @@ -13,8 +13,7 @@ define(['./_baseIteratee', './_basePullAt'], function(baseIteratee, basePullAt) * @since 2.0.0 * @category Array * @param {Array} array The array to modify. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the new array of removed elements. * @example * diff --git a/reverse.js b/reverse.js index dab455d4f..ee971f274 100644 --- a/reverse.js +++ b/reverse.js @@ -30,7 +30,7 @@ define([], function() { * // => [3, 2, 1] */ function reverse(array) { - return array ? nativeReverse.call(array) : array; + return array == null ? array : nativeReverse.call(array); } return reverse; diff --git a/slice.js b/slice.js index 61ae877fd..526f1e7c0 100644 --- a/slice.js +++ b/slice.js @@ -20,7 +20,7 @@ define(['./_baseSlice', './_isIterateeCall', './toInteger'], function(baseSlice, * @returns {Array} Returns the slice of `array`. */ function slice(array, start, end) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/sortedIndexBy.js b/sortedIndexBy.js index e0d50dcfc..a2e98952c 100644 --- a/sortedIndexBy.js +++ b/sortedIndexBy.js @@ -11,8 +11,7 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. * @example diff --git a/sortedIndexOf.js b/sortedIndexOf.js index 9f70eaa09..b1a70d7cc 100644 --- a/sortedIndexOf.js +++ b/sortedIndexOf.js @@ -17,7 +17,7 @@ define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) { * // => 1 */ function sortedIndexOf(array, value) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (length) { var index = baseSortedIndex(array, value); if (index < length && eq(array[index], value)) { diff --git a/sortedLastIndexBy.js b/sortedLastIndexBy.js index 1362689db..95638d902 100644 --- a/sortedLastIndexBy.js +++ b/sortedLastIndexBy.js @@ -11,8 +11,7 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {number} Returns the index at which `value` should be inserted * into `array`. * @example diff --git a/sortedLastIndexOf.js b/sortedLastIndexOf.js index d1b3341f8..278b6628c 100644 --- a/sortedLastIndexOf.js +++ b/sortedLastIndexOf.js @@ -17,7 +17,7 @@ define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) { * // => 3 */ function sortedLastIndexOf(array, value) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (length) { var index = baseSortedIndex(array, value, true) - 1; if (eq(array[index], value)) { diff --git a/tail.js b/tail.js index 46081d966..4fe1c6d32 100644 --- a/tail.js +++ b/tail.js @@ -15,7 +15,7 @@ define(['./_baseSlice'], function(baseSlice) { * // => [2, 3] */ function tail(array) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; return length ? baseSlice(array, 1, length) : []; } diff --git a/takeRight.js b/takeRight.js index 9ad9bf6df..56a53eb58 100644 --- a/takeRight.js +++ b/takeRight.js @@ -29,7 +29,7 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * // => [] */ function takeRight(array, n, guard) { - var length = array ? array.length : 0; + var length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/takeRightWhile.js b/takeRightWhile.js index 05506f3cb..c0d14e910 100644 --- a/takeRightWhile.js +++ b/takeRightWhile.js @@ -10,8 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/takeWhile.js b/takeWhile.js index 49fa20ef8..134c4234d 100644 --- a/takeWhile.js +++ b/takeWhile.js @@ -10,8 +10,7 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. + * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/times.js b/times.js index 0549732ef..cb2e673f5 100644 --- a/times.js +++ b/times.js @@ -1,4 +1,4 @@ -define(['./_baseIteratee', './_baseTimes', './toInteger'], function(baseIteratee, baseTimes, toInteger) { +define(['./_baseTimes', './_castFunction', './toInteger'], function(baseTimes, castFunction, toInteger) { /** Used as references for various `Number` constants. */ var MAX_SAFE_INTEGER = 9007199254740991; @@ -36,7 +36,7 @@ define(['./_baseIteratee', './_baseTimes', './toInteger'], function(baseIteratee var index = MAX_ARRAY_LENGTH, length = nativeMin(n, MAX_ARRAY_LENGTH); - iteratee = baseIteratee(iteratee); + iteratee = castFunction(iteratee); n -= MAX_ARRAY_LENGTH; var result = baseTimes(length, iteratee); diff --git a/toArray.js b/toArray.js index f2f1bce1b..679188187 100644 --- a/toArray.js +++ b/toArray.js @@ -8,7 +8,7 @@ define(['./_Symbol', './_copyArray', './_getTag', './isArrayLike', './isString', setTag = '[object Set]'; /** Built-in value references. */ - var iteratorSymbol = Symbol ? Symbol.iterator : undefined; + var symIterator = Symbol ? Symbol.iterator : undefined; /** * Converts `value` to an array. @@ -40,8 +40,8 @@ define(['./_Symbol', './_copyArray', './_getTag', './isArrayLike', './isString', if (isArrayLike(value)) { return isString(value) ? stringToArray(value) : copyArray(value); } - if (iteratorSymbol && value[iteratorSymbol]) { - return iteratorToArray(value[iteratorSymbol]()); + if (symIterator && value[symIterator]) { + return iteratorToArray(value[symIterator]()); } var tag = getTag(value), func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); diff --git a/unionBy.js b/unionBy.js index 627017550..e12b1e7b0 100644 --- a/unionBy.js +++ b/unionBy.js @@ -15,8 +15,7 @@ define(['./_baseFlatten', './_baseIteratee', './_baseRest', './_baseUniq', './is * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of combined values. * @example * diff --git a/unionWith.js b/unionWith.js index 48e1a0c26..c99459065 100644 --- a/unionWith.js +++ b/unionWith.js @@ -26,9 +26,7 @@ define(['./_baseFlatten', './_baseRest', './_baseUniq', './isArrayLikeObject', ' */ var unionWith = baseRest(function(arrays) { var comparator = last(arrays); - if (isArrayLikeObject(comparator)) { - comparator = undefined; - } + comparator = typeof comparator == 'function' ? comparator : undefined; return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); }); diff --git a/uniq.js b/uniq.js index 63978dda3..ac3c9d3be 100644 --- a/uniq.js +++ b/uniq.js @@ -19,9 +19,7 @@ define(['./_baseUniq'], function(baseUniq) { * // => [2, 1] */ function uniq(array) { - return (array && array.length) - ? baseUniq(array) - : []; + return (array && array.length) ? baseUniq(array) : []; } return uniq; diff --git a/uniqBy.js b/uniqBy.js index db4d9d03e..1a58b3c2c 100644 --- a/uniqBy.js +++ b/uniqBy.js @@ -12,8 +12,7 @@ define(['./_baseIteratee', './_baseUniq'], function(baseIteratee, baseUniq) { * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. * @example * @@ -25,9 +24,7 @@ define(['./_baseIteratee', './_baseUniq'], function(baseIteratee, baseUniq) { * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniqBy(array, iteratee) { - return (array && array.length) - ? baseUniq(array, baseIteratee(iteratee, 2)) - : []; + return (array && array.length) ? baseUniq(array, baseIteratee(iteratee, 2)) : []; } return uniqBy; diff --git a/uniqWith.js b/uniqWith.js index ae65156b9..ddef21ca0 100644 --- a/uniqWith.js +++ b/uniqWith.js @@ -24,9 +24,8 @@ define(['./_baseUniq'], function(baseUniq) { * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] */ function uniqWith(array, comparator) { - return (array && array.length) - ? baseUniq(array, undefined, comparator) - : []; + comparator = typeof comparator == 'function' ? comparator : undefined; + return (array && array.length) ? baseUniq(array, undefined, comparator) : []; } return uniqWith; diff --git a/values.js b/values.js index ab82f26c6..aafc34dbd 100644 --- a/values.js +++ b/values.js @@ -27,7 +27,7 @@ define(['./_baseValues', './keys'], function(baseValues, keys) { * // => ['h', 'i'] */ function values(object) { - return object ? baseValues(object, keys(object)) : []; + return object == null ? [] : baseValues(object, keys(object)); } return values; diff --git a/wrap.js b/wrap.js index 77323cc4e..7904eeb02 100644 --- a/wrap.js +++ b/wrap.js @@ -1,4 +1,4 @@ -define(['./identity', './partial'], function(identity, partial) { +define(['./_castFunction', './partial'], function(castFunction, partial) { /** * Creates a function that provides `value` to `wrapper` as its first @@ -23,8 +23,7 @@ define(['./identity', './partial'], function(identity, partial) { * // => '

fred, barney, & pebbles

' */ function wrap(value, wrapper) { - wrapper = wrapper == null ? identity : wrapper; - return partial(wrapper, value); + return partial(castFunction(wrapper), value); } return wrap; diff --git a/xorBy.js b/xorBy.js index b78ca30ee..21fd7f2ea 100644 --- a/xorBy.js +++ b/xorBy.js @@ -15,8 +15,7 @@ define(['./_arrayFilter', './_baseIteratee', './_baseRest', './_baseXor', './isA * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function} [iteratee=_.identity] - * The iteratee invoked per element. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example * diff --git a/xorWith.js b/xorWith.js index 775a9ccee..7ca65161b 100644 --- a/xorWith.js +++ b/xorWith.js @@ -26,9 +26,7 @@ define(['./_arrayFilter', './_baseRest', './_baseXor', './isArrayLikeObject', '. */ var xorWith = baseRest(function(arrays) { var comparator = last(arrays); - if (isArrayLikeObject(comparator)) { - comparator = undefined; - } + comparator = typeof comparator == 'function' ? comparator : undefined; return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator); }); diff --git a/zipWith.js b/zipWith.js index 371d7ccbb..6e8a8c3c5 100644 --- a/zipWith.js +++ b/zipWith.js @@ -13,7 +13,8 @@ define(['./_baseRest', './unzipWith'], function(baseRest, unzipWith) { * @since 3.8.0 * @category Array * @param {...Array} [arrays] The arrays to process. - * @param {Function} [iteratee=_.identity] The function to combine grouped values. + * @param {Function} [iteratee=_.identity] The function to combine + * grouped values. * @returns {Array} Returns the new array of grouped elements. * @example *