From 07c844053e9dda6377e936e1bda9d50ef37e930c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 7 May 2016 11:55:10 -0700 Subject: [PATCH] Bump to v4.12.0. --- README.md | 4 +-- _Hash.js | 30 +++++++++++++----- _ListCache.js | 32 ++++++++++++++++++++ _MapCache.js | 28 ++++++++--------- _SetCache.js | 10 +++--- _Stack.js | 14 +++------ _arrayConcat.js | 25 --------------- _assocGet.js | 16 ---------- _assocSet.js | 20 ------------ _baseAt.js | 2 +- _baseConforms.js | 2 +- _baseFunctions.js | 2 +- _baseGetAllKeys.js | 4 +-- _baseMatches.js | 2 +- _baseMatchesProperty.js | 2 +- _baseProperty.js | 2 +- _basePropertyDeep.js | 2 +- _baseRange.js | 2 +- _baseToPairs.js | 2 +- _baseUnary.js | 2 +- _cacheHas.js | 24 ++++----------- _cachePush.js | 27 ----------------- _composeArgs.js | 2 +- _composeArgsRight.js | 2 +- _createAssigner.js | 2 +- _createCaseFirst.js | 2 +- _createCurryWrapper.js | 4 +-- _createHybridWrapper.js | 8 ++--- _createOver.js | 2 +- _createToPairs.js | 30 ++++++++++++++++++ _createWrapper.js | 1 + _equalArrays.js | 20 +++++++----- _getPlaceholder.js => _getHolder.js | 4 +-- _getMapData.js | 18 +++++++++++ _hashClear.js | 14 +++++++++ _hashDelete.js | 8 ++--- _hashGet.js | 10 +++--- _hashHas.js | 8 +++-- _hashSet.js | 10 ++++-- _isFlattenable.js | 3 +- _listCacheClear.js | 12 ++++++++ _assocDelete.js => _listCacheDelete.js | 19 +++++++----- _listCacheGet.js | 19 ++++++++++++ _assocHas.js => _listCacheHas.js | 11 ++++--- _listCacheSet.js | 25 +++++++++++++++ _mapClear.js => _mapCacheClear.js | 7 +++-- _mapCacheDelete.js | 16 ++++++++++ _mapCacheGet.js | 16 ++++++++++ _mapCacheHas.js | 16 ++++++++++ _mapCacheSet.js | 18 +++++++++++ _mapDelete.js | 23 -------------- _mapGet.js | 23 -------------- _mapHas.js | 23 -------------- _mapSet.js | 28 ----------------- _mapToArray.js | 4 +-- _matchesStrictComparable.js | 2 +- _setCacheAdd.js | 19 ++++++++++++ _setCacheHas.js | 14 +++++++++ _setToArray.js | 4 +-- _setToPairs.js | 18 +++++++++++ _stackClear.js | 4 ++- _stackDelete.js | 7 +---- _stackGet.js | 7 +---- _stackHas.js | 7 +---- _stackSet.js | 20 +++--------- array.default.js | 23 +++++++------- array.js | 1 + ary.js | 2 +- at.js | 2 +- bind.js | 4 +-- bindKey.js | 4 +-- chunk.js | 2 +- concat.js | 20 ++++++------ cond.js | 2 +- conforms.js | 2 +- constant.js | 2 +- first.js | 1 + flip.js | 2 +- flow.js | 2 +- flowRight.js | 2 +- forEach.js | 5 ++- forEachRight.js | 5 ++- forIn.js | 2 +- forInRight.js | 2 +- forOwn.js | 2 +- forOwnRight.js | 2 +- functions.js | 2 +- functionsIn.js | 2 +- isFinite.js | 8 ++--- lang.default.js | 5 +-- lang.js | 1 + lodash.default.js | 5 +-- lodash.js | 4 ++- matches.js | 2 +- matchesProperty.js | 2 +- memoize.js | 2 +- merge.js | 2 +- method.js | 2 +- methodOf.js | 2 +- negate.js | 2 +- nth.js | 4 +-- nthArg.js | 4 +-- package.json | 3 +- partial.js | 4 +-- partialRight.js | 4 +-- property.js | 2 +- propertyOf.js | 2 +- range.js | 2 +- rangeRight.js | 2 +- split.js | 2 +- template.js | 14 ++++----- toFinite.js | 42 ++++++++++++++++++++++++++ toInteger.js | 24 +++++---------- toLength.js | 4 +-- toNumber.js | 8 ++--- toPairs.js | 11 +++---- toPairsIn.js | 13 ++++---- toSafeInteger.js | 4 +-- unary.js | 2 +- without.js | 2 +- wrapperLodash.js | 14 ++++----- xor.js | 2 +- xorBy.js | 2 +- xorWith.js | 2 +- 124 files changed, 587 insertions(+), 480 deletions(-) create mode 100644 _ListCache.js delete mode 100644 _arrayConcat.js delete mode 100644 _assocGet.js delete mode 100644 _assocSet.js delete mode 100644 _cachePush.js create mode 100644 _createToPairs.js rename _getPlaceholder.js => _getHolder.js (78%) create mode 100644 _getMapData.js create mode 100644 _hashClear.js create mode 100644 _listCacheClear.js rename _assocDelete.js => _listCacheDelete.js (59%) create mode 100644 _listCacheGet.js rename _assocHas.js => _listCacheHas.js (50%) create mode 100644 _listCacheSet.js rename _mapClear.js => _mapCacheClear.js (64%) create mode 100644 _mapCacheDelete.js create mode 100644 _mapCacheGet.js create mode 100644 _mapCacheHas.js create mode 100644 _mapCacheSet.js delete mode 100644 _mapDelete.js delete mode 100644 _mapGet.js delete mode 100644 _mapHas.js delete mode 100644 _mapSet.js create mode 100644 _setCacheAdd.js create mode 100644 _setCacheHas.js create mode 100644 _setToPairs.js create mode 100644 first.js create mode 100644 toFinite.js diff --git a/README.md b/README.md index d969687c1..f5f1e8819 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.11.2 +# lodash-es v4.12.0 The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. @@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): $ lodash modularize exports=es -o ./ ``` -See the [package source](https://github.com/lodash/lodash/tree/4.11.2-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.12.0-es) for more details. diff --git a/_Hash.js b/_Hash.js index 4796078cc..8c1371d8d 100644 --- a/_Hash.js +++ b/_Hash.js @@ -1,18 +1,32 @@ -import nativeCreate from './_nativeCreate'; - -/** Used for built-in method references. */ -var objectProto = Object.prototype; +import hashClear from './_hashClear'; +import hashDelete from './_hashDelete'; +import hashGet from './_hashGet'; +import hashHas from './_hashHas'; +import hashSet from './_hashSet'; /** * Creates a hash object. * * @private * @constructor - * @returns {Object} Returns the new hash object. + * @param {Array} [entries] The key-value pairs to cache. */ -function Hash() {} +function Hash(entries) { + var index = -1, + length = entries ? entries.length : 0; -// Avoid inheriting from `Object.prototype` when possible. -Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto; + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } +} + +// Add methods to `Hash`. +Hash.prototype.clear = hashClear; +Hash.prototype['delete'] = hashDelete; +Hash.prototype.get = hashGet; +Hash.prototype.has = hashHas; +Hash.prototype.set = hashSet; export default Hash; diff --git a/_ListCache.js b/_ListCache.js new file mode 100644 index 000000000..ee966baa3 --- /dev/null +++ b/_ListCache.js @@ -0,0 +1,32 @@ +import listCacheClear from './_listCacheClear'; +import listCacheDelete from './_listCacheDelete'; +import listCacheGet from './_listCacheGet'; +import listCacheHas from './_listCacheHas'; +import listCacheSet from './_listCacheSet'; + +/** + * Creates an list cache object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ +function ListCache(entries) { + var index = -1, + length = entries ? entries.length : 0; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } +} + +// Add methods to `ListCache`. +ListCache.prototype.clear = listCacheClear; +ListCache.prototype['delete'] = listCacheDelete; +ListCache.prototype.get = listCacheGet; +ListCache.prototype.has = listCacheHas; +ListCache.prototype.set = listCacheSet; + +export default ListCache; diff --git a/_MapCache.js b/_MapCache.js index f549d0716..ba137e972 100644 --- a/_MapCache.js +++ b/_MapCache.js @@ -1,32 +1,32 @@ -import mapClear from './_mapClear'; -import mapDelete from './_mapDelete'; -import mapGet from './_mapGet'; -import mapHas from './_mapHas'; -import mapSet from './_mapSet'; +import mapCacheClear from './_mapCacheClear'; +import mapCacheDelete from './_mapCacheDelete'; +import mapCacheGet from './_mapCacheGet'; +import mapCacheHas from './_mapCacheHas'; +import mapCacheSet from './_mapCacheSet'; /** * Creates a map cache object to store key-value pairs. * * @private * @constructor - * @param {Array} [values] The values to cache. + * @param {Array} [entries] The key-value pairs to cache. */ -function MapCache(values) { +function MapCache(entries) { var index = -1, - length = values ? values.length : 0; + length = entries ? entries.length : 0; this.clear(); while (++index < length) { - var entry = values[index]; + var entry = entries[index]; this.set(entry[0], entry[1]); } } // Add methods to `MapCache`. -MapCache.prototype.clear = mapClear; -MapCache.prototype['delete'] = mapDelete; -MapCache.prototype.get = mapGet; -MapCache.prototype.has = mapHas; -MapCache.prototype.set = mapSet; +MapCache.prototype.clear = mapCacheClear; +MapCache.prototype['delete'] = mapCacheDelete; +MapCache.prototype.get = mapCacheGet; +MapCache.prototype.has = mapCacheHas; +MapCache.prototype.set = mapCacheSet; export default MapCache; diff --git a/_SetCache.js b/_SetCache.js index 1fdc2ce8b..419774778 100644 --- a/_SetCache.js +++ b/_SetCache.js @@ -1,9 +1,10 @@ import MapCache from './_MapCache'; -import cachePush from './_cachePush'; +import setCacheAdd from './_setCacheAdd'; +import setCacheHas from './_setCacheHas'; /** * - * Creates a set cache object to store unique values. + * Creates an array cache object to store unique values. * * @private * @constructor @@ -15,11 +16,12 @@ function SetCache(values) { this.__data__ = new MapCache; while (++index < length) { - this.push(values[index]); + this.add(values[index]); } } // Add methods to `SetCache`. -SetCache.prototype.push = cachePush; +SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; +SetCache.prototype.has = setCacheHas; export default SetCache; diff --git a/_Stack.js b/_Stack.js index 43dd238ac..9578b3f2b 100644 --- a/_Stack.js +++ b/_Stack.js @@ -1,3 +1,4 @@ +import ListCache from './_ListCache'; import stackClear from './_stackClear'; import stackDelete from './_stackDelete'; import stackGet from './_stackGet'; @@ -9,17 +10,10 @@ import stackSet from './_stackSet'; * * @private * @constructor - * @param {Array} [values] The values to cache. + * @param {Array} [entries] The key-value pairs to cache. */ -function Stack(values) { - var index = -1, - length = values ? values.length : 0; - - this.clear(); - while (++index < length) { - var entry = values[index]; - this.set(entry[0], entry[1]); - } +function Stack(entries) { + this.__data__ = new ListCache(entries); } // Add methods to `Stack`. diff --git a/_arrayConcat.js b/_arrayConcat.js deleted file mode 100644 index 61a7df31c..000000000 --- a/_arrayConcat.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Creates a new array concatenating `array` with `other`. - * - * @private - * @param {Array} array The first array to concatenate. - * @param {Array} other The second array to concatenate. - * @returns {Array} Returns the new concatenated array. - */ -function arrayConcat(array, other) { - var index = -1, - length = array.length, - othIndex = -1, - othLength = other.length, - result = Array(length + othLength); - - while (++index < length) { - result[index] = array[index]; - } - while (++othIndex < othLength) { - result[index++] = other[othIndex]; - } - return result; -} - -export default arrayConcat; diff --git a/_assocGet.js b/_assocGet.js deleted file mode 100644 index 721227d00..000000000 --- a/_assocGet.js +++ /dev/null @@ -1,16 +0,0 @@ -import assocIndexOf from './_assocIndexOf'; - -/** - * Gets the associative array value for `key`. - * - * @private - * @param {Array} array The array to query. - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ -function assocGet(array, key) { - var index = assocIndexOf(array, key); - return index < 0 ? undefined : array[index][1]; -} - -export default assocGet; diff --git a/_assocSet.js b/_assocSet.js deleted file mode 100644 index beabfc44b..000000000 --- a/_assocSet.js +++ /dev/null @@ -1,20 +0,0 @@ -import assocIndexOf from './_assocIndexOf'; - -/** - * Sets the associative array `key` to `value`. - * - * @private - * @param {Array} array The array to modify. - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - */ -function assocSet(array, key, value) { - var index = assocIndexOf(array, key); - if (index < 0) { - array.push([key, value]); - } else { - array[index][1] = value; - } -} - -export default assocSet; diff --git a/_baseAt.js b/_baseAt.js index 944cf9e01..6ff2bdd50 100644 --- a/_baseAt.js +++ b/_baseAt.js @@ -6,7 +6,7 @@ import get from './get'; * @private * @param {Object} object The object to iterate over. * @param {string[]} paths The property paths of elements to pick. - * @returns {Array} Returns the new array of picked elements. + * @returns {Array} Returns the picked elements. */ function baseAt(object, paths) { var index = -1, diff --git a/_baseConforms.js b/_baseConforms.js index c8623a1c7..1c60bc583 100644 --- a/_baseConforms.js +++ b/_baseConforms.js @@ -5,7 +5,7 @@ import keys from './keys'; * * @private * @param {Object} source The object of property predicates to conform to. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. */ function baseConforms(source) { var props = keys(source), diff --git a/_baseFunctions.js b/_baseFunctions.js index 45f0be6aa..3d8b4a58a 100644 --- a/_baseFunctions.js +++ b/_baseFunctions.js @@ -8,7 +8,7 @@ import isFunction from './isFunction'; * @private * @param {Object} object The object to inspect. * @param {Array} props The property names to filter. - * @returns {Array} Returns the new array of filtered property names. + * @returns {Array} Returns the function names. */ function baseFunctions(object, props) { return arrayFilter(props, function(key) { diff --git a/_baseGetAllKeys.js b/_baseGetAllKeys.js index 7c9487948..cf117547e 100644 --- a/_baseGetAllKeys.js +++ b/_baseGetAllKeys.js @@ -14,9 +14,7 @@ import isArray from './isArray'; */ function baseGetAllKeys(object, keysFunc, symbolsFunc) { var result = keysFunc(object); - return isArray(object) - ? result - : arrayPush(result, symbolsFunc(object)); + return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); } export default baseGetAllKeys; diff --git a/_baseMatches.js b/_baseMatches.js index 6cbb044a8..14ce12d22 100644 --- a/_baseMatches.js +++ b/_baseMatches.js @@ -7,7 +7,7 @@ import matchesStrictComparable from './_matchesStrictComparable'; * * @private * @param {Object} source The object of property values to match. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. */ function baseMatches(source) { var matchData = getMatchData(source); diff --git a/_baseMatchesProperty.js b/_baseMatchesProperty.js index 500ca6878..de6ed4f7a 100644 --- a/_baseMatchesProperty.js +++ b/_baseMatchesProperty.js @@ -16,7 +16,7 @@ var UNORDERED_COMPARE_FLAG = 1, * @private * @param {string} path The path of the property to get. * @param {*} srcValue The value to match. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. */ function baseMatchesProperty(path, srcValue) { if (isKey(path) && isStrictComparable(srcValue)) { diff --git a/_baseProperty.js b/_baseProperty.js index 96ac4c835..90f032924 100644 --- a/_baseProperty.js +++ b/_baseProperty.js @@ -3,7 +3,7 @@ * * @private * @param {string} key The key of the property to get. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new accessor function. */ function baseProperty(key) { return function(object) { diff --git a/_basePropertyDeep.js b/_basePropertyDeep.js index 3913f638d..efa1a1266 100644 --- a/_basePropertyDeep.js +++ b/_basePropertyDeep.js @@ -5,7 +5,7 @@ import baseGet from './_baseGet'; * * @private * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new accessor function. */ function basePropertyDeep(path) { return function(object) { diff --git a/_baseRange.js b/_baseRange.js index 0f08adf71..f179f14e8 100644 --- a/_baseRange.js +++ b/_baseRange.js @@ -11,7 +11,7 @@ var nativeCeil = Math.ceil, * @param {number} end The end of the range. * @param {number} step The value to increment or decrement by. * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Array} Returns the new array of numbers. + * @returns {Array} Returns the range of numbers. */ function baseRange(start, end, step, fromRight) { var index = -1, diff --git a/_baseToPairs.js b/_baseToPairs.js index 68eb14b63..10c834a13 100644 --- a/_baseToPairs.js +++ b/_baseToPairs.js @@ -7,7 +7,7 @@ import arrayMap from './_arrayMap'; * @private * @param {Object} object The object to query. * @param {Array} props The property names to get values for. - * @returns {Object} Returns the new array of key-value pairs. + * @returns {Object} Returns the key-value pairs. */ function baseToPairs(object, props) { return arrayMap(props, function(key) { diff --git a/_baseUnary.js b/_baseUnary.js index 0419362b2..23a25e32d 100644 --- a/_baseUnary.js +++ b/_baseUnary.js @@ -3,7 +3,7 @@ * * @private * @param {Function} func The function to cap arguments for. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new capped function. */ function baseUnary(func) { return function(value) { diff --git a/_cacheHas.js b/_cacheHas.js index c5761e636..b0110d076 100644 --- a/_cacheHas.js +++ b/_cacheHas.js @@ -1,25 +1,13 @@ -import isKeyable from './_isKeyable'; - -/** Used to stand-in for `undefined` hash values. */ -var HASH_UNDEFINED = '__lodash_hash_undefined__'; - /** - * Checks if `value` is in `cache`. + * Checks if a cache value for `key` exists. * * @private - * @param {Object} cache The set cache to search. - * @param {*} value The value to search for. - * @returns {number} Returns `true` if `value` is found, else `false`. + * @param {Object} cache The cache to query. + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ -function cacheHas(cache, value) { - var map = cache.__data__; - if (isKeyable(value)) { - var data = map.__data__, - hash = typeof value == 'string' ? data.string : data.hash; - - return hash[value] === HASH_UNDEFINED; - } - return map.has(value); +function cacheHas(cache, key) { + return cache.has(key); } export default cacheHas; diff --git a/_cachePush.js b/_cachePush.js deleted file mode 100644 index ccfd13b4d..000000000 --- a/_cachePush.js +++ /dev/null @@ -1,27 +0,0 @@ -import isKeyable from './_isKeyable'; - -/** Used to stand-in for `undefined` hash values. */ -var HASH_UNDEFINED = '__lodash_hash_undefined__'; - -/** - * Adds `value` to the set cache. - * - * @private - * @name push - * @memberOf SetCache - * @param {*} value The value to cache. - */ -function cachePush(value) { - var map = this.__data__; - if (isKeyable(value)) { - var data = map.__data__, - hash = typeof value == 'string' ? data.string : data.hash; - - hash[value] = HASH_UNDEFINED; - } - else { - map.set(value, HASH_UNDEFINED); - } -} - -export default cachePush; diff --git a/_composeArgs.js b/_composeArgs.js index 21f7e43de..82643bdf0 100644 --- a/_composeArgs.js +++ b/_composeArgs.js @@ -6,7 +6,7 @@ var nativeMax = Math.max; * placeholders, and provided arguments into a single array of arguments. * * @private - * @param {Array|Object} args The provided arguments. + * @param {Array} args The provided arguments. * @param {Array} partials The arguments to prepend to those provided. * @param {Array} holders The `partials` placeholder indexes. * @params {boolean} [isCurried] Specify composing for a curried function. diff --git a/_composeArgsRight.js b/_composeArgsRight.js index 65db64190..9540e39cf 100644 --- a/_composeArgsRight.js +++ b/_composeArgsRight.js @@ -6,7 +6,7 @@ var nativeMax = Math.max; * is tailored for `_.partialRight`. * * @private - * @param {Array|Object} args The provided arguments. + * @param {Array} args The provided arguments. * @param {Array} partials The arguments to append to those provided. * @param {Array} holders The `partials` placeholder indexes. * @params {boolean} [isCurried] Specify composing for a curried function. diff --git a/_createAssigner.js b/_createAssigner.js index ef06868ea..f27a167fa 100644 --- a/_createAssigner.js +++ b/_createAssigner.js @@ -15,7 +15,7 @@ function createAssigner(assigner) { customizer = length > 1 ? sources[length - 1] : undefined, guard = length > 2 ? sources[2] : undefined; - customizer = typeof customizer == 'function' + customizer = (assigner.length > 3 && typeof customizer == 'function') ? (length--, customizer) : undefined; diff --git a/_createCaseFirst.js b/_createCaseFirst.js index 35279b667..3d8649fb7 100644 --- a/_createCaseFirst.js +++ b/_createCaseFirst.js @@ -8,7 +8,7 @@ import toString from './toString'; * * @private * @param {string} methodName The name of the `String` case method to use. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new case function. */ function createCaseFirst(methodName) { return function(string) { diff --git a/_createCurryWrapper.js b/_createCurryWrapper.js index 69db47654..cb24d3f27 100644 --- a/_createCurryWrapper.js +++ b/_createCurryWrapper.js @@ -2,7 +2,7 @@ import apply from './_apply'; import createCtorWrapper from './_createCtorWrapper'; import createHybridWrapper from './_createHybridWrapper'; import createRecurryWrapper from './_createRecurryWrapper'; -import getPlaceholder from './_getPlaceholder'; +import getHolder from './_getHolder'; import replaceHolders from './_replaceHolders'; import root from './_root'; @@ -23,7 +23,7 @@ function createCurryWrapper(func, bitmask, arity) { var length = arguments.length, args = Array(length), index = length, - placeholder = getPlaceholder(wrapper); + placeholder = getHolder(wrapper); while (index--) { args[index] = arguments[index]; diff --git a/_createHybridWrapper.js b/_createHybridWrapper.js index 37752f2d5..0b9226937 100644 --- a/_createHybridWrapper.js +++ b/_createHybridWrapper.js @@ -3,7 +3,7 @@ import composeArgsRight from './_composeArgsRight'; import countHolders from './_countHolders'; import createCtorWrapper from './_createCtorWrapper'; import createRecurryWrapper from './_createRecurryWrapper'; -import getPlaceholder from './_getPlaceholder'; +import getHolder from './_getHolder'; import reorder from './_reorder'; import replaceHolders from './_replaceHolders'; import root from './_root'; @@ -46,14 +46,14 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials function wrapper() { var length = arguments.length, - index = length, - args = Array(length); + args = Array(length), + index = length; while (index--) { args[index] = arguments[index]; } if (isCurried) { - var placeholder = getPlaceholder(wrapper), + var placeholder = getHolder(wrapper), holdersCount = countHolders(args, placeholder); } if (partials) { diff --git a/_createOver.js b/_createOver.js index 1f4093d9e..b44f22d58 100644 --- a/_createOver.js +++ b/_createOver.js @@ -12,7 +12,7 @@ import rest from './rest'; * * @private * @param {Function} arrayFunc The function to iterate over iteratees. - * @returns {Function} Returns the new invoker function. + * @returns {Function} Returns the new over function. */ function createOver(arrayFunc) { return rest(function(iteratees) { diff --git a/_createToPairs.js b/_createToPairs.js new file mode 100644 index 000000000..88d139153 --- /dev/null +++ b/_createToPairs.js @@ -0,0 +1,30 @@ +import baseToPairs from './_baseToPairs'; +import getTag from './_getTag'; +import mapToArray from './_mapToArray'; +import setToPairs from './_setToPairs'; + +/** `Object#toString` result references. */ +var mapTag = '[object Map]', + setTag = '[object Set]'; + +/** + * Creates a `_.toPairs` or `_.toPairsIn` function. + * + * @private + * @param {Function} keysFunc The function to get the keys of a given object. + * @returns {Function} Returns the new pairs function. + */ +function createToPairs(keysFunc) { + return function(object) { + var tag = getTag(object); + if (tag == mapTag) { + return mapToArray(object); + } + if (tag == setTag) { + return setToPairs(object); + } + return baseToPairs(object, keysFunc(object)); + }; +} + +export default createToPairs; diff --git a/_createWrapper.js b/_createWrapper.js index 846e94fc6..eca547642 100644 --- a/_createWrapper.js +++ b/_createWrapper.js @@ -39,6 +39,7 @@ var nativeMax = Math.max; * 64 - `_.partialRight` * 128 - `_.rearg` * 256 - `_.ary` + * 512 - `_.flip` * @param {*} [thisArg] The `this` binding of `func`. * @param {Array} [partials] The arguments to be partially applied. * @param {Array} [holders] The `partials` placeholder indexes. diff --git a/_equalArrays.js b/_equalArrays.js index a36357bbb..b13f4d265 100644 --- a/_equalArrays.js +++ b/_equalArrays.js @@ -1,3 +1,4 @@ +import SetCache from './_SetCache'; import arraySome from './_arraySome'; /** Used to compose bitmasks for comparison styles. */ @@ -19,9 +20,7 @@ var UNORDERED_COMPARE_FLAG = 1, * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. */ function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { - var index = -1, - isPartial = bitmask & PARTIAL_COMPARE_FLAG, - isUnordered = bitmask & UNORDERED_COMPARE_FLAG, + var isPartial = bitmask & PARTIAL_COMPARE_FLAG, arrLength = array.length, othLength = other.length; @@ -33,7 +32,10 @@ function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { if (stacked) { return stacked == other; } - var result = true; + var index = -1, + result = true, + seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined; + stack.set(array, other); // Ignore non-index properties. @@ -54,10 +56,12 @@ function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { break; } // Recursively compare arrays (susceptible to call stack limits). - if (isUnordered) { - if (!arraySome(other, function(othValue) { - return arrValue === othValue || - equalFunc(arrValue, othValue, customizer, bitmask, stack); + if (seen) { + if (!arraySome(other, function(othValue, othIndex) { + if (!seen.has(othIndex) && + (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) { + return seen.add(othIndex); + } })) { result = false; break; diff --git a/_getPlaceholder.js b/_getHolder.js similarity index 78% rename from _getPlaceholder.js rename to _getHolder.js index ba0d7543b..9f76b190b 100644 --- a/_getPlaceholder.js +++ b/_getHolder.js @@ -5,9 +5,9 @@ * @param {Function} func The function to inspect. * @returns {*} Returns the placeholder value. */ -function getPlaceholder(func) { +function getHolder(func) { var object = func; return object.placeholder; } -export default getPlaceholder; +export default getHolder; diff --git a/_getMapData.js b/_getMapData.js new file mode 100644 index 000000000..adcbb6bde --- /dev/null +++ b/_getMapData.js @@ -0,0 +1,18 @@ +import isKeyable from './_isKeyable'; + +/** + * Gets the data for `map`. + * + * @private + * @param {Object} map The map to query. + * @param {string} key The reference key. + * @returns {*} Returns the map data. + */ +function getMapData(map, key) { + var data = map.__data__; + return isKeyable(key) + ? data[typeof key == 'string' ? 'string' : 'hash'] + : data.map; +} + +export default getMapData; diff --git a/_hashClear.js b/_hashClear.js new file mode 100644 index 000000000..ac510cebe --- /dev/null +++ b/_hashClear.js @@ -0,0 +1,14 @@ +import nativeCreate from './_nativeCreate'; + +/** + * Removes all key-value entries from the hash. + * + * @private + * @name clear + * @memberOf Hash + */ +function hashClear() { + this.__data__ = nativeCreate ? nativeCreate(null) : {}; +} + +export default hashClear; diff --git a/_hashDelete.js b/_hashDelete.js index 300da9b3b..857dbd3e0 100644 --- a/_hashDelete.js +++ b/_hashDelete.js @@ -1,15 +1,15 @@ -import hashHas from './_hashHas'; - /** * Removes `key` and its value from the hash. * * @private + * @name delete + * @memberOf Hash * @param {Object} hash The hash to modify. * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ -function hashDelete(hash, key) { - return hashHas(hash, key) && delete hash[key]; +function hashDelete(key) { + return this.has(key) && delete this.__data__[key]; } export default hashDelete; diff --git a/_hashGet.js b/_hashGet.js index 9bdbe2c6f..4e8c118f5 100644 --- a/_hashGet.js +++ b/_hashGet.js @@ -13,16 +13,18 @@ var hasOwnProperty = objectProto.hasOwnProperty; * Gets the hash value for `key`. * * @private - * @param {Object} hash The hash to query. + * @name get + * @memberOf Hash * @param {string} key The key of the value to get. * @returns {*} Returns the entry value. */ -function hashGet(hash, key) { +function hashGet(key) { + var data = this.__data__; if (nativeCreate) { - var result = hash[key]; + var result = data[key]; return result === HASH_UNDEFINED ? undefined : result; } - return hasOwnProperty.call(hash, key) ? hash[key] : undefined; + return hasOwnProperty.call(data, key) ? data[key] : undefined; } export default hashGet; diff --git a/_hashHas.js b/_hashHas.js index 3eb82b7be..e1b698309 100644 --- a/_hashHas.js +++ b/_hashHas.js @@ -10,12 +10,14 @@ var hasOwnProperty = objectProto.hasOwnProperty; * Checks if a hash value for `key` exists. * * @private - * @param {Object} hash The hash to query. + * @name has + * @memberOf Hash * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ -function hashHas(hash, key) { - return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key); +function hashHas(key) { + var data = this.__data__; + return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key); } export default hashHas; diff --git a/_hashSet.js b/_hashSet.js index 3f72147be..37227ed7b 100644 --- a/_hashSet.js +++ b/_hashSet.js @@ -7,12 +7,16 @@ var HASH_UNDEFINED = '__lodash_hash_undefined__'; * Sets the hash `key` to `value`. * * @private - * @param {Object} hash The hash to modify. + * @name set + * @memberOf Hash * @param {string} key The key of the value to set. * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. */ -function hashSet(hash, key, value) { - hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; +function hashSet(key, value) { + var data = this.__data__; + data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; + return this; } export default hashSet; diff --git a/_isFlattenable.js b/_isFlattenable.js index 4a98c9b76..bac7447f7 100644 --- a/_isFlattenable.js +++ b/_isFlattenable.js @@ -1,6 +1,5 @@ import isArguments from './isArguments'; import isArray from './isArray'; -import isArrayLikeObject from './isArrayLikeObject'; /** * Checks if `value` is a flattenable `arguments` object or array. @@ -10,7 +9,7 @@ import isArrayLikeObject from './isArrayLikeObject'; * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. */ function isFlattenable(value) { - return isArrayLikeObject(value) && (isArray(value) || isArguments(value)); + return isArray(value) || isArguments(value); } export default isFlattenable; diff --git a/_listCacheClear.js b/_listCacheClear.js new file mode 100644 index 000000000..493e847d2 --- /dev/null +++ b/_listCacheClear.js @@ -0,0 +1,12 @@ +/** + * Removes all key-value entries from the list cache. + * + * @private + * @name clear + * @memberOf ListCache + */ +function listCacheClear() { + this.__data__ = []; +} + +export default listCacheClear; diff --git a/_assocDelete.js b/_listCacheDelete.js similarity index 59% rename from _assocDelete.js rename to _listCacheDelete.js index dbdb350a5..9d7bac53e 100644 --- a/_assocDelete.js +++ b/_listCacheDelete.js @@ -7,25 +7,28 @@ var arrayProto = Array.prototype; var splice = arrayProto.splice; /** - * Removes `key` and its value from the associative array. + * Removes `key` and its value from the list cache. * * @private - * @param {Array} array The array to modify. + * @name delete + * @memberOf ListCache * @param {string} key The key of the value to remove. * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ -function assocDelete(array, key) { - var index = assocIndexOf(array, key); +function listCacheDelete(key) { + var data = this.__data__, + index = assocIndexOf(data, key); + if (index < 0) { return false; } - var lastIndex = array.length - 1; + var lastIndex = data.length - 1; if (index == lastIndex) { - array.pop(); + data.pop(); } else { - splice.call(array, index, 1); + splice.call(data, index, 1); } return true; } -export default assocDelete; +export default listCacheDelete; diff --git a/_listCacheGet.js b/_listCacheGet.js new file mode 100644 index 000000000..7a52b08f1 --- /dev/null +++ b/_listCacheGet.js @@ -0,0 +1,19 @@ +import assocIndexOf from './_assocIndexOf'; + +/** + * Gets the list cache value for `key`. + * + * @private + * @name get + * @memberOf ListCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ +function listCacheGet(key) { + var data = this.__data__, + index = assocIndexOf(data, key); + + return index < 0 ? undefined : data[index][1]; +} + +export default listCacheGet; diff --git a/_assocHas.js b/_listCacheHas.js similarity index 50% rename from _assocHas.js rename to _listCacheHas.js index 2f8b8fd23..3db6fade0 100644 --- a/_assocHas.js +++ b/_listCacheHas.js @@ -1,15 +1,16 @@ import assocIndexOf from './_assocIndexOf'; /** - * Checks if an associative array value for `key` exists. + * Checks if a list cache value for `key` exists. * * @private - * @param {Array} array The array to query. + * @name has + * @memberOf ListCache * @param {string} key The key of the entry to check. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ -function assocHas(array, key) { - return assocIndexOf(array, key) > -1; +function listCacheHas(key) { + return assocIndexOf(this.__data__, key) > -1; } -export default assocHas; +export default listCacheHas; diff --git a/_listCacheSet.js b/_listCacheSet.js new file mode 100644 index 000000000..a6c468365 --- /dev/null +++ b/_listCacheSet.js @@ -0,0 +1,25 @@ +import assocIndexOf from './_assocIndexOf'; + +/** + * Sets the list cache `key` to `value`. + * + * @private + * @name set + * @memberOf ListCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the list cache instance. + */ +function listCacheSet(key, value) { + var data = this.__data__, + index = assocIndexOf(data, key); + + if (index < 0) { + data.push([key, value]); + } else { + data[index][1] = value; + } + return this; +} + +export default listCacheSet; diff --git a/_mapClear.js b/_mapCacheClear.js similarity index 64% rename from _mapClear.js rename to _mapCacheClear.js index 8d27a8d68..d10073fc5 100644 --- a/_mapClear.js +++ b/_mapCacheClear.js @@ -1,4 +1,5 @@ import Hash from './_Hash'; +import ListCache from './_ListCache'; import Map from './_Map'; /** @@ -8,12 +9,12 @@ import Map from './_Map'; * @name clear * @memberOf MapCache */ -function mapClear() { +function mapCacheClear() { this.__data__ = { 'hash': new Hash, - 'map': Map ? new Map : [], + 'map': new (Map || ListCache), 'string': new Hash }; } -export default mapClear; +export default mapCacheClear; diff --git a/_mapCacheDelete.js b/_mapCacheDelete.js new file mode 100644 index 000000000..88b896f30 --- /dev/null +++ b/_mapCacheDelete.js @@ -0,0 +1,16 @@ +import getMapData from './_getMapData'; + +/** + * Removes `key` and its value from the map. + * + * @private + * @name delete + * @memberOf MapCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ +function mapCacheDelete(key) { + return getMapData(this, key)['delete'](key); +} + +export default mapCacheDelete; diff --git a/_mapCacheGet.js b/_mapCacheGet.js new file mode 100644 index 000000000..d6c7c468a --- /dev/null +++ b/_mapCacheGet.js @@ -0,0 +1,16 @@ +import getMapData from './_getMapData'; + +/** + * Gets the map value for `key`. + * + * @private + * @name get + * @memberOf MapCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ +function mapCacheGet(key) { + return getMapData(this, key).get(key); +} + +export default mapCacheGet; diff --git a/_mapCacheHas.js b/_mapCacheHas.js new file mode 100644 index 000000000..d64e370d8 --- /dev/null +++ b/_mapCacheHas.js @@ -0,0 +1,16 @@ +import getMapData from './_getMapData'; + +/** + * Checks if a map value for `key` exists. + * + * @private + * @name has + * @memberOf MapCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ +function mapCacheHas(key) { + return getMapData(this, key).has(key); +} + +export default mapCacheHas; diff --git a/_mapCacheSet.js b/_mapCacheSet.js new file mode 100644 index 000000000..f8a6cd728 --- /dev/null +++ b/_mapCacheSet.js @@ -0,0 +1,18 @@ +import getMapData from './_getMapData'; + +/** + * Sets the map `key` to `value`. + * + * @private + * @name set + * @memberOf MapCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the map cache instance. + */ +function mapCacheSet(key, value) { + getMapData(this, key).set(key, value); + return this; +} + +export default mapCacheSet; diff --git a/_mapDelete.js b/_mapDelete.js deleted file mode 100644 index 20c7f86d9..000000000 --- a/_mapDelete.js +++ /dev/null @@ -1,23 +0,0 @@ -import Map from './_Map'; -import assocDelete from './_assocDelete'; -import hashDelete from './_hashDelete'; -import isKeyable from './_isKeyable'; - -/** - * Removes `key` and its value from the map. - * - * @private - * @name delete - * @memberOf MapCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ -function mapDelete(key) { - var data = this.__data__; - if (isKeyable(key)) { - return hashDelete(typeof key == 'string' ? data.string : data.hash, key); - } - return Map ? data.map['delete'](key) : assocDelete(data.map, key); -} - -export default mapDelete; diff --git a/_mapGet.js b/_mapGet.js deleted file mode 100644 index a6bc8fa4c..000000000 --- a/_mapGet.js +++ /dev/null @@ -1,23 +0,0 @@ -import Map from './_Map'; -import assocGet from './_assocGet'; -import hashGet from './_hashGet'; -import isKeyable from './_isKeyable'; - -/** - * Gets the map value for `key`. - * - * @private - * @name get - * @memberOf MapCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ -function mapGet(key) { - var data = this.__data__; - if (isKeyable(key)) { - return hashGet(typeof key == 'string' ? data.string : data.hash, key); - } - return Map ? data.map.get(key) : assocGet(data.map, key); -} - -export default mapGet; diff --git a/_mapHas.js b/_mapHas.js deleted file mode 100644 index 0615d87f8..000000000 --- a/_mapHas.js +++ /dev/null @@ -1,23 +0,0 @@ -import Map from './_Map'; -import assocHas from './_assocHas'; -import hashHas from './_hashHas'; -import isKeyable from './_isKeyable'; - -/** - * Checks if a map value for `key` exists. - * - * @private - * @name has - * @memberOf MapCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ -function mapHas(key) { - var data = this.__data__; - if (isKeyable(key)) { - return hashHas(typeof key == 'string' ? data.string : data.hash, key); - } - return Map ? data.map.has(key) : assocHas(data.map, key); -} - -export default mapHas; diff --git a/_mapSet.js b/_mapSet.js deleted file mode 100644 index daa61c820..000000000 --- a/_mapSet.js +++ /dev/null @@ -1,28 +0,0 @@ -import Map from './_Map'; -import assocSet from './_assocSet'; -import hashSet from './_hashSet'; -import isKeyable from './_isKeyable'; - -/** - * Sets the map `key` to `value`. - * - * @private - * @name set - * @memberOf MapCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the map cache instance. - */ -function mapSet(key, value) { - var data = this.__data__; - if (isKeyable(key)) { - hashSet(typeof key == 'string' ? data.string : data.hash, key, value); - } else if (Map) { - data.map.set(key, value); - } else { - assocSet(data.map, key, value); - } - return this; -} - -export default mapSet; diff --git a/_mapToArray.js b/_mapToArray.js index fd5adc419..82346d500 100644 --- a/_mapToArray.js +++ b/_mapToArray.js @@ -1,9 +1,9 @@ /** - * Converts `map` to an array. + * Converts `map` to its key-value pairs. * * @private * @param {Object} map The map to convert. - * @returns {Array} Returns the converted array. + * @returns {Array} Returns the key-value pairs. */ function mapToArray(map) { var index = -1, diff --git a/_matchesStrictComparable.js b/_matchesStrictComparable.js index a9dd8af95..531ffb3d0 100644 --- a/_matchesStrictComparable.js +++ b/_matchesStrictComparable.js @@ -5,7 +5,7 @@ * @private * @param {string} key The key of the property to get. * @param {*} srcValue The value to match. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. */ function matchesStrictComparable(key, srcValue) { return function(object) { diff --git a/_setCacheAdd.js b/_setCacheAdd.js new file mode 100644 index 000000000..d3a42d36a --- /dev/null +++ b/_setCacheAdd.js @@ -0,0 +1,19 @@ +/** Used to stand-in for `undefined` hash values. */ +var HASH_UNDEFINED = '__lodash_hash_undefined__'; + +/** + * Adds `value` to the array cache. + * + * @private + * @name add + * @memberOf SetCache + * @alias push + * @param {*} value The value to cache. + * @returns {Object} Returns the cache instance. + */ +function setCacheAdd(value) { + this.__data__.set(value, HASH_UNDEFINED); + return this; +} + +export default setCacheAdd; diff --git a/_setCacheHas.js b/_setCacheHas.js new file mode 100644 index 000000000..67f4c8ae2 --- /dev/null +++ b/_setCacheHas.js @@ -0,0 +1,14 @@ +/** + * Checks if `value` is in the array cache. + * + * @private + * @name has + * @memberOf SetCache + * @param {*} value The value to search for. + * @returns {number} Returns `true` if `value` is found, else `false`. + */ +function setCacheHas(value) { + return this.__data__.has(value); +} + +export default setCacheHas; diff --git a/_setToArray.js b/_setToArray.js index 7ab0451dd..fdf823ccf 100644 --- a/_setToArray.js +++ b/_setToArray.js @@ -1,9 +1,9 @@ /** - * Converts `set` to an array. + * Converts `set` to an array of its values. * * @private * @param {Object} set The set to convert. - * @returns {Array} Returns the converted array. + * @returns {Array} Returns the values. */ function setToArray(set) { var index = -1, diff --git a/_setToPairs.js b/_setToPairs.js new file mode 100644 index 000000000..f0d123bfc --- /dev/null +++ b/_setToPairs.js @@ -0,0 +1,18 @@ +/** + * Converts `set` to its value-value pairs. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the value-value pairs. + */ +function setToPairs(set) { + var index = -1, + result = Array(set.size); + + set.forEach(function(value) { + result[++index] = [value, value]; + }); + return result; +} + +export default setToPairs; diff --git a/_stackClear.js b/_stackClear.js index 8e0c9c038..d39f417fc 100644 --- a/_stackClear.js +++ b/_stackClear.js @@ -1,3 +1,5 @@ +import ListCache from './_ListCache'; + /** * Removes all key-value entries from the stack. * @@ -6,7 +8,7 @@ * @memberOf Stack */ function stackClear() { - this.__data__ = { 'array': [], 'map': null }; + this.__data__ = new ListCache; } export default stackClear; diff --git a/_stackDelete.js b/_stackDelete.js index 52519820a..429ab21fd 100644 --- a/_stackDelete.js +++ b/_stackDelete.js @@ -1,5 +1,3 @@ -import assocDelete from './_assocDelete'; - /** * Removes `key` and its value from the stack. * @@ -10,10 +8,7 @@ import assocDelete from './_assocDelete'; * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ function stackDelete(key) { - var data = this.__data__, - array = data.array; - - return array ? assocDelete(array, key) : data.map['delete'](key); + return this.__data__['delete'](key); } export default stackDelete; diff --git a/_stackGet.js b/_stackGet.js index 3ae4204e6..139b9acc1 100644 --- a/_stackGet.js +++ b/_stackGet.js @@ -1,5 +1,3 @@ -import assocGet from './_assocGet'; - /** * Gets the stack value for `key`. * @@ -10,10 +8,7 @@ import assocGet from './_assocGet'; * @returns {*} Returns the entry value. */ function stackGet(key) { - var data = this.__data__, - array = data.array; - - return array ? assocGet(array, key) : data.map.get(key); + return this.__data__.get(key); } export default stackGet; diff --git a/_stackHas.js b/_stackHas.js index 993dce6d9..bc25f5a7e 100644 --- a/_stackHas.js +++ b/_stackHas.js @@ -1,5 +1,3 @@ -import assocHas from './_assocHas'; - /** * Checks if a stack value for `key` exists. * @@ -10,10 +8,7 @@ import assocHas from './_assocHas'; * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. */ function stackHas(key) { - var data = this.__data__, - array = data.array; - - return array ? assocHas(array, key) : data.map.has(key); + return this.__data__.has(key); } export default stackHas; diff --git a/_stackSet.js b/_stackSet.js index 1bd39239d..fe646275f 100644 --- a/_stackSet.js +++ b/_stackSet.js @@ -1,5 +1,5 @@ +import ListCache from './_ListCache'; import MapCache from './_MapCache'; -import assocSet from './_assocSet'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -15,21 +15,11 @@ var LARGE_ARRAY_SIZE = 200; * @returns {Object} Returns the stack cache instance. */ function stackSet(key, value) { - var data = this.__data__, - array = data.array; - - if (array) { - if (array.length < (LARGE_ARRAY_SIZE - 1)) { - assocSet(array, key, value); - } else { - data.array = null; - data.map = new MapCache(array); - } - } - var map = data.map; - if (map) { - map.set(key, value); + var cache = this.__data__; + if (cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) { + cache = this.__data__ = new MapCache(cache.__data__); } + cache.set(key, value); return this; } diff --git a/array.default.js b/array.default.js index 316fd15a4..4adc415d1 100644 --- a/array.default.js +++ b/array.default.js @@ -11,6 +11,7 @@ import dropWhile from './dropWhile'; import fill from './fill'; import findIndex from './findIndex'; import findLastIndex from './findLastIndex'; +import first from './first'; import flatten from './flatten'; import flattenDeep from './flattenDeep'; import flattenDepth from './flattenDepth'; @@ -66,15 +67,15 @@ import zipWith from './zipWith'; export default { chunk, compact, concat, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, - fill, findIndex, findLastIndex, flatten, flattenDeep, - flattenDepth, fromPairs, head, indexOf, initial, - intersection, intersectionBy, intersectionWith, join, last, - lastIndexOf, nth, pull, pullAll, pullAllBy, - pullAllWith, pullAt, remove, reverse, slice, - sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, sortedLastIndexBy, - sortedLastIndexOf, sortedUniq, sortedUniqBy, tail, take, - takeRight, takeRightWhile, takeWhile, union, unionBy, - unionWith, uniq, uniqBy, uniqWith, unzip, - unzipWith, without, xor, xorBy, xorWith, - zip, zipObject, zipObjectDeep, zipWith + fill, findIndex, findLastIndex, first, flatten, + flattenDeep, flattenDepth, fromPairs, head, indexOf, + initial, intersection, intersectionBy, intersectionWith, join, + last, lastIndexOf, nth, pull, pullAll, + pullAllBy, pullAllWith, pullAt, remove, reverse, + slice, sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, + sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy, tail, + take, takeRight, takeRightWhile, takeWhile, union, + unionBy, unionWith, uniq, uniqBy, uniqWith, + unzip, unzipWith, without, xor, xorBy, + xorWith, zip, zipObject, zipObjectDeep, zipWith }; diff --git a/array.js b/array.js index 5aee782e5..9296fc766 100644 --- a/array.js +++ b/array.js @@ -11,6 +11,7 @@ export { default as dropWhile } from './dropWhile'; export { default as fill } from './fill'; export { default as findIndex } from './findIndex'; export { default as findLastIndex } from './findLastIndex'; +export { default as first } from './first'; export { default as flatten } from './flatten'; export { default as flattenDeep } from './flattenDeep'; export { default as flattenDepth } from './flattenDepth'; diff --git a/ary.js b/ary.js index 2d5abc1bb..0798dee52 100644 --- a/ary.js +++ b/ary.js @@ -14,7 +14,7 @@ var ARY_FLAG = 128; * @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 methods like `_.map`. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new capped function. * @example * * _.map(['6', '8', '10'], _.ary(parseInt, 1)); diff --git a/at.js b/at.js index f0ed13489..4b75444ad 100644 --- a/at.js +++ b/at.js @@ -11,7 +11,7 @@ import rest from './rest'; * @category Object * @param {Object} object The object to iterate over. * @param {...(string|string[])} [paths] The property paths of elements to pick. - * @returns {Array} Returns the new array of picked elements. + * @returns {Array} Returns the picked values. * @example * * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; diff --git a/bind.js b/bind.js index 947dbedaa..14bd2260f 100644 --- a/bind.js +++ b/bind.js @@ -1,5 +1,5 @@ import createWrapper from './_createWrapper'; -import getPlaceholder from './_getPlaceholder'; +import getHolder from './_getHolder'; import replaceHolders from './_replaceHolders'; import rest from './rest'; @@ -45,7 +45,7 @@ var BIND_FLAG = 1, var bind = rest(function(func, thisArg, partials) { var bitmask = BIND_FLAG; if (partials.length) { - var holders = replaceHolders(partials, getPlaceholder(bind)); + var holders = replaceHolders(partials, getHolder(bind)); bitmask |= PARTIAL_FLAG; } return createWrapper(func, bitmask, thisArg, partials, holders); diff --git a/bindKey.js b/bindKey.js index ef3bd6ed6..cfc43e43b 100644 --- a/bindKey.js +++ b/bindKey.js @@ -1,5 +1,5 @@ import createWrapper from './_createWrapper'; -import getPlaceholder from './_getPlaceholder'; +import getHolder from './_getHolder'; import replaceHolders from './_replaceHolders'; import rest from './rest'; @@ -56,7 +56,7 @@ var BIND_FLAG = 1, var bindKey = rest(function(object, key, partials) { var bitmask = BIND_FLAG | BIND_KEY_FLAG; if (partials.length) { - var holders = replaceHolders(partials, getPlaceholder(bindKey)); + var holders = replaceHolders(partials, getHolder(bindKey)); bitmask |= PARTIAL_FLAG; } return createWrapper(key, bitmask, object, partials, holders); diff --git a/chunk.js b/chunk.js index 700b0e619..5f147383e 100644 --- a/chunk.js +++ b/chunk.js @@ -18,7 +18,7 @@ var nativeCeil = Math.ceil, * @param {Array} array The array to process. * @param {number} [size=1] The length of each chunk * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the new array containing chunks. + * @returns {Array} Returns the new array of chunks. * @example * * _.chunk(['a', 'b', 'c', 'd'], 2); diff --git a/concat.js b/concat.js index 39e438959..73f28f230 100644 --- a/concat.js +++ b/concat.js @@ -1,7 +1,7 @@ -import arrayConcat from './_arrayConcat'; +import arrayPush from './_arrayPush'; import baseFlatten from './_baseFlatten'; -import castArray from './castArray'; import copyArray from './_copyArray'; +import isArray from './isArray'; /** * Creates a new array concatenating `array` with any additional arrays @@ -27,16 +27,16 @@ import copyArray from './_copyArray'; */ function concat() { var length = arguments.length, - array = castArray(arguments[0]); + args = Array(length ? length - 1 : 0), + array = arguments[0], + index = length; - if (length < 2) { - return length ? copyArray(array) : []; + while (index--) { + args[index - 1] = arguments[index]; } - var args = Array(length - 1); - while (length--) { - args[length - 1] = arguments[length]; - } - return arrayConcat(array, baseFlatten(args, 1)); + return length + ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)) + : []; } export default concat; diff --git a/cond.js b/cond.js index eea509455..c08ca1482 100644 --- a/cond.js +++ b/cond.js @@ -17,7 +17,7 @@ var FUNC_ERROR_TEXT = 'Expected a function'; * @since 4.0.0 * @category Util * @param {Array} pairs The predicate-function pairs. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new composite function. * @example * * var func = _.cond([ diff --git a/conforms.js b/conforms.js index fd8f0d9fc..2a467f3dd 100644 --- a/conforms.js +++ b/conforms.js @@ -11,7 +11,7 @@ import baseConforms from './_baseConforms'; * @since 4.0.0 * @category Util * @param {Object} source The object of property predicates to conform to. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. * @example * * var users = [ diff --git a/constant.js b/constant.js index 209e213c0..78dd50cae 100644 --- a/constant.js +++ b/constant.js @@ -6,7 +6,7 @@ * @since 2.4.0 * @category Util * @param {*} value The value to return from the new function. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new constant function. * @example * * var object = { 'user': 'fred' }; diff --git a/first.js b/first.js new file mode 100644 index 000000000..5a7e2c5b4 --- /dev/null +++ b/first.js @@ -0,0 +1 @@ +export { default } from './head' diff --git a/flip.js b/flip.js index 8f3c0e802..f52c15a07 100644 --- a/flip.js +++ b/flip.js @@ -11,7 +11,7 @@ var FLIP_FLAG = 512; * @since 4.0.0 * @category Function * @param {Function} func The function to flip arguments for. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new flipped function. * @example * * var flipped = _.flip(function() { diff --git a/flow.js b/flow.js index 03f549cf4..a54f2ae56 100644 --- a/flow.js +++ b/flow.js @@ -10,7 +10,7 @@ import createFlow from './_createFlow'; * @since 3.0.0 * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new composite function. * @see _.flowRight * @example * diff --git a/flowRight.js b/flowRight.js index e46c205d3..a0284a071 100644 --- a/flowRight.js +++ b/flowRight.js @@ -9,7 +9,7 @@ import createFlow from './_createFlow'; * @memberOf _ * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new composite function. * @see _.flow * @example * diff --git a/forEach.js b/forEach.js index abdf97417..28dfe48e3 100644 --- a/forEach.js +++ b/forEach.js @@ -34,9 +34,8 @@ import isArray from './isArray'; * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forEach(collection, iteratee) { - return (typeof iteratee == 'function' && isArray(collection)) - ? arrayEach(collection, iteratee) - : baseEach(collection, baseIteratee(iteratee)); + var func = isArray(collection) ? arrayEach : baseEach; + return func(collection, baseIteratee(iteratee, 3)); } export default forEach; diff --git a/forEachRight.js b/forEachRight.js index 0b7d05894..a297e28d5 100644 --- a/forEachRight.js +++ b/forEachRight.js @@ -24,9 +24,8 @@ import isArray from './isArray'; * // => Logs `2` then `1`. */ function forEachRight(collection, iteratee) { - return (typeof iteratee == 'function' && isArray(collection)) - ? arrayEachRight(collection, iteratee) - : baseEachRight(collection, baseIteratee(iteratee)); + var func = isArray(collection) ? arrayEachRight : baseEachRight; + return func(collection, baseIteratee(iteratee, 3)); } export default forEachRight; diff --git a/forIn.js b/forIn.js index d0defc737..8e3fe30e2 100644 --- a/forIn.js +++ b/forIn.js @@ -33,7 +33,7 @@ import keysIn from './keysIn'; function forIn(object, iteratee) { return object == null ? object - : baseFor(object, baseIteratee(iteratee), keysIn); + : baseFor(object, baseIteratee(iteratee, 3), keysIn); } export default forIn; diff --git a/forInRight.js b/forInRight.js index 5075c1497..3b4897dae 100644 --- a/forInRight.js +++ b/forInRight.js @@ -31,7 +31,7 @@ import keysIn from './keysIn'; function forInRight(object, iteratee) { return object == null ? object - : baseForRight(object, baseIteratee(iteratee), keysIn); + : baseForRight(object, baseIteratee(iteratee, 3), keysIn); } export default forInRight; diff --git a/forOwn.js b/forOwn.js index b340b3172..1f282df0f 100644 --- a/forOwn.js +++ b/forOwn.js @@ -30,7 +30,7 @@ import baseIteratee from './_baseIteratee'; * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forOwn(object, iteratee) { - return object && baseForOwn(object, baseIteratee(iteratee)); + return object && baseForOwn(object, baseIteratee(iteratee, 3)); } export default forOwn; diff --git a/forOwnRight.js b/forOwnRight.js index 68aec5b83..9d1dca0df 100644 --- a/forOwnRight.js +++ b/forOwnRight.js @@ -28,7 +28,7 @@ import baseIteratee from './_baseIteratee'; * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. */ function forOwnRight(object, iteratee) { - return object && baseForOwnRight(object, baseIteratee(iteratee)); + return object && baseForOwnRight(object, baseIteratee(iteratee, 3)); } export default forOwnRight; diff --git a/functions.js b/functions.js index 9c2000c64..8905eea4c 100644 --- a/functions.js +++ b/functions.js @@ -10,7 +10,7 @@ import keys from './keys'; * @memberOf _ * @category Object * @param {Object} object The object to inspect. - * @returns {Array} Returns the new array of property names. + * @returns {Array} Returns the function names. * @see _.functionsIn * @example * diff --git a/functionsIn.js b/functionsIn.js index 998e2c153..60bc21089 100644 --- a/functionsIn.js +++ b/functionsIn.js @@ -10,7 +10,7 @@ import keysIn from './keysIn'; * @since 4.0.0 * @category Object * @param {Object} object The object to inspect. - * @returns {Array} Returns the new array of property names. + * @returns {Array} Returns the function names. * @see _.functions * @example * diff --git a/isFinite.js b/isFinite.js index 22d8a351b..cea5d0702 100644 --- a/isFinite.js +++ b/isFinite.js @@ -21,14 +21,14 @@ var nativeIsFinite = root.isFinite; * _.isFinite(3); * // => true * - * _.isFinite(Number.MAX_VALUE); - * // => true - * - * _.isFinite(3.14); + * _.isFinite(Number.MIN_VALUE); * // => true * * _.isFinite(Infinity); * // => false + * + * _.isFinite('3'); + * // => false */ function isFinite(value) { return typeof value == 'number' && nativeIsFinite(value); diff --git a/lang.default.js b/lang.default.js index f56c00e73..8996b1d56 100644 --- a/lang.default.js +++ b/lang.default.js @@ -46,6 +46,7 @@ import isWeakSet from './isWeakSet'; import lt from './lt'; import lte from './lte'; import toArray from './toArray'; +import toFinite from './toFinite'; import toInteger from './toInteger'; import toLength from './toLength'; import toNumber from './toNumber'; @@ -63,6 +64,6 @@ export default { isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, - lt, lte, toArray, toInteger, toLength, - toNumber, toPlainObject, toSafeInteger, toString + lt, lte, toArray, toFinite, toInteger, + toLength, toNumber, toPlainObject, toSafeInteger, toString }; diff --git a/lang.js b/lang.js index 4d7b42def..2c027be03 100644 --- a/lang.js +++ b/lang.js @@ -46,6 +46,7 @@ export { default as isWeakSet } from './isWeakSet'; export { default as lt } from './lt'; export { default as lte } from './lte'; export { default as toArray } from './toArray'; +export { default as toFinite } from './toFinite'; export { default as toInteger } from './toInteger'; export { default as toLength } from './toLength'; export { default as toNumber } from './toNumber'; diff --git a/lodash.default.js b/lodash.default.js index ad3919ba6..a0bb35f4a 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.11.2 (Custom Build) + * lodash (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -44,7 +44,7 @@ import toInteger from './toInteger'; import lodash from './wrapperLodash'; /** Used as the semantic version number. */ -var VERSION = '4.11.2'; +var VERSION = '4.12.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_KEY_FLAG = 2; @@ -373,6 +373,7 @@ lodash.sum = math.sum; lodash.sumBy = math.sumBy; lodash.template = string.template; lodash.times = util.times; +lodash.toFinite = lang.toFinite; lodash.toInteger = toInteger; lodash.toLength = lang.toLength; lodash.toLower = string.toLower; diff --git a/lodash.js b/lodash.js index d0faeee94..f00a4f2c9 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.11.2 (Custom Build) + * lodash (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -74,6 +74,7 @@ export { default as findKey } from './findKey'; export { default as findLast } from './findLast'; export { default as findLastIndex } from './findLastIndex'; export { default as findLastKey } from './findLastKey'; +export { default as first } from './first'; export { default as flatMap } from './flatMap'; export { default as flatMapDeep } from './flatMapDeep'; export { default as flatMapDepth } from './flatMapDepth'; @@ -262,6 +263,7 @@ export { default as throttle } from './throttle'; export { default as thru } from './thru'; export { default as times } from './times'; export { default as toArray } from './toArray'; +export { default as toFinite } from './toFinite'; export { default as toInteger } from './toInteger'; export { default as toIterator } from './toIterator'; export { default as toJSON } from './toJSON'; diff --git a/matches.js b/matches.js index c9227d65e..26ae4d282 100644 --- a/matches.js +++ b/matches.js @@ -14,7 +14,7 @@ import baseMatches from './_baseMatches'; * @since 3.0.0 * @category Util * @param {Object} source The object of property values to match. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. * @example * * var users = [ diff --git a/matchesProperty.js b/matchesProperty.js index e2c9cd4df..f47accddc 100644 --- a/matchesProperty.js +++ b/matchesProperty.js @@ -14,7 +14,7 @@ import baseMatchesProperty from './_baseMatchesProperty'; * @category Util * @param {Array|string} path The path of the property to get. * @param {*} srcValue The value to match. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new spec function. * @example * * var users = [ diff --git a/memoize.js b/memoize.js index d836dae7a..895b2d7a6 100644 --- a/memoize.js +++ b/memoize.js @@ -22,7 +22,7 @@ var FUNC_ERROR_TEXT = 'Expected a function'; * @category Function * @param {Function} func The function to have its output memoized. * @param {Function} [resolver] The function to resolve the cache key. - * @returns {Function} Returns the new memoizing function. + * @returns {Function} Returns the new memoized function. * @example * * var object = { 'a': 1, 'b': 2 }; diff --git a/merge.js b/merge.js index 41db8e478..733d0b3da 100644 --- a/merge.js +++ b/merge.js @@ -6,7 +6,7 @@ import createAssigner from './_createAssigner'; * 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 + * 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. * diff --git a/method.js b/method.js index 6ce1f1569..8f2a31fcf 100644 --- a/method.js +++ b/method.js @@ -11,7 +11,7 @@ import rest from './rest'; * @category Util * @param {Array|string} path The path of the method to invoke. * @param {...*} [args] The arguments to invoke the method with. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new invoker function. * @example * * var objects = [ diff --git a/methodOf.js b/methodOf.js index d474eaf92..e14c1508d 100644 --- a/methodOf.js +++ b/methodOf.js @@ -12,7 +12,7 @@ import rest from './rest'; * @category Util * @param {Object} object The object to query. * @param {...*} [args] The arguments to invoke the method with. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new invoker function. * @example * * var array = _.times(3, _.constant), diff --git a/negate.js b/negate.js index 468d54fec..242eaf558 100644 --- a/negate.js +++ b/negate.js @@ -11,7 +11,7 @@ var FUNC_ERROR_TEXT = 'Expected a function'; * @since 3.0.0 * @category Function * @param {Function} predicate The predicate to negate. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new negated function. * @example * * function isEven(n) { diff --git a/nth.js b/nth.js index 910e0a292..b93914c11 100644 --- a/nth.js +++ b/nth.js @@ -2,8 +2,8 @@ import baseNth from './_baseNth'; import toInteger from './toInteger'; /** - * Gets the nth element of `array`. If `n` is negative, the nth element - * from the end is returned. + * Gets the element at `n` index of `array`. If `n` is negative, the nth + * element from the end is returned. * * @static * @memberOf _ diff --git a/nthArg.js b/nthArg.js index 29bbe7fd4..e67b068ed 100644 --- a/nthArg.js +++ b/nthArg.js @@ -3,7 +3,7 @@ import rest from './rest'; import toInteger from './toInteger'; /** - * Creates a function that returns its nth argument. If `n` is negative, + * Creates a function that gets the argument at `n` index. If `n` is negative, * the nth argument from the end is returned. * * @static @@ -11,7 +11,7 @@ import toInteger from './toInteger'; * @since 4.0.0 * @category Util * @param {number} [n=0] The index of the argument to return. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new pass-thru function. * @example * * var func = _.nthArg(1); diff --git a/package.json b/package.json index 7e8979a2f..159881deb 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,12 @@ { "name": "lodash-es", - "version": "4.11.2", + "version": "4.12.0", "description": "Lodash exported as ES modules.", "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", "bugs": "https://github.com/lodash/lodash-cli/issues", "repository": "lodash/lodash", "license": "MIT", - "private": true, "jsnext:main": "lodash.js", "main": "lodash.js", "author": "John-David Dalton (http://allyoucanleet.com/)", diff --git a/partial.js b/partial.js index a7789fe8e..9a5db5500 100644 --- a/partial.js +++ b/partial.js @@ -1,5 +1,5 @@ import createWrapper from './_createWrapper'; -import getPlaceholder from './_getPlaceholder'; +import getHolder from './_getHolder'; import replaceHolders from './_replaceHolders'; import rest from './rest'; @@ -40,7 +40,7 @@ var PARTIAL_FLAG = 32; * // => 'hi fred' */ var partial = rest(function(func, partials) { - var holders = replaceHolders(partials, getPlaceholder(partial)); + var holders = replaceHolders(partials, getHolder(partial)); return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders); }); diff --git a/partialRight.js b/partialRight.js index 0d1b9e975..9401e7e9c 100644 --- a/partialRight.js +++ b/partialRight.js @@ -1,5 +1,5 @@ import createWrapper from './_createWrapper'; -import getPlaceholder from './_getPlaceholder'; +import getHolder from './_getHolder'; import replaceHolders from './_replaceHolders'; import rest from './rest'; @@ -39,7 +39,7 @@ var PARTIAL_RIGHT_FLAG = 64; * // => 'hello fred' */ var partialRight = rest(function(func, partials) { - var holders = replaceHolders(partials, getPlaceholder(partialRight)); + var holders = replaceHolders(partials, getHolder(partialRight)); return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); }); diff --git a/property.js b/property.js index b7cc87595..381ddfc94 100644 --- a/property.js +++ b/property.js @@ -11,7 +11,7 @@ import toKey from './_toKey'; * @since 2.4.0 * @category Util * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new accessor function. * @example * * var objects = [ diff --git a/propertyOf.js b/propertyOf.js index 0be962a7e..8011aeec4 100644 --- a/propertyOf.js +++ b/propertyOf.js @@ -9,7 +9,7 @@ import baseGet from './_baseGet'; * @since 3.0.0 * @category Util * @param {Object} object The object to query. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new accessor function. * @example * * var array = [0, 1, 2], diff --git a/range.js b/range.js index cafc6e1b9..e266bd277 100644 --- a/range.js +++ b/range.js @@ -16,7 +16,7 @@ import createRange from './_createRange'; * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns the new array of numbers. + * @returns {Array} Returns the range of numbers. * @see _.inRange, _.rangeRight * @example * diff --git a/rangeRight.js b/rangeRight.js index 8cf15d0a5..f9707966d 100644 --- a/rangeRight.js +++ b/rangeRight.js @@ -11,7 +11,7 @@ import createRange from './_createRange'; * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns the new array of numbers. + * @returns {Array} Returns the range of numbers. * @see _.inRange, _.range * @example * diff --git a/split.js b/split.js index ca8195406..14ad5392b 100644 --- a/split.js +++ b/split.js @@ -28,7 +28,7 @@ var nativeSplit = stringProto.split; * @param {string} [string=''] The string to split. * @param {RegExp|string} separator The separator pattern to split by. * @param {number} [limit] The length to truncate results to. - * @returns {Array} Returns the new array of string segments. + * @returns {Array} Returns the string segments. * @example * * _.split('a-b-c', '-', 2); diff --git a/template.js b/template.js index 9c69aa210..2a70593eb 100644 --- a/template.js +++ b/template.js @@ -91,12 +91,6 @@ var reUnescapedString = /['\n\r\u2028\u2029\\]/g; * compiled({ 'user': 'pebbles' }); * // => 'hello pebbles!' * - * // Use custom template delimiters. - * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; - * var compiled = _.template('hello {{ user }}!'); - * compiled({ 'user': 'mustache' }); - * // => 'hello mustache!' - * * // Use backslashes to treat delimiters as plain text. * var compiled = _.template('<%= "\\<%- value %\\>" %>'); * compiled({ 'value': 'ignored' }); @@ -122,9 +116,15 @@ var reUnescapedString = /['\n\r\u2028\u2029\\]/g; * // return __p; * // } * + * // Use custom template delimiters. + * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; + * var compiled = _.template('hello {{ user }}!'); + * compiled({ 'user': 'mustache' }); + * // => 'hello mustache!' + * * // Use the `source` property to inline compiled templates for meaningful * // line numbers in error messages and stack traces. - * fs.writeFileSync(path.join(cwd, 'jst.js'), '\ + * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\ * var JST = {\ * "main": ' + _.template(mainText).source + '\ * };\ diff --git a/toFinite.js b/toFinite.js new file mode 100644 index 000000000..d0e85b46a --- /dev/null +++ b/toFinite.js @@ -0,0 +1,42 @@ +import toNumber from './toNumber'; + +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0, + MAX_INTEGER = 1.7976931348623157e+308; + +/** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ +function toFinite(value) { + if (!value) { + return value === 0 ? value : 0; + } + value = toNumber(value); + if (value === INFINITY || value === -INFINITY) { + var sign = (value < 0 ? -1 : 1); + return sign * MAX_INTEGER; + } + return value === value ? value : 0; +} + +export default toFinite; diff --git a/toInteger.js b/toInteger.js index f563e03f2..1bb0c9f9b 100644 --- a/toInteger.js +++ b/toInteger.js @@ -1,8 +1,4 @@ -import toNumber from './toNumber'; - -/** Used as references for various `Number` constants. */ -var INFINITY = 1 / 0, - MAX_INTEGER = 1.7976931348623157e+308; +import toFinite from './toFinite'; /** * Converts `value` to an integer. @@ -18,7 +14,7 @@ var INFINITY = 1 / 0, * @returns {number} Returns the converted integer. * @example * - * _.toInteger(3); + * _.toInteger(3.2); * // => 3 * * _.toInteger(Number.MIN_VALUE); @@ -27,20 +23,14 @@ var INFINITY = 1 / 0, * _.toInteger(Infinity); * // => 1.7976931348623157e+308 * - * _.toInteger('3'); + * _.toInteger('3.2'); * // => 3 */ function toInteger(value) { - if (!value) { - return value === 0 ? value : 0; - } - value = toNumber(value); - if (value === INFINITY || value === -INFINITY) { - var sign = (value < 0 ? -1 : 1); - return sign * MAX_INTEGER; - } - var remainder = value % 1; - return value === value ? (remainder ? value - remainder : value) : 0; + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; } export default toInteger; diff --git a/toLength.js b/toLength.js index 395cb5ae7..73a2e2ff9 100644 --- a/toLength.js +++ b/toLength.js @@ -19,7 +19,7 @@ var MAX_ARRAY_LENGTH = 4294967295; * @returns {number} Returns the converted integer. * @example * - * _.toLength(3); + * _.toLength(3.2); * // => 3 * * _.toLength(Number.MIN_VALUE); @@ -28,7 +28,7 @@ var MAX_ARRAY_LENGTH = 4294967295; * _.toLength(Infinity); * // => 4294967295 * - * _.toLength('3'); + * _.toLength('3.2'); * // => 3 */ function toLength(value) { diff --git a/toNumber.js b/toNumber.js index 5917c9d99..4ce009e64 100644 --- a/toNumber.js +++ b/toNumber.js @@ -31,8 +31,8 @@ var freeParseInt = parseInt; * @returns {number} Returns the number. * @example * - * _.toNumber(3); - * // => 3 + * _.toNumber(3.2); + * // => 3.2 * * _.toNumber(Number.MIN_VALUE); * // => 5e-324 @@ -40,8 +40,8 @@ var freeParseInt = parseInt; * _.toNumber(Infinity); * // => Infinity * - * _.toNumber('3'); - * // => 3 + * _.toNumber('3.2'); + * // => 3.2 */ function toNumber(value) { if (typeof value == 'number') { diff --git a/toPairs.js b/toPairs.js index 2fe0d05ed..434d03999 100644 --- a/toPairs.js +++ b/toPairs.js @@ -1,9 +1,10 @@ -import baseToPairs from './_baseToPairs'; +import createToPairs from './_createToPairs'; import keys from './keys'; /** * Creates an array of own enumerable string keyed-value pairs for `object` - * which can be consumed by `_.fromPairs`. + * which can be consumed by `_.fromPairs`. If `object` is a map or set, its + * entries are returned. * * @static * @memberOf _ @@ -11,7 +12,7 @@ import keys from './keys'; * @alias entries * @category Object * @param {Object} object The object to query. - * @returns {Array} Returns the new array of key-value pairs. + * @returns {Array} Returns the key-value pairs. * @example * * function Foo() { @@ -24,8 +25,6 @@ import keys from './keys'; * _.toPairs(new Foo); * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) */ -function toPairs(object) { - return baseToPairs(object, keys(object)); -} +var toPairs = createToPairs(keys); export default toPairs; diff --git a/toPairsIn.js b/toPairsIn.js index dad440d07..d0a2ed4d5 100644 --- a/toPairsIn.js +++ b/toPairsIn.js @@ -1,9 +1,10 @@ -import baseToPairs from './_baseToPairs'; +import createToPairs from './_createToPairs'; import keysIn from './keysIn'; /** * Creates an array of own and inherited enumerable string keyed-value pairs - * for `object` which can be consumed by `_.fromPairs`. + * for `object` which can be consumed by `_.fromPairs`. If `object` is a map + * or set, its entries are returned. * * @static * @memberOf _ @@ -11,7 +12,7 @@ import keysIn from './keysIn'; * @alias entriesIn * @category Object * @param {Object} object The object to query. - * @returns {Array} Returns the new array of key-value pairs. + * @returns {Array} Returns the key-value pairs. * @example * * function Foo() { @@ -22,10 +23,8 @@ import keysIn from './keysIn'; * Foo.prototype.c = 3; * * _.toPairsIn(new Foo); - * // => [['a', 1], ['b', 2], ['c', 1]] (iteration order is not guaranteed) + * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) */ -function toPairsIn(object) { - return baseToPairs(object, keysIn(object)); -} +var toPairsIn = createToPairs(keysIn); export default toPairsIn; diff --git a/toSafeInteger.js b/toSafeInteger.js index f333275cc..88cc90651 100644 --- a/toSafeInteger.js +++ b/toSafeInteger.js @@ -16,7 +16,7 @@ var MAX_SAFE_INTEGER = 9007199254740991; * @returns {number} Returns the converted integer. * @example * - * _.toSafeInteger(3); + * _.toSafeInteger(3.2); * // => 3 * * _.toSafeInteger(Number.MIN_VALUE); @@ -25,7 +25,7 @@ var MAX_SAFE_INTEGER = 9007199254740991; * _.toSafeInteger(Infinity); * // => 9007199254740991 * - * _.toSafeInteger('3'); + * _.toSafeInteger('3.2'); * // => 3 */ function toSafeInteger(value) { diff --git a/unary.js b/unary.js index 8d6c946d9..d8dd210c9 100644 --- a/unary.js +++ b/unary.js @@ -9,7 +9,7 @@ import ary from './ary'; * @since 4.0.0 * @category Function * @param {Function} func The function to cap arguments for. - * @returns {Function} Returns the new function. + * @returns {Function} Returns the new capped function. * @example * * _.map(['6', '8', '10'], _.unary(parseInt)); diff --git a/without.js b/without.js index fa222fe6b..055bbdf3b 100644 --- a/without.js +++ b/without.js @@ -11,7 +11,7 @@ import rest from './rest'; * @memberOf _ * @since 0.1.0 * @category Array - * @param {Array} array The array to filter. + * @param {Array} array The array to inspect. * @param {...*} [values] The values to exclude. * @returns {Array} Returns the new array of filtered values. * @see _.difference, _.xor diff --git a/wrapperLodash.js b/wrapperLodash.js index f45f42894..838eac692 100644 --- a/wrapperLodash.js +++ b/wrapperLodash.js @@ -83,10 +83,10 @@ var hasOwnProperty = objectProto.hasOwnProperty; * `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`, + * `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`, @@ -95,9 +95,9 @@ var hasOwnProperty = objectProto.hasOwnProperty; * `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`, + * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toFinite`, + * `toInteger`, `toJSON`, `toLength`, `toLower`, `toNumber`, `toSafeInteger`, + * `toString`, `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, * `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words` * * @name _ diff --git a/xor.js b/xor.js index e2e84f64d..0c9aafa8e 100644 --- a/xor.js +++ b/xor.js @@ -14,7 +14,7 @@ import rest from './rest'; * @since 2.4.0 * @category Array * @param {...Array} [arrays] The arrays to inspect. - * @returns {Array} Returns the new array of values. + * @returns {Array} Returns the new array of filtered values. * @see _.difference, _.without * @example * diff --git a/xorBy.js b/xorBy.js index 15e2c400a..51047f0ca 100644 --- a/xorBy.js +++ b/xorBy.js @@ -18,7 +18,7 @@ import rest from './rest'; * @param {...Array} [arrays] The arrays to inspect. * @param {Array|Function|Object|string} [iteratee=_.identity] * The iteratee invoked per element. - * @returns {Array} Returns the new array of values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor); diff --git a/xorWith.js b/xorWith.js index 1c5bc4f78..92dcd4e5e 100644 --- a/xorWith.js +++ b/xorWith.js @@ -15,7 +15,7 @@ import rest from './rest'; * @category Array * @param {...Array} [arrays] The arrays to inspect. * @param {Function} [comparator] The comparator invoked per element. - * @returns {Array} Returns the new array of values. + * @returns {Array} Returns the new array of filtered values. * @example * * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];