From 26837e7fe2cca48cd04d9875991320b4a71f706d Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 16 Dec 2015 17:50:05 -0800 Subject: [PATCH] Bump to v3.8.0. --- README.md | 6 +- array.js | 6 +- array/difference.js | 11 +- array/indexOf.js | 11 +- array/intersection.js | 11 +- array/pull.js | 11 +- array/pullAt.js | 1 - array/union.js | 7 +- array/uniq.js | 9 +- array/unzip.js | 20 +- array/unzipWith.js | 42 ++++ array/without.js | 13 +- array/xor.js | 4 +- array/zipWith.js | 39 +++ collection/at.js | 6 +- collection/includes.js | 11 +- collection/invoke.js | 5 +- collection/map.js | 9 +- collection/reduceRight.js | 2 +- collection/reject.js | 11 - internal/baseAssign.js | 21 +- internal/baseAt.js | 9 +- internal/baseFlatten.js | 11 +- internal/baseGet.js | 4 +- internal/baseIsEqual.js | 3 +- internal/baseMap.js | 5 +- internal/baseMerge.js | 4 +- internal/baseMergeDeep.js | 6 +- internal/basePullAt.js | 2 +- internal/binaryIndexBy.js | 2 +- internal/composeArgsRight.js | 6 +- internal/createFind.js | 2 +- internal/createFlow.js | 8 +- internal/createObjectMapper.js | 26 ++ internal/createPadDir.js | 2 +- internal/equalByTag.js | 3 +- internal/getLength.js | 2 +- internal/isArrayLike.js | 15 ++ internal/isIterateeCall.js | 12 +- internal/isKey.js | 2 +- internal/isStrictComparable.js | 2 +- internal/pickByArray.js | 2 +- internal/pickByCallback.js | 2 +- internal/toIterable.js | 4 +- lang/isArguments.js | 8 +- lang/isEmpty.js | 7 +- lang/isRegExp.js | 2 +- main.js | 440 ++++++++++++++++++--------------- object.js | 3 +- object/assign.js | 1 - object/keys.js | 9 +- object/mapKeys.js | 26 ++ object/mapValues.js | 12 +- object/omit.js | 5 - package.json | 2 +- support.js | 3 +- utility/callback.js | 6 +- utility/method.js | 2 +- 58 files changed, 531 insertions(+), 385 deletions(-) create mode 100644 array/unzipWith.js create mode 100644 array/zipWith.js create mode 100644 internal/createObjectMapper.js create mode 100644 internal/isArrayLike.js create mode 100644 object/mapKeys.js diff --git a/README.md b/README.md index 5907769d5..794572525 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash v3.7.0 +# lodash v3.8.0 The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. @@ -13,8 +13,8 @@ $ lodash modern exports=amd -d -o ./main.js Using bower or volo: ```bash -$ bower i lodash#3.7.0-amd -$ volo add lodash/3.7.0-amd +$ bower i lodash#3.8.0-amd +$ volo add lodash/3.8.0-amd ``` Defining a build as `'lodash'`. diff --git a/array.js b/array.js index 460fc4ba9..b3953a6c8 100644 --- a/array.js +++ b/array.js @@ -1,4 +1,4 @@ -define(['./array/chunk', './array/compact', './array/difference', './array/drop', './array/dropRight', './array/dropRightWhile', './array/dropWhile', './array/fill', './array/findIndex', './array/findLastIndex', './array/first', './array/flatten', './array/flattenDeep', './array/head', './array/indexOf', './array/initial', './array/intersection', './array/last', './array/lastIndexOf', './array/object', './array/pull', './array/pullAt', './array/remove', './array/rest', './array/slice', './array/sortedIndex', './array/sortedLastIndex', './array/tail', './array/take', './array/takeRight', './array/takeRightWhile', './array/takeWhile', './array/union', './array/uniq', './array/unique', './array/unzip', './array/without', './array/xor', './array/zip', './array/zipObject'], function(chunk, compact, difference, drop, dropRight, dropRightWhile, dropWhile, fill, findIndex, findLastIndex, first, flatten, flattenDeep, head, indexOf, initial, intersection, last, lastIndexOf, object, pull, pullAt, remove, rest, slice, sortedIndex, sortedLastIndex, tail, take, takeRight, takeRightWhile, takeWhile, union, uniq, unique, unzip, without, xor, zip, zipObject) { +define(['./array/chunk', './array/compact', './array/difference', './array/drop', './array/dropRight', './array/dropRightWhile', './array/dropWhile', './array/fill', './array/findIndex', './array/findLastIndex', './array/first', './array/flatten', './array/flattenDeep', './array/head', './array/indexOf', './array/initial', './array/intersection', './array/last', './array/lastIndexOf', './array/object', './array/pull', './array/pullAt', './array/remove', './array/rest', './array/slice', './array/sortedIndex', './array/sortedLastIndex', './array/tail', './array/take', './array/takeRight', './array/takeRightWhile', './array/takeWhile', './array/union', './array/uniq', './array/unique', './array/unzip', './array/unzipWith', './array/without', './array/xor', './array/zip', './array/zipObject', './array/zipWith'], function(chunk, compact, difference, drop, dropRight, dropRightWhile, dropWhile, fill, findIndex, findLastIndex, first, flatten, flattenDeep, head, indexOf, initial, intersection, last, lastIndexOf, object, pull, pullAt, remove, rest, slice, sortedIndex, sortedLastIndex, tail, take, takeRight, takeRightWhile, takeWhile, union, uniq, unique, unzip, unzipWith, without, xor, zip, zipObject, zipWith) { return { 'chunk': chunk, 'compact': compact, @@ -36,9 +36,11 @@ define(['./array/chunk', './array/compact', './array/difference', './array/drop' 'uniq': uniq, 'unique': unique, 'unzip': unzip, + 'unzipWith': unzipWith, 'without': without, 'xor': xor, 'zip': zip, - 'zipObject': zipObject + 'zipObject': zipObject, + 'zipWith': zipWith }; }); diff --git a/array/difference.js b/array/difference.js index 073c5a9cf..b8dc353ac 100644 --- a/array/difference.js +++ b/array/difference.js @@ -1,12 +1,9 @@ -define(['../internal/baseDifference', '../internal/baseFlatten', '../lang/isArguments', '../lang/isArray', '../function/restParam'], function(baseDifference, baseFlatten, isArguments, isArray, restParam) { +define(['../internal/baseDifference', '../internal/baseFlatten', '../internal/isArrayLike', '../function/restParam'], function(baseDifference, baseFlatten, isArrayLike, restParam) { /** * Creates an array excluding all values of the provided arrays using - * `SameValueZero` for equality comparisons. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * * @static * @memberOf _ @@ -20,7 +17,7 @@ define(['../internal/baseDifference', '../internal/baseFlatten', '../lang/isArgu * // => [1, 3] */ var difference = restParam(function(array, values) { - return (isArray(array) || isArguments(array)) + return isArrayLike(array) ? baseDifference(array, baseFlatten(values, false, true)) : []; }); diff --git a/array/indexOf.js b/array/indexOf.js index af8c09ac9..763e2d8d7 100644 --- a/array/indexOf.js +++ b/array/indexOf.js @@ -5,13 +5,10 @@ define(['../internal/baseIndexOf', '../internal/binaryIndex'], function(baseInde /** * Gets the index at which the first occurrence of `value` is found in `array` - * using `SameValueZero` for equality comparisons. If `fromIndex` is negative, - * it is used as the offset from the end of `array`. If `array` is sorted - * providing `true` for `fromIndex` performs a faster binary search. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it is used as the offset + * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` + * performs a faster binary search. * * @static * @memberOf _ diff --git a/array/intersection.js b/array/intersection.js index f4c3633b1..4f3213f9d 100644 --- a/array/intersection.js +++ b/array/intersection.js @@ -1,13 +1,10 @@ -define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/createCache', '../lang/isArguments', '../lang/isArray'], function(baseIndexOf, cacheIndexOf, createCache, isArguments, isArray) { +define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/createCache', '../internal/isArrayLike'], function(baseIndexOf, cacheIndexOf, createCache, isArrayLike) { /** - * Creates an array of unique values in all provided arrays using `SameValueZero` + * Creates an array of unique values in all provided arrays using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) * for equality comparisons. * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. - * * @static * @memberOf _ * @category Array @@ -28,7 +25,7 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea while (++argsIndex < argsLength) { var value = arguments[argsIndex]; - if (isArray(value) || isArguments(value)) { + if (isArrayLike(value)) { args.push(value); caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null); } diff --git a/array/pull.js b/array/pull.js index 3ae67b26a..ed0af99e4 100644 --- a/array/pull.js +++ b/array/pull.js @@ -7,14 +7,11 @@ define(['../internal/baseIndexOf'], function(baseIndexOf) { var splice = arrayProto.splice; /** - * Removes all provided values from `array` using `SameValueZero` for equality - * comparisons. + * Removes all provided values from `array` using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * - * **Notes:** - * - Unlike `_.without`, this method mutates `array` - * - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except - * that `NaN` matches `NaN` + * **Note:** Unlike `_.without`, this method mutates `array`. * * @static * @memberOf _ diff --git a/array/pullAt.js b/array/pullAt.js index 837ee4410..c368261c7 100644 --- a/array/pullAt.js +++ b/array/pullAt.js @@ -26,7 +26,6 @@ define(['../internal/baseAt', '../internal/baseCompareAscending', '../internal/b * // => [10, 20] */ var pullAt = restParam(function(array, indexes) { - array || (array = []); indexes = baseFlatten(indexes); var result = baseAt(array, indexes); diff --git a/array/union.js b/array/union.js index 74ba1e47e..c55bcd44f 100644 --- a/array/union.js +++ b/array/union.js @@ -2,11 +2,8 @@ define(['../internal/baseFlatten', '../internal/baseUniq', '../function/restPara /** * Creates an array of unique values, in order, of the provided arrays using - * `SameValueZero` for equality comparisons. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * * @static * @memberOf _ diff --git a/array/uniq.js b/array/uniq.js index 554599168..1e2dd27f9 100644 --- a/array/uniq.js +++ b/array/uniq.js @@ -1,8 +1,9 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isIterateeCall', '../internal/sortedUniq'], function(baseCallback, baseUniq, isIterateeCall, sortedUniq) { /** - * Creates a duplicate-free version of an array, using `SameValueZero` for - * equality comparisons, in which only the first occurence of each element + * Creates a duplicate-free version of an array, using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons, in which only the first occurence of each element * is kept. Providing `true` for `isSorted` performs a faster search algorithm * for sorted arrays. If an iteratee function is provided it is invoked for * each element in the array to generate the criterion by which uniqueness @@ -20,10 +21,6 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera * callback returns `true` for elements that have the properties of the given * object, else `false`. * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. - * * @static * @memberOf _ * @alias unique diff --git a/array/unzip.js b/array/unzip.js index 2fe376397..de8e39f93 100644 --- a/array/unzip.js +++ b/array/unzip.js @@ -1,8 +1,11 @@ -define(['../internal/arrayMap', '../internal/arrayMax', '../internal/baseProperty', '../internal/getLength'], function(arrayMap, arrayMax, baseProperty, getLength) { +define(['../internal/arrayFilter', '../internal/arrayMap', '../internal/baseProperty', '../internal/isArrayLike'], function(arrayFilter, arrayMap, baseProperty, isArrayLike) { + + /* Native method references for those with the same name as other `lodash` methods. */ + var nativeMax = Math.max; /** * This method is like `_.zip` except that it accepts an array of grouped - * elements and creates an array regrouping the elements to their pre-`_.zip` + * elements and creates an array regrouping the elements to their pre-zip * configuration. * * @static @@ -19,10 +22,19 @@ define(['../internal/arrayMap', '../internal/arrayMax', '../internal/basePropert * // => [['fred', 'barney'], [30, 40], [true, false]] */ function unzip(array) { + if (!(array && array.length)) { + return []; + } var index = -1, - length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0, - result = Array(length); + length = 0; + array = arrayFilter(array, function(group) { + if (isArrayLike(group)) { + length = nativeMax(group.length, length); + return true; + } + }); + var result = Array(length); while (++index < length) { result[index] = arrayMap(array, baseProperty(index)); } diff --git a/array/unzipWith.js b/array/unzipWith.js new file mode 100644 index 000000000..fb521815b --- /dev/null +++ b/array/unzipWith.js @@ -0,0 +1,42 @@ +define(['../internal/arrayMap', '../internal/arrayReduce', '../internal/bindCallback', './unzip'], function(arrayMap, arrayReduce, bindCallback, unzip) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * This method is like `_.unzip` except that it accepts an iteratee to specify + * how regrouped values should be combined. The `iteratee` is bound to `thisArg` + * and invoked with four arguments: (accumulator, value, index, group). + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array of grouped elements to process. + * @param {Function} [iteratee] The function to combine regrouped values. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * var zipped = _.zip([1, 2], [10, 20], [100, 200]); + * // => [[1, 10, 100], [2, 20, 200]] + * + * _.unzipWith(zipped, _.add); + * // => [3, 30, 300] + */ + function unzipWith(array, iteratee, thisArg) { + var length = array ? array.length : 0; + if (!length) { + return []; + } + var result = unzip(array); + if (iteratee == null) { + return result; + } + iteratee = bindCallback(iteratee, thisArg, 4); + return arrayMap(result, function(group) { + return arrayReduce(group, iteratee, undefined, true); + }); + } + + return unzipWith; +}); diff --git a/array/without.js b/array/without.js index 743b8952f..1c55b87dd 100644 --- a/array/without.js +++ b/array/without.js @@ -1,12 +1,9 @@ -define(['../internal/baseDifference', '../lang/isArguments', '../lang/isArray', '../function/restParam'], function(baseDifference, isArguments, isArray, restParam) { +define(['../internal/baseDifference', '../internal/isArrayLike', '../function/restParam'], function(baseDifference, isArrayLike, restParam) { /** - * Creates an array excluding all provided values using `SameValueZero` for - * equality comparisons. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * Creates an array excluding all provided values using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * * @static * @memberOf _ @@ -20,7 +17,7 @@ define(['../internal/baseDifference', '../lang/isArguments', '../lang/isArray', * // => [3] */ var without = restParam(function(array, values) { - return (isArray(array) || isArguments(array)) + return isArrayLike(array) ? baseDifference(array, values) : []; }); diff --git a/array/xor.js b/array/xor.js index bb25427d2..9cd790caf 100644 --- a/array/xor.js +++ b/array/xor.js @@ -1,4 +1,4 @@ -define(['../internal/baseDifference', '../internal/baseUniq', '../lang/isArguments', '../lang/isArray'], function(baseDifference, baseUniq, isArguments, isArray) { +define(['../internal/baseDifference', '../internal/baseUniq', '../internal/isArrayLike'], function(baseDifference, baseUniq, isArrayLike) { /** * Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) @@ -20,7 +20,7 @@ define(['../internal/baseDifference', '../internal/baseUniq', '../lang/isArgumen while (++index < length) { var array = arguments[index]; - if (isArray(array) || isArguments(array)) { + if (isArrayLike(array)) { var result = result ? baseDifference(result, array).concat(baseDifference(array, result)) : array; diff --git a/array/zipWith.js b/array/zipWith.js new file mode 100644 index 000000000..914e4a88c --- /dev/null +++ b/array/zipWith.js @@ -0,0 +1,39 @@ +define(['../function/restParam', './unzipWith'], function(restParam, unzipWith) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * This method is like `_.zip` except that it accepts an iteratee to specify + * how grouped values should be combined. The `iteratee` is bound to `thisArg` + * and invoked with four arguments: (accumulator, value, index, group). + * + * @static + * @memberOf _ + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @param {Function} [iteratee] The function to combine grouped values. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Array} Returns the new array of grouped elements. + * @example + * + * _.zipWith([1, 2], [10, 20], [100, 200], _.add); + * // => [111, 222] + */ + var zipWith = restParam(function(arrays) { + var length = arrays.length, + iteratee = arrays[length - 2], + thisArg = arrays[length - 1]; + + if (length > 2 && typeof iteratee == 'function') { + length -= 2; + } else { + iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined; + thisArg = undefined; + } + arrays.length = length; + return unzipWith(arrays, iteratee, thisArg); + }); + + return zipWith; +}); diff --git a/collection/at.js b/collection/at.js index 8436c8f4e..1c4215bd0 100644 --- a/collection/at.js +++ b/collection/at.js @@ -1,4 +1,4 @@ -define(['../internal/baseAt', '../internal/baseFlatten', '../internal/getLength', '../internal/isLength', '../function/restParam', '../internal/toIterable'], function(baseAt, baseFlatten, getLength, isLength, restParam, toIterable) { +define(['../internal/baseAt', '../internal/baseFlatten', '../function/restParam'], function(baseAt, baseFlatten, restParam) { /** * Creates an array of elements corresponding to the given keys, or indexes, @@ -21,10 +21,6 @@ define(['../internal/baseAt', '../internal/baseFlatten', '../internal/getLength' * // => ['barney', 'pebbles'] */ var at = restParam(function(collection, props) { - var length = collection ? getLength(collection) : 0; - if (isLength(length)) { - collection = toIterable(collection); - } return baseAt(collection, baseFlatten(props)); }); diff --git a/collection/includes.js b/collection/includes.js index 76b28c6ee..cf77f0ea6 100644 --- a/collection/includes.js +++ b/collection/includes.js @@ -4,13 +4,10 @@ define(['../internal/baseIndexOf', '../internal/getLength', '../lang/isArray', ' var nativeMax = Math.max; /** - * Checks if `value` is in `collection` using `SameValueZero` for equality - * comparisons. If `fromIndex` is negative, it is used as the offset from - * the end of `collection`. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * Checks if `value` is in `collection` using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it is used as the offset + * from the end of `collection`. * * @static * @memberOf _ diff --git a/collection/invoke.js b/collection/invoke.js index 6ae2abd1b..06c0d41d6 100644 --- a/collection/invoke.js +++ b/collection/invoke.js @@ -1,4 +1,4 @@ -define(['../internal/baseEach', '../internal/getLength', '../internal/invokePath', '../internal/isKey', '../internal/isLength', '../function/restParam'], function(baseEach, getLength, invokePath, isKey, isLength, restParam) { +define(['../internal/baseEach', '../internal/invokePath', '../internal/isArrayLike', '../internal/isKey', '../function/restParam'], function(baseEach, invokePath, isArrayLike, isKey, restParam) { /** * Invokes the method at `path` on each element in `collection`, returning @@ -26,8 +26,7 @@ define(['../internal/baseEach', '../internal/getLength', '../internal/invokePath var index = -1, isFunc = typeof path == 'function', isProp = isKey(path), - length = getLength(collection), - result = isLength(length) ? Array(length) : []; + result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value) { var func = isFunc ? path : (isProp && value != null && value[path]); diff --git a/collection/map.js b/collection/map.js index dfebf9f6c..144e398bb 100644 --- a/collection/map.js +++ b/collection/map.js @@ -20,10 +20,11 @@ define(['../internal/arrayMap', '../internal/baseCallback', '../internal/baseMap * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. * * The guarded methods are: - * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`, - * `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, - * `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, - * `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words` + * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, + * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, + * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, + * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, + * `sum`, `uniq`, and `words` * * @static * @memberOf _ diff --git a/collection/reduceRight.js b/collection/reduceRight.js index 4af771384..9d695af5c 100644 --- a/collection/reduceRight.js +++ b/collection/reduceRight.js @@ -22,7 +22,7 @@ define(['../internal/arrayReduceRight', '../internal/baseEachRight', '../interna * }, []); * // => [4, 5, 2, 3, 0, 1] */ - var reduceRight = createReduce(arrayReduceRight, baseEachRight); + var reduceRight = createReduce(arrayReduceRight, baseEachRight); return reduceRight; }); diff --git a/collection/reject.js b/collection/reject.js index c0d8cab92..e94a1996c 100644 --- a/collection/reject.js +++ b/collection/reject.js @@ -4,17 +4,6 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base * The opposite of `_.filter`; this method returns the elements of `collection` * that `predicate` does **not** return truthy for. * - * If a property name is provided for `predicate` the created `_.property` - * style callback returns the property value of the given element. - * - * If a value is also provided for `thisArg` the created `_.matchesProperty` - * style callback returns `true` for elements that have a matching property - * value, else `false`. - * - * If an object is provided for `predicate` the created `_.matches` style - * callback returns `true` for elements that have the properties of the given - * object, else `false`. - * * @static * @memberOf _ * @category Collection diff --git a/internal/baseAssign.js b/internal/baseAssign.js index 94814d90b..1271600dc 100644 --- a/internal/baseAssign.js +++ b/internal/baseAssign.js @@ -1,7 +1,7 @@ define(['./baseCopy', './getSymbols', '../lang/isNative', '../object/keys'], function(baseCopy, getSymbols, isNative, keys) { /** Native method references. */ - var preventExtensions = isNative(Object.preventExtensions = Object.preventExtensions) && preventExtensions; + var preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions; /** Used as `baseAssign`. */ var nativeAssign = (function() { @@ -11,12 +11,19 @@ define(['./baseCopy', './getSymbols', '../lang/isNative', '../object/keys'], fun // // Use `Object.preventExtensions` on a plain object instead of simply using // `Object('x')` because Chrome and IE fail to throw an error when attempting - // to assign values to readonly indexes of strings in strict mode. - var object = { '1': 0 }, - func = preventExtensions && isNative(func = Object.assign) && func; - - try { func(preventExtensions(object), 'xo'); } catch(e) {} - return !object[1] && func; + // to assign values to readonly indexes of strings. + var func = preventExtensions && isNative(func = Object.assign) && func; + try { + if (func) { + var object = preventExtensions({ '1': 0 }); + object[0] = 1; + } + } catch(e) { + // Only attempt in strict mode. + try { func(object, 'xo'); } catch(e) {} + return !object[1] && func; + } + return false; }()); /** diff --git a/internal/baseAt.js b/internal/baseAt.js index 33f58c36d..ccad82974 100644 --- a/internal/baseAt.js +++ b/internal/baseAt.js @@ -1,4 +1,4 @@ -define(['./isIndex', './isLength'], function(isIndex, isLength) { +define(['./isArrayLike', './isIndex'], function(isArrayLike, isIndex) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -14,8 +14,9 @@ define(['./isIndex', './isLength'], function(isIndex, isLength) { */ function baseAt(collection, props) { var index = -1, - length = collection.length, - isArr = isLength(length), + isNil = collection == null, + isArr = !isNil && isArrayLike(collection), + length = isArr && collection.length, propsLength = props.length, result = Array(propsLength); @@ -24,7 +25,7 @@ define(['./isIndex', './isLength'], function(isIndex, isLength) { if (isArr) { result[index] = isIndex(key, length) ? collection[key] : undefined; } else { - result[index] = collection[key]; + result[index] = isNil ? undefined : collection[key]; } } return result; diff --git a/internal/baseFlatten.js b/internal/baseFlatten.js index 6e57dcb14..f1ef6d84f 100644 --- a/internal/baseFlatten.js +++ b/internal/baseFlatten.js @@ -1,4 +1,4 @@ -define(['../lang/isArguments', '../lang/isArray', './isLength', './isObjectLike'], function(isArguments, isArray, isLength, isObjectLike) { +define(['../lang/isArguments', '../lang/isArray', './isArrayLike', './isObjectLike'], function(isArguments, isArray, isArrayLike, isObjectLike) { /** * The base implementation of `_.flatten` with added support for restricting @@ -6,8 +6,8 @@ define(['../lang/isArguments', '../lang/isArray', './isLength', './isObjectLike' * * @private * @param {Array} array The array to flatten. - * @param {boolean} isDeep Specify a deep flatten. - * @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects. + * @param {boolean} [isDeep] Specify a deep flatten. + * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, isDeep, isStrict) { @@ -18,8 +18,8 @@ define(['../lang/isArguments', '../lang/isArray', './isLength', './isObjectLike' while (++index < length) { var value = array[index]; - - if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) { + if (isObjectLike(value) && isArrayLike(value) && + (isStrict || isArray(value) || isArguments(value))) { if (isDeep) { // Recursively flatten arrays (susceptible to call stack limits). value = baseFlatten(value, isDeep, isStrict); @@ -27,7 +27,6 @@ define(['../lang/isArguments', '../lang/isArray', './isLength', './isObjectLike' var valIndex = -1, valLength = value.length; - result.length += valLength; while (++valIndex < valLength) { result[++resIndex] = value[valIndex]; } diff --git a/internal/baseGet.js b/internal/baseGet.js index 589b137d5..118171720 100644 --- a/internal/baseGet.js +++ b/internal/baseGet.js @@ -24,9 +24,9 @@ define(['./toObject'], function(toObject) { length = path.length; while (object != null && ++index < length) { - var result = object = object[path[index]]; + object = object[path[index]]; } - return result; + return (index && index == length) ? object : undefined; } return baseGet; diff --git a/internal/baseIsEqual.js b/internal/baseIsEqual.js index 67c930cf4..295eba677 100644 --- a/internal/baseIsEqual.js +++ b/internal/baseIsEqual.js @@ -16,8 +16,7 @@ define(['./baseIsEqualDeep'], function(baseIsEqualDeep) { function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) { // Exit early for identical values. if (value === other) { - // Treat `+0` vs. `-0` as not equal. - return value !== 0 || (1 / value == 1 / other); + return true; } var valType = typeof value, othType = typeof other; diff --git a/internal/baseMap.js b/internal/baseMap.js index 1d5a6a00d..98f547bfa 100644 --- a/internal/baseMap.js +++ b/internal/baseMap.js @@ -1,4 +1,4 @@ -define(['./baseEach', './getLength', './isLength'], function(baseEach, getLength, isLength) { +define(['./baseEach', './isArrayLike'], function(baseEach, isArrayLike) { /** * The base implementation of `_.map` without support for callback shorthands @@ -11,8 +11,7 @@ define(['./baseEach', './getLength', './isLength'], function(baseEach, getLength */ function baseMap(collection, iteratee) { var index = -1, - length = getLength(collection), - result = isLength(length) ? Array(length) : []; + result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value, key, collection) { result[++index] = iteratee(value, key, collection); diff --git a/internal/baseMerge.js b/internal/baseMerge.js index 6b72ba847..91ab64ba9 100644 --- a/internal/baseMerge.js +++ b/internal/baseMerge.js @@ -1,4 +1,4 @@ -define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './isLength', '../lang/isObject', './isObjectLike', '../lang/isTypedArray', '../object/keys'], function(arrayEach, baseMergeDeep, getSymbols, isArray, isLength, isObject, isObjectLike, isTypedArray, keys) { +define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './isArrayLike', '../lang/isObject', './isObjectLike', '../lang/isTypedArray', '../object/keys'], function(arrayEach, baseMergeDeep, getSymbols, isArray, isArrayLike, isObject, isObjectLike, isTypedArray, keys) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -25,7 +25,7 @@ define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './ if (!isObject(object)) { return object; } - var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source)); + var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)); if (!isSrcArr) { var props = keys(source); push.apply(props, getSymbols(source)); diff --git a/internal/baseMergeDeep.js b/internal/baseMergeDeep.js index 9cb8faecb..d9d13921a 100644 --- a/internal/baseMergeDeep.js +++ b/internal/baseMergeDeep.js @@ -1,4 +1,4 @@ -define(['./arrayCopy', './getLength', '../lang/isArguments', '../lang/isArray', './isLength', '../lang/isPlainObject', '../lang/isTypedArray', '../lang/toPlainObject'], function(arrayCopy, getLength, isArguments, isArray, isLength, isPlainObject, isTypedArray, toPlainObject) { +define(['./arrayCopy', '../lang/isArguments', '../lang/isArray', './isArrayLike', '../lang/isPlainObject', '../lang/isTypedArray', '../lang/toPlainObject'], function(arrayCopy, isArguments, isArray, isArrayLike, isPlainObject, isTypedArray, toPlainObject) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -34,10 +34,10 @@ define(['./arrayCopy', './getLength', '../lang/isArguments', '../lang/isArray', if (isCommon) { result = srcValue; - if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) { + if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) { result = isArray(value) ? value - : (getLength(value) ? arrayCopy(value) : []); + : (isArrayLike(value) ? arrayCopy(value) : []); } else if (isPlainObject(srcValue) || isArguments(srcValue)) { result = isArguments(value) diff --git a/internal/basePullAt.js b/internal/basePullAt.js index 464467098..c5b6be4ca 100644 --- a/internal/basePullAt.js +++ b/internal/basePullAt.js @@ -16,7 +16,7 @@ define(['./isIndex'], function(isIndex) { * @returns {Array} Returns `array`. */ function basePullAt(array, indexes) { - var length = indexes.length; + var length = array ? indexes.length : 0; while (length--) { var index = parseFloat(indexes[length]); if (index != previous && isIndex(index)) { diff --git a/internal/binaryIndexBy.js b/internal/binaryIndexBy.js index 4bc5d450d..7b27ad368 100644 --- a/internal/binaryIndexBy.js +++ b/internal/binaryIndexBy.js @@ -11,7 +11,7 @@ define([], function() { /** Used as references for the maximum length and index of an array. */ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1, - MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1; + MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1; /** * This function is like `binaryIndex` except that it invokes `iteratee` for diff --git a/internal/composeArgsRight.js b/internal/composeArgsRight.js index 7c6d6d4ed..28dc476c6 100644 --- a/internal/composeArgsRight.js +++ b/internal/composeArgsRight.js @@ -25,12 +25,12 @@ define([], function() { while (++argsIndex < argsLength) { result[argsIndex] = args[argsIndex]; } - var pad = argsIndex; + var offset = argsIndex; while (++rightIndex < rightLength) { - result[pad + rightIndex] = partials[rightIndex]; + result[offset + rightIndex] = partials[rightIndex]; } while (++holdersIndex < holdersLength) { - result[pad + holders[holdersIndex]] = args[argsIndex++]; + result[offset + holders[holdersIndex]] = args[argsIndex++]; } return result; } diff --git a/internal/createFind.js b/internal/createFind.js index 770d4a3a1..86bcba49e 100644 --- a/internal/createFind.js +++ b/internal/createFind.js @@ -19,7 +19,7 @@ define(['./baseCallback', './baseFind', './baseFindIndex', '../lang/isArray'], f return index > -1 ? collection[index] : undefined; } return baseFind(collection, predicate, eachFunc); - } + }; } return createFind; diff --git a/internal/createFlow.js b/internal/createFlow.js index 70b2b46d1..27dbe1097 100644 --- a/internal/createFlow.js +++ b/internal/createFlow.js @@ -1,5 +1,11 @@ define(['./LodashWrapper', './getData', './getFuncName', '../lang/isArray', './isLaziable'], function(LodashWrapper, getData, getFuncName, isArray, isLaziable) { + /** Used to compose bitmasks for wrapper metadata. */ + var CURRY_FLAG = 8, + PARTIAL_FLAG = 32, + ARY_FLAG = 128, + REARG_FLAG = 256; + /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; @@ -35,7 +41,7 @@ define(['./LodashWrapper', './getData', './getFuncName', '../lang/isArray', './i funcName = getFuncName(func); var data = funcName == 'wrapper' ? getData(func) : null; - if (data && isLaziable(data[0])) { + if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) { wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); } else { wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); diff --git a/internal/createObjectMapper.js b/internal/createObjectMapper.js new file mode 100644 index 000000000..80e15f340 --- /dev/null +++ b/internal/createObjectMapper.js @@ -0,0 +1,26 @@ +define(['./baseCallback', './baseForOwn'], function(baseCallback, baseForOwn) { + + /** + * Creates a function for `_.mapKeys` or `_.mapValues`. + * + * @private + * @param {boolean} [isMapKeys] Specify mapping keys instead of values. + * @returns {Function} Returns the new map function. + */ + function createObjectMapper(isMapKeys) { + return function(object, iteratee, thisArg) { + var result = {}; + iteratee = baseCallback(iteratee, thisArg, 3); + + baseForOwn(object, function(value, key, object) { + var mapped = iteratee(value, key, object); + key = isMapKeys ? mapped : key; + value = isMapKeys ? value : mapped; + result[key] = value; + }); + return result; + }; + } + + return createObjectMapper; +}); diff --git a/internal/createPadDir.js b/internal/createPadDir.js index 2bcaecb2f..092fbcdef 100644 --- a/internal/createPadDir.js +++ b/internal/createPadDir.js @@ -10,7 +10,7 @@ define(['./baseToString', './createPadding'], function(baseToString, createPaddi function createPadDir(fromRight) { return function(string, length, chars) { string = baseToString(string); - return string && ((fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string)); + return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string); }; } diff --git a/internal/equalByTag.js b/internal/equalByTag.js index d6519e2df..8c01d1f16 100644 --- a/internal/equalByTag.js +++ b/internal/equalByTag.js @@ -36,8 +36,7 @@ define([], function() { // Treat `NaN` vs. `NaN` as equal. return (object != +object) ? other != +other - // But, treat `-0` vs. `+0` as not equal. - : (object == 0 ? ((1 / object) == (1 / other)) : object == +other); + : object == +other; case regexpTag: case stringTag: diff --git a/internal/getLength.js b/internal/getLength.js index e9b12ec71..e7dfddff5 100644 --- a/internal/getLength.js +++ b/internal/getLength.js @@ -4,7 +4,7 @@ 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) - * in Safari on iOS 8.1 ARM64. + * that affects Safari on at least iOS 8.1-8.3 ARM64. * * @private * @param {Object} object The object to query. diff --git a/internal/isArrayLike.js b/internal/isArrayLike.js new file mode 100644 index 000000000..6d79bd308 --- /dev/null +++ b/internal/isArrayLike.js @@ -0,0 +1,15 @@ +define(['./getLength', './isLength'], function(getLength, isLength) { + + /** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ + function isArrayLike(value) { + return value != null && isLength(getLength(value)); + } + + return isArrayLike; +}); diff --git a/internal/isIterateeCall.js b/internal/isIterateeCall.js index e93d3d621..efbc40f6e 100644 --- a/internal/isIterateeCall.js +++ b/internal/isIterateeCall.js @@ -1,4 +1,4 @@ -define(['./getLength', './isIndex', './isLength', '../lang/isObject'], function(getLength, isIndex, isLength, isObject) { +define(['./isArrayLike', './isIndex', '../lang/isObject'], function(isArrayLike, isIndex, isObject) { /** * Checks if the provided arguments are from an iteratee call. @@ -14,13 +14,9 @@ define(['./getLength', './isIndex', './isLength', '../lang/isObject'], function( return false; } var type = typeof index; - if (type == 'number') { - var length = getLength(object), - prereq = isLength(length) && isIndex(index, length); - } else { - prereq = type == 'string' && index in object; - } - if (prereq) { + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object)) { var other = object[index]; return value === value ? (value === other) : (other !== other); } diff --git a/internal/isKey.js b/internal/isKey.js index 03d92e10d..5fe2add10 100644 --- a/internal/isKey.js +++ b/internal/isKey.js @@ -1,7 +1,7 @@ define(['../lang/isArray', './toObject'], function(isArray, toObject) { /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/, + var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/; /** diff --git a/internal/isStrictComparable.js b/internal/isStrictComparable.js index 1c56266c1..954911098 100644 --- a/internal/isStrictComparable.js +++ b/internal/isStrictComparable.js @@ -9,7 +9,7 @@ define(['../lang/isObject'], function(isObject) { * equality comparisons, else `false`. */ function isStrictComparable(value) { - return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value)); + return value === value && !isObject(value); } return isStrictComparable; diff --git a/internal/pickByArray.js b/internal/pickByArray.js index 726cfcc96..b9375cf55 100644 --- a/internal/pickByArray.js +++ b/internal/pickByArray.js @@ -1,7 +1,7 @@ define(['./toObject'], function(toObject) { /** - * A specialized version of `_.pick` that picks `object` properties specified + * A specialized version of `_.pick` which picks `object` properties specified * by `props`. * * @private diff --git a/internal/pickByCallback.js b/internal/pickByCallback.js index 0136037f1..4bd15b35f 100644 --- a/internal/pickByCallback.js +++ b/internal/pickByCallback.js @@ -1,7 +1,7 @@ define(['./baseForIn'], function(baseForIn) { /** - * A specialized version of `_.pick` that picks `object` properties `predicate` + * A specialized version of `_.pick` which picks `object` properties `predicate` * returns truthy for. * * @private diff --git a/internal/toIterable.js b/internal/toIterable.js index 7e9f306b9..1054a845f 100644 --- a/internal/toIterable.js +++ b/internal/toIterable.js @@ -1,4 +1,4 @@ -define(['./getLength', './isLength', '../lang/isObject', '../object/values'], function(getLength, isLength, isObject, values) { +define(['./isArrayLike', '../lang/isObject', '../object/values'], function(isArrayLike, isObject, values) { /** * Converts `value` to an array-like object if it is not one. @@ -11,7 +11,7 @@ define(['./getLength', './isLength', '../lang/isObject', '../object/values'], fu if (value == null) { return []; } - if (!isLength(getLength(value))) { + if (!isArrayLike(value)) { return values(value); } return isObject(value) ? value : Object(value); diff --git a/lang/isArguments.js b/lang/isArguments.js index 038190205..66a290a68 100644 --- a/lang/isArguments.js +++ b/lang/isArguments.js @@ -1,7 +1,4 @@ -define(['../internal/isLength', '../internal/isObjectLike'], function(isLength, isObjectLike) { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['../internal/isArrayLike', '../internal/isObjectLike'], function(isArrayLike, isObjectLike) { /** `Object#toString` result references. */ var argsTag = '[object Arguments]'; @@ -32,8 +29,7 @@ define(['../internal/isLength', '../internal/isObjectLike'], function(isLength, * // => false */ function isArguments(value) { - var length = isObjectLike(value) ? value.length : undefined; - return isLength(length) && objToString.call(value) == argsTag; + return isObjectLike(value) && isArrayLike(value) && objToString.call(value) == argsTag; } return isArguments; diff --git a/lang/isEmpty.js b/lang/isEmpty.js index 42db6b956..abed2b7c0 100644 --- a/lang/isEmpty.js +++ b/lang/isEmpty.js @@ -1,4 +1,4 @@ -define(['../internal/getLength', './isArguments', './isArray', './isFunction', '../internal/isLength', '../internal/isObjectLike', './isString', '../object/keys'], function(getLength, isArguments, isArray, isFunction, isLength, isObjectLike, isString, keys) { +define(['./isArguments', './isArray', '../internal/isArrayLike', './isFunction', '../internal/isObjectLike', './isString', '../object/keys'], function(isArguments, isArray, isArrayLike, isFunction, isObjectLike, isString, keys) { /** * Checks if `value` is empty. A value is considered empty unless it is an @@ -31,10 +31,9 @@ define(['../internal/getLength', './isArguments', './isArray', './isFunction', ' if (value == null) { return true; } - var length = getLength(value); - if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) || + if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) || (isObjectLike(value) && isFunction(value.splice)))) { - return !length; + return !value.length; } return !keys(value).length; } diff --git a/lang/isRegExp.js b/lang/isRegExp.js index bb515d749..ea56e70c1 100644 --- a/lang/isRegExp.js +++ b/lang/isRegExp.js @@ -29,7 +29,7 @@ define(['../internal/isObjectLike'], function(isObjectLike) { * // => false */ function isRegExp(value) { - return (isObjectLike(value) && objToString.call(value) == regexpTag) || false; + return isObjectLike(value) && objToString.call(value) == regexpTag; } return isRegExp; diff --git a/main.js b/main.js index cedaa4313..63adfb2e6 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.7.0 (Custom Build) + * lodash 3.8.0 (Custom Build) * Build: `lodash modern exports="amd" -d -o ./main.js` * Copyright 2012-2015 The Dojo Foundation * Based on Underscore.js 1.8.3 @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '3.7.0'; + var VERSION = '3.8.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -88,7 +88,7 @@ reInterpolate = /<%=([\s\S]+?)%>/g; /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/, + var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g; @@ -277,8 +277,6 @@ */ var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this; - /*--------------------------------------------------------------------------*/ - /** * The base implementation of `compareAscending` which compares values and * sorts them in ascending order without guaranteeing a stable sort. @@ -649,8 +647,6 @@ return htmlUnescapes[chr]; } - /*--------------------------------------------------------------------------*/ - /** * Create a new pristine `lodash` function using the given `context` object. * @@ -746,7 +742,7 @@ getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols, getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, push = arrayProto.push, - preventExtensions = isNative(Object.preventExtensions = Object.preventExtensions) && preventExtensions, + preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions, propertyIsEnumerable = objectProto.propertyIsEnumerable, Set = isNative(Set = context.Set) && Set, setTimeout = context.setTimeout, @@ -774,12 +770,19 @@ // // Use `Object.preventExtensions` on a plain object instead of simply using // `Object('x')` because Chrome and IE fail to throw an error when attempting - // to assign values to readonly indexes of strings in strict mode. - var object = { '1': 0 }, - func = preventExtensions && isNative(func = Object.assign) && func; - - try { func(preventExtensions(object), 'xo'); } catch(e) {} - return !object[1] && func; + // to assign values to readonly indexes of strings. + var func = preventExtensions && isNative(func = Object.assign) && func; + try { + if (func) { + var object = preventExtensions({ '1': 0 }); + object[0] = 1; + } + } catch(e) { + // Only attempt in strict mode. + try { func(object, 'xo'); } catch(e) {} + return !object[1] && func; + } + return false; }()); /* Native method references for those with the same name as other `lodash` methods. */ @@ -800,7 +803,7 @@ /** Used as references for the maximum length and index of an array. */ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1, - MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, + MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; /** Used as the size, in bytes, of each `Float64Array` element. */ @@ -818,8 +821,6 @@ /** Used to lookup unminified function names. */ var realNames = {}; - /*------------------------------------------------------------------------*/ - /** * Creates a `lodash` object which wraps `value` to enable implicit chaining. * Methods that operate on and return arrays, collections, and functions can @@ -959,6 +960,7 @@ (function(x) { var Ctor = function() { this.x = x; }, + args = arguments, object = { '0': x, 'length': x }, props = []; @@ -1008,7 +1010,7 @@ * @type boolean */ try { - support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1); + support.nonEnumArgs = !propertyIsEnumerable.call(args, 1); } catch(e) { support.nonEnumArgs = true; } @@ -1075,8 +1077,6 @@ } }; - /*------------------------------------------------------------------------*/ - /** * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. * @@ -1205,8 +1205,6 @@ return result; } - /*------------------------------------------------------------------------*/ - /** * Creates a cache object to store key/value pairs. * @@ -1275,8 +1273,6 @@ return this; } - /*------------------------------------------------------------------------*/ - /** * * Creates a cache object to store unique values. @@ -1326,8 +1322,6 @@ } } - /*------------------------------------------------------------------------*/ - /** * Copies the values of `source` to `array`. * @@ -1671,8 +1665,9 @@ */ function baseAt(collection, props) { var index = -1, - length = collection.length, - isArr = isLength(length), + isNil = collection == null, + isArr = !isNil && isArrayLike(collection), + length = isArr && collection.length, propsLength = props.length, result = Array(propsLength); @@ -1681,7 +1676,7 @@ if (isArr) { result[index] = isIndex(key, length) ? collection[key] : undefined; } else { - result[index] = collection[key]; + result[index] = isNil ? undefined : collection[key]; } } return result; @@ -2008,8 +2003,8 @@ * * @private * @param {Array} array The array to flatten. - * @param {boolean} isDeep Specify a deep flatten. - * @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects. + * @param {boolean} [isDeep] Specify a deep flatten. + * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, isDeep, isStrict) { @@ -2020,8 +2015,8 @@ while (++index < length) { var value = array[index]; - - if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) { + if (isObjectLike(value) && isArrayLike(value) && + (isStrict || isArray(value) || isArguments(value))) { if (isDeep) { // Recursively flatten arrays (susceptible to call stack limits). value = baseFlatten(value, isDeep, isStrict); @@ -2029,7 +2024,6 @@ var valIndex = -1, valLength = value.length; - result.length += valLength; while (++valIndex < valLength) { result[++resIndex] = value[valIndex]; } @@ -2150,9 +2144,9 @@ length = path.length; while (object != null && ++index < length) { - var result = object = object[path[index]]; + object = object[path[index]]; } - return result; + return (index && index == length) ? object : undefined; } /** @@ -2171,8 +2165,7 @@ function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) { // Exit early for identical values. if (value === other) { - // Treat `+0` vs. `-0` as not equal. - return value !== 0 || (1 / value == 1 / other); + return true; } var valType = typeof value, othType = typeof other; @@ -2321,8 +2314,7 @@ */ function baseMap(collection, iteratee) { var index = -1, - length = getLength(collection), - result = isLength(length) ? Array(length) : []; + result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value, key, collection) { result[++index] = iteratee(value, key, collection); @@ -2421,7 +2413,7 @@ if (!isObject(object)) { return object; } - var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source)); + var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)); if (!isSrcArr) { var props = keys(source); push.apply(props, getSymbols(source)); @@ -2484,10 +2476,10 @@ if (isCommon) { result = srcValue; - if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) { + if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) { result = isArray(value) ? value - : (getLength(value) ? arrayCopy(value) : []); + : (isArrayLike(value) ? arrayCopy(value) : []); } else if (isPlainObject(srcValue) || isArguments(srcValue)) { result = isArguments(value) @@ -2549,7 +2541,7 @@ * @returns {Array} Returns `array`. */ function basePullAt(array, indexes) { - var length = indexes.length; + var length = array ? indexes.length : 0; while (length--) { var index = parseFloat(indexes[length]); if (index != previous && isIndex(index)) { @@ -3035,12 +3027,12 @@ while (++argsIndex < argsLength) { result[argsIndex] = args[argsIndex]; } - var pad = argsIndex; + var offset = argsIndex; while (++rightIndex < rightLength) { - result[pad + rightIndex] = partials[rightIndex]; + result[offset + rightIndex] = partials[rightIndex]; } while (++holdersIndex < holdersLength) { - result[pad + holders[holdersIndex]] = args[argsIndex++]; + result[offset + holders[holdersIndex]] = args[argsIndex++]; } return result; } @@ -3308,7 +3300,7 @@ return index > -1 ? collection[index] : undefined; } return baseFind(collection, predicate, eachFunc); - } + }; } /** @@ -3374,7 +3366,7 @@ funcName = getFuncName(func); var data = funcName == 'wrapper' ? getData(func) : null; - if (data && isLaziable(data[0])) { + if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) { wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); } else { wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); @@ -3444,6 +3436,28 @@ }; } + /** + * Creates a function for `_.mapKeys` or `_.mapValues`. + * + * @private + * @param {boolean} [isMapKeys] Specify mapping keys instead of values. + * @returns {Function} Returns the new map function. + */ + function createObjectMapper(isMapKeys) { + return function(object, iteratee, thisArg) { + var result = {}; + iteratee = getCallback(iteratee, thisArg, 3); + + baseForOwn(object, function(value, key, object) { + var mapped = iteratee(value, key, object); + key = isMapKeys ? mapped : key; + value = isMapKeys ? value : mapped; + result[key] = value; + }); + return result; + }; + } + /** * Creates a function for `_.padLeft` or `_.padRight`. * @@ -3454,7 +3468,7 @@ function createPadDir(fromRight) { return function(string, length, chars) { string = baseToString(string); - return string && ((fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string)); + return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string); }; } @@ -3800,8 +3814,7 @@ // Treat `NaN` vs. `NaN` as equal. return (object != +object) ? other != +other - // But, treat `-0` vs. `+0` as not equal. - : (object == 0 ? ((1 / object) == (1 / other)) : object == +other); + : object == +other; case regexpTag: case stringTag: @@ -3981,7 +3994,7 @@ * 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) - * in Safari on iOS 8.1 ARM64. + * that affects Safari on at least iOS 8.1-8.3 ARM64. * * @private * @param {Object} object The object to query. @@ -4120,6 +4133,17 @@ return func == null ? undefined : func.apply(object, args); } + /** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ + function isArrayLike(value) { + return value != null && isLength(getLength(value)); + } + /** * Checks if `value` is a valid array-like index. * @@ -4148,13 +4172,9 @@ return false; } var type = typeof index; - if (type == 'number') { - var length = getLength(object), - prereq = isLength(length) && isIndex(index, length); - } else { - prereq = type == 'string' && index in object; - } - if (prereq) { + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object)) { var other = object[index]; return value === value ? (value === other) : (other !== other); } @@ -4215,7 +4235,7 @@ * equality comparisons, else `false`. */ function isStrictComparable(value) { - return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value)); + return value === value && !isObject(value); } /** @@ -4289,7 +4309,7 @@ } /** - * A specialized version of `_.pick` that picks `object` properties specified + * A specialized version of `_.pick` which picks `object` properties specified * by `props`. * * @private @@ -4314,7 +4334,7 @@ } /** - * A specialized version of `_.pick` that picks `object` properties `predicate` + * A specialized version of `_.pick` which picks `object` properties `predicate` * returns truthy for. * * @private @@ -4459,7 +4479,7 @@ if (value == null) { return []; } - if (!isLength(getLength(value))) { + if (!isArrayLike(value)) { return values(value); } return isObject(value) ? value : Object(value); @@ -4507,8 +4527,6 @@ : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__)); } - /*------------------------------------------------------------------------*/ - /** * Creates an array of elements split into groups the length of `size`. * If `collection` can't be split evenly, the final chunk will be the remaining @@ -4577,11 +4595,8 @@ /** * Creates an array excluding all values of the provided arrays using - * `SameValueZero` for equality comparisons. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * * @static * @memberOf _ @@ -4595,7 +4610,7 @@ * // => [1, 3] */ var difference = restParam(function(array, values) { - return (isArray(array) || isArguments(array)) + return isArrayLike(array) ? baseDifference(array, baseFlatten(values, false, true)) : []; }); @@ -4990,13 +5005,10 @@ /** * Gets the index at which the first occurrence of `value` is found in `array` - * using `SameValueZero` for equality comparisons. If `fromIndex` is negative, - * it is used as the offset from the end of `array`. If `array` is sorted - * providing `true` for `fromIndex` performs a faster binary search. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it is used as the offset + * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` + * performs a faster binary search. * * @static * @memberOf _ @@ -5056,13 +5068,10 @@ } /** - * Creates an array of unique values in all provided arrays using `SameValueZero` + * Creates an array of unique values in all provided arrays using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) * for equality comparisons. * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. - * * @static * @memberOf _ * @category Array @@ -5083,7 +5092,7 @@ while (++argsIndex < argsLength) { var value = arguments[argsIndex]; - if (isArray(value) || isArguments(value)) { + if (isArrayLike(value)) { args.push(value); caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null); } @@ -5188,14 +5197,11 @@ } /** - * Removes all provided values from `array` using `SameValueZero` for equality - * comparisons. + * Removes all provided values from `array` using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * - * **Notes:** - * - Unlike `_.without`, this method mutates `array` - * - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except - * that `NaN` matches `NaN` + * **Note:** Unlike `_.without`, this method mutates `array`. * * @static * @memberOf _ @@ -5259,7 +5265,6 @@ * // => [10, 20] */ var pullAt = restParam(function(array, indexes) { - array || (array = []); indexes = baseFlatten(indexes); var result = baseAt(array, indexes); @@ -5626,11 +5631,8 @@ /** * Creates an array of unique values, in order, of the provided arrays using - * `SameValueZero` for equality comparisons. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * * @static * @memberOf _ @@ -5647,8 +5649,9 @@ }); /** - * Creates a duplicate-free version of an array, using `SameValueZero` for - * equality comparisons, in which only the first occurence of each element + * Creates a duplicate-free version of an array, using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons, in which only the first occurence of each element * is kept. Providing `true` for `isSorted` performs a faster search algorithm * for sorted arrays. If an iteratee function is provided it is invoked for * each element in the array to generate the criterion by which uniqueness @@ -5666,10 +5669,6 @@ * callback returns `true` for elements that have the properties of the given * object, else `false`. * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. - * * @static * @memberOf _ * @alias unique @@ -5719,7 +5718,7 @@ /** * This method is like `_.zip` except that it accepts an array of grouped - * elements and creates an array regrouping the elements to their pre-`_.zip` + * elements and creates an array regrouping the elements to their pre-zip * configuration. * * @static @@ -5736,10 +5735,19 @@ * // => [['fred', 'barney'], [30, 40], [true, false]] */ function unzip(array) { + if (!(array && array.length)) { + return []; + } var index = -1, - length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0, - result = Array(length); + length = 0; + array = arrayFilter(array, function(group) { + if (isArrayLike(group)) { + length = nativeMax(group.length, length); + return true; + } + }); + var result = Array(length); while (++index < length) { result[index] = arrayMap(array, baseProperty(index)); } @@ -5747,12 +5755,44 @@ } /** - * Creates an array excluding all provided values using `SameValueZero` for - * equality comparisons. + * This method is like `_.unzip` except that it accepts an iteratee to specify + * how regrouped values should be combined. The `iteratee` is bound to `thisArg` + * and invoked with four arguments: (accumulator, value, index, group). * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array of grouped elements to process. + * @param {Function} [iteratee] The function to combine regrouped values. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * var zipped = _.zip([1, 2], [10, 20], [100, 200]); + * // => [[1, 10, 100], [2, 20, 200]] + * + * _.unzipWith(zipped, _.add); + * // => [3, 30, 300] + */ + function unzipWith(array, iteratee, thisArg) { + var length = array ? array.length : 0; + if (!length) { + return []; + } + var result = unzip(array); + if (iteratee == null) { + return result; + } + iteratee = bindCallback(iteratee, thisArg, 4); + return arrayMap(result, function(group) { + return arrayReduce(group, iteratee, undefined, true); + }); + } + + /** + * Creates an array excluding all provided values using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. * * @static * @memberOf _ @@ -5766,7 +5806,7 @@ * // => [3] */ var without = restParam(function(array, values) { - return (isArray(array) || isArguments(array)) + return isArrayLike(array) ? baseDifference(array, values) : []; }); @@ -5791,7 +5831,7 @@ while (++index < length) { var array = arguments[index]; - if (isArray(array) || isArguments(array)) { + if (isArrayLike(array)) { var result = result ? baseDifference(result, array).concat(baseDifference(array, result)) : array; @@ -5857,7 +5897,37 @@ return result; } - /*------------------------------------------------------------------------*/ + /** + * This method is like `_.zip` except that it accepts an iteratee to specify + * how grouped values should be combined. The `iteratee` is bound to `thisArg` + * and invoked with four arguments: (accumulator, value, index, group). + * + * @static + * @memberOf _ + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @param {Function} [iteratee] The function to combine grouped values. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Array} Returns the new array of grouped elements. + * @example + * + * _.zipWith([1, 2], [10, 20], [100, 200], _.add); + * // => [111, 222] + */ + var zipWith = restParam(function(arrays) { + var length = arrays.length, + iteratee = arrays[length - 2], + thisArg = arrays[length - 1]; + + if (length > 2 && typeof iteratee == 'function') { + length -= 2; + } else { + iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined; + thisArg = undefined; + } + arrays.length = length; + return unzipWith(arrays, iteratee, thisArg); + }); /** * Creates a `lodash` object that wraps `value` with explicit method @@ -6109,8 +6179,6 @@ return baseWrapperValue(this.__wrapped__, this.__actions__); } - /*------------------------------------------------------------------------*/ - /** * Creates an array of elements corresponding to the given keys, or indexes, * of `collection`. Keys may be specified as individual arguments or as arrays @@ -6132,10 +6200,6 @@ * // => ['barney', 'pebbles'] */ var at = restParam(function(collection, props) { - var length = collection ? getLength(collection) : 0; - if (isLength(length)) { - collection = toIterable(collection); - } return baseAt(collection, baseFlatten(props)); }); @@ -6508,13 +6572,10 @@ }); /** - * Checks if `value` is in `collection` using `SameValueZero` for equality - * comparisons. If `fromIndex` is negative, it is used as the offset from - * the end of `collection`. - * - * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * comparisons are like strict equality comparisons, e.g. `===`, except that - * `NaN` matches `NaN`. + * Checks if `value` is in `collection` using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it is used as the offset + * from the end of `collection`. * * @static * @memberOf _ @@ -6634,8 +6695,7 @@ var index = -1, isFunc = typeof path == 'function', isProp = isKey(path), - length = getLength(collection), - result = isLength(length) ? Array(length) : []; + result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value) { var func = isFunc ? path : (isProp && value != null && value[path]); @@ -6664,10 +6724,11 @@ * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. * * The guarded methods are: - * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`, - * `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, - * `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, - * `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words` + * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, + * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, + * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, + * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, + * `sum`, `uniq`, and `words` * * @static * @memberOf _ @@ -6855,23 +6916,12 @@ * }, []); * // => [4, 5, 2, 3, 0, 1] */ - var reduceRight = createReduce(arrayReduceRight, baseEachRight); + var reduceRight = createReduce(arrayReduceRight, baseEachRight); /** * The opposite of `_.filter`; this method returns the elements of `collection` * that `predicate` does **not** return truthy for. * - * If a property name is provided for `predicate` the created `_.property` - * style callback returns the property value of the given element. - * - * If a value is also provided for `thisArg` the created `_.matchesProperty` - * style callback returns `true` for elements that have a matching property - * value, else `false`. - * - * If an object is provided for `predicate` the created `_.matches` style - * callback returns `true` for elements that have the properties of the given - * object, else `false`. - * * @static * @memberOf _ * @category Collection @@ -7250,8 +7300,6 @@ return filter(collection, baseMatches(source)); } - /*------------------------------------------------------------------------*/ - /** * Gets the number of milliseconds that have elapsed since the Unix epoch * (1 January 1970 00:00:00 UTC). @@ -7270,8 +7318,6 @@ return new Date().getTime(); }; - /*------------------------------------------------------------------------*/ - /** * The opposite of `_.before`; this method creates a function that invokes * `func` once it is called `n` or more times. @@ -8251,8 +8297,6 @@ return createWrapper(wrapper, PARTIAL_FLAG, null, [value], []); } - /*------------------------------------------------------------------------*/ - /** * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned, * otherwise they are assigned by reference. If `customizer` is provided it is @@ -8384,8 +8428,7 @@ * // => false */ function isArguments(value) { - var length = isObjectLike(value) ? value.length : undefined; - return isLength(length) && objToString.call(value) == argsTag; + return isObjectLike(value) && isArrayLike(value) && objToString.call(value) == argsTag; } /** @@ -8506,10 +8549,9 @@ if (value == null) { return true; } - var length = getLength(value); - if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) || + if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) || (isObjectLike(value) && isFunction(value.splice)))) { - return !length; + return !value.length; } return !keys(value).length; } @@ -8899,7 +8941,7 @@ * // => false */ function isRegExp(value) { - return (isObjectLike(value) && objToString.call(value) == regexpTag) || false; + return isObjectLike(value) && objToString.call(value) == regexpTag; } /** @@ -9015,8 +9057,6 @@ return baseCopy(value, keysIn(value)); } - /*------------------------------------------------------------------------*/ - /** * Assigns own enumerable properties of source object(s) to the destination * object. Subsequent sources overwrite property assignments of previous sources. @@ -9027,7 +9067,6 @@ * **Note:** This method mutates `object` and is based on * [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign). * - * * @static * @memberOf _ * @alias extend @@ -9499,12 +9538,9 @@ * // => ['0', '1'] */ var keys = !nativeKeys ? shimKeys : function(object) { - if (object) { - var Ctor = object.constructor, - length = object.length; - } + var Ctor = object != null && object.constructor; if ((typeof Ctor == 'function' && Ctor.prototype === object) || - (typeof object != 'function' && isLength(length))) { + (typeof object != 'function' && isArrayLike(object))) { return shimKeys(object); } return isObject(object) ? nativeKeys(object) : []; @@ -9561,6 +9597,28 @@ return result; } + /** + * 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`. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Object} Returns the new mapped object. + * @example + * + * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { + * return key + value; + * }); + * // => { 'a1': 1, 'b2': 2 } + */ + var mapKeys = createObjectMapper(true); + /** * Creates an object with the same keys as `object` and values generated by * running each own enumerable property of `object` through `iteratee`. The @@ -9602,15 +9660,7 @@ * _.mapValues(users, 'age'); * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) */ - function mapValues(object, iteratee, thisArg) { - var result = {}; - iteratee = getCallback(iteratee, thisArg, 3); - - baseForOwn(object, function(value, key, object) { - result[key] = iteratee(value, key, object); - }); - return result; - } + var mapValues = createObjectMapper(); /** * Recursively merges own enumerable properties of the source object(s), that @@ -9665,11 +9715,6 @@ /** * The opposite of `_.pick`; this method creates an object composed of the * own and inherited enumerable properties of `object` that are not omitted. - * Property names may be specified as individual arguments or as arrays of - * property names. If `predicate` is provided it is invoked for each property - * of `object` omitting the properties `predicate` returns truthy for. The - * predicate is bound to `thisArg` and invoked with three arguments: - * (value, key, object). * * @static * @memberOf _ @@ -9963,8 +10008,6 @@ return baseValues(object, keysIn(object)); } - /*------------------------------------------------------------------------*/ - /** * Checks if `n` is between `start` and up to but not including, `end`. If * `end` is not specified it is set to `start` with `start` then set to `0`. @@ -10069,8 +10112,6 @@ return baseRandom(min, max); } - /*------------------------------------------------------------------------*/ - /** * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). * @@ -10936,8 +10977,6 @@ return string.match(pattern || reWords) || []; } - /*------------------------------------------------------------------------*/ - /** * Attempts to invoke `func`, returning either the result or the caught error * object. Any additional arguments are provided to `func` when it is invoked. @@ -11008,7 +11047,9 @@ if (guard && isIterateeCall(func, thisArg, guard)) { thisArg = null; } - return baseCallback(func, thisArg); + return isObjectLike(func) + ? matches(func) + : baseCallback(func, thisArg); } /** @@ -11133,7 +11174,7 @@ var method = restParam(function(path, args) { return function(object) { return invokePath(object, path, args); - } + }; }); /** @@ -11470,8 +11511,6 @@ return baseToString(prefix) + id; } - /*------------------------------------------------------------------------*/ - /** * Adds two numbers. * @@ -11636,8 +11675,6 @@ : baseSum(collection, iteratee); } - /*------------------------------------------------------------------------*/ - // Ensure wrappers are instances of `baseLodash`. lodash.prototype = baseLodash.prototype; @@ -11708,6 +11745,7 @@ lodash.keys = keys; lodash.keysIn = keysIn; lodash.map = map; + lodash.mapKeys = mapKeys; lodash.mapValues = mapValues; lodash.matches = matches; lodash.matchesProperty = matchesProperty; @@ -11756,6 +11794,7 @@ lodash.union = union; lodash.uniq = uniq; lodash.unzip = unzip; + lodash.unzipWith = unzipWith; lodash.values = values; lodash.valuesIn = valuesIn; lodash.where = where; @@ -11764,6 +11803,7 @@ lodash.xor = xor; lodash.zip = zip; lodash.zipObject = zipObject; + lodash.zipWith = zipWith; // Add aliases. lodash.backflow = flowRight; @@ -11782,8 +11822,6 @@ // Add functions to `lodash.prototype`. mixin(lodash, lodash); - /*------------------------------------------------------------------------*/ - // Add functions that return unwrapped values when chaining. lodash.add = add; lodash.attempt = attempt; @@ -11887,8 +11925,6 @@ return source; }()), false); - /*------------------------------------------------------------------------*/ - // Add functions capable of returning wrapped and unwrapped values when chaining. lodash.sample = sample; @@ -11901,8 +11937,6 @@ }); }; - /*------------------------------------------------------------------------*/ - /** * The semantic version number. * @@ -12013,8 +12047,13 @@ LazyWrapper.prototype.slice = function(start, end) { start = start == null ? 0 : (+start || 0); - var result = start < 0 ? this.takeRight(-start) : this.drop(start); + var result = this; + if (start < 0) { + result = this.takeRight(-start); + } else if (start) { + result = this.drop(start); + } if (end !== undefined) { end = (+end || 0); result = end < 0 ? result.dropRight(-end) : result.take(end - start); @@ -12037,7 +12076,6 @@ lodash.prototype[methodName] = function() { var args = arguments, - length = args.length, chainAll = this.__chain__, value = this.__wrapped__, isHybrid = !!this.__actions__.length, @@ -12126,8 +12164,6 @@ return lodash; } - /*--------------------------------------------------------------------------*/ - // Export lodash. var _ = runInContext(); diff --git a/object.js b/object.js index ef7932b7c..91d7045c7 100644 --- a/object.js +++ b/object.js @@ -1,4 +1,4 @@ -define(['./object/assign', './object/create', './object/defaults', './object/extend', './object/findKey', './object/findLastKey', './object/forIn', './object/forInRight', './object/forOwn', './object/forOwnRight', './object/functions', './object/get', './object/has', './object/invert', './object/keys', './object/keysIn', './object/mapValues', './object/merge', './object/methods', './object/omit', './object/pairs', './object/pick', './object/result', './object/set', './object/transform', './object/values', './object/valuesIn'], function(assign, create, defaults, extend, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, get, has, invert, keys, keysIn, mapValues, merge, methods, omit, pairs, pick, result, set, transform, values, valuesIn) { +define(['./object/assign', './object/create', './object/defaults', './object/extend', './object/findKey', './object/findLastKey', './object/forIn', './object/forInRight', './object/forOwn', './object/forOwnRight', './object/functions', './object/get', './object/has', './object/invert', './object/keys', './object/keysIn', './object/mapKeys', './object/mapValues', './object/merge', './object/methods', './object/omit', './object/pairs', './object/pick', './object/result', './object/set', './object/transform', './object/values', './object/valuesIn'], function(assign, create, defaults, extend, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, get, has, invert, keys, keysIn, mapKeys, mapValues, merge, methods, omit, pairs, pick, result, set, transform, values, valuesIn) { return { 'assign': assign, 'create': create, @@ -16,6 +16,7 @@ define(['./object/assign', './object/create', './object/defaults', './object/ext 'invert': invert, 'keys': keys, 'keysIn': keysIn, + 'mapKeys': mapKeys, 'mapValues': mapValues, 'merge': merge, 'methods': methods, diff --git a/object/assign.js b/object/assign.js index fe58629a8..a2deebb20 100644 --- a/object/assign.js +++ b/object/assign.js @@ -10,7 +10,6 @@ define(['../internal/assignWith', '../internal/baseAssign', '../internal/createA * **Note:** This method mutates `object` and is based on * [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign). * - * * @static * @memberOf _ * @alias extend diff --git a/object/keys.js b/object/keys.js index db04cb7d4..60f7577aa 100644 --- a/object/keys.js +++ b/object/keys.js @@ -1,4 +1,4 @@ -define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../internal/shimKeys'], function(isLength, isNative, isObject, shimKeys) { +define(['../internal/isArrayLike', '../lang/isNative', '../lang/isObject', '../internal/shimKeys'], function(isArrayLike, isNative, isObject, shimKeys) { /* Native method references for those with the same name as other `lodash` methods. */ var nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys; @@ -31,12 +31,9 @@ define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../inte * // => ['0', '1'] */ var keys = !nativeKeys ? shimKeys : function(object) { - if (object) { - var Ctor = object.constructor, - length = object.length; - } + var Ctor = object != null && object.constructor; if ((typeof Ctor == 'function' && Ctor.prototype === object) || - (typeof object != 'function' && isLength(length))) { + (typeof object != 'function' && isArrayLike(object))) { return shimKeys(object); } return isObject(object) ? nativeKeys(object) : []; diff --git a/object/mapKeys.js b/object/mapKeys.js new file mode 100644 index 000000000..bcb44aab2 --- /dev/null +++ b/object/mapKeys.js @@ -0,0 +1,26 @@ +define(['../internal/createObjectMapper'], function(createObjectMapper) { + + /** + * 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`. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Object} Returns the new mapped object. + * @example + * + * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { + * return key + value; + * }); + * // => { 'a1': 1, 'b2': 2 } + */ + var mapKeys = createObjectMapper(true); + + return mapKeys; +}); diff --git a/object/mapValues.js b/object/mapValues.js index 941b27f14..ad58b5e6e 100644 --- a/object/mapValues.js +++ b/object/mapValues.js @@ -1,4 +1,4 @@ -define(['../internal/baseCallback', '../internal/baseForOwn'], function(baseCallback, baseForOwn) { +define(['../internal/createObjectMapper'], function(createObjectMapper) { /** * Creates an object with the same keys as `object` and values generated by @@ -41,15 +41,7 @@ define(['../internal/baseCallback', '../internal/baseForOwn'], function(baseCall * _.mapValues(users, 'age'); * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) */ - function mapValues(object, iteratee, thisArg) { - var result = {}; - iteratee = baseCallback(iteratee, thisArg, 3); - - baseForOwn(object, function(value, key, object) { - result[key] = iteratee(value, key, object); - }); - return result; - } + var mapValues = createObjectMapper(); return mapValues; }); diff --git a/object/omit.js b/object/omit.js index 8fa33ed36..b6669c6df 100644 --- a/object/omit.js +++ b/object/omit.js @@ -3,11 +3,6 @@ define(['../internal/arrayMap', '../internal/baseDifference', '../internal/baseF /** * The opposite of `_.pick`; this method creates an object composed of the * own and inherited enumerable properties of `object` that are not omitted. - * Property names may be specified as individual arguments or as arrays of - * property names. If `predicate` is provided it is invoked for each property - * of `object` omitting the properties `predicate` returns truthy for. The - * predicate is bound to `thisArg` and invoked with three arguments: - * (value, key, object). * * @static * @memberOf _ diff --git a/package.json b/package.json index 5b558fec6..926d8094c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash", - "version": "3.7.0", + "version": "3.8.0", "main": "main.js", "private": true, "volo": { diff --git a/support.js b/support.js index ccc89202e..f632d7992 100644 --- a/support.js +++ b/support.js @@ -20,6 +20,7 @@ define(['./internal/root'], function(root) { (function(x) { var Ctor = function() { this.x = x; }, + args = arguments, object = { '0': x, 'length': x }, props = []; @@ -69,7 +70,7 @@ define(['./internal/root'], function(root) { * @type boolean */ try { - support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1); + support.nonEnumArgs = !propertyIsEnumerable.call(args, 1); } catch(e) { support.nonEnumArgs = true; } diff --git a/utility/callback.js b/utility/callback.js index 993a62054..977de379c 100644 --- a/utility/callback.js +++ b/utility/callback.js @@ -1,4 +1,4 @@ -define(['../internal/baseCallback', '../internal/isIterateeCall'], function(baseCallback, isIterateeCall) { +define(['../internal/baseCallback', '../internal/isIterateeCall', '../internal/isObjectLike', './matches'], function(baseCallback, isIterateeCall, isObjectLike, matches) { /** * Creates a function that invokes `func` with the `this` binding of `thisArg` @@ -42,7 +42,9 @@ define(['../internal/baseCallback', '../internal/isIterateeCall'], function(base if (guard && isIterateeCall(func, thisArg, guard)) { thisArg = null; } - return baseCallback(func, thisArg); + return isObjectLike(func) + ? matches(func) + : baseCallback(func, thisArg); } return callback; diff --git a/utility/method.js b/utility/method.js index 2d32d5504..c62709424 100644 --- a/utility/method.js +++ b/utility/method.js @@ -24,7 +24,7 @@ define(['../internal/invokePath', '../function/restParam'], function(invokePath, var method = restParam(function(path, args) { return function(object) { return invokePath(object, path, args); - } + }; }); return method;