diff --git a/LICENSE b/LICENSE index bcbe13d67..e0c69d560 100644 --- a/LICENSE +++ b/LICENSE @@ -1,23 +1,47 @@ -The MIT License (MIT) +Copyright jQuery Foundation and other contributors -Copyright 2012-2016 The Dojo Foundation -Based on Underscore.js, copyright 2009-2016 Jeremy Ashkenas, +Based on Underscore.js, copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +This software consists of voluntary contributions made by many +individuals. For exact contribution history, see the revision history +available at https://github.com/lodash/lodash -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The following license applies to all parts of this software except as +documented below: -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +==== + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +==== + +Copyright and related rights for sample code are waived via CC0. Sample +code is defined as all source code displayed within the prose of the +documentation. + +CC0: http://creativecommons.org/publicdomain/zero/1.0/ + +==== + +Files located in the node_modules and vendor directories are externally +maintained libraries used by this software which have their own +licenses; we recommend you read them, as their terms may differ from the +terms above. diff --git a/README.md b/README.md index 0f11ca914..e005f0290 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.6.1 +# lodash-amd v4.7.0 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.6.1-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.7.0-amd) for more details. diff --git a/_DataView.js b/_DataView.js new file mode 100644 index 000000000..c48819bec --- /dev/null +++ b/_DataView.js @@ -0,0 +1,7 @@ +define(['./_getNative', './_root'], function(getNative, root) { + + /* Built-in method references that are verified to be native. */ + var DataView = getNative(root, 'DataView'); + + return DataView; +}); diff --git a/_LazyWrapper.js b/_LazyWrapper.js index 66062b0bf..0852233ef 100644 --- a/_LazyWrapper.js +++ b/_LazyWrapper.js @@ -20,6 +20,7 @@ define(['./_baseCreate', './_baseLodash'], function(baseCreate, baseLodash) { this.__views__ = []; } + // Ensure `LazyWrapper` is an instance of `baseLodash`. LazyWrapper.prototype = baseCreate(baseLodash.prototype); LazyWrapper.prototype.constructor = LazyWrapper; diff --git a/_LodashWrapper.js b/_LodashWrapper.js index a09a8aa4e..ce72ec969 100644 --- a/_LodashWrapper.js +++ b/_LodashWrapper.js @@ -8,7 +8,7 @@ define(['./_baseCreate', './_baseLodash'], function(baseCreate, baseLodash) { * * @private * @param {*} value The value to wrap. - * @param {boolean} [chainAll] Enable chaining for all wrapper methods. + * @param {boolean} [chainAll] Enable explicit method chain sequences. */ function LodashWrapper(value, chainAll) { this.__wrapped__ = value; diff --git a/_MapCache.js b/_MapCache.js index 67e19b70c..a9e92f4d7 100644 --- a/_MapCache.js +++ b/_MapCache.js @@ -18,7 +18,7 @@ define(['./_mapClear', './_mapDelete', './_mapGet', './_mapHas', './_mapSet'], f } } - // Add functions to the `MapCache`. + // Add methods to `MapCache`. MapCache.prototype.clear = mapClear; MapCache.prototype['delete'] = mapDelete; MapCache.prototype.get = mapGet; diff --git a/_Promise.js b/_Promise.js new file mode 100644 index 000000000..9d2c38818 --- /dev/null +++ b/_Promise.js @@ -0,0 +1,7 @@ +define(['./_getNative', './_root'], function(getNative, root) { + + /* Built-in method references that are verified to be native. */ + var Promise = getNative(root, 'Promise'); + + return Promise; +}); diff --git a/_SetCache.js b/_SetCache.js index e25032495..ae5f43105 100644 --- a/_SetCache.js +++ b/_SetCache.js @@ -18,7 +18,7 @@ define(['./_MapCache', './_cachePush'], function(MapCache, cachePush) { } } - // Add functions to the `SetCache`. + // Add methods to `SetCache`. SetCache.prototype.push = cachePush; return SetCache; diff --git a/_Stack.js b/_Stack.js index bd3cbc17e..688998b9b 100644 --- a/_Stack.js +++ b/_Stack.js @@ -18,7 +18,7 @@ define(['./_stackClear', './_stackDelete', './_stackGet', './_stackHas', './_sta } } - // Add functions to the `Stack` cache. + // Add methods to `Stack`. Stack.prototype.clear = stackClear; Stack.prototype['delete'] = stackDelete; Stack.prototype.get = stackGet; diff --git a/_arrayEvery.js b/_arrayEvery.js index a0268bd90..45673ab0c 100644 --- a/_arrayEvery.js +++ b/_arrayEvery.js @@ -7,7 +7,8 @@ define([], function() { * @private * @param {Array} array The array to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. */ function arrayEvery(array, predicate) { var index = -1, diff --git a/_arrayReduce.js b/_arrayReduce.js index 1ea0a59f9..7f6952bbc 100644 --- a/_arrayReduce.js +++ b/_arrayReduce.js @@ -8,7 +8,8 @@ define([], function() { * @param {Array} array The array to iterate over. * @param {Function} iteratee The function invoked per iteration. * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value. + * @param {boolean} [initAccum] Specify using the first element of `array` as + * the initial value. * @returns {*} Returns the accumulated value. */ function arrayReduce(array, iteratee, accumulator, initAccum) { diff --git a/_arrayReduceRight.js b/_arrayReduceRight.js index ee1e346b5..d4bf6eb8a 100644 --- a/_arrayReduceRight.js +++ b/_arrayReduceRight.js @@ -8,7 +8,8 @@ define([], function() { * @param {Array} array The array to iterate over. * @param {Function} iteratee The function invoked per iteration. * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value. + * @param {boolean} [initAccum] Specify using the last element of `array` as + * the initial value. * @returns {*} Returns the accumulated value. */ function arrayReduceRight(array, iteratee, accumulator, initAccum) { diff --git a/_arraySome.js b/_arraySome.js index 2b15a25a1..7344ac74f 100644 --- a/_arraySome.js +++ b/_arraySome.js @@ -7,7 +7,8 @@ define([], function() { * @private * @param {Array} array The array to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. */ function arraySome(array, predicate) { var index = -1, diff --git a/_assocDelete.js b/_assocDelete.js index 8a84bbd29..128d8d88a 100644 --- a/_assocDelete.js +++ b/_assocDelete.js @@ -10,7 +10,7 @@ define(['./_assocIndexOf'], function(assocIndexOf) { * Removes `key` and its value from the associative array. * * @private - * @param {Array} array The array to query. + * @param {Array} array The array to modify. * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ diff --git a/_assocIndexOf.js b/_assocIndexOf.js index 78a07596a..e5faa1b29 100644 --- a/_assocIndexOf.js +++ b/_assocIndexOf.js @@ -1,8 +1,7 @@ define(['./eq'], function(eq) { /** - * Gets the index at which the first occurrence of `key` is found in `array` - * of key-value pairs. + * Gets the index at which the `key` is found in `array` of key-value pairs. * * @private * @param {Array} array The array to search. diff --git a/_baseCastArrayLikeObject.js b/_baseCastArrayLikeObject.js index 1014ace5b..83693ddda 100644 --- a/_baseCastArrayLikeObject.js +++ b/_baseCastArrayLikeObject.js @@ -5,7 +5,7 @@ define(['./isArrayLikeObject'], function(isArrayLikeObject) { * * @private * @param {*} value The value to inspect. - * @returns {Array} Returns the array-like object. + * @returns {Array|Object} Returns the cast array-like object. */ function baseCastArrayLikeObject(value) { return isArrayLikeObject(value) ? value : []; diff --git a/_baseCastFunction.js b/_baseCastFunction.js index 842a7b8da..3cf65a37d 100644 --- a/_baseCastFunction.js +++ b/_baseCastFunction.js @@ -5,7 +5,7 @@ define(['./identity'], function(identity) { * * @private * @param {*} value The value to inspect. - * @returns {Array} Returns the array-like object. + * @returns {Function} Returns cast function. */ function baseCastFunction(value) { return typeof value == 'function' ? value : identity; diff --git a/_baseCastKey.js b/_baseCastKey.js new file mode 100644 index 000000000..40b9f0626 --- /dev/null +++ b/_baseCastKey.js @@ -0,0 +1,15 @@ +define(['./isSymbol'], function(isSymbol) { + + /** + * Casts `value` to a string if it's not a string or symbol. + * + * @private + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the cast key. + */ + function baseCastKey(key) { + return (typeof key == 'string' || isSymbol(key)) ? key : (key + ''); + } + + return baseCastKey; +}); diff --git a/_baseClone.js b/_baseClone.js index eb6cf4936..f7ddeeab5 100644 --- a/_baseClone.js +++ b/_baseClone.js @@ -1,4 +1,4 @@ -define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_baseForOwn', './_cloneBuffer', './_copyArray', './_copySymbols', './_getTag', './_initCloneArray', './_initCloneByTag', './_initCloneObject', './isArray', './isBuffer', './_isHostObject', './isObject'], function(Stack, arrayEach, assignValue, baseAssign, baseForOwn, cloneBuffer, copyArray, copySymbols, getTag, initCloneArray, initCloneByTag, initCloneObject, isArray, isBuffer, isHostObject, isObject) { +define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_cloneBuffer', './_copyArray', './_copySymbols', './_getAllKeys', './_getTag', './_initCloneArray', './_initCloneByTag', './_initCloneObject', './isArray', './isBuffer', './_isHostObject', './isObject', './keys'], function(Stack, arrayEach, assignValue, baseAssign, cloneBuffer, copyArray, copySymbols, getAllKeys, getTag, initCloneArray, initCloneByTag, initCloneObject, isArray, isBuffer, isHostObject, isObject, keys) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -21,6 +21,7 @@ define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_baseF weakMapTag = '[object WeakMap]'; var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', float32Tag = '[object Float32Array]', float64Tag = '[object Float64Array]', int8Tag = '[object Int8Array]', @@ -34,16 +35,16 @@ define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_baseF /** Used to identify `toStringTag` values supported by `_.clone`. */ var cloneableTags = {}; cloneableTags[argsTag] = cloneableTags[arrayTag] = - cloneableTags[arrayBufferTag] = cloneableTags[boolTag] = - cloneableTags[dateTag] = cloneableTags[float32Tag] = - cloneableTags[float64Tag] = cloneableTags[int8Tag] = - cloneableTags[int16Tag] = cloneableTags[int32Tag] = - cloneableTags[mapTag] = cloneableTags[numberTag] = - cloneableTags[objectTag] = cloneableTags[regexpTag] = - cloneableTags[setTag] = cloneableTags[stringTag] = - cloneableTags[symbolTag] = cloneableTags[uint8Tag] = - cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = - cloneableTags[uint32Tag] = true; + cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = + cloneableTags[boolTag] = cloneableTags[dateTag] = + cloneableTags[float32Tag] = cloneableTags[float64Tag] = + cloneableTags[int8Tag] = cloneableTags[int16Tag] = + cloneableTags[int32Tag] = cloneableTags[mapTag] = + cloneableTags[numberTag] = cloneableTags[objectTag] = + cloneableTags[regexpTag] = cloneableTags[setTag] = + cloneableTags[stringTag] = cloneableTags[symbolTag] = + cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = + cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false; @@ -91,14 +92,13 @@ define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_baseF } result = initCloneObject(isFunc ? {} : value); if (!isDeep) { - result = baseAssign(result, value); - return isFull ? copySymbols(value, result) : result; + return copySymbols(value, baseAssign(result, value)); } } else { if (!cloneableTags[tag]) { return object ? value : {}; } - result = initCloneByTag(value, tag, isDeep); + result = initCloneByTag(value, tag, baseClone, isDeep); } } // Check for circular references and return its corresponding clone. @@ -109,11 +109,18 @@ define(['./_Stack', './_arrayEach', './_assignValue', './_baseAssign', './_baseF } stack.set(value, result); + if (!isArr) { + var props = isFull ? getAllKeys(value) : keys(value); + } // Recursively populate clone (susceptible to call stack limits). - (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) { + arrayEach(props || value, function(subValue, key) { + if (props) { + key = subValue; + subValue = value[key]; + } assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack)); }); - return (isFull && !isArr) ? copySymbols(value, result) : result; + return result; } return baseClone; diff --git a/_baseConforms.js b/_baseConforms.js index 23759283f..cd61f2542 100644 --- a/_baseConforms.js +++ b/_baseConforms.js @@ -24,7 +24,8 @@ define(['./keys'], function(keys) { predicate = source[key], value = object[key]; - if ((value === undefined && !(key in Object(object))) || !predicate(value)) { + if ((value === undefined && + !(key in Object(object))) || !predicate(value)) { return false; } } diff --git a/_baseDifference.js b/_baseDifference.js index 51f5ca3a1..b35fe02a9 100644 --- a/_baseDifference.js +++ b/_baseDifference.js @@ -4,8 +4,8 @@ define(['./_SetCache', './_arrayIncludes', './_arrayIncludesWith', './_arrayMap' var LARGE_ARRAY_SIZE = 200; /** - * The base implementation of methods like `_.difference` without support for - * excluding multiple arrays or iteratee shorthands. + * The base implementation of methods like `_.difference` without support + * for excluding multiple arrays or iteratee shorthands. * * @private * @param {Array} array The array to inspect. diff --git a/_baseEvery.js b/_baseEvery.js index 5a5411d18..a4487ae3b 100644 --- a/_baseEvery.js +++ b/_baseEvery.js @@ -6,7 +6,8 @@ define(['./_baseEach'], function(baseEach) { * @private * @param {Array|Object} collection The collection to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false` + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false` */ function baseEvery(collection, predicate) { var result = true; diff --git a/_baseFind.js b/_baseFind.js index b229efce4..805f86fdd 100644 --- a/_baseFind.js +++ b/_baseFind.js @@ -9,7 +9,8 @@ define([], function() { * @param {Array|Object} collection The collection to search. * @param {Function} predicate The function invoked per iteration. * @param {Function} eachFunc The function to iterate over `collection`. - * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself. + * @param {boolean} [retKey] Specify returning the key of the found element + * instead of the element itself. * @returns {*} Returns the found element or its key, else `undefined`. */ function baseFind(collection, predicate, eachFunc, retKey) { diff --git a/_baseFor.js b/_baseFor.js index 41b0d2579..64b1f4d85 100644 --- a/_baseFor.js +++ b/_baseFor.js @@ -1,10 +1,9 @@ define(['./_createBaseFor'], function(createBaseFor) { /** - * The base implementation of `baseForIn` and `baseForOwn` which iterates - * over `object` properties returned by `keysFunc` invoking `iteratee` for - * each property. Iteratee functions may exit iteration early by explicitly - * returning `false`. + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` invoking `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. * * @private * @param {Object} object The object to iterate over. diff --git a/_baseForIn.js b/_baseForIn.js deleted file mode 100644 index 6f2f3a7ae..000000000 --- a/_baseForIn.js +++ /dev/null @@ -1,16 +0,0 @@ -define(['./_baseFor', './keysIn'], function(baseFor, keysIn) { - - /** - * The base implementation of `_.forIn` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. - */ - function baseForIn(object, iteratee) { - return object == null ? object : baseFor(object, iteratee, keysIn); - } - - return baseForIn; -}); diff --git a/_baseGet.js b/_baseGet.js index 78b66a3c4..eb0f1a303 100644 --- a/_baseGet.js +++ b/_baseGet.js @@ -12,7 +12,7 @@ define(['./_baseCastPath', './_isKey'], function(baseCastPath, isKey) { * @returns {*} Returns the resolved value. */ function baseGet(object, path) { - path = isKey(path, object) ? [path + ''] : baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); var index = 0, length = path.length; diff --git a/_baseGetAllKeys.js b/_baseGetAllKeys.js new file mode 100644 index 000000000..73433e567 --- /dev/null +++ b/_baseGetAllKeys.js @@ -0,0 +1,22 @@ +define(['./_arrayPush', './isArray'], function(arrayPush, isArray) { + + /** + * The base implementation of `getAllKeys` and `getAllKeysIn` which uses + * `keysFunc` and `symbolsFunc` to get the enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Function} keysFunc The function to get the keys of `object`. + * @param {Function} symbolsFunc The function to get the symbols of `object`. + * @returns {Array} Returns the array of property names and symbols. + */ + function baseGetAllKeys(object, keysFunc, symbolsFunc) { + var result = keysFunc(object); + return isArray(object) + ? result + : arrayPush(result, symbolsFunc(object)); + } + + return baseGetAllKeys; +}); diff --git a/_baseHas.js b/_baseHas.js index 80fb0a5fb..f03fa4e95 100644 --- a/_baseHas.js +++ b/_baseHas.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./_getPrototype'], function(getPrototype) { /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -6,9 +6,6 @@ define([], function() { /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; - /** Built-in value references. */ - var getPrototypeOf = Object.getPrototypeOf; - /** * The base implementation of `_.has` without support for deep paths. * @@ -22,7 +19,7 @@ define([], function() { // that are composed entirely of index properties, return `false` for // `hasOwnProperty` checks of them. return hasOwnProperty.call(object, key) || - (typeof object == 'object' && key in object && getPrototypeOf(object) === null); + (typeof object == 'object' && key in object && getPrototype(object) === null); } return baseHas; diff --git a/_baseIsEqualDeep.js b/_baseIsEqualDeep.js index ae443886a..2b66ab08d 100644 --- a/_baseIsEqualDeep.js +++ b/_baseIsEqualDeep.js @@ -24,7 +24,8 @@ define(['./_Stack', './_equalArrays', './_equalByTag', './_equalObjects', './_ge * @param {Object} other The other object to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} [customizer] The function to customize comparisons. - * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} [stack] Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ @@ -57,8 +58,11 @@ define(['./_Stack', './_equalArrays', './_equalByTag', './_equalObjects', './_ge othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); if (objIsWrapped || othIsWrapped) { + var objUnwrapped = objIsWrapped ? object.value() : object, + othUnwrapped = othIsWrapped ? other.value() : other; + stack || (stack = new Stack); - return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack); + return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack); } } if (!isSameTag) { diff --git a/_baseIsMatch.js b/_baseIsMatch.js index 5ac2a3414..3f559d973 100644 --- a/_baseIsMatch.js +++ b/_baseIsMatch.js @@ -46,9 +46,10 @@ define(['./_Stack', './_baseIsEqual'], function(Stack, baseIsEqual) { return false; } } else { - var stack = new Stack, - result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined; - + var stack = new Stack; + if (customizer) { + var result = customizer(objValue, srcValue, key, object, source, stack); + } if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result diff --git a/_baseIteratee.js b/_baseIteratee.js index ed461246e..536cb5799 100644 --- a/_baseIteratee.js +++ b/_baseIteratee.js @@ -8,14 +8,15 @@ define(['./_baseMatches', './_baseMatchesProperty', './identity', './isArray', ' * @returns {Function} Returns the iteratee. */ function baseIteratee(value) { - var type = typeof value; - if (type == 'function') { + // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. + // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. + if (typeof value == 'function') { return value; } if (value == null) { return identity; } - if (type == 'object') { + if (typeof value == 'object') { return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value); diff --git a/_baseLodash.js b/_baseLodash.js index e4dfecf22..e3238f3cb 100644 --- a/_baseLodash.js +++ b/_baseLodash.js @@ -1,7 +1,7 @@ define([], function() { /** - * The function whose prototype all chaining wrappers inherit from. + * The function whose prototype chain sequence wrappers inherit from. * * @private */ diff --git a/_baseMean.js b/_baseMean.js new file mode 100644 index 000000000..e4d20a303 --- /dev/null +++ b/_baseMean.js @@ -0,0 +1,21 @@ +define(['./_baseSum'], function(baseSum) { + + /** Used as references for various `Number` constants. */ + var NAN = 0 / 0; + + /** + * The base implementation of `_.mean` and `_.meanBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the mean. + */ + function baseMean(array, iteratee) { + var length = array ? array.length : 0; + return length ? (baseSum(array, iteratee) / length) : NAN; + } + + return baseMean; +}); diff --git a/_baseMerge.js b/_baseMerge.js index c53a5fc08..201dae764 100644 --- a/_baseMerge.js +++ b/_baseMerge.js @@ -11,16 +11,16 @@ define(['./_Stack', './_arrayEach', './_assignMergeValue', './_baseMergeDeep', ' * @param {Object} source The source object. * @param {number} srcIndex The index of `source`. * @param {Function} [customizer] The function to customize merged values. - * @param {Object} [stack] Tracks traversed source values and their merged counterparts. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. */ function baseMerge(object, source, srcIndex, customizer, stack) { if (object === source) { return; } - var props = (isArray(source) || isTypedArray(source)) - ? undefined - : keysIn(source); - + if (!(isArray(source) || isTypedArray(source))) { + var props = keysIn(source); + } arrayEach(props || source, function(srcValue, key) { if (props) { key = srcValue; diff --git a/_baseMergeDeep.js b/_baseMergeDeep.js index 14cebd295..68f61460e 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -15,7 +15,8 @@ define(['./_assignMergeValue', './_baseClone', './_copyArray', './isArguments', * @param {number} srcIndex The index of `source`. * @param {Function} mergeFunc The function to merge values. * @param {Function} [customizer] The function to customize assigned values. - * @param {Object} [stack] Tracks traversed source values and their merged counterparts. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. */ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { var objValue = object[key], @@ -43,7 +44,7 @@ define(['./_assignMergeValue', './_baseClone', './_copyArray', './isArguments', } else { isCommon = false; - newValue = baseClone(srcValue, !customizer); + newValue = baseClone(srcValue, true); } } else if (isPlainObject(srcValue) || isArguments(srcValue)) { @@ -52,7 +53,7 @@ define(['./_assignMergeValue', './_baseClone', './_copyArray', './isArguments', } else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { isCommon = false; - newValue = baseClone(srcValue, !customizer); + newValue = baseClone(srcValue, true); } else { newValue = objValue; diff --git a/_baseOrderBy.js b/_baseOrderBy.js index 804188da5..3d555b236 100644 --- a/_baseOrderBy.js +++ b/_baseOrderBy.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseIteratee', './_baseMap', './_baseSortBy', './_compareMultiple'], function(arrayMap, baseIteratee, baseMap, baseSortBy, compareMultiple) { +define(['./_arrayMap', './_baseIteratee', './_baseMap', './_baseSortBy', './_compareMultiple', './identity'], function(arrayMap, baseIteratee, baseMap, baseSortBy, compareMultiple, identity) { /** * The base implementation of `_.orderBy` without param guards. @@ -11,7 +11,7 @@ define(['./_arrayMap', './_baseIteratee', './_baseMap', './_baseSortBy', './_com */ function baseOrderBy(collection, iteratees, orders) { var index = -1; - iteratees = arrayMap(iteratees.length ? iteratees : Array(1), baseIteratee); + iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseIteratee); var result = baseMap(collection, function(value, key, collection) { var criteria = arrayMap(iteratees, function(iteratee) { diff --git a/_basePick.js b/_basePick.js index 6a2fa1e08..4ad9c8061 100644 --- a/_basePick.js +++ b/_basePick.js @@ -2,11 +2,11 @@ define(['./_arrayReduce'], function(arrayReduce) { /** * The base implementation of `_.pick` without support for individual - * property names. + * property identifiers. * * @private * @param {Object} object The source object. - * @param {string[]} props The property names to pick. + * @param {string[]} props The property identifiers to pick. * @returns {Object} Returns the new object. */ function basePick(object, props) { diff --git a/_basePickBy.js b/_basePickBy.js index ad56917fd..a08b25e34 100644 --- a/_basePickBy.js +++ b/_basePickBy.js @@ -1,4 +1,4 @@ -define(['./_baseForIn'], function(baseForIn) { +define(['./_getAllKeysIn'], function(getAllKeysIn) { /** * The base implementation of `_.pickBy` without support for iteratee shorthands. @@ -9,12 +9,19 @@ define(['./_baseForIn'], function(baseForIn) { * @returns {Object} Returns the new object. */ function basePickBy(object, predicate) { - var result = {}; - baseForIn(object, function(value, key) { + var index = -1, + props = getAllKeysIn(object), + length = props.length, + result = {}; + + while (++index < length) { + var key = props[index], + value = object[key]; + if (predicate(value, key)) { result[key] = value; } - }); + } return result; } diff --git a/_baseReduce.js b/_baseReduce.js index cd82fa0d0..071d11614 100644 --- a/_baseReduce.js +++ b/_baseReduce.js @@ -8,7 +8,8 @@ define([], function() { * @param {Array|Object} collection The collection to iterate over. * @param {Function} iteratee The function invoked per iteration. * @param {*} accumulator The initial value. - * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value. + * @param {boolean} initAccum Specify using the first or last element of + * `collection` as the initial value. * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the accumulated value. */ diff --git a/_baseRepeat.js b/_baseRepeat.js new file mode 100644 index 000000000..34800919b --- /dev/null +++ b/_baseRepeat.js @@ -0,0 +1,38 @@ +define([], function() { + + /** Used as references for various `Number` constants. */ + var MAX_SAFE_INTEGER = 9007199254740991; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeFloor = Math.floor; + + /** + * The base implementation of `_.repeat` which doesn't coerce arguments. + * + * @private + * @param {string} string The string to repeat. + * @param {number} n The number of times to repeat the string. + * @returns {string} Returns the repeated string. + */ + function baseRepeat(string, n) { + var result = ''; + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result; + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string; + } + n = nativeFloor(n / 2); + if (n) { + string += string; + } + } while (n); + + return result; + } + + return baseRepeat; +}); diff --git a/_baseSet.js b/_baseSet.js index 274cb3cbe..5d2d83579 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -14,7 +14,7 @@ define(['./_assignValue', './_baseCastPath', './_isIndex', './_isKey', './isObje * @returns {Object} Returns `object`. */ function baseSet(object, path, value, customizer) { - path = isKey(path, object) ? [path + ''] : baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); var index = -1, length = path.length, diff --git a/_baseSome.js b/_baseSome.js index 9e71766ca..fb7972b52 100644 --- a/_baseSome.js +++ b/_baseSome.js @@ -6,7 +6,8 @@ define(['./_baseEach'], function(baseEach) { * @private * @param {Array|Object} collection The collection to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. */ function baseSome(collection, predicate) { var result; diff --git a/_baseSortedIndexBy.js b/_baseSortedIndexBy.js index babda4ff4..45600db89 100644 --- a/_baseSortedIndexBy.js +++ b/_baseSortedIndexBy.js @@ -21,7 +21,8 @@ define([], function() { * @param {*} value The value to evaluate. * @param {Function} iteratee The iteratee invoked per element. * @param {boolean} [retHighest] Specify returning the highest qualified index. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. */ function baseSortedIndexBy(array, value, iteratee, retHighest) { value = iteratee(value); diff --git a/_baseSum.js b/_baseSum.js index 3448ed335..06ccf6e99 100644 --- a/_baseSum.js +++ b/_baseSum.js @@ -4,7 +4,8 @@ define([], function() { var undefined; /** - * The base implementation of `_.sum` without support for iteratee shorthands. + * The base implementation of `_.sum` and `_.sumBy` without support for + * iteratee shorthands. * * @private * @param {Array} array The array to iterate over. diff --git a/_baseUnset.js b/_baseUnset.js index ff5bbf7a8..ed96fe1d7 100644 --- a/_baseUnset.js +++ b/_baseUnset.js @@ -9,7 +9,7 @@ define(['./_baseCastPath', './has', './_isKey', './last', './_parent'], function * @returns {boolean} Returns `true` if the property is deleted, else `false`. */ function baseUnset(object, path) { - path = isKey(path, object) ? [path + ''] : baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); object = parent(object, path); var key = last(path); return (object != null && has(object, key)) ? delete object[key] : true; diff --git a/_baseZipObject.js b/_baseZipObject.js index 8480283cc..f2c741111 100644 --- a/_baseZipObject.js +++ b/_baseZipObject.js @@ -7,7 +7,7 @@ define([], function() { * This base implementation of `_.zipObject` which assigns values using `assignFunc`. * * @private - * @param {Array} props The property names. + * @param {Array} props The property identifiers. * @param {Array} values The property values. * @param {Function} assignFunc The function to assign values. * @returns {Object} Returns the new object. @@ -19,7 +19,8 @@ define([], function() { result = {}; while (++index < length) { - assignFunc(result, props[index], index < valsLength ? values[index] : undefined); + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); } return result; } diff --git a/_cloneDataView.js b/_cloneDataView.js new file mode 100644 index 000000000..7a018a432 --- /dev/null +++ b/_cloneDataView.js @@ -0,0 +1,17 @@ +define(['./_cloneArrayBuffer'], function(cloneArrayBuffer) { + + /** + * Creates a clone of `dataView`. + * + * @private + * @param {Object} dataView The data view to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned data view. + */ + function cloneDataView(dataView, isDeep) { + var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; + return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); + } + + return cloneDataView; +}); diff --git a/_cloneMap.js b/_cloneMap.js index 8638a9f14..0a258709b 100644 --- a/_cloneMap.js +++ b/_cloneMap.js @@ -5,10 +5,13 @@ define(['./_addMapEntry', './_arrayReduce', './_mapToArray'], function(addMapEnt * * @private * @param {Object} map The map to clone. + * @param {Function} cloneFunc The function to clone values. + * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the cloned map. */ - function cloneMap(map) { - return arrayReduce(mapToArray(map), addMapEntry, new map.constructor); + function cloneMap(map, isDeep, cloneFunc) { + var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map); + return arrayReduce(array, addMapEntry, new map.constructor); } return cloneMap; diff --git a/_cloneSet.js b/_cloneSet.js index e2683300f..f87c6788e 100644 --- a/_cloneSet.js +++ b/_cloneSet.js @@ -5,10 +5,13 @@ define(['./_addSetEntry', './_arrayReduce', './_setToArray'], function(addSetEnt * * @private * @param {Object} set The set to clone. + * @param {Function} cloneFunc The function to clone values. + * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the cloned set. */ - function cloneSet(set) { - return arrayReduce(setToArray(set), addSetEntry, new set.constructor); + function cloneSet(set, isDeep, cloneFunc) { + var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set); + return arrayReduce(array, addSetEntry, new set.constructor); } return cloneSet; diff --git a/_compareMultiple.js b/_compareMultiple.js index 30d838877..28f347141 100644 --- a/_compareMultiple.js +++ b/_compareMultiple.js @@ -37,7 +37,7 @@ define(['./_compareAscending'], function(compareAscending) { // for more details. // // This also ensures a stable sort in V8 and other engines. - // See https://code.google.com/p/v8/issues/detail?id=90 for more details. + // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. return object.index - other.index; } diff --git a/_copyObject.js b/_copyObject.js index 825043a3f..c1bd3dd68 100644 --- a/_copyObject.js +++ b/_copyObject.js @@ -5,7 +5,7 @@ define(['./_copyObjectWith'], function(copyObjectWith) { * * @private * @param {Object} source The object to copy properties from. - * @param {Array} props The property names to copy. + * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. * @returns {Object} Returns `object`. */ diff --git a/_copyObjectWith.js b/_copyObjectWith.js index d1b26d3a9..4cc5123fd 100644 --- a/_copyObjectWith.js +++ b/_copyObjectWith.js @@ -6,7 +6,7 @@ define(['./_assignValue'], function(assignValue) { * * @private * @param {Object} source The object to copy properties from. - * @param {Array} props The property names to copy. + * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. * @param {Function} [customizer] The function to customize copied values. * @returns {Object} Returns `object`. diff --git a/_createBaseFor.js b/_createBaseFor.js index fa545e504..d9358dada 100644 --- a/_createBaseFor.js +++ b/_createBaseFor.js @@ -1,7 +1,7 @@ define([], function() { /** - * Creates a base function for methods like `_.forIn`. + * Creates a base function for methods like `_.forIn` and `_.forOwn`. * * @private * @param {boolean} [fromRight] Specify iterating from right to left. diff --git a/_createBaseWrapper.js b/_createBaseWrapper.js index 909ee5d27..54656fedf 100644 --- a/_createBaseWrapper.js +++ b/_createBaseWrapper.js @@ -9,7 +9,8 @@ define(['./_createCtorWrapper', './_root'], function(createCtorWrapper, root) { * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {*} [thisArg] The `this` binding of `func`. * @returns {Function} Returns the new wrapped function. */ diff --git a/_createCurryWrapper.js b/_createCurryWrapper.js index dea871ef6..8a5f4bff4 100644 --- a/_createCurryWrapper.js +++ b/_createCurryWrapper.js @@ -8,7 +8,8 @@ define(['./_apply', './_createCtorWrapper', './_createHybridWrapper', './_create * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {number} arity The arity of `func`. * @returns {Function} Returns the new wrapped function. */ diff --git a/_createFlow.js b/_createFlow.js index 36ecc971f..cd35fcab9 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -55,7 +55,9 @@ define(['./_LodashWrapper', './_baseFlatten', './_getData', './_getFuncName', '. ) { wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); } else { - wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); + wrapper = (func.length == 1 && isLaziable(func)) + ? wrapper[funcName]() + : wrapper.thru(func); } } return function() { diff --git a/_createHybridWrapper.js b/_createHybridWrapper.js index 84b01f340..fb875e17d 100644 --- a/_createHybridWrapper.js +++ b/_createHybridWrapper.js @@ -17,11 +17,14 @@ define(['./_composeArgs', './_composeArgsRight', './_countHolders', './_createCt * * @private * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to prepend to those provided to the new function. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. * @param {Array} [holders] The `partials` placeholder indexes. - * @param {Array} [partialsRight] The arguments to append to those provided to the new function. + * @param {Array} [partialsRight] The arguments to append to those provided + * to the new function. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. * @param {Array} [argPos] The argument positions of the new function. * @param {number} [ary] The arity cap of `func`. diff --git a/_createMathOperation.js b/_createMathOperation.js new file mode 100644 index 000000000..43adc37a9 --- /dev/null +++ b/_createMathOperation.js @@ -0,0 +1,30 @@ +define([], function() { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * Creates a function that performs a mathematical operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @returns {Function} Returns the new mathematical operation function. + */ + function createMathOperation(operator) { + return function(value, other) { + var result; + if (value === undefined && other === undefined) { + return 0; + } + if (value !== undefined) { + result = value; + } + if (other !== undefined) { + result = result === undefined ? other : operator(result, other); + } + return result; + }; + } + + return createMathOperation; +}); diff --git a/_createPadding.js b/_createPadding.js index a8b21ef70..fcd788422 100644 --- a/_createPadding.js +++ b/_createPadding.js @@ -1,4 +1,4 @@ -define(['./repeat', './_stringSize', './_stringToArray', './toInteger'], function(repeat, stringSize, stringToArray, toInteger) { +define(['./_baseRepeat', './_stringSize', './_stringToArray'], function(baseRepeat, stringSize, stringToArray) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -23,25 +23,21 @@ define(['./repeat', './_stringSize', './_stringToArray', './toInteger'], functio * is truncated if the number of characters exceeds `length`. * * @private - * @param {string} string The string to create padding for. - * @param {number} [length=0] The padding length. + * @param {number} length The padding length. * @param {string} [chars=' '] The string used as padding. * @returns {string} Returns the padding for `string`. */ - function createPadding(string, length, chars) { - length = toInteger(length); - - var strLength = stringSize(string); - if (!length || strLength >= length) { - return ''; - } - var padLength = length - strLength; + function createPadding(length, chars) { chars = chars === undefined ? ' ' : (chars + ''); - var result = repeat(chars, nativeCeil(padLength / stringSize(chars))); + var charsLength = chars.length; + if (charsLength < 2) { + return charsLength ? baseRepeat(chars, length) : chars; + } + var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); return reHasComplexSymbol.test(chars) - ? stringToArray(result).slice(0, padLength).join('') - : result.slice(0, padLength); + ? stringToArray(result).slice(0, length).join('') + : result.slice(0, length); } return createPadding; diff --git a/_createPartialWrapper.js b/_createPartialWrapper.js index dcccbe2f5..b3f1d9762 100644 --- a/_createPartialWrapper.js +++ b/_createPartialWrapper.js @@ -10,9 +10,11 @@ define(['./_apply', './_createCtorWrapper', './_root'], function(apply, createCt * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {*} thisArg The `this` binding of `func`. - * @param {Array} partials The arguments to prepend to those provided to the new function. + * @param {Array} partials The arguments to prepend to those provided to + * the new function. * @returns {Function} Returns the new wrapped function. */ function createPartialWrapper(func, bitmask, thisArg, partials) { diff --git a/_createRecurryWrapper.js b/_createRecurryWrapper.js index b6bc26a86..1d8ab99cb 100644 --- a/_createRecurryWrapper.js +++ b/_createRecurryWrapper.js @@ -16,11 +16,13 @@ define(['./_copyArray', './_isLaziable', './_setData'], function(copyArray, isLa * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {Function} wrapFunc The function to create the `func` wrapper. * @param {*} placeholder The placeholder value. * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to prepend to those provided to the new function. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. * @param {Array} [holders] The `partials` placeholder indexes. * @param {Array} [argPos] The argument positions of the new function. * @param {number} [ary] The arity cap of `func`. diff --git a/_equalArrays.js b/_equalArrays.js index f890cc287..69905d64c 100644 --- a/_equalArrays.js +++ b/_equalArrays.js @@ -16,7 +16,8 @@ define(['./_arraySome'], function(arraySome) { * @param {Array} other The other array to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} stack Tracks traversed `array` and `other` objects. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. */ @@ -58,12 +59,16 @@ define(['./_arraySome'], function(arraySome) { // Recursively compare arrays (susceptible to call stack limits). if (isUnordered) { if (!arraySome(other, function(othValue) { - return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack); + return arrValue === othValue || + equalFunc(arrValue, othValue, customizer, bitmask, stack); })) { result = false; break; } - } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) { + } else if (!( + arrValue === othValue || + equalFunc(arrValue, othValue, customizer, bitmask, stack) + )) { result = false; break; } diff --git a/_equalByTag.js b/_equalByTag.js index f8ef3c203..66a8834d1 100644 --- a/_equalByTag.js +++ b/_equalByTag.js @@ -18,7 +18,8 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set stringTag = '[object String]', symbolTag = '[object Symbol]'; - var arrayBufferTag = '[object ArrayBuffer]'; + var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]'; /** Used to convert symbols to primitives and strings. */ var symbolProto = Symbol ? Symbol.prototype : undefined, @@ -37,12 +38,21 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set * @param {string} tag The `toStringTag` of the objects to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} stack Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { switch (tag) { + case dataViewTag: + if ((object.byteLength != other.byteLength) || + (object.byteOffset != other.byteOffset)) { + return false; + } + object = object.buffer; + other = other.buffer; + case arrayBufferTag: if ((object.byteLength != other.byteLength) || !equalFunc(new Uint8Array(object), new Uint8Array(other))) { @@ -52,8 +62,9 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set case boolTag: case dateTag: - // Coerce dates and booleans to numbers, dates to milliseconds and booleans - // to `1` or `0` treating invalid dates coerced to `NaN` as not equal. + // Coerce dates and booleans to numbers, dates to milliseconds and + // booleans to `1` or `0` treating invalid dates coerced to `NaN` as + // not equal. return +object == +other; case errorTag: @@ -65,8 +76,8 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set case regexpTag: case stringTag: - // Coerce regexes to strings and treat strings primitives and string - // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details. + // Coerce regexes to strings and treat strings, primitives and objects, + // as equal. See https://es5.github.io/#x15.10.6.4 for more details. return object == (other + ''); case mapTag: @@ -84,8 +95,11 @@ define(['./_Symbol', './_Uint8Array', './_equalArrays', './_mapToArray', './_set if (stacked) { return stacked == other; } + bitmask |= UNORDERED_COMPARE_FLAG; + stack.set(object, other); + // Recursively compare objects (susceptible to call stack limits). - return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask | UNORDERED_COMPARE_FLAG, stack.set(object, other)); + return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); case symbolTag: if (symbolValueOf) { diff --git a/_equalObjects.js b/_equalObjects.js index 79d224d5c..a18e4b9e4 100644 --- a/_equalObjects.js +++ b/_equalObjects.js @@ -15,7 +15,8 @@ define(['./_baseHas', './keys'], function(baseHas, keys) { * @param {Object} other The other object to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} stack Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ diff --git a/_getAllKeys.js b/_getAllKeys.js new file mode 100644 index 000000000..461075ae0 --- /dev/null +++ b/_getAllKeys.js @@ -0,0 +1,15 @@ +define(['./_baseGetAllKeys', './_getSymbols', './keys'], function(baseGetAllKeys, getSymbols, keys) { + + /** + * Creates an array of own enumerable property names and symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeys(object) { + return baseGetAllKeys(object, keys, getSymbols); + } + + return getAllKeys; +}); diff --git a/_getAllKeysIn.js b/_getAllKeysIn.js new file mode 100644 index 000000000..16f47482f --- /dev/null +++ b/_getAllKeysIn.js @@ -0,0 +1,16 @@ +define(['./_baseGetAllKeys', './_getSymbolsIn', './keysIn'], function(baseGetAllKeys, getSymbolsIn, keysIn) { + + /** + * Creates an array of own and inherited enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeysIn(object) { + return baseGetAllKeys(object, keysIn, getSymbolsIn); + } + + return getAllKeysIn; +}); diff --git a/_getLength.js b/_getLength.js index 86ad66a1e..d59b46856 100644 --- a/_getLength.js +++ b/_getLength.js @@ -3,8 +3,9 @@ define(['./_baseProperty'], function(baseProperty) { /** * Gets the "length" property value of `object`. * - * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) - * that affects Safari on at least iOS 8.1-8.3 ARM64. + * **Note:** This function is used to avoid a + * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects + * Safari on at least iOS 8.1-8.3 ARM64. * * @private * @param {Object} object The object to query. diff --git a/_getPrototype.js b/_getPrototype.js new file mode 100644 index 000000000..e3b18ace8 --- /dev/null +++ b/_getPrototype.js @@ -0,0 +1,18 @@ +define([], function() { + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeGetPrototype = Object.getPrototypeOf; + + /** + * Gets the `[[Prototype]]` of `value`. + * + * @private + * @param {*} value The value to query. + * @returns {null|Object} Returns the `[[Prototype]]`. + */ + function getPrototype(value) { + return nativeGetPrototype(Object(value)); + } + + return getPrototype; +}); diff --git a/_getSymbols.js b/_getSymbols.js index bb47d7147..0cabe48ac 100644 --- a/_getSymbols.js +++ b/_getSymbols.js @@ -4,15 +4,24 @@ define([], function() { var getOwnPropertySymbols = Object.getOwnPropertySymbols; /** - * Creates an array of the own symbol properties of `object`. + * Creates an array of the own enumerable symbol properties of `object`. * * @private * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ - var getSymbols = getOwnPropertySymbols || function() { - return []; - }; + function getSymbols(object) { + // Coerce `object` to an object to avoid non-object errors in V8. + // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details. + return getOwnPropertySymbols(Object(object)); + } + + // Fallback for IE < 11. + if (!getOwnPropertySymbols) { + getSymbols = function() { + return []; + }; + } return getSymbols; }); diff --git a/_getSymbolsIn.js b/_getSymbolsIn.js new file mode 100644 index 000000000..a0bba888e --- /dev/null +++ b/_getSymbolsIn.js @@ -0,0 +1,24 @@ +define(['./_arrayPush', './_getPrototype', './_getSymbols'], function(arrayPush, getPrototype, getSymbols) { + + /** Built-in value references. */ + var getOwnPropertySymbols = Object.getOwnPropertySymbols; + + /** + * Creates an array of the own and inherited enumerable symbol properties + * of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ + var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) { + var result = []; + while (object) { + arrayPush(result, getSymbols(object)); + object = getPrototype(object); + } + return result; + }; + + return getSymbolsIn; +}); diff --git a/_getTag.js b/_getTag.js index 35336f592..734b2e1cc 100644 --- a/_getTag.js +++ b/_getTag.js @@ -1,11 +1,14 @@ -define(['./_Map', './_Set', './_WeakMap'], function(Map, Set, WeakMap) { +define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap'], function(DataView, Map, Promise, Set, WeakMap) { /** `Object#toString` result references. */ var mapTag = '[object Map]', objectTag = '[object Object]', + promiseTag = '[object Promise]', setTag = '[object Set]', weakMapTag = '[object WeakMap]'; + var dataViewTag = '[object DataView]'; + /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -19,7 +22,9 @@ define(['./_Map', './_Set', './_WeakMap'], function(Map, Set, WeakMap) { var objectToString = objectProto.toString; /** Used to detect maps, sets, and weakmaps. */ - var mapCtorString = Map ? funcToString.call(Map) : '', + var dataViewCtorString = DataView ? (DataView + '') : '', + mapCtorString = Map ? funcToString.call(Map) : '', + promiseCtorString = Promise ? funcToString.call(Promise) : '', setCtorString = Set ? funcToString.call(Set) : '', weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : ''; @@ -34,8 +39,11 @@ define(['./_Map', './_Set', './_WeakMap'], function(Map, Set, WeakMap) { return objectToString.call(value); } - // Fallback for IE 11 providing `toStringTag` values for maps, sets, and weakmaps. - if ((Map && getTag(new Map) != mapTag) || + // Fallback for data views, maps, sets, and weak maps in IE 11, + // for data views in Edge, and promises in Node.js. + if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || + (Map && getTag(new Map) != mapTag) || + (Promise && getTag(Promise.resolve()) != promiseTag) || (Set && getTag(new Set) != setTag) || (WeakMap && getTag(new WeakMap) != weakMapTag)) { getTag = function(value) { @@ -45,7 +53,9 @@ define(['./_Map', './_Set', './_WeakMap'], function(Map, Set, WeakMap) { if (ctorString) { switch (ctorString) { + case dataViewCtorString: return dataViewTag; case mapCtorString: return mapTag; + case promiseCtorString: return promiseTag; case setCtorString: return setTag; case weakMapCtorString: return weakMapTag; } diff --git a/_hasPath.js b/_hasPath.js index 7174a5687..df0354391 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,4 +1,4 @@ -define(['./_baseCastPath', './isArguments', './isArray', './_isIndex', './_isKey', './isLength', './isString', './last', './_parent'], function(baseCastPath, isArguments, isArray, isIndex, isKey, isLength, isString, last, parent) { +define(['./_baseCastPath', './isArguments', './isArray', './_isIndex', './_isKey', './isLength', './isString'], function(baseCastPath, isArguments, isArray, isIndex, isKey, isLength, isString) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -19,10 +19,16 @@ define(['./_baseCastPath', './isArguments', './isArray', './_isIndex', './_isKey var result = hasFunc(object, path); if (!result && !isKey(path)) { path = baseCastPath(path); - object = parent(object, path); - if (object != null) { - path = last(path); - result = hasFunc(object, path); + + var index = -1, + length = path.length; + + while (object != null && ++index < length) { + var key = path[index]; + if (!(result = hasFunc(object, key))) { + break; + } + object = object[key]; } } var length = object ? object.length : undefined; diff --git a/_initCloneByTag.js b/_initCloneByTag.js index d81ee8152..474cd8d4f 100644 --- a/_initCloneByTag.js +++ b/_initCloneByTag.js @@ -1,4 +1,4 @@ -define(['./_cloneArrayBuffer', './_cloneMap', './_cloneRegExp', './_cloneSet', './_cloneSymbol', './_cloneTypedArray'], function(cloneArrayBuffer, cloneMap, cloneRegExp, cloneSet, cloneSymbol, cloneTypedArray) { +define(['./_cloneArrayBuffer', './_cloneDataView', './_cloneMap', './_cloneRegExp', './_cloneSet', './_cloneSymbol', './_cloneTypedArray'], function(cloneArrayBuffer, cloneDataView, cloneMap, cloneRegExp, cloneSet, cloneSymbol, cloneTypedArray) { /** `Object#toString` result references. */ var boolTag = '[object Boolean]', @@ -11,6 +11,7 @@ define(['./_cloneArrayBuffer', './_cloneMap', './_cloneRegExp', './_cloneSet', ' symbolTag = '[object Symbol]'; var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', float32Tag = '[object Float32Array]', float64Tag = '[object Float64Array]', int8Tag = '[object Int8Array]', @@ -30,10 +31,11 @@ define(['./_cloneArrayBuffer', './_cloneMap', './_cloneRegExp', './_cloneSet', ' * @private * @param {Object} object The object to clone. * @param {string} tag The `toStringTag` of the object to clone. + * @param {Function} cloneFunc The function to clone values. * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the initialized clone. */ - function initCloneByTag(object, tag, isDeep) { + function initCloneByTag(object, tag, cloneFunc, isDeep) { var Ctor = object.constructor; switch (tag) { case arrayBufferTag: @@ -43,13 +45,16 @@ define(['./_cloneArrayBuffer', './_cloneMap', './_cloneRegExp', './_cloneSet', ' case dateTag: return new Ctor(+object); + case dataViewTag: + return cloneDataView(object, isDeep); + case float32Tag: case float64Tag: case int8Tag: case int16Tag: case int32Tag: case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: return cloneTypedArray(object, isDeep); case mapTag: - return cloneMap(object); + return cloneMap(object, isDeep, cloneFunc); case numberTag: case stringTag: @@ -59,7 +64,7 @@ define(['./_cloneArrayBuffer', './_cloneMap', './_cloneRegExp', './_cloneSet', ' return cloneRegExp(object); case setTag: - return cloneSet(object); + return cloneSet(object, isDeep, cloneFunc); case symbolTag: return cloneSymbol(object); diff --git a/_initCloneObject.js b/_initCloneObject.js index b9d839b50..ac3ede90d 100644 --- a/_initCloneObject.js +++ b/_initCloneObject.js @@ -1,7 +1,4 @@ -define(['./_baseCreate', './_isPrototype'], function(baseCreate, isPrototype) { - - /** Built-in value references. */ - var getPrototypeOf = Object.getPrototypeOf; +define(['./_baseCreate', './_getPrototype', './_isPrototype'], function(baseCreate, getPrototype, isPrototype) { /** * Initializes an object clone. @@ -12,7 +9,7 @@ define(['./_baseCreate', './_isPrototype'], function(baseCreate, isPrototype) { */ function initCloneObject(object) { return (typeof object.constructor == 'function' && !isPrototype(object)) - ? baseCreate(getPrototypeOf(object)) + ? baseCreate(getPrototype(object)) : {}; } diff --git a/_isIterateeCall.js b/_isIterateeCall.js index 4aedaef0d..6d0240e7a 100644 --- a/_isIterateeCall.js +++ b/_isIterateeCall.js @@ -7,7 +7,8 @@ define(['./eq', './isArrayLike', './_isIndex', './isObject'], function(eq, isArr * @param {*} value The potential iteratee value argument. * @param {*} index The potential iteratee index or key argument. * @param {*} object The potential iteratee object argument. - * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. */ function isIterateeCall(value, index, object) { if (!isObject(object)) { @@ -15,8 +16,9 @@ define(['./eq', './isArrayLike', './_isIndex', './isObject'], function(eq, isArr } var type = typeof index; if (type == 'number' - ? (isArrayLike(object) && isIndex(index, object.length)) - : (type == 'string' && index in object)) { + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { return eq(object[index], value); } return false; diff --git a/_isKey.js b/_isKey.js index 4536fb50c..2f45c3ca0 100644 --- a/_isKey.js +++ b/_isKey.js @@ -1,4 +1,4 @@ -define(['./isArray'], function(isArray) { +define(['./isArray', './isSymbol'], function(isArray, isSymbol) { /** Used to match property names within property paths. */ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, @@ -13,11 +13,12 @@ define(['./isArray'], function(isArray) { * @returns {boolean} Returns `true` if `value` is a property name, else `false`. */ function isKey(value, object) { - if (typeof value == 'number') { + var type = typeof value; + if (type == 'number' || type == 'symbol') { return true; } return !isArray(value) && - (reIsPlainProp.test(value) || !reIsDeepProp.test(value) || + (isSymbol(value) || reIsPlainProp.test(value) || !reIsDeepProp.test(value) || (object != null && value in Object(object))); } diff --git a/_isLaziable.js b/_isLaziable.js index 6ed983cee..a214922d6 100644 --- a/_isLaziable.js +++ b/_isLaziable.js @@ -5,7 +5,8 @@ define(['./_LazyWrapper', './_getData', './_getFuncName', './wrapperLodash'], fu * * @private * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`. + * @returns {boolean} Returns `true` if `func` has a lazy counterpart, + * else `false`. */ function isLaziable(func) { var funcName = getFuncName(func), diff --git a/_mapSet.js b/_mapSet.js index d4451186a..4f78c873d 100644 --- a/_mapSet.js +++ b/_mapSet.js @@ -8,7 +8,7 @@ define(['./_Map', './_assocSet', './_hashSet', './_isKeyable'], function(Map, as * @memberOf MapCache * @param {string} key The key of the value to set. * @param {*} value The value to set. - * @returns {Object} Returns the map cache object. + * @returns {Object} Returns the map cache instance. */ function mapSet(key, value) { var data = this.__data__; diff --git a/_mergeData.js b/_mergeData.js index ed4f5e93a..68c98d9c0 100644 --- a/_mergeData.js +++ b/_mergeData.js @@ -19,10 +19,11 @@ define(['./_composeArgs', './_composeArgsRight', './_copyArray', './_replaceHold * * Merging metadata reduces the number of wrappers used to invoke a function. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` - * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg` - * modify function arguments, making the order in which they are executed important, - * preventing the merging of metadata. However, we make an exception for a safe - * combined case where curried functions have `_.ary` and or `_.rearg` applied. + * may be applied regardless of execution order. Methods like `_.ary` and + * `_.rearg` modify function arguments, making the order in which they are + * executed important, preventing the merging of metadata. However, we make + * an exception for a safe combined case where curried functions have `_.ary` + * and or `_.rearg` applied. * * @private * @param {Array} data The destination metadata. diff --git a/_mergeDefaults.js b/_mergeDefaults.js index 9929cb288..172c3dbce 100644 --- a/_mergeDefaults.js +++ b/_mergeDefaults.js @@ -12,7 +12,8 @@ define(['./_baseMerge', './isObject'], function(baseMerge, isObject) { * @param {string} key The key of the property to merge. * @param {Object} object The parent object of `objValue`. * @param {Object} source The parent object of `srcValue`. - * @param {Object} [stack] Tracks traversed source values and their merged counterparts. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. * @returns {*} Returns the value to assign. */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { diff --git a/_parent.js b/_parent.js index 83cea9dfc..6155c060b 100644 --- a/_parent.js +++ b/_parent.js @@ -1,4 +1,4 @@ -define(['./_baseSlice', './get'], function(baseSlice, get) { +define(['./_baseGet', './_baseSlice'], function(baseGet, baseSlice) { /** * Gets the parent value at `path` of `object`. @@ -9,7 +9,7 @@ define(['./_baseSlice', './get'], function(baseSlice, get) { * @returns {*} Returns the parent value. */ function parent(object, path) { - return path.length == 1 ? object : get(object, baseSlice(path, 0, -1)); + return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); } return parent; diff --git a/_setData.js b/_setData.js index c17fefe10..fe6d75317 100644 --- a/_setData.js +++ b/_setData.js @@ -8,8 +8,9 @@ define(['./_baseSetData', './now'], function(baseSetData, now) { * Sets metadata for `func`. * * **Note:** If this function becomes hot, i.e. is invoked a lot in a short - * period of time, it will trip its breaker and transition to an identity function - * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070) + * period of time, it will trip its breaker and transition to an identity + * function to avoid garbage collection pauses in V8. See + * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) * for more details. * * @private diff --git a/_stackSet.js b/_stackSet.js index 9119e004f..af95bbd0b 100644 --- a/_stackSet.js +++ b/_stackSet.js @@ -11,7 +11,7 @@ define(['./_MapCache', './_assocSet'], function(MapCache, assocSet) { * @memberOf Stack * @param {string} key The key of the value to set. * @param {*} value The value to set. - * @returns {Object} Returns the stack cache object. + * @returns {Object} Returns the stack cache instance. */ function stackSet(key, value) { var data = this.__data__, diff --git a/_stringToPath.js b/_stringToPath.js index 356635e24..55ecd1759 100644 --- a/_stringToPath.js +++ b/_stringToPath.js @@ -1,4 +1,4 @@ -define(['./toString'], function(toString) { +define(['./memoize', './toString'], function(memoize, toString) { /** Used to match property names within property paths. */ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g; @@ -13,13 +13,13 @@ define(['./toString'], function(toString) { * @param {string} string The string to convert. * @returns {Array} Returns the property path array. */ - function stringToPath(string) { + var stringToPath = memoize(function(string) { var result = []; toString(string).replace(rePropName, function(match, number, quote, string) { result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); }); return result; - } + }); return stringToPath; }); diff --git a/add.js b/add.js index 82f145a58..c9a8930dc 100644 --- a/add.js +++ b/add.js @@ -1,13 +1,11 @@ -define([], function() { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_createMathOperation'], function(createMathOperation) { /** * Adds two numbers. * * @static * @memberOf _ + * @since 3.4.0 * @category Math * @param {number} augend The first number in an addition. * @param {number} addend The second number in an addition. @@ -17,19 +15,9 @@ define([], function() { * _.add(6, 4); * // => 10 */ - function add(augend, addend) { - var result; - if (augend === undefined && addend === undefined) { - return 0; - } - if (augend !== undefined) { - result = augend; - } - if (addend !== undefined) { - result = result === undefined ? addend : (result + addend); - } - return result; - } + var add = createMathOperation(function(augend, addend) { + return augend + addend; + }); return add; }); diff --git a/after.js b/after.js index f6ac517c1..1a0ce6bf6 100644 --- a/after.js +++ b/after.js @@ -9,6 +9,7 @@ define(['./toInteger'], function(toInteger) { * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {number} n The number of calls before `func` is invoked. * @param {Function} func The function to restrict. @@ -24,7 +25,7 @@ define(['./toInteger'], function(toInteger) { * _.forEach(saves, function(type) { * asyncSave({ 'type': type, 'complete': done }); * }); - * // => logs 'done saving!' after the two async saves have completed + * // => Logs 'done saving!' after the two async saves have completed. */ function after(n, func) { if (typeof func != 'function') { diff --git a/ary.js b/ary.js index 9b85fe2c7..a7a7ca768 100644 --- a/ary.js +++ b/ary.js @@ -12,10 +12,11 @@ define(['./_createWrapper'], function(createWrapper) { * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} func The function to cap arguments for. * @param {number} [n=func.length] The arity cap. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the new function. * @example * diff --git a/assign.js b/assign.js index 30b69a0ac..6d5e5e935 100644 --- a/assign.js +++ b/assign.js @@ -13,15 +13,16 @@ define(['./_assignValue', './_copyObject', './_createAssigner', './isArrayLike', var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); /** - * Assigns own enumerable properties of source objects to the destination - * object. Source objects are applied from left to right. Subsequent sources - * overwrite property assignments of previous sources. + * Assigns own enumerable string keyed properties of source objects to the + * destination object. Source objects are applied from left to right. + * Subsequent sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object` and is loosely based on * [`Object.assign`](https://mdn.io/Object/assign). * * @static * @memberOf _ + * @since 0.10.0 * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. diff --git a/assignIn.js b/assignIn.js index f948e03b6..2a6986d4a 100644 --- a/assignIn.js +++ b/assignIn.js @@ -17,6 +17,7 @@ define(['./_assignValue', './_copyObject', './_createAssigner', './isArrayLike', * * @static * @memberOf _ + * @since 4.0.0 * @alias extend * @category Object * @param {Object} object The destination object. diff --git a/assignInWith.js b/assignInWith.js index 9a10c99f1..7ad9d0c0d 100644 --- a/assignInWith.js +++ b/assignInWith.js @@ -1,15 +1,16 @@ define(['./_copyObjectWith', './_createAssigner', './keysIn'], function(copyObjectWith, createAssigner, keysIn) { /** - * This method is like `_.assignIn` except that it accepts `customizer` which - * is invoked to produce the assigned values. If `customizer` returns `undefined` - * assignment is handled by the method instead. The `customizer` is invoked - * with five arguments: (objValue, srcValue, key, object, source). + * This method is like `_.assignIn` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined` assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). * * **Note:** This method mutates `object`. * * @static * @memberOf _ + * @since 4.0.0 * @alias extendWith * @category Object * @param {Object} object The destination object. diff --git a/assignWith.js b/assignWith.js index d27b26a53..8cf2170a1 100644 --- a/assignWith.js +++ b/assignWith.js @@ -1,15 +1,16 @@ define(['./_copyObjectWith', './_createAssigner', './keys'], function(copyObjectWith, createAssigner, keys) { /** - * This method is like `_.assign` except that it accepts `customizer` which - * is invoked to produce the assigned values. If `customizer` returns `undefined` - * assignment is handled by the method instead. The `customizer` is invoked - * with five arguments: (objValue, srcValue, key, object, source). + * This method is like `_.assign` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined` assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). * * **Note:** This method mutates `object`. * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The destination object. * @param {...Object} sources The source objects. diff --git a/at.js b/at.js index 8a9c7664e..25d98085e 100644 --- a/at.js +++ b/at.js @@ -5,6 +5,7 @@ define(['./_baseAt', './_baseFlatten', './rest'], function(baseAt, baseFlatten, * * @static * @memberOf _ + * @since 1.0.0 * @category Object * @param {Object} object The object to iterate over. * @param {...(string|string[])} [paths] The property paths of elements to pick, diff --git a/attempt.js b/attempt.js index 737f47881..3a4cc8fe0 100644 --- a/attempt.js +++ b/attempt.js @@ -9,8 +9,10 @@ define(['./_apply', './isError', './rest'], function(apply, isError, rest) { * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {Function} func The function to attempt. + * @param {...*} [args] The arguments to invoke `func` with. * @returns {*} Returns the `func` result or error object. * @example * diff --git a/before.js b/before.js index 5dcb29c3c..7adb1412b 100644 --- a/before.js +++ b/before.js @@ -13,6 +13,7 @@ define(['./toInteger'], function(toInteger) { * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {number} n The number of calls at which `func` is no longer invoked. * @param {Function} func The function to restrict. diff --git a/bind.js b/bind.js index 0f5eecdbb..47081975f 100644 --- a/bind.js +++ b/bind.js @@ -17,6 +17,7 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to bind. * @param {*} thisArg The `this` binding of `func`. diff --git a/bindAll.js b/bindAll.js index 975b069bb..8688e1b5b 100644 --- a/bindAll.js +++ b/bindAll.js @@ -7,6 +7,7 @@ define(['./_arrayEach', './_baseFlatten', './bind', './rest'], function(arrayEac * **Note:** This method doesn't set the "length" property of bound functions. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {Object} object The object to bind and assign the bound methods to. @@ -24,7 +25,7 @@ define(['./_arrayEach', './_baseFlatten', './bind', './rest'], function(arrayEac * * _.bindAll(view, 'onClick'); * jQuery(element).on('click', view.onClick); - * // => logs 'clicked docs' when clicked + * // => Logs 'clicked docs' when clicked. */ var bindAll = rest(function(object, methodNames) { arrayEach(baseFlatten(methodNames, 1), function(key) { diff --git a/bindKey.js b/bindKey.js index d65175cb8..2b0fb4570 100644 --- a/bindKey.js +++ b/bindKey.js @@ -10,8 +10,8 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], * any additional `_.bindKey` arguments to those provided to the bound function. * * This method differs from `_.bind` by allowing bound functions to reference - * methods that may be redefined or don't yet exist. - * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) + * methods that may be redefined or don't yet exist. See + * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) * for more details. * * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic @@ -19,6 +19,7 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], * * @static * @memberOf _ + * @since 0.10.0 * @category Function * @param {Object} object The object to invoke the method on. * @param {string} key The key of the method. diff --git a/camelCase.js b/camelCase.js index b06b737e2..fb2704df9 100644 --- a/camelCase.js +++ b/camelCase.js @@ -5,6 +5,7 @@ define(['./capitalize', './_createCompounder'], function(capitalize, createCompo * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the camel cased string. @@ -13,10 +14,10 @@ define(['./capitalize', './_createCompounder'], function(capitalize, createCompo * _.camelCase('Foo Bar'); * // => 'fooBar' * - * _.camelCase('--foo-bar'); + * _.camelCase('--foo-bar--'); * // => 'fooBar' * - * _.camelCase('__foo_bar__'); + * _.camelCase('__FOO_BAR__'); * // => 'fooBar' */ var camelCase = createCompounder(function(result, word, index) { diff --git a/capitalize.js b/capitalize.js index 0b0b5f24f..99e1f5e40 100644 --- a/capitalize.js +++ b/capitalize.js @@ -6,6 +6,7 @@ define(['./toString', './upperFirst'], function(toString, upperFirst) { * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to capitalize. * @returns {string} Returns the capitalized string. diff --git a/castArray.js b/castArray.js index aa34bbe69..d98e8c1dd 100644 --- a/castArray.js +++ b/castArray.js @@ -5,6 +5,7 @@ define(['./isArray'], function(isArray) { * * @static * @memberOf _ + * @since 4.4.0 * @category Lang * @param {*} value The value to inspect. * @returns {Array} Returns the cast array. diff --git a/ceil.js b/ceil.js index 098cac0c6..3a3b868a6 100644 --- a/ceil.js +++ b/ceil.js @@ -5,6 +5,7 @@ define(['./_createRound'], function(createRound) { * * @static * @memberOf _ + * @since 3.10.0 * @category Math * @param {number} number The number to round up. * @param {number} [precision=0] The precision to round up to. diff --git a/chain.js b/chain.js index 465a93051..0ae77a63e 100644 --- a/chain.js +++ b/chain.js @@ -1,11 +1,13 @@ define(['./wrapperLodash'], function(lodash) { /** - * Creates a `lodash` object that wraps `value` with explicit method chaining enabled. - * The result of such method chaining must be unwrapped with `_#value`. + * Creates a `lodash` wrapper instance that wraps `value` with explicit method + * chain sequences enabled. The result of such sequences must be unwrapped + * with `_#value`. * * @static * @memberOf _ + * @since 1.3.0 * @category Seq * @param {*} value The value to wrap. * @returns {Object} Returns the new `lodash` wrapper instance. diff --git a/chunk.js b/chunk.js index 3aa2efe1c..85f2c7ef3 100644 --- a/chunk.js +++ b/chunk.js @@ -11,6 +11,7 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to process. * @param {number} [size=0] The length of each chunk. diff --git a/clamp.js b/clamp.js index 4bdcb6660..54963592a 100644 --- a/clamp.js +++ b/clamp.js @@ -8,6 +8,7 @@ define(['./_baseClamp', './toNumber'], function(baseClamp, toNumber) { * * @static * @memberOf _ + * @since 4.0.0 * @category Number * @param {number} number The number to clamp. * @param {number} [lower] The lower bound. diff --git a/clone.js b/clone.js index 79aa2e1a1..a0efe3a58 100644 --- a/clone.js +++ b/clone.js @@ -13,6 +13,7 @@ define(['./_baseClone'], function(baseClone) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to clone. * @returns {*} Returns the cloned value. diff --git a/cloneDeep.js b/cloneDeep.js index 649b9e02f..b693fd57c 100644 --- a/cloneDeep.js +++ b/cloneDeep.js @@ -5,6 +5,7 @@ define(['./_baseClone'], function(baseClone) { * * @static * @memberOf _ + * @since 1.0.0 * @category Lang * @param {*} value The value to recursively clone. * @returns {*} Returns the deep cloned value. diff --git a/cloneDeepWith.js b/cloneDeepWith.js index a1cf71056..ba5ed4a50 100644 --- a/cloneDeepWith.js +++ b/cloneDeepWith.js @@ -5,6 +5,7 @@ define(['./_baseClone'], function(baseClone) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to recursively clone. * @param {Function} [customizer] The function to customize cloning. diff --git a/cloneWith.js b/cloneWith.js index 1ebc3df4f..512869e85 100644 --- a/cloneWith.js +++ b/cloneWith.js @@ -8,6 +8,7 @@ define(['./_baseClone'], function(baseClone) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to clone. * @param {Function} [customizer] The function to customize cloning. diff --git a/collection.js b/collection.js index 8c564ea3e..3102572b4 100644 --- a/collection.js +++ b/collection.js @@ -1,4 +1,4 @@ -define(['./at', './countBy', './each', './eachRight', './every', './filter', './find', './findLast', './flatMap', './forEach', './forEachRight', './groupBy', './includes', './invokeMap', './keyBy', './map', './orderBy', './partition', './reduce', './reduceRight', './reject', './sample', './sampleSize', './shuffle', './size', './some', './sortBy'], function(at, countBy, each, eachRight, every, filter, find, findLast, flatMap, forEach, forEachRight, groupBy, includes, invokeMap, keyBy, map, orderBy, partition, reduce, reduceRight, reject, sample, sampleSize, shuffle, size, some, sortBy) { +define(['./at', './countBy', './each', './eachRight', './every', './filter', './find', './findLast', './flatMap', './flatMapDeep', './flatMapDepth', './forEach', './forEachRight', './groupBy', './includes', './invokeMap', './keyBy', './map', './orderBy', './partition', './reduce', './reduceRight', './reject', './sample', './sampleSize', './shuffle', './size', './some', './sortBy'], function(at, countBy, each, eachRight, every, filter, find, findLast, flatMap, flatMapDeep, flatMapDepth, forEach, forEachRight, groupBy, includes, invokeMap, keyBy, map, orderBy, partition, reduce, reduceRight, reject, sample, sampleSize, shuffle, size, some, sortBy) { return { 'at': at, 'countBy': countBy, @@ -9,6 +9,8 @@ define(['./at', './countBy', './each', './eachRight', './every', './filter', './ 'find': find, 'findLast': findLast, 'flatMap': flatMap, + 'flatMapDeep': flatMapDeep, + 'flatMapDepth': flatMapDepth, 'forEach': forEach, 'forEachRight': forEachRight, 'groupBy': groupBy, diff --git a/commit.js b/commit.js index 2a86f5a22..ff0dd3bba 100644 --- a/commit.js +++ b/commit.js @@ -1,10 +1,11 @@ define(['./_LodashWrapper'], function(LodashWrapper) { /** - * Executes the chained sequence and returns the wrapped result. + * Executes the chain sequence and returns the wrapped result. * * @name commit * @memberOf _ + * @since 3.2.0 * @category Seq * @returns {Object} Returns the new `lodash` wrapper instance. * @example diff --git a/compact.js b/compact.js index 6f0c71679..94a3e7557 100644 --- a/compact.js +++ b/compact.js @@ -6,6 +6,7 @@ define([], function() { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to compact. * @returns {Array} Returns the new array of filtered values. diff --git a/concat.js b/concat.js index 77c1a1398..d0786c8ff 100644 --- a/concat.js +++ b/concat.js @@ -1,4 +1,4 @@ -define(['./_arrayConcat', './_baseFlatten', './isArray', './rest'], function(arrayConcat, baseFlatten, isArray, rest) { +define(['./_arrayConcat', './_baseFlatten', './castArray', './_copyArray'], function(arrayConcat, baseFlatten, castArray, copyArray) { /** * Creates a new array concatenating `array` with any additional arrays @@ -6,6 +6,7 @@ define(['./_arrayConcat', './_baseFlatten', './isArray', './rest'], function(arr * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to concatenate. * @param {...*} [values] The values to concatenate. @@ -21,13 +22,19 @@ define(['./_arrayConcat', './_baseFlatten', './isArray', './rest'], function(arr * console.log(array); * // => [1] */ - var concat = rest(function(array, values) { - if (!isArray(array)) { - array = array == null ? [] : [Object(array)]; + function concat() { + var length = arguments.length, + array = castArray(arguments[0]); + + if (length < 2) { + return length ? copyArray(array) : []; } - values = baseFlatten(values, 1); - return arrayConcat(array, values); - }); + var args = Array(length - 1); + while (length--) { + args[length - 1] = arguments[length]; + } + return arrayConcat(array, baseFlatten(args, 1)); + } return concat; }); diff --git a/cond.js b/cond.js index f6a51ef02..b849f8095 100644 --- a/cond.js +++ b/cond.js @@ -11,6 +11,7 @@ define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {Array} pairs The predicate-function pairs. * @returns {Function} Returns the new function. @@ -32,13 +33,14 @@ define(['./_apply', './_arrayMap', './_baseIteratee', './rest'], function(apply, * // => 'no match' */ function cond(pairs) { - var length = pairs ? pairs.length : 0; + var length = pairs ? pairs.length : 0, + toIteratee = baseIteratee; pairs = !length ? [] : arrayMap(pairs, function(pair) { if (typeof pair[1] != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - return [baseIteratee(pair[0]), pair[1]]; + return [toIteratee(pair[0]), pair[1]]; }); return rest(function(args) { diff --git a/conforms.js b/conforms.js index b81341537..8bb1653b7 100644 --- a/conforms.js +++ b/conforms.js @@ -7,6 +7,7 @@ define(['./_baseClone', './_baseConforms'], function(baseClone, baseConforms) { * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {Object} source The object of property predicates to conform to. * @returns {Function} Returns the new function. diff --git a/constant.js b/constant.js index 53f88e439..01dcb97c4 100644 --- a/constant.js +++ b/constant.js @@ -5,6 +5,7 @@ define([], function() { * * @static * @memberOf _ + * @since 2.4.0 * @category Util * @param {*} value The value to return from the new function. * @returns {Function} Returns the new function. diff --git a/countBy.js b/countBy.js index 15f3620dc..b8d345929 100644 --- a/countBy.js +++ b/countBy.js @@ -14,9 +14,11 @@ define(['./_createAggregator'], function(createAggregator) { * * @static * @memberOf _ + * @since 0.5.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * diff --git a/create.js b/create.js index dd93fbec1..bc2abec36 100644 --- a/create.js +++ b/create.js @@ -1,11 +1,13 @@ define(['./_baseAssign', './_baseCreate'], function(baseAssign, baseCreate) { /** - * Creates an object that inherits from the `prototype` object. If a `properties` - * object is given its own enumerable properties are assigned to the created object. + * Creates an object that inherits from the `prototype` object. If a + * `properties` object is given its own enumerable string keyed properties + * are assigned to the created object. * * @static * @memberOf _ + * @since 2.3.0 * @category Object * @param {Object} prototype The object to inherit from. * @param {Object} [properties] The properties to assign to the object. diff --git a/curry.js b/curry.js index 9cba3b1c5..bda3bd183 100644 --- a/curry.js +++ b/curry.js @@ -20,10 +20,11 @@ define(['./_createWrapper'], function(createWrapper) { * * @static * @memberOf _ + * @since 2.0.0 * @category Function * @param {Function} func The function to curry. * @param {number} [arity=func.length] The arity of `func`. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the new curried function. * @example * diff --git a/curryRight.js b/curryRight.js index 8040a5768..d21ca4a85 100644 --- a/curryRight.js +++ b/curryRight.js @@ -17,10 +17,11 @@ define(['./_createWrapper'], function(createWrapper) { * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} func The function to curry. * @param {number} [arity=func.length] The arity of `func`. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the new curried function. * @example * diff --git a/debounce.js b/debounce.js index 83a6df259..f250113f5 100644 --- a/debounce.js +++ b/debounce.js @@ -7,7 +7,8 @@ define(['./isObject', './now', './toNumber'], function(isObject, now, toNumber) var FUNC_ERROR_TEXT = 'Expected a function'; /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeMax = Math.max; + var nativeMax = Math.max, + nativeMin = Math.min; /** * Creates a debounced function that delays invoking `func` until after `wait` @@ -28,16 +29,17 @@ define(['./isObject', './now', './toNumber'], function(isObject, now, toNumber) * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to debounce. * @param {number} [wait=0] The number of milliseconds to delay. - * @param {Object} [options] The options object. - * @param {boolean} [options.leading=false] Specify invoking on the leading - * edge of the timeout. - * @param {number} [options.maxWait] The maximum time `func` is allowed to be - * delayed before it's invoked. - * @param {boolean} [options.trailing=true] Specify invoking on the trailing - * edge of the timeout. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. * @returns {Function} Returns the new debounced function. * @example * @@ -59,14 +61,12 @@ define(['./isObject', './now', './toNumber'], function(isObject, now, toNumber) * jQuery(window).on('popstate', debounced.cancel); */ function debounce(func, wait, options) { - var args, - maxTimeoutId, + var lastArgs, + lastThis, result, - stamp, - thisArg, - timeoutId, - trailingCall, - lastCalled = 0, + timerId, + lastCallTime = 0, + lastInvokeTime = 0, leading = false, maxWait = false, trailing = true; @@ -81,92 +81,94 @@ define(['./isObject', './now', './toNumber'], function(isObject, now, toNumber) trailing = 'trailing' in options ? !!options.trailing : trailing; } - function cancel() { - if (timeoutId) { - clearTimeout(timeoutId); - } - if (maxTimeoutId) { - clearTimeout(maxTimeoutId); - } - lastCalled = 0; - args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined; - } + function invokeFunc(time) { + var args = lastArgs, + thisArg = lastThis; - function complete(isCalled, id) { - if (id) { - clearTimeout(id); - } - maxTimeoutId = timeoutId = trailingCall = undefined; - if (isCalled) { - lastCalled = now(); - result = func.apply(thisArg, args); - if (!timeoutId && !maxTimeoutId) { - args = thisArg = undefined; - } - } - } - - function delayed() { - var remaining = wait - (now() - stamp); - if (remaining <= 0 || remaining > wait) { - complete(trailingCall, maxTimeoutId); - } else { - timeoutId = setTimeout(delayed, remaining); - } - } - - function flush() { - if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) { - result = func.apply(thisArg, args); - } - cancel(); + lastArgs = lastThis = undefined; + lastInvokeTime = time; + result = func.apply(thisArg, args); return result; } - function maxDelayed() { - complete(trailing, timeoutId); + function leadingEdge(time) { + // Reset any `maxWait` timer. + lastInvokeTime = time; + // Start the timer for the trailing edge. + timerId = setTimeout(timerExpired, wait); + // Invoke the leading edge. + return leading ? invokeFunc(time) : result; + } + + function remainingWait(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime, + result = wait - timeSinceLastCall; + + return maxWait === false ? result : nativeMin(result, maxWait - timeSinceLastInvoke); + } + + function shouldInvoke(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime; + + // Either this is the first call, activity has stopped and we're at the + // trailing edge, the system time has gone backwards and we're treating + // it as the trailing edge, or we've hit the `maxWait` limit. + return (!lastCallTime || (timeSinceLastCall >= wait) || + (timeSinceLastCall < 0) || (maxWait !== false && timeSinceLastInvoke >= maxWait)); + } + + function timerExpired() { + var time = now(); + if (shouldInvoke(time)) { + return trailingEdge(time); + } + // Restart the timer. + timerId = setTimeout(timerExpired, remainingWait(time)); + } + + function trailingEdge(time) { + clearTimeout(timerId); + timerId = undefined; + + // Only invoke if we have `lastArgs` which means `func` has been + // debounced at least once. + if (trailing && lastArgs) { + return invokeFunc(time); + } + lastArgs = lastThis = undefined; + return result; + } + + function cancel() { + if (timerId !== undefined) { + clearTimeout(timerId); + } + lastCallTime = lastInvokeTime = 0; + lastArgs = lastThis = timerId = undefined; + } + + function flush() { + return timerId === undefined ? result : trailingEdge(now()); } function debounced() { - args = arguments; - stamp = now(); - thisArg = this; - trailingCall = trailing && (timeoutId || !leading); + var time = now(), + isInvoking = shouldInvoke(time); - if (maxWait === false) { - var leadingCall = leading && !timeoutId; - } else { - if (!lastCalled && !maxTimeoutId && !leading) { - lastCalled = stamp; - } - var remaining = maxWait - (stamp - lastCalled); + lastArgs = arguments; + lastThis = this; + lastCallTime = time; - var isCalled = (remaining <= 0 || remaining > maxWait) && - (leading || maxTimeoutId); - - if (isCalled) { - if (maxTimeoutId) { - maxTimeoutId = clearTimeout(maxTimeoutId); - } - lastCalled = stamp; - result = func.apply(thisArg, args); + if (isInvoking) { + if (timerId === undefined) { + return leadingEdge(lastCallTime); } - else if (!maxTimeoutId) { - maxTimeoutId = setTimeout(maxDelayed, remaining); - } - } - if (isCalled && timeoutId) { - timeoutId = clearTimeout(timeoutId); - } - else if (!timeoutId && wait !== maxWait) { - timeoutId = setTimeout(delayed, wait); - } - if (leadingCall) { - isCalled = true; - result = func.apply(thisArg, args); - } - if (isCalled && !timeoutId && !maxTimeoutId) { - args = thisArg = undefined; + // Handle invocations in a tight loop. + clearTimeout(timerId); + timerId = setTimeout(timerExpired, wait); + return invokeFunc(lastCallTime); } return result; } diff --git a/deburr.js b/deburr.js index e8f0ae047..b15787667 100644 --- a/deburr.js +++ b/deburr.js @@ -17,11 +17,14 @@ define(['./_deburrLetter', './toString'], function(deburrLetter, toString) { var reComboMark = RegExp(rsCombo, 'g'); /** - * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) - * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). + * Deburrs `string` by converting + * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * to basic latin letters and removing + * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to deburr. * @returns {string} Returns the deburred string. diff --git a/defaults.js b/defaults.js index 155e2a83f..3aaf60141 100644 --- a/defaults.js +++ b/defaults.js @@ -4,14 +4,15 @@ define(['./_apply', './_assignInDefaults', './assignInWith', './rest'], function var undefined; /** - * Assigns own and inherited enumerable properties of source objects to the - * destination object for all destination properties that resolve to `undefined`. - * Source objects are applied from left to right. Once a property is set, - * additional values of the same property are ignored. + * Assigns own and inherited enumerable string keyed properties of source + * objects to the destination object for all destination properties that + * resolve to `undefined`. Source objects are applied from left to right. + * Once a property is set, additional values of the same property are ignored. * * **Note:** This method mutates `object`. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The destination object. diff --git a/defaultsDeep.js b/defaultsDeep.js index d649b5d9c..45adb30a3 100644 --- a/defaultsDeep.js +++ b/defaultsDeep.js @@ -11,6 +11,7 @@ define(['./_apply', './_mergeDefaults', './mergeWith', './rest'], function(apply * * @static * @memberOf _ + * @since 3.10.0 * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. diff --git a/defer.js b/defer.js index 06741b97e..557170813 100644 --- a/defer.js +++ b/defer.js @@ -6,6 +6,7 @@ define(['./_baseDelay', './rest'], function(baseDelay, rest) { * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to defer. * @param {...*} [args] The arguments to invoke `func` with. @@ -15,7 +16,7 @@ define(['./_baseDelay', './rest'], function(baseDelay, rest) { * _.defer(function(text) { * console.log(text); * }, 'deferred'); - * // => logs 'deferred' after one or more milliseconds + * // => Logs 'deferred' after one or more milliseconds. */ var defer = rest(function(func, args) { return baseDelay(func, 1, args); diff --git a/delay.js b/delay.js index 58a1f7c36..4092527a5 100644 --- a/delay.js +++ b/delay.js @@ -6,6 +6,7 @@ define(['./_baseDelay', './rest', './toNumber'], function(baseDelay, rest, toNum * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to delay. * @param {number} wait The number of milliseconds to delay invocation. @@ -16,7 +17,7 @@ define(['./_baseDelay', './rest', './toNumber'], function(baseDelay, rest, toNum * _.delay(function(text) { * console.log(text); * }, 1000, 'later'); - * // => logs 'later' after one second + * // => Logs 'later' after one second. */ var delay = rest(function(func, wait, args) { return baseDelay(func, toNumber(wait) || 0, args); diff --git a/difference.js b/difference.js index 21498b5bd..0f9298fd7 100644 --- a/difference.js +++ b/difference.js @@ -1,13 +1,14 @@ define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './rest'], function(baseDifference, baseFlatten, isArrayLikeObject, rest) { /** - * Creates an array of unique `array` values not included in the other - * given arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Creates an array of unique `array` values not included in the other given + * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. The order of result values is determined by the * order they occur in the first array. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. diff --git a/differenceBy.js b/differenceBy.js index 0975f225c..96d8efab4 100644 --- a/differenceBy.js +++ b/differenceBy.js @@ -11,10 +11,12 @@ define(['./_baseDifference', './_baseFlatten', './_baseIteratee', './isArrayLike * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example * diff --git a/differenceWith.js b/differenceWith.js index 1557b54f3..ba68aa3c0 100644 --- a/differenceWith.js +++ b/differenceWith.js @@ -11,6 +11,7 @@ define(['./_baseDifference', './_baseFlatten', './isArrayLikeObject', './last', * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. diff --git a/divide.js b/divide.js new file mode 100644 index 000000000..921c329a5 --- /dev/null +++ b/divide.js @@ -0,0 +1,23 @@ +define(['./_createMathOperation'], function(createMathOperation) { + + /** + * Divide two numbers. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Math + * @param {number} dividend The first number in a division. + * @param {number} divisor The second number in a division. + * @returns {number} Returns the quotient. + * @example + * + * _.divide(6, 4); + * // => 1.5 + */ + var divide = createMathOperation(function(dividend, divisor) { + return dividend / divisor; + }); + + return divide; +}); diff --git a/drop.js b/drop.js index a2a6b8e6b..51b61d9f3 100644 --- a/drop.js +++ b/drop.js @@ -8,10 +8,11 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * * @static * @memberOf _ + * @since 0.5.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/dropRight.js b/dropRight.js index 8606dff7e..dbc3c2d94 100644 --- a/dropRight.js +++ b/dropRight.js @@ -8,10 +8,11 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/dropRightWhile.js b/dropRightWhile.js index e9579a3b1..c45298bec 100644 --- a/dropRightWhile.js +++ b/dropRightWhile.js @@ -7,9 +7,11 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/dropWhile.js b/dropWhile.js index 116ce5ee1..8be33cbf2 100644 --- a/dropWhile.js +++ b/dropWhile.js @@ -7,9 +7,11 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/endsWith.js b/endsWith.js index 6cf8afb1a..a5cb26656 100644 --- a/endsWith.js +++ b/endsWith.js @@ -8,11 +8,13 @@ define(['./_baseClamp', './toInteger', './toString'], function(baseClamp, toInte * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to search. * @param {string} [target] The string to search for. * @param {number} [position=string.length] The position to search from. - * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`. + * @returns {boolean} Returns `true` if `string` ends with `target`, + * else `false`. * @example * * _.endsWith('abc', 'c'); diff --git a/entries.js b/entries.js new file mode 100644 index 000000000..271456895 --- /dev/null +++ b/entries.js @@ -0,0 +1,3 @@ +define(["./toPairs"], function(toPairs) { + return toPairs; +}); diff --git a/entriesIn.js b/entriesIn.js new file mode 100644 index 000000000..801f3c547 --- /dev/null +++ b/entriesIn.js @@ -0,0 +1,3 @@ +define(["./toPairsIn"], function(toPairsIn) { + return toPairsIn; +}); diff --git a/eq.js b/eq.js index 11fad7058..1a687217a 100644 --- a/eq.js +++ b/eq.js @@ -1,11 +1,13 @@ define([], function() { /** - * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * comparison between two values to determine if they are equivalent. * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. diff --git a/escape.js b/escape.js index ef8a049cf..23a24b900 100644 --- a/escape.js +++ b/escape.js @@ -13,20 +13,22 @@ define(['./_escapeHtmlChar', './toString'], function(escapeHtmlChar, toString) { * * Though the ">" character is escaped for symmetry, characters like * ">" and "/" don't need escaping in HTML and have no special meaning - * unless they're part of a tag or unquoted attribute value. - * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) + * unless they're part of a tag or unquoted attribute value. See + * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * * Backticks are escaped because in IE < 9, they can break out of * attribute values or HTML comments. See [#59](https://html5sec.org/#59), * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and - * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/) - * for more details. + * [#133](https://html5sec.org/#133) of the + * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details. * - * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping) - * to reduce XSS vectors. + * When working with HTML you should always + * [quote attribute values](http://wonko.com/post/html-escaping) to reduce + * XSS vectors. * * @static + * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The string to escape. diff --git a/escapeRegExp.js b/escapeRegExp.js index e08ca8030..8f5901325 100644 --- a/escapeRegExp.js +++ b/escapeRegExp.js @@ -10,6 +10,7 @@ define(['./toString'], function(toString) { * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to escape. * @returns {string} Returns the escaped string. diff --git a/every.js b/every.js index 396830647..1614d4d58 100644 --- a/every.js +++ b/every.js @@ -10,19 +10,22 @@ define(['./_arrayEvery', './_baseEvery', './_baseIteratee', './isArray', './_isI * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. + * @param {Array|Function|Object|string} [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`. * @example * * _.every([true, 1, null, 'yes'], Boolean); * // => false * * var users = [ - * { 'user': 'barney', 'active': false }, - * { 'user': 'fred', 'active': false } + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * * // The `_.matches` iteratee shorthand. diff --git a/fill.js b/fill.js index 37832f6b3..1ff0b8d1e 100644 --- a/fill.js +++ b/fill.js @@ -8,6 +8,7 @@ define(['./_baseFill', './_isIterateeCall'], function(baseFill, isIterateeCall) * * @static * @memberOf _ + * @since 3.2.0 * @category Array * @param {Array} array The array to fill. * @param {*} value The value to fill `array` with. diff --git a/filter.js b/filter.js index 87eb82d08..b4553f4d5 100644 --- a/filter.js +++ b/filter.js @@ -2,14 +2,16 @@ define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], func /** * Iterates over elements of `collection`, returning an array of all elements - * `predicate` returns truthy for. The predicate is invoked with three arguments: - * (value, index|key, collection). + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @example * diff --git a/find.js b/find.js index ed3112b82..a4d531106 100644 --- a/find.js +++ b/find.js @@ -5,14 +5,16 @@ define(['./_baseEach', './_baseFind', './_baseFindIndex', './_baseIteratee', './ /** * Iterates over elements of `collection`, returning the first element - * `predicate` returns truthy for. The predicate is invoked with three arguments: - * (value, index|key, collection). + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {*} Returns the matched element, else `undefined`. * @example * diff --git a/findIndex.js b/findIndex.js index bff92db31..60683152c 100644 --- a/findIndex.js +++ b/findIndex.js @@ -6,9 +6,11 @@ define(['./_baseFindIndex', './_baseIteratee'], function(baseFindIndex, baseIter * * @static * @memberOf _ + * @since 1.1.0 * @category Array * @param {Array} array The array to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {number} Returns the index of the found element, else `-1`. * @example * diff --git a/findKey.js b/findKey.js index 8b3ef0615..03073740a 100644 --- a/findKey.js +++ b/findKey.js @@ -6,10 +6,13 @@ define(['./_baseFind', './_baseForOwn', './_baseIteratee'], function(baseFind, b * * @static * @memberOf _ + * @since 1.1.0 * @category Object * @param {Object} object The object to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @returns {string|undefined} Returns the key of the matched element, else `undefined`. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. * @example * * var users = { diff --git a/findLast.js b/findLast.js index 3eb730243..a7a8cc397 100644 --- a/findLast.js +++ b/findLast.js @@ -9,9 +9,11 @@ define(['./_baseEachRight', './_baseFind', './_baseFindIndex', './_baseIteratee' * * @static * @memberOf _ + * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {*} Returns the matched element, else `undefined`. * @example * diff --git a/findLastIndex.js b/findLastIndex.js index 25124b375..4a5ba33d2 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -6,9 +6,11 @@ define(['./_baseFindIndex', './_baseIteratee'], function(baseFindIndex, baseIter * * @static * @memberOf _ + * @since 2.0.0 * @category Array * @param {Array} array The array to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {number} Returns the index of the found element, else `-1`. * @example * diff --git a/findLastKey.js b/findLastKey.js index 4e5c9356c..e7a7d9151 100644 --- a/findLastKey.js +++ b/findLastKey.js @@ -6,10 +6,13 @@ define(['./_baseFind', './_baseForOwnRight', './_baseIteratee'], function(baseFi * * @static * @memberOf _ + * @since 2.0.0 * @category Object * @param {Object} object The object to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @returns {string|undefined} Returns the key of the matched element, else `undefined`. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. * @example * * var users = { diff --git a/flatMap.js b/flatMap.js index e1cd819ed..7d6f17d6d 100644 --- a/flatMap.js +++ b/flatMap.js @@ -1,15 +1,17 @@ define(['./_baseFlatten', './map'], function(baseFlatten, map) { /** - * Creates an array of flattened values by running each element in `collection` - * through `iteratee` and concating its result to the other mapped values. - * The iteratee is invoked with three arguments: (value, index|key, collection). + * Creates a flattened array of values by running each element in `collection` + * through `iteratee` and flattening the mapped results. The iteratee is + * invoked with three arguments: (value, index|key, collection). * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example * diff --git a/flatMapDeep.js b/flatMapDeep.js new file mode 100644 index 000000000..c139d2f9b --- /dev/null +++ b/flatMapDeep.js @@ -0,0 +1,32 @@ +define(['./_baseFlatten', './map'], function(baseFlatten, map) { + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0; + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDeep([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMapDeep(collection, iteratee) { + return baseFlatten(map(collection, iteratee), INFINITY); + } + + return flatMapDeep; +}); diff --git a/flatMapDepth.js b/flatMapDepth.js new file mode 100644 index 000000000..382f05c51 --- /dev/null +++ b/flatMapDepth.js @@ -0,0 +1,34 @@ +define(['./_baseFlatten', './map', './toInteger'], function(baseFlatten, map, toInteger) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results up to `depth` times. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDepth([1, 2], duplicate, 2); + * // => [[1, 1], [2, 2]] + */ + function flatMapDepth(collection, iteratee, depth) { + depth = depth === undefined ? 1 : toInteger(depth); + return baseFlatten(map(collection, iteratee), depth); + } + + return flatMapDepth; +}); diff --git a/flatten.js b/flatten.js index 835e9d619..a9edd3ccd 100644 --- a/flatten.js +++ b/flatten.js @@ -5,6 +5,7 @@ define(['./_baseFlatten'], function(baseFlatten) { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. diff --git a/flattenDeep.js b/flattenDeep.js index cb6a9632d..958d9ffca 100644 --- a/flattenDeep.js +++ b/flattenDeep.js @@ -8,6 +8,7 @@ define(['./_baseFlatten'], function(baseFlatten) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. diff --git a/flattenDepth.js b/flattenDepth.js index 218c8e415..5538da2f7 100644 --- a/flattenDepth.js +++ b/flattenDepth.js @@ -8,6 +8,7 @@ define(['./_baseFlatten', './toInteger'], function(baseFlatten, toInteger) { * * @static * @memberOf _ + * @since 4.4.0 * @category Array * @param {Array} array The array to flatten. * @param {number} [depth=1] The maximum recursion depth. diff --git a/flip.js b/flip.js index 0d84d58e8..a5cd7314d 100644 --- a/flip.js +++ b/flip.js @@ -8,6 +8,7 @@ define(['./_createWrapper'], function(createWrapper) { * * @static * @memberOf _ + * @since 4.0.0 * @category Function * @param {Function} func The function to flip arguments for. * @returns {Function} Returns the new function. diff --git a/floor.js b/floor.js index 064867a71..e510356af 100644 --- a/floor.js +++ b/floor.js @@ -5,6 +5,7 @@ define(['./_createRound'], function(createRound) { * * @static * @memberOf _ + * @since 3.10.0 * @category Math * @param {number} number The number to round down. * @param {number} [precision=0] The precision to round down to. diff --git a/flow.js b/flow.js index 4c961d905..3111d4411 100644 --- a/flow.js +++ b/flow.js @@ -7,6 +7,7 @@ define(['./_createFlow'], function(createFlow) { * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. * @returns {Function} Returns the new function. diff --git a/flowRight.js b/flowRight.js index 60719180e..1fc431968 100644 --- a/flowRight.js +++ b/flowRight.js @@ -5,6 +5,7 @@ define(['./_createFlow'], function(createFlow) { * invokes the given functions from right to left. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. diff --git a/forEach.js b/forEach.js index cf14f9b4d..e3b60b001 100644 --- a/forEach.js +++ b/forEach.js @@ -1,16 +1,17 @@ -define(['./_arrayEach', './_baseCastFunction', './_baseEach', './isArray'], function(arrayEach, baseCastFunction, baseEach, isArray) { +define(['./_arrayEach', './_baseEach', './_baseIteratee', './isArray'], function(arrayEach, baseEach, baseIteratee, isArray) { /** * Iterates over elements of `collection` invoking `iteratee` for each element. * The iteratee is invoked with three arguments: (value, index|key, collection). * Iteratee functions may exit iteration early by explicitly returning `false`. * - * **Note:** As with other "Collections" methods, objects with a "length" property - * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn` - * for object iteration. + * **Note:** As with other "Collections" methods, objects with a "length" + * property are iterated like arrays. To avoid this behavior use `_.forIn` + * or `_.forOwn` for object iteration. * * @static * @memberOf _ + * @since 0.1.0 * @alias each * @category Collection * @param {Array|Object} collection The collection to iterate over. @@ -21,17 +22,17 @@ define(['./_arrayEach', './_baseCastFunction', './_baseEach', './isArray'], func * _([1, 2]).forEach(function(value) { * console.log(value); * }); - * // => logs `1` then `2` + * // => Logs `1` then `2`. * * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { * console.log(key); * }); - * // => logs 'a' then 'b' (iteration order is not guaranteed) + * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forEach(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEach(collection, iteratee) - : baseEach(collection, baseCastFunction(iteratee)); + : baseEach(collection, baseIteratee(iteratee)); } return forEach; diff --git a/forEachRight.js b/forEachRight.js index b9beb02bb..f08a9243a 100644 --- a/forEachRight.js +++ b/forEachRight.js @@ -1,4 +1,4 @@ -define(['./_arrayEachRight', './_baseCastFunction', './_baseEachRight', './isArray'], function(arrayEachRight, baseCastFunction, baseEachRight, isArray) { +define(['./_arrayEachRight', './_baseEachRight', './_baseIteratee', './isArray'], function(arrayEachRight, baseEachRight, baseIteratee, isArray) { /** * This method is like `_.forEach` except that it iterates over elements of @@ -6,6 +6,7 @@ define(['./_arrayEachRight', './_baseCastFunction', './_baseEachRight', './isArr * * @static * @memberOf _ + * @since 2.0.0 * @alias eachRight * @category Collection * @param {Array|Object} collection The collection to iterate over. @@ -16,12 +17,12 @@ define(['./_arrayEachRight', './_baseCastFunction', './_baseEachRight', './isArr * _.forEachRight([1, 2], function(value) { * console.log(value); * }); - * // => logs `2` then `1` + * // => Logs `2` then `1`. */ function forEachRight(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEachRight(collection, iteratee) - : baseEachRight(collection, baseCastFunction(iteratee)); + : baseEachRight(collection, baseIteratee(iteratee)); } return forEachRight; diff --git a/forIn.js b/forIn.js index 25ab15625..d79fba995 100644 --- a/forIn.js +++ b/forIn.js @@ -1,13 +1,14 @@ -define(['./_baseCastFunction', './_baseFor', './keysIn'], function(baseCastFunction, baseFor, keysIn) { +define(['./_baseFor', './_baseIteratee', './keysIn'], function(baseFor, baseIteratee, keysIn) { /** - * Iterates over own and inherited enumerable properties of an object invoking - * `iteratee` for each property. The iteratee is invoked with three arguments: - * (value, key, object). Iteratee functions may exit iteration early by explicitly - * returning `false`. + * Iterates over own and inherited enumerable string keyed properties of an + * object invoking `iteratee` for each property. The iteratee is invoked with + * three arguments: (value, key, object). Iteratee functions may exit iteration + * early by explicitly returning `false`. * * @static * @memberOf _ + * @since 0.3.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -24,12 +25,12 @@ define(['./_baseCastFunction', './_baseFor', './keysIn'], function(baseCastFunct * _.forIn(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed) + * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). */ function forIn(object, iteratee) { return object == null ? object - : baseFor(object, baseCastFunction(iteratee), keysIn); + : baseFor(object, baseIteratee(iteratee), keysIn); } return forIn; diff --git a/forInRight.js b/forInRight.js index d946264e2..525f6f443 100644 --- a/forInRight.js +++ b/forInRight.js @@ -1,4 +1,4 @@ -define(['./_baseCastFunction', './_baseForRight', './keysIn'], function(baseCastFunction, baseForRight, keysIn) { +define(['./_baseForRight', './_baseIteratee', './keysIn'], function(baseForRight, baseIteratee, keysIn) { /** * This method is like `_.forIn` except that it iterates over properties of @@ -6,6 +6,7 @@ define(['./_baseCastFunction', './_baseForRight', './keysIn'], function(baseCast * * @static * @memberOf _ + * @since 2.0.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -22,12 +23,12 @@ define(['./_baseCastFunction', './_baseForRight', './keysIn'], function(baseCast * _.forInRight(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c' + * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. */ function forInRight(object, iteratee) { return object == null ? object - : baseForRight(object, baseCastFunction(iteratee), keysIn); + : baseForRight(object, baseIteratee(iteratee), keysIn); } return forInRight; diff --git a/forOwn.js b/forOwn.js index be1efd512..311188d8d 100644 --- a/forOwn.js +++ b/forOwn.js @@ -1,13 +1,14 @@ -define(['./_baseCastFunction', './_baseForOwn'], function(baseCastFunction, baseForOwn) { +define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) { /** - * Iterates over own enumerable properties of an object invoking `iteratee` - * for each property. The iteratee is invoked with three arguments: + * Iterates over own enumerable string keyed properties of an object invoking + * `iteratee` for each property. The iteratee is invoked with three arguments: * (value, key, object). Iteratee functions may exit iteration early by * explicitly returning `false`. * * @static * @memberOf _ + * @since 0.3.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -24,10 +25,10 @@ define(['./_baseCastFunction', './_baseForOwn'], function(baseCastFunction, base * _.forOwn(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'a' then 'b' (iteration order is not guaranteed) + * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forOwn(object, iteratee) { - return object && baseForOwn(object, baseCastFunction(iteratee)); + return object && baseForOwn(object, baseIteratee(iteratee)); } return forOwn; diff --git a/forOwnRight.js b/forOwnRight.js index 4c0d565e6..d1ca29db4 100644 --- a/forOwnRight.js +++ b/forOwnRight.js @@ -1,4 +1,4 @@ -define(['./_baseCastFunction', './_baseForOwnRight'], function(baseCastFunction, baseForOwnRight) { +define(['./_baseForOwnRight', './_baseIteratee'], function(baseForOwnRight, baseIteratee) { /** * This method is like `_.forOwn` except that it iterates over properties of @@ -6,6 +6,7 @@ define(['./_baseCastFunction', './_baseForOwnRight'], function(baseCastFunction, * * @static * @memberOf _ + * @since 2.0.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -22,10 +23,10 @@ define(['./_baseCastFunction', './_baseForOwnRight'], function(baseCastFunction, * _.forOwnRight(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b' + * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, baseCastFunction(iteratee)); + return object && baseForOwnRight(object, baseIteratee(iteratee)); } return forOwnRight; diff --git a/fromPairs.js b/fromPairs.js index c547710f6..2a08889e4 100644 --- a/fromPairs.js +++ b/fromPairs.js @@ -6,6 +6,7 @@ define([], function() { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} pairs The key-value pairs. * @returns {Object} Returns the new object. diff --git a/functions.js b/functions.js index 7ccd1e515..4338ad553 100644 --- a/functions.js +++ b/functions.js @@ -5,6 +5,7 @@ define(['./_baseFunctions', './keys'], function(baseFunctions, keys) { * of `object`. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to inspect. diff --git a/functionsIn.js b/functionsIn.js index 20c2caa11..4347a7e79 100644 --- a/functionsIn.js +++ b/functionsIn.js @@ -6,6 +6,7 @@ define(['./_baseFunctions', './keysIn'], function(baseFunctions, keysIn) { * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to inspect. * @returns {Array} Returns the new array of property names. diff --git a/get.js b/get.js index 2b941ace8..cb3c64c73 100644 --- a/get.js +++ b/get.js @@ -9,10 +9,11 @@ define(['./_baseGet'], function(baseGet) { * * @static * @memberOf _ + * @since 3.7.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path of the property to get. - * @param {*} [defaultValue] The value returned if the resolved value is `undefined`. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. * @returns {*} Returns the resolved value. * @example * diff --git a/groupBy.js b/groupBy.js index d1ea4ab4a..feca22489 100644 --- a/groupBy.js +++ b/groupBy.js @@ -14,9 +14,11 @@ define(['./_createAggregator'], function(createAggregator) { * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * diff --git a/gt.js b/gt.js index 0c75014fd..c83bcd6ec 100644 --- a/gt.js +++ b/gt.js @@ -5,10 +5,12 @@ define([], function() { * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. * @example * * _.gt(3, 1); diff --git a/gte.js b/gte.js index b4e4ed2bd..99dd311f1 100644 --- a/gte.js +++ b/gte.js @@ -5,10 +5,12 @@ define([], function() { * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is greater than or equal to + * `other`, else `false`. * @example * * _.gte(3, 1); diff --git a/has.js b/has.js index f0812455c..aae94854a 100644 --- a/has.js +++ b/has.js @@ -4,6 +4,7 @@ define(['./_baseHas', './_hasPath'], function(baseHas, hasPath) { * Checks if `path` is a direct property of `object`. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. diff --git a/hasIn.js b/hasIn.js index 3dd30ca39..6c8153447 100644 --- a/hasIn.js +++ b/hasIn.js @@ -5,6 +5,7 @@ define(['./_baseHasIn', './_hasPath'], function(baseHasIn, hasPath) { * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path to check. diff --git a/head.js b/head.js index 49e7808e4..9ebdc8daf 100644 --- a/head.js +++ b/head.js @@ -8,6 +8,7 @@ define([], function() { * * @static * @memberOf _ + * @since 0.1.0 * @alias first * @category Array * @param {Array} array The array to query. diff --git a/identity.js b/identity.js index 316cc6848..99f6b4d6b 100644 --- a/identity.js +++ b/identity.js @@ -4,6 +4,7 @@ define([], function() { * This method returns the first argument given to it. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {*} value Any value. diff --git a/inRange.js b/inRange.js index 8b90e0236..cb4ddf280 100644 --- a/inRange.js +++ b/inRange.js @@ -11,6 +11,7 @@ define(['./_baseInRange', './toNumber'], function(baseInRange, toNumber) { * * @static * @memberOf _ + * @since 3.3.0 * @category Number * @param {number} number The number to check. * @param {number} [start=0] The start of the range. diff --git a/includes.js b/includes.js index e6f737099..2af31fbd8 100644 --- a/includes.js +++ b/includes.js @@ -4,18 +4,20 @@ define(['./_baseIndexOf', './isArrayLike', './isString', './toInteger', './value var nativeMax = Math.max; /** - * Checks if `value` is in `collection`. If `collection` is a string it's checked - * for a substring of `value`, otherwise [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Checks if `value` is in `collection`. If `collection` is a string it's + * checked for a substring of `value`, otherwise + * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * is used for equality comparisons. If `fromIndex` is negative, it's used as * the offset from the end of `collection`. * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object|string} collection The collection to search. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. * @returns {boolean} Returns `true` if `value` is found, else `false`. * @example * diff --git a/indexOf.js b/indexOf.js index de535b2db..349faf175 100644 --- a/indexOf.js +++ b/indexOf.js @@ -11,6 +11,7 @@ define(['./_baseIndexOf', './toInteger'], function(baseIndexOf, toInteger) { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. diff --git a/initial.js b/initial.js index 91be26bdd..0bfabc051 100644 --- a/initial.js +++ b/initial.js @@ -5,6 +5,7 @@ define(['./dropRight'], function(dropRight) { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to query. * @returns {Array} Returns the slice of `array`. diff --git a/intersection.js b/intersection.js index bc6d84e6d..1a7a89e75 100644 --- a/intersection.js +++ b/intersection.js @@ -8,6 +8,7 @@ define(['./_arrayMap', './_baseCastArrayLikeObject', './_baseIntersection', './r * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of intersecting values. diff --git a/intersectionBy.js b/intersectionBy.js index 83f140e9b..6d5447b3e 100644 --- a/intersectionBy.js +++ b/intersectionBy.js @@ -11,9 +11,11 @@ define(['./_arrayMap', './_baseCastArrayLikeObject', './_baseIntersection', './_ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of intersecting values. * @example * diff --git a/intersectionWith.js b/intersectionWith.js index 0b50274ce..faf2a3061 100644 --- a/intersectionWith.js +++ b/intersectionWith.js @@ -11,6 +11,7 @@ define(['./_arrayMap', './_baseCastArrayLikeObject', './_baseIntersection', './l * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. diff --git a/invert.js b/invert.js index b331b33f1..c7af45d8c 100644 --- a/invert.js +++ b/invert.js @@ -2,11 +2,12 @@ define(['./constant', './_createInverter', './identity'], function(constant, cre /** * Creates an object composed of the inverted keys and values of `object`. - * If `object` contains duplicate values, subsequent values overwrite property - * assignments of previous values. + * If `object` contains duplicate values, subsequent values overwrite + * property assignments of previous values. * * @static * @memberOf _ + * @since 0.7.0 * @category Object * @param {Object} object The object to invert. * @returns {Object} Returns the new inverted object. diff --git a/invertBy.js b/invertBy.js index 6ebd392ac..35a940369 100644 --- a/invertBy.js +++ b/invertBy.js @@ -15,9 +15,11 @@ define(['./_baseIteratee', './_createInverter'], function(baseIteratee, createIn * * @static * @memberOf _ + * @since 4.1.0 * @category Object * @param {Object} object The object to invert. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Object} Returns the new inverted object. * @example * diff --git a/invoke.js b/invoke.js index c625c650b..b8cd7c9ec 100644 --- a/invoke.js +++ b/invoke.js @@ -5,6 +5,7 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path of the method to invoke. diff --git a/invokeMap.js b/invokeMap.js index b957dfe0b..69aecab21 100644 --- a/invokeMap.js +++ b/invokeMap.js @@ -11,6 +11,7 @@ define(['./_apply', './_baseEach', './_baseInvoke', './isArrayLike', './_isKey', * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {Array|Function|string} path The path of the method to invoke or diff --git a/isArguments.js b/isArguments.js index 52409921e..fc112bef2 100644 --- a/isArguments.js +++ b/isArguments.js @@ -23,9 +23,11 @@ define(['./isArrayLikeObject'], function(isArrayLikeObject) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isArguments(function() { return arguments; }()); diff --git a/isArray.js b/isArray.js index c1e74b1a4..28b7a7eab 100644 --- a/isArray.js +++ b/isArray.js @@ -5,10 +5,12 @@ define([], function() { * * @static * @memberOf _ + * @since 0.1.0 * @type {Function} * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isArray([1, 2, 3]); diff --git a/isArrayBuffer.js b/isArrayBuffer.js index a7bc87511..f32588720 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -16,9 +16,11 @@ define(['./isObjectLike'], function(isObjectLike) { * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isArrayBuffer(new ArrayBuffer(2)); diff --git a/isArrayLike.js b/isArrayLike.js index b3744082d..c8cd8761c 100644 --- a/isArrayLike.js +++ b/isArrayLike.js @@ -7,6 +7,7 @@ define(['./_getLength', './isFunction', './isLength'], function(getLength, isFun * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. diff --git a/isArrayLikeObject.js b/isArrayLikeObject.js index 59664b58b..926dc0b1e 100644 --- a/isArrayLikeObject.js +++ b/isArrayLikeObject.js @@ -6,9 +6,11 @@ define(['./isArrayLike', './isObjectLike'], function(isArrayLike, isObjectLike) * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. * @example * * _.isArrayLikeObject([1, 2, 3]); diff --git a/isBoolean.js b/isBoolean.js index 50168627f..245475a65 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -17,9 +17,11 @@ define(['./isObjectLike'], function(isObjectLike) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isBoolean(false); diff --git a/isBuffer.js b/isBuffer.js index 2b5938c21..ea51b6f88 100644 --- a/isBuffer.js +++ b/isBuffer.js @@ -32,6 +32,7 @@ define(['./constant', './_root'], function(constant, root) { * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. diff --git a/isDate.js b/isDate.js index 4acd73b1c..358ccdc9e 100644 --- a/isDate.js +++ b/isDate.js @@ -17,9 +17,11 @@ define(['./isObjectLike'], function(isObjectLike) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isDate(new Date); diff --git a/isElement.js b/isElement.js index 45db28b74..5ed4aec74 100644 --- a/isElement.js +++ b/isElement.js @@ -5,9 +5,11 @@ define(['./isObjectLike', './isPlainObject'], function(isObjectLike, isPlainObje * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. + * @returns {boolean} Returns `true` if `value` is a DOM element, + * else `false`. * @example * * _.isElement(document.body); diff --git a/isEmpty.js b/isEmpty.js index 084528140..99db7ed95 100644 --- a/isEmpty.js +++ b/isEmpty.js @@ -1,4 +1,8 @@ -define(['./isArguments', './isArray', './isArrayLike', './isFunction', './isString'], function(isArguments, isArray, isArrayLike, isFunction, isString) { +define(['./_getTag', './isArguments', './isArray', './isArrayLike', './isBuffer', './isFunction', './isObjectLike', './isString', './keys'], function(getTag, isArguments, isArray, isArrayLike, isBuffer, isFunction, isObjectLike, isString, keys) { + + /** `Object#toString` result references. */ + var mapTag = '[object Map]', + setTag = '[object Set]'; /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -6,13 +10,25 @@ define(['./isArguments', './isArray', './isArrayLike', './isFunction', './isStri /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; + /** Built-in value references. */ + var propertyIsEnumerable = objectProto.propertyIsEnumerable; + + /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */ + var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); + /** - * Checks if `value` is an empty collection or object. A value is considered - * empty if it's an `arguments` object, array, string, or jQuery-like collection - * with a length of `0` or has no own enumerable properties. + * Checks if `value` is an empty object, collection, map, or set. + * + * Objects are considered empty if they have no own enumerable string keyed + * properties. + * + * Array-like values such as `arguments` objects, arrays, buffers, strings, or + * jQuery-like collections are considered empty if they have a `length` of `0`. + * Similarly, maps and sets are considered empty if they have a `size` of `0`. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is empty, else `false`. @@ -35,16 +51,22 @@ define(['./isArguments', './isArray', './isArrayLike', './isFunction', './isStri */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || - isFunction(value.splice) || isArguments(value))) { + (isArray(value) || isString(value) || isFunction(value.splice) || + isArguments(value) || isBuffer(value))) { return !value.length; } + if (isObjectLike(value)) { + var tag = getTag(value); + if (tag == mapTag || tag == setTag) { + return !value.size; + } + } for (var key in value) { if (hasOwnProperty.call(value, key)) { return false; } } - return true; + return !(nonEnumShadows && keys(value).length); } return isEmpty; diff --git a/isEqual.js b/isEqual.js index 89553b931..32e672ed1 100644 --- a/isEqual.js +++ b/isEqual.js @@ -12,10 +12,12 @@ define(['./_baseIsEqual'], function(baseIsEqual) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @returns {boolean} Returns `true` if the values are equivalent, + * else `false`. * @example * * var object = { 'user': 'fred' }; diff --git a/isEqualWith.js b/isEqualWith.js index 8a6f018c9..1e55e2f32 100644 --- a/isEqualWith.js +++ b/isEqualWith.js @@ -11,11 +11,13 @@ define(['./_baseIsEqual'], function(baseIsEqual) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @returns {boolean} Returns `true` if the values are equivalent, + * else `false`. * @example * * function isGreeting(value) { diff --git a/isError.js b/isError.js index cb7e9d779..b0f14b2b5 100644 --- a/isError.js +++ b/isError.js @@ -18,9 +18,11 @@ define(['./isObjectLike'], function(isObjectLike) { * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an error object, else `false`. + * @returns {boolean} Returns `true` if `value` is an error object, + * else `false`. * @example * * _.isError(new Error); diff --git a/isFinite.js b/isFinite.js index f741ebd21..377f3e49a 100644 --- a/isFinite.js +++ b/isFinite.js @@ -6,13 +6,16 @@ define(['./_root'], function(root) { /** * Checks if `value` is a finite primitive number. * - * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite). + * **Note:** This method is based on + * [`Number.isFinite`](https://mdn.io/Number/isFinite). * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. + * @returns {boolean} Returns `true` if `value` is a finite number, + * else `false`. * @example * * _.isFinite(3); diff --git a/isFunction.js b/isFunction.js index 23d268a90..2c445475f 100644 --- a/isFunction.js +++ b/isFunction.js @@ -18,9 +18,11 @@ define(['./isObject'], function(isObject) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isFunction(_); diff --git a/isInteger.js b/isInteger.js index 2d2c75b98..b8ab781bf 100644 --- a/isInteger.js +++ b/isInteger.js @@ -3,10 +3,12 @@ define(['./toInteger'], function(toInteger) { /** * Checks if `value` is an integer. * - * **Note:** This method is based on [`Number.isInteger`](https://mdn.io/Number/isInteger). + * **Note:** This method is based on + * [`Number.isInteger`](https://mdn.io/Number/isInteger). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an integer, else `false`. diff --git a/isLength.js b/isLength.js index 836e56f35..3cde9c1af 100644 --- a/isLength.js +++ b/isLength.js @@ -6,13 +6,16 @@ define([], function() { /** * Checks if `value` is a valid array-like length. * - * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * **Note:** This function is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @returns {boolean} Returns `true` if `value` is a valid length, + * else `false`. * @example * * _.isLength(3); diff --git a/isMap.js b/isMap.js index d1f26cc30..c0cce4d4f 100644 --- a/isMap.js +++ b/isMap.js @@ -8,9 +8,11 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isMap(new Map); diff --git a/isMatch.js b/isMatch.js index 2d0a2f714..765476af1 100644 --- a/isMatch.js +++ b/isMatch.js @@ -9,6 +9,7 @@ define(['./_baseIsMatch', './_getMatchData'], function(baseIsMatch, getMatchData * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. diff --git a/isMatchWith.js b/isMatchWith.js index a3fd2f0b9..8a9a6480e 100644 --- a/isMatchWith.js +++ b/isMatchWith.js @@ -11,6 +11,7 @@ define(['./_baseIsMatch', './_getMatchData'], function(baseIsMatch, getMatchData * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. diff --git a/isNaN.js b/isNaN.js index ab308b8bb..542bfb82e 100644 --- a/isNaN.js +++ b/isNaN.js @@ -3,11 +3,13 @@ define(['./isNumber'], function(isNumber) { /** * Checks if `value` is `NaN`. * - * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4) - * which returns `true` for `undefined` and other non-numeric values. + * **Note:** This method is not the same as + * [`isNaN`](https://es5.github.io/#x15.1.2.4) which returns `true` for + * `undefined` and other non-numeric values. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. @@ -27,7 +29,8 @@ define(['./isNumber'], function(isNumber) { */ function isNaN(value) { // An `NaN` primitive is the only value that is not equal to itself. - // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE. + // Perform the `toStringTag` check first to avoid errors with some + // ActiveX objects in IE. return isNumber(value) && value != +value; } diff --git a/isNative.js b/isNative.js index eeef4e41b..2a1b53358 100644 --- a/isNative.js +++ b/isNative.js @@ -3,7 +3,7 @@ define(['./isFunction', './_isHostObject', './isObjectLike'], function(isFunctio /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; - /** Used to detect host constructors (Safari > 5). */ + /** Used to detect host constructors (Safari). */ var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used for built-in method references. */ @@ -26,9 +26,11 @@ define(['./isFunction', './_isHostObject', './isObjectLike'], function(isFunctio * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. * @example * * _.isNative(Array.prototype.push); diff --git a/isNil.js b/isNil.js index 38b8af622..0007f6786 100644 --- a/isNil.js +++ b/isNil.js @@ -5,6 +5,7 @@ define([], function() { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is nullish, else `false`. diff --git a/isNull.js b/isNull.js index efcfab5ea..2b39266da 100644 --- a/isNull.js +++ b/isNull.js @@ -5,6 +5,7 @@ define([], function() { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `null`, else `false`. diff --git a/isNumber.js b/isNumber.js index eb466b2bc..fd76ee700 100644 --- a/isNumber.js +++ b/isNumber.js @@ -15,14 +15,16 @@ define(['./isObjectLike'], function(isObjectLike) { /** * Checks if `value` is classified as a `Number` primitive or object. * - * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified - * as numbers, use the `_.isFinite` method. + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are + * classified as numbers, use the `_.isFinite` method. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isNumber(3); diff --git a/isObject.js b/isObject.js index 7e9fed50f..78cf34876 100644 --- a/isObject.js +++ b/isObject.js @@ -6,6 +6,7 @@ define([], function() { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. diff --git a/isObjectLike.js b/isObjectLike.js index 8d3f5bdaf..bfa102ec6 100644 --- a/isObjectLike.js +++ b/isObjectLike.js @@ -6,6 +6,7 @@ define([], function() { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. diff --git a/isPlainObject.js b/isPlainObject.js index 0491de540..8f5760674 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -1,4 +1,4 @@ -define(['./_isHostObject', './isObjectLike'], function(isHostObject, isObjectLike) { +define(['./_getPrototype', './_isHostObject', './isObjectLike'], function(getPrototype, isHostObject, isObjectLike) { /** `Object#toString` result references. */ var objectTag = '[object Object]'; @@ -9,6 +9,9 @@ define(['./_isHostObject', './isObjectLike'], function(isHostObject, isObjectLik /** Used to resolve the decompiled source of functions. */ var funcToString = Function.prototype.toString; + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + /** Used to infer the `Object` constructor. */ var objectCtorString = funcToString.call(Object); @@ -18,18 +21,17 @@ define(['./_isHostObject', './isObjectLike'], function(isHostObject, isObjectLik */ var objectToString = objectProto.toString; - /** Built-in value references. */ - var getPrototypeOf = Object.getPrototypeOf; - /** * Checks if `value` is a plain object, that is, an object created by the * `Object` constructor or one with a `[[Prototype]]` of `null`. * * @static * @memberOf _ + * @since 0.8.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @returns {boolean} Returns `true` if `value` is a plain object, + * else `false`. * @example * * function Foo() { @@ -53,11 +55,11 @@ define(['./_isHostObject', './isObjectLike'], function(isHostObject, isObjectLik objectToString.call(value) != objectTag || isHostObject(value)) { return false; } - var proto = getPrototypeOf(value); + var proto = getPrototype(value); if (proto === null) { return true; } - var Ctor = proto.constructor; + var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; return (typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString); } diff --git a/isRegExp.js b/isRegExp.js index 7da1d82bb..88d018947 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -17,9 +17,11 @@ define(['./isObject'], function(isObject) { * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isRegExp(/abc/); diff --git a/isSafeInteger.js b/isSafeInteger.js index c315a93b8..595a66987 100644 --- a/isSafeInteger.js +++ b/isSafeInteger.js @@ -7,13 +7,16 @@ define(['./isInteger'], function(isInteger) { * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 * double precision number which isn't the result of a rounded unsafe integer. * - * **Note:** This method is based on [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). + * **Note:** This method is based on + * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. + * @returns {boolean} Returns `true` if `value` is a safe integer, + * else `false`. * @example * * _.isSafeInteger(3); diff --git a/isSet.js b/isSet.js index 6dde3d9b6..4e49e2869 100644 --- a/isSet.js +++ b/isSet.js @@ -8,9 +8,11 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isSet(new Set); diff --git a/isString.js b/isString.js index 9a1a85198..17bf98f41 100644 --- a/isString.js +++ b/isString.js @@ -16,10 +16,12 @@ define(['./isArray', './isObjectLike'], function(isArray, isObjectLike) { * Checks if `value` is classified as a `String` primitive or object. * * @static + * @since 0.1.0 * @memberOf _ * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isString('abc'); diff --git a/isSymbol.js b/isSymbol.js index 93d8de34c..74ded64f9 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -17,9 +17,11 @@ define(['./isObjectLike'], function(isObjectLike) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isSymbol(Symbol.iterator); diff --git a/isTypedArray.js b/isTypedArray.js index df4476057..1af5854cd 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -16,6 +16,7 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { weakMapTag = '[object WeakMap]'; var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', float32Tag = '[object Float32Array]', float64Tag = '[object Float64Array]', int8Tag = '[object Int8Array]', @@ -35,11 +36,12 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { typedArrayTags[uint32Tag] = true; typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = - typedArrayTags[dateTag] = typedArrayTags[errorTag] = - typedArrayTags[funcTag] = typedArrayTags[mapTag] = - typedArrayTags[numberTag] = typedArrayTags[objectTag] = - typedArrayTags[regexpTag] = typedArrayTags[setTag] = - typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; + typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = + typedArrayTags[errorTag] = typedArrayTags[funcTag] = + typedArrayTags[mapTag] = typedArrayTags[numberTag] = + typedArrayTags[objectTag] = typedArrayTags[regexpTag] = + typedArrayTags[setTag] = typedArrayTags[stringTag] = + typedArrayTags[weakMapTag] = false; /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -55,9 +57,11 @@ define(['./isLength', './isObjectLike'], function(isLength, isObjectLike) { * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isTypedArray(new Uint8Array); diff --git a/isUndefined.js b/isUndefined.js index 3ff95bcfd..abd66ec8e 100644 --- a/isUndefined.js +++ b/isUndefined.js @@ -7,6 +7,7 @@ define([], function() { * Checks if `value` is `undefined`. * * @static + * @since 0.1.0 * @memberOf _ * @category Lang * @param {*} value The value to check. diff --git a/isWeakMap.js b/isWeakMap.js index 83fecb1db..dda1cdef8 100644 --- a/isWeakMap.js +++ b/isWeakMap.js @@ -8,9 +8,11 @@ define(['./_getTag', './isObjectLike'], function(getTag, isObjectLike) { * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isWeakMap(new WeakMap); diff --git a/isWeakSet.js b/isWeakSet.js index 52eb3fd7c..e6fe04ded 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -17,9 +17,11 @@ define(['./isObjectLike'], function(isObjectLike) { * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isWeakSet(new WeakSet); diff --git a/iteratee.js b/iteratee.js index cea5c33e2..b3a8b3d26 100644 --- a/iteratee.js +++ b/iteratee.js @@ -2,12 +2,13 @@ define(['./_baseClone', './_baseIteratee'], function(baseClone, baseIteratee) { /** * Creates a function that invokes `func` with the arguments of the created - * function. If `func` is a property name the created callback returns the - * property value for a given element. If `func` is an object the created - * callback returns `true` for elements that contain the equivalent object - * properties, otherwise it returns `false`. + * function. If `func` is a property name the created function returns the + * property value for a given element. If `func` is an array or object the + * created function returns `true` for elements that contain the equivalent + * source properties, otherwise it returns `false`. * * @static + * @since 4.0.0 * @memberOf _ * @category Util * @param {*} [func=_.identity] The value to convert to a callback. @@ -15,20 +16,31 @@ define(['./_baseClone', './_baseIteratee'], function(baseClone, baseIteratee) { * @example * * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * + * // The `_.matches` iteratee shorthand. + * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true })); + * // => [{ 'user': 'barney', 'age': 36, 'active': true }] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.filter(users, _.iteratee(['user', 'fred'])); + * // => [{ 'user': 'fred', 'age': 40 }] + * + * // The `_.property` iteratee shorthand. + * _.map(users, _.iteratee('user')); + * // => ['barney', 'fred'] + * * // Create custom iteratee shorthands. - * _.iteratee = _.wrap(_.iteratee, function(callback, func) { - * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func); - * return !p ? callback(func) : function(object) { - * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]); + * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) { + * return !_.isRegExp(func) ? iteratee(func) : function(string) { + * return func.test(string); * }; * }); * - * _.filter(users, 'age > 36'); - * // => [{ 'user': 'fred', 'age': 40 }] + * _.filter(['abc', 'def'], /ef/); + * // => ['def'] */ function iteratee(func) { return baseIteratee(typeof func == 'function' ? func : baseClone(func, true)); diff --git a/join.js b/join.js index e9f8a9fbc..faa734fa9 100644 --- a/join.js +++ b/join.js @@ -11,6 +11,7 @@ define([], function() { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to convert. * @param {string} [separator=','] The element separator. diff --git a/kebabCase.js b/kebabCase.js index 649241059..173c22799 100644 --- a/kebabCase.js +++ b/kebabCase.js @@ -1,10 +1,12 @@ define(['./_createCompounder'], function(createCompounder) { /** - * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). + * Converts `string` to + * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the kebab cased string. @@ -16,7 +18,7 @@ define(['./_createCompounder'], function(createCompounder) { * _.kebabCase('fooBar'); * // => 'foo-bar' * - * _.kebabCase('__foo_bar__'); + * _.kebabCase('__FOO_BAR__'); * // => 'foo-bar' */ var kebabCase = createCompounder(function(result, word, index) { diff --git a/keyBy.js b/keyBy.js index 70d19d1a2..874f38bd2 100644 --- a/keyBy.js +++ b/keyBy.js @@ -8,9 +8,11 @@ define(['./_createAggregator'], function(createAggregator) { * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * diff --git a/keys.js b/keys.js index 43bf2cda9..5cdee8055 100644 --- a/keys.js +++ b/keys.js @@ -8,6 +8,7 @@ define(['./_baseHas', './_baseKeys', './_indexKeys', './isArrayLike', './_isInde * for more details. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. diff --git a/keysIn.js b/keysIn.js index da87e01f6..879dfe9ac 100644 --- a/keysIn.js +++ b/keysIn.js @@ -13,6 +13,7 @@ define(['./_baseKeysIn', './_indexKeys', './_isIndex', './_isPrototype'], functi * * @static * @memberOf _ + * @since 3.0.0 * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. diff --git a/last.js b/last.js index 7ba9866d8..ac5152af0 100644 --- a/last.js +++ b/last.js @@ -8,6 +8,7 @@ define([], function() { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to query. * @returns {*} Returns the last element of `array`. diff --git a/lastIndexOf.js b/lastIndexOf.js index ae2dc71f8..a51af701e 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -13,6 +13,7 @@ define(['./_indexOfNaN', './toInteger'], function(indexOfNaN, toInteger) { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. @@ -35,7 +36,11 @@ define(['./_indexOfNaN', './toInteger'], function(indexOfNaN, toInteger) { var index = length; if (fromIndex !== undefined) { index = toInteger(fromIndex); - index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1; + index = ( + index < 0 + ? nativeMax(length + index, 0) + : nativeMin(index, length - 1) + ) + 1; } if (value !== value) { return indexOfNaN(array, index, true); diff --git a/lowerCase.js b/lowerCase.js index f544df6bd..5cbf9dfdf 100644 --- a/lowerCase.js +++ b/lowerCase.js @@ -5,12 +5,13 @@ define(['./_createCompounder'], function(createCompounder) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the lower cased string. * @example * - * _.lowerCase('--Foo-Bar'); + * _.lowerCase('--Foo-Bar--'); * // => 'foo bar' * * _.lowerCase('fooBar'); diff --git a/lowerFirst.js b/lowerFirst.js index 48eef6e5f..8f43cbb59 100644 --- a/lowerFirst.js +++ b/lowerFirst.js @@ -5,6 +5,7 @@ define(['./_createCaseFirst'], function(createCaseFirst) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the converted string. diff --git a/lt.js b/lt.js index 4e3e84501..2d939ee9e 100644 --- a/lt.js +++ b/lt.js @@ -5,10 +5,12 @@ define([], function() { * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. * @example * * _.lt(1, 3); diff --git a/lte.js b/lte.js index 608e0d700..fa5fe65a2 100644 --- a/lte.js +++ b/lte.js @@ -5,10 +5,12 @@ define([], function() { * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is less than or equal to + * `other`, else `false`. * @example * * _.lte(1, 3); diff --git a/main.js b/main.js index 3e9dea8d3..d0cee56d0 100644 --- a/main.js +++ b/main.js @@ -1,11 +1,11 @@ /** * @license - * lodash 4.6.1 (Custom Build) + * lodash 4.7.0 (Custom Build) * Build: `lodash exports="amd" -d -o ./main.js` - * Copyright 2012-2016 The Dojo Foundation + * Copyright jQuery Foundation and other contributors + * Released under MIT license * Based on Underscore.js 1.8.3 - * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - * Available under MIT license + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */ ;(function() { @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.6.1'; + var VERSION = '4.7.0'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -78,6 +78,7 @@ mapTag = '[object Map]', numberTag = '[object Number]', objectTag = '[object Object]', + promiseTag = '[object Promise]', regexpTag = '[object RegExp]', setTag = '[object Set]', stringTag = '[object String]', @@ -86,6 +87,7 @@ weakSetTag = '[object WeakSet]'; var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', float32Tag = '[object Float32Array]', float64Tag = '[object Float64Array]', int8Tag = '[object Int8Array]', @@ -144,7 +146,7 @@ /** Used to detect binary string values. */ var reIsBinary = /^0b[01]+$/i; - /** Used to detect host constructors (Safari > 5). */ + /** Used to detect host constructors (Safari). */ var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used to detect octal string values. */ @@ -228,15 +230,15 @@ ].join('|'), 'g'); /** Used to detect strings that need a more robust regexp to match words. */ - var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; /** Used to assign default `context` object properties. */ var contextProps = [ - 'Array', 'Buffer', 'Date', 'Error', 'Float32Array', 'Float64Array', + 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', - 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', - 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_', - 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' + 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', + 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', + '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' ]; /** Used to make template sourceURLs easier to identify. */ @@ -251,25 +253,26 @@ typedArrayTags[uint32Tag] = true; typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = - typedArrayTags[dateTag] = typedArrayTags[errorTag] = - typedArrayTags[funcTag] = typedArrayTags[mapTag] = - typedArrayTags[numberTag] = typedArrayTags[objectTag] = - typedArrayTags[regexpTag] = typedArrayTags[setTag] = - typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; + typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = + typedArrayTags[errorTag] = typedArrayTags[funcTag] = + typedArrayTags[mapTag] = typedArrayTags[numberTag] = + typedArrayTags[objectTag] = typedArrayTags[regexpTag] = + typedArrayTags[setTag] = typedArrayTags[stringTag] = + typedArrayTags[weakMapTag] = false; /** Used to identify `toStringTag` values supported by `_.clone`. */ var cloneableTags = {}; cloneableTags[argsTag] = cloneableTags[arrayTag] = - cloneableTags[arrayBufferTag] = cloneableTags[boolTag] = - cloneableTags[dateTag] = cloneableTags[float32Tag] = - cloneableTags[float64Tag] = cloneableTags[int8Tag] = - cloneableTags[int16Tag] = cloneableTags[int32Tag] = - cloneableTags[mapTag] = cloneableTags[numberTag] = - cloneableTags[objectTag] = cloneableTags[regexpTag] = - cloneableTags[setTag] = cloneableTags[stringTag] = - cloneableTags[symbolTag] = cloneableTags[uint8Tag] = - cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = - cloneableTags[uint32Tag] = true; + cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = + cloneableTags[boolTag] = cloneableTags[dateTag] = + cloneableTags[float32Tag] = cloneableTags[float64Tag] = + cloneableTags[int8Tag] = cloneableTags[int16Tag] = + cloneableTags[int32Tag] = cloneableTags[mapTag] = + cloneableTags[numberTag] = cloneableTags[objectTag] = + cloneableTags[regexpTag] = cloneableTags[setTag] = + cloneableTags[stringTag] = cloneableTags[symbolTag] = + cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = + cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false; @@ -514,7 +517,8 @@ * @private * @param {Array} array The array to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. */ function arrayEvery(array, predicate) { var index = -1, @@ -633,7 +637,8 @@ * @param {Array} array The array to iterate over. * @param {Function} iteratee The function invoked per iteration. * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value. + * @param {boolean} [initAccum] Specify using the first element of `array` as + * the initial value. * @returns {*} Returns the accumulated value. */ function arrayReduce(array, iteratee, accumulator, initAccum) { @@ -657,7 +662,8 @@ * @param {Array} array The array to iterate over. * @param {Function} iteratee The function invoked per iteration. * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value. + * @param {boolean} [initAccum] Specify using the last element of `array` as + * the initial value. * @returns {*} Returns the accumulated value. */ function arrayReduceRight(array, iteratee, accumulator, initAccum) { @@ -678,7 +684,8 @@ * @private * @param {Array} array The array to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. */ function arraySome(array, predicate) { var index = -1, @@ -730,7 +737,8 @@ * @param {Array|Object} collection The collection to search. * @param {Function} predicate The function invoked per iteration. * @param {Function} eachFunc The function to iterate over `collection`. - * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself. + * @param {boolean} [retKey] Specify returning the key of the found element + * instead of the element itself. * @returns {*} Returns the found element or its key, else `undefined`. */ function baseFind(collection, predicate, eachFunc, retKey) { @@ -812,6 +820,20 @@ return -1; } + /** + * The base implementation of `_.mean` and `_.meanBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the mean. + */ + function baseMean(array, iteratee) { + var length = array ? array.length : 0; + return length ? (baseSum(array, iteratee) / length) : NAN; + } + /** * The base implementation of `_.reduce` and `_.reduceRight`, without support * for iteratee shorthands, which iterates over `collection` using `eachFunc`. @@ -820,7 +842,8 @@ * @param {Array|Object} collection The collection to iterate over. * @param {Function} iteratee The function invoked per iteration. * @param {*} accumulator The initial value. - * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value. + * @param {boolean} initAccum Specify using the first or last element of + * `collection` as the initial value. * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the accumulated value. */ @@ -854,7 +877,8 @@ } /** - * The base implementation of `_.sum` without support for iteratee shorthands. + * The base implementation of `_.sum` and `_.sumBy` without support for + * iteratee shorthands. * * @private * @param {Array} array The array to iterate over. @@ -1051,7 +1075,7 @@ // for more details. // // This also ensures a stable sort in V8 and other engines. - // See https://code.google.com/p/v8/issues/detail?id=90 for more details. + // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. return object.index - other.index; } @@ -1075,6 +1099,29 @@ return result; } + /** + * Creates a function that performs a mathematical operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @returns {Function} Returns the new mathematical operation function. + */ + function createMathOperation(operator) { + return function(value, other) { + var result; + if (value === undefined && other === undefined) { + return 0; + } + if (value !== undefined) { + result = value; + } + if (other !== undefined) { + result = result === undefined ? other : operator(result, other); + } + return result; + }; + } + /** * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters. * @@ -1286,6 +1333,7 @@ * * @static * @memberOf _ + * @since 1.1.0 * @category Util * @param {Object} [context=root] The context object. * @returns {Function} Returns a new `lodash` function. @@ -1364,7 +1412,6 @@ Uint8Array = context.Uint8Array, clearTimeout = context.clearTimeout, enumerate = Reflect ? Reflect.enumerate : undefined, - getPrototypeOf = Object.getPrototypeOf, getOwnPropertySymbols = Object.getOwnPropertySymbols, iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined, objectCreate = Object.create, @@ -1375,6 +1422,7 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeCeil = Math.ceil, nativeFloor = Math.floor, + nativeGetPrototype = Object.getPrototypeOf, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = Object.keys, @@ -1385,7 +1433,9 @@ nativeReverse = arrayProto.reverse; /* Built-in method references that are verified to be native. */ - var Map = getNative(context, 'Map'), + var DataView = getNative(context, 'DataView'), + Map = getNative(context, 'Map'), + Promise = getNative(context, 'Promise'), Set = getNative(context, 'Set'), WeakMap = getNative(context, 'WeakMap'), nativeCreate = getNative(Object, 'create'); @@ -1400,7 +1450,9 @@ var realNames = {}; /** Used to detect maps, sets, and weakmaps. */ - var mapCtorString = Map ? funcToString.call(Map) : '', + var dataViewCtorString = DataView ? (DataView + '') : '', + mapCtorString = Map ? funcToString.call(Map) : '', + promiseCtorString = Promise ? funcToString.call(Promise) : '', setCtorString = Set ? funcToString.call(Set) : '', weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : ''; @@ -1413,25 +1465,25 @@ /** * Creates a `lodash` object which wraps `value` to enable implicit method - * chaining. Methods that operate on and return arrays, collections, and - * functions can be chained together. Methods that retrieve a single value or - * may return a primitive value will automatically end the chain sequence and - * return the unwrapped value. Otherwise, the value must be unwrapped with - * `_#value`. + * chain sequences. Methods that operate on and return arrays, collections, + * and functions can be chained together. Methods that retrieve a single value + * or may return a primitive value will automatically end the chain sequence + * and return the unwrapped value. Otherwise, the value must be unwrapped + * with `_#value`. * - * Explicit chaining, which must be unwrapped with `_#value` in all cases, - * may be enabled using `_.chain`. + * Explicit chain sequences, which must be unwrapped with `_#value`, may be + * enabled using `_.chain`. * * The execution of chained methods is lazy, that is, it's deferred until * `_#value` is implicitly or explicitly called. * - * Lazy evaluation allows several methods to support shortcut fusion. Shortcut - * fusion is an optimization to merge iteratee calls; this avoids the creation - * of intermediate arrays and can greatly reduce the number of iteratee executions. - * Sections of a chain sequence qualify for shortcut fusion if the section is - * applied to an array of at least two hundred elements and any iteratees - * accept only one argument. The heuristic for whether a section qualifies - * for shortcut fusion is subject to change. + * Lazy evaluation allows several methods to support shortcut fusion. + * Shortcut fusion is an optimization to merge iteratee calls; this avoids + * the creation of intermediate arrays and can greatly reduce the number of + * iteratee executions. Sections of a chain sequence qualify for shortcut + * fusion if the section is applied to an array of at least two hundred + * elements and any iteratees accept only one argument. The heuristic for + * whether a section qualifies for shortcut fusion is subject to change. * * Chaining is supported in custom builds as long as the `_#value` method is * directly or indirectly included in the build. @@ -1456,48 +1508,49 @@ * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, - * `flatten`, `flattenDeep`, `flattenDepth`, `flip`, `flow`, `flowRight`, - * `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`, `intersection`, - * `intersectionBy`, `intersectionWith`, `invert`, `invertBy`, `invokeMap`, - * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, - * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`, - * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, - * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`, - * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`, - * `pullAll`, `pullAllBy`, `pullAllWith`, `pullAt`, `push`, `range`, - * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`, - * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, - * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, - * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, - * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, - * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `update`, `values`, - * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, - * `zipObjectDeep`, and `zipWith` + * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, + * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, + * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, + * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, + * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, + * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, + * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, + * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, + * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, + * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, + * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, + * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, + * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, + * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, + * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, + * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, + * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, + * `zipObject`, `zipObjectDeep`, and `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, - * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `each`, `eachRight`, - * `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, - * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`, `floor`, - * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, - * `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`, `includes`, - * `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`, `isArrayBuffer`, - * `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isBuffer`, `isDate`, - * `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`, `isFinite`, - * `isFunction`, `isInteger`, `isLength`, `isMap`, `isMatch`, `isMatchWith`, - * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`, - * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isSet`, `isString`, - * `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, - * `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, - * `maxBy`, `mean`, `min`, `minBy`, `noConflict`, `noop`, `now`, `pad`, - * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, - * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, - * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, - * `sortedLastIndexBy`, `startCase`, `startsWith`, `subtract`, `sum`, `sumBy`, - * `template`, `times`, `toInteger`, `toJSON`, `toLength`, `toLower`, - * `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, `trimEnd`, - * `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`, - * `value`, and `words` + * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`, + * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`, + * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`, + * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, + * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`, + * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`, + * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isBuffer`, + * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`, + * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`, `isMatch`, + * `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, + * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`, + * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`, + * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, + * `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`, + * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`, + * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`, + * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, + * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, + * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toInteger`, + * `toJSON`, `toLength`, `toLower`, `toNumber`, `toSafeInteger`, `toString`, + * `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, + * `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words` * * @name _ * @constructor @@ -1538,7 +1591,7 @@ } /** - * The function whose prototype all chaining wrappers inherit from. + * The function whose prototype chain sequence wrappers inherit from. * * @private */ @@ -1551,7 +1604,7 @@ * * @private * @param {*} value The value to wrap. - * @param {boolean} [chainAll] Enable chaining for all wrapper methods. + * @param {boolean} [chainAll] Enable explicit method chain sequences. */ function LodashWrapper(value, chainAll) { this.__wrapped__ = value; @@ -1622,6 +1675,13 @@ } }; + // Ensure wrappers are instances of `baseLodash`. + lodash.prototype = baseLodash.prototype; + lodash.prototype.constructor = lodash; + + LodashWrapper.prototype = baseCreate(baseLodash.prototype); + LodashWrapper.prototype.constructor = LodashWrapper; + /*------------------------------------------------------------------------*/ /** @@ -1738,6 +1798,10 @@ return result; } + // Ensure `LazyWrapper` is an instance of `baseLodash`. + LazyWrapper.prototype = baseCreate(baseLodash.prototype); + LazyWrapper.prototype.constructor = LazyWrapper; + /*------------------------------------------------------------------------*/ /** @@ -1801,6 +1865,9 @@ hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; } + // Avoid inheriting from `Object.prototype` when possible. + Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto; + /*------------------------------------------------------------------------*/ /** @@ -1895,7 +1962,7 @@ * @memberOf MapCache * @param {string} key The key of the value to set. * @param {*} value The value to set. - * @returns {Object} Returns the map cache object. + * @returns {Object} Returns the map cache instance. */ function mapSet(key, value) { var data = this.__data__; @@ -1909,6 +1976,13 @@ return this; } + // Add methods to `MapCache`. + MapCache.prototype.clear = mapClear; + MapCache.prototype['delete'] = mapDelete; + MapCache.prototype.get = mapGet; + MapCache.prototype.has = mapHas; + MapCache.prototype.set = mapSet; + /*------------------------------------------------------------------------*/ /** @@ -1969,6 +2043,9 @@ } } + // Add methods to `SetCache`. + SetCache.prototype.push = cachePush; + /*------------------------------------------------------------------------*/ /** @@ -2056,7 +2133,7 @@ * @memberOf Stack * @param {string} key The key of the value to set. * @param {*} value The value to set. - * @returns {Object} Returns the stack cache object. + * @returns {Object} Returns the stack cache instance. */ function stackSet(key, value) { var data = this.__data__, @@ -2077,13 +2154,20 @@ return this; } + // Add methods to `Stack`. + Stack.prototype.clear = stackClear; + Stack.prototype['delete'] = stackDelete; + Stack.prototype.get = stackGet; + Stack.prototype.has = stackHas; + Stack.prototype.set = stackSet; + /*------------------------------------------------------------------------*/ /** * Removes `key` and its value from the associative array. * * @private - * @param {Array} array The array to query. + * @param {Array} array The array to modify. * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ @@ -2127,8 +2211,7 @@ } /** - * Gets the index at which the first occurrence of `key` is found in `array` - * of key-value pairs. + * Gets the index at which the `key` is found in `array` of key-value pairs. * * @private * @param {Array} array The array to search. @@ -2272,7 +2355,7 @@ * * @private * @param {*} value The value to inspect. - * @returns {Array} Returns the array-like object. + * @returns {Array|Object} Returns the cast array-like object. */ function baseCastArrayLikeObject(value) { return isArrayLikeObject(value) ? value : []; @@ -2283,12 +2366,23 @@ * * @private * @param {*} value The value to inspect. - * @returns {Array} Returns the array-like object. + * @returns {Function} Returns cast function. */ function baseCastFunction(value) { return typeof value == 'function' ? value : identity; } + /** + * Casts `value` to a string if it's not a string or symbol. + * + * @private + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the cast key. + */ + function baseCastKey(key) { + return (typeof key == 'string' || isSymbol(key)) ? key : (key + ''); + } + /** * Casts `value` to a path array if it's not one. * @@ -2365,14 +2459,13 @@ } result = initCloneObject(isFunc ? {} : value); if (!isDeep) { - result = baseAssign(result, value); - return isFull ? copySymbols(value, result) : result; + return copySymbols(value, baseAssign(result, value)); } } else { if (!cloneableTags[tag]) { return object ? value : {}; } - result = initCloneByTag(value, tag, isDeep); + result = initCloneByTag(value, tag, baseClone, isDeep); } } // Check for circular references and return its corresponding clone. @@ -2383,11 +2476,18 @@ } stack.set(value, result); + if (!isArr) { + var props = isFull ? getAllKeys(value) : keys(value); + } // Recursively populate clone (susceptible to call stack limits). - (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) { + arrayEach(props || value, function(subValue, key) { + if (props) { + key = subValue; + subValue = value[key]; + } assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack)); }); - return (isFull && !isArr) ? copySymbols(value, result) : result; + return result; } /** @@ -2411,7 +2511,8 @@ predicate = source[key], value = object[key]; - if ((value === undefined && !(key in Object(object))) || !predicate(value)) { + if ((value === undefined && + !(key in Object(object))) || !predicate(value)) { return false; } } @@ -2449,8 +2550,8 @@ } /** - * The base implementation of methods like `_.difference` without support for - * excluding multiple arrays or iteratee shorthands. + * The base implementation of methods like `_.difference` without support + * for excluding multiple arrays or iteratee shorthands. * * @private * @param {Array} array The array to inspect. @@ -2529,7 +2630,8 @@ * @private * @param {Array|Object} collection The collection to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false` + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false` */ function baseEvery(collection, predicate) { var result = true; @@ -2620,10 +2722,9 @@ } /** - * The base implementation of `baseForIn` and `baseForOwn` which iterates - * over `object` properties returned by `keysFunc` invoking `iteratee` for - * each property. Iteratee functions may exit iteration early by explicitly - * returning `false`. + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` invoking `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. * * @private * @param {Object} object The object to iterate over. @@ -2645,18 +2746,6 @@ */ var baseForRight = createBaseFor(true); - /** - * The base implementation of `_.forIn` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. - */ - function baseForIn(object, iteratee) { - return object == null ? object : baseFor(object, iteratee, keysIn); - } - /** * The base implementation of `_.forOwn` without support for iteratee shorthands. * @@ -2705,7 +2794,7 @@ * @returns {*} Returns the resolved value. */ function baseGet(object, path) { - path = isKey(path, object) ? [path + ''] : baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); var index = 0, length = path.length; @@ -2716,6 +2805,24 @@ return (index && index == length) ? object : undefined; } + /** + * The base implementation of `getAllKeys` and `getAllKeysIn` which uses + * `keysFunc` and `symbolsFunc` to get the enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Function} keysFunc The function to get the keys of `object`. + * @param {Function} symbolsFunc The function to get the symbols of `object`. + * @returns {Array} Returns the array of property names and symbols. + */ + function baseGetAllKeys(object, keysFunc, symbolsFunc) { + var result = keysFunc(object); + return isArray(object) + ? result + : arrayPush(result, symbolsFunc(object)); + } + /** * The base implementation of `_.has` without support for deep paths. * @@ -2729,7 +2836,7 @@ // that are composed entirely of index properties, return `false` for // `hasOwnProperty` checks of them. return hasOwnProperty.call(object, key) || - (typeof object == 'object' && key in object && getPrototypeOf(object) === null); + (typeof object == 'object' && key in object && getPrototype(object) === null); } /** @@ -2892,7 +2999,8 @@ * @param {Object} other The other object to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} [customizer] The function to customize comparisons. - * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} [stack] Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ @@ -2925,8 +3033,11 @@ othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); if (objIsWrapped || othIsWrapped) { + var objUnwrapped = objIsWrapped ? object.value() : object, + othUnwrapped = othIsWrapped ? other.value() : other; + stack || (stack = new Stack); - return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack); + return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack); } } if (!isSameTag) { @@ -2975,9 +3086,10 @@ return false; } } else { - var stack = new Stack, - result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined; - + var stack = new Stack; + if (customizer) { + var result = customizer(objValue, srcValue, key, object, source, stack); + } if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result @@ -2997,14 +3109,15 @@ * @returns {Function} Returns the iteratee. */ function baseIteratee(value) { - var type = typeof value; - if (type == 'function') { + // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. + // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. + if (typeof value == 'function') { return value; } if (value == null) { return identity; } - if (type == 'object') { + if (typeof value == 'object') { return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value); @@ -3118,16 +3231,16 @@ * @param {Object} source The source object. * @param {number} srcIndex The index of `source`. * @param {Function} [customizer] The function to customize merged values. - * @param {Object} [stack] Tracks traversed source values and their merged counterparts. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. */ function baseMerge(object, source, srcIndex, customizer, stack) { if (object === source) { return; } - var props = (isArray(source) || isTypedArray(source)) - ? undefined - : keysIn(source); - + if (!(isArray(source) || isTypedArray(source))) { + var props = keysIn(source); + } arrayEach(props || source, function(srcValue, key) { if (props) { key = srcValue; @@ -3162,7 +3275,8 @@ * @param {number} srcIndex The index of `source`. * @param {Function} mergeFunc The function to merge values. * @param {Function} [customizer] The function to customize assigned values. - * @param {Object} [stack] Tracks traversed source values and their merged counterparts. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. */ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { var objValue = object[key], @@ -3190,7 +3304,7 @@ } else { isCommon = false; - newValue = baseClone(srcValue, !customizer); + newValue = baseClone(srcValue, true); } } else if (isPlainObject(srcValue) || isArguments(srcValue)) { @@ -3199,7 +3313,7 @@ } else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { isCommon = false; - newValue = baseClone(srcValue, !customizer); + newValue = baseClone(srcValue, true); } else { newValue = objValue; @@ -3230,7 +3344,7 @@ */ function baseOrderBy(collection, iteratees, orders) { var index = -1; - iteratees = arrayMap(iteratees.length ? iteratees : Array(1), getIteratee()); + iteratees = arrayMap(iteratees.length ? iteratees : [identity], getIteratee()); var result = baseMap(collection, function(value, key, collection) { var criteria = arrayMap(iteratees, function(iteratee) { @@ -3246,11 +3360,11 @@ /** * The base implementation of `_.pick` without support for individual - * property names. + * property identifiers. * * @private * @param {Object} object The source object. - * @param {string[]} props The property names to pick. + * @param {string[]} props The property identifiers to pick. * @returns {Object} Returns the new object. */ function basePick(object, props) { @@ -3272,12 +3386,19 @@ * @returns {Object} Returns the new object. */ function basePickBy(object, predicate) { - var result = {}; - baseForIn(object, function(value, key) { + var index = -1, + props = getAllKeysIn(object), + length = props.length, + result = {}; + + while (++index < length) { + var key = props[index], + value = object[key]; + if (predicate(value, key)) { result[key] = value; } - }); + } return result; } @@ -3414,6 +3535,34 @@ return result; } + /** + * The base implementation of `_.repeat` which doesn't coerce arguments. + * + * @private + * @param {string} string The string to repeat. + * @param {number} n The number of times to repeat the string. + * @returns {string} Returns the repeated string. + */ + function baseRepeat(string, n) { + var result = ''; + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result; + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string; + } + n = nativeFloor(n / 2); + if (n) { + string += string; + } + } while (n); + + return result; + } + /** * The base implementation of `_.set`. * @@ -3425,7 +3574,7 @@ * @returns {Object} Returns `object`. */ function baseSet(object, path, value, customizer) { - path = isKey(path, object) ? [path + ''] : baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); var index = -1, length = path.length, @@ -3501,7 +3650,8 @@ * @private * @param {Array|Object} collection The collection to iterate over. * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. */ function baseSome(collection, predicate) { var result; @@ -3555,7 +3705,8 @@ * @param {*} value The value to evaluate. * @param {Function} iteratee The iteratee invoked per element. * @param {boolean} [retHighest] Specify returning the highest qualified index. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. */ function baseSortedIndexBy(array, value, iteratee, retHighest) { value = iteratee(value); @@ -3702,7 +3853,7 @@ * @returns {boolean} Returns `true` if the property is deleted, else `false`. */ function baseUnset(object, path) { - path = isKey(path, object) ? [path + ''] : baseCastPath(path); + path = isKey(path, object) ? [path] : baseCastPath(path); object = parent(object, path); var key = last(path); return (object != null && has(object, key)) ? delete object[key] : true; @@ -3794,7 +3945,7 @@ * This base implementation of `_.zipObject` which assigns values using `assignFunc`. * * @private - * @param {Array} props The property names. + * @param {Array} props The property identifiers. * @param {Array} values The property values. * @param {Function} assignFunc The function to assign values. * @returns {Object} Returns the new object. @@ -3806,7 +3957,8 @@ result = {}; while (++index < length) { - assignFunc(result, props[index], index < valsLength ? values[index] : undefined); + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); } return result; } @@ -3841,15 +3993,31 @@ return result; } + /** + * Creates a clone of `dataView`. + * + * @private + * @param {Object} dataView The data view to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned data view. + */ + function cloneDataView(dataView, isDeep) { + var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; + return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); + } + /** * Creates a clone of `map`. * * @private * @param {Object} map The map to clone. + * @param {Function} cloneFunc The function to clone values. + * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the cloned map. */ - function cloneMap(map) { - return arrayReduce(mapToArray(map), addMapEntry, new map.constructor); + function cloneMap(map, isDeep, cloneFunc) { + var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map); + return arrayReduce(array, addMapEntry, new map.constructor); } /** @@ -3870,10 +4038,13 @@ * * @private * @param {Object} set The set to clone. + * @param {Function} cloneFunc The function to clone values. + * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the cloned set. */ - function cloneSet(set) { - return arrayReduce(setToArray(set), addSetEntry, new set.constructor); + function cloneSet(set, isDeep, cloneFunc) { + var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set); + return arrayReduce(array, addSetEntry, new set.constructor); } /** @@ -3996,7 +4167,7 @@ * * @private * @param {Object} source The object to copy properties from. - * @param {Array} props The property names to copy. + * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. * @returns {Object} Returns `object`. */ @@ -4010,7 +4181,7 @@ * * @private * @param {Object} source The object to copy properties from. - * @param {Array} props The property names to copy. + * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. * @param {Function} [customizer] The function to customize copied values. * @returns {Object} Returns `object`. @@ -4125,7 +4296,7 @@ } /** - * Creates a base function for methods like `_.forIn`. + * Creates a base function for methods like `_.forIn` and `_.forOwn`. * * @private * @param {boolean} [fromRight] Specify iterating from right to left. @@ -4154,7 +4325,8 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {*} [thisArg] The `this` binding of `func`. * @returns {Function} Returns the new wrapped function. */ @@ -4242,7 +4414,8 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {number} arity The arity of `func`. * @returns {Function} Returns the new wrapped function. */ @@ -4314,7 +4487,9 @@ ) { wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); } else { - wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); + wrapper = (func.length == 1 && isLaziable(func)) + ? wrapper[funcName]() + : wrapper.thru(func); } } return function() { @@ -4342,11 +4517,14 @@ * * @private * @param {Function|string} func The function or method name to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to prepend to those provided to the new function. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. * @param {Array} [holders] The `partials` placeholder indexes. - * @param {Array} [partialsRight] The arguments to append to those provided to the new function. + * @param {Array} [partialsRight] The arguments to append to those provided + * to the new function. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. * @param {Array} [argPos] The argument positions of the new function. * @param {number} [ary] The arity cap of `func`. @@ -4445,25 +4623,21 @@ * is truncated if the number of characters exceeds `length`. * * @private - * @param {string} string The string to create padding for. - * @param {number} [length=0] The padding length. + * @param {number} length The padding length. * @param {string} [chars=' '] The string used as padding. * @returns {string} Returns the padding for `string`. */ - function createPadding(string, length, chars) { - length = toInteger(length); - - var strLength = stringSize(string); - if (!length || strLength >= length) { - return ''; - } - var padLength = length - strLength; + function createPadding(length, chars) { chars = chars === undefined ? ' ' : (chars + ''); - var result = repeat(chars, nativeCeil(padLength / stringSize(chars))); + var charsLength = chars.length; + if (charsLength < 2) { + return charsLength ? baseRepeat(chars, length) : chars; + } + var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); return reHasComplexSymbol.test(chars) - ? stringToArray(result).slice(0, padLength).join('') - : result.slice(0, padLength); + ? stringToArray(result).slice(0, length).join('') + : result.slice(0, length); } /** @@ -4473,9 +4647,11 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {*} thisArg The `this` binding of `func`. - * @param {Array} partials The arguments to prepend to those provided to the new function. + * @param {Array} partials The arguments to prepend to those provided to + * the new function. * @returns {Function} Returns the new wrapped function. */ function createPartialWrapper(func, bitmask, thisArg, partials) { @@ -4532,11 +4708,13 @@ * * @private * @param {Function} func The function to wrap. - * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. + * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` + * for more details. * @param {Function} wrapFunc The function to create the `func` wrapper. * @param {*} placeholder The placeholder value. * @param {*} [thisArg] The `this` binding of `func`. - * @param {Array} [partials] The arguments to prepend to those provided to the new function. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. * @param {Array} [holders] The `partials` placeholder indexes. * @param {Array} [argPos] The argument positions of the new function. * @param {number} [ary] The arity cap of `func`. @@ -4695,7 +4873,8 @@ * @param {Array} other The other array to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} stack Tracks traversed `array` and `other` objects. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. */ @@ -4737,12 +4916,16 @@ // Recursively compare arrays (susceptible to call stack limits). if (isUnordered) { if (!arraySome(other, function(othValue) { - return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack); + return arrValue === othValue || + equalFunc(arrValue, othValue, customizer, bitmask, stack); })) { result = false; break; } - } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) { + } else if (!( + arrValue === othValue || + equalFunc(arrValue, othValue, customizer, bitmask, stack) + )) { result = false; break; } @@ -4764,12 +4947,21 @@ * @param {string} tag The `toStringTag` of the objects to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} stack Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { switch (tag) { + case dataViewTag: + if ((object.byteLength != other.byteLength) || + (object.byteOffset != other.byteOffset)) { + return false; + } + object = object.buffer; + other = other.buffer; + case arrayBufferTag: if ((object.byteLength != other.byteLength) || !equalFunc(new Uint8Array(object), new Uint8Array(other))) { @@ -4779,8 +4971,9 @@ case boolTag: case dateTag: - // Coerce dates and booleans to numbers, dates to milliseconds and booleans - // to `1` or `0` treating invalid dates coerced to `NaN` as not equal. + // Coerce dates and booleans to numbers, dates to milliseconds and + // booleans to `1` or `0` treating invalid dates coerced to `NaN` as + // not equal. return +object == +other; case errorTag: @@ -4792,8 +4985,8 @@ case regexpTag: case stringTag: - // Coerce regexes to strings and treat strings primitives and string - // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details. + // Coerce regexes to strings and treat strings, primitives and objects, + // as equal. See https://es5.github.io/#x15.10.6.4 for more details. return object == (other + ''); case mapTag: @@ -4811,8 +5004,11 @@ if (stacked) { return stacked == other; } + bitmask |= UNORDERED_COMPARE_FLAG; + stack.set(object, other); + // Recursively compare objects (susceptible to call stack limits). - return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask | UNORDERED_COMPARE_FLAG, stack.set(object, other)); + return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); case symbolTag: if (symbolValueOf) { @@ -4831,7 +5027,8 @@ * @param {Object} other The other object to compare. * @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` for more details. + * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` + * for more details. * @param {Object} stack Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ @@ -4897,6 +5094,29 @@ return result; } + /** + * Creates an array of own enumerable property names and symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeys(object) { + return baseGetAllKeys(object, keys, getSymbols); + } + + /** + * Creates an array of own and inherited enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeysIn(object) { + return baseGetAllKeys(object, keysIn, getSymbolsIn); + } + /** * Gets metadata for `func`. * @@ -4950,8 +5170,9 @@ /** * Gets the "length" property value of `object`. * - * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) - * that affects Safari on at least iOS 8.1-8.3 ARM64. + * **Note:** This function is used to avoid a + * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects + * Safari on at least iOS 8.1-8.3 ARM64. * * @private * @param {Object} object The object to query. @@ -5002,14 +5223,51 @@ } /** - * Creates an array of the own symbol properties of `object`. + * Gets the `[[Prototype]]` of `value`. + * + * @private + * @param {*} value The value to query. + * @returns {null|Object} Returns the `[[Prototype]]`. + */ + function getPrototype(value) { + return nativeGetPrototype(Object(value)); + } + + /** + * Creates an array of the own enumerable symbol properties of `object`. * * @private * @param {Object} object The object to query. * @returns {Array} Returns the array of symbols. */ - var getSymbols = getOwnPropertySymbols || function() { - return []; + function getSymbols(object) { + // Coerce `object` to an object to avoid non-object errors in V8. + // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details. + return getOwnPropertySymbols(Object(object)); + } + + // Fallback for IE < 11. + if (!getOwnPropertySymbols) { + getSymbols = function() { + return []; + }; + } + + /** + * Creates an array of the own and inherited enumerable symbol properties + * of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ + var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) { + var result = []; + while (object) { + arrayPush(result, getSymbols(object)); + object = getPrototype(object); + } + return result; }; /** @@ -5023,8 +5281,11 @@ return objectToString.call(value); } - // Fallback for IE 11 providing `toStringTag` values for maps, sets, and weakmaps. - if ((Map && getTag(new Map) != mapTag) || + // Fallback for data views, maps, sets, and weak maps in IE 11, + // for data views in Edge, and promises in Node.js. + if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || + (Map && getTag(new Map) != mapTag) || + (Promise && getTag(Promise.resolve()) != promiseTag) || (Set && getTag(new Set) != setTag) || (WeakMap && getTag(new WeakMap) != weakMapTag)) { getTag = function(value) { @@ -5034,7 +5295,9 @@ if (ctorString) { switch (ctorString) { + case dataViewCtorString: return dataViewTag; case mapCtorString: return mapTag; + case promiseCtorString: return promiseTag; case setCtorString: return setTag; case weakMapCtorString: return weakMapTag; } @@ -5087,10 +5350,16 @@ var result = hasFunc(object, path); if (!result && !isKey(path)) { path = baseCastPath(path); - object = parent(object, path); - if (object != null) { - path = last(path); - result = hasFunc(object, path); + + var index = -1, + length = path.length; + + while (object != null && ++index < length) { + var key = path[index]; + if (!(result = hasFunc(object, key))) { + break; + } + object = object[key]; } } var length = object ? object.length : undefined; @@ -5128,7 +5397,7 @@ */ function initCloneObject(object) { return (typeof object.constructor == 'function' && !isPrototype(object)) - ? baseCreate(getPrototypeOf(object)) + ? baseCreate(getPrototype(object)) : {}; } @@ -5141,10 +5410,11 @@ * @private * @param {Object} object The object to clone. * @param {string} tag The `toStringTag` of the object to clone. + * @param {Function} cloneFunc The function to clone values. * @param {boolean} [isDeep] Specify a deep clone. * @returns {Object} Returns the initialized clone. */ - function initCloneByTag(object, tag, isDeep) { + function initCloneByTag(object, tag, cloneFunc, isDeep) { var Ctor = object.constructor; switch (tag) { case arrayBufferTag: @@ -5154,13 +5424,16 @@ case dateTag: return new Ctor(+object); + case dataViewTag: + return cloneDataView(object, isDeep); + case float32Tag: case float64Tag: case int8Tag: case int16Tag: case int32Tag: case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: return cloneTypedArray(object, isDeep); case mapTag: - return cloneMap(object); + return cloneMap(object, isDeep, cloneFunc); case numberTag: case stringTag: @@ -5170,7 +5443,7 @@ return cloneRegExp(object); case setTag: - return cloneSet(object); + return cloneSet(object, isDeep, cloneFunc); case symbolTag: return cloneSymbol(object); @@ -5201,7 +5474,8 @@ * @param {*} value The potential iteratee value argument. * @param {*} index The potential iteratee index or key argument. * @param {*} object The potential iteratee object argument. - * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. */ function isIterateeCall(value, index, object) { if (!isObject(object)) { @@ -5209,8 +5483,9 @@ } var type = typeof index; if (type == 'number' - ? (isArrayLike(object) && isIndex(index, object.length)) - : (type == 'string' && index in object)) { + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { return eq(object[index], value); } return false; @@ -5225,11 +5500,12 @@ * @returns {boolean} Returns `true` if `value` is a property name, else `false`. */ function isKey(value, object) { - if (typeof value == 'number') { + var type = typeof value; + if (type == 'number' || type == 'symbol') { return true; } return !isArray(value) && - (reIsPlainProp.test(value) || !reIsDeepProp.test(value) || + (isSymbol(value) || reIsPlainProp.test(value) || !reIsDeepProp.test(value) || (object != null && value in Object(object))); } @@ -5251,7 +5527,8 @@ * * @private * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`. + * @returns {boolean} Returns `true` if `func` has a lazy counterpart, + * else `false`. */ function isLaziable(func) { var funcName = getFuncName(func), @@ -5298,10 +5575,11 @@ * * Merging metadata reduces the number of wrappers used to invoke a function. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` - * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg` - * modify function arguments, making the order in which they are executed important, - * preventing the merging of metadata. However, we make an exception for a safe - * combined case where curried functions have `_.ary` and or `_.rearg` applied. + * may be applied regardless of execution order. Methods like `_.ary` and + * `_.rearg` modify function arguments, making the order in which they are + * executed important, preventing the merging of metadata. However, we make + * an exception for a safe combined case where curried functions have `_.ary` + * and or `_.rearg` applied. * * @private * @param {Array} data The destination metadata. @@ -5372,7 +5650,8 @@ * @param {string} key The key of the property to merge. * @param {Object} object The parent object of `objValue`. * @param {Object} source The parent object of `srcValue`. - * @param {Object} [stack] Tracks traversed source values and their merged counterparts. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. * @returns {*} Returns the value to assign. */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { @@ -5391,7 +5670,7 @@ * @returns {*} Returns the parent value. */ function parent(object, path) { - return path.length == 1 ? object : get(object, baseSlice(path, 0, -1)); + return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); } /** @@ -5420,8 +5699,9 @@ * Sets metadata for `func`. * * **Note:** If this function becomes hot, i.e. is invoked a lot in a short - * period of time, it will trip its breaker and transition to an identity function - * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070) + * period of time, it will trip its breaker and transition to an identity + * function to avoid garbage collection pauses in V8. See + * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) * for more details. * * @private @@ -5456,13 +5736,13 @@ * @param {string} string The string to convert. * @returns {Array} Returns the property path array. */ - function stringToPath(string) { + var stringToPath = memoize(function(string) { var result = []; toString(string).replace(rePropName, function(match, number, quote, string) { result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); }); return result; - } + }); /** * Creates a clone of `wrapper`. @@ -5491,6 +5771,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to process. * @param {number} [size=0] The length of each chunk. @@ -5526,6 +5807,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to compact. * @returns {Array} Returns the new array of filtered values. @@ -5555,6 +5837,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to concatenate. * @param {...*} [values] The values to concatenate. @@ -5570,22 +5853,29 @@ * console.log(array); * // => [1] */ - var concat = rest(function(array, values) { - if (!isArray(array)) { - array = array == null ? [] : [Object(array)]; + function concat() { + var length = arguments.length, + array = castArray(arguments[0]); + + if (length < 2) { + return length ? copyArray(array) : []; } - values = baseFlatten(values, 1); - return arrayConcat(array, values); - }); + var args = Array(length - 1); + while (length--) { + args[length - 1] = arguments[length]; + } + return arrayConcat(array, baseFlatten(args, 1)); + } /** - * Creates an array of unique `array` values not included in the other - * given arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Creates an array of unique `array` values not included in the other given + * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * for equality comparisons. The order of result values is determined by the * order they occur in the first array. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. @@ -5609,10 +5899,12 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of filtered values. * @example * @@ -5641,6 +5933,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. @@ -5668,10 +5961,11 @@ * * @static * @memberOf _ + * @since 0.5.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * @@ -5701,10 +5995,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * @@ -5737,9 +6032,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -5777,9 +6074,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -5818,6 +6117,7 @@ * * @static * @memberOf _ + * @since 3.2.0 * @category Array * @param {Array} array The array to fill. * @param {*} value The value to fill `array` with. @@ -5856,9 +6156,11 @@ * * @static * @memberOf _ + * @since 1.1.0 * @category Array * @param {Array} array The array to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {number} Returns the index of the found element, else `-1`. * @example * @@ -5895,9 +6197,11 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Array * @param {Array} array The array to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {number} Returns the index of the found element, else `-1`. * @example * @@ -5933,6 +6237,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. @@ -5951,6 +6256,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to flatten. * @returns {Array} Returns the new flattened array. @@ -5969,6 +6275,7 @@ * * @static * @memberOf _ + * @since 4.4.0 * @category Array * @param {Array} array The array to flatten. * @param {number} [depth=1] The maximum recursion depth. @@ -5998,6 +6305,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} pairs The key-value pairs. * @returns {Object} Returns the new object. @@ -6023,6 +6331,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @alias first * @category Array * @param {Array} array The array to query. @@ -6047,6 +6356,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. @@ -6078,6 +6388,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to query. * @returns {Array} Returns the slice of `array`. @@ -6098,6 +6409,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of intersecting values. @@ -6121,9 +6433,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of intersecting values. * @example * @@ -6156,6 +6470,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. @@ -6187,6 +6502,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to convert. * @param {string} [separator=','] The element separator. @@ -6205,6 +6521,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to query. * @returns {*} Returns the last element of `array`. @@ -6224,6 +6541,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. @@ -6246,7 +6564,11 @@ var index = length; if (fromIndex !== undefined) { index = toInteger(fromIndex); - index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1; + index = ( + index < 0 + ? nativeMax(length + index, 0) + : nativeMin(index, length - 1) + ) + 1; } if (value !== value) { return indexOfNaN(array, index, true); @@ -6269,6 +6591,7 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Array * @param {Array} array The array to modify. * @param {...*} [values] The values to remove. @@ -6290,6 +6613,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. @@ -6317,10 +6641,12 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns `array`. * @example * @@ -6345,6 +6671,7 @@ * * @static * @memberOf _ + * @since 4.6.0 * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. @@ -6372,6 +6699,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to modify. * @param {...(number|number[])} [indexes] The indexes of elements to remove, @@ -6406,9 +6734,11 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Array * @param {Array} array The array to modify. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new array of removed elements. * @example * @@ -6453,7 +6783,9 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array + * @param {Array} array The array to modify. * @returns {Array} Returns `array`. * @example * @@ -6472,11 +6804,13 @@ /** * Creates a slice of `array` from `start` up to, but not including, `end`. * - * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice) - * to ensure dense arrays are returned. + * **Note:** This method is used instead of + * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are + * returned. * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to slice. * @param {number} [start=0] The start position. @@ -6500,15 +6834,17 @@ } /** - * Uses a binary search to determine the lowest index at which `value` should - * be inserted into `array` in order to maintain its sort order. + * Uses a binary search to determine the lowest index at which `value` + * should be inserted into `array` in order to maintain its sort order. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * _.sortedIndex([30, 50], 40); @@ -6528,11 +6864,14 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 }; @@ -6554,6 +6893,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. @@ -6581,10 +6921,12 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * _.sortedLastIndex([4, 5], 4); @@ -6601,11 +6943,14 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * // The `_.property` iteratee shorthand. @@ -6622,6 +6967,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. @@ -6648,6 +6994,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @returns {Array} Returns the new duplicate free array. @@ -6668,6 +7015,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {Function} [iteratee] The iteratee invoked per element. @@ -6688,6 +7036,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to query. * @returns {Array} Returns the slice of `array`. @@ -6705,10 +7054,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * @@ -6737,10 +7087,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * @@ -6768,14 +7119,16 @@ /** * Creates a slice of `array` with elements taken from the end. Elements are - * taken until `predicate` returns falsey. The predicate is invoked with three - * arguments: (value, index, array). + * taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -6813,9 +7166,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * @@ -6853,6 +7208,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of combined values. @@ -6867,14 +7223,17 @@ /** * This method is like `_.union` except that it accepts `iteratee` which is - * invoked for each element of each `arrays` to generate the criterion by which - * uniqueness is computed. The iteratee is invoked with one argument: (value). + * invoked for each element of each `arrays` to generate the criterion by + * which uniqueness is computed. The iteratee is invoked with one argument: + * (value). * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of combined values. * @example * @@ -6900,6 +7259,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. @@ -6923,11 +7283,12 @@ /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) - * for equality comparisons, in which only the first occurrence of each element - * is kept. + * for equality comparisons, in which only the first occurrence of each + * element is kept. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to inspect. * @returns {Array} Returns the new duplicate free array. @@ -6949,9 +7310,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. * @example * @@ -6975,6 +7338,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {Function} [comparator] The comparator invoked per element. @@ -6999,6 +7363,7 @@ * * @static * @memberOf _ + * @since 1.2.0 * @category Array * @param {Array} array The array of grouped elements to process. * @returns {Array} Returns the new array of regrouped elements. @@ -7033,9 +7398,11 @@ * * @static * @memberOf _ + * @since 3.8.0 * @category Array * @param {Array} array The array of grouped elements to process. - * @param {Function} [iteratee=_.identity] The function to combine regrouped values. + * @param {Function} [iteratee=_.identity] The function to combine + * regrouped values. * @returns {Array} Returns the new array of regrouped elements. * @example * @@ -7065,6 +7432,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to filter. * @param {...*} [values] The values to exclude. @@ -7081,12 +7449,14 @@ }); /** - * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) + * Creates an array of unique values that is the + * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) * of the given arrays. The order of result values is determined by the order * they occur in the arrays. * * @static * @memberOf _ + * @since 2.4.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of values. @@ -7101,14 +7471,17 @@ /** * This method is like `_.xor` except that it accepts `iteratee` which is - * invoked for each element of each `arrays` to generate the criterion by which - * by which they're compared. The iteratee is invoked with one argument: (value). + * invoked for each element of each `arrays` to generate the criterion by + * which by which they're compared. The iteratee is invoked with one argument: + * (value). * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of values. * @example * @@ -7134,6 +7507,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. @@ -7155,12 +7529,13 @@ }); /** - * Creates an array of grouped elements, the first of which contains the first - * elements of the given arrays, the second of which contains the second elements - * of the given arrays, and so on. + * Creates an array of grouped elements, the first of which contains the + * first elements of the given arrays, the second of which contains the + * second elements of the given arrays, and so on. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {...Array} [arrays] The arrays to process. * @returns {Array} Returns the new array of grouped elements. @@ -7173,12 +7548,13 @@ /** * This method is like `_.fromPairs` except that it accepts two arrays, - * one of property names and one of corresponding values. + * one of property identifiers and one of corresponding values. * * @static * @memberOf _ + * @since 0.4.0 * @category Array - * @param {Array} [props=[]] The property names. + * @param {Array} [props=[]] The property identifiers. * @param {Array} [values=[]] The property values. * @returns {Object} Returns the new object. * @example @@ -7195,8 +7571,9 @@ * * @static * @memberOf _ + * @since 4.1.0 * @category Array - * @param {Array} [props=[]] The property names. + * @param {Array} [props=[]] The property identifiers. * @param {Array} [values=[]] The property values. * @returns {Object} Returns the new object. * @example @@ -7215,6 +7592,7 @@ * * @static * @memberOf _ + * @since 3.8.0 * @category Array * @param {...Array} [arrays] The arrays to process. * @param {Function} [iteratee=_.identity] The function to combine grouped values. @@ -7237,11 +7615,13 @@ /*------------------------------------------------------------------------*/ /** - * Creates a `lodash` object that wraps `value` with explicit method chaining enabled. - * The result of such method chaining must be unwrapped with `_#value`. + * Creates a `lodash` wrapper instance that wraps `value` with explicit method + * chain sequences enabled. The result of such sequences must be unwrapped + * with `_#value`. * * @static * @memberOf _ + * @since 1.3.0 * @category Seq * @param {*} value The value to wrap. * @returns {Object} Returns the new `lodash` wrapper instance. @@ -7272,10 +7652,11 @@ /** * This method invokes `interceptor` and returns `value`. The interceptor * is invoked with one argument; (value). The purpose of this method is to - * "tap into" a method chain in order to modify intermediate results. + * "tap into" a method chain sequence in order to modify intermediate results. * * @static * @memberOf _ + * @since 0.1.0 * @category Seq * @param {*} value The value to provide to `interceptor`. * @param {Function} interceptor The function to invoke. @@ -7299,10 +7680,11 @@ /** * This method is like `_.tap` except that it returns the result of `interceptor`. * The purpose of this method is to "pass thru" values replacing intermediate - * results in a method chain. + * results in a method chain sequence. * * @static * @memberOf _ + * @since 3.0.0 * @category Seq * @param {*} value The value to provide to `interceptor`. * @param {Function} interceptor The function to invoke. @@ -7327,6 +7709,7 @@ * * @name at * @memberOf _ + * @since 1.0.0 * @category Seq * @param {...(string|string[])} [paths] The property paths of elements to pick, * specified individually or in arrays. @@ -7367,10 +7750,11 @@ }); /** - * Enables explicit method chaining on the wrapper object. + * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. * * @name chain * @memberOf _ + * @since 0.1.0 * @category Seq * @returns {Object} Returns the new `lodash` wrapper instance. * @example @@ -7397,10 +7781,11 @@ } /** - * Executes the chained sequence and returns the wrapped result. + * Executes the chain sequence and returns the wrapped result. * * @name commit * @memberOf _ + * @since 3.2.0 * @category Seq * @returns {Object} Returns the new `lodash` wrapper instance. * @example @@ -7425,33 +7810,13 @@ return new LodashWrapper(this.value(), this.__chain__); } - /** - * This method is the wrapper version of `_.flatMap`. - * - * @name flatMap - * @memberOf _ - * @category Seq - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * function duplicate(n) { - * return [n, n]; - * } - * - * _([1, 2]).flatMap(duplicate).value(); - * // => [1, 1, 2, 2] - */ - function wrapperFlatMap(iteratee) { - return this.map(iteratee).flatten(); - } - /** * Gets the next value on a wrapped object following the * [iterator protocol](https://mdn.io/iteration_protocols#iterator). * * @name next * @memberOf _ + * @since 4.0.0 * @category Seq * @returns {Object} Returns the next iterator value. * @example @@ -7482,6 +7847,7 @@ * * @name Symbol.iterator * @memberOf _ + * @since 4.0.0 * @category Seq * @returns {Object} Returns the wrapper object. * @example @@ -7499,10 +7865,11 @@ } /** - * Creates a clone of the chained sequence planting `value` as the wrapped value. + * Creates a clone of the chain sequence planting `value` as the wrapped value. * * @name plant * @memberOf _ + * @since 3.2.0 * @category Seq * @param {*} value The value to plant. * @returns {Object} Returns the new `lodash` wrapper instance. @@ -7548,6 +7915,7 @@ * * @name reverse * @memberOf _ + * @since 0.1.0 * @category Seq * @returns {Object} Returns the new `lodash` wrapper instance. * @example @@ -7579,10 +7947,11 @@ } /** - * Executes the chained sequence to extract the unwrapped value. + * Executes the chain sequence to resolve the unwrapped value. * * @name value * @memberOf _ + * @since 0.1.0 * @alias toJSON, valueOf * @category Seq * @returns {*} Returns the resolved unwrapped value. @@ -7605,9 +7974,11 @@ * * @static * @memberOf _ + * @since 0.5.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * @@ -7628,19 +7999,22 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. - * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. + * @param {Array|Function|Object|string} [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`. * @example * * _.every([true, 1, null, 'yes'], Boolean); * // => false * * var users = [ - * { 'user': 'barney', 'active': false }, - * { 'user': 'fred', 'active': false } + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * * // The `_.matches` iteratee shorthand. @@ -7665,14 +8039,16 @@ /** * Iterates over elements of `collection`, returning an array of all elements - * `predicate` returns truthy for. The predicate is invoked with three arguments: - * (value, index|key, collection). + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @example * @@ -7703,14 +8079,16 @@ /** * Iterates over elements of `collection`, returning the first element - * `predicate` returns truthy for. The predicate is invoked with three arguments: - * (value, index|key, collection). + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {*} Returns the matched element, else `undefined`. * @example * @@ -7750,9 +8128,11 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {*} Returns the matched element, else `undefined`. * @example * @@ -7771,15 +8151,17 @@ } /** - * Creates an array of flattened values by running each element in `collection` - * through `iteratee` and concating its result to the other mapped values. - * The iteratee is invoked with three arguments: (value, index|key, collection). + * Creates a flattened array of values by running each element in `collection` + * through `iteratee` and flattening the mapped results. The iteratee is + * invoked with three arguments: (value, index|key, collection). * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new flattened array. * @example * @@ -7794,17 +8176,70 @@ return baseFlatten(map(collection, iteratee), 1); } + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDeep([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMapDeep(collection, iteratee) { + return baseFlatten(map(collection, iteratee), INFINITY); + } + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results up to `depth` times. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDepth([1, 2], duplicate, 2); + * // => [[1, 1], [2, 2]] + */ + function flatMapDepth(collection, iteratee, depth) { + depth = depth === undefined ? 1 : toInteger(depth); + return baseFlatten(map(collection, iteratee), depth); + } + /** * Iterates over elements of `collection` invoking `iteratee` for each element. * The iteratee is invoked with three arguments: (value, index|key, collection). * Iteratee functions may exit iteration early by explicitly returning `false`. * - * **Note:** As with other "Collections" methods, objects with a "length" property - * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn` - * for object iteration. + * **Note:** As with other "Collections" methods, objects with a "length" + * property are iterated like arrays. To avoid this behavior use `_.forIn` + * or `_.forOwn` for object iteration. * * @static * @memberOf _ + * @since 0.1.0 * @alias each * @category Collection * @param {Array|Object} collection The collection to iterate over. @@ -7815,17 +8250,17 @@ * _([1, 2]).forEach(function(value) { * console.log(value); * }); - * // => logs `1` then `2` + * // => Logs `1` then `2`. * * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { * console.log(key); * }); - * // => logs 'a' then 'b' (iteration order is not guaranteed) + * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forEach(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEach(collection, iteratee) - : baseEach(collection, baseCastFunction(iteratee)); + : baseEach(collection, getIteratee(iteratee)); } /** @@ -7834,6 +8269,7 @@ * * @static * @memberOf _ + * @since 2.0.0 * @alias eachRight * @category Collection * @param {Array|Object} collection The collection to iterate over. @@ -7844,12 +8280,12 @@ * _.forEachRight([1, 2], function(value) { * console.log(value); * }); - * // => logs `2` then `1` + * // => Logs `2` then `1`. */ function forEachRight(collection, iteratee) { return (typeof iteratee == 'function' && isArray(collection)) ? arrayEachRight(collection, iteratee) - : baseEachRight(collection, baseCastFunction(iteratee)); + : baseEachRight(collection, getIteratee(iteratee)); } /** @@ -7860,9 +8296,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * @@ -7882,18 +8320,20 @@ }); /** - * Checks if `value` is in `collection`. If `collection` is a string it's checked - * for a substring of `value`, otherwise [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Checks if `value` is in `collection`. If `collection` is a string it's + * checked for a substring of `value`, otherwise + * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * is used for equality comparisons. If `fromIndex` is negative, it's used as * the offset from the end of `collection`. * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object|string} collection The collection to search. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. * @returns {boolean} Returns `true` if `value` is found, else `false`. * @example * @@ -7930,6 +8370,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {Array|Function|string} path The path of the method to invoke or @@ -7965,9 +8406,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee to transform keys. * @returns {Object} Returns the composed aggregate object. * @example * @@ -8004,9 +8447,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new mapped array. * @example * @@ -8042,24 +8487,26 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function[]|Object[]|string[]} [iteratees=[_.identity]] The iteratees to sort by. + * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] + * The iteratees to sort by. * @param {string[]} [orders] The sort orders of `iteratees`. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. * @returns {Array} Returns the new sorted array. * @example * * var users = [ * { 'user': 'fred', 'age': 48 }, * { 'user': 'barney', 'age': 34 }, - * { 'user': 'fred', 'age': 42 }, + * { 'user': 'fred', 'age': 40 }, * { 'user': 'barney', 'age': 36 } * ]; * * // Sort by `user` in ascending order and by `age` in descending order. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] */ function orderBy(collection, iteratees, orders, guard) { if (collection == null) { @@ -8083,9 +8530,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the array of grouped elements. * @example * @@ -8131,6 +8580,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -8162,6 +8612,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -8189,9 +8640,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @example * @@ -8228,6 +8681,7 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to sample. * @returns {*} Returns the random element. @@ -8249,6 +8703,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to sample. * @param {number} [n=0] The number of elements to sample. @@ -8285,6 +8740,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to shuffle. * @returns {Array} Returns the new shuffled array. @@ -8299,10 +8755,11 @@ /** * Gets the size of `collection` by returning its length for array-like - * values or the number of own enumerable properties for objects. + * values or the number of own enumerable string keyed properties for objects. * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to inspect. * @returns {number} Returns the collection size. @@ -8325,6 +8782,12 @@ var result = collection.length; return (result && isString(collection)) ? stringSize(collection) : result; } + if (isObjectLike(collection)) { + var tag = getTag(collection); + if (tag == mapTag || tag == setTag) { + return collection.size; + } + } return keys(collection).length; } @@ -8335,11 +8798,14 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. - * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. * @example * * _.some([null, 0, 'yes', false], Boolean); @@ -8378,30 +8844,32 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]] - * The iteratees to sort by, specified individually or in arrays. + * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} + * [iteratees=[_.identity]] The iteratees to sort by, specified individually + * or in arrays. * @returns {Array} Returns the new sorted array. * @example * * var users = [ * { 'user': 'fred', 'age': 48 }, * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 42 }, + * { 'user': 'fred', 'age': 40 }, * { 'user': 'barney', 'age': 34 } * ]; * * _.sortBy(users, function(o) { return o.user; }); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] * * _.sortBy(users, ['user', 'age']); - * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]] + * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]] * * _.sortBy(users, 'user', function(o) { * return Math.floor(o.age / 10); * }); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] */ var sortBy = rest(function(collection, iteratees) { if (collection == null) { @@ -8424,6 +8892,7 @@ * * @static * @memberOf _ + * @since 2.4.0 * @type {Function} * @category Date * @returns {number} Returns the timestamp. @@ -8432,7 +8901,7 @@ * _.defer(function(stamp) { * console.log(_.now() - stamp); * }, _.now()); - * // => logs the number of milliseconds it took for the deferred function to be invoked + * // => Logs the number of milliseconds it took for the deferred function to be invoked. */ var now = Date.now; @@ -8444,6 +8913,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {number} n The number of calls before `func` is invoked. * @param {Function} func The function to restrict. @@ -8459,7 +8929,7 @@ * _.forEach(saves, function(type) { * asyncSave({ 'type': type, 'complete': done }); * }); - * // => logs 'done saving!' after the two async saves have completed + * // => Logs 'done saving!' after the two async saves have completed. */ function after(n, func) { if (typeof func != 'function') { @@ -8479,10 +8949,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} func The function to cap arguments for. * @param {number} [n=func.length] The arity cap. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the new function. * @example * @@ -8502,6 +8973,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {number} n The number of calls at which `func` is no longer invoked. * @param {Function} func The function to restrict. @@ -8541,6 +9013,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to bind. * @param {*} thisArg The `this` binding of `func`. @@ -8577,8 +9050,8 @@ * any additional `_.bindKey` arguments to those provided to the bound function. * * This method differs from `_.bind` by allowing bound functions to reference - * methods that may be redefined or don't yet exist. - * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) + * methods that may be redefined or don't yet exist. See + * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) * for more details. * * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic @@ -8586,6 +9059,7 @@ * * @static * @memberOf _ + * @since 0.10.0 * @category Function * @param {Object} object The object to invoke the method on. * @param {string} key The key of the method. @@ -8639,10 +9113,11 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Function * @param {Function} func The function to curry. * @param {number} [arity=func.length] The arity of `func`. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the new curried function. * @example * @@ -8683,10 +9158,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} func The function to curry. * @param {number} [arity=func.length] The arity of `func`. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the new curried function. * @example * @@ -8735,16 +9211,17 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to debounce. * @param {number} [wait=0] The number of milliseconds to delay. - * @param {Object} [options] The options object. - * @param {boolean} [options.leading=false] Specify invoking on the leading - * edge of the timeout. - * @param {number} [options.maxWait] The maximum time `func` is allowed to be - * delayed before it's invoked. - * @param {boolean} [options.trailing=true] Specify invoking on the trailing - * edge of the timeout. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. * @returns {Function} Returns the new debounced function. * @example * @@ -8766,14 +9243,12 @@ * jQuery(window).on('popstate', debounced.cancel); */ function debounce(func, wait, options) { - var args, - maxTimeoutId, + var lastArgs, + lastThis, result, - stamp, - thisArg, - timeoutId, - trailingCall, - lastCalled = 0, + timerId, + lastCallTime = 0, + lastInvokeTime = 0, leading = false, maxWait = false, trailing = true; @@ -8788,92 +9263,94 @@ trailing = 'trailing' in options ? !!options.trailing : trailing; } - function cancel() { - if (timeoutId) { - clearTimeout(timeoutId); - } - if (maxTimeoutId) { - clearTimeout(maxTimeoutId); - } - lastCalled = 0; - args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined; - } + function invokeFunc(time) { + var args = lastArgs, + thisArg = lastThis; - function complete(isCalled, id) { - if (id) { - clearTimeout(id); - } - maxTimeoutId = timeoutId = trailingCall = undefined; - if (isCalled) { - lastCalled = now(); - result = func.apply(thisArg, args); - if (!timeoutId && !maxTimeoutId) { - args = thisArg = undefined; - } - } - } - - function delayed() { - var remaining = wait - (now() - stamp); - if (remaining <= 0 || remaining > wait) { - complete(trailingCall, maxTimeoutId); - } else { - timeoutId = setTimeout(delayed, remaining); - } - } - - function flush() { - if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) { - result = func.apply(thisArg, args); - } - cancel(); + lastArgs = lastThis = undefined; + lastInvokeTime = time; + result = func.apply(thisArg, args); return result; } - function maxDelayed() { - complete(trailing, timeoutId); + function leadingEdge(time) { + // Reset any `maxWait` timer. + lastInvokeTime = time; + // Start the timer for the trailing edge. + timerId = setTimeout(timerExpired, wait); + // Invoke the leading edge. + return leading ? invokeFunc(time) : result; + } + + function remainingWait(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime, + result = wait - timeSinceLastCall; + + return maxWait === false ? result : nativeMin(result, maxWait - timeSinceLastInvoke); + } + + function shouldInvoke(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime; + + // Either this is the first call, activity has stopped and we're at the + // trailing edge, the system time has gone backwards and we're treating + // it as the trailing edge, or we've hit the `maxWait` limit. + return (!lastCallTime || (timeSinceLastCall >= wait) || + (timeSinceLastCall < 0) || (maxWait !== false && timeSinceLastInvoke >= maxWait)); + } + + function timerExpired() { + var time = now(); + if (shouldInvoke(time)) { + return trailingEdge(time); + } + // Restart the timer. + timerId = setTimeout(timerExpired, remainingWait(time)); + } + + function trailingEdge(time) { + clearTimeout(timerId); + timerId = undefined; + + // Only invoke if we have `lastArgs` which means `func` has been + // debounced at least once. + if (trailing && lastArgs) { + return invokeFunc(time); + } + lastArgs = lastThis = undefined; + return result; + } + + function cancel() { + if (timerId !== undefined) { + clearTimeout(timerId); + } + lastCallTime = lastInvokeTime = 0; + lastArgs = lastThis = timerId = undefined; + } + + function flush() { + return timerId === undefined ? result : trailingEdge(now()); } function debounced() { - args = arguments; - stamp = now(); - thisArg = this; - trailingCall = trailing && (timeoutId || !leading); + var time = now(), + isInvoking = shouldInvoke(time); - if (maxWait === false) { - var leadingCall = leading && !timeoutId; - } else { - if (!lastCalled && !maxTimeoutId && !leading) { - lastCalled = stamp; - } - var remaining = maxWait - (stamp - lastCalled); + lastArgs = arguments; + lastThis = this; + lastCallTime = time; - var isCalled = (remaining <= 0 || remaining > maxWait) && - (leading || maxTimeoutId); - - if (isCalled) { - if (maxTimeoutId) { - maxTimeoutId = clearTimeout(maxTimeoutId); - } - lastCalled = stamp; - result = func.apply(thisArg, args); + if (isInvoking) { + if (timerId === undefined) { + return leadingEdge(lastCallTime); } - else if (!maxTimeoutId) { - maxTimeoutId = setTimeout(maxDelayed, remaining); - } - } - if (isCalled && timeoutId) { - timeoutId = clearTimeout(timeoutId); - } - else if (!timeoutId && wait !== maxWait) { - timeoutId = setTimeout(delayed, wait); - } - if (leadingCall) { - isCalled = true; - result = func.apply(thisArg, args); - } - if (isCalled && !timeoutId && !maxTimeoutId) { - args = thisArg = undefined; + // Handle invocations in a tight loop. + clearTimeout(timerId); + timerId = setTimeout(timerExpired, wait); + return invokeFunc(lastCallTime); } return result; } @@ -8888,6 +9365,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to defer. * @param {...*} [args] The arguments to invoke `func` with. @@ -8897,7 +9375,7 @@ * _.defer(function(text) { * console.log(text); * }, 'deferred'); - * // => logs 'deferred' after one or more milliseconds + * // => Logs 'deferred' after one or more milliseconds. */ var defer = rest(function(func, args) { return baseDelay(func, 1, args); @@ -8909,6 +9387,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to delay. * @param {number} wait The number of milliseconds to delay invocation. @@ -8919,7 +9398,7 @@ * _.delay(function(text) { * console.log(text); * }, 1000, 'later'); - * // => logs 'later' after one second + * // => Logs 'later' after one second. */ var delay = rest(function(func, wait, args) { return baseDelay(func, toNumber(wait) || 0, args); @@ -8930,6 +9409,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Function * @param {Function} func The function to flip arguments for. * @returns {Function} Returns the new function. @@ -8955,11 +9435,13 @@ * * **Note:** The cache is exposed as the `cache` property on the memoized * 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/6.0/#sec-properties-of-the-map-prototype-object) + * constructor with one whose instances implement the + * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object) * method interface of `delete`, `get`, `has`, and `set`. * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to have its output memoized. * @param {Function} [resolver] The function to resolve the cache key. @@ -9004,10 +9486,13 @@ memoized.cache = cache.set(key, result); return result; }; - memoized.cache = new memoize.Cache; + memoized.cache = new (memoize.Cache || MapCache); return memoized; } + // Assign cache to `_.memoize`. + memoize.Cache = MapCache; + /** * Creates a function that negates the result of the predicate `func`. The * `func` predicate is invoked with the `this` binding and arguments of the @@ -9015,6 +9500,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} predicate The predicate to negate. * @returns {Function} Returns the new function. @@ -9043,6 +9529,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. @@ -9062,6 +9549,7 @@ * corresponding `transforms`. * * @static + * @since 4.0.0 * @memberOf _ * @category Function * @param {Function} func The function to wrap. @@ -9116,6 +9604,7 @@ * * @static * @memberOf _ + * @since 0.2.0 * @category Function * @param {Function} func The function to partially apply arguments to. * @param {...*} [partials] The arguments to be partially applied. @@ -9152,6 +9641,7 @@ * * @static * @memberOf _ + * @since 1.0.0 * @category Function * @param {Function} func The function to partially apply arguments to. * @param {...*} [partials] The arguments to be partially applied. @@ -9184,6 +9674,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} func The function to rearrange arguments for. * @param {...(number|number[])} indexes The arranged argument indexes, @@ -9204,12 +9695,15 @@ /** * Creates a function that invokes `func` with the `this` binding of the - * created function and arguments from `start` and beyond provided as an array. + * created function and arguments from `start` and beyond provided as + * an array. * - * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters). + * **Note:** This method is based on the + * [rest parameter](https://mdn.io/rest_parameters). * * @static * @memberOf _ + * @since 4.0.0 * @category Function * @param {Function} func The function to apply a rest parameter to. * @param {number} [start=func.length-1] The start position of the rest parameter. @@ -9254,13 +9748,16 @@ } /** - * Creates a function that invokes `func` with the `this` binding of the created - * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3). + * Creates a function that invokes `func` with the `this` binding of the + * create function and an array of arguments much like + * [`Function#apply`](https://es5.github.io/#x15.3.4.3). * - * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator). + * **Note:** This method is based on the + * [spread operator](https://mdn.io/spread_operator). * * @static * @memberOf _ + * @since 3.2.0 * @category Function * @param {Function} func The function to spread arguments over. * @param {number} [start=0] The start position of the spread. @@ -9310,23 +9807,24 @@ * throttled function. Subsequent calls to the throttled function return the * result of the last `func` invocation. * - * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked - * on the trailing edge of the timeout only if the throttled function is - * invoked more than once during the `wait` timeout. + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the throttled function + * is invoked more than once during the `wait` timeout. * * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation) * for details over the differences between `_.throttle` and `_.debounce`. * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to throttle. * @param {number} [wait=0] The number of milliseconds to throttle invocations to. - * @param {Object} [options] The options object. - * @param {boolean} [options.leading=true] Specify invoking on the leading - * edge of the timeout. - * @param {boolean} [options.trailing=true] Specify invoking on the trailing - * edge of the timeout. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=true] + * Specify invoking on the leading edge of the timeout. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. * @returns {Function} Returns the new throttled function. * @example * @@ -9364,6 +9862,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Function * @param {Function} func The function to cap arguments for. * @returns {Function} Returns the new function. @@ -9384,6 +9883,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {*} value The value to wrap. * @param {Function} [wrapper=identity] The wrapper function. @@ -9409,6 +9909,7 @@ * * @static * @memberOf _ + * @since 4.4.0 * @category Lang * @param {*} value The value to inspect. * @returns {Array} Returns the cast array. @@ -9457,6 +9958,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to clone. * @returns {*} Returns the cloned value. @@ -9480,6 +9982,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to clone. * @param {Function} [customizer] The function to customize cloning. @@ -9510,6 +10013,7 @@ * * @static * @memberOf _ + * @since 1.0.0 * @category Lang * @param {*} value The value to recursively clone. * @returns {*} Returns the deep cloned value. @@ -9530,6 +10034,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to recursively clone. * @param {Function} [customizer] The function to customize cloning. @@ -9556,11 +10061,13 @@ } /** - * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) * comparison between two values to determine if they are equivalent. * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. @@ -9594,10 +10101,12 @@ * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. * @example * * _.gt(3, 1); @@ -9618,10 +10127,12 @@ * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is greater than or equal to + * `other`, else `false`. * @example * * _.gte(3, 1); @@ -9642,9 +10153,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isArguments(function() { return arguments; }()); @@ -9664,10 +10177,12 @@ * * @static * @memberOf _ + * @since 0.1.0 * @type {Function} * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isArray([1, 2, 3]); @@ -9689,9 +10204,11 @@ * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isArrayBuffer(new ArrayBuffer(2)); @@ -9711,6 +10228,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. @@ -9738,9 +10256,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. * @example * * _.isArrayLikeObject([1, 2, 3]); @@ -9764,9 +10284,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isBoolean(false); @@ -9785,6 +10307,7 @@ * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. @@ -9805,9 +10328,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isDate(new Date); @@ -9825,9 +10350,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. + * @returns {boolean} Returns `true` if `value` is a DOM element, + * else `false`. * @example * * _.isElement(document.body); @@ -9841,12 +10368,18 @@ } /** - * Checks if `value` is an empty collection or object. A value is considered - * empty if it's an `arguments` object, array, string, or jQuery-like collection - * with a length of `0` or has no own enumerable properties. + * Checks if `value` is an empty object, collection, map, or set. + * + * Objects are considered empty if they have no own enumerable string keyed + * properties. + * + * Array-like values such as `arguments` objects, arrays, buffers, strings, or + * jQuery-like collections are considered empty if they have a `length` of `0`. + * Similarly, maps and sets are considered empty if they have a `size` of `0`. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is empty, else `false`. @@ -9869,16 +10402,22 @@ */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || - isFunction(value.splice) || isArguments(value))) { + (isArray(value) || isString(value) || isFunction(value.splice) || + isArguments(value) || isBuffer(value))) { return !value.length; } + if (isObjectLike(value)) { + var tag = getTag(value); + if (tag == mapTag || tag == setTag) { + return !value.size; + } + } for (var key in value) { if (hasOwnProperty.call(value, key)) { return false; } } - return true; + return !(nonEnumShadows && keys(value).length); } /** @@ -9893,10 +10432,12 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @returns {boolean} Returns `true` if the values are equivalent, + * else `false`. * @example * * var object = { 'user': 'fred' }; @@ -9920,11 +10461,13 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @returns {boolean} Returns `true` if the values are equivalent, + * else `false`. * @example * * function isGreeting(value) { @@ -9955,9 +10498,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an error object, else `false`. + * @returns {boolean} Returns `true` if `value` is an error object, + * else `false`. * @example * * _.isError(new Error); @@ -9977,13 +10522,16 @@ /** * Checks if `value` is a finite primitive number. * - * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite). + * **Note:** This method is based on + * [`Number.isFinite`](https://mdn.io/Number/isFinite). * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. + * @returns {boolean} Returns `true` if `value` is a finite number, + * else `false`. * @example * * _.isFinite(3); @@ -10007,9 +10555,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isFunction(_); @@ -10029,10 +10579,12 @@ /** * Checks if `value` is an integer. * - * **Note:** This method is based on [`Number.isInteger`](https://mdn.io/Number/isInteger). + * **Note:** This method is based on + * [`Number.isInteger`](https://mdn.io/Number/isInteger). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an integer, else `false`. @@ -10057,13 +10609,16 @@ /** * Checks if `value` is a valid array-like length. * - * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * **Note:** This function is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @returns {boolean} Returns `true` if `value` is a valid length, + * else `false`. * @example * * _.isLength(3); @@ -10089,6 +10644,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. @@ -10117,6 +10673,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. @@ -10143,9 +10700,11 @@ * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isMap(new Map); @@ -10167,6 +10726,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. @@ -10193,6 +10753,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. @@ -10224,11 +10785,13 @@ /** * Checks if `value` is `NaN`. * - * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4) - * which returns `true` for `undefined` and other non-numeric values. + * **Note:** This method is not the same as + * [`isNaN`](https://es5.github.io/#x15.1.2.4) which returns `true` for + * `undefined` and other non-numeric values. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. @@ -10248,7 +10811,8 @@ */ function isNaN(value) { // An `NaN` primitive is the only value that is not equal to itself. - // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE. + // Perform the `toStringTag` check first to avoid errors with some + // ActiveX objects in IE. return isNumber(value) && value != +value; } @@ -10257,9 +10821,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. * @example * * _.isNative(Array.prototype.push); @@ -10284,6 +10850,7 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `null`, else `false`. @@ -10304,6 +10871,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is nullish, else `false`. @@ -10325,14 +10893,16 @@ /** * Checks if `value` is classified as a `Number` primitive or object. * - * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified - * as numbers, use the `_.isFinite` method. + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are + * classified as numbers, use the `_.isFinite` method. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isNumber(3); @@ -10358,9 +10928,11 @@ * * @static * @memberOf _ + * @since 0.8.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @returns {boolean} Returns `true` if `value` is a plain object, + * else `false`. * @example * * function Foo() { @@ -10384,11 +10956,11 @@ objectToString.call(value) != objectTag || isHostObject(value)) { return false; } - var proto = getPrototypeOf(value); + var proto = getPrototype(value); if (proto === null) { return true; } - var Ctor = proto.constructor; + var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; return (typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString); } @@ -10398,9 +10970,11 @@ * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isRegExp(/abc/); @@ -10417,13 +10991,16 @@ * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 * double precision number which isn't the result of a rounded unsafe integer. * - * **Note:** This method is based on [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). + * **Note:** This method is based on + * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. + * @returns {boolean} Returns `true` if `value` is a safe integer, + * else `false`. * @example * * _.isSafeInteger(3); @@ -10447,9 +11024,11 @@ * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isSet(new Set); @@ -10466,10 +11045,12 @@ * Checks if `value` is classified as a `String` primitive or object. * * @static + * @since 0.1.0 * @memberOf _ * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isString('abc'); @@ -10488,9 +11069,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isSymbol(Symbol.iterator); @@ -10509,9 +11092,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isTypedArray(new Uint8Array); @@ -10529,6 +11114,7 @@ * Checks if `value` is `undefined`. * * @static + * @since 0.1.0 * @memberOf _ * @category Lang * @param {*} value The value to check. @@ -10550,9 +11136,11 @@ * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isWeakMap(new WeakMap); @@ -10570,9 +11158,11 @@ * * @static * @memberOf _ + * @since 4.3.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. * @example * * _.isWeakSet(new WeakSet); @@ -10590,10 +11180,12 @@ * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. * @example * * _.lt(1, 3); @@ -10614,10 +11206,12 @@ * * @static * @memberOf _ + * @since 3.9.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`. + * @returns {boolean} Returns `true` if `value` is less than or equal to + * `other`, else `false`. * @example * * _.lte(1, 3); @@ -10637,6 +11231,7 @@ * Converts `value` to an array. * * @static + * @since 0.1.0 * @memberOf _ * @category Lang * @param {*} value The value to convert. @@ -10674,10 +11269,12 @@ /** * Converts `value` to an integer. * - * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). + * **Note:** This function is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. @@ -10712,10 +11309,12 @@ * Converts `value` to an integer suitable for use as the length of an * array-like object. * - * **Note:** This method is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * **Note:** This method is based on + * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. @@ -10742,6 +11341,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to process. * @returns {number} Returns the number. @@ -10760,12 +11360,18 @@ * // => 3 */ function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } if (isObject(value)) { var other = isFunction(value.valueOf) ? value.valueOf() : value; value = isObject(other) ? (other + '') : other; } if (typeof value != 'string') { - return value === 0 ? value : +value; + return value === 0 ? value : +value; } value = value.replace(reTrim, ''); var isBinary = reIsBinary.test(value); @@ -10775,11 +11381,12 @@ } /** - * Converts `value` to a plain object flattening inherited enumerable - * properties of `value` to own properties of the plain object. + * Converts `value` to a plain object flattening inherited enumerable string + * keyed properties of `value` to own properties of the plain object. * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to convert. * @returns {Object} Returns the converted plain object. @@ -10807,6 +11414,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. @@ -10834,6 +11442,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to process. * @returns {string} Returns the string. @@ -10866,15 +11475,16 @@ /*------------------------------------------------------------------------*/ /** - * Assigns own enumerable properties of source objects to the destination - * object. Source objects are applied from left to right. Subsequent sources - * overwrite property assignments of previous sources. + * Assigns own enumerable string keyed properties of source objects to the + * destination object. Source objects are applied from left to right. + * Subsequent sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object` and is loosely based on * [`Object.assign`](https://mdn.io/Object/assign). * * @static * @memberOf _ + * @since 0.10.0 * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. @@ -10915,6 +11525,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @alias extend * @category Object * @param {Object} object The destination object. @@ -10947,15 +11558,16 @@ }); /** - * This method is like `_.assignIn` except that it accepts `customizer` which - * is invoked to produce the assigned values. If `customizer` returns `undefined` - * assignment is handled by the method instead. The `customizer` is invoked - * with five arguments: (objValue, srcValue, key, object, source). + * This method is like `_.assignIn` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined` assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). * * **Note:** This method mutates `object`. * * @static * @memberOf _ + * @since 4.0.0 * @alias extendWith * @category Object * @param {Object} object The destination object. @@ -10978,15 +11590,16 @@ }); /** - * This method is like `_.assign` except that it accepts `customizer` which - * is invoked to produce the assigned values. If `customizer` returns `undefined` - * assignment is handled by the method instead. The `customizer` is invoked - * with five arguments: (objValue, srcValue, key, object, source). + * This method is like `_.assign` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined` assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). * * **Note:** This method mutates `object`. * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The destination object. * @param {...Object} sources The source objects. @@ -11012,6 +11625,7 @@ * * @static * @memberOf _ + * @since 1.0.0 * @category Object * @param {Object} object The object to iterate over. * @param {...(string|string[])} [paths] The property paths of elements to pick, @@ -11032,11 +11646,13 @@ }); /** - * Creates an object that inherits from the `prototype` object. If a `properties` - * object is given its own enumerable properties are assigned to the created object. + * Creates an object that inherits from the `prototype` object. If a + * `properties` object is given its own enumerable string keyed properties + * are assigned to the created object. * * @static * @memberOf _ + * @since 2.3.0 * @category Object * @param {Object} prototype The object to inherit from. * @param {Object} [properties] The properties to assign to the object. @@ -11069,14 +11685,15 @@ } /** - * Assigns own and inherited enumerable properties of source objects to the - * destination object for all destination properties that resolve to `undefined`. - * Source objects are applied from left to right. Once a property is set, - * additional values of the same property are ignored. + * Assigns own and inherited enumerable string keyed properties of source + * objects to the destination object for all destination properties that + * resolve to `undefined`. Source objects are applied from left to right. + * Once a property is set, additional values of the same property are ignored. * * **Note:** This method mutates `object`. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The destination object. @@ -11100,6 +11717,7 @@ * * @static * @memberOf _ + * @since 3.10.0 * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. @@ -11121,10 +11739,13 @@ * * @static * @memberOf _ + * @since 1.1.0 * @category Object * @param {Object} object The object to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @returns {string|undefined} Returns the key of the matched element, else `undefined`. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. * @example * * var users = { @@ -11158,10 +11779,13 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Object * @param {Object} object The object to search. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @returns {string|undefined} Returns the key of the matched element, else `undefined`. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. * @example * * var users = { @@ -11190,13 +11814,14 @@ } /** - * Iterates over own and inherited enumerable properties of an object invoking - * `iteratee` for each property. The iteratee is invoked with three arguments: - * (value, key, object). Iteratee functions may exit iteration early by explicitly - * returning `false`. + * Iterates over own and inherited enumerable string keyed properties of an + * object invoking `iteratee` for each property. The iteratee is invoked with + * three arguments: (value, key, object). Iteratee functions may exit iteration + * early by explicitly returning `false`. * * @static * @memberOf _ + * @since 0.3.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -11213,12 +11838,12 @@ * _.forIn(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed) + * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). */ function forIn(object, iteratee) { return object == null ? object - : baseFor(object, baseCastFunction(iteratee), keysIn); + : baseFor(object, getIteratee(iteratee), keysIn); } /** @@ -11227,6 +11852,7 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -11243,22 +11869,23 @@ * _.forInRight(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c' + * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. */ function forInRight(object, iteratee) { return object == null ? object - : baseForRight(object, baseCastFunction(iteratee), keysIn); + : baseForRight(object, getIteratee(iteratee), keysIn); } /** - * Iterates over own enumerable properties of an object invoking `iteratee` - * for each property. The iteratee is invoked with three arguments: + * Iterates over own enumerable string keyed properties of an object invoking + * `iteratee` for each property. The iteratee is invoked with three arguments: * (value, key, object). Iteratee functions may exit iteration early by * explicitly returning `false`. * * @static * @memberOf _ + * @since 0.3.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -11275,10 +11902,10 @@ * _.forOwn(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'a' then 'b' (iteration order is not guaranteed) + * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forOwn(object, iteratee) { - return object && baseForOwn(object, baseCastFunction(iteratee)); + return object && baseForOwn(object, getIteratee(iteratee)); } /** @@ -11287,6 +11914,7 @@ * * @static * @memberOf _ + * @since 2.0.0 * @category Object * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -11303,10 +11931,10 @@ * _.forOwnRight(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b' + * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, baseCastFunction(iteratee)); + return object && baseForOwnRight(object, getIteratee(iteratee)); } /** @@ -11314,6 +11942,7 @@ * of `object`. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to inspect. @@ -11340,6 +11969,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to inspect. * @returns {Array} Returns the new array of property names. @@ -11365,10 +11995,11 @@ * * @static * @memberOf _ + * @since 3.7.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path of the property to get. - * @param {*} [defaultValue] The value returned if the resolved value is `undefined`. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. * @returns {*} Returns the resolved value. * @example * @@ -11392,6 +12023,7 @@ * Checks if `path` is a direct property of `object`. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. @@ -11423,6 +12055,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path to check. @@ -11449,11 +12082,12 @@ /** * Creates an object composed of the inverted keys and values of `object`. - * If `object` contains duplicate values, subsequent values overwrite property - * assignments of previous values. + * If `object` contains duplicate values, subsequent values overwrite + * property assignments of previous values. * * @static * @memberOf _ + * @since 0.7.0 * @category Object * @param {Object} object The object to invert. * @returns {Object} Returns the new inverted object. @@ -11477,9 +12111,11 @@ * * @static * @memberOf _ + * @since 4.1.0 * @category Object * @param {Object} object The object to invert. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Object} Returns the new inverted object. * @example * @@ -11506,6 +12142,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path of the method to invoke. @@ -11528,6 +12165,7 @@ * for more details. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. @@ -11574,6 +12212,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. @@ -11612,14 +12251,16 @@ /** * The opposite of `_.mapValues`; this method creates an object with the * same values as `object` and keys generated by running each own enumerable - * property of `object` through `iteratee`. The iteratee is invoked with - * three arguments: (value, key, object). + * string keyed property of `object` through `iteratee`. The iteratee is + * invoked with three arguments: (value, key, object). * * @static * @memberOf _ + * @since 3.8.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @example * @@ -11640,14 +12281,17 @@ /** * Creates an object with the same keys as `object` and values generated by - * running each own enumerable property of `object` through `iteratee`. The - * iteratee is invoked with three arguments: (value, key, object). + * running each own enumerable string keyed property of `object` through + * `iteratee`. The iteratee is invoked with three arguments: + * (value, key, object). * * @static * @memberOf _ + * @since 2.4.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @example * @@ -11675,17 +12319,18 @@ /** * This method is like `_.assign` except that it recursively merges own and - * inherited enumerable properties of source objects into the destination - * object. Source properties that resolve to `undefined` are skipped if a - * destination value exists. Array and plain object properties are merged - * recursively.Other objects and value types are overridden by assignment. - * Source objects are applied from left to right. Subsequent sources - * overwrite property assignments of previous sources. + * inherited enumerable string keyed properties of source objects into the + * destination object. Source properties that resolve to `undefined` are + * skipped if a destination value exists. Array and plain object properties + * are merged recursively.Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object`. * * @static * @memberOf _ + * @since 0.5.0 * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. @@ -11718,6 +12363,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The destination object. * @param {...Object} sources The source objects. @@ -11750,14 +12396,16 @@ /** * The opposite of `_.pick`; this method creates an object composed of the - * own and inherited enumerable properties of `object` that are not omitted. + * own and inherited enumerable string keyed properties of `object` that are + * not omitted. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property names to omit, specified - * individually or in arrays. + * @param {...(string|string[])} [props] The property identifiers to omit, + * specified individually or in arrays. * @returns {Object} Returns the new object. * @example * @@ -11770,21 +12418,23 @@ if (object == null) { return {}; } - props = arrayMap(baseFlatten(props, 1), String); - return basePick(object, baseDifference(keysIn(object), props)); + props = arrayMap(baseFlatten(props, 1), baseCastKey); + return basePick(object, baseDifference(getAllKeysIn(object), props)); }); /** * The opposite of `_.pickBy`; this method creates an object composed of - * the own and inherited enumerable properties of `object` that `predicate` - * doesn't return truthy for. The predicate is invoked with two arguments: - * (value, key). + * the own and inherited enumerable string keyed properties of `object` that + * `predicate` doesn't return truthy for. The predicate is invoked with two + * arguments: (value, key). * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per property. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per property. * @returns {Object} Returns the new object. * @example * @@ -11804,11 +12454,12 @@ * Creates an object composed of the picked `object` properties. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property names to pick, specified - * individually or in arrays. + * @param {...(string|string[])} [props] The property identifiers to pick, + * specified individually or in arrays. * @returns {Object} Returns the new object. * @example * @@ -11827,9 +12478,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per property. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per property. * @returns {Object} Returns the new object. * @example * @@ -11843,16 +12496,17 @@ } /** - * This method is like `_.get` except that if the resolved value is a function - * it's invoked with the `this` binding of its parent object and its result - * is returned. + * This method is like `_.get` except that if the resolved value is a + * function it's invoked with the `this` binding of its parent object and + * its result is returned. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path of the property to resolve. - * @param {*} [defaultValue] The value returned if the resolved value is `undefined`. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. * @returns {*} Returns the resolved value. * @example * @@ -11871,17 +12525,25 @@ * // => 'default' */ function result(object, path, defaultValue) { - if (!isKey(path, object)) { - path = baseCastPath(path); - var result = get(object, path); - object = parent(object, path); - } else { - result = object == null ? undefined : object[path]; + path = isKey(path, object) ? [path] : baseCastPath(path); + + var index = -1, + length = path.length; + + // Ensure the loop is entered when path is empty. + if (!length) { + object = undefined; + length = 1; } - if (result === undefined) { - result = defaultValue; + while (++index < length) { + var value = object == null ? undefined : object[path[index]]; + if (value === undefined) { + index = length; + value = defaultValue; + } + object = isFunction(value) ? value.call(object) : value; } - return isFunction(result) ? result.call(object) : result; + return object; } /** @@ -11894,6 +12556,7 @@ * * @static * @memberOf _ + * @since 3.7.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. @@ -11925,6 +12588,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. @@ -11944,11 +12608,13 @@ } /** - * Creates an array of own enumerable key-value pairs for `object` which - * can be consumed by `_.fromPairs`. + * Creates an array of own enumerable string keyed-value pairs for `object` + * which can be consumed by `_.fromPairs`. * * @static * @memberOf _ + * @since 4.0.0 + * @alias entries * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the new array of key-value pairs. @@ -11969,11 +12635,13 @@ } /** - * Creates an array of own and inherited enumerable key-value pairs for - * `object` which can be consumed by `_.fromPairs`. + * Creates an array of own and inherited enumerable string keyed-value pairs + * for `object` which can be consumed by `_.fromPairs`. * * @static * @memberOf _ + * @since 4.0.0 + * @alias entriesIn * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the new array of key-value pairs. @@ -11996,13 +12664,14 @@ /** * An alternative to `_.reduce`; this method transforms `object` to a new * `accumulator` object which is the result of running each of its own enumerable - * properties through `iteratee`, with each invocation potentially mutating - * the `accumulator` object. The iteratee is invoked with four arguments: + * string keyed properties through `iteratee`, with each invocation potentially + * mutating the `accumulator` object. The iteratee is invoked with four arguments: * (accumulator, value, key, object). Iteratee functions may exit iteration * early by explicitly returning `false`. * * @static * @memberOf _ + * @since 1.3.0 * @category Object * @param {Array|Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -12031,7 +12700,7 @@ if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {}; + accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; } } else { accumulator = {}; @@ -12050,6 +12719,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to unset. @@ -12082,6 +12752,7 @@ * * @static * @memberOf _ + * @since 4.6.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. @@ -12113,6 +12784,7 @@ * * @static * @memberOf _ + * @since 4.6.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. @@ -12132,11 +12804,12 @@ } /** - * Creates an array of the own enumerable property values of `object`. + * Creates an array of the own enumerable string keyed property values of `object`. * * **Note:** Non-object values are coerced to objects. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. @@ -12161,12 +12834,14 @@ } /** - * Creates an array of the own and inherited enumerable property values of `object`. + * Creates an array of the own and inherited enumerable string keyed property + * values of `object`. * * **Note:** Non-object values are coerced to objects. * * @static * @memberOf _ + * @since 3.0.0 * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the array of property values. @@ -12193,6 +12868,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Number * @param {number} number The number to clamp. * @param {number} [lower] The lower bound. @@ -12230,6 +12906,7 @@ * * @static * @memberOf _ + * @since 3.3.0 * @category Number * @param {number} number The number to check. * @param {number} [start=0] The start of the range. @@ -12273,14 +12950,15 @@ /** * Produces a random number between the inclusive `lower` and `upper` bounds. * If only one argument is provided a number between `0` and the given number - * is returned. If `floating` is `true`, or either `lower` or `upper` are floats, - * a floating-point number is returned instead of an integer. + * is returned. If `floating` is `true`, or either `lower` or `upper` are + * floats, a floating-point number is returned instead of an integer. * * **Note:** JavaScript follows the IEEE-754 standard for resolving * floating-point values which can produce unexpected results. * * @static * @memberOf _ + * @since 0.7.0 * @category Number * @param {number} [lower=0] The lower bound. * @param {number} [upper=1] The upper bound. @@ -12346,6 +13024,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the camel cased string. @@ -12354,10 +13033,10 @@ * _.camelCase('Foo Bar'); * // => 'fooBar' * - * _.camelCase('--foo-bar'); + * _.camelCase('--foo-bar--'); * // => 'fooBar' * - * _.camelCase('__foo_bar__'); + * _.camelCase('__FOO_BAR__'); * // => 'fooBar' */ var camelCase = createCompounder(function(result, word, index) { @@ -12371,6 +13050,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to capitalize. * @returns {string} Returns the capitalized string. @@ -12384,11 +13064,14 @@ } /** - * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) - * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). + * Deburrs `string` by converting + * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * to basic latin letters and removing + * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to deburr. * @returns {string} Returns the deburred string. @@ -12407,11 +13090,13 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to search. * @param {string} [target] The string to search for. * @param {number} [position=string.length] The position to search from. - * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`. + * @returns {boolean} Returns `true` if `string` ends with `target`, + * else `false`. * @example * * _.endsWith('abc', 'c'); @@ -12445,20 +13130,22 @@ * * Though the ">" character is escaped for symmetry, characters like * ">" and "/" don't need escaping in HTML and have no special meaning - * unless they're part of a tag or unquoted attribute value. - * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) + * unless they're part of a tag or unquoted attribute value. See + * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * * Backticks are escaped because in IE < 9, they can break out of * attribute values or HTML comments. See [#59](https://html5sec.org/#59), * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and - * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/) - * for more details. + * [#133](https://html5sec.org/#133) of the + * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details. * - * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping) - * to reduce XSS vectors. + * When working with HTML you should always + * [quote attribute values](http://wonko.com/post/html-escaping) to reduce + * XSS vectors. * * @static + * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The string to escape. @@ -12481,6 +13168,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to escape. * @returns {string} Returns the escaped string. @@ -12497,10 +13185,12 @@ } /** - * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). + * Converts `string` to + * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the kebab cased string. @@ -12512,7 +13202,7 @@ * _.kebabCase('fooBar'); * // => 'foo-bar' * - * _.kebabCase('__foo_bar__'); + * _.kebabCase('__FOO_BAR__'); * // => 'foo-bar' */ var kebabCase = createCompounder(function(result, word, index) { @@ -12524,12 +13214,13 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the lower cased string. * @example * - * _.lowerCase('--Foo-Bar'); + * _.lowerCase('--Foo-Bar--'); * // => 'foo bar' * * _.lowerCase('fooBar'); @@ -12547,6 +13238,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the converted string. @@ -12560,30 +13252,13 @@ */ var lowerFirst = createCaseFirst('toLowerCase'); - /** - * Converts the first character of `string` to upper case. - * - * @static - * @memberOf _ - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the converted string. - * @example - * - * _.upperFirst('fred'); - * // => 'Fred' - * - * _.upperFirst('FRED'); - * // => 'FRED' - */ - var upperFirst = createCaseFirst('toUpperCase'); - /** * Pads `string` on the left and right sides if it's shorter than `length`. * Padding characters are truncated if they can't be evenly divided by `length`. * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to pad. * @param {number} [length=0] The padding length. @@ -12604,15 +13279,16 @@ string = toString(string); length = toInteger(length); - var strLength = stringSize(string); + var strLength = length ? stringSize(string) : 0; if (!length || strLength >= length) { return string; } - var mid = (length - strLength) / 2, - leftLength = nativeFloor(mid), - rightLength = nativeCeil(mid); - - return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars); + var mid = (length - strLength) / 2; + return ( + createPadding(nativeFloor(mid), chars) + + string + + createPadding(nativeCeil(mid), chars) + ); } /** @@ -12621,6 +13297,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to pad. * @param {number} [length=0] The padding length. @@ -12639,7 +13316,12 @@ */ function padEnd(string, length, chars) { string = toString(string); - return string + createPadding(string, length, chars); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (string + createPadding(length - strLength, chars)) + : string; } /** @@ -12648,6 +13330,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to pad. * @param {number} [length=0] The padding length. @@ -12666,23 +13349,29 @@ */ function padStart(string, length, chars) { string = toString(string); - return createPadding(string, length, chars) + string; + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (createPadding(length - strLength, chars) + string) + : string; } /** * Converts `string` to an integer of the specified radix. If `radix` is - * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal, - * in which case a `radix` of `16` is used. + * `undefined` or `0`, a `radix` of `10` is used unless `value` is a + * hexadecimal, in which case a `radix` of `16` is used. * - * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2) - * of `parseInt`. + * **Note:** This method aligns with the + * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. * * @static * @memberOf _ + * @since 1.1.0 * @category String * @param {string} string The string to convert. * @param {number} [radix=10] The radix to interpret `value` by. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {number} Returns the converted integer. * @example * @@ -12694,7 +13383,7 @@ */ function parseInt(string, radix, guard) { // Chrome fails to trim leading whitespace characters. - // See https://code.google.com/p/v8/issues/detail?id=3109 for more details. + // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details. if (guard || radix == null) { radix = 0; } else if (radix) { @@ -12709,6 +13398,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to repeat. * @param {number} [n=0] The number of times to repeat the string. @@ -12725,33 +13415,18 @@ * // => '' */ function repeat(string, n) { - string = toString(string); - n = toInteger(n); - - var result = ''; - if (!string || n < 1 || n > MAX_SAFE_INTEGER) { - return result; - } - // Leverage the exponentiation by squaring algorithm for a faster repeat. - // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. - do { - if (n % 2) { - result += string; - } - n = nativeFloor(n / 2); - string += string; - } while (n); - - return result; + return baseRepeat(toString(string), toInteger(n)); } /** * Replaces matches for `pattern` in `string` with `replacement`. * - * **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace). + * **Note:** This method is based on + * [`String#replace`](https://mdn.io/String/replace). * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to modify. * @param {RegExp|string} pattern The pattern to replace. @@ -12770,10 +13445,12 @@ } /** - * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case). + * Converts `string` to + * [snake case](https://en.wikipedia.org/wiki/Snake_case). * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the snake cased string. @@ -12785,7 +13462,7 @@ * _.snakeCase('fooBar'); * // => 'foo_bar' * - * _.snakeCase('--foo-bar'); + * _.snakeCase('--FOO-BAR--'); * // => 'foo_bar' */ var snakeCase = createCompounder(function(result, word, index) { @@ -12795,10 +13472,12 @@ /** * Splits `string` by `separator`. * - * **Note:** This method is based on [`String#split`](https://mdn.io/String/split). + * **Note:** This method is based on + * [`String#split`](https://mdn.io/String/split). * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to split. * @param {RegExp|string} separator The separator pattern to split by. @@ -12814,26 +13493,28 @@ } /** - * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). + * Converts `string` to + * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). * * @static * @memberOf _ + * @since 3.1.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the start cased string. * @example * - * _.startCase('--foo-bar'); + * _.startCase('--foo-bar--'); * // => 'Foo Bar' * * _.startCase('fooBar'); * // => 'Foo Bar' * - * _.startCase('__foo_bar__'); - * // => 'Foo Bar' + * _.startCase('__FOO_BAR__'); + * // => 'FOO BAR' */ var startCase = createCompounder(function(result, word, index) { - return result + (index ? ' ' : '') + capitalize(word); + return result + (index ? ' ' : '') + upperFirst(word); }); /** @@ -12841,11 +13522,13 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to search. * @param {string} [target] The string to search for. * @param {number} [position=0] The position to search from. - * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`. + * @returns {boolean} Returns `true` if `string` starts with `target`, + * else `false`. * @example * * _.startsWith('abc', 'a'); @@ -12881,17 +13564,24 @@ * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). * * @static + * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The template string. - * @param {Object} [options] The options object. - * @param {RegExp} [options.escape] The HTML "escape" delimiter. - * @param {RegExp} [options.evaluate] The "evaluate" delimiter. - * @param {Object} [options.imports] An object to import into the template as free variables. - * @param {RegExp} [options.interpolate] The "interpolate" delimiter. - * @param {string} [options.sourceURL] The sourceURL of the template's compiled source. - * @param {string} [options.variable] The data object variable name. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param {Object} [options={}] The options object. + * @param {RegExp} [options.escape=_.templateSettings.escape] + * The HTML "escape" delimiter. + * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] + * The "evaluate" delimiter. + * @param {Object} [options.imports=_.templateSettings.imports] + * An object to import into the template as free variables. + * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] + * The "interpolate" delimiter. + * @param {string} [options.sourceURL='lodash.templateSources[n]'] + * The sourceURL of the compiled template. + * @param {string} [options.variable='obj'] + * The data object variable name. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the compiled template function. * @example * @@ -12940,7 +13630,7 @@ * // Use the `sourceURL` option to specify a custom sourceURL for the template. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); * compiled(data); - * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector + * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. * * // Use the `variable` option to ensure a with-statement isn't used in the compiled template. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); @@ -12960,7 +13650,8 @@ * '); */ function template(string, options, guard) { - // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/) + // Based on John Resig's `tmpl` implementation + // (http://ejohn.org/blog/javascript-micro-templating/) // and Laura Doktorova's doT.js (https://github.com/olado/doT). var settings = lodash.templateSettings; @@ -13072,13 +13763,14 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the lower cased string. * @example * - * _.toLower('--Foo-Bar'); - * // => '--foo-bar' + * _.toLower('--Foo-Bar--'); + * // => '--foo-bar--' * * _.toLower('fooBar'); * // => 'foobar' @@ -13096,13 +13788,14 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the upper cased string. * @example * - * _.toUpper('--foo-bar'); - * // => '--FOO-BAR' + * _.toUpper('--foo-bar--'); + * // => '--FOO-BAR--' * * _.toUpper('fooBar'); * // => 'FOOBAR' @@ -13119,10 +13812,11 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to trim. * @param {string} [chars=whitespace] The characters to trim. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the trimmed string. * @example * @@ -13160,10 +13854,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to trim. * @param {string} [chars=whitespace] The characters to trim. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the trimmed string. * @example * @@ -13196,10 +13891,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to trim. * @param {string} [chars=whitespace] The characters to trim. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the trimmed string. * @example * @@ -13234,9 +13930,10 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to truncate. - * @param {Object} [options=({})] The options object. + * @param {Object} [options={}] The options object. * @param {number} [options.length=30] The maximum string length. * @param {string} [options.omission='...'] The string to indicate text is omitted. * @param {RegExp|string} [options.separator] The separator pattern to truncate to. @@ -13321,14 +14018,15 @@ /** * The inverse of `_.escape`; this method converts the HTML entities - * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their - * corresponding characters. + * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to + * their corresponding characters. * - * **Note:** No other HTML entities are unescaped. To unescape additional HTML - * entities use a third-party library like [_he_](https://mths.be/he). + * **Note:** No other HTML entities are unescaped. To unescape additional + * HTML entities use a third-party library like [_he_](https://mths.be/he). * * @static * @memberOf _ + * @since 0.6.0 * @category String * @param {string} [string=''] The string to unescape. * @returns {string} Returns the unescaped string. @@ -13349,6 +14047,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the upper cased string. @@ -13367,15 +14066,35 @@ return result + (index ? ' ' : '') + word.toUpperCase(); }); + /** + * Converts the first character of `string` to upper case. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.upperFirst('fred'); + * // => 'Fred' + * + * _.upperFirst('FRED'); + * // => 'FRED' + */ + var upperFirst = createCaseFirst('toUpperCase'); + /** * Splits `string` into an array of its words. * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to inspect. * @param {RegExp|string} [pattern] The pattern to match words. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the words of `string`. * @example * @@ -13403,8 +14122,10 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {Function} func The function to attempt. + * @param {...*} [args] The arguments to invoke `func` with. * @returns {*} Returns the `func` result or error object. * @example * @@ -13432,6 +14153,7 @@ * **Note:** This method doesn't set the "length" property of bound functions. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {Object} object The object to bind and assign the bound methods to. @@ -13449,7 +14171,7 @@ * * _.bindAll(view, 'onClick'); * jQuery(element).on('click', view.onClick); - * // => logs 'clicked docs' when clicked + * // => Logs 'clicked docs' when clicked. */ var bindAll = rest(function(object, methodNames) { arrayEach(baseFlatten(methodNames, 1), function(key) { @@ -13466,6 +14188,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {Array} pairs The predicate-function pairs. * @returns {Function} Returns the new function. @@ -13515,6 +14238,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {Object} source The object of property predicates to conform to. * @returns {Function} Returns the new function. @@ -13537,6 +14261,7 @@ * * @static * @memberOf _ + * @since 2.4.0 * @category Util * @param {*} value The value to return from the new function. * @returns {Function} Returns the new function. @@ -13561,6 +14286,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. * @returns {Function} Returns the new function. @@ -13581,6 +14307,7 @@ * invokes the given functions from right to left. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. @@ -13601,6 +14328,7 @@ * This method returns the first argument given to it. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {*} value Any value. @@ -13618,12 +14346,13 @@ /** * Creates a function that invokes `func` with the arguments of the created - * function. If `func` is a property name the created callback returns the - * property value for a given element. If `func` is an object the created - * callback returns `true` for elements that contain the equivalent object - * properties, otherwise it returns `false`. + * function. If `func` is a property name the created function returns the + * property value for a given element. If `func` is an array or object the + * created function returns `true` for elements that contain the equivalent + * source properties, otherwise it returns `false`. * * @static + * @since 4.0.0 * @memberOf _ * @category Util * @param {*} [func=_.identity] The value to convert to a callback. @@ -13631,20 +14360,31 @@ * @example * * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * + * // The `_.matches` iteratee shorthand. + * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true })); + * // => [{ 'user': 'barney', 'age': 36, 'active': true }] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.filter(users, _.iteratee(['user', 'fred'])); + * // => [{ 'user': 'fred', 'age': 40 }] + * + * // The `_.property` iteratee shorthand. + * _.map(users, _.iteratee('user')); + * // => ['barney', 'fred'] + * * // Create custom iteratee shorthands. - * _.iteratee = _.wrap(_.iteratee, function(callback, func) { - * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func); - * return !p ? callback(func) : function(object) { - * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]); + * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) { + * return !_.isRegExp(func) ? iteratee(func) : function(string) { + * return func.test(string); * }; * }); * - * _.filter(users, 'age > 36'); - * // => [{ 'user': 'fred', 'age': 40 }] + * _.filter(['abc', 'def'], /ef/); + * // => ['def'] */ function iteratee(func) { return baseIteratee(typeof func == 'function' ? func : baseClone(func, true)); @@ -13660,6 +14400,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {Object} source The object of property values to match. * @returns {Function} Returns the new function. @@ -13686,6 +14427,7 @@ * * @static * @memberOf _ + * @since 3.2.0 * @category Util * @param {Array|string} path The path of the property to get. * @param {*} srcValue The value to match. @@ -13710,6 +14452,7 @@ * * @static * @memberOf _ + * @since 3.7.0 * @category Util * @param {Array|string} path The path of the method to invoke. * @param {...*} [args] The arguments to invoke the method with. @@ -13724,8 +14467,8 @@ * _.map(objects, _.method('a.b.c')); * // => [2, 1] * - * _.invokeMap(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c'); - * // => [1, 2] + * _.map(objects, _.method(['a', 'b', 'c'])); + * // => [2, 1] */ var method = rest(function(path, args) { return function(object) { @@ -13740,6 +14483,7 @@ * * @static * @memberOf _ + * @since 3.7.0 * @category Util * @param {Object} object The object to query. * @param {...*} [args] The arguments to invoke the method with. @@ -13762,21 +14506,21 @@ }); /** - * Adds all own enumerable function properties of a source object to the - * destination object. If `object` is a function then methods are added to - * its prototype as well. + * Adds all own enumerable string keyed function properties of a source + * object to the destination object. If `object` is a function then methods + * are added to its prototype as well. * * **Note:** Use `_.runInContext` to create a pristine `lodash` function to * avoid conflicts caused by modifying the original. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {Function|Object} [object=lodash] The destination object. * @param {Object} source The object of functions to add. - * @param {Object} [options] The options object. - * @param {boolean} [options.chain=true] Specify whether the functions added - * are chainable. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.chain=true] Specify whether mixins are chainable. * @returns {Function|Object} Returns `object`. * @example * @@ -13838,6 +14582,7 @@ * the `lodash` function. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @returns {Function} Returns the `lodash` function. @@ -13858,6 +14603,7 @@ * * @static * @memberOf _ + * @since 2.3.0 * @category Util * @example * @@ -13875,6 +14621,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {number} [n=0] The index of the argument to return. * @returns {Function} Returns the new function. @@ -13898,6 +14645,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {...(Function|Function[])} iteratees The iteratees to invoke. * @returns {Function} Returns the new function. @@ -13916,6 +14664,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {...(Function|Function[])} predicates The predicates to check. * @returns {Function} Returns the new function. @@ -13940,6 +14689,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {...(Function|Function[])} predicates The predicates to check. * @returns {Function} Returns the new function. @@ -13963,6 +14713,7 @@ * * @static * @memberOf _ + * @since 2.4.0 * @category Util * @param {Array|string} path The path of the property to get. * @returns {Function} Returns the new function. @@ -13989,6 +14740,7 @@ * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {Object} object The object to query. * @returns {Function} Returns the new function. @@ -14019,6 +14771,7 @@ * floating-point values which can produce unexpected results. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {number} [start=0] The start of the range. @@ -14056,6 +14809,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. @@ -14091,6 +14845,7 @@ * each invocation. The iteratee is invoked with one argument; (index). * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {number} n The number of times to invoke `iteratee`. @@ -14112,7 +14867,7 @@ var index = MAX_ARRAY_LENGTH, length = nativeMin(n, MAX_ARRAY_LENGTH); - iteratee = baseCastFunction(iteratee); + iteratee = getIteratee(iteratee); n -= MAX_ARRAY_LENGTH; var result = baseTimes(length, iteratee); @@ -14127,6 +14882,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {*} value The value to convert. * @returns {Array} Returns the new property path array. @@ -14148,13 +14904,17 @@ * // => false */ function toPath(value) { - return isArray(value) ? arrayMap(value, String) : stringToPath(value); + if (isArray(value)) { + return arrayMap(value, baseCastKey); + } + return isSymbol(value) ? [value] : copyArray(stringToPath(value)); } /** * Generates a unique ID. If `prefix` is given the ID is appended to it. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {string} [prefix=''] The value to prefix the ID with. @@ -14179,6 +14939,7 @@ * * @static * @memberOf _ + * @since 3.4.0 * @category Math * @param {number} augend The first number in an addition. * @param {number} addend The second number in an addition. @@ -14188,25 +14949,16 @@ * _.add(6, 4); * // => 10 */ - function add(augend, addend) { - var result; - if (augend === undefined && addend === undefined) { - return 0; - } - if (augend !== undefined) { - result = augend; - } - if (addend !== undefined) { - result = result === undefined ? addend : (result + addend); - } - return result; - } + var add = createMathOperation(function(augend, addend) { + return augend + addend; + }); /** * Computes `number` rounded up to `precision`. * * @static * @memberOf _ + * @since 3.10.0 * @category Math * @param {number} number The number to round up. * @param {number} [precision=0] The precision to round up to. @@ -14224,11 +14976,31 @@ */ var ceil = createRound('ceil'); + /** + * Divide two numbers. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Math + * @param {number} dividend The first number in a division. + * @param {number} divisor The second number in a division. + * @returns {number} Returns the quotient. + * @example + * + * _.divide(6, 4); + * // => 1.5 + */ + var divide = createMathOperation(function(dividend, divisor) { + return dividend / divisor; + }); + /** * Computes `number` rounded down to `precision`. * * @static * @memberOf _ + * @since 3.10.0 * @category Math * @param {number} number The number to round down. * @param {number} [precision=0] The precision to round down to. @@ -14251,6 +15023,7 @@ * `undefined` is returned. * * @static + * @since 0.1.0 * @memberOf _ * @category Math * @param {Array} array The array to iterate over. @@ -14276,9 +15049,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {*} Returns the maximum value. * @example * @@ -14302,6 +15077,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. * @returns {number} Returns the mean. @@ -14311,7 +15087,35 @@ * // => 5 */ function mean(array) { - return sum(array) / (array ? array.length : 0); + return baseMean(array, identity); + } + + /** + * This method is like `_.mean` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the value to be averaged. + * The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Math + * @param {Array} array The array to iterate over. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. + * @returns {number} Returns the mean. + * @example + * + * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; + * + * _.meanBy(objects, function(o) { return o.n; }); + * // => 5 + * + * // The `_.property` iteratee shorthand. + * _.meanBy(objects, 'n'); + * // => 5 + */ + function meanBy(array, iteratee) { + return baseMean(array, getIteratee(iteratee)); } /** @@ -14319,6 +15123,7 @@ * `undefined` is returned. * * @static + * @since 0.1.0 * @memberOf _ * @category Math * @param {Array} array The array to iterate over. @@ -14344,9 +15149,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {*} Returns the minimum value. * @example * @@ -14365,11 +15172,31 @@ : undefined; } + /** + * Multiply two numbers. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Math + * @param {number} multiplier The first number in a multiplication. + * @param {number} multiplicand The second number in a multiplication. + * @returns {number} Returns the product. + * @example + * + * _.multiply(6, 4); + * // => 24 + */ + var multiply = createMathOperation(function(multiplier, multiplicand) { + return multiplier * multiplicand; + }); + /** * Computes `number` rounded to `precision`. * * @static * @memberOf _ + * @since 3.10.0 * @category Math * @param {number} number The number to round. * @param {number} [precision=0] The precision to round to. @@ -14392,6 +15219,7 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {number} minuend The first number in a subtraction. * @param {number} subtrahend The second number in a subtraction. @@ -14401,25 +15229,16 @@ * _.subtract(6, 4); * // => 2 */ - function subtract(minuend, subtrahend) { - var result; - if (minuend === undefined && subtrahend === undefined) { - return 0; - } - if (minuend !== undefined) { - result = minuend; - } - if (subtrahend !== undefined) { - result = result === undefined ? subtrahend : (result - subtrahend); - } - return result; - } + var subtract = createMathOperation(function(minuend, subtrahend) { + return minuend - subtrahend; + }); /** * Computes the sum of the values in `array`. * * @static * @memberOf _ + * @since 3.4.0 * @category Math * @param {Array} array The array to iterate over. * @returns {number} Returns the sum. @@ -14441,9 +15260,11 @@ * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {number} Returns the sum. * @example * @@ -14464,40 +15285,7 @@ /*------------------------------------------------------------------------*/ - // Ensure wrappers are instances of `baseLodash`. - lodash.prototype = baseLodash.prototype; - lodash.prototype.constructor = lodash; - - LodashWrapper.prototype = baseCreate(baseLodash.prototype); - LodashWrapper.prototype.constructor = LodashWrapper; - - LazyWrapper.prototype = baseCreate(baseLodash.prototype); - LazyWrapper.prototype.constructor = LazyWrapper; - - // Avoid inheriting from `Object.prototype` when possible. - Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto; - - // Add functions to the `MapCache`. - MapCache.prototype.clear = mapClear; - MapCache.prototype['delete'] = mapDelete; - MapCache.prototype.get = mapGet; - MapCache.prototype.has = mapHas; - MapCache.prototype.set = mapSet; - - // Add functions to the `SetCache`. - SetCache.prototype.push = cachePush; - - // Add functions to the `Stack` cache. - Stack.prototype.clear = stackClear; - Stack.prototype['delete'] = stackDelete; - Stack.prototype.get = stackGet; - Stack.prototype.has = stackHas; - Stack.prototype.set = stackSet; - - // Assign cache to `_.memoize`. - memoize.Cache = MapCache; - - // Add functions that return wrapped values when chaining. + // Add methods that return wrapped values in chain sequences. lodash.after = after; lodash.ary = ary; lodash.assign = assign; @@ -14536,6 +15324,8 @@ lodash.fill = fill; lodash.filter = filter; lodash.flatMap = flatMap; + lodash.flatMapDeep = flatMapDeep; + lodash.flatMapDepth = flatMapDepth; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; lodash.flattenDepth = flattenDepth; @@ -14647,15 +15437,17 @@ lodash.zipWith = zipWith; // Add aliases. + lodash.entries = toPairs; + lodash.entriesIn = toPairsIn; lodash.extend = assignIn; lodash.extendWith = assignInWith; - // Add functions to `lodash.prototype`. + // Add methods to `lodash.prototype`. mixin(lodash, lodash); /*------------------------------------------------------------------------*/ - // Add functions that return unwrapped values when chaining. + // Add methods that return unwrapped values in chain sequences. lodash.add = add; lodash.attempt = attempt; lodash.camelCase = camelCase; @@ -14667,6 +15459,7 @@ lodash.cloneDeepWith = cloneDeepWith; lodash.cloneWith = cloneWith; lodash.deburr = deburr; + lodash.divide = divide; lodash.endsWith = endsWith; lodash.eq = eq; lodash.escape = escape; @@ -14744,8 +15537,10 @@ lodash.max = max; lodash.maxBy = maxBy; lodash.mean = mean; + lodash.meanBy = meanBy; lodash.min = min; lodash.minBy = minBy; + lodash.multiply = multiply; lodash.noConflict = noConflict; lodash.noop = noop; lodash.now = now; @@ -14985,7 +15780,7 @@ }; }); - // Add `Array` and `String` methods to `lodash.prototype`. + // Add `Array` methods to `lodash.prototype`. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { var func = arrayProto[methodName], chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', @@ -14994,15 +15789,16 @@ lodash.prototype[methodName] = function() { var args = arguments; if (retUnwrapped && !this.__chain__) { - return func.apply(this.value(), args); + var value = this.value(); + return func.apply(isArray(value) ? value : [], args); } return this[chainName](function(value) { - return func.apply(value, args); + return func.apply(isArray(value) ? value : [], args); }); }; }); - // Map minified function names to their real names. + // Map minified method names to their real names. baseForOwn(LazyWrapper.prototype, function(func, methodName) { var lodashFunc = lodash[methodName]; if (lodashFunc) { @@ -15018,16 +15814,15 @@ 'func': undefined }]; - // Add functions to the lazy wrapper. + // Add methods to `LazyWrapper`. LazyWrapper.prototype.clone = lazyClone; LazyWrapper.prototype.reverse = lazyReverse; LazyWrapper.prototype.value = lazyValue; - // Add chaining functions to the `lodash` wrapper. + // Add chain sequence methods to the `lodash` wrapper. lodash.prototype.at = wrapperAt; lodash.prototype.chain = wrapperChain; lodash.prototype.commit = wrapperCommit; - lodash.prototype.flatMap = wrapperFlatMap; lodash.prototype.next = wrapperNext; lodash.prototype.plant = wrapperPlant; lodash.prototype.reverse = wrapperReverse; diff --git a/map.js b/map.js index 0d37011fc..35195cb96 100644 --- a/map.js +++ b/map.js @@ -16,9 +16,11 @@ define(['./_arrayMap', './_baseIteratee', './_baseMap', './isArray'], function(a * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new mapped array. * @example * diff --git a/mapKeys.js b/mapKeys.js index 6d2e4d2c8..efeb05917 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -3,14 +3,16 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) /** * The opposite of `_.mapValues`; this method creates an object with the * same values as `object` and keys generated by running each own enumerable - * property of `object` through `iteratee`. The iteratee is invoked with - * three arguments: (value, key, object). + * string keyed property of `object` through `iteratee`. The iteratee is + * invoked with three arguments: (value, key, object). * * @static * @memberOf _ + * @since 3.8.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @example * diff --git a/mapValues.js b/mapValues.js index 97c699776..e35fa7b4b 100644 --- a/mapValues.js +++ b/mapValues.js @@ -2,14 +2,17 @@ define(['./_baseForOwn', './_baseIteratee'], function(baseForOwn, baseIteratee) /** * Creates an object with the same keys as `object` and values generated by - * running each own enumerable property of `object` through `iteratee`. The - * iteratee is invoked with three arguments: (value, key, object). + * running each own enumerable string keyed property of `object` through + * `iteratee`. The iteratee is invoked with three arguments: + * (value, key, object). * * @static * @memberOf _ + * @since 2.4.0 * @category Object * @param {Object} object The object to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The function invoked per iteration. * @returns {Object} Returns the new mapped object. * @example * diff --git a/matches.js b/matches.js index 413e39607..9104bc5ee 100644 --- a/matches.js +++ b/matches.js @@ -10,6 +10,7 @@ define(['./_baseClone', './_baseMatches'], function(baseClone, baseMatches) { * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {Object} source The object of property values to match. * @returns {Function} Returns the new function. diff --git a/matchesProperty.js b/matchesProperty.js index 7f4c6ada0..bc4724841 100644 --- a/matchesProperty.js +++ b/matchesProperty.js @@ -9,6 +9,7 @@ define(['./_baseClone', './_baseMatchesProperty'], function(baseClone, baseMatch * * @static * @memberOf _ + * @since 3.2.0 * @category Util * @param {Array|string} path The path of the property to get. * @param {*} srcValue The value to match. diff --git a/math.js b/math.js index d9d5ca27d..d662e00c0 100644 --- a/math.js +++ b/math.js @@ -1,13 +1,16 @@ -define(['./add', './ceil', './floor', './max', './maxBy', './mean', './min', './minBy', './round', './subtract', './sum', './sumBy'], function(add, ceil, floor, max, maxBy, mean, min, minBy, round, subtract, sum, sumBy) { +define(['./add', './ceil', './divide', './floor', './max', './maxBy', './mean', './meanBy', './min', './minBy', './multiply', './round', './subtract', './sum', './sumBy'], function(add, ceil, divide, floor, max, maxBy, mean, meanBy, min, minBy, multiply, round, subtract, sum, sumBy) { return { 'add': add, 'ceil': ceil, + 'divide': divide, 'floor': floor, 'max': max, 'maxBy': maxBy, 'mean': mean, + 'meanBy': meanBy, 'min': min, 'minBy': minBy, + 'multiply': multiply, 'round': round, 'subtract': subtract, 'sum': sum, diff --git a/max.js b/max.js index ce11d1674..06c792c37 100644 --- a/max.js +++ b/max.js @@ -8,6 +8,7 @@ define(['./_baseExtremum', './gt', './identity'], function(baseExtremum, gt, ide * `undefined` is returned. * * @static + * @since 0.1.0 * @memberOf _ * @category Math * @param {Array} array The array to iterate over. diff --git a/maxBy.js b/maxBy.js index 794fb8b47..0f5e9e608 100644 --- a/maxBy.js +++ b/maxBy.js @@ -10,9 +10,11 @@ define(['./_baseExtremum', './_baseIteratee', './gt'], function(baseExtremum, ba * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {*} Returns the maximum value. * @example * diff --git a/mean.js b/mean.js index 5ee6669b5..9b8f11f95 100644 --- a/mean.js +++ b/mean.js @@ -1,10 +1,11 @@ -define(['./sum'], function(sum) { +define(['./_baseMean', './identity'], function(baseMean, identity) { /** * Computes the mean of the values in `array`. * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. * @returns {number} Returns the mean. @@ -14,7 +15,7 @@ define(['./sum'], function(sum) { * // => 5 */ function mean(array) { - return sum(array) / (array ? array.length : 0); + return baseMean(array, identity); } return mean; diff --git a/meanBy.js b/meanBy.js new file mode 100644 index 000000000..567258316 --- /dev/null +++ b/meanBy.js @@ -0,0 +1,32 @@ +define(['./_baseIteratee', './_baseMean'], function(baseIteratee, baseMean) { + + /** + * This method is like `_.mean` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the value to be averaged. + * The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Math + * @param {Array} array The array to iterate over. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. + * @returns {number} Returns the mean. + * @example + * + * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; + * + * _.meanBy(objects, function(o) { return o.n; }); + * // => 5 + * + * // The `_.property` iteratee shorthand. + * _.meanBy(objects, 'n'); + * // => 5 + */ + function meanBy(array, iteratee) { + return baseMean(array, baseIteratee(iteratee)); + } + + return meanBy; +}); diff --git a/memoize.js b/memoize.js index 587899031..b21a9757d 100644 --- a/memoize.js +++ b/memoize.js @@ -12,11 +12,13 @@ define(['./_MapCache'], function(MapCache) { * * **Note:** The cache is exposed as the `cache` property on the memoized * 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/6.0/#sec-properties-of-the-map-prototype-object) + * constructor with one whose instances implement the + * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object) * method interface of `delete`, `get`, `has`, and `set`. * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to have its output memoized. * @param {Function} [resolver] The function to resolve the cache key. @@ -61,7 +63,7 @@ define(['./_MapCache'], function(MapCache) { memoized.cache = cache.set(key, result); return result; }; - memoized.cache = new memoize.Cache; + memoized.cache = new (memoize.Cache || MapCache); return memoized; } diff --git a/merge.js b/merge.js index ce57040a3..b9362cfbf 100644 --- a/merge.js +++ b/merge.js @@ -2,17 +2,18 @@ define(['./_baseMerge', './_createAssigner'], function(baseMerge, createAssigner /** * This method is like `_.assign` except that it recursively merges own and - * inherited enumerable properties of source objects into the destination - * object. Source properties that resolve to `undefined` are skipped if a - * destination value exists. Array and plain object properties are merged - * recursively.Other objects and value types are overridden by assignment. - * Source objects are applied from left to right. Subsequent sources - * overwrite property assignments of previous sources. + * inherited enumerable string keyed properties of source objects into the + * destination object. Source properties that resolve to `undefined` are + * skipped if a destination value exists. Array and plain object properties + * are merged recursively.Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object`. * * @static * @memberOf _ + * @since 0.5.0 * @category Object * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. diff --git a/mergeWith.js b/mergeWith.js index 326edb4c3..df7b6a3d5 100644 --- a/mergeWith.js +++ b/mergeWith.js @@ -11,6 +11,7 @@ define(['./_baseMerge', './_createAssigner'], function(baseMerge, createAssigner * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The destination object. * @param {...Object} sources The source objects. diff --git a/method.js b/method.js index b7403fd15..84a87e506 100644 --- a/method.js +++ b/method.js @@ -6,6 +6,7 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * * @static * @memberOf _ + * @since 3.7.0 * @category Util * @param {Array|string} path The path of the method to invoke. * @param {...*} [args] The arguments to invoke the method with. @@ -20,8 +21,8 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * _.map(objects, _.method('a.b.c')); * // => [2, 1] * - * _.invokeMap(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c'); - * // => [1, 2] + * _.map(objects, _.method(['a', 'b', 'c'])); + * // => [2, 1] */ var method = rest(function(path, args) { return function(object) { diff --git a/methodOf.js b/methodOf.js index 3a6996105..b619cc904 100644 --- a/methodOf.js +++ b/methodOf.js @@ -7,6 +7,7 @@ define(['./_baseInvoke', './rest'], function(baseInvoke, rest) { * * @static * @memberOf _ + * @since 3.7.0 * @category Util * @param {Object} object The object to query. * @param {...*} [args] The arguments to invoke the method with. diff --git a/min.js b/min.js index 49a64e25d..6f30e4cb4 100644 --- a/min.js +++ b/min.js @@ -8,6 +8,7 @@ define(['./_baseExtremum', './identity', './lt'], function(baseExtremum, identit * `undefined` is returned. * * @static + * @since 0.1.0 * @memberOf _ * @category Math * @param {Array} array The array to iterate over. diff --git a/minBy.js b/minBy.js index 652286c01..99cdb108d 100644 --- a/minBy.js +++ b/minBy.js @@ -10,9 +10,11 @@ define(['./_baseExtremum', './_baseIteratee', './lt'], function(baseExtremum, ba * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {*} Returns the minimum value. * @example * diff --git a/mixin.js b/mixin.js index f8e972ca6..c1903aa91 100644 --- a/mixin.js +++ b/mixin.js @@ -1,21 +1,21 @@ define(['./_arrayEach', './_arrayPush', './_baseFunctions', './_copyArray', './isFunction', './isObject', './keys'], function(arrayEach, arrayPush, baseFunctions, copyArray, isFunction, isObject, keys) { /** - * Adds all own enumerable function properties of a source object to the - * destination object. If `object` is a function then methods are added to - * its prototype as well. + * Adds all own enumerable string keyed function properties of a source + * object to the destination object. If `object` is a function then methods + * are added to its prototype as well. * * **Note:** Use `_.runInContext` to create a pristine `lodash` function to * avoid conflicts caused by modifying the original. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {Function|Object} [object=lodash] The destination object. * @param {Object} source The object of functions to add. - * @param {Object} [options] The options object. - * @param {boolean} [options.chain=true] Specify whether the functions added - * are chainable. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.chain=true] Specify whether mixins are chainable. * @returns {Function|Object} Returns `object`. * @example * diff --git a/multiply.js b/multiply.js new file mode 100644 index 000000000..3967deca1 --- /dev/null +++ b/multiply.js @@ -0,0 +1,23 @@ +define(['./_createMathOperation'], function(createMathOperation) { + + /** + * Multiply two numbers. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Math + * @param {number} multiplier The first number in a multiplication. + * @param {number} multiplicand The second number in a multiplication. + * @returns {number} Returns the product. + * @example + * + * _.multiply(6, 4); + * // => 24 + */ + var multiply = createMathOperation(function(multiplier, multiplicand) { + return multiplier * multiplicand; + }); + + return multiply; +}); diff --git a/negate.js b/negate.js index 8ebc36d16..7dc297d00 100644 --- a/negate.js +++ b/negate.js @@ -10,6 +10,7 @@ define([], function() { * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} predicate The predicate to negate. * @returns {Function} Returns the new function. diff --git a/next.js b/next.js index ec30008e0..59e98cc96 100644 --- a/next.js +++ b/next.js @@ -9,6 +9,7 @@ define(['./toArray'], function(toArray) { * * @name next * @memberOf _ + * @since 4.0.0 * @category Seq * @returns {Object} Returns the next iterator value. * @example diff --git a/noop.js b/noop.js index 66bb011b5..215980316 100644 --- a/noop.js +++ b/noop.js @@ -6,6 +6,7 @@ define([], function() { * * @static * @memberOf _ + * @since 2.3.0 * @category Util * @example * diff --git a/now.js b/now.js index f84dcff36..13bd9e7f7 100644 --- a/now.js +++ b/now.js @@ -6,6 +6,7 @@ define([], function() { * * @static * @memberOf _ + * @since 2.4.0 * @type {Function} * @category Date * @returns {number} Returns the timestamp. @@ -14,7 +15,7 @@ define([], function() { * _.defer(function(stamp) { * console.log(_.now() - stamp); * }, _.now()); - * // => logs the number of milliseconds it took for the deferred function to be invoked + * // => Logs the number of milliseconds it took for the deferred function to be invoked. */ var now = Date.now; diff --git a/nthArg.js b/nthArg.js index 01b1170fc..b6a2022e0 100644 --- a/nthArg.js +++ b/nthArg.js @@ -5,6 +5,7 @@ define(['./toInteger'], function(toInteger) { * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {number} [n=0] The index of the argument to return. * @returns {Function} Returns the new function. diff --git a/object.js b/object.js index 4c022f102..d3e63db36 100644 --- a/object.js +++ b/object.js @@ -1,4 +1,4 @@ -define(['./assign', './assignIn', './assignInWith', './assignWith', './create', './defaults', './defaultsDeep', './extend', './extendWith', './findKey', './findLastKey', './forIn', './forInRight', './forOwn', './forOwnRight', './functions', './functionsIn', './get', './has', './hasIn', './invert', './invertBy', './invoke', './keys', './keysIn', './mapKeys', './mapValues', './merge', './mergeWith', './omit', './omitBy', './pick', './pickBy', './result', './set', './setWith', './toPairs', './toPairsIn', './transform', './unset', './update', './updateWith', './values', './valuesIn'], function(assign, assignIn, assignInWith, assignWith, create, defaults, defaultsDeep, extend, extendWith, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, functionsIn, get, has, hasIn, invert, invertBy, invoke, keys, keysIn, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, result, set, setWith, toPairs, toPairsIn, transform, unset, update, updateWith, values, valuesIn) { +define(['./assign', './assignIn', './assignInWith', './assignWith', './create', './defaults', './defaultsDeep', './entries', './entriesIn', './extend', './extendWith', './findKey', './findLastKey', './forIn', './forInRight', './forOwn', './forOwnRight', './functions', './functionsIn', './get', './has', './hasIn', './invert', './invertBy', './invoke', './keys', './keysIn', './mapKeys', './mapValues', './merge', './mergeWith', './omit', './omitBy', './pick', './pickBy', './result', './set', './setWith', './toPairs', './toPairsIn', './transform', './unset', './update', './updateWith', './values', './valuesIn'], function(assign, assignIn, assignInWith, assignWith, create, defaults, defaultsDeep, entries, entriesIn, extend, extendWith, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, functionsIn, get, has, hasIn, invert, invertBy, invoke, keys, keysIn, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, result, set, setWith, toPairs, toPairsIn, transform, unset, update, updateWith, values, valuesIn) { return { 'assign': assign, 'assignIn': assignIn, @@ -7,6 +7,8 @@ define(['./assign', './assignIn', './assignInWith', './assignWith', './create', 'create': create, 'defaults': defaults, 'defaultsDeep': defaultsDeep, + 'entries': entries, + 'entriesIn': entriesIn, 'extend': extend, 'extendWith': extendWith, 'findKey': findKey, diff --git a/omit.js b/omit.js index 2d4303713..be537017f 100644 --- a/omit.js +++ b/omit.js @@ -1,15 +1,17 @@ -define(['./_arrayMap', './_baseDifference', './_baseFlatten', './_basePick', './keysIn', './rest'], function(arrayMap, baseDifference, baseFlatten, basePick, keysIn, rest) { +define(['./_arrayMap', './_baseCastKey', './_baseDifference', './_baseFlatten', './_basePick', './_getAllKeysIn', './rest'], function(arrayMap, baseCastKey, baseDifference, baseFlatten, basePick, getAllKeysIn, rest) { /** * The opposite of `_.pick`; this method creates an object composed of the - * own and inherited enumerable properties of `object` that are not omitted. + * own and inherited enumerable string keyed properties of `object` that are + * not omitted. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property names to omit, specified - * individually or in arrays. + * @param {...(string|string[])} [props] The property identifiers to omit, + * specified individually or in arrays. * @returns {Object} Returns the new object. * @example * @@ -22,8 +24,8 @@ define(['./_arrayMap', './_baseDifference', './_baseFlatten', './_basePick', './ if (object == null) { return {}; } - props = arrayMap(baseFlatten(props, 1), String); - return basePick(object, baseDifference(keysIn(object), props)); + props = arrayMap(baseFlatten(props, 1), baseCastKey); + return basePick(object, baseDifference(getAllKeysIn(object), props)); }); return omit; diff --git a/omitBy.js b/omitBy.js index 2c72b1f76..0fe502c83 100644 --- a/omitBy.js +++ b/omitBy.js @@ -2,15 +2,17 @@ define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) /** * The opposite of `_.pickBy`; this method creates an object composed of - * the own and inherited enumerable properties of `object` that `predicate` - * doesn't return truthy for. The predicate is invoked with two arguments: - * (value, key). + * the own and inherited enumerable string keyed properties of `object` that + * `predicate` doesn't return truthy for. The predicate is invoked with two + * arguments: (value, key). * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per property. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per property. * @returns {Object} Returns the new object. * @example * diff --git a/once.js b/once.js index abb183827..22c0aff46 100644 --- a/once.js +++ b/once.js @@ -7,6 +7,7 @@ define(['./before'], function(before) { * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. diff --git a/orderBy.js b/orderBy.js index 3257021b7..25ce65a2b 100644 --- a/orderBy.js +++ b/orderBy.js @@ -11,24 +11,26 @@ define(['./_baseOrderBy', './isArray'], function(baseOrderBy, isArray) { * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function[]|Object[]|string[]} [iteratees=[_.identity]] The iteratees to sort by. + * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] + * The iteratees to sort by. * @param {string[]} [orders] The sort orders of `iteratees`. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. * @returns {Array} Returns the new sorted array. * @example * * var users = [ * { 'user': 'fred', 'age': 48 }, * { 'user': 'barney', 'age': 34 }, - * { 'user': 'fred', 'age': 42 }, + * { 'user': 'fred', 'age': 40 }, * { 'user': 'barney', 'age': 36 } * ]; * * // Sort by `user` in ascending order and by `age` in descending order. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] */ function orderBy(collection, iteratees, orders, guard) { if (collection == null) { diff --git a/over.js b/over.js index c3ca7f249..b66f15bcd 100644 --- a/over.js +++ b/over.js @@ -6,6 +6,7 @@ define(['./_arrayMap', './_createOver'], function(arrayMap, createOver) { * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {...(Function|Function[])} iteratees The iteratees to invoke. * @returns {Function} Returns the new function. diff --git a/overArgs.js b/overArgs.js index ef78e6a31..99e8471d0 100644 --- a/overArgs.js +++ b/overArgs.js @@ -8,6 +8,7 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './rest' * corresponding `transforms`. * * @static + * @since 4.0.0 * @memberOf _ * @category Function * @param {Function} func The function to wrap. diff --git a/overEvery.js b/overEvery.js index 810468274..b2f2f3be2 100644 --- a/overEvery.js +++ b/overEvery.js @@ -6,6 +6,7 @@ define(['./_arrayEvery', './_createOver'], function(arrayEvery, createOver) { * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {...(Function|Function[])} predicates The predicates to check. * @returns {Function} Returns the new function. diff --git a/overSome.js b/overSome.js index 04421cdd7..23bb7e23b 100644 --- a/overSome.js +++ b/overSome.js @@ -6,6 +6,7 @@ define(['./_arraySome', './_createOver'], function(arraySome, createOver) { * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {...(Function|Function[])} predicates The predicates to check. * @returns {Function} Returns the new function. diff --git a/package.json b/package.json index 7f3b7ed02..4cb5ed4d7 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "lodash-amd", - "version": "4.6.1", + "version": "4.7.0", "description": "Lodash exported as AMD modules.", "homepage": "https://lodash.com/custom-builds", "license": "MIT", "main": "main.js", + "private": true, "keywords": "amd, modules, stdlib, util", "author": "John-David Dalton (http://allyoucanleet.com/)", "contributors": [ diff --git a/pad.js b/pad.js index cd98c62ab..1e6965223 100644 --- a/pad.js +++ b/pad.js @@ -10,6 +10,7 @@ define(['./_createPadding', './_stringSize', './toInteger', './toString'], funct * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to pad. * @param {number} [length=0] The padding length. @@ -30,15 +31,16 @@ define(['./_createPadding', './_stringSize', './toInteger', './toString'], funct string = toString(string); length = toInteger(length); - var strLength = stringSize(string); + var strLength = length ? stringSize(string) : 0; if (!length || strLength >= length) { return string; } - var mid = (length - strLength) / 2, - leftLength = nativeFloor(mid), - rightLength = nativeCeil(mid); - - return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars); + var mid = (length - strLength) / 2; + return ( + createPadding(nativeFloor(mid), chars) + + string + + createPadding(nativeCeil(mid), chars) + ); } return pad; diff --git a/padEnd.js b/padEnd.js index 993e2e426..ac65e79be 100644 --- a/padEnd.js +++ b/padEnd.js @@ -1,4 +1,4 @@ -define(['./_createPadding', './toString'], function(createPadding, toString) { +define(['./_createPadding', './_stringSize', './toInteger', './toString'], function(createPadding, stringSize, toInteger, toString) { /** * Pads `string` on the right side if it's shorter than `length`. Padding @@ -6,6 +6,7 @@ define(['./_createPadding', './toString'], function(createPadding, toString) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to pad. * @param {number} [length=0] The padding length. @@ -24,7 +25,12 @@ define(['./_createPadding', './toString'], function(createPadding, toString) { */ function padEnd(string, length, chars) { string = toString(string); - return string + createPadding(string, length, chars); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (string + createPadding(length - strLength, chars)) + : string; } return padEnd; diff --git a/padStart.js b/padStart.js index 2dd041356..0543e7e2e 100644 --- a/padStart.js +++ b/padStart.js @@ -1,4 +1,4 @@ -define(['./_createPadding', './toString'], function(createPadding, toString) { +define(['./_createPadding', './_stringSize', './toInteger', './toString'], function(createPadding, stringSize, toInteger, toString) { /** * Pads `string` on the left side if it's shorter than `length`. Padding @@ -6,6 +6,7 @@ define(['./_createPadding', './toString'], function(createPadding, toString) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to pad. * @param {number} [length=0] The padding length. @@ -24,7 +25,12 @@ define(['./_createPadding', './toString'], function(createPadding, toString) { */ function padStart(string, length, chars) { string = toString(string); - return createPadding(string, length, chars) + string; + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (createPadding(length - strLength, chars) + string) + : string; } return padStart; diff --git a/parseInt.js b/parseInt.js index 93f994f81..d6aaa0f21 100644 --- a/parseInt.js +++ b/parseInt.js @@ -11,18 +11,19 @@ define(['./_root', './toString'], function(root, toString) { /** * Converts `string` to an integer of the specified radix. If `radix` is - * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal, - * in which case a `radix` of `16` is used. + * `undefined` or `0`, a `radix` of `10` is used unless `value` is a + * hexadecimal, in which case a `radix` of `16` is used. * - * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2) - * of `parseInt`. + * **Note:** This method aligns with the + * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. * * @static * @memberOf _ + * @since 1.1.0 * @category String * @param {string} string The string to convert. * @param {number} [radix=10] The radix to interpret `value` by. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {number} Returns the converted integer. * @example * @@ -34,7 +35,7 @@ define(['./_root', './toString'], function(root, toString) { */ function parseInt(string, radix, guard) { // Chrome fails to trim leading whitespace characters. - // See https://code.google.com/p/v8/issues/detail?id=3109 for more details. + // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details. if (guard || radix == null) { radix = 0; } else if (radix) { diff --git a/partial.js b/partial.js index 6c592224a..16fa6f294 100644 --- a/partial.js +++ b/partial.js @@ -19,6 +19,7 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], * * @static * @memberOf _ + * @since 0.2.0 * @category Function * @param {Function} func The function to partially apply arguments to. * @param {...*} [partials] The arguments to be partially applied. diff --git a/partialRight.js b/partialRight.js index bc8169ce9..71d15acf3 100644 --- a/partialRight.js +++ b/partialRight.js @@ -18,6 +18,7 @@ define(['./_createWrapper', './_getPlaceholder', './_replaceHolders', './rest'], * * @static * @memberOf _ + * @since 1.0.0 * @category Function * @param {Function} func The function to partially apply arguments to. * @param {...*} [partials] The arguments to be partially applied. diff --git a/partition.js b/partition.js index 8702e9829..01475c64c 100644 --- a/partition.js +++ b/partition.js @@ -8,9 +8,11 @@ define(['./_createAggregator'], function(createAggregator) { * * @static * @memberOf _ + * @since 3.0.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the array of grouped elements. * @example * diff --git a/pick.js b/pick.js index 182ff3665..52d6ffc8d 100644 --- a/pick.js +++ b/pick.js @@ -4,11 +4,12 @@ define(['./_baseFlatten', './_basePick', './rest'], function(baseFlatten, basePi * Creates an object composed of the picked `object` properties. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property names to pick, specified - * individually or in arrays. + * @param {...(string|string[])} [props] The property identifiers to pick, + * specified individually or in arrays. * @returns {Object} Returns the new object. * @example * diff --git a/pickBy.js b/pickBy.js index 65f6c6c0d..d184cb878 100644 --- a/pickBy.js +++ b/pickBy.js @@ -6,9 +6,11 @@ define(['./_baseIteratee', './_basePickBy'], function(baseIteratee, basePickBy) * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The source object. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per property. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per property. * @returns {Object} Returns the new object. * @example * diff --git a/plant.js b/plant.js index af5a1932b..1de366841 100644 --- a/plant.js +++ b/plant.js @@ -4,10 +4,11 @@ define(['./_baseLodash', './_wrapperClone'], function(baseLodash, wrapperClone) var undefined; /** - * Creates a clone of the chained sequence planting `value` as the wrapped value. + * Creates a clone of the chain sequence planting `value` as the wrapped value. * * @name plant * @memberOf _ + * @since 3.2.0 * @category Seq * @param {*} value The value to plant. * @returns {Object} Returns the new `lodash` wrapper instance. diff --git a/property.js b/property.js index ad60026ed..0e7f36744 100644 --- a/property.js +++ b/property.js @@ -5,6 +5,7 @@ define(['./_baseProperty', './_basePropertyDeep', './_isKey'], function(baseProp * * @static * @memberOf _ + * @since 2.4.0 * @category Util * @param {Array|string} path The path of the property to get. * @returns {Function} Returns the new function. diff --git a/propertyOf.js b/propertyOf.js index 7b9246880..9a7fad1cc 100644 --- a/propertyOf.js +++ b/propertyOf.js @@ -9,6 +9,7 @@ define(['./_baseGet'], function(baseGet) { * * @static * @memberOf _ + * @since 3.0.0 * @category Util * @param {Object} object The object to query. * @returns {Function} Returns the new function. diff --git a/pull.js b/pull.js index 764d0327f..600478d2b 100644 --- a/pull.js +++ b/pull.js @@ -10,6 +10,7 @@ define(['./pullAll', './rest'], function(pullAll, rest) { * * @static * @memberOf _ + * @since 2.0.0 * @category Array * @param {Array} array The array to modify. * @param {...*} [values] The values to remove. diff --git a/pullAll.js b/pullAll.js index cc62ebc3b..fbc2a158e 100644 --- a/pullAll.js +++ b/pullAll.js @@ -7,6 +7,7 @@ define(['./_basePullAll'], function(basePullAll) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. diff --git a/pullAllBy.js b/pullAllBy.js index c50fc5186..4e610bd5d 100644 --- a/pullAllBy.js +++ b/pullAllBy.js @@ -9,10 +9,12 @@ define(['./_baseIteratee', './_basePullAll'], function(baseIteratee, basePullAll * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns `array`. * @example * diff --git a/pullAllWith.js b/pullAllWith.js index 22b18cf9c..46df678f7 100644 --- a/pullAllWith.js +++ b/pullAllWith.js @@ -12,6 +12,7 @@ define(['./_basePullAll'], function(basePullAll) { * * @static * @memberOf _ + * @since 4.6.0 * @category Array * @param {Array} array The array to modify. * @param {Array} values The values to remove. diff --git a/pullAt.js b/pullAt.js index 8b789b1c9..77518365e 100644 --- a/pullAt.js +++ b/pullAt.js @@ -8,6 +8,7 @@ define(['./_arrayMap', './_baseAt', './_baseFlatten', './_basePullAt', './_compa * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to modify. * @param {...(number|number[])} [indexes] The indexes of elements to remove, diff --git a/random.js b/random.js index 35f065cfc..17378ed29 100644 --- a/random.js +++ b/random.js @@ -13,14 +13,15 @@ define(['./_baseRandom', './_isIterateeCall', './toNumber'], function(baseRandom /** * Produces a random number between the inclusive `lower` and `upper` bounds. * If only one argument is provided a number between `0` and the given number - * is returned. If `floating` is `true`, or either `lower` or `upper` are floats, - * a floating-point number is returned instead of an integer. + * is returned. If `floating` is `true`, or either `lower` or `upper` are + * floats, a floating-point number is returned instead of an integer. * * **Note:** JavaScript follows the IEEE-754 standard for resolving * floating-point values which can produce unexpected results. * * @static * @memberOf _ + * @since 0.7.0 * @category Number * @param {number} [lower=0] The lower bound. * @param {number} [upper=1] The upper bound. diff --git a/range.js b/range.js index 1f9f13008..d2957bbcf 100644 --- a/range.js +++ b/range.js @@ -10,6 +10,7 @@ define(['./_createRange'], function(createRange) { * floating-point values which can produce unexpected results. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {number} [start=0] The start of the range. diff --git a/rangeRight.js b/rangeRight.js index 78c6d77fd..aff1f286b 100644 --- a/rangeRight.js +++ b/rangeRight.js @@ -6,6 +6,7 @@ define(['./_createRange'], function(createRange) { * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. diff --git a/rearg.js b/rearg.js index a30e435a9..5bddbe49f 100644 --- a/rearg.js +++ b/rearg.js @@ -14,6 +14,7 @@ define(['./_baseFlatten', './_createWrapper', './rest'], function(baseFlatten, c * * @static * @memberOf _ + * @since 3.0.0 * @category Function * @param {Function} func The function to rearrange arguments for. * @param {...(number|number[])} indexes The arranged argument indexes, diff --git a/reduce.js b/reduce.js index ed81bc3c4..906d2e02d 100644 --- a/reduce.js +++ b/reduce.js @@ -17,6 +17,7 @@ define(['./_arrayReduce', './_baseEach', './_baseIteratee', './_baseReduce', './ * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. diff --git a/reduceRight.js b/reduceRight.js index ce8a230f6..5d4af66cb 100644 --- a/reduceRight.js +++ b/reduceRight.js @@ -6,6 +6,7 @@ define(['./_arrayReduceRight', './_baseEachRight', './_baseIteratee', './_baseRe * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. diff --git a/reject.js b/reject.js index 86785c66d..0b2844214 100644 --- a/reject.js +++ b/reject.js @@ -6,9 +6,11 @@ define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], func * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new filtered array. * @example * diff --git a/remove.js b/remove.js index 21413ac04..3b383036d 100644 --- a/remove.js +++ b/remove.js @@ -10,9 +10,11 @@ define(['./_baseIteratee', './_basePullAt'], function(baseIteratee, basePullAt) * * @static * @memberOf _ + * @since 2.0.0 * @category Array * @param {Array} array The array to modify. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the new array of removed elements. * @example * diff --git a/repeat.js b/repeat.js index c780e7c66..913987ebd 100644 --- a/repeat.js +++ b/repeat.js @@ -1,16 +1,11 @@ -define(['./toInteger', './toString'], function(toInteger, toString) { - - /** Used as references for various `Number` constants. */ - var MAX_SAFE_INTEGER = 9007199254740991; - - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeFloor = Math.floor; +define(['./_baseRepeat', './toInteger', './toString'], function(baseRepeat, toInteger, toString) { /** * Repeats the given string `n` times. * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to repeat. * @param {number} [n=0] The number of times to repeat the string. @@ -27,24 +22,7 @@ define(['./toInteger', './toString'], function(toInteger, toString) { * // => '' */ function repeat(string, n) { - string = toString(string); - n = toInteger(n); - - var result = ''; - if (!string || n < 1 || n > MAX_SAFE_INTEGER) { - return result; - } - // Leverage the exponentiation by squaring algorithm for a faster repeat. - // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. - do { - if (n % 2) { - result += string; - } - n = nativeFloor(n / 2); - string += string; - } while (n); - - return result; + return baseRepeat(toString(string), toInteger(n)); } return repeat; diff --git a/replace.js b/replace.js index c93751fe7..0cb10da6a 100644 --- a/replace.js +++ b/replace.js @@ -3,10 +3,12 @@ define(['./toString'], function(toString) { /** * Replaces matches for `pattern` in `string` with `replacement`. * - * **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace). + * **Note:** This method is based on + * [`String#replace`](https://mdn.io/String/replace). * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to modify. * @param {RegExp|string} pattern The pattern to replace. diff --git a/rest.js b/rest.js index 24b851b03..b358555da 100644 --- a/rest.js +++ b/rest.js @@ -11,12 +11,15 @@ define(['./_apply', './toInteger'], function(apply, toInteger) { /** * Creates a function that invokes `func` with the `this` binding of the - * created function and arguments from `start` and beyond provided as an array. + * created function and arguments from `start` and beyond provided as + * an array. * - * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters). + * **Note:** This method is based on the + * [rest parameter](https://mdn.io/rest_parameters). * * @static * @memberOf _ + * @since 4.0.0 * @category Function * @param {Function} func The function to apply a rest parameter to. * @param {number} [start=func.length-1] The start position of the rest parameter. diff --git a/result.js b/result.js index 1d795e1cf..be5a4f285 100644 --- a/result.js +++ b/result.js @@ -1,19 +1,20 @@ -define(['./_baseCastPath', './get', './isFunction', './_isKey', './_parent'], function(baseCastPath, get, isFunction, isKey, parent) { +define(['./_baseCastPath', './isFunction', './_isKey'], function(baseCastPath, isFunction, isKey) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; /** - * This method is like `_.get` except that if the resolved value is a function - * it's invoked with the `this` binding of its parent object and its result - * is returned. + * This method is like `_.get` except that if the resolved value is a + * function it's invoked with the `this` binding of its parent object and + * its result is returned. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. * @param {Array|string} path The path of the property to resolve. - * @param {*} [defaultValue] The value returned if the resolved value is `undefined`. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. * @returns {*} Returns the resolved value. * @example * @@ -32,17 +33,25 @@ define(['./_baseCastPath', './get', './isFunction', './_isKey', './_parent'], fu * // => 'default' */ function result(object, path, defaultValue) { - if (!isKey(path, object)) { - path = baseCastPath(path); - var result = get(object, path); - object = parent(object, path); - } else { - result = object == null ? undefined : object[path]; + path = isKey(path, object) ? [path] : baseCastPath(path); + + var index = -1, + length = path.length; + + // Ensure the loop is entered when path is empty. + if (!length) { + object = undefined; + length = 1; } - if (result === undefined) { - result = defaultValue; + while (++index < length) { + var value = object == null ? undefined : object[path[index]]; + if (value === undefined) { + index = length; + value = defaultValue; + } + object = isFunction(value) ? value.call(object) : value; } - return isFunction(result) ? result.call(object) : result; + return object; } return result; diff --git a/reverse.js b/reverse.js index 6f4ba3ca5..dab455d4f 100644 --- a/reverse.js +++ b/reverse.js @@ -15,7 +15,9 @@ define([], function() { * * @static * @memberOf _ + * @since 4.0.0 * @category Array + * @param {Array} array The array to modify. * @returns {Array} Returns `array`. * @example * diff --git a/round.js b/round.js index ecd3e47e9..ea55bb7c4 100644 --- a/round.js +++ b/round.js @@ -5,6 +5,7 @@ define(['./_createRound'], function(createRound) { * * @static * @memberOf _ + * @since 3.10.0 * @category Math * @param {number} number The number to round. * @param {number} [precision=0] The precision to round to. diff --git a/sample.js b/sample.js index 91538735e..44c5b4fc1 100644 --- a/sample.js +++ b/sample.js @@ -8,6 +8,7 @@ define(['./_baseRandom', './isArrayLike', './values'], function(baseRandom, isAr * * @static * @memberOf _ + * @since 2.0.0 * @category Collection * @param {Array|Object} collection The collection to sample. * @returns {*} Returns the random element. diff --git a/sampleSize.js b/sampleSize.js index c7d36d5a2..5e884eb69 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -6,6 +6,7 @@ define(['./_baseClamp', './_baseRandom', './toArray', './toInteger'], function(b * * @static * @memberOf _ + * @since 4.0.0 * @category Collection * @param {Array|Object} collection The collection to sample. * @param {number} [n=0] The number of elements to sample. diff --git a/seq.js b/seq.js index 990a7e6fe..42c31191f 100644 --- a/seq.js +++ b/seq.js @@ -1,9 +1,8 @@ -define(['./wrapperAt', './chain', './commit', './wrapperFlatMap', './wrapperLodash', './next', './plant', './wrapperReverse', './tap', './thru', './toIterator', './toJSON', './wrapperValue', './valueOf', './wrapperChain'], function(at, chain, commit, flatMap, lodash, next, plant, reverse, tap, thru, toIterator, toJSON, value, valueOf, wrapperChain) { +define(['./wrapperAt', './chain', './commit', './wrapperLodash', './next', './plant', './wrapperReverse', './tap', './thru', './toIterator', './toJSON', './wrapperValue', './valueOf', './wrapperChain'], function(at, chain, commit, lodash, next, plant, reverse, tap, thru, toIterator, toJSON, value, valueOf, wrapperChain) { return { 'at': at, 'chain': chain, 'commit': commit, - 'flatMap': flatMap, 'lodash': lodash, 'next': next, 'plant': plant, diff --git a/set.js b/set.js index 1f3aae4b8..4d530c8ef 100644 --- a/set.js +++ b/set.js @@ -10,6 +10,7 @@ define(['./_baseSet'], function(baseSet) { * * @static * @memberOf _ + * @since 3.7.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. diff --git a/setWith.js b/setWith.js index 90426780a..91d045a03 100644 --- a/setWith.js +++ b/setWith.js @@ -13,6 +13,7 @@ define(['./_baseSet'], function(baseSet) { * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. diff --git a/shuffle.js b/shuffle.js index 80c26f532..852e98f72 100644 --- a/shuffle.js +++ b/shuffle.js @@ -9,6 +9,7 @@ define(['./sampleSize'], function(sampleSize) { * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to shuffle. * @returns {Array} Returns the new shuffled array. diff --git a/size.js b/size.js index a7cd25178..323255d6b 100644 --- a/size.js +++ b/size.js @@ -1,11 +1,16 @@ -define(['./isArrayLike', './isString', './keys', './_stringSize'], function(isArrayLike, isString, keys, stringSize) { +define(['./_getTag', './isArrayLike', './isObjectLike', './isString', './keys', './_stringSize'], function(getTag, isArrayLike, isObjectLike, isString, keys, stringSize) { + + /** `Object#toString` result references. */ + var mapTag = '[object Map]', + setTag = '[object Set]'; /** * Gets the size of `collection` by returning its length for array-like - * values or the number of own enumerable properties for objects. + * values or the number of own enumerable string keyed properties for objects. * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to inspect. * @returns {number} Returns the collection size. @@ -28,6 +33,12 @@ define(['./isArrayLike', './isString', './keys', './_stringSize'], function(isAr var result = collection.length; return (result && isString(collection)) ? stringSize(collection) : result; } + if (isObjectLike(collection)) { + var tag = getTag(collection); + if (tag == mapTag || tag == setTag) { + return collection.size; + } + } return keys(collection).length; } diff --git a/slice.js b/slice.js index 9dbb5b11a..61ae877fd 100644 --- a/slice.js +++ b/slice.js @@ -6,11 +6,13 @@ define(['./_baseSlice', './_isIterateeCall', './toInteger'], function(baseSlice, /** * Creates a slice of `array` from `start` up to, but not including, `end`. * - * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice) - * to ensure dense arrays are returned. + * **Note:** This method is used instead of + * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are + * returned. * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to slice. * @param {number} [start=0] The start position. diff --git a/snakeCase.js b/snakeCase.js index 2dab89cac..eae6eee22 100644 --- a/snakeCase.js +++ b/snakeCase.js @@ -1,10 +1,12 @@ define(['./_createCompounder'], function(createCompounder) { /** - * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case). + * Converts `string` to + * [snake case](https://en.wikipedia.org/wiki/Snake_case). * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the snake cased string. @@ -16,7 +18,7 @@ define(['./_createCompounder'], function(createCompounder) { * _.snakeCase('fooBar'); * // => 'foo_bar' * - * _.snakeCase('--foo-bar'); + * _.snakeCase('--FOO-BAR--'); * // => 'foo_bar' */ var snakeCase = createCompounder(function(result, word, index) { diff --git a/some.js b/some.js index 8cfbb2e90..9c515fb41 100644 --- a/some.js +++ b/some.js @@ -10,11 +10,14 @@ define(['./_arraySome', './_baseIteratee', './_baseSome', './isArray', './_isIte * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. - * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. * @example * * _.some([null, 0, 'yes', false], Boolean); diff --git a/sortBy.js b/sortBy.js index 6a98f05b0..c5ce90eb5 100644 --- a/sortBy.js +++ b/sortBy.js @@ -8,30 +8,32 @@ define(['./_baseFlatten', './_baseOrderBy', './_isIterateeCall', './rest'], func * * @static * @memberOf _ + * @since 0.1.0 * @category Collection * @param {Array|Object} collection The collection to iterate over. - * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]] - * The iteratees to sort by, specified individually or in arrays. + * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} + * [iteratees=[_.identity]] The iteratees to sort by, specified individually + * or in arrays. * @returns {Array} Returns the new sorted array. * @example * * var users = [ * { 'user': 'fred', 'age': 48 }, * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 42 }, + * { 'user': 'fred', 'age': 40 }, * { 'user': 'barney', 'age': 34 } * ]; * * _.sortBy(users, function(o) { return o.user; }); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] * * _.sortBy(users, ['user', 'age']); - * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]] + * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]] * * _.sortBy(users, 'user', function(o) { * return Math.floor(o.age / 10); * }); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] */ var sortBy = rest(function(collection, iteratees) { if (collection == null) { diff --git a/sortedIndex.js b/sortedIndex.js index a5e828ce8..22ee6bae9 100644 --- a/sortedIndex.js +++ b/sortedIndex.js @@ -1,15 +1,17 @@ define(['./_baseSortedIndex'], function(baseSortedIndex) { /** - * Uses a binary search to determine the lowest index at which `value` should - * be inserted into `array` in order to maintain its sort order. + * Uses a binary search to determine the lowest index at which `value` + * should be inserted into `array` in order to maintain its sort order. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * _.sortedIndex([30, 50], 40); diff --git a/sortedIndexBy.js b/sortedIndexBy.js index b647f9f23..8263e0471 100644 --- a/sortedIndexBy.js +++ b/sortedIndexBy.js @@ -7,11 +7,14 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 }; diff --git a/sortedIndexOf.js b/sortedIndexOf.js index e09f57dfb..661b7f102 100644 --- a/sortedIndexOf.js +++ b/sortedIndexOf.js @@ -6,6 +6,7 @@ define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. diff --git a/sortedLastIndex.js b/sortedLastIndex.js index 3abde99da..5e13844be 100644 --- a/sortedLastIndex.js +++ b/sortedLastIndex.js @@ -7,10 +7,12 @@ define(['./_baseSortedIndex'], function(baseSortedIndex) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * _.sortedLastIndex([4, 5], 4); diff --git a/sortedLastIndexBy.js b/sortedLastIndexBy.js index 56637e483..cfab74e87 100644 --- a/sortedLastIndexBy.js +++ b/sortedLastIndexBy.js @@ -7,11 +7,14 @@ define(['./_baseIteratee', './_baseSortedIndexBy'], function(baseIteratee, baseS * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. - * @returns {number} Returns the index at which `value` should be inserted into `array`. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. * @example * * // The `_.property` iteratee shorthand. diff --git a/sortedLastIndexOf.js b/sortedLastIndexOf.js index bd3c33fd2..8b87209cf 100644 --- a/sortedLastIndexOf.js +++ b/sortedLastIndexOf.js @@ -6,6 +6,7 @@ define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to search. * @param {*} value The value to search for. diff --git a/sortedUniq.js b/sortedUniq.js index 6ed493ff4..32baec8ae 100644 --- a/sortedUniq.js +++ b/sortedUniq.js @@ -6,6 +6,7 @@ define(['./_baseSortedUniq'], function(baseSortedUniq) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @returns {Array} Returns the new duplicate free array. diff --git a/sortedUniqBy.js b/sortedUniqBy.js index adcd7a2ba..0a0b80690 100644 --- a/sortedUniqBy.js +++ b/sortedUniqBy.js @@ -6,6 +6,7 @@ define(['./_baseIteratee', './_baseSortedUniqBy'], function(baseIteratee, baseSo * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {Function} [iteratee] The iteratee invoked per element. diff --git a/split.js b/split.js index 36e4d2d2f..d831fe06d 100644 --- a/split.js +++ b/split.js @@ -3,10 +3,12 @@ define(['./toString'], function(toString) { /** * Splits `string` by `separator`. * - * **Note:** This method is based on [`String#split`](https://mdn.io/String/split). + * **Note:** This method is based on + * [`String#split`](https://mdn.io/String/split). * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to split. * @param {RegExp|string} separator The separator pattern to split by. diff --git a/spread.js b/spread.js index c4538b19a..fe9a743a2 100644 --- a/spread.js +++ b/spread.js @@ -10,13 +10,16 @@ define(['./_apply', './_arrayPush', './rest', './toInteger'], function(apply, ar var nativeMax = Math.max; /** - * Creates a function that invokes `func` with the `this` binding of the created - * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3). + * Creates a function that invokes `func` with the `this` binding of the + * create function and an array of arguments much like + * [`Function#apply`](https://es5.github.io/#x15.3.4.3). * - * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator). + * **Note:** This method is based on the + * [spread operator](https://mdn.io/spread_operator). * * @static * @memberOf _ + * @since 3.2.0 * @category Function * @param {Function} func The function to spread arguments over. * @param {number} [start=0] The start position of the spread. diff --git a/startCase.js b/startCase.js index 69cf85edd..b65e73414 100644 --- a/startCase.js +++ b/startCase.js @@ -1,26 +1,28 @@ -define(['./capitalize', './_createCompounder'], function(capitalize, createCompounder) { +define(['./_createCompounder', './upperFirst'], function(createCompounder, upperFirst) { /** - * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). + * Converts `string` to + * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). * * @static * @memberOf _ + * @since 3.1.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the start cased string. * @example * - * _.startCase('--foo-bar'); + * _.startCase('--foo-bar--'); * // => 'Foo Bar' * * _.startCase('fooBar'); * // => 'Foo Bar' * - * _.startCase('__foo_bar__'); - * // => 'Foo Bar' + * _.startCase('__FOO_BAR__'); + * // => 'FOO BAR' */ var startCase = createCompounder(function(result, word, index) { - return result + (index ? ' ' : '') + capitalize(word); + return result + (index ? ' ' : '') + upperFirst(word); }); return startCase; diff --git a/startsWith.js b/startsWith.js index 61248c6f6..b40763b9e 100644 --- a/startsWith.js +++ b/startsWith.js @@ -5,11 +5,13 @@ define(['./_baseClamp', './toInteger', './toString'], function(baseClamp, toInte * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to search. * @param {string} [target] The string to search for. * @param {number} [position=0] The position to search from. - * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`. + * @returns {boolean} Returns `true` if `string` starts with `target`, + * else `false`. * @example * * _.startsWith('abc', 'a'); diff --git a/subtract.js b/subtract.js index d1edb2946..6039aec8f 100644 --- a/subtract.js +++ b/subtract.js @@ -1,13 +1,11 @@ -define([], function() { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_createMathOperation'], function(createMathOperation) { /** * Subtract two numbers. * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {number} minuend The first number in a subtraction. * @param {number} subtrahend The second number in a subtraction. @@ -17,19 +15,9 @@ define([], function() { * _.subtract(6, 4); * // => 2 */ - function subtract(minuend, subtrahend) { - var result; - if (minuend === undefined && subtrahend === undefined) { - return 0; - } - if (minuend !== undefined) { - result = minuend; - } - if (subtrahend !== undefined) { - result = result === undefined ? subtrahend : (result - subtrahend); - } - return result; - } + var subtract = createMathOperation(function(minuend, subtrahend) { + return minuend - subtrahend; + }); return subtract; }); diff --git a/sum.js b/sum.js index 1a46aaf23..c5067e348 100644 --- a/sum.js +++ b/sum.js @@ -5,6 +5,7 @@ define(['./_baseSum', './identity'], function(baseSum, identity) { * * @static * @memberOf _ + * @since 3.4.0 * @category Math * @param {Array} array The array to iterate over. * @returns {number} Returns the sum. diff --git a/sumBy.js b/sumBy.js index ee96275b8..c306ca5b7 100644 --- a/sumBy.js +++ b/sumBy.js @@ -7,9 +7,11 @@ define(['./_baseIteratee', './_baseSum'], function(baseIteratee, baseSum) { * * @static * @memberOf _ + * @since 4.0.0 * @category Math * @param {Array} array The array to iterate over. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {number} Returns the sum. * @example * diff --git a/tail.js b/tail.js index 2dbeee8d7..086b8bb05 100644 --- a/tail.js +++ b/tail.js @@ -5,6 +5,7 @@ define(['./drop'], function(drop) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to query. * @returns {Array} Returns the slice of `array`. diff --git a/take.js b/take.js index 9056d1921..0941bbada 100644 --- a/take.js +++ b/take.js @@ -8,10 +8,11 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/takeRight.js b/takeRight.js index 86a6955d5..9ad9bf6df 100644 --- a/takeRight.js +++ b/takeRight.js @@ -8,10 +8,11 @@ define(['./_baseSlice', './toInteger'], function(baseSlice, toInteger) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/takeRightWhile.js b/takeRightWhile.js index 0967637b4..4aa80bdad 100644 --- a/takeRightWhile.js +++ b/takeRightWhile.js @@ -2,14 +2,16 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { /** * Creates a slice of `array` with elements taken from the end. Elements are - * taken until `predicate` returns falsey. The predicate is invoked with three - * arguments: (value, index, array). + * taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/takeWhile.js b/takeWhile.js index 2173b2b68..6babf2ca8 100644 --- a/takeWhile.js +++ b/takeWhile.js @@ -7,9 +7,11 @@ define(['./_baseIteratee', './_baseWhile'], function(baseIteratee, baseWhile) { * * @static * @memberOf _ + * @since 3.0.0 * @category Array * @param {Array} array The array to query. - * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. + * @param {Array|Function|Object|string} [predicate=_.identity] + * The function invoked per iteration. * @returns {Array} Returns the slice of `array`. * @example * diff --git a/tap.js b/tap.js index 98e02e125..29d29699c 100644 --- a/tap.js +++ b/tap.js @@ -3,10 +3,11 @@ define([], function() { /** * This method invokes `interceptor` and returns `value`. The interceptor * is invoked with one argument; (value). The purpose of this method is to - * "tap into" a method chain in order to modify intermediate results. + * "tap into" a method chain sequence in order to modify intermediate results. * * @static * @memberOf _ + * @since 0.1.0 * @category Seq * @param {*} value The value to provide to `interceptor`. * @param {Function} interceptor The function to invoke. diff --git a/template.js b/template.js index f1b4909ff..def89bc82 100644 --- a/template.js +++ b/template.js @@ -35,17 +35,24 @@ define(['./_assignInDefaults', './assignInWith', './attempt', './_baseValues', ' * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). * * @static + * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The template string. - * @param {Object} [options] The options object. - * @param {RegExp} [options.escape] The HTML "escape" delimiter. - * @param {RegExp} [options.evaluate] The "evaluate" delimiter. - * @param {Object} [options.imports] An object to import into the template as free variables. - * @param {RegExp} [options.interpolate] The "interpolate" delimiter. - * @param {string} [options.sourceURL] The sourceURL of the template's compiled source. - * @param {string} [options.variable] The data object variable name. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param {Object} [options={}] The options object. + * @param {RegExp} [options.escape=_.templateSettings.escape] + * The HTML "escape" delimiter. + * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] + * The "evaluate" delimiter. + * @param {Object} [options.imports=_.templateSettings.imports] + * An object to import into the template as free variables. + * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] + * The "interpolate" delimiter. + * @param {string} [options.sourceURL='templateSources[n]'] + * The sourceURL of the compiled template. + * @param {string} [options.variable='obj'] + * The data object variable name. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the compiled template function. * @example * @@ -94,7 +101,7 @@ define(['./_assignInDefaults', './assignInWith', './attempt', './_baseValues', ' * // Use the `sourceURL` option to specify a custom sourceURL for the template. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); * compiled(data); - * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector + * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. * * // Use the `variable` option to ensure a with-statement isn't used in the compiled template. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); @@ -114,7 +121,8 @@ define(['./_assignInDefaults', './assignInWith', './attempt', './_baseValues', ' * '); */ function template(string, options, guard) { - // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/) + // Based on John Resig's `tmpl` implementation + // (http://ejohn.org/blog/javascript-micro-templating/) // and Laura Doktorova's doT.js (https://github.com/olado/doT). var settings = templateSettings.imports._.templateSettings || templateSettings; diff --git a/throttle.js b/throttle.js index e84e94a42..a63e41b9f 100644 --- a/throttle.js +++ b/throttle.js @@ -13,23 +13,24 @@ define(['./debounce', './isObject'], function(debounce, isObject) { * throttled function. Subsequent calls to the throttled function return the * result of the last `func` invocation. * - * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked - * on the trailing edge of the timeout only if the throttled function is - * invoked more than once during the `wait` timeout. + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the throttled function + * is invoked more than once during the `wait` timeout. * * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation) * for details over the differences between `_.throttle` and `_.debounce`. * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {Function} func The function to throttle. * @param {number} [wait=0] The number of milliseconds to throttle invocations to. - * @param {Object} [options] The options object. - * @param {boolean} [options.leading=true] Specify invoking on the leading - * edge of the timeout. - * @param {boolean} [options.trailing=true] Specify invoking on the trailing - * edge of the timeout. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=true] + * Specify invoking on the leading edge of the timeout. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. * @returns {Function} Returns the new throttled function. * @example * diff --git a/thru.js b/thru.js index d97b1a37b..506bfd907 100644 --- a/thru.js +++ b/thru.js @@ -3,10 +3,11 @@ define([], function() { /** * This method is like `_.tap` except that it returns the result of `interceptor`. * The purpose of this method is to "pass thru" values replacing intermediate - * results in a method chain. + * results in a method chain sequence. * * @static * @memberOf _ + * @since 3.0.0 * @category Seq * @param {*} value The value to provide to `interceptor`. * @param {Function} interceptor The function to invoke. diff --git a/times.js b/times.js index d5a0368c4..ff8cfe46a 100644 --- a/times.js +++ b/times.js @@ -1,4 +1,4 @@ -define(['./_baseCastFunction', './_baseTimes', './toInteger'], function(baseCastFunction, baseTimes, toInteger) { +define(['./_baseIteratee', './_baseTimes', './toInteger'], function(baseIteratee, baseTimes, toInteger) { /** Used as references for various `Number` constants. */ var MAX_SAFE_INTEGER = 9007199254740991; @@ -14,6 +14,7 @@ define(['./_baseCastFunction', './_baseTimes', './toInteger'], function(baseCast * each invocation. The iteratee is invoked with one argument; (index). * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {number} n The number of times to invoke `iteratee`. @@ -35,7 +36,7 @@ define(['./_baseCastFunction', './_baseTimes', './toInteger'], function(baseCast var index = MAX_ARRAY_LENGTH, length = nativeMin(n, MAX_ARRAY_LENGTH); - iteratee = baseCastFunction(iteratee); + iteratee = baseIteratee(iteratee); n -= MAX_ARRAY_LENGTH; var result = baseTimes(length, iteratee); diff --git a/toArray.js b/toArray.js index 9c97dc7d4..3fc5ea392 100644 --- a/toArray.js +++ b/toArray.js @@ -14,6 +14,7 @@ define(['./_Symbol', './_copyArray', './_getTag', './isArrayLike', './isString', * Converts `value` to an array. * * @static + * @since 0.1.0 * @memberOf _ * @category Lang * @param {*} value The value to convert. diff --git a/toInteger.js b/toInteger.js index b235878b1..c5e5cfc94 100644 --- a/toInteger.js +++ b/toInteger.js @@ -7,10 +7,12 @@ define(['./toNumber'], function(toNumber) { /** * Converts `value` to an integer. * - * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). + * **Note:** This function is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. diff --git a/toIterator.js b/toIterator.js index 1785c0db7..ed27c3b28 100644 --- a/toIterator.js +++ b/toIterator.js @@ -5,6 +5,7 @@ define([], function() { * * @name Symbol.iterator * @memberOf _ + * @since 4.0.0 * @category Seq * @returns {Object} Returns the wrapper object. * @example diff --git a/toLength.js b/toLength.js index 81748adfe..c91dadb1e 100644 --- a/toLength.js +++ b/toLength.js @@ -7,10 +7,12 @@ define(['./_baseClamp', './toInteger'], function(baseClamp, toInteger) { * Converts `value` to an integer suitable for use as the length of an * array-like object. * - * **Note:** This method is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * **Note:** This method is based on + * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. diff --git a/toLower.js b/toLower.js index 2bd2eb3a5..6d9edb5c1 100644 --- a/toLower.js +++ b/toLower.js @@ -6,13 +6,14 @@ define(['./toString'], function(toString) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the lower cased string. * @example * - * _.toLower('--Foo-Bar'); - * // => '--foo-bar' + * _.toLower('--Foo-Bar--'); + * // => '--foo-bar--' * * _.toLower('fooBar'); * // => 'foobar' diff --git a/toNumber.js b/toNumber.js index 52c6ae6a2..a0d47abe0 100644 --- a/toNumber.js +++ b/toNumber.js @@ -1,4 +1,4 @@ -define(['./isFunction', './isObject'], function(isFunction, isObject) { +define(['./isFunction', './isObject', './isSymbol'], function(isFunction, isObject, isSymbol) { /** Used as references for various `Number` constants. */ var NAN = 0 / 0; @@ -23,6 +23,7 @@ define(['./isFunction', './isObject'], function(isFunction, isObject) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to process. * @returns {number} Returns the number. @@ -41,12 +42,18 @@ define(['./isFunction', './isObject'], function(isFunction, isObject) { * // => 3 */ function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } if (isObject(value)) { var other = isFunction(value.valueOf) ? value.valueOf() : value; value = isObject(other) ? (other + '') : other; } if (typeof value != 'string') { - return value === 0 ? value : +value; + return value === 0 ? value : +value; } value = value.replace(reTrim, ''); var isBinary = reIsBinary.test(value); diff --git a/toPairs.js b/toPairs.js index 36abfb69d..56c76df5a 100644 --- a/toPairs.js +++ b/toPairs.js @@ -1,11 +1,13 @@ define(['./_baseToPairs', './keys'], function(baseToPairs, keys) { /** - * Creates an array of own enumerable key-value pairs for `object` which - * can be consumed by `_.fromPairs`. + * Creates an array of own enumerable string keyed-value pairs for `object` + * which can be consumed by `_.fromPairs`. * * @static * @memberOf _ + * @since 4.0.0 + * @alias entries * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the new array of key-value pairs. diff --git a/toPairsIn.js b/toPairsIn.js index 53ea1ec9b..c03ba8e02 100644 --- a/toPairsIn.js +++ b/toPairsIn.js @@ -1,11 +1,13 @@ define(['./_baseToPairs', './keysIn'], function(baseToPairs, keysIn) { /** - * Creates an array of own and inherited enumerable key-value pairs for - * `object` which can be consumed by `_.fromPairs`. + * Creates an array of own and inherited enumerable string keyed-value pairs + * for `object` which can be consumed by `_.fromPairs`. * * @static * @memberOf _ + * @since 4.0.0 + * @alias entriesIn * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the new array of key-value pairs. diff --git a/toPath.js b/toPath.js index a08cf4045..8551dee88 100644 --- a/toPath.js +++ b/toPath.js @@ -1,10 +1,11 @@ -define(['./_arrayMap', './isArray', './_stringToPath'], function(arrayMap, isArray, stringToPath) { +define(['./_arrayMap', './_baseCastKey', './_copyArray', './isArray', './isSymbol', './_stringToPath'], function(arrayMap, baseCastKey, copyArray, isArray, isSymbol, stringToPath) { /** * Converts `value` to a property path array. * * @static * @memberOf _ + * @since 4.0.0 * @category Util * @param {*} value The value to convert. * @returns {Array} Returns the new property path array. @@ -26,7 +27,10 @@ define(['./_arrayMap', './isArray', './_stringToPath'], function(arrayMap, isArr * // => false */ function toPath(value) { - return isArray(value) ? arrayMap(value, String) : stringToPath(value); + if (isArray(value)) { + return arrayMap(value, baseCastKey); + } + return isSymbol(value) ? [value] : copyArray(stringToPath(value)); } return toPath; diff --git a/toPlainObject.js b/toPlainObject.js index 1f0f5d4aa..424245977 100644 --- a/toPlainObject.js +++ b/toPlainObject.js @@ -1,11 +1,12 @@ define(['./_copyObject', './keysIn'], function(copyObject, keysIn) { /** - * Converts `value` to a plain object flattening inherited enumerable - * properties of `value` to own properties of the plain object. + * Converts `value` to a plain object flattening inherited enumerable string + * keyed properties of `value` to own properties of the plain object. * * @static * @memberOf _ + * @since 3.0.0 * @category Lang * @param {*} value The value to convert. * @returns {Object} Returns the converted plain object. diff --git a/toSafeInteger.js b/toSafeInteger.js index dfb7a478a..90bb92034 100644 --- a/toSafeInteger.js +++ b/toSafeInteger.js @@ -9,6 +9,7 @@ define(['./_baseClamp', './toInteger'], function(baseClamp, toInteger) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {number} Returns the converted integer. diff --git a/toString.js b/toString.js index b1fe3786d..686bed692 100644 --- a/toString.js +++ b/toString.js @@ -16,6 +16,7 @@ define(['./_Symbol', './isSymbol'], function(Symbol, isSymbol) { * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to process. * @returns {string} Returns the string. diff --git a/toUpper.js b/toUpper.js index c1b433f2b..b9907fd6e 100644 --- a/toUpper.js +++ b/toUpper.js @@ -6,13 +6,14 @@ define(['./toString'], function(toString) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the upper cased string. * @example * - * _.toUpper('--foo-bar'); - * // => '--FOO-BAR' + * _.toUpper('--foo-bar--'); + * // => '--FOO-BAR--' * * _.toUpper('fooBar'); * // => 'FOOBAR' diff --git a/transform.js b/transform.js index a7ff744dc..9962c9262 100644 --- a/transform.js +++ b/transform.js @@ -1,18 +1,16 @@ -define(['./_arrayEach', './_baseCreate', './_baseForOwn', './_baseIteratee', './isArray', './isFunction', './isObject', './isTypedArray'], function(arrayEach, baseCreate, baseForOwn, baseIteratee, isArray, isFunction, isObject, isTypedArray) { - - /** Built-in value references. */ - var getPrototypeOf = Object.getPrototypeOf; +define(['./_arrayEach', './_baseCreate', './_baseForOwn', './_baseIteratee', './_getPrototype', './isArray', './isFunction', './isObject', './isTypedArray'], function(arrayEach, baseCreate, baseForOwn, baseIteratee, getPrototype, isArray, isFunction, isObject, isTypedArray) { /** * An alternative to `_.reduce`; this method transforms `object` to a new * `accumulator` object which is the result of running each of its own enumerable - * properties through `iteratee`, with each invocation potentially mutating - * the `accumulator` object. The iteratee is invoked with four arguments: + * string keyed properties through `iteratee`, with each invocation potentially + * mutating the `accumulator` object. The iteratee is invoked with four arguments: * (accumulator, value, key, object). Iteratee functions may exit iteration * early by explicitly returning `false`. * * @static * @memberOf _ + * @since 1.3.0 * @category Object * @param {Array|Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. @@ -41,7 +39,7 @@ define(['./_arrayEach', './_baseCreate', './_baseForOwn', './_baseIteratee', './ if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {}; + accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; } } else { accumulator = {}; diff --git a/trim.js b/trim.js index f13351f6b..c6a61bd59 100644 --- a/trim.js +++ b/trim.js @@ -11,10 +11,11 @@ define(['./_charsEndIndex', './_charsStartIndex', './_stringToArray', './toStrin * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to trim. * @param {string} [chars=whitespace] The characters to trim. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the trimmed string. * @example * diff --git a/trimEnd.js b/trimEnd.js index e04c083bd..f6d3ab96e 100644 --- a/trimEnd.js +++ b/trimEnd.js @@ -11,10 +11,11 @@ define(['./_charsEndIndex', './_stringToArray', './toString'], function(charsEnd * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to trim. * @param {string} [chars=whitespace] The characters to trim. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the trimmed string. * @example * diff --git a/trimStart.js b/trimStart.js index c8328e92d..4ef48c8ec 100644 --- a/trimStart.js +++ b/trimStart.js @@ -11,10 +11,11 @@ define(['./_charsStartIndex', './_stringToArray', './toString'], function(charsS * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to trim. * @param {string} [chars=whitespace] The characters to trim. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {string} Returns the trimmed string. * @example * diff --git a/truncate.js b/truncate.js index 0f83fee0b..af32287cd 100644 --- a/truncate.js +++ b/truncate.js @@ -29,9 +29,10 @@ define(['./isObject', './isRegExp', './_stringSize', './_stringToArray', './toIn * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to truncate. - * @param {Object} [options=({})] The options object. + * @param {Object} [options={}] The options object. * @param {number} [options.length=30] The maximum string length. * @param {string} [options.omission='...'] The string to indicate text is omitted. * @param {RegExp|string} [options.separator] The separator pattern to truncate to. diff --git a/unary.js b/unary.js index 2c62cf27c..b4ded3cb6 100644 --- a/unary.js +++ b/unary.js @@ -6,6 +6,7 @@ define(['./ary'], function(ary) { * * @static * @memberOf _ + * @since 4.0.0 * @category Function * @param {Function} func The function to cap arguments for. * @returns {Function} Returns the new function. diff --git a/unescape.js b/unescape.js index caed0ff26..e3b9ce9e5 100644 --- a/unescape.js +++ b/unescape.js @@ -6,14 +6,15 @@ define(['./toString', './_unescapeHtmlChar'], function(toString, unescapeHtmlCha /** * The inverse of `_.escape`; this method converts the HTML entities - * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their - * corresponding characters. + * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to + * their corresponding characters. * - * **Note:** No other HTML entities are unescaped. To unescape additional HTML - * entities use a third-party library like [_he_](https://mths.be/he). + * **Note:** No other HTML entities are unescaped. To unescape additional + * HTML entities use a third-party library like [_he_](https://mths.be/he). * * @static * @memberOf _ + * @since 0.6.0 * @category String * @param {string} [string=''] The string to unescape. * @returns {string} Returns the unescaped string. diff --git a/union.js b/union.js index 97758544b..db26f604b 100644 --- a/union.js +++ b/union.js @@ -7,6 +7,7 @@ define(['./_baseFlatten', './_baseUniq', './rest'], function(baseFlatten, baseUn * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of combined values. diff --git a/unionBy.js b/unionBy.js index 3fc0d36fa..71eeafd29 100644 --- a/unionBy.js +++ b/unionBy.js @@ -5,14 +5,17 @@ define(['./_baseFlatten', './_baseIteratee', './_baseUniq', './isArrayLikeObject /** * This method is like `_.union` except that it accepts `iteratee` which is - * invoked for each element of each `arrays` to generate the criterion by which - * uniqueness is computed. The iteratee is invoked with one argument: (value). + * invoked for each element of each `arrays` to generate the criterion by + * which uniqueness is computed. The iteratee is invoked with one argument: + * (value). * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [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 3eb0f1855..76cf0e445 100644 --- a/unionWith.js +++ b/unionWith.js @@ -10,6 +10,7 @@ define(['./_baseFlatten', './_baseUniq', './isArrayLikeObject', './last', './res * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. diff --git a/uniq.js b/uniq.js index aeca96e3d..ec97cafcc 100644 --- a/uniq.js +++ b/uniq.js @@ -3,11 +3,12 @@ define(['./_baseUniq'], function(baseUniq) { /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) - * for equality comparisons, in which only the first occurrence of each element - * is kept. + * for equality comparisons, in which only the first occurrence of each + * element is kept. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to inspect. * @returns {Array} Returns the new duplicate free array. diff --git a/uniqBy.js b/uniqBy.js index 8460af2bc..641717ee7 100644 --- a/uniqBy.js +++ b/uniqBy.js @@ -7,9 +7,11 @@ define(['./_baseIteratee', './_baseUniq'], function(baseIteratee, baseUniq) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. * @example * diff --git a/uniqWith.js b/uniqWith.js index d88cc8a19..a00e487df 100644 --- a/uniqWith.js +++ b/uniqWith.js @@ -10,6 +10,7 @@ define(['./_baseUniq'], function(baseUniq) { * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {Array} array The array to inspect. * @param {Function} [comparator] The comparator invoked per element. diff --git a/uniqueId.js b/uniqueId.js index 77b715a78..e26abf6b9 100644 --- a/uniqueId.js +++ b/uniqueId.js @@ -7,6 +7,7 @@ define(['./toString'], function(toString) { * Generates a unique ID. If `prefix` is given the ID is appended to it. * * @static + * @since 0.1.0 * @memberOf _ * @category Util * @param {string} [prefix=''] The value to prefix the ID with. diff --git a/unset.js b/unset.js index e3b5e8461..da26cbd63 100644 --- a/unset.js +++ b/unset.js @@ -7,6 +7,7 @@ define(['./_baseUnset'], function(baseUnset) { * * @static * @memberOf _ + * @since 4.0.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to unset. diff --git a/unzip.js b/unzip.js index 431e34210..6ba80e270 100644 --- a/unzip.js +++ b/unzip.js @@ -10,6 +10,7 @@ define(['./_arrayFilter', './_arrayMap', './_baseProperty', './_baseTimes', './i * * @static * @memberOf _ + * @since 1.2.0 * @category Array * @param {Array} array The array of grouped elements to process. * @returns {Array} Returns the new array of regrouped elements. diff --git a/unzipWith.js b/unzipWith.js index a52411a11..afa47fbf8 100644 --- a/unzipWith.js +++ b/unzipWith.js @@ -10,9 +10,11 @@ define(['./_apply', './_arrayMap', './unzip'], function(apply, arrayMap, unzip) * * @static * @memberOf _ + * @since 3.8.0 * @category Array * @param {Array} array The array of grouped elements to process. - * @param {Function} [iteratee=_.identity] The function to combine regrouped values. + * @param {Function} [iteratee=_.identity] The function to combine + * regrouped values. * @returns {Array} Returns the new array of regrouped elements. * @example * diff --git a/update.js b/update.js index 140be343c..33022aa23 100644 --- a/update.js +++ b/update.js @@ -9,6 +9,7 @@ define(['./_baseCastFunction', './_baseUpdate'], function(baseCastFunction, base * * @static * @memberOf _ + * @since 4.6.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. diff --git a/updateWith.js b/updateWith.js index 9a96a6c7b..5523c9dc9 100644 --- a/updateWith.js +++ b/updateWith.js @@ -13,6 +13,7 @@ define(['./_baseCastFunction', './_baseUpdate'], function(baseCastFunction, base * * @static * @memberOf _ + * @since 4.6.0 * @category Object * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. diff --git a/upperCase.js b/upperCase.js index cba4b0ec6..3e01a23b0 100644 --- a/upperCase.js +++ b/upperCase.js @@ -5,6 +5,7 @@ define(['./_createCompounder'], function(createCompounder) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the upper cased string. diff --git a/upperFirst.js b/upperFirst.js index 5ef818936..f984e8e10 100644 --- a/upperFirst.js +++ b/upperFirst.js @@ -5,6 +5,7 @@ define(['./_createCaseFirst'], function(createCaseFirst) { * * @static * @memberOf _ + * @since 4.0.0 * @category String * @param {string} [string=''] The string to convert. * @returns {string} Returns the converted string. diff --git a/values.js b/values.js index 80f79bebc..ab82f26c6 100644 --- a/values.js +++ b/values.js @@ -1,11 +1,12 @@ define(['./_baseValues', './keys'], function(baseValues, keys) { /** - * Creates an array of the own enumerable property values of `object`. + * Creates an array of the own enumerable string keyed property values of `object`. * * **Note:** Non-object values are coerced to objects. * * @static + * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The object to query. diff --git a/valuesIn.js b/valuesIn.js index c6861850f..bdefc68a1 100644 --- a/valuesIn.js +++ b/valuesIn.js @@ -1,12 +1,14 @@ define(['./_baseValues', './keysIn'], function(baseValues, keysIn) { /** - * Creates an array of the own and inherited enumerable property values of `object`. + * Creates an array of the own and inherited enumerable string keyed property + * values of `object`. * * **Note:** Non-object values are coerced to objects. * * @static * @memberOf _ + * @since 3.0.0 * @category Object * @param {Object} object The object to query. * @returns {Array} Returns the array of property values. diff --git a/without.js b/without.js index ca0416dbc..106521c41 100644 --- a/without.js +++ b/without.js @@ -7,6 +7,7 @@ define(['./_baseDifference', './isArrayLikeObject', './rest'], function(baseDiff * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {Array} array The array to filter. * @param {...*} [values] The values to exclude. diff --git a/words.js b/words.js index dfc0e839f..17879af24 100644 --- a/words.js +++ b/words.js @@ -55,17 +55,18 @@ define(['./toString'], function(toString) { ].join('|'), 'g'); /** Used to detect strings that need a more robust regexp to match words. */ - var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; /** * Splits `string` into an array of its words. * * @static * @memberOf _ + * @since 3.0.0 * @category String * @param {string} [string=''] The string to inspect. * @param {RegExp|string} [pattern] The pattern to match words. - * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Array} Returns the words of `string`. * @example * diff --git a/wrap.js b/wrap.js index 3b9b0fe49..3bededca1 100644 --- a/wrap.js +++ b/wrap.js @@ -8,6 +8,7 @@ define(['./identity', './partial'], function(identity, partial) { * * @static * @memberOf _ + * @since 0.1.0 * @category Function * @param {*} value The value to wrap. * @param {Function} [wrapper=identity] The wrapper function. diff --git a/wrapperAt.js b/wrapperAt.js index a663c4c43..067b8f5ec 100644 --- a/wrapperAt.js +++ b/wrapperAt.js @@ -8,6 +8,7 @@ define(['./_LazyWrapper', './_LodashWrapper', './_baseAt', './_baseFlatten', './ * * @name at * @memberOf _ + * @since 1.0.0 * @category Seq * @param {...(string|string[])} [paths] The property paths of elements to pick, * specified individually or in arrays. diff --git a/wrapperChain.js b/wrapperChain.js index 7a10e6eee..bfe00cf13 100644 --- a/wrapperChain.js +++ b/wrapperChain.js @@ -1,10 +1,11 @@ define(['./chain'], function(chain) { /** - * Enables explicit method chaining on the wrapper object. + * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. * * @name chain * @memberOf _ + * @since 0.1.0 * @category Seq * @returns {Object} Returns the new `lodash` wrapper instance. * @example diff --git a/wrapperFlatMap.js b/wrapperFlatMap.js deleted file mode 100644 index 9fd432134..000000000 --- a/wrapperFlatMap.js +++ /dev/null @@ -1,25 +0,0 @@ -define([], function() { - - /** - * This method is the wrapper version of `_.flatMap`. - * - * @name flatMap - * @memberOf _ - * @category Seq - * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. - * @returns {Object} Returns the new `lodash` wrapper instance. - * @example - * - * function duplicate(n) { - * return [n, n]; - * } - * - * _([1, 2]).flatMap(duplicate).value(); - * // => [1, 1, 2, 2] - */ - function wrapperFlatMap(iteratee) { - return this.map(iteratee).flatten(); - } - - return wrapperFlatMap; -}); diff --git a/wrapperLodash.js b/wrapperLodash.js index d1ad3006e..e4dda7814 100644 --- a/wrapperLodash.js +++ b/wrapperLodash.js @@ -8,25 +8,25 @@ define(['./_LazyWrapper', './_LodashWrapper', './_baseLodash', './isArray', './i /** * Creates a `lodash` object which wraps `value` to enable implicit method - * chaining. Methods that operate on and return arrays, collections, and - * functions can be chained together. Methods that retrieve a single value or - * may return a primitive value will automatically end the chain sequence and - * return the unwrapped value. Otherwise, the value must be unwrapped with - * `_#value`. + * chain sequences. Methods that operate on and return arrays, collections, + * and functions can be chained together. Methods that retrieve a single value + * or may return a primitive value will automatically end the chain sequence + * and return the unwrapped value. Otherwise, the value must be unwrapped + * with `_#value`. * - * Explicit chaining, which must be unwrapped with `_#value` in all cases, - * may be enabled using `_.chain`. + * Explicit chain sequences, which must be unwrapped with `_#value`, may be + * enabled using `_.chain`. * * The execution of chained methods is lazy, that is, it's deferred until * `_#value` is implicitly or explicitly called. * - * Lazy evaluation allows several methods to support shortcut fusion. Shortcut - * fusion is an optimization to merge iteratee calls; this avoids the creation - * of intermediate arrays and can greatly reduce the number of iteratee executions. - * Sections of a chain sequence qualify for shortcut fusion if the section is - * applied to an array of at least two hundred elements and any iteratees - * accept only one argument. The heuristic for whether a section qualifies - * for shortcut fusion is subject to change. + * Lazy evaluation allows several methods to support shortcut fusion. + * Shortcut fusion is an optimization to merge iteratee calls; this avoids + * the creation of intermediate arrays and can greatly reduce the number of + * iteratee executions. Sections of a chain sequence qualify for shortcut + * fusion if the section is applied to an array of at least two hundred + * elements and any iteratees accept only one argument. The heuristic for + * whether a section qualifies for shortcut fusion is subject to change. * * Chaining is supported in custom builds as long as the `_#value` method is * directly or indirectly included in the build. @@ -51,48 +51,49 @@ define(['./_LazyWrapper', './_LodashWrapper', './_baseLodash', './isArray', './i * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, - * `flatten`, `flattenDeep`, `flattenDepth`, `flip`, `flow`, `flowRight`, - * `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`, `intersection`, - * `intersectionBy`, `intersectionWith`, `invert`, `invertBy`, `invokeMap`, - * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, - * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`, - * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, - * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`, - * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`, - * `pullAll`, `pullAllBy`, `pullAllWith`, `pullAt`, `push`, `range`, - * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`, - * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, - * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, - * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, - * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, - * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `update`, `values`, - * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, - * `zipObjectDeep`, and `zipWith` + * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, + * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, + * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, + * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, + * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, + * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, + * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, + * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, + * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, + * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, + * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, + * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, + * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, + * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, + * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, + * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, + * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, + * `zipObject`, `zipObjectDeep`, and `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, - * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `each`, `eachRight`, - * `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, - * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`, `floor`, - * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, - * `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`, `includes`, - * `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`, `isArrayBuffer`, - * `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isBuffer`, `isDate`, - * `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`, `isFinite`, - * `isFunction`, `isInteger`, `isLength`, `isMap`, `isMatch`, `isMatchWith`, - * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`, - * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isSet`, `isString`, - * `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, - * `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, - * `maxBy`, `mean`, `min`, `minBy`, `noConflict`, `noop`, `now`, `pad`, - * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, - * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, - * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, - * `sortedLastIndexBy`, `startCase`, `startsWith`, `subtract`, `sum`, `sumBy`, - * `template`, `times`, `toInteger`, `toJSON`, `toLength`, `toLower`, - * `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, `trimEnd`, - * `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`, - * `value`, and `words` + * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`, + * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`, + * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`, + * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, + * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`, + * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`, + * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isBuffer`, + * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`, + * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`, `isMatch`, + * `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, + * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`, + * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`, + * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, + * `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`, + * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`, + * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`, + * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, + * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, + * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toInteger`, + * `toJSON`, `toLength`, `toLower`, `toNumber`, `toSafeInteger`, `toString`, + * `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, + * `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words` * * @name _ * @constructor diff --git a/wrapperReverse.js b/wrapperReverse.js index cc9a8c8c0..55e0f27f1 100644 --- a/wrapperReverse.js +++ b/wrapperReverse.js @@ -10,6 +10,7 @@ define(['./_LazyWrapper', './_LodashWrapper', './reverse', './thru'], function(L * * @name reverse * @memberOf _ + * @since 0.1.0 * @category Seq * @returns {Object} Returns the new `lodash` wrapper instance. * @example diff --git a/wrapperValue.js b/wrapperValue.js index 3c6d805c0..e8719c86c 100644 --- a/wrapperValue.js +++ b/wrapperValue.js @@ -1,10 +1,11 @@ define(['./_baseWrapperValue'], function(baseWrapperValue) { /** - * Executes the chained sequence to extract the unwrapped value. + * Executes the chain sequence to resolve the unwrapped value. * * @name value * @memberOf _ + * @since 0.1.0 * @alias toJSON, valueOf * @category Seq * @returns {*} Returns the resolved unwrapped value. diff --git a/xor.js b/xor.js index 9ac743980..3af66887c 100644 --- a/xor.js +++ b/xor.js @@ -1,12 +1,14 @@ define(['./_arrayFilter', './_baseXor', './isArrayLikeObject', './rest'], function(arrayFilter, baseXor, isArrayLikeObject, rest) { /** - * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) + * Creates an array of unique values that is the + * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) * of the given arrays. The order of result values is determined by the order * they occur in the arrays. * * @static * @memberOf _ + * @since 2.4.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of values. diff --git a/xorBy.js b/xorBy.js index e4092a3e8..2029ed290 100644 --- a/xorBy.js +++ b/xorBy.js @@ -5,14 +5,17 @@ define(['./_arrayFilter', './_baseIteratee', './_baseXor', './isArrayLikeObject' /** * This method is like `_.xor` except that it accepts `iteratee` which is - * invoked for each element of each `arrays` to generate the criterion by which - * by which they're compared. The iteratee is invoked with one argument: (value). + * invoked for each element of each `arrays` to generate the criterion by + * which by which they're compared. The iteratee is invoked with one argument: + * (value). * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @param {Array|Function|Object|string} [iteratee=_.identity] + * The iteratee invoked per element. * @returns {Array} Returns the new array of values. * @example * diff --git a/xorWith.js b/xorWith.js index 25faf26e7..29eae9951 100644 --- a/xorWith.js +++ b/xorWith.js @@ -10,6 +10,7 @@ define(['./_arrayFilter', './_baseXor', './isArrayLikeObject', './last', './rest * * @static * @memberOf _ + * @since 4.0.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. diff --git a/zip.js b/zip.js index 212a628bf..8b47d8446 100644 --- a/zip.js +++ b/zip.js @@ -1,12 +1,13 @@ define(['./rest', './unzip'], function(rest, unzip) { /** - * Creates an array of grouped elements, the first of which contains the first - * elements of the given arrays, the second of which contains the second elements - * of the given arrays, and so on. + * Creates an array of grouped elements, the first of which contains the + * first elements of the given arrays, the second of which contains the + * second elements of the given arrays, and so on. * * @static * @memberOf _ + * @since 0.1.0 * @category Array * @param {...Array} [arrays] The arrays to process. * @returns {Array} Returns the new array of grouped elements. diff --git a/zipObject.js b/zipObject.js index b903d7743..e458f908e 100644 --- a/zipObject.js +++ b/zipObject.js @@ -2,12 +2,13 @@ define(['./_assignValue', './_baseZipObject'], function(assignValue, baseZipObje /** * This method is like `_.fromPairs` except that it accepts two arrays, - * one of property names and one of corresponding values. + * one of property identifiers and one of corresponding values. * * @static * @memberOf _ + * @since 0.4.0 * @category Array - * @param {Array} [props=[]] The property names. + * @param {Array} [props=[]] The property identifiers. * @param {Array} [values=[]] The property values. * @returns {Object} Returns the new object. * @example diff --git a/zipObjectDeep.js b/zipObjectDeep.js index 5a2a0cd4e..f7c27e5e9 100644 --- a/zipObjectDeep.js +++ b/zipObjectDeep.js @@ -5,8 +5,9 @@ define(['./_baseSet', './_baseZipObject'], function(baseSet, baseZipObject) { * * @static * @memberOf _ + * @since 4.1.0 * @category Array - * @param {Array} [props=[]] The property names. + * @param {Array} [props=[]] The property identifiers. * @param {Array} [values=[]] The property values. * @returns {Object} Returns the new object. * @example diff --git a/zipWith.js b/zipWith.js index ee3ab533f..4d5b4f0b4 100644 --- a/zipWith.js +++ b/zipWith.js @@ -10,6 +10,7 @@ define(['./rest', './unzipWith'], function(rest, unzipWith) { * * @static * @memberOf _ + * @since 3.8.0 * @category Array * @param {...Array} [arrays] The arrays to process. * @param {Function} [iteratee=_.identity] The function to combine grouped values.