From e5817a291d971124c43944ccd1e9cf18835df519 Mon Sep 17 00:00:00 2001 From: Steve Zhu Date: Sat, 9 May 2015 10:29:30 -0400 Subject: [PATCH] Lodash v3.8.0 --- .npm/package/npm-shrinkwrap.json | 2 +- lodash.js | 446 +++++++++++++++++-------------- package.js | 4 +- 3 files changed, 245 insertions(+), 207 deletions(-) diff --git a/.npm/package/npm-shrinkwrap.json b/.npm/package/npm-shrinkwrap.json index c910f8f..32dc3f2 100644 --- a/.npm/package/npm-shrinkwrap.json +++ b/.npm/package/npm-shrinkwrap.json @@ -1,7 +1,7 @@ { "dependencies": { "lodash": { - "version": "3.7.0" + "version": "3.8.0" } } } diff --git a/lodash.js b/lodash.js index 2e8075a..2bed95a 100755 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.7.0 (Custom Build) + * lodash 3.8.0 (Custom Build) * Build: `lodash compat -o ./lodash.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; @@ -286,8 +286,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. @@ -678,8 +676,6 @@ return htmlUnescapes[chr]; } - /*--------------------------------------------------------------------------*/ - /** * Create a new pristine `lodash` function using the given `context` object. * @@ -776,7 +772,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, @@ -804,12 +800,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. */ @@ -830,7 +833,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. */ @@ -876,8 +879,6 @@ } }); - /*------------------------------------------------------------------------*/ - /** * Creates a `lodash` object which wraps `value` to enable implicit chaining. * Methods that operate on and return arrays, collections, and functions can @@ -1017,6 +1018,7 @@ (function(x) { var Ctor = function() { this.x = x; }, + args = arguments, object = { '0': x, 'length': x }, props = []; @@ -1030,7 +1032,7 @@ * @memberOf _.support * @type boolean */ - support.argsTag = objToString.call(arguments) == argsTag; + support.argsTag = objToString.call(args) == argsTag; /** * Detect if `name` or `message` properties of `Error.prototype` are @@ -1159,7 +1161,7 @@ * @type boolean */ try { - support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1); + support.nonEnumArgs = !propertyIsEnumerable.call(args, 1); } catch(e) { support.nonEnumArgs = true; } @@ -1226,8 +1228,6 @@ } }; - /*------------------------------------------------------------------------*/ - /** * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. * @@ -1356,8 +1356,6 @@ return result; } - /*------------------------------------------------------------------------*/ - /** * Creates a cache object to store key/value pairs. * @@ -1426,8 +1424,6 @@ return this; } - /*------------------------------------------------------------------------*/ - /** * * Creates a cache object to store unique values. @@ -1477,8 +1473,6 @@ } } - /*------------------------------------------------------------------------*/ - /** * Copies the values of `source` to `array`. * @@ -1822,8 +1816,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); @@ -1832,7 +1827,7 @@ if (isArr) { result[index] = isIndex(key, length) ? collection[key] : undefined; } else { - result[index] = collection[key]; + result[index] = isNil ? undefined : collection[key]; } } return result; @@ -2162,8 +2157,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) { @@ -2174,8 +2169,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); @@ -2183,7 +2178,6 @@ var valIndex = -1, valLength = value.length; - result.length += valLength; while (++valIndex < valLength) { result[++resIndex] = value[valIndex]; } @@ -2305,9 +2299,9 @@ length = path.length; while (object != null && ++index < length) { - var result = object = toObject(object)[path[index]]; + object = toObject(object)[path[index]]; } - return result; + return (index && index == length) ? object : undefined; } /** @@ -2326,8 +2320,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; @@ -2476,8 +2469,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); @@ -2577,7 +2569,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)); @@ -2640,10 +2632,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) @@ -2705,7 +2697,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)) { @@ -3191,12 +3183,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; } @@ -3464,7 +3456,7 @@ return index > -1 ? collection[index] : undefined; } return baseFind(collection, predicate, eachFunc); - } + }; } /** @@ -3530,7 +3522,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); @@ -3600,6 +3592,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`. * @@ -3610,7 +3624,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); }; } @@ -3956,8 +3970,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: @@ -4137,7 +4150,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. @@ -4280,6 +4293,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. * @@ -4308,13 +4332,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); } @@ -4375,7 +4395,7 @@ * equality comparisons, else `false`. */ function isStrictComparable(value) { - return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value)); + return value === value && !isObject(value); } /** @@ -4449,7 +4469,7 @@ } /** - * A specialized version of `_.pick` that picks `object` properties specified + * A specialized version of `_.pick` which picks `object` properties specified * by `props`. * * @private @@ -4474,7 +4494,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 @@ -4628,7 +4648,7 @@ if (value == null) { return []; } - if (!isLength(getLength(value))) { + if (!isArrayLike(value)) { return values(value); } if (lodash.support.unindexedChars && isString(value)) { @@ -4689,8 +4709,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 @@ -4759,11 +4777,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 _ @@ -4777,7 +4792,7 @@ * // => [1, 3] */ var difference = restParam(function(array, values) { - return (isArray(array) || isArguments(array)) + return isArrayLike(array) ? baseDifference(array, baseFlatten(values, false, true)) : []; }); @@ -5172,13 +5187,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 _ @@ -5238,13 +5250,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 @@ -5265,7 +5274,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); } @@ -5370,14 +5379,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 _ @@ -5441,7 +5447,6 @@ * // => [10, 20] */ var pullAt = restParam(function(array, indexes) { - array || (array = []); indexes = baseFlatten(indexes); var result = baseAt(array, indexes); @@ -5808,11 +5813,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 _ @@ -5829,8 +5831,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 @@ -5848,10 +5851,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 @@ -5901,7 +5900,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 @@ -5918,10 +5917,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)); } @@ -5929,12 +5937,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). + * + * @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]] * - * **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`. + * _.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 _ @@ -5948,7 +5988,7 @@ * // => [3] */ var without = restParam(function(array, values) { - return (isArray(array) || isArguments(array)) + return isArrayLike(array) ? baseDifference(array, values) : []; }); @@ -5973,7 +6013,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; @@ -6039,7 +6079,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 @@ -6291,8 +6361,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 @@ -6314,8 +6382,7 @@ * // => ['barney', 'pebbles'] */ var at = restParam(function(collection, props) { - var length = collection ? getLength(collection) : 0; - if (isLength(length)) { + if (isArrayLike(collection)) { collection = toIterable(collection); } return baseAt(collection, baseFlatten(props)); @@ -6690,13 +6757,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 _ @@ -6816,8 +6880,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]); @@ -6846,10 +6909,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 _ @@ -7037,23 +7101,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 @@ -7432,8 +7485,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). @@ -7452,8 +7503,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. @@ -8433,8 +8482,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 @@ -8566,15 +8613,13 @@ * // => 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; } // Fallback for environments without a `toStringTag` for `arguments` objects. if (!support.argsTag) { isArguments = function(value) { - var length = isObjectLike(value) ? value.length : undefined; - return isLength(length) && hasOwnProperty.call(value, 'callee') && - !propertyIsEnumerable.call(value, 'callee'); + return isObjectLike(value) && isArrayLike(value) && + hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee'); }; } @@ -8696,10 +8741,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; } @@ -9207,8 +9251,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. @@ -9219,7 +9261,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 @@ -9691,12 +9732,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' ? lodash.support.enumPrototypes : isLength(length))) { + (typeof object == 'function' ? lodash.support.enumPrototypes : isArrayLike(object))) { return shimKeys(object); } return isObject(object) ? nativeKeys(object) : []; @@ -9782,6 +9820,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 @@ -9823,15 +9883,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 @@ -9886,11 +9938,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 _ @@ -10184,8 +10231,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`. @@ -10290,8 +10335,6 @@ return baseRandom(min, max); } - /*------------------------------------------------------------------------*/ - /** * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). * @@ -11157,8 +11200,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. @@ -11229,7 +11270,9 @@ if (guard && isIterateeCall(func, thisArg, guard)) { thisArg = null; } - return baseCallback(func, thisArg); + return isObjectLike(func) + ? matches(func) + : baseCallback(func, thisArg); } /** @@ -11354,7 +11397,7 @@ var method = restParam(function(path, args) { return function(object) { return invokePath(object, path, args); - } + }; }); /** @@ -11691,8 +11734,6 @@ return baseToString(prefix) + id; } - /*------------------------------------------------------------------------*/ - /** * Adds two numbers. * @@ -11857,8 +11898,6 @@ : baseSum(collection, iteratee); } - /*------------------------------------------------------------------------*/ - // Ensure wrappers are instances of `baseLodash`. lodash.prototype = baseLodash.prototype; @@ -11929,6 +11968,7 @@ lodash.keys = keys; lodash.keysIn = keysIn; lodash.map = map; + lodash.mapKeys = mapKeys; lodash.mapValues = mapValues; lodash.matches = matches; lodash.matchesProperty = matchesProperty; @@ -11977,6 +12017,7 @@ lodash.union = union; lodash.uniq = uniq; lodash.unzip = unzip; + lodash.unzipWith = unzipWith; lodash.values = values; lodash.valuesIn = valuesIn; lodash.where = where; @@ -11985,6 +12026,7 @@ lodash.xor = xor; lodash.zip = zip; lodash.zipObject = zipObject; + lodash.zipWith = zipWith; // Add aliases. lodash.backflow = flowRight; @@ -12003,8 +12045,6 @@ // Add functions to `lodash.prototype`. mixin(lodash, lodash); - /*------------------------------------------------------------------------*/ - // Add functions that return unwrapped values when chaining. lodash.add = add; lodash.attempt = attempt; @@ -12108,8 +12148,6 @@ return source; }()), false); - /*------------------------------------------------------------------------*/ - // Add functions capable of returning wrapped and unwrapped values when chaining. lodash.sample = sample; @@ -12122,8 +12160,6 @@ }); }; - /*------------------------------------------------------------------------*/ - /** * The semantic version number. * @@ -12234,8 +12270,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); @@ -12258,7 +12299,6 @@ lodash.prototype[methodName] = function() { var args = arguments, - length = args.length, chainAll = this.__chain__, value = this.__wrapped__, isHybrid = !!this.__actions__.length, @@ -12358,8 +12398,6 @@ return lodash; } - /*--------------------------------------------------------------------------*/ - // Export lodash. var _ = runInContext(); @@ -12392,4 +12430,4 @@ // Export for a browser or Rhino. root._ = _; } -}.call(this)); \ No newline at end of file +}.call(this)); diff --git a/package.js b/package.js index f76af0b..f4f0616 100755 --- a/package.js +++ b/package.js @@ -1,9 +1,9 @@ -Npm.depends({'lodash': '3.7.0'}); +Npm.depends({'lodash': '3.8.0'}); Package.describe({ name: "stevezhu:lodash", summary: "A utility library delivering consistency, customization, performance, & extras.", - version: "3.7.0", + version: "3.8.0", git: "https://github.com/stevezhu/meteor-lodash.git" });