diff --git a/README.md b/README.md index 794572525..fa2618016 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash v3.8.0 +# lodash v3.9.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.8.0-amd -$ volo add lodash/3.8.0-amd +$ bower i lodash#3.9.0-amd +$ volo add lodash/3.9.0-amd ``` Defining a build as `'lodash'`. diff --git a/array/intersection.js b/array/intersection.js index 4f3213f9d..1c2e60d73 100644 --- a/array/intersection.js +++ b/array/intersection.js @@ -1,4 +1,4 @@ -define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/createCache', '../internal/isArrayLike'], function(baseIndexOf, cacheIndexOf, createCache, isArrayLike) { +define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/createCache', '../internal/isArrayLike', '../function/restParam'], function(baseIndexOf, cacheIndexOf, createCache, isArrayLike, restParam) { /** * Creates an array of unique values in all provided arrays using @@ -14,27 +14,19 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea * _.intersection([1, 2], [4, 2], [2, 1]); * // => [2] */ - function intersection() { - var args = [], - argsIndex = -1, - argsLength = arguments.length, - caches = [], + var intersection = restParam(function(arrays) { + var othLength = arrays.length, + othIndex = othLength, + caches = Array(length), indexOf = baseIndexOf, isCommon = true, result = []; - while (++argsIndex < argsLength) { - var value = arguments[argsIndex]; - if (isArrayLike(value)) { - args.push(value); - caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null); - } + while (othIndex--) { + var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : []; + caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null; } - argsLength = args.length; - if (argsLength < 2) { - return result; - } - var array = args[0], + var array = arrays[0], index = -1, length = array ? array.length : 0, seen = caches[0]; @@ -43,10 +35,10 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea while (++index < length) { value = array[index]; if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) { - argsIndex = argsLength; - while (--argsIndex) { - var cache = caches[argsIndex]; - if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) { + var othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) { continue outer; } } @@ -57,7 +49,7 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea } } return result; - } + }); return intersection; }); diff --git a/array/zipWith.js b/array/zipWith.js index 914e4a88c..a961409a9 100644 --- a/array/zipWith.js +++ b/array/zipWith.js @@ -22,8 +22,8 @@ define(['../function/restParam', './unzipWith'], function(restParam, unzipWith) */ var zipWith = restParam(function(arrays) { var length = arrays.length, - iteratee = arrays[length - 2], - thisArg = arrays[length - 1]; + iteratee = length > 2 ? arrays[length - 2] : undefined, + thisArg = length > 1 ? arrays[length - 1] : undefined; if (length > 2 && typeof iteratee == 'function') { length -= 2; diff --git a/chain/lodash.js b/chain/lodash.js index 581a643ed..e76777f75 100644 --- a/chain/lodash.js +++ b/chain/lodash.js @@ -45,30 +45,31 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/bas * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`, * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, - * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, - * `merge`, `mixin`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`, - * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`, - * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`, - * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, - * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, - * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`, - * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`, - * `without`, `wrap`, `xor`, `zip`, and `zipObject` + * `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, + * `memoize`, `merge`, `method`, `methodOf`, `mixin`, `negate`, `omit`, `once`, + * `pairs`, `partial`, `partialRight`, `partition`, `pick`, `plant`, `pluck`, + * `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, `rearg`, + * `reject`, `remove`, `rest`, `restParam`, `reverse`, `set`, `shuffle`, + * `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, `spread`, + * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, + * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`, + * `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `where`, `without`, + * `wrap`, `xor`, `zip`, `zipObject`, `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, - * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, - * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`, - * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite` - * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, - * `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, - * `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, `noConflict`, - * `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, - * `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, `shift`, `size`, - * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`, `startsWith`, - * `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, - * `uniqueId`, `value`, and `words` + * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `get`, + * `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, + * `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, + * `isFinite` `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, + * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, + * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lt`, `lte`, + * `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`, + * `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, + * `runInContext`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, + * `sortedLastIndex`, `startCase`, `startsWith`, `sum`, `template`, `trim`, + * `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words` * * The wrapper method `sample` will return a wrapped value when `n` is provided, * otherwise an unwrapped value is returned. diff --git a/collection/invoke.js b/collection/invoke.js index 06c0d41d6..36025ebb9 100644 --- a/collection/invoke.js +++ b/collection/invoke.js @@ -1,7 +1,7 @@ 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 + * Invokes the method at `path` of each element in `collection`, returning * an array of the results of each invoked method. Any additional arguments * are provided to each invoked method. If `methodName` is a function it is * invoked for, and `this` bound to, each element in `collection`. @@ -29,7 +29,7 @@ define(['../internal/baseEach', '../internal/invokePath', '../internal/isArrayLi result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value) { - var func = isFunc ? path : (isProp && value != null && value[path]); + var func = isFunc ? path : ((isProp && value != null) ? value[path] : null); result[++index] = func ? func.apply(value, args) : invokePath(value, path, args); }); return result; diff --git a/collection/map.js b/collection/map.js index 144e398bb..330524b68 100644 --- a/collection/map.js +++ b/collection/map.js @@ -16,7 +16,7 @@ define(['../internal/arrayMap', '../internal/baseCallback', '../internal/baseMap * callback returns `true` for elements that have the properties of the given * object, else `false`. * - * Many lodash methods are guarded to work as interatees for methods like + * Many lodash methods are guarded to work as iteratees for methods like * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. * * The guarded methods are: diff --git a/collection/reduce.js b/collection/reduce.js index 300699cfa..3b2789c40 100644 --- a/collection/reduce.js +++ b/collection/reduce.js @@ -8,7 +8,7 @@ define(['../internal/arrayReduce', '../internal/baseEach', '../internal/createRe * value. The `iteratee` is bound to `thisArg` and invoked with four arguments: * (accumulator, value, index|key, collection). * - * Many lodash methods are guarded to work as interatees for methods like + * Many lodash methods are guarded to work as iteratees for methods like * `_.reduce`, `_.reduceRight`, and `_.transform`. * * The guarded methods are: diff --git a/date/now.js b/date/now.js index 3599d302d..858be9f30 100644 --- a/date/now.js +++ b/date/now.js @@ -1,7 +1,7 @@ -define(['../lang/isNative'], function(isNative) { +define(['../internal/getNative'], function(getNative) { /* Native method references for those with the same name as other `lodash` methods. */ - var nativeNow = isNative(nativeNow = Date.now) && nativeNow; + var nativeNow = getNative(Date, 'now'); /** * Gets the number of milliseconds that have elapsed since the Unix epoch diff --git a/function/debounce.js b/function/debounce.js index d3e1a268d..9f31a40dd 100644 --- a/function/debounce.js +++ b/function/debounce.js @@ -10,12 +10,13 @@ define(['../lang/isObject', '../date/now'], function(isObject, now) { var nativeMax = Math.max; /** - * Creates a function that delays invoking `func` until after `wait` milliseconds - * have elapsed since the last time it was invoked. The created function comes - * with a `cancel` method to cancel delayed invocations. Provide an options - * object to indicate that `func` should be invoked on the leading and/or - * trailing edge of the `wait` timeout. Subsequent calls to the debounced - * function return the result of the last `func` invocation. + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked. The debounced function comes with a `cancel` method to cancel + * delayed invocations. Provide an options object to indicate that `func` + * should be invoked on the leading and/or trailing edge of the `wait` timeout. + * Subsequent calls to the debounced function return the result of the last + * `func` invocation. * * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked * on the trailing edge of the timeout only if the the debounced function is diff --git a/function/memoize.js b/function/memoize.js index c839d552c..f2eaf5a19 100644 --- a/function/memoize.js +++ b/function/memoize.js @@ -60,14 +60,14 @@ define(['../internal/MapCache'], function(MapCache) { } var memoized = function() { var args = arguments, - cache = memoized.cache, - key = resolver ? resolver.apply(this, args) : args[0]; + key = resolver ? resolver.apply(this, args) : args[0], + cache = memoized.cache; if (cache.has(key)) { return cache.get(key); } var result = func.apply(this, args); - cache.set(key, result); + memoized.cache = cache.set(key, result); return result; }; memoized.cache = new memoize.Cache; diff --git a/function/throttle.js b/function/throttle.js index 21e1288ea..9af2c15e4 100644 --- a/function/throttle.js +++ b/function/throttle.js @@ -11,12 +11,12 @@ define(['./debounce', '../lang/isObject'], function(debounce, isObject) { }; /** - * Creates a function that only invokes `func` at most once per every `wait` - * milliseconds. The created function comes with a `cancel` method to cancel - * delayed invocations. Provide an options object to indicate that `func` - * should be invoked on the leading and/or trailing edge of the `wait` timeout. - * Subsequent calls to the throttled function return the result of the last - * `func` call. + * Creates a throttled function that only invokes `func` at most once per + * every `wait` milliseconds. The throttled function comes with a `cancel` + * method to cancel delayed invocations. Provide an options object to indicate + * that `func` should be invoked on the leading and/or trailing edge of the + * `wait` timeout. Subsequent calls to the throttled function return the + * result of the last `func` call. * * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked * on the trailing edge of the timeout only if the the throttled function is diff --git a/internal/SetCache.js b/internal/SetCache.js index 52863fbe0..d1058be6a 100644 --- a/internal/SetCache.js +++ b/internal/SetCache.js @@ -1,10 +1,10 @@ -define(['./cachePush', '../lang/isNative', './root'], function(cachePush, isNative, root) { +define(['./cachePush', './getNative', './root'], function(cachePush, getNative, root) { /** Native method references. */ - var Set = isNative(Set = root.Set) && Set; + var Set = getNative(root, 'Set'); /* Native method references for those with the same name as other `lodash` methods. */ - var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate; + var nativeCreate = getNative(Object, 'create'); /** * diff --git a/internal/arrayExtremum.js b/internal/arrayExtremum.js new file mode 100644 index 000000000..32cf72e1d --- /dev/null +++ b/internal/arrayExtremum.js @@ -0,0 +1,33 @@ +define([], function() { + + /** + * A specialized version of `baseExtremum` for arrays whichs invokes `iteratee` + * with one argument: (value). + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} comparator The function used to compare values. + * @param {*} exValue The initial extremum value. + * @returns {*} Returns the extremum value. + */ + function arrayExtremum(array, iteratee, comparator, exValue) { + var index = -1, + length = array.length, + computed = exValue, + result = computed; + + while (++index < length) { + var value = array[index], + current = +iteratee(value); + + if (comparator(current, computed)) { + computed = current; + result = value; + } + } + return result; + } + + return arrayExtremum; +}); diff --git a/internal/arrayMax.js b/internal/arrayMax.js deleted file mode 100644 index 893629cb2..000000000 --- a/internal/arrayMax.js +++ /dev/null @@ -1,28 +0,0 @@ -define([], function() { - - /** Used as references for `-Infinity` and `Infinity`. */ - var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY; - - /** - * A specialized version of `_.max` for arrays without support for iteratees. - * - * @private - * @param {Array} array The array to iterate over. - * @returns {*} Returns the maximum value. - */ - function arrayMax(array) { - var index = -1, - length = array.length, - result = NEGATIVE_INFINITY; - - while (++index < length) { - var value = array[index]; - if (value > result) { - result = value; - } - } - return result; - } - - return arrayMax; -}); diff --git a/internal/arrayMin.js b/internal/arrayMin.js deleted file mode 100644 index 0d20f6d52..000000000 --- a/internal/arrayMin.js +++ /dev/null @@ -1,28 +0,0 @@ -define([], function() { - - /** Used as references for `-Infinity` and `Infinity`. */ - var POSITIVE_INFINITY = Number.POSITIVE_INFINITY; - - /** - * A specialized version of `_.min` for arrays without support for iteratees. - * - * @private - * @param {Array} array The array to iterate over. - * @returns {*} Returns the minimum value. - */ - function arrayMin(array) { - var index = -1, - length = array.length, - result = POSITIVE_INFINITY; - - while (++index < length) { - var value = array[index]; - if (value < result) { - result = value; - } - } - return result; - } - - return arrayMin; -}); diff --git a/internal/assignWith.js b/internal/assignWith.js index 5fbe021d2..69ce0cc7c 100644 --- a/internal/assignWith.js +++ b/internal/assignWith.js @@ -1,14 +1,8 @@ -define(['./getSymbols', '../object/keys'], function(getSymbols, keys) { +define(['../object/keys'], function(keys) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used for native method references. */ - var arrayProto = Array.prototype; - - /** Native method references. */ - var push = arrayProto.push; - /** * A specialized version of `_.assign` for customizing assigned values without * support for argument juggling, multiple sources, and `this` binding `customizer` @@ -21,10 +15,8 @@ define(['./getSymbols', '../object/keys'], function(getSymbols, keys) { * @returns {Object} Returns `object`. */ function assignWith(object, source, customizer) { - var props = keys(source); - push.apply(props, getSymbols(source)); - var index = -1, + props = keys(source), length = props.length; while (++index < length) { diff --git a/internal/baseAssign.js b/internal/baseAssign.js index 1271600dc..ed4b33286 100644 --- a/internal/baseAssign.js +++ b/internal/baseAssign.js @@ -1,30 +1,4 @@ -define(['./baseCopy', './getSymbols', '../lang/isNative', '../object/keys'], function(baseCopy, getSymbols, isNative, keys) { - - /** Native method references. */ - var preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions; - - /** Used as `baseAssign`. */ - var nativeAssign = (function() { - // Avoid `Object.assign` in Firefox 34-37 which have an early implementation - // with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344 - // for more details. - // - // 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. - 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; - }()); +define(['./baseCopy', '../object/keys'], function(baseCopy, keys) { /** * The base implementation of `_.assign` without support for argument juggling, @@ -35,11 +9,11 @@ define(['./baseCopy', './getSymbols', '../lang/isNative', '../object/keys'], fun * @param {Object} source The source object. * @returns {Object} Returns `object`. */ - var baseAssign = nativeAssign || function(object, source) { + function baseAssign(object, source) { return source == null ? object - : baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object)); - }; + : baseCopy(source, keys(source), object); + } return baseAssign; }); diff --git a/internal/baseAt.js b/internal/baseAt.js index ccad82974..015b09c0b 100644 --- a/internal/baseAt.js +++ b/internal/baseAt.js @@ -16,7 +16,7 @@ define(['./isArrayLike', './isIndex'], function(isArrayLike, isIndex) { var index = -1, isNil = collection == null, isArr = !isNil && isArrayLike(collection), - length = isArr && collection.length, + length = isArr ? collection.length : 0, propsLength = props.length, result = Array(propsLength); diff --git a/internal/baseCompareAscending.js b/internal/baseCompareAscending.js index c78745c17..196e170ce 100644 --- a/internal/baseCompareAscending.js +++ b/internal/baseCompareAscending.js @@ -8,19 +8,28 @@ define([], function() { * sorts them in ascending order without guaranteeing a stable sort. * * @private - * @param {*} value The value to compare to `other`. - * @param {*} other The value to compare to `value`. + * @param {*} value The value to compare. + * @param {*} other The other value to compare. * @returns {number} Returns the sort order indicator for `value`. */ function baseCompareAscending(value, other) { if (value !== other) { - var valIsReflexive = value === value, + var valIsNull = value === null, + valIsUndef = value === undefined, + valIsReflexive = value === value; + + var othIsNull = other === null, + othIsUndef = other === undefined, othIsReflexive = other === other; - if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) { + if ((value > other && !othIsNull) || !valIsReflexive || + (valIsNull && !othIsUndef && othIsReflexive) || + (valIsUndef && othIsReflexive)) { return 1; } - if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) { + if ((value < other && !valIsNull) || !othIsReflexive || + (othIsNull && !valIsUndef && valIsReflexive) || + (othIsUndef && valIsReflexive)) { return -1; } } diff --git a/internal/baseCreate.js b/internal/baseCreate.js index 3583f6993..6b41af706 100644 --- a/internal/baseCreate.js +++ b/internal/baseCreate.js @@ -1,4 +1,4 @@ -define(['../lang/isObject', './root'], function(isObject, root) { +define(['../lang/isObject'], function(isObject) { /** * The base implementation of `_.create` without support for assigning @@ -9,14 +9,14 @@ define(['../lang/isObject', './root'], function(isObject, root) { * @returns {Object} Returns the new object. */ var baseCreate = (function() { - function Object() {} + function object() {} return function(prototype) { if (isObject(prototype)) { - Object.prototype = prototype; - var result = new Object; - Object.prototype = null; + object.prototype = prototype; + var result = new object; + object.prototype = null; } - return result || root.Object(); + return result || {}; }; }()); diff --git a/internal/extremumBy.js b/internal/baseExtremum.js similarity index 51% rename from internal/extremumBy.js rename to internal/baseExtremum.js index 983a2b8f0..e48c983d9 100644 --- a/internal/extremumBy.js +++ b/internal/baseExtremum.js @@ -1,30 +1,24 @@ define(['./baseEach'], function(baseEach) { - /** Used as references for `-Infinity` and `Infinity`. */ - var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY, - POSITIVE_INFINITY = Number.POSITIVE_INFINITY; - /** * Gets the extremum value of `collection` invoking `iteratee` for each value * in `collection` to generate the criterion by which the value is ranked. - * The `iteratee` is invoked with three arguments: (value, index, collection). + * The `iteratee` is invoked with three arguments: (value, index|key, collection). * * @private * @param {Array|Object|string} collection The collection to iterate over. * @param {Function} iteratee The function invoked per iteration. - * @param {boolean} [isMin] Specify returning the minimum, instead of the - * maximum, extremum value. + * @param {Function} comparator The function used to compare values. + * @param {*} exValue The initial extremum value. * @returns {*} Returns the extremum value. */ - function extremumBy(collection, iteratee, isMin) { - var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY, - computed = exValue, + function baseExtremum(collection, iteratee, comparator, exValue) { + var computed = exValue, result = computed; baseEach(collection, function(value, index, collection) { - var current = iteratee(value, index, collection); - if ((isMin ? (current < computed) : (current > computed)) || - (current === exValue && current === result)) { + var current = +iteratee(value, index, collection); + if (comparator(current, computed) || (current === exValue && current === result)) { computed = current; result = value; } @@ -32,5 +26,5 @@ define(['./baseEach'], function(baseEach) { return result; } - return extremumBy; + return baseExtremum; }); diff --git a/internal/baseGet.js b/internal/baseGet.js index 118171720..1b037f89e 100644 --- a/internal/baseGet.js +++ b/internal/baseGet.js @@ -20,11 +20,11 @@ define(['./toObject'], function(toObject) { if (pathKey !== undefined && pathKey in toObject(object)) { path = [pathKey]; } - var index = -1, + var index = 0, length = path.length; - while (object != null && ++index < length) { - object = object[path[index]]; + while (object != null && index < length) { + object = object[path[index++]]; } return (index && index == length) ? object : undefined; } diff --git a/internal/baseIsEqual.js b/internal/baseIsEqual.js index 295eba677..64d0c31a0 100644 --- a/internal/baseIsEqual.js +++ b/internal/baseIsEqual.js @@ -1,4 +1,4 @@ -define(['./baseIsEqualDeep'], function(baseIsEqualDeep) { +define(['./baseIsEqualDeep', '../lang/isObject'], function(baseIsEqualDeep, isObject) { /** * The base implementation of `_.isEqual` without support for `this` binding @@ -14,17 +14,10 @@ define(['./baseIsEqualDeep'], function(baseIsEqualDeep) { * @returns {boolean} Returns `true` if the values are equivalent, else `false`. */ function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) { - // Exit early for identical values. if (value === other) { return true; } - var valType = typeof value, - othType = typeof other; - - // Exit early for unlike primitive values. - if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') || - value == null || other == null) { - // Return `false` unless both values are `NaN`. + if (value == null || other == null || (!isObject(value) && !isObject(other))) { return value !== value && other !== other; } return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB); diff --git a/internal/baseIsEqualDeep.js b/internal/baseIsEqualDeep.js index 23ac53740..fdc03945b 100644 --- a/internal/baseIsEqualDeep.js +++ b/internal/baseIsEqualDeep.js @@ -62,11 +62,11 @@ define(['./equalArrays', './equalByTag', './equalObjects', '../lang/isArray', '. return equalByTag(object, other, objTag); } if (!isLoose) { - var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), + othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); - if (valWrapped || othWrapped) { - return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB); + if (objIsWrapped || othIsWrapped) { + return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB); } } if (!isSameTag) { diff --git a/internal/baseIsMatch.js b/internal/baseIsMatch.js index 2093b8d58..d98c92cef 100644 --- a/internal/baseIsMatch.js +++ b/internal/baseIsMatch.js @@ -1,4 +1,4 @@ -define(['./baseIsEqual'], function(baseIsEqual) { +define(['./baseIsEqual', './toObject'], function(baseIsEqual, toObject) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -9,41 +9,43 @@ define(['./baseIsEqual'], function(baseIsEqual) { * * @private * @param {Object} object The object to inspect. - * @param {Array} props The source property names to match. - * @param {Array} values The source values to match. - * @param {Array} strictCompareFlags Strict comparison flags for source values. + * @param {Array} matchData The propery names, values, and compare flags to match. * @param {Function} [customizer] The function to customize comparing objects. * @returns {boolean} Returns `true` if `object` is a match, else `false`. */ - function baseIsMatch(object, props, values, strictCompareFlags, customizer) { - var index = -1, - length = props.length, + function baseIsMatch(object, matchData, customizer) { + var index = matchData.length, + length = index, noCustomizer = !customizer; - while (++index < length) { - if ((noCustomizer && strictCompareFlags[index]) - ? values[index] !== object[props[index]] - : !(props[index] in object) + if (object == null) { + return !length; + } + object = toObject(object); + while (index--) { + var data = matchData[index]; + if ((noCustomizer && data[2]) + ? data[1] !== object[data[0]] + : !(data[0] in object) ) { return false; } } - index = -1; while (++index < length) { - var key = props[index], + data = matchData[index]; + var key = data[0], objValue = object[key], - srcValue = values[index]; + srcValue = data[1]; - if (noCustomizer && strictCompareFlags[index]) { - var result = objValue !== undefined || (key in object); - } else { - result = customizer ? customizer(objValue, srcValue, key) : undefined; - if (result === undefined) { - result = baseIsEqual(srcValue, objValue, customizer, true); + if (noCustomizer && data[2]) { + if (objValue === undefined && !(key in object)) { + return false; + } + } else { + var result = customizer ? customizer(objValue, srcValue, key) : undefined; + if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) { + return false; } - } - if (!result) { - return false; } } return true; diff --git a/internal/baseMatches.js b/internal/baseMatches.js index fbde9aac8..a4700e1b1 100644 --- a/internal/baseMatches.js +++ b/internal/baseMatches.js @@ -1,4 +1,4 @@ -define(['./baseIsMatch', '../utility/constant', './isStrictComparable', '../object/keys', './toObject'], function(baseIsMatch, constant, isStrictComparable, keys, toObject) { +define(['./baseIsMatch', './getMatchData', './toObject'], function(baseIsMatch, getMatchData, toObject) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -11,35 +11,20 @@ define(['./baseIsMatch', '../utility/constant', './isStrictComparable', '../obje * @returns {Function} Returns the new function. */ function baseMatches(source) { - var props = keys(source), - length = props.length; + var matchData = getMatchData(source); + if (matchData.length == 1 && matchData[0][2]) { + var key = matchData[0][0], + value = matchData[0][1]; - if (!length) { - return constant(true); - } - if (length == 1) { - var key = props[0], - value = source[key]; - - if (isStrictComparable(value)) { - return function(object) { - if (object == null) { - return false; - } - return object[key] === value && (value !== undefined || (key in toObject(object))); - }; - } - } - var values = Array(length), - strictCompareFlags = Array(length); - - while (length--) { - value = source[props[length]]; - values[length] = value; - strictCompareFlags[length] = isStrictComparable(value); + return function(object) { + if (object == null) { + return false; + } + return object[key] === value && (value !== undefined || (key in toObject(object))); + }; } return function(object) { - return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags); + return baseIsMatch(object, matchData); }; } diff --git a/internal/baseMatchesProperty.js b/internal/baseMatchesProperty.js index 16bbc457c..3a2969080 100644 --- a/internal/baseMatchesProperty.js +++ b/internal/baseMatchesProperty.js @@ -9,12 +9,12 @@ define(['./baseGet', './baseIsEqual', './baseSlice', '../lang/isArray', './isKey * * @private * @param {string} path The path of the property to get. - * @param {*} value The value to compare. + * @param {*} srcValue The value to compare. * @returns {Function} Returns the new function. */ - function baseMatchesProperty(path, value) { + function baseMatchesProperty(path, srcValue) { var isArr = isArray(path), - isCommon = isKey(path) && isStrictComparable(value), + isCommon = isKey(path) && isStrictComparable(srcValue), pathKey = (path + ''); path = toPath(path); @@ -32,9 +32,9 @@ define(['./baseGet', './baseIsEqual', './baseSlice', '../lang/isArray', './isKey key = last(path); object = toObject(object); } - return object[key] === value - ? (value !== undefined || (key in object)) - : baseIsEqual(value, object[key], null, true); + return object[key] === srcValue + ? (srcValue !== undefined || (key in object)) + : baseIsEqual(srcValue, object[key], undefined, true); }; } diff --git a/internal/baseMerge.js b/internal/baseMerge.js index 91ab64ba9..fe6519b7e 100644 --- a/internal/baseMerge.js +++ b/internal/baseMerge.js @@ -1,14 +1,8 @@ -define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './isArrayLike', '../lang/isObject', './isObjectLike', '../lang/isTypedArray', '../object/keys'], function(arrayEach, baseMergeDeep, getSymbols, isArray, isArrayLike, isObject, isObjectLike, isTypedArray, keys) { +define(['./arrayEach', './baseMergeDeep', '../lang/isArray', './isArrayLike', '../lang/isObject', './isObjectLike', '../lang/isTypedArray', '../object/keys'], function(arrayEach, baseMergeDeep, isArray, isArrayLike, isObject, isObjectLike, isTypedArray, keys) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used for native method references. */ - var arrayProto = Array.prototype; - - /** Native method references. */ - var push = arrayProto.push; - /** * The base implementation of `_.merge` without support for argument juggling, * multiple sources, and `this` binding `customizer` functions. @@ -25,11 +19,9 @@ define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './ if (!isObject(object)) { return object; } - var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)); - if (!isSrcArr) { - var props = keys(source); - push.apply(props, getSymbols(source)); - } + var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)), + props = isSrcArr ? null : keys(source); + arrayEach(props || source, function(srcValue, key) { if (props) { key = srcValue; @@ -48,7 +40,7 @@ define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './ if (isCommon) { result = srcValue; } - if ((isSrcArr || result !== undefined) && + if ((result !== undefined || (isSrcArr && !(key in object))) && (isCommon || (result === result ? (result !== value) : (value === value)))) { object[key] = result; } diff --git a/internal/basePullAt.js b/internal/basePullAt.js index c5b6be4ca..b9f10441e 100644 --- a/internal/basePullAt.js +++ b/internal/basePullAt.js @@ -18,7 +18,7 @@ define(['./isIndex'], function(isIndex) { function basePullAt(array, indexes) { var length = array ? indexes.length : 0; while (length--) { - var index = parseFloat(indexes[length]); + var index = indexes[length]; if (index != previous && isIndex(index)) { var previous = index; splice.call(array, index, 1); diff --git a/internal/baseToString.js b/internal/baseToString.js index ffaf1dd7d..bccd2b79c 100644 --- a/internal/baseToString.js +++ b/internal/baseToString.js @@ -1,7 +1,7 @@ define([], function() { /** - * Converts `value` to a string if it is not one. An empty string is returned + * Converts `value` to a string if it's not one. An empty string is returned * for `null` or `undefined` values. * * @private diff --git a/internal/binaryIndex.js b/internal/binaryIndex.js index 68ca3cc3d..72fb07b04 100644 --- a/internal/binaryIndex.js +++ b/internal/binaryIndex.js @@ -1,7 +1,7 @@ define(['./binaryIndexBy', '../utility/identity'], function(binaryIndexBy, identity) { /** Used as references for the maximum length and index of an array. */ - var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1, + var MAX_ARRAY_LENGTH = 4294967295, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; /** @@ -24,7 +24,7 @@ define(['./binaryIndexBy', '../utility/identity'], function(binaryIndexBy, ident var mid = (low + high) >>> 1, computed = array[mid]; - if (retHighest ? (computed <= value) : (computed < value)) { + if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) { low = mid + 1; } else { high = mid; diff --git a/internal/binaryIndexBy.js b/internal/binaryIndexBy.js index 7b27ad368..3c0119cd0 100644 --- a/internal/binaryIndexBy.js +++ b/internal/binaryIndexBy.js @@ -10,7 +10,7 @@ define([], function() { var nativeMin = Math.min; /** Used as references for the maximum length and index of an array. */ - var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1, + var MAX_ARRAY_LENGTH = 4294967295, MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1; /** @@ -32,17 +32,23 @@ define([], function() { var low = 0, high = array ? array.length : 0, valIsNaN = value !== value, + valIsNull = value === null, valIsUndef = value === undefined; while (low < high) { var mid = floor((low + high) / 2), computed = iteratee(array[mid]), + isDef = computed !== undefined, isReflexive = computed === computed; if (valIsNaN) { var setLow = isReflexive || retHighest; + } else if (valIsNull) { + setLow = isReflexive && isDef && (retHighest || computed != null); } else if (valIsUndef) { - setLow = isReflexive && (retHighest || computed !== undefined); + setLow = isReflexive && (retHighest || isDef); + } else if (computed == null) { + setLow = false; } else { setLow = retHighest ? (computed <= value) : (computed < value); } diff --git a/internal/bufferClone.js b/internal/bufferClone.js index c59960440..f3cb4a0a6 100644 --- a/internal/bufferClone.js +++ b/internal/bufferClone.js @@ -1,10 +1,10 @@ -define(['../utility/constant', '../lang/isNative', './root'], function(constant, isNative, root) { +define(['../utility/constant', './getNative', './root'], function(constant, getNative, root) { /** Native method references. */ - var ArrayBuffer = isNative(ArrayBuffer = root.ArrayBuffer) && ArrayBuffer, - bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice, + var ArrayBuffer = getNative(root, 'ArrayBuffer'), + bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'), floor = Math.floor, - Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array; + Uint8Array = getNative(root, 'Uint8Array'); /** Used to clone array buffers. */ var Float64Array = (function() { @@ -12,10 +12,10 @@ define(['../utility/constant', '../lang/isNative', './root'], function(constant, // where the array buffer's `byteLength` is not a multiple of the typed // array's `BYTES_PER_ELEMENT`. try { - var func = isNative(func = root.Float64Array) && func, + var func = getNative(root, 'Float64Array'), result = new func(new ArrayBuffer(10), 0, 1) && func; } catch(e) {} - return result; + return result || null; }()); /** Used as the size, in bytes, of each `Float64Array` element. */ diff --git a/internal/charAtCallback.js b/internal/charAtCallback.js deleted file mode 100644 index a96fd83e5..000000000 --- a/internal/charAtCallback.js +++ /dev/null @@ -1,15 +0,0 @@ -define([], function() { - - /** - * Used by `_.max` and `_.min` as the default callback for string values. - * - * @private - * @param {string} string The string to inspect. - * @returns {number} Returns the code unit of the first character of the string. - */ - function charAtCallback(string) { - return string.charCodeAt(0); - } - - return charAtCallback; -}); diff --git a/internal/createAssigner.js b/internal/createAssigner.js index a0cb7fd15..57807fd36 100644 --- a/internal/createAssigner.js +++ b/internal/createAssigner.js @@ -1,5 +1,8 @@ define(['./bindCallback', './isIterateeCall', '../function/restParam'], function(bindCallback, isIterateeCall, restParam) { + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + /** * Creates a function that assigns properties of source object(s) to a given * destination object. @@ -14,19 +17,19 @@ define(['./bindCallback', './isIterateeCall', '../function/restParam'], function return restParam(function(object, sources) { var index = -1, length = object == null ? 0 : sources.length, - customizer = length > 2 && sources[length - 2], - guard = length > 2 && sources[2], - thisArg = length > 1 && sources[length - 1]; + customizer = length > 2 ? sources[length - 2] : undefined, + guard = length > 2 ? sources[2] : undefined, + thisArg = length > 1 ? sources[length - 1] : undefined; if (typeof customizer == 'function') { customizer = bindCallback(customizer, thisArg, 5); length -= 2; } else { - customizer = typeof thisArg == 'function' ? thisArg : null; + customizer = typeof thisArg == 'function' ? thisArg : undefined; length -= (customizer ? 1 : 0); } if (guard && isIterateeCall(sources[0], sources[1], guard)) { - customizer = length < 3 ? null : customizer; + customizer = length < 3 ? undefined : customizer; length = 1; } while (++index < length) { diff --git a/internal/createCache.js b/internal/createCache.js index 5d62a371f..adf6fc503 100644 --- a/internal/createCache.js +++ b/internal/createCache.js @@ -1,10 +1,10 @@ -define(['./SetCache', '../utility/constant', '../lang/isNative', './root'], function(SetCache, constant, isNative, root) { +define(['./SetCache', '../utility/constant', './getNative', './root'], function(SetCache, constant, getNative, root) { /** Native method references. */ - var Set = isNative(Set = root.Set) && Set; + var Set = getNative(root, 'Set'); /* Native method references for those with the same name as other `lodash` methods. */ - var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate; + var nativeCreate = getNative(Object, 'create'); /** * Creates a `Set` cache object to optimize linear searches of large arrays. diff --git a/internal/createCtorWrapper.js b/internal/createCtorWrapper.js index f2b176d09..72df566a1 100644 --- a/internal/createCtorWrapper.js +++ b/internal/createCtorWrapper.js @@ -10,8 +10,20 @@ define(['./baseCreate', '../lang/isObject'], function(baseCreate, isObject) { */ function createCtorWrapper(Ctor) { return function() { + // Use a `switch` statement to work with class constructors. + // See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-call-thisargument-argumentslist + // for more details. + var args = arguments; + switch (args.length) { + case 0: return new Ctor; + case 1: return new Ctor(args[0]); + case 2: return new Ctor(args[0], args[1]); + case 3: return new Ctor(args[0], args[1], args[2]); + case 4: return new Ctor(args[0], args[1], args[2], args[3]); + case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); + } var thisBinding = baseCreate(Ctor.prototype), - result = Ctor.apply(thisBinding, arguments); + result = Ctor.apply(thisBinding, args); // Mimic the constructor's `return` behavior. // See https://es5.github.io/#x13.2.2 for more details. diff --git a/internal/createExtremum.js b/internal/createExtremum.js index d391b94aa..1c7d76b74 100644 --- a/internal/createExtremum.js +++ b/internal/createExtremum.js @@ -1,31 +1,27 @@ -define(['./baseCallback', './charAtCallback', './extremumBy', '../lang/isArray', './isIterateeCall', '../lang/isString', './toIterable'], function(baseCallback, charAtCallback, extremumBy, isArray, isIterateeCall, isString, toIterable) { +define(['./arrayExtremum', './baseCallback', './baseExtremum', './isIterateeCall', './toIterable'], function(arrayExtremum, baseCallback, baseExtremum, isIterateeCall, toIterable) { /** * Creates a `_.max` or `_.min` function. * * @private - * @param {Function} arrayFunc The function to get the extremum value from an array. - * @param {boolean} [isMin] Specify returning the minimum, instead of the maximum, - * extremum value. + * @param {Function} comparator The function used to compare values. + * @param {*} exValue The initial extremum value. * @returns {Function} Returns the new extremum function. */ - function createExtremum(arrayFunc, isMin) { + function createExtremum(comparator, exValue) { return function(collection, iteratee, thisArg) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { iteratee = null; } - var noIteratee = iteratee == null; - - iteratee = noIteratee ? iteratee : baseCallback(iteratee, thisArg, 3); - if (noIteratee) { - var isArr = isArray(collection); - if (!isArr && isString(collection)) { - iteratee = charAtCallback; - } else { - return arrayFunc(isArr ? collection : toIterable(collection)); + iteratee = baseCallback(iteratee, thisArg, 3); + if (iteratee.length == 1) { + collection = toIterable(collection); + var result = arrayExtremum(collection, iteratee, comparator, exValue); + if (!(collection.length && result === exValue)) { + return result; } } - return extremumBy(collection, iteratee, isMin); + return baseExtremum(collection, iteratee, comparator, exValue); }; } diff --git a/internal/createFlow.js b/internal/createFlow.js index 27dbe1097..bdd93945e 100644 --- a/internal/createFlow.js +++ b/internal/createFlow.js @@ -18,11 +18,8 @@ define(['./LodashWrapper', './getData', './getFuncName', '../lang/isArray', './i */ function createFlow(fromRight) { return function() { - var length = arguments.length; - if (!length) { - return function() { return arguments[0]; }; - } var wrapper, + length = arguments.length, index = fromRight ? length : -1, leftIndex = 0, funcs = Array(length); @@ -32,15 +29,17 @@ define(['./LodashWrapper', './getData', './getFuncName', '../lang/isArray', './i if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - var funcName = wrapper ? '' : getFuncName(func); - wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper; + if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') { + wrapper = new LodashWrapper([]); + } } index = wrapper ? -1 : length; while (++index < length) { func = funcs[index]; - funcName = getFuncName(func); - var data = funcName == 'wrapper' ? getData(func) : null; + var funcName = getFuncName(func), + data = funcName == 'wrapper' ? getData(func) : null; + 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 { @@ -53,7 +52,7 @@ define(['./LodashWrapper', './getData', './getFuncName', '../lang/isArray', './i return wrapper.plant(args[0]).value(); } var index = 0, - result = funcs[index].apply(this, args); + result = length ? funcs[index].apply(this, args) : args[0]; while (++index < length) { result = funcs[index].call(this, result); diff --git a/internal/createHybridWrapper.js b/internal/createHybridWrapper.js index e9bcb437a..2a9767b50 100644 --- a/internal/createHybridWrapper.js +++ b/internal/createHybridWrapper.js @@ -39,10 +39,8 @@ define(['./arrayCopy', './composeArgs', './composeArgsRight', './createCtorWrapp isBindKey = bitmask & BIND_KEY_FLAG, isCurry = bitmask & CURRY_FLAG, isCurryBound = bitmask & CURRY_BOUND_FLAG, - isCurryRight = bitmask & CURRY_RIGHT_FLAG; - - var Ctor = !isBindKey && createCtorWrapper(func), - key = func; + isCurryRight = bitmask & CURRY_RIGHT_FLAG, + Ctor = isBindKey ? null : createCtorWrapper(func); function wrapper() { // Avoid `arguments` object use disqualifying optimizations by @@ -89,17 +87,18 @@ define(['./arrayCopy', './composeArgs', './composeArgsRight', './createCtorWrapp return result; } } - var thisBinding = isBind ? thisArg : this; - if (isBindKey) { - func = thisBinding[key]; - } + var thisBinding = isBind ? thisArg : this, + fn = isBindKey ? thisBinding[func] : func; + if (argPos) { args = reorder(args, argPos); } if (isAry && ary < args.length) { args.length = ary; } - var fn = (this && this !== root && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func; + if (this && this !== root && this instanceof wrapper) { + fn = Ctor || createCtorWrapper(func); + } return fn.apply(thisBinding, args); } return wrapper; diff --git a/internal/equalArrays.js b/internal/equalArrays.js index c6e38c57c..bf57df658 100644 --- a/internal/equalArrays.js +++ b/internal/equalArrays.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./arraySome'], function(arraySome) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -20,40 +20,35 @@ define([], function() { function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) { var index = -1, arrLength = array.length, - othLength = other.length, - result = true; + othLength = other.length; if (arrLength != othLength && !(isLoose && othLength > arrLength)) { return false; } - // Deep compare the contents, ignoring non-numeric properties. - while (result && ++index < arrLength) { + // Ignore non-index properties. + while (++index < arrLength) { var arrValue = array[index], - othValue = other[index]; + othValue = other[index], + result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined; - result = undefined; - if (customizer) { - result = isLoose - ? customizer(othValue, arrValue, index) - : customizer(arrValue, othValue, index); - } - if (result === undefined) { - // Recursively compare arrays (susceptible to call stack limits). - if (isLoose) { - var othIndex = othLength; - while (othIndex--) { - othValue = other[othIndex]; - result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); - if (result) { - break; - } - } - } else { - result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); + if (result !== undefined) { + if (result) { + continue; } + return false; + } + // Recursively compare arrays (susceptible to call stack limits). + if (isLoose) { + if (!arraySome(other, function(othValue) { + return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); + })) { + return false; + } + } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) { + return false; } } - return !!result; + return true; } return equalArrays; diff --git a/internal/equalObjects.js b/internal/equalObjects.js index 1ba272f22..612404e43 100644 --- a/internal/equalObjects.js +++ b/internal/equalObjects.js @@ -32,29 +32,22 @@ define(['../object/keys'], function(keys) { if (objLength != othLength && !isLoose) { return false; } - var skipCtor = isLoose, - index = -1; - - while (++index < objLength) { - var key = objProps[index], - result = isLoose ? key in other : hasOwnProperty.call(other, key); - - if (result) { - var objValue = object[key], - othValue = other[key]; - - result = undefined; - if (customizer) { - result = isLoose - ? customizer(othValue, objValue, key) - : customizer(objValue, othValue, key); - } - if (result === undefined) { - // Recursively compare objects (susceptible to call stack limits). - result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB); - } + var index = objLength; + while (index--) { + var key = objProps[index]; + if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) { + return false; } - if (!result) { + } + var skipCtor = isLoose; + while (++index < objLength) { + key = objProps[index]; + var objValue = object[key], + othValue = other[key], + result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined; + + // Recursively compare objects (susceptible to call stack limits). + if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) { return false; } skipCtor || (skipCtor = key == 'constructor'); diff --git a/internal/getFuncName.js b/internal/getFuncName.js index d044a2dfa..5dbf450d3 100644 --- a/internal/getFuncName.js +++ b/internal/getFuncName.js @@ -1,4 +1,4 @@ -define(['./baseProperty', '../utility/constant', './realNames', '../support'], function(baseProperty, constant, realNames, support) { +define(['./realNames'], function(realNames) { /** * Gets the name of `func`. @@ -7,29 +7,20 @@ define(['./baseProperty', '../utility/constant', './realNames', '../support'], f * @param {Function} func The function to query. * @returns {string} Returns the function name. */ - var getFuncName = (function() { - if (!support.funcNames) { - return constant(''); - } - if (constant.name == 'constant') { - return baseProperty('name'); - } - return function(func) { - var result = func.name, - array = realNames[result], - length = array ? array.length : 0; + function getFuncName(func) { + var result = func.name, + array = realNames[result], + length = array ? array.length : 0; - while (length--) { - var data = array[length], - otherFunc = data.func; - - if (otherFunc == null || otherFunc == func) { - return data.name; - } + while (length--) { + var data = array[length], + otherFunc = data.func; + if (otherFunc == null || otherFunc == func) { + return data.name; } - return result; - }; - }()); + } + return result; + } return getFuncName; }); diff --git a/internal/getMatchData.js b/internal/getMatchData.js new file mode 100644 index 000000000..e72a66a80 --- /dev/null +++ b/internal/getMatchData.js @@ -0,0 +1,21 @@ +define(['./isStrictComparable', '../object/pairs'], function(isStrictComparable, pairs) { + + /** + * Gets the propery names, values, and compare flags of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the match data of `object`. + */ + function getMatchData(object) { + var result = pairs(object), + length = result.length; + + while (length--) { + result[length][2] = isStrictComparable(result[length][1]); + } + return result; + } + + return getMatchData; +}); diff --git a/internal/getNative.js b/internal/getNative.js new file mode 100644 index 000000000..7d821b31a --- /dev/null +++ b/internal/getNative.js @@ -0,0 +1,20 @@ +define(['../lang/isNative'], function(isNative) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ + function getNative(object, key) { + var value = object == null ? undefined : object[key]; + return isNative(value) ? value : undefined; + } + + return getNative; +}); diff --git a/internal/getSymbols.js b/internal/getSymbols.js deleted file mode 100644 index c85234718..000000000 --- a/internal/getSymbols.js +++ /dev/null @@ -1,18 +0,0 @@ -define(['../utility/constant', '../lang/isNative', './toObject'], function(constant, isNative, toObject) { - - /** Native method references. */ - var getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols; - - /** - * Creates an array of the own symbols of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of symbols. - */ - var getSymbols = !getOwnPropertySymbols ? constant([]) : function(object) { - return getOwnPropertySymbols(toObject(object)); - }; - - return getSymbols; -}); diff --git a/internal/isIndex.js b/internal/isIndex.js index 8715429a6..92d7c6d2b 100644 --- a/internal/isIndex.js +++ b/internal/isIndex.js @@ -4,7 +4,7 @@ define([], function() { * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) * of an array-like value. */ - var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; + var MAX_SAFE_INTEGER = 9007199254740991; /** * Checks if `value` is a valid array-like index. @@ -15,7 +15,7 @@ define([], function() { * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex(value, length) { - value = +value; + value = typeof value == 'number' ? value : parseFloat(value); length = length == null ? MAX_SAFE_INTEGER : length; return value > -1 && value % 1 == 0 && value < length; } diff --git a/internal/isLength.js b/internal/isLength.js index 49fb58d24..f96fa0b73 100644 --- a/internal/isLength.js +++ b/internal/isLength.js @@ -4,7 +4,7 @@ define([], function() { * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) * of an array-like value. */ - var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; + var MAX_SAFE_INTEGER = 9007199254740991; /** * Checks if `value` is a valid array-like length. diff --git a/internal/metaMap.js b/internal/metaMap.js index 4fae003ea..60dfa228e 100644 --- a/internal/metaMap.js +++ b/internal/metaMap.js @@ -1,7 +1,7 @@ -define(['../lang/isNative', './root'], function(isNative, root) { +define(['./getNative', './root'], function(getNative, root) { /** Native method references. */ - var WeakMap = isNative(WeakMap = root.WeakMap) && WeakMap; + var WeakMap = getNative(root, 'WeakMap'); /** Used to store function metadata. */ var metaMap = WeakMap && new WeakMap; diff --git a/internal/root.js b/internal/root.js index 7f2ef4908..10a426173 100644 --- a/internal/root.js +++ b/internal/root.js @@ -24,7 +24,7 @@ define([], function() { /** * Used as a reference to the global object. * - * The `this` value is used if it is the global object to avoid Greasemonkey's + * The `this` value is used if it's the global object to avoid Greasemonkey's * restricted `window` object, otherwise the `window` object is used. */ var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this; diff --git a/internal/shimKeys.js b/internal/shimKeys.js index 030c27982..4a9d432f6 100644 --- a/internal/shimKeys.js +++ b/internal/shimKeys.js @@ -1,4 +1,4 @@ -define(['../lang/isArguments', '../lang/isArray', './isIndex', './isLength', '../object/keysIn', '../support'], function(isArguments, isArray, isIndex, isLength, keysIn, support) { +define(['../lang/isArguments', '../lang/isArray', './isIndex', './isLength', '../object/keysIn'], function(isArguments, isArray, isIndex, isLength, keysIn) { /** Used for native method references. */ var objectProto = Object.prototype; @@ -19,8 +19,8 @@ define(['../lang/isArguments', '../lang/isArray', './isIndex', './isLength', '.. propsLength = props.length, length = propsLength && object.length; - var allowIndexes = length && isLength(length) && - (isArray(object) || (support.nonEnumArgs && isArguments(object))); + var allowIndexes = !!length && isLength(length) && + (isArray(object) || isArguments(object)); var index = -1, result = []; diff --git a/internal/toIterable.js b/internal/toIterable.js index 1054a845f..c8f9a562c 100644 --- a/internal/toIterable.js +++ b/internal/toIterable.js @@ -1,7 +1,7 @@ define(['./isArrayLike', '../lang/isObject', '../object/values'], function(isArrayLike, isObject, values) { /** - * Converts `value` to an array-like object if it is not one. + * Converts `value` to an array-like object if it's not one. * * @private * @param {*} value The value to process. diff --git a/internal/toObject.js b/internal/toObject.js index 561b539d7..cabcf9963 100644 --- a/internal/toObject.js +++ b/internal/toObject.js @@ -1,7 +1,7 @@ define(['../lang/isObject'], function(isObject) { /** - * Converts `value` to an object if it is not one. + * Converts `value` to an object if it's not one. * * @private * @param {*} value The value to process. diff --git a/internal/toPath.js b/internal/toPath.js index 624c8f4c9..3bafab1fd 100644 --- a/internal/toPath.js +++ b/internal/toPath.js @@ -7,7 +7,7 @@ define(['./baseToString', '../lang/isArray'], function(baseToString, isArray) { var reEscapeChar = /\\(\\)?/g; /** - * Converts `value` to property path array if it is not one. + * Converts `value` to property path array if it's not one. * * @private * @param {*} value The value to process. diff --git a/lang.js b/lang.js index cc1ecb9e5..f15f29d2d 100644 --- a/lang.js +++ b/lang.js @@ -1,7 +1,10 @@ -define(['./lang/clone', './lang/cloneDeep', './lang/isArguments', './lang/isArray', './lang/isBoolean', './lang/isDate', './lang/isElement', './lang/isEmpty', './lang/isEqual', './lang/isError', './lang/isFinite', './lang/isFunction', './lang/isMatch', './lang/isNaN', './lang/isNative', './lang/isNull', './lang/isNumber', './lang/isObject', './lang/isPlainObject', './lang/isRegExp', './lang/isString', './lang/isTypedArray', './lang/isUndefined', './lang/toArray', './lang/toPlainObject'], function(clone, cloneDeep, isArguments, isArray, isBoolean, isDate, isElement, isEmpty, isEqual, isError, isFinite, isFunction, isMatch, isNaN, isNative, isNull, isNumber, isObject, isPlainObject, isRegExp, isString, isTypedArray, isUndefined, toArray, toPlainObject) { +define(['./lang/clone', './lang/cloneDeep', './lang/eq', './lang/gt', './lang/gte', './lang/isArguments', './lang/isArray', './lang/isBoolean', './lang/isDate', './lang/isElement', './lang/isEmpty', './lang/isEqual', './lang/isError', './lang/isFinite', './lang/isFunction', './lang/isMatch', './lang/isNaN', './lang/isNative', './lang/isNull', './lang/isNumber', './lang/isObject', './lang/isPlainObject', './lang/isRegExp', './lang/isString', './lang/isTypedArray', './lang/isUndefined', './lang/lt', './lang/lte', './lang/toArray', './lang/toPlainObject'], function(clone, cloneDeep, eq, gt, gte, isArguments, isArray, isBoolean, isDate, isElement, isEmpty, isEqual, isError, isFinite, isFunction, isMatch, isNaN, isNative, isNull, isNumber, isObject, isPlainObject, isRegExp, isString, isTypedArray, isUndefined, lt, lte, toArray, toPlainObject) { return { 'clone': clone, 'cloneDeep': cloneDeep, + 'eq': eq, + 'gt': gt, + 'gte': gte, 'isArguments': isArguments, 'isArray': isArray, 'isBoolean': isBoolean, @@ -23,6 +26,8 @@ define(['./lang/clone', './lang/cloneDeep', './lang/isArguments', './lang/isArra 'isString': isString, 'isTypedArray': isTypedArray, 'isUndefined': isUndefined, + 'lt': lt, + 'lte': lte, 'toArray': toArray, 'toPlainObject': toPlainObject }; diff --git a/lang/clone.js b/lang/clone.js index 049e98f04..beadc783d 100644 --- a/lang/clone.js +++ b/lang/clone.js @@ -60,8 +60,9 @@ define(['../internal/baseClone', '../internal/bindCallback', '../internal/isIter customizer = isDeep; isDeep = false; } - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); - return baseClone(value, isDeep, customizer); + return typeof customizer == 'function' + ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1)) + : baseClone(value, isDeep); } return clone; diff --git a/lang/cloneDeep.js b/lang/cloneDeep.js index ba3745d1a..ea7cb59f5 100644 --- a/lang/cloneDeep.js +++ b/lang/cloneDeep.js @@ -46,8 +46,9 @@ define(['../internal/baseClone', '../internal/bindCallback'], function(baseClone * // => 20 */ function cloneDeep(value, customizer, thisArg) { - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); - return baseClone(value, true, customizer); + return typeof customizer == 'function' + ? baseClone(value, true, bindCallback(customizer, thisArg, 1)) + : baseClone(value, true); } return cloneDeep; diff --git a/lang/eq.js b/lang/eq.js new file mode 100644 index 000000000..7459fa8af --- /dev/null +++ b/lang/eq.js @@ -0,0 +1,3 @@ +define(["./isEqual"], function(isEqual) { + return isEqual; +}); diff --git a/lang/gt.js b/lang/gt.js new file mode 100644 index 000000000..0c75014fd --- /dev/null +++ b/lang/gt.js @@ -0,0 +1,28 @@ +define([], function() { + + /** + * Checks if `value` is greater than `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`. + * @example + * + * _.gt(3, 1); + * // => true + * + * _.gt(3, 3); + * // => false + * + * _.gt(1, 3); + * // => false + */ + function gt(value, other) { + return value > other; + } + + return gt; +}); diff --git a/lang/gte.js b/lang/gte.js new file mode 100644 index 000000000..b4e4ed2bd --- /dev/null +++ b/lang/gte.js @@ -0,0 +1,28 @@ +define([], function() { + + /** + * Checks if `value` is greater than or equal to `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`. + * @example + * + * _.gte(3, 1); + * // => true + * + * _.gte(3, 3); + * // => true + * + * _.gte(1, 3); + * // => false + */ + function gte(value, other) { + return value >= other; + } + + return gte; +}); diff --git a/lang/isArray.js b/lang/isArray.js index 29149adbc..d37ad32cd 100644 --- a/lang/isArray.js +++ b/lang/isArray.js @@ -1,4 +1,4 @@ -define(['../internal/isLength', './isNative', '../internal/isObjectLike'], function(isLength, isNative, isObjectLike) { +define(['../internal/getNative', '../internal/isLength', '../internal/isObjectLike'], function(getNative, isLength, isObjectLike) { /** `Object#toString` result references. */ var arrayTag = '[object Array]'; @@ -13,7 +13,7 @@ define(['../internal/isLength', './isNative', '../internal/isObjectLike'], funct var objToString = objectProto.toString; /* Native method references for those with the same name as other `lodash` methods. */ - var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray; + var nativeIsArray = getNative(Array, 'isArray'); /** * Checks if `value` is classified as an `Array` object. diff --git a/lang/isEqual.js b/lang/isEqual.js index 581773f31..239d22966 100644 --- a/lang/isEqual.js +++ b/lang/isEqual.js @@ -1,4 +1,4 @@ -define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isStrictComparable'], function(baseIsEqual, bindCallback, isStrictComparable) { +define(['../internal/baseIsEqual', '../internal/bindCallback'], function(baseIsEqual, bindCallback) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -18,6 +18,7 @@ define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isSt * * @static * @memberOf _ + * @alias eq * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. @@ -47,12 +48,9 @@ define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isSt * // => true */ function isEqual(value, other, customizer, thisArg) { - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); - if (!customizer && isStrictComparable(value) && isStrictComparable(other)) { - return value === other; - } + customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined; var result = customizer ? customizer(value, other) : undefined; - return result === undefined ? baseIsEqual(value, other, customizer) : !!result; + return result === undefined ? baseIsEqual(value, other, customizer) : !!result; } return isEqual; diff --git a/lang/isFinite.js b/lang/isFinite.js index fb3029bd4..f3701741d 100644 --- a/lang/isFinite.js +++ b/lang/isFinite.js @@ -1,8 +1,8 @@ -define(['./isNative', '../internal/root'], function(isNative, root) { +define(['../internal/getNative', '../internal/root'], function(getNative, root) { /* Native method references for those with the same name as other `lodash` methods. */ var nativeIsFinite = root.isFinite, - nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite; + nativeNumIsFinite = getNative(Number, 'isFinite'); /** * Checks if `value` is a finite primitive number. diff --git a/lang/isFunction.js b/lang/isFunction.js index ead1c8f38..3e6b4cfbc 100644 --- a/lang/isFunction.js +++ b/lang/isFunction.js @@ -1,4 +1,4 @@ -define(['../internal/baseIsFunction', './isNative', '../internal/root'], function(baseIsFunction, isNative, root) { +define(['../internal/baseIsFunction', '../internal/getNative', '../internal/root'], function(baseIsFunction, getNative, root) { /** `Object#toString` result references. */ var funcTag = '[object Function]'; @@ -13,7 +13,7 @@ define(['../internal/baseIsFunction', './isNative', '../internal/root'], functio var objToString = objectProto.toString; /** Native method references. */ - var Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array; + var Uint8Array = getNative(root, 'Uint8Array'); /** * Checks if `value` is classified as a `Function` object. diff --git a/lang/isMatch.js b/lang/isMatch.js index 27e786035..930542c8c 100644 --- a/lang/isMatch.js +++ b/lang/isMatch.js @@ -1,4 +1,4 @@ -define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isStrictComparable', '../object/keys', '../internal/toObject'], function(baseIsMatch, bindCallback, isStrictComparable, keys, toObject) { +define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/getMatchData'], function(baseIsMatch, bindCallback, getMatchData) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -43,33 +43,8 @@ define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isSt * // => true */ function isMatch(object, source, customizer, thisArg) { - var props = keys(source), - length = props.length; - - if (!length) { - return true; - } - if (object == null) { - return false; - } - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); - object = toObject(object); - if (!customizer && length == 1) { - var key = props[0], - value = source[key]; - - if (isStrictComparable(value)) { - return value === object[key] && (value !== undefined || (key in object)); - } - } - var values = Array(length), - strictCompareFlags = Array(length); - - while (length--) { - value = values[length] = source[props[length]]; - strictCompareFlags[length] = isStrictComparable(value); - } - return baseIsMatch(object, props, values, strictCompareFlags, customizer); + customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined; + return baseIsMatch(object, getMatchData(source), customizer); } return isMatch; diff --git a/lang/isNative.js b/lang/isNative.js index bf3c10a20..bbd7601b9 100644 --- a/lang/isNative.js +++ b/lang/isNative.js @@ -12,6 +12,9 @@ define(['../string/escapeRegExp', '../internal/isObjectLike'], function(escapeRe /** Used to resolve the decompiled source of functions. */ var fnToString = Function.prototype.toString; + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + /** * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) * of values. @@ -20,8 +23,8 @@ define(['../string/escapeRegExp', '../internal/isObjectLike'], function(escapeRe /** Used to detect if a method is native. */ var reIsNative = RegExp('^' + - escapeRegExp(objToString) - .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' + escapeRegExp(fnToString.call(hasOwnProperty)) + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); /** diff --git a/lang/isObject.js b/lang/isObject.js index 029158d95..0d8b30ca3 100644 --- a/lang/isObject.js +++ b/lang/isObject.js @@ -24,7 +24,7 @@ define([], function() { // Avoid a V8 JIT bug in Chrome 19-20. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. var type = typeof value; - return type == 'function' || (!!value && type == 'object'); + return !!value && (type == 'object' || type == 'function'); } return isObject; diff --git a/lang/isPlainObject.js b/lang/isPlainObject.js index ec4dc8c3b..70a9f80cf 100644 --- a/lang/isPlainObject.js +++ b/lang/isPlainObject.js @@ -1,4 +1,4 @@ -define(['./isNative', '../internal/shimIsPlainObject'], function(isNative, shimIsPlainObject) { +define(['../internal/getNative', '../internal/shimIsPlainObject'], function(getNative, shimIsPlainObject) { /** `Object#toString` result references. */ var objectTag = '[object Object]'; @@ -13,7 +13,7 @@ define(['./isNative', '../internal/shimIsPlainObject'], function(isNative, shimI var objToString = objectProto.toString; /** Native method references. */ - var getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf; + var getPrototypeOf = getNative(Object, 'getPrototypeOf'); /** * Checks if `value` is a plain object, that is, an object created by the @@ -49,8 +49,8 @@ define(['./isNative', '../internal/shimIsPlainObject'], function(isNative, shimI if (!(value && objToString.call(value) == objectTag)) { return false; } - var valueOf = value.valueOf, - objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); + var valueOf = getNative(value, 'valueOf'), + objProto = valueOf && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); return objProto ? (value == objProto || getPrototypeOf(value) == objProto) diff --git a/lang/lt.js b/lang/lt.js new file mode 100644 index 000000000..4e3e84501 --- /dev/null +++ b/lang/lt.js @@ -0,0 +1,28 @@ +define([], function() { + + /** + * Checks if `value` is less than `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`. + * @example + * + * _.lt(1, 3); + * // => true + * + * _.lt(3, 3); + * // => false + * + * _.lt(3, 1); + * // => false + */ + function lt(value, other) { + return value < other; + } + + return lt; +}); diff --git a/lang/lte.js b/lang/lte.js new file mode 100644 index 000000000..608e0d700 --- /dev/null +++ b/lang/lte.js @@ -0,0 +1,28 @@ +define([], function() { + + /** + * Checks if `value` is less than or equal to `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`. + * @example + * + * _.lte(1, 3); + * // => true + * + * _.lte(3, 3); + * // => true + * + * _.lte(3, 1); + * // => false + */ + function lte(value, other) { + return value <= other; + } + + return lte; +}); diff --git a/main.js b/main.js index 63adfb2e6..a7d245a77 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.8.0 (Custom Build) + * lodash 3.9.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.8.0'; + var VERSION = '3.9.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -272,7 +272,7 @@ /** * Used as a reference to the global object. * - * The `this` value is used if it is the global object to avoid Greasemonkey's + * The `this` value is used if it's the global object to avoid Greasemonkey's * restricted `window` object, otherwise the `window` object is used. */ var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this; @@ -282,19 +282,28 @@ * sorts them in ascending order without guaranteeing a stable sort. * * @private - * @param {*} value The value to compare to `other`. - * @param {*} other The value to compare to `value`. + * @param {*} value The value to compare. + * @param {*} other The other value to compare. * @returns {number} Returns the sort order indicator for `value`. */ function baseCompareAscending(value, other) { if (value !== other) { - var valIsReflexive = value === value, + var valIsNull = value === null, + valIsUndef = value === undefined, + valIsReflexive = value === value; + + var othIsNull = other === null, + othIsUndef = other === undefined, othIsReflexive = other === other; - if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) { + if ((value > other && !othIsNull) || !valIsReflexive || + (valIsNull && !othIsUndef && othIsReflexive) || + (valIsUndef && othIsReflexive)) { return 1; } - if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) { + if ((value < other && !valIsNull) || !othIsReflexive || + (othIsNull && !valIsUndef && valIsReflexive) || + (othIsUndef && valIsReflexive)) { return -1; } } @@ -362,7 +371,7 @@ } /** - * Converts `value` to a string if it is not one. An empty string is returned + * Converts `value` to a string if it's not one. An empty string is returned * for `null` or `undefined` values. * * @private @@ -376,17 +385,6 @@ return value == null ? '' : (value + ''); } - /** - * Used by `_.max` and `_.min` as the default callback for string values. - * - * @private - * @param {string} string The string to inspect. - * @returns {number} Returns the code unit of the first character of the string. - */ - function charAtCallback(string) { - return string.charCodeAt(0); - } - /** * Used by `_.trim` and `_.trimLeft` to get the index of the first character * of `string` that is not found in `chars`. @@ -707,7 +705,7 @@ stringProto = String.prototype; /** Used to detect DOM support. */ - var document = (document = context.window) && document.document; + var document = (document = context.window) ? document.document : null; /** Used to resolve the decompiled source of functions. */ var fnToString = Function.prototype.toString; @@ -729,26 +727,23 @@ /** Used to detect if a method is native. */ var reIsNative = RegExp('^' + - escapeRegExp(objToString) - .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' + escapeRegExp(fnToString.call(hasOwnProperty)) + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); /** Native method references. */ - var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer, - bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice, + var ArrayBuffer = getNative(context, 'ArrayBuffer'), + bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'), ceil = Math.ceil, clearTimeout = context.clearTimeout, floor = Math.floor, - getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols, - getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, + getPrototypeOf = getNative(Object, 'getPrototypeOf'), push = arrayProto.push, - preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions, - propertyIsEnumerable = objectProto.propertyIsEnumerable, - Set = isNative(Set = context.Set) && Set, + Set = getNative(context, 'Set'), setTimeout = context.setTimeout, splice = arrayProto.splice, - Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array, - WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap; + Uint8Array = getNative(context, 'Uint8Array'), + WeakMap = getNative(context, 'WeakMap'); /** Used to clone array buffers. */ var Float64Array = (function() { @@ -756,53 +751,29 @@ // where the array buffer's `byteLength` is not a multiple of the typed // array's `BYTES_PER_ELEMENT`. try { - var func = isNative(func = context.Float64Array) && func, + var func = getNative(context, 'Float64Array'), result = new func(new ArrayBuffer(10), 0, 1) && func; } catch(e) {} - return result; - }()); - - /** Used as `baseAssign`. */ - var nativeAssign = (function() { - // Avoid `Object.assign` in Firefox 34-37 which have an early implementation - // with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344 - // for more details. - // - // 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. - 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; + return result || null; }()); /* Native method references for those with the same name as other `lodash` methods. */ - var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray, - nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate, + var nativeCreate = getNative(Object, 'create'), + nativeIsArray = getNative(Array, 'isArray'), nativeIsFinite = context.isFinite, - nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys, + nativeKeys = getNative(Object, 'keys'), nativeMax = Math.max, nativeMin = Math.min, - nativeNow = isNative(nativeNow = Date.now) && nativeNow, - nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite, + nativeNow = getNative(Date, 'now'), + nativeNumIsFinite = getNative(Number, 'isFinite'), nativeParseInt = context.parseInt, nativeRandom = Math.random; /** Used as references for `-Infinity` and `Infinity`. */ - var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY, - POSITIVE_INFINITY = Number.POSITIVE_INFINITY; + var POSITIVE_INFINITY = Number.POSITIVE_INFINITY; /** Used as references for the maximum length and index of an array. */ - var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1, + var MAX_ARRAY_LENGTH = 4294967295, MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; @@ -813,7 +784,7 @@ * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) * of an array-like value. */ - var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; + var MAX_SAFE_INTEGER = 9007199254740991; /** Used to store function metadata. */ var metaMap = WeakMap && new WeakMap; @@ -860,30 +831,31 @@ * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`, * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, - * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, - * `merge`, `mixin`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`, - * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`, - * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`, - * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, - * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, - * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`, - * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`, - * `without`, `wrap`, `xor`, `zip`, and `zipObject` + * `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, + * `memoize`, `merge`, `method`, `methodOf`, `mixin`, `negate`, `omit`, `once`, + * `pairs`, `partial`, `partialRight`, `partition`, `pick`, `plant`, `pluck`, + * `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, `rearg`, + * `reject`, `remove`, `rest`, `restParam`, `reverse`, `set`, `shuffle`, + * `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, `spread`, + * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, + * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`, + * `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `where`, `without`, + * `wrap`, `xor`, `zip`, `zipObject`, `zipWith` * * The wrapper methods that are **not** chainable by default are: * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, - * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, - * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`, - * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite` - * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, - * `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, - * `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, `noConflict`, - * `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, - * `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, `shift`, `size`, - * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`, `startsWith`, - * `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, - * `uniqueId`, `value`, and `words` + * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `get`, + * `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, + * `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, + * `isFinite` `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, + * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, + * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lt`, `lte`, + * `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`, + * `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, + * `runInContext`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, + * `sortedLastIndex`, `startCase`, `startsWith`, `sum`, `template`, `trim`, + * `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words` * * The wrapper method `sample` will return a wrapped value when `n` is provided, * otherwise an unwrapped value is returned. @@ -960,31 +932,12 @@ (function(x) { var Ctor = function() { this.x = x; }, - args = arguments, object = { '0': x, 'length': x }, props = []; Ctor.prototype = { 'valueOf': x, 'y': x }; for (var key in new Ctor) { props.push(key); } - /** - * Detect if functions can be decompiled by `Function#toString` - * (all but Firefox OS certified apps, older Opera mobile browsers, and - * the PlayStation 3; forced `false` for Windows 8 apps). - * - * @memberOf _.support - * @type boolean - */ - support.funcDecomp = /\bthis\b/.test(function() { return this; }); - - /** - * Detect if `Function#name` is supported (all but IE). - * - * @memberOf _.support - * @type boolean - */ - support.funcNames = typeof Function.name == 'string'; - /** * Detect if the DOM is supported. * @@ -996,24 +949,6 @@ } catch(e) { support.dom = false; } - - /** - * Detect if `arguments` object indexes are non-enumerable. - * - * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object - * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat - * `arguments` object indexes as non-enumerable and fail `hasOwnProperty` - * checks for indexes that exceed the number of function parameters and - * whose associated argument values are `0`. - * - * @memberOf _.support - * @type boolean - */ - try { - support.nonEnumArgs = !propertyIsEnumerable.call(args, 1); - } catch(e) { - support.nonEnumArgs = true; - } }(1, 0)); /** @@ -1404,6 +1339,35 @@ return true; } + /** + * A specialized version of `baseExtremum` for arrays whichs invokes `iteratee` + * with one argument: (value). + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} comparator The function used to compare values. + * @param {*} exValue The initial extremum value. + * @returns {*} Returns the extremum value. + */ + function arrayExtremum(array, iteratee, comparator, exValue) { + var index = -1, + length = array.length, + computed = exValue, + result = computed; + + while (++index < length) { + var value = array[index], + current = +iteratee(value); + + if (comparator(current, computed)) { + computed = current; + result = value; + } + } + return result; + } + /** * A specialized version of `_.filter` for arrays without support for callback * shorthands and `this` binding. @@ -1448,48 +1412,6 @@ return result; } - /** - * A specialized version of `_.max` for arrays without support for iteratees. - * - * @private - * @param {Array} array The array to iterate over. - * @returns {*} Returns the maximum value. - */ - function arrayMax(array) { - var index = -1, - length = array.length, - result = NEGATIVE_INFINITY; - - while (++index < length) { - var value = array[index]; - if (value > result) { - result = value; - } - } - return result; - } - - /** - * A specialized version of `_.min` for arrays without support for iteratees. - * - * @private - * @param {Array} array The array to iterate over. - * @returns {*} Returns the minimum value. - */ - function arrayMin(array) { - var index = -1, - length = array.length, - result = POSITIVE_INFINITY; - - while (++index < length) { - var value = array[index]; - if (value < result) { - result = value; - } - } - return result; - } - /** * A specialized version of `_.reduce` for arrays without support for callback * shorthands and `this` binding. @@ -1620,10 +1542,8 @@ * @returns {Object} Returns `object`. */ function assignWith(object, source, customizer) { - var props = keys(source); - push.apply(props, getSymbols(source)); - var index = -1, + props = keys(source), length = props.length; while (++index < length) { @@ -1648,11 +1568,11 @@ * @param {Object} source The source object. * @returns {Object} Returns `object`. */ - var baseAssign = nativeAssign || function(object, source) { + function baseAssign(object, source) { return source == null ? object - : baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object)); - }; + : baseCopy(source, keys(source), object); + } /** * The base implementation of `_.at` without support for string collections @@ -1667,7 +1587,7 @@ var index = -1, isNil = collection == null, isArr = !isNil && isArrayLike(collection), - length = isArr && collection.length, + length = isArr ? collection.length : 0, propsLength = props.length, result = Array(propsLength); @@ -1808,14 +1728,14 @@ * @returns {Object} Returns the new object. */ var baseCreate = (function() { - function Object() {} + function object() {} return function(prototype) { if (isObject(prototype)) { - Object.prototype = prototype; - var result = new Object; - Object.prototype = null; + object.prototype = prototype; + var result = new object; + object.prototype = null; } - return result || context.Object(); + return result || {}; }; }()); @@ -1924,6 +1844,32 @@ return result; } + /** + * Gets the extremum value of `collection` invoking `iteratee` for each value + * in `collection` to generate the criterion by which the value is ranked. + * The `iteratee` is invoked with three arguments: (value, index|key, collection). + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} comparator The function used to compare values. + * @param {*} exValue The initial extremum value. + * @returns {*} Returns the extremum value. + */ + function baseExtremum(collection, iteratee, comparator, exValue) { + var computed = exValue, + result = computed; + + baseEach(collection, function(value, index, collection) { + var current = +iteratee(value, index, collection); + if (comparator(current, computed) || (current === exValue && current === result)) { + computed = current; + result = value; + } + }); + return result; + } + /** * The base implementation of `_.fill` without an iteratee call guard. * @@ -2140,11 +2086,11 @@ if (pathKey !== undefined && pathKey in toObject(object)) { path = [pathKey]; } - var index = -1, + var index = 0, length = path.length; - while (object != null && ++index < length) { - object = object[path[index]]; + while (object != null && index < length) { + object = object[path[index++]]; } return (index && index == length) ? object : undefined; } @@ -2163,17 +2109,10 @@ * @returns {boolean} Returns `true` if the values are equivalent, else `false`. */ function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) { - // Exit early for identical values. if (value === other) { return true; } - var valType = typeof value, - othType = typeof other; - - // Exit early for unlike primitive values. - if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') || - value == null || other == null) { - // Return `false` unless both values are `NaN`. + if (value == null || other == null || (!isObject(value) && !isObject(other))) { return value !== value && other !== other; } return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB); @@ -2224,11 +2163,11 @@ return equalByTag(object, other, objTag); } if (!isLoose) { - var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), + othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); - if (valWrapped || othWrapped) { - return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB); + if (objIsWrapped || othIsWrapped) { + return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB); } } if (!isSameTag) { @@ -2263,41 +2202,43 @@ * * @private * @param {Object} object The object to inspect. - * @param {Array} props The source property names to match. - * @param {Array} values The source values to match. - * @param {Array} strictCompareFlags Strict comparison flags for source values. + * @param {Array} matchData The propery names, values, and compare flags to match. * @param {Function} [customizer] The function to customize comparing objects. * @returns {boolean} Returns `true` if `object` is a match, else `false`. */ - function baseIsMatch(object, props, values, strictCompareFlags, customizer) { - var index = -1, - length = props.length, + function baseIsMatch(object, matchData, customizer) { + var index = matchData.length, + length = index, noCustomizer = !customizer; - while (++index < length) { - if ((noCustomizer && strictCompareFlags[index]) - ? values[index] !== object[props[index]] - : !(props[index] in object) + if (object == null) { + return !length; + } + object = toObject(object); + while (index--) { + var data = matchData[index]; + if ((noCustomizer && data[2]) + ? data[1] !== object[data[0]] + : !(data[0] in object) ) { return false; } } - index = -1; while (++index < length) { - var key = props[index], + data = matchData[index]; + var key = data[0], objValue = object[key], - srcValue = values[index]; + srcValue = data[1]; - if (noCustomizer && strictCompareFlags[index]) { - var result = objValue !== undefined || (key in object); - } else { - result = customizer ? customizer(objValue, srcValue, key) : undefined; - if (result === undefined) { - result = baseIsEqual(srcValue, objValue, customizer, true); + if (noCustomizer && data[2]) { + if (objValue === undefined && !(key in object)) { + return false; + } + } else { + var result = customizer ? customizer(objValue, srcValue, key) : undefined; + if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) { + return false; } - } - if (!result) { - return false; } } return true; @@ -2330,35 +2271,20 @@ * @returns {Function} Returns the new function. */ function baseMatches(source) { - var props = keys(source), - length = props.length; + var matchData = getMatchData(source); + if (matchData.length == 1 && matchData[0][2]) { + var key = matchData[0][0], + value = matchData[0][1]; - if (!length) { - return constant(true); - } - if (length == 1) { - var key = props[0], - value = source[key]; - - if (isStrictComparable(value)) { - return function(object) { - if (object == null) { - return false; - } - return object[key] === value && (value !== undefined || (key in toObject(object))); - }; - } - } - var values = Array(length), - strictCompareFlags = Array(length); - - while (length--) { - value = source[props[length]]; - values[length] = value; - strictCompareFlags[length] = isStrictComparable(value); + return function(object) { + if (object == null) { + return false; + } + return object[key] === value && (value !== undefined || (key in toObject(object))); + }; } return function(object) { - return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags); + return baseIsMatch(object, matchData); }; } @@ -2368,12 +2294,12 @@ * * @private * @param {string} path The path of the property to get. - * @param {*} value The value to compare. + * @param {*} srcValue The value to compare. * @returns {Function} Returns the new function. */ - function baseMatchesProperty(path, value) { + function baseMatchesProperty(path, srcValue) { var isArr = isArray(path), - isCommon = isKey(path) && isStrictComparable(value), + isCommon = isKey(path) && isStrictComparable(srcValue), pathKey = (path + ''); path = toPath(path); @@ -2391,9 +2317,9 @@ key = last(path); object = toObject(object); } - return object[key] === value - ? (value !== undefined || (key in object)) - : baseIsEqual(value, object[key], null, true); + return object[key] === srcValue + ? (srcValue !== undefined || (key in object)) + : baseIsEqual(srcValue, object[key], undefined, true); }; } @@ -2413,11 +2339,9 @@ if (!isObject(object)) { return object; } - var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)); - if (!isSrcArr) { - var props = keys(source); - push.apply(props, getSymbols(source)); - } + var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)), + props = isSrcArr ? null : keys(source); + arrayEach(props || source, function(srcValue, key) { if (props) { key = srcValue; @@ -2436,7 +2360,7 @@ if (isCommon) { result = srcValue; } - if ((isSrcArr || result !== undefined) && + if ((result !== undefined || (isSrcArr && !(key in object))) && (isCommon || (result === result ? (result !== value) : (value === value)))) { object[key] = result; } @@ -2543,7 +2467,7 @@ function basePullAt(array, indexes) { var length = array ? indexes.length : 0; while (length--) { - var index = parseFloat(indexes[length]); + var index = indexes[length]; if (index != previous && isIndex(index)) { var previous = index; splice.call(array, index, 1); @@ -2856,7 +2780,7 @@ var mid = (low + high) >>> 1, computed = array[mid]; - if (retHighest ? (computed <= value) : (computed < value)) { + if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) { low = mid + 1; } else { high = mid; @@ -2886,17 +2810,23 @@ var low = 0, high = array ? array.length : 0, valIsNaN = value !== value, + valIsNull = value === null, valIsUndef = value === undefined; while (low < high) { var mid = floor((low + high) / 2), computed = iteratee(array[mid]), + isDef = computed !== undefined, isReflexive = computed === computed; if (valIsNaN) { var setLow = isReflexive || retHighest; + } else if (valIsNull) { + setLow = isReflexive && isDef && (retHighest || computed != null); } else if (valIsUndef) { - setLow = isReflexive && (retHighest || computed !== undefined); + setLow = isReflexive && (retHighest || isDef); + } else if (computed == null) { + setLow = false; } else { setLow = retHighest ? (computed <= value) : (computed < value); } @@ -3086,19 +3016,19 @@ return restParam(function(object, sources) { var index = -1, length = object == null ? 0 : sources.length, - customizer = length > 2 && sources[length - 2], - guard = length > 2 && sources[2], - thisArg = length > 1 && sources[length - 1]; + customizer = length > 2 ? sources[length - 2] : undefined, + guard = length > 2 ? sources[2] : undefined, + thisArg = length > 1 ? sources[length - 1] : undefined; if (typeof customizer == 'function') { customizer = bindCallback(customizer, thisArg, 5); length -= 2; } else { - customizer = typeof thisArg == 'function' ? thisArg : null; + customizer = typeof thisArg == 'function' ? thisArg : undefined; length -= (customizer ? 1 : 0); } if (guard && isIterateeCall(sources[0], sources[1], guard)) { - customizer = length < 3 ? null : customizer; + customizer = length < 3 ? undefined : customizer; length = 1; } while (++index < length) { @@ -3223,8 +3153,20 @@ */ function createCtorWrapper(Ctor) { return function() { + // Use a `switch` statement to work with class constructors. + // See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-call-thisargument-argumentslist + // for more details. + var args = arguments; + switch (args.length) { + case 0: return new Ctor; + case 1: return new Ctor(args[0]); + case 2: return new Ctor(args[0], args[1]); + case 3: return new Ctor(args[0], args[1], args[2]); + case 4: return new Ctor(args[0], args[1], args[2], args[3]); + case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); + } var thisBinding = baseCreate(Ctor.prototype), - result = Ctor.apply(thisBinding, arguments); + result = Ctor.apply(thisBinding, args); // Mimic the constructor's `return` behavior. // See https://es5.github.io/#x13.2.2 for more details. @@ -3255,32 +3197,24 @@ * Creates a `_.max` or `_.min` function. * * @private - * @param {Function} arrayFunc The function to get the extremum value from an array. - * @param {boolean} [isMin] Specify returning the minimum, instead of the maximum, - * extremum value. + * @param {Function} comparator The function used to compare values. + * @param {*} exValue The initial extremum value. * @returns {Function} Returns the new extremum function. */ - function createExtremum(arrayFunc, isMin) { + function createExtremum(comparator, exValue) { return function(collection, iteratee, thisArg) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { iteratee = null; } - var func = getCallback(), - noIteratee = iteratee == null; - - if (!(func === baseCallback && noIteratee)) { - noIteratee = false; - iteratee = func(iteratee, thisArg, 3); - } - if (noIteratee) { - var isArr = isArray(collection); - if (!isArr && isString(collection)) { - iteratee = charAtCallback; - } else { - return arrayFunc(isArr ? collection : toIterable(collection)); + iteratee = getCallback(iteratee, thisArg, 3); + if (iteratee.length == 1) { + collection = toIterable(collection); + var result = arrayExtremum(collection, iteratee, comparator, exValue); + if (!(collection.length && result === exValue)) { + return result; } } - return extremumBy(collection, iteratee, isMin); + return baseExtremum(collection, iteratee, comparator, exValue); }; } @@ -3343,11 +3277,8 @@ */ function createFlow(fromRight) { return function() { - var length = arguments.length; - if (!length) { - return function() { return arguments[0]; }; - } var wrapper, + length = arguments.length, index = fromRight ? length : -1, leftIndex = 0, funcs = Array(length); @@ -3357,15 +3288,17 @@ if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - var funcName = wrapper ? '' : getFuncName(func); - wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper; + if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') { + wrapper = new LodashWrapper([]); + } } index = wrapper ? -1 : length; while (++index < length) { func = funcs[index]; - funcName = getFuncName(func); - var data = funcName == 'wrapper' ? getData(func) : null; + var funcName = getFuncName(func), + data = funcName == 'wrapper' ? getData(func) : null; + 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 { @@ -3378,7 +3311,7 @@ return wrapper.plant(args[0]).value(); } var index = 0, - result = funcs[index].apply(this, args); + result = length ? funcs[index].apply(this, args) : args[0]; while (++index < length) { result = funcs[index].call(this, result); @@ -3527,10 +3460,8 @@ isBindKey = bitmask & BIND_KEY_FLAG, isCurry = bitmask & CURRY_FLAG, isCurryBound = bitmask & CURRY_BOUND_FLAG, - isCurryRight = bitmask & CURRY_RIGHT_FLAG; - - var Ctor = !isBindKey && createCtorWrapper(func), - key = func; + isCurryRight = bitmask & CURRY_RIGHT_FLAG, + Ctor = isBindKey ? null : createCtorWrapper(func); function wrapper() { // Avoid `arguments` object use disqualifying optimizations by @@ -3577,17 +3508,18 @@ return result; } } - var thisBinding = isBind ? thisArg : this; - if (isBindKey) { - func = thisBinding[key]; - } + var thisBinding = isBind ? thisArg : this, + fn = isBindKey ? thisBinding[func] : func; + if (argPos) { args = reorder(args, argPos); } if (isAry && ary < args.length) { args.length = ary; } - var fn = (this && this !== root && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func; + if (this && this !== root && this instanceof wrapper) { + fn = Ctor || createCtorWrapper(func); + } return fn.apply(thisBinding, args); } return wrapper; @@ -3661,10 +3593,10 @@ */ function createSortedIndex(retHighest) { return function(array, value, iteratee, thisArg) { - var func = getCallback(iteratee); - return (func === baseCallback && iteratee == null) + var callback = getCallback(iteratee); + return (iteratee == null && callback === baseCallback) ? binaryIndex(array, value, retHighest) - : binaryIndexBy(array, value, func(iteratee, thisArg, 1), retHighest); + : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest); }; } @@ -3750,40 +3682,35 @@ function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) { var index = -1, arrLength = array.length, - othLength = other.length, - result = true; + othLength = other.length; if (arrLength != othLength && !(isLoose && othLength > arrLength)) { return false; } - // Deep compare the contents, ignoring non-numeric properties. - while (result && ++index < arrLength) { + // Ignore non-index properties. + while (++index < arrLength) { var arrValue = array[index], - othValue = other[index]; + othValue = other[index], + result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined; - result = undefined; - if (customizer) { - result = isLoose - ? customizer(othValue, arrValue, index) - : customizer(arrValue, othValue, index); - } - if (result === undefined) { - // Recursively compare arrays (susceptible to call stack limits). - if (isLoose) { - var othIndex = othLength; - while (othIndex--) { - othValue = other[othIndex]; - result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); - if (result) { - break; - } - } - } else { - result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); + if (result !== undefined) { + if (result) { + continue; } + return false; + } + // Recursively compare arrays (susceptible to call stack limits). + if (isLoose) { + if (!arraySome(other, function(othValue) { + return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); + })) { + return false; + } + } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) { + return false; } } - return !!result; + return true; } /** @@ -3848,29 +3775,22 @@ if (objLength != othLength && !isLoose) { return false; } - var skipCtor = isLoose, - index = -1; - - while (++index < objLength) { - var key = objProps[index], - result = isLoose ? key in other : hasOwnProperty.call(other, key); - - if (result) { - var objValue = object[key], - othValue = other[key]; - - result = undefined; - if (customizer) { - result = isLoose - ? customizer(othValue, objValue, key) - : customizer(objValue, othValue, key); - } - if (result === undefined) { - // Recursively compare objects (susceptible to call stack limits). - result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB); - } + var index = objLength; + while (index--) { + var key = objProps[index]; + if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) { + return false; } - if (!result) { + } + var skipCtor = isLoose; + while (++index < objLength) { + key = objProps[index]; + var objValue = object[key], + othValue = other[key], + result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined; + + // Recursively compare objects (susceptible to call stack limits). + if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) { return false; } skipCtor || (skipCtor = key == 'constructor'); @@ -3890,34 +3810,6 @@ return true; } - /** - * Gets the extremum value of `collection` invoking `iteratee` for each value - * in `collection` to generate the criterion by which the value is ranked. - * The `iteratee` is invoked with three arguments: (value, index, collection). - * - * @private - * @param {Array|Object|string} collection The collection to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {boolean} [isMin] Specify returning the minimum, instead of the - * maximum, extremum value. - * @returns {*} Returns the extremum value. - */ - function extremumBy(collection, iteratee, isMin) { - var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY, - computed = exValue, - result = computed; - - baseEach(collection, function(value, index, collection) { - var current = iteratee(value, index, collection); - if ((isMin ? (current < computed) : (current > computed)) || - (current === exValue && current === result)) { - computed = current; - result = value; - } - }); - return result; - } - /** * Gets the appropriate "callback" function. If the `_.callback` method is * customized this function returns the custom method, otherwise it returns @@ -3951,29 +3843,20 @@ * @param {Function} func The function to query. * @returns {string} Returns the function name. */ - var getFuncName = (function() { - if (!support.funcNames) { - return constant(''); - } - if (constant.name == 'constant') { - return baseProperty('name'); - } - return function(func) { - var result = func.name, - array = realNames[result], - length = array ? array.length : 0; + function getFuncName(func) { + var result = func.name, + array = realNames[result], + length = array ? array.length : 0; - while (length--) { - var data = array[length], - otherFunc = data.func; - - if (otherFunc == null || otherFunc == func) { - return data.name; - } + while (length--) { + var data = array[length], + otherFunc = data.func; + if (otherFunc == null || otherFunc == func) { + return data.name; } - return result; - }; - }()); + } + return result; + } /** * Gets the appropriate "indexOf" function. If the `_.indexOf` method is @@ -4003,15 +3886,34 @@ var getLength = baseProperty('length'); /** - * Creates an array of the own symbols of `object`. + * Gets the propery names, values, and compare flags of `object`. * * @private * @param {Object} object The object to query. - * @returns {Array} Returns the array of symbols. + * @returns {Array} Returns the match data of `object`. */ - var getSymbols = !getOwnPropertySymbols ? constant([]) : function(object) { - return getOwnPropertySymbols(toObject(object)); - }; + function getMatchData(object) { + var result = pairs(object), + length = result.length; + + while (length--) { + result[length][2] = isStrictComparable(result[length][1]); + } + return result; + } + + /** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ + function getNative(object, key) { + var value = object == null ? undefined : object[key]; + return isNative(value) ? value : undefined; + } /** * Gets the view, applying any `transforms` to the `start` and `end` positions. @@ -4153,7 +4055,7 @@ * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex(value, length) { - value = +value; + value = typeof value == 'number' ? value : parseFloat(value); length = length == null ? MAX_SAFE_INTEGER : length; return value > -1 && value % 1 == 0 && value < length; } @@ -4450,11 +4352,10 @@ function shimKeys(object) { var props = keysIn(object), propsLength = props.length, - length = propsLength && object.length, - support = lodash.support; + length = propsLength && object.length; - var allowIndexes = length && isLength(length) && - (isArray(object) || (support.nonEnumArgs && isArguments(object))); + var allowIndexes = !!length && isLength(length) && + (isArray(object) || isArguments(object)); var index = -1, result = []; @@ -4469,7 +4370,7 @@ } /** - * Converts `value` to an array-like object if it is not one. + * Converts `value` to an array-like object if it's not one. * * @private * @param {*} value The value to process. @@ -4486,7 +4387,7 @@ } /** - * Converts `value` to an object if it is not one. + * Converts `value` to an object if it's not one. * * @private * @param {*} value The value to process. @@ -4497,7 +4398,7 @@ } /** - * Converts `value` to property path array if it is not one. + * Converts `value` to property path array if it's not one. * * @private * @param {*} value The value to process. @@ -5081,27 +4982,19 @@ * _.intersection([1, 2], [4, 2], [2, 1]); * // => [2] */ - function intersection() { - var args = [], - argsIndex = -1, - argsLength = arguments.length, - caches = [], + var intersection = restParam(function(arrays) { + var othLength = arrays.length, + othIndex = othLength, + caches = Array(length), indexOf = getIndexOf(), isCommon = indexOf == baseIndexOf, result = []; - while (++argsIndex < argsLength) { - var value = arguments[argsIndex]; - if (isArrayLike(value)) { - args.push(value); - caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null); - } + while (othIndex--) { + var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : []; + caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null; } - argsLength = args.length; - if (argsLength < 2) { - return result; - } - var array = args[0], + var array = arrays[0], index = -1, length = array ? array.length : 0, seen = caches[0]; @@ -5110,10 +5003,10 @@ while (++index < length) { value = array[index]; if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) { - argsIndex = argsLength; - while (--argsIndex) { - var cache = caches[argsIndex]; - if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) { + var othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) { continue outer; } } @@ -5124,7 +5017,7 @@ } } return result; - } + }); /** * Gets the last element of `array`. @@ -5707,9 +5600,9 @@ iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted; isSorted = false; } - var func = getCallback(); - if (!(func === baseCallback && iteratee == null)) { - iteratee = func(iteratee, thisArg, 3); + var callback = getCallback(); + if (!(iteratee == null && callback === baseCallback)) { + iteratee = callback(iteratee, thisArg, 3); } return (isSorted && getIndexOf() == baseIndexOf) ? sortedUniq(array, iteratee) @@ -5916,8 +5809,8 @@ */ var zipWith = restParam(function(arrays) { var length = arrays.length, - iteratee = arrays[length - 2], - thisArg = arrays[length - 1]; + iteratee = length > 2 ? arrays[length - 2] : undefined, + thisArg = length > 1 ? arrays[length - 1] : undefined; if (length > 2 && typeof iteratee == 'function') { length -= 2; @@ -6670,7 +6563,7 @@ }); /** - * Invokes the method at `path` on each element in `collection`, returning + * Invokes the method at `path` of each element in `collection`, returning * an array of the results of each invoked method. Any additional arguments * are provided to each invoked method. If `methodName` is a function it is * invoked for, and `this` bound to, each element in `collection`. @@ -6698,7 +6591,7 @@ result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value) { - var func = isFunc ? path : (isProp && value != null && value[path]); + var func = isFunc ? path : ((isProp && value != null) ? value[path] : null); result[++index] = func ? func.apply(value, args) : invokePath(value, path, args); }); return result; @@ -6720,7 +6613,7 @@ * callback returns `true` for elements that have the properties of the given * object, else `false`. * - * Many lodash methods are guarded to work as interatees for methods like + * Many lodash methods are guarded to work as iteratees for methods like * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. * * The guarded methods are: @@ -6864,7 +6757,7 @@ * value. The `iteratee` is bound to `thisArg` and invoked with four arguments: * (accumulator, value, index|key, collection). * - * Many lodash methods are guarded to work as interatees for methods like + * Many lodash methods are guarded to work as iteratees for methods like * `_.reduce`, `_.reduceRight`, and `_.transform`. * * The guarded methods are: @@ -7641,12 +7534,13 @@ var curryRight = createCurry(CURRY_RIGHT_FLAG); /** - * Creates a function that delays invoking `func` until after `wait` milliseconds - * have elapsed since the last time it was invoked. The created function comes - * with a `cancel` method to cancel delayed invocations. Provide an options - * object to indicate that `func` should be invoked on the leading and/or - * trailing edge of the `wait` timeout. Subsequent calls to the debounced - * function return the result of the last `func` invocation. + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked. The debounced function comes with a `cancel` method to cancel + * delayed invocations. Provide an options object to indicate that `func` + * should be invoked on the leading and/or trailing edge of the `wait` timeout. + * Subsequent calls to the debounced function return the result of the last + * `func` invocation. * * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked * on the trailing edge of the timeout only if the the debounced function is @@ -7960,14 +7854,14 @@ } var memoized = function() { var args = arguments, - cache = memoized.cache, - key = resolver ? resolver.apply(this, args) : args[0]; + key = resolver ? resolver.apply(this, args) : args[0], + cache = memoized.cache; if (cache.has(key)) { return cache.get(key); } var result = func.apply(this, args); - cache.set(key, result); + memoized.cache = cache.set(key, result); return result; }; memoized.cache = new memoize.Cache; @@ -8214,12 +8108,12 @@ } /** - * Creates a function that only invokes `func` at most once per every `wait` - * milliseconds. The created function comes with a `cancel` method to cancel - * delayed invocations. Provide an options object to indicate that `func` - * should be invoked on the leading and/or trailing edge of the `wait` timeout. - * Subsequent calls to the throttled function return the result of the last - * `func` call. + * Creates a throttled function that only invokes `func` at most once per + * every `wait` milliseconds. The throttled function comes with a `cancel` + * method to cancel delayed invocations. Provide an options object to indicate + * that `func` should be invoked on the leading and/or trailing edge of the + * `wait` timeout. Subsequent calls to the throttled function return the + * result of the last `func` call. * * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked * on the trailing edge of the timeout only if the the throttled function is @@ -8357,8 +8251,9 @@ customizer = isDeep; isDeep = false; } - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); - return baseClone(value, isDeep, customizer); + return typeof customizer == 'function' + ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1)) + : baseClone(value, isDeep); } /** @@ -8407,8 +8302,57 @@ * // => 20 */ function cloneDeep(value, customizer, thisArg) { - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); - return baseClone(value, true, customizer); + return typeof customizer == 'function' + ? baseClone(value, true, bindCallback(customizer, thisArg, 1)) + : baseClone(value, true); + } + + /** + * Checks if `value` is greater than `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`. + * @example + * + * _.gt(3, 1); + * // => true + * + * _.gt(3, 3); + * // => false + * + * _.gt(1, 3); + * // => false + */ + function gt(value, other) { + return value > other; + } + + /** + * Checks if `value` is greater than or equal to `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`. + * @example + * + * _.gte(3, 1); + * // => true + * + * _.gte(3, 3); + * // => true + * + * _.gte(1, 3); + * // => false + */ + function gte(value, other) { + return value >= other; } /** @@ -8571,6 +8515,7 @@ * * @static * @memberOf _ + * @alias eq * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. @@ -8600,12 +8545,9 @@ * // => true */ function isEqual(value, other, customizer, thisArg) { - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); - if (!customizer && isStrictComparable(value) && isStrictComparable(other)) { - return value === other; - } + customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined; var result = customizer ? customizer(value, other) : undefined; - return result === undefined ? baseIsEqual(value, other, customizer) : !!result; + return result === undefined ? baseIsEqual(value, other, customizer) : !!result; } /** @@ -8707,7 +8649,7 @@ // Avoid a V8 JIT bug in Chrome 19-20. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. var type = typeof value; - return type == 'function' || (!!value && type == 'object'); + return !!value && (type == 'object' || type == 'function'); } /** @@ -8750,33 +8692,8 @@ * // => true */ function isMatch(object, source, customizer, thisArg) { - var props = keys(source), - length = props.length; - - if (!length) { - return true; - } - if (object == null) { - return false; - } - customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); - object = toObject(object); - if (!customizer && length == 1) { - var key = props[0], - value = source[key]; - - if (isStrictComparable(value)) { - return value === object[key] && (value !== undefined || (key in object)); - } - } - var values = Array(length), - strictCompareFlags = Array(length); - - while (length--) { - value = values[length] = source[props[length]]; - strictCompareFlags[length] = isStrictComparable(value); - } - return baseIsMatch(object, props, values, strictCompareFlags, customizer); + customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined; + return baseIsMatch(object, getMatchData(source), customizer); } /** @@ -8916,8 +8833,8 @@ if (!(value && objToString.call(value) == objectTag)) { return false; } - var valueOf = value.valueOf, - objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); + var valueOf = getNative(value, 'valueOf'), + objProto = valueOf && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); return objProto ? (value == objProto || getPrototypeOf(value) == objProto) @@ -9004,6 +8921,54 @@ return value === undefined; } + /** + * Checks if `value` is less than `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`. + * @example + * + * _.lt(1, 3); + * // => true + * + * _.lt(3, 3); + * // => false + * + * _.lt(3, 1); + * // => false + */ + function lt(value, other) { + return value < other; + } + + /** + * Checks if `value` is less than or equal to `other`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`. + * @example + * + * _.lte(1, 3); + * // => true + * + * _.lte(3, 3); + * // => true + * + * _.lte(3, 1); + * // => false + */ + function lte(value, other) { + return value <= other; + } + /** * Converts `value` to an array. * @@ -9396,7 +9361,7 @@ } /** - * Gets the property value of `path` on `object`. If the resolved value is + * Gets the property value at `path` of `object`. If the resolved value is * `undefined` the `defaultValue` is used in its place. * * @static @@ -9454,10 +9419,14 @@ if (!result && !isKey(path)) { path = toPath(path); object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); + if (object == null) { + return false; + } path = last(path); - result = object != null && hasOwnProperty.call(object, path); + result = hasOwnProperty.call(object, path); } - return result; + return result || (isLength(object.length) && isIndex(path, object.length) && + (isArray(object) || isArguments(object))); } /** @@ -9538,7 +9507,7 @@ * // => ['0', '1'] */ var keys = !nativeKeys ? shimKeys : function(object) { - var Ctor = object != null && object.constructor; + var Ctor = object == null ? null : object.constructor; if ((typeof Ctor == 'function' && Ctor.prototype === object) || (typeof object != 'function' && isArrayLike(object))) { return shimKeys(object); @@ -9577,7 +9546,7 @@ } var length = object.length; length = (length && isLength(length) && - (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0; + (isArray(object) || isArguments(object)) && length) || 0; var Ctor = object.constructor, index = -1, @@ -9764,6 +9733,8 @@ * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed) */ function pairs(object) { + object = toObject(object); + var index = -1, props = keys(object), length = props.length, @@ -9940,7 +9911,7 @@ if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype); + accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : null); } } else { accumulator = {}; @@ -10215,7 +10186,7 @@ * use a third-party library like [_he_](https://mths.be/he). * * Though the ">" character is escaped for symmetry, characters like - * ">" and "/" don't require escaping in HTML and have no special meaning + * ">" and "/" don't need escaping in HTML and have no special meaning * unless they're part of a tag or unquoted attribute value. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. @@ -10292,7 +10263,7 @@ }); /** - * Pads `string` on the left and right sides if it is shorter than `length`. + * Pads `string` on the left and right sides if it's shorter than `length`. * Padding characters are truncated if they can't be evenly divided by `length`. * * @static @@ -10330,7 +10301,7 @@ } /** - * Pads `string` on the left side if it is shorter than `length`. Padding + * Pads `string` on the left side if it's shorter than `length`. Padding * characters are truncated if they exceed `length`. * * @static @@ -10354,7 +10325,7 @@ var padLeft = createPadDir(); /** - * Pads `string` on the right side if it is shorter than `length`. Padding + * Pads `string` on the right side if it's shorter than `length`. Padding * characters are truncated if they exceed `length`. * * @static @@ -10835,7 +10806,7 @@ } /** - * Truncates `string` if it is longer than the given maximum string length. + * Truncates `string` if it's longer than the given maximum string length. * The last characters of the truncated string are replaced with the omission * string which defaults to "...". * @@ -11134,7 +11105,7 @@ * @memberOf _ * @category Utility * @param {Array|string} path The path of the property to get. - * @param {*} value The value to compare. + * @param {*} srcValue The value to match. * @returns {Function} Returns the new function. * @example * @@ -11146,8 +11117,8 @@ * _.find(users, _.matchesProperty('user', 'fred')); * // => { 'user': 'fred' } */ - function matchesProperty(path, value) { - return baseMatchesProperty(path, baseClone(value, true)); + function matchesProperty(path, srcValue) { + return baseMatchesProperty(path, baseClone(srcValue, true)); } /** @@ -11228,9 +11199,6 @@ * }); * } * - * // use `_.runInContext` to avoid conflicts (esp. in Node.js) - * var _ = require('lodash').runInContext(); - * * _.mixin({ 'vowels': vowels }); * _.vowels('fred'); * // => ['e'] @@ -11245,8 +11213,8 @@ function mixin(object, source, options) { if (options == null) { var isObj = isObject(source), - props = isObj && keys(source), - methodNames = props && props.length && baseFunctions(source, props); + props = isObj ? keys(source) : null, + methodNames = (props && props.length) ? baseFunctions(source, props) : null; if (!(methodNames ? methodNames.length : isObj)) { methodNames = false; @@ -11576,7 +11544,7 @@ * _.max(users, 'age'); * // => { 'user': 'fred', 'age': 40 } */ - var max = createExtremum(arrayMax); + var max = createExtremum(gt, -Infinity); /** * Gets the minimum value of `collection`. If `collection` is empty or falsey @@ -11625,7 +11593,7 @@ * _.min(users, 'age'); * // => { 'user': 'barney', 'age': 36 } */ - var min = createExtremum(arrayMin, true); + var min = createExtremum(lt, Infinity); /** * Gets the sum of the values in `collection`. @@ -11663,12 +11631,12 @@ if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { iteratee = null; } - var func = getCallback(), + var callback = getCallback(), noIteratee = iteratee == null; - if (!(func === baseCallback && noIteratee)) { + if (!(noIteratee && callback === baseCallback)) { noIteratee = false; - iteratee = func(iteratee, thisArg, 3); + iteratee = callback(iteratee, thisArg, 3); } return noIteratee ? arraySum(isArray(collection) ? collection : toIterable(collection)) @@ -11843,6 +11811,8 @@ lodash.findWhere = findWhere; lodash.first = first; lodash.get = get; + lodash.gt = gt; + lodash.gte = gte; lodash.has = has; lodash.identity = identity; lodash.includes = includes; @@ -11872,6 +11842,8 @@ lodash.kebabCase = kebabCase; lodash.last = last; lodash.lastIndexOf = lastIndexOf; + lodash.lt = lt; + lodash.lte = lte; lodash.max = max; lodash.min = min; lodash.noConflict = noConflict; @@ -11908,6 +11880,7 @@ lodash.all = every; lodash.any = some; lodash.contains = includes; + lodash.eq = isEqual; lodash.detect = find; lodash.foldl = reduce; lodash.foldr = reduceRight; diff --git a/math/max.js b/math/max.js index 4e728e736..def0ed8db 100644 --- a/math/max.js +++ b/math/max.js @@ -1,4 +1,4 @@ -define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax, createExtremum) { +define(['../internal/createExtremum', '../lang/gt'], function(createExtremum, gt) { /** * Gets the maximum value of `collection`. If `collection` is empty or falsey @@ -47,7 +47,7 @@ define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax * _.max(users, 'age'); * // => { 'user': 'fred', 'age': 40 } */ - var max = createExtremum(arrayMax); + var max = createExtremum(gt, -Infinity); return max; }); diff --git a/math/min.js b/math/min.js index 04400c401..e7810f255 100644 --- a/math/min.js +++ b/math/min.js @@ -1,4 +1,4 @@ -define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin, createExtremum) { +define(['../internal/createExtremum', '../lang/lt'], function(createExtremum, lt) { /** * Gets the minimum value of `collection`. If `collection` is empty or falsey @@ -47,7 +47,7 @@ define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin * _.min(users, 'age'); * // => { 'user': 'barney', 'age': 36 } */ - var min = createExtremum(arrayMin, true); + var min = createExtremum(lt, Infinity); return min; }); diff --git a/object/get.js b/object/get.js index d9b5a5d26..61170c966 100644 --- a/object/get.js +++ b/object/get.js @@ -4,7 +4,7 @@ define(['../internal/baseGet', '../internal/toPath'], function(baseGet, toPath) var undefined; /** - * Gets the property value of `path` on `object`. If the resolved value is + * Gets the property value at `path` of `object`. If the resolved value is * `undefined` the `defaultValue` is used in its place. * * @static diff --git a/object/has.js b/object/has.js index 38cd782c5..7884453ce 100644 --- a/object/has.js +++ b/object/has.js @@ -1,4 +1,4 @@ -define(['../internal/baseGet', '../internal/baseSlice', '../internal/isKey', '../array/last', '../internal/toPath'], function(baseGet, baseSlice, isKey, last, toPath) { +define(['../internal/baseGet', '../internal/baseSlice', '../lang/isArguments', '../lang/isArray', '../internal/isIndex', '../internal/isKey', '../internal/isLength', '../array/last', '../internal/toPath'], function(baseGet, baseSlice, isArguments, isArray, isIndex, isKey, isLength, last, toPath) { /** Used for native method references. */ var objectProto = Object.prototype; @@ -36,10 +36,14 @@ define(['../internal/baseGet', '../internal/baseSlice', '../internal/isKey', '.. if (!result && !isKey(path)) { path = toPath(path); object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); + if (object == null) { + return false; + } path = last(path); - result = object != null && hasOwnProperty.call(object, path); + result = hasOwnProperty.call(object, path); } - return result; + return result || (isLength(object.length) && isIndex(path, object.length) && + (isArray(object) || isArguments(object))); } return has; diff --git a/object/keys.js b/object/keys.js index 60f7577aa..4ce3ce649 100644 --- a/object/keys.js +++ b/object/keys.js @@ -1,7 +1,7 @@ -define(['../internal/isArrayLike', '../lang/isNative', '../lang/isObject', '../internal/shimKeys'], function(isArrayLike, isNative, isObject, shimKeys) { +define(['../internal/getNative', '../internal/isArrayLike', '../lang/isObject', '../internal/shimKeys'], function(getNative, isArrayLike, isObject, shimKeys) { /* Native method references for those with the same name as other `lodash` methods. */ - var nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys; + var nativeKeys = getNative(Object, 'keys'); /** * Creates an array of the own enumerable property names of `object`. @@ -31,7 +31,7 @@ define(['../internal/isArrayLike', '../lang/isNative', '../lang/isObject', '../i * // => ['0', '1'] */ var keys = !nativeKeys ? shimKeys : function(object) { - var Ctor = object != null && object.constructor; + var Ctor = object == null ? null : object.constructor; if ((typeof Ctor == 'function' && Ctor.prototype === object) || (typeof object != 'function' && isArrayLike(object))) { return shimKeys(object); diff --git a/object/keysIn.js b/object/keysIn.js index 6fbd497d5..1eeafc169 100644 --- a/object/keysIn.js +++ b/object/keysIn.js @@ -1,4 +1,4 @@ -define(['../lang/isArguments', '../lang/isArray', '../internal/isIndex', '../internal/isLength', '../lang/isObject', '../support'], function(isArguments, isArray, isIndex, isLength, isObject, support) { +define(['../lang/isArguments', '../lang/isArray', '../internal/isIndex', '../internal/isLength', '../lang/isObject'], function(isArguments, isArray, isIndex, isLength, isObject) { /** Used for native method references. */ var objectProto = Object.prototype; @@ -37,7 +37,7 @@ define(['../lang/isArguments', '../lang/isArray', '../internal/isIndex', '../int } var length = object.length; length = (length && isLength(length) && - (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0; + (isArray(object) || isArguments(object)) && length) || 0; var Ctor = object.constructor, index = -1, diff --git a/object/pairs.js b/object/pairs.js index b5fc5c311..f50463bcb 100644 --- a/object/pairs.js +++ b/object/pairs.js @@ -1,4 +1,4 @@ -define(['./keys'], function(keys) { +define(['./keys', '../internal/toObject'], function(keys, toObject) { /** * Creates a two dimensional array of the key-value pairs for `object`, @@ -15,6 +15,8 @@ define(['./keys'], function(keys) { * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed) */ function pairs(object) { + object = toObject(object); + var index = -1, props = keys(object), length = props.length, diff --git a/object/transform.js b/object/transform.js index 612c71eed..436faf2ed 100644 --- a/object/transform.js +++ b/object/transform.js @@ -39,7 +39,7 @@ define(['../internal/arrayEach', '../internal/baseCallback', '../internal/baseCr if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype); + accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : null); } } else { accumulator = {}; diff --git a/package.json b/package.json index 926d8094c..e04894d98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash", - "version": "3.8.0", + "version": "3.9.0", "main": "main.js", "private": true, "volo": { diff --git a/string/escape.js b/string/escape.js index 076352d72..41e798367 100644 --- a/string/escape.js +++ b/string/escape.js @@ -12,7 +12,7 @@ define(['../internal/baseToString', '../internal/escapeHtmlChar'], function(base * use a third-party library like [_he_](https://mths.be/he). * * Though the ">" character is escaped for symmetry, characters like - * ">" and "/" don't require escaping in HTML and have no special meaning + * ">" and "/" don't need escaping in HTML and have no special meaning * unless they're part of a tag or unquoted attribute value. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. diff --git a/string/pad.js b/string/pad.js index a5132c447..df116b20b 100644 --- a/string/pad.js +++ b/string/pad.js @@ -8,7 +8,7 @@ define(['../internal/baseToString', '../internal/createPadding', '../internal/ro var nativeIsFinite = root.isFinite; /** - * Pads `string` on the left and right sides if it is shorter than `length`. + * Pads `string` on the left and right sides if it's shorter than `length`. * Padding characters are truncated if they can't be evenly divided by `length`. * * @static diff --git a/string/padLeft.js b/string/padLeft.js index 8308143a7..55224a9a9 100644 --- a/string/padLeft.js +++ b/string/padLeft.js @@ -1,7 +1,7 @@ define(['../internal/createPadDir'], function(createPadDir) { /** - * Pads `string` on the left side if it is shorter than `length`. Padding + * Pads `string` on the left side if it's shorter than `length`. Padding * characters are truncated if they exceed `length`. * * @static diff --git a/string/padRight.js b/string/padRight.js index 774efd2cd..0fae3e9b9 100644 --- a/string/padRight.js +++ b/string/padRight.js @@ -1,7 +1,7 @@ define(['../internal/createPadDir'], function(createPadDir) { /** - * Pads `string` on the right side if it is shorter than `length`. Padding + * Pads `string` on the right side if it's shorter than `length`. Padding * characters are truncated if they exceed `length`. * * @static diff --git a/string/trunc.js b/string/trunc.js index 8e0447174..a8d0b53a4 100644 --- a/string/trunc.js +++ b/string/trunc.js @@ -8,7 +8,7 @@ define(['../internal/baseToString', '../internal/isIterateeCall', '../lang/isObj var reFlags = /\w*$/; /** - * Truncates `string` if it is longer than the given maximum string length. + * Truncates `string` if it's longer than the given maximum string length. * The last characters of the truncated string are replaced with the omission * string which defaults to "...". * diff --git a/support.js b/support.js index f632d7992..f2141836e 100644 --- a/support.js +++ b/support.js @@ -1,13 +1,7 @@ define(['./internal/root'], function(root) { - /** Used for native method references. */ - var objectProto = Object.prototype; - /** Used to detect DOM support. */ - var document = (document = root.window) && document.document; - - /** Native method references. */ - var propertyIsEnumerable = objectProto.propertyIsEnumerable; + var document = (document = root.window) ? document.document : null; /** * An object environment feature flags. @@ -20,31 +14,12 @@ define(['./internal/root'], function(root) { (function(x) { var Ctor = function() { this.x = x; }, - args = arguments, object = { '0': x, 'length': x }, props = []; Ctor.prototype = { 'valueOf': x, 'y': x }; for (var key in new Ctor) { props.push(key); } - /** - * Detect if functions can be decompiled by `Function#toString` - * (all but Firefox OS certified apps, older Opera mobile browsers, and - * the PlayStation 3; forced `false` for Windows 8 apps). - * - * @memberOf _.support - * @type boolean - */ - support.funcDecomp = /\bthis\b/.test(function() { return this; }); - - /** - * Detect if `Function#name` is supported (all but IE). - * - * @memberOf _.support - * @type boolean - */ - support.funcNames = typeof Function.name == 'string'; - /** * Detect if the DOM is supported. * @@ -56,24 +31,6 @@ define(['./internal/root'], function(root) { } catch(e) { support.dom = false; } - - /** - * Detect if `arguments` object indexes are non-enumerable. - * - * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object - * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat - * `arguments` object indexes as non-enumerable and fail `hasOwnProperty` - * checks for indexes that exceed the number of function parameters and - * whose associated argument values are `0`. - * - * @memberOf _.support - * @type boolean - */ - try { - support.nonEnumArgs = !propertyIsEnumerable.call(args, 1); - } catch(e) { - support.nonEnumArgs = true; - } }(1, 0)); return support; diff --git a/utility/matchesProperty.js b/utility/matchesProperty.js index 30755d0b6..6ec905c88 100644 --- a/utility/matchesProperty.js +++ b/utility/matchesProperty.js @@ -12,7 +12,7 @@ define(['../internal/baseClone', '../internal/baseMatchesProperty'], function(ba * @memberOf _ * @category Utility * @param {Array|string} path The path of the property to get. - * @param {*} value The value to compare. + * @param {*} srcValue The value to match. * @returns {Function} Returns the new function. * @example * @@ -24,8 +24,8 @@ define(['../internal/baseClone', '../internal/baseMatchesProperty'], function(ba * _.find(users, _.matchesProperty('user', 'fred')); * // => { 'user': 'fred' } */ - function matchesProperty(path, value) { - return baseMatchesProperty(path, baseClone(value, true)); + function matchesProperty(path, srcValue) { + return baseMatchesProperty(path, baseClone(srcValue, true)); } return matchesProperty; diff --git a/utility/mixin.js b/utility/mixin.js index ad115e5a5..c6ec3e721 100644 --- a/utility/mixin.js +++ b/utility/mixin.js @@ -31,9 +31,6 @@ define(['../internal/arrayCopy', '../internal/baseFunctions', '../lang/isFunctio * }); * } * - * // use `_.runInContext` to avoid conflicts (esp. in Node.js) - * var _ = require('lodash').runInContext(); - * * _.mixin({ 'vowels': vowels }); * _.vowels('fred'); * // => ['e'] diff --git a/utility/times.js b/utility/times.js index 6304ae532..de17e3227 100644 --- a/utility/times.js +++ b/utility/times.js @@ -8,7 +8,7 @@ define(['../internal/bindCallback', '../internal/root'], function(bindCallback, nativeMin = Math.min; /** Used as references for the maximum length and index of an array. */ - var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1; + var MAX_ARRAY_LENGTH = 4294967295; /** * Invokes the iteratee function `n` times, returning an array of the results