Compare commits

..

1 Commits

Author SHA1 Message Date
John-David Dalton
fec213a98c Bump to v3.7.0. 2015-12-16 17:49:35 -08:00
121 changed files with 1686 additions and 815 deletions

View File

@@ -1,4 +1,4 @@
# lodash v3.6.0 # lodash v3.7.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. 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.
@@ -10,6 +10,13 @@ $ lodash modern exports=amd -d -o ./main.js
## Installation ## Installation
Using bower or volo:
```bash
$ bower i lodash#3.7.0-amd
$ volo add lodash/3.7.0-amd
```
Defining a build as `'lodash'`. Defining a build as `'lodash'`.
```js ```js

View File

@@ -23,7 +23,8 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
argsLength = arguments.length, argsLength = arguments.length,
caches = [], caches = [],
indexOf = baseIndexOf, indexOf = baseIndexOf,
isCommon = true; isCommon = true,
result = [];
while (++argsIndex < argsLength) { while (++argsIndex < argsLength) {
var value = arguments[argsIndex]; var value = arguments[argsIndex];
@@ -33,10 +34,12 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
} }
} }
argsLength = args.length; argsLength = args.length;
if (argsLength < 2) {
return result;
}
var array = args[0], var array = args[0],
index = -1, index = -1,
length = array ? array.length : 0, length = array ? array.length : 0,
result = [],
seen = caches[0]; seen = caches[0];
outer: outer:

View File

@@ -1,10 +1,4 @@
define(['../internal/baseAt', '../internal/baseCompareAscending', '../internal/baseFlatten', '../internal/isIndex', '../function/restParam'], function(baseAt, baseCompareAscending, baseFlatten, isIndex, restParam) { define(['../internal/baseAt', '../internal/baseCompareAscending', '../internal/baseFlatten', '../internal/basePullAt', '../function/restParam'], function(baseAt, baseCompareAscending, baseFlatten, basePullAt, restParam) {
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/** /**
* Removes elements from `array` corresponding to the given indexes and returns * Removes elements from `array` corresponding to the given indexes and returns
@@ -35,17 +29,8 @@ define(['../internal/baseAt', '../internal/baseCompareAscending', '../internal/b
array || (array = []); array || (array = []);
indexes = baseFlatten(indexes); indexes = baseFlatten(indexes);
var length = indexes.length, var result = baseAt(array, indexes);
result = baseAt(array, indexes); basePullAt(array, indexes.sort(baseCompareAscending));
indexes.sort(baseCompareAscending);
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return result; return result;
}); });

View File

@@ -1,10 +1,4 @@
define(['../internal/baseCallback'], function(baseCallback) { define(['../internal/baseCallback', '../internal/basePullAt'], function(baseCallback, basePullAt) {
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/** /**
* Removes all elements from `array` that `predicate` returns truthy for * Removes all elements from `array` that `predicate` returns truthy for
@@ -46,19 +40,23 @@ define(['../internal/baseCallback'], function(baseCallback) {
* // => [2, 4] * // => [2, 4]
*/ */
function remove(array, predicate, thisArg) { function remove(array, predicate, thisArg) {
var result = [];
if (!(array && array.length)) {
return result;
}
var index = -1, var index = -1,
length = array ? array.length : 0, indexes = [],
result = []; length = array.length;
predicate = baseCallback(predicate, thisArg, 3); predicate = baseCallback(predicate, thisArg, 3);
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];
if (predicate(value, index, array)) { if (predicate(value, index, array)) {
result.push(value); result.push(value);
splice.call(array, index--, 1); indexes.push(index);
length--;
} }
} }
basePullAt(array, indexes);
return result; return result;
} }

View File

@@ -3,7 +3,7 @@ define(['../internal/baseSlice', '../internal/isIterateeCall'], function(baseSli
/** /**
* Creates a slice of `array` from `start` up to, but not including, `end`. * Creates a slice of `array` from `start` up to, but not including, `end`.
* *
* **Note:** This function is used instead of `Array#slice` to support node * **Note:** This method is used instead of `Array#slice` to support node
* lists in IE < 9 and to ensure dense arrays are returned. * lists in IE < 9 and to ensure dense arrays are returned.
* *
* @static * @static

View File

@@ -1,12 +1,13 @@
define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isIterateeCall', '../internal/sortedUniq'], function(baseCallback, baseUniq, isIterateeCall, sortedUniq) { define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isIterateeCall', '../internal/sortedUniq'], function(baseCallback, baseUniq, isIterateeCall, sortedUniq) {
/** /**
* Creates a duplicate-value-free version of an array using `SameValueZero` * Creates a duplicate-free version of an array, using `SameValueZero` for
* for equality comparisons. Providing `true` for `isSorted` performs a faster * equality comparisons, in which only the first occurence of each element
* search algorithm for sorted arrays. If an iteratee function is provided it * is kept. Providing `true` for `isSorted` performs a faster search algorithm
* is invoked for each value in the array to generate the criterion by which * for sorted arrays. If an iteratee function is provided it is invoked for
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked * each element in the array to generate the criterion by which uniqueness
* with three arguments: (value, index, array). * is computed. The `iteratee` is bound to `thisArg` and invoked with three
* arguments: (value, index, array).
* *
* If a property name is provided for `iteratee` the created `_.property` * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
@@ -34,8 +35,8 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
* @returns {Array} Returns the new duplicate-value-free array. * @returns {Array} Returns the new duplicate-value-free array.
* @example * @example
* *
* _.uniq([1, 2, 1]); * _.uniq([2, 1, 2]);
* // => [1, 2] * // => [2, 1]
* *
* // using `isSorted` * // using `isSorted`
* _.uniq([1, 1, 2], true); * _.uniq([1, 1, 2], true);

View File

@@ -1,7 +1,4 @@
define(['../internal/arrayMap', '../internal/arrayMax', '../internal/baseProperty'], function(arrayMap, arrayMax, baseProperty) { define(['../internal/arrayMap', '../internal/arrayMax', '../internal/baseProperty', '../internal/getLength'], function(arrayMap, arrayMax, baseProperty, getLength) {
/** Used to the length of n-tuples for `_.unzip`. */
var getLength = baseProperty('length');
/** /**
* This method is like `_.zip` except that it accepts an array of grouped * This method is like `_.zip` except that it accepts an array of grouped

View File

@@ -45,8 +45,8 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/bas
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`, * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`,
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, * `merge`, `mixin`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`, * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`, * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
@@ -60,15 +60,15 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/bas
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`, * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`
* `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, * `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `isTypedArray`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, * `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, `noConflict`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, * `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, * `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, `shift`, `size`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`, `startsWith`,
* `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`, * `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`,
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words` * `uniqueId`, `value`, and `words`
* *
* The wrapper method `sample` will return a wrapped value when `n` is provided, * The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned. * otherwise an unwrapped value is returned.
@@ -83,8 +83,8 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/bas
* var wrapped = _([1, 2, 3]); * var wrapped = _([1, 2, 3]);
* *
* // returns an unwrapped value * // returns an unwrapped value
* wrapped.reduce(function(sum, n) { * wrapped.reduce(function(total, n) {
* return sum + n; * return total + n;
* }); * });
* // => 6 * // => 6
* *

View File

@@ -1,4 +1,4 @@
define(['../internal/baseAt', '../internal/baseFlatten', '../internal/isLength', '../function/restParam', '../internal/toIterable'], function(baseAt, baseFlatten, isLength, restParam, toIterable) { define(['../internal/baseAt', '../internal/baseFlatten', '../internal/getLength', '../internal/isLength', '../function/restParam', '../internal/toIterable'], function(baseAt, baseFlatten, getLength, isLength, restParam, toIterable) {
/** /**
* Creates an array of elements corresponding to the given keys, or indexes, * Creates an array of elements corresponding to the given keys, or indexes,
@@ -21,7 +21,7 @@ define(['../internal/baseAt', '../internal/baseFlatten', '../internal/isLength',
* // => ['barney', 'pebbles'] * // => ['barney', 'pebbles']
*/ */
var at = restParam(function(collection, props) { var at = restParam(function(collection, props) {
var length = collection ? collection.length : 0; var length = collection ? getLength(collection) : 0;
if (isLength(length)) { if (isLength(length)) {
collection = toIterable(collection); collection = toIterable(collection);
} }

View File

@@ -1,5 +1,8 @@
define(['../internal/arrayEvery', '../internal/baseCallback', '../internal/baseEvery', '../lang/isArray', '../internal/isIterateeCall'], function(arrayEvery, baseCallback, baseEvery, isArray, isIterateeCall) { define(['../internal/arrayEvery', '../internal/baseCallback', '../internal/baseEvery', '../lang/isArray', '../internal/isIterateeCall'], function(arrayEvery, baseCallback, baseEvery, isArray, isIterateeCall) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Checks if `predicate` returns truthy for **all** elements of `collection`. * Checks if `predicate` returns truthy for **all** elements of `collection`.
* The predicate is bound to `thisArg` and invoked with three arguments: * The predicate is bound to `thisArg` and invoked with three arguments:
@@ -53,7 +56,7 @@ define(['../internal/arrayEvery', '../internal/baseCallback', '../internal/baseE
if (thisArg && isIterateeCall(collection, predicate, thisArg)) { if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null; predicate = null;
} }
if (typeof predicate != 'function' || typeof thisArg != 'undefined') { if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3); predicate = baseCallback(predicate, thisArg, 3);
} }
return func(collection, predicate); return func(collection, predicate);

View File

@@ -3,10 +3,10 @@ define(['../internal/arrayEach', '../internal/baseEach', '../internal/createForE
/** /**
* Iterates over elements of `collection` invoking `iteratee` for each element. * Iterates over elements of `collection` invoking `iteratee` for each element.
* The `iteratee` is bound to `thisArg` and invoked with three arguments: * The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection). Iterator functions may exit iteration early * (value, index|key, collection). Iteratee functions may exit iteration early
* by explicitly returning `false`. * by explicitly returning `false`.
* *
* **Note:** As with other "Collections" methods, objects with a `length` property * **Note:** As with other "Collections" methods, objects with a "length" property
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn` * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
* may be used for object iteration. * may be used for object iteration.
* *

View File

@@ -1,4 +1,4 @@
define(['../internal/baseIndexOf', '../lang/isArray', '../internal/isIterateeCall', '../internal/isLength', '../lang/isString', '../object/values'], function(baseIndexOf, isArray, isIterateeCall, isLength, isString, values) { define(['../internal/baseIndexOf', '../internal/getLength', '../lang/isArray', '../internal/isIterateeCall', '../internal/isLength', '../lang/isString', '../object/values'], function(baseIndexOf, getLength, isArray, isIterateeCall, isLength, isString, values) {
/* Native method references for those with the same name as other `lodash` methods. */ /* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max; var nativeMax = Math.max;
@@ -36,7 +36,7 @@ define(['../internal/baseIndexOf', '../lang/isArray', '../internal/isIterateeCal
* // => true * // => true
*/ */
function includes(collection, target, fromIndex, guard) { function includes(collection, target, fromIndex, guard) {
var length = collection ? collection.length : 0; var length = collection ? getLength(collection) : 0;
if (!isLength(length)) { if (!isLength(length)) {
collection = values(collection); collection = values(collection);
length = collection.length; length = collection.length;

View File

@@ -1,19 +1,16 @@
define(['../internal/baseEach', '../internal/isLength', '../function/restParam'], function(baseEach, isLength, restParam) { define(['../internal/baseEach', '../internal/getLength', '../internal/invokePath', '../internal/isKey', '../internal/isLength', '../function/restParam'], function(baseEach, getLength, invokePath, isKey, isLength, restParam) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Invokes the method named by `methodName` on each element in `collection`, * Invokes the method at `path` on each element in `collection`, returning
* returning an array of the results of each invoked method. Any additional * an array of the results of each invoked method. Any additional arguments
* arguments are provided to each invoked method. If `methodName` is a function * are provided to each invoked method. If `methodName` is a function it is
* it is invoked for, and `this` bound to, each element in `collection`. * invoked for, and `this` bound to, each element in `collection`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|string} methodName The name of the method to invoke or * @param {Array|Function|string} path The path of the method to invoke or
* the function invoked per iteration. * the function invoked per iteration.
* @param {...*} [args] The arguments to invoke the method with. * @param {...*} [args] The arguments to invoke the method with.
* @returns {Array} Returns the array of results. * @returns {Array} Returns the array of results.
@@ -25,15 +22,16 @@ define(['../internal/baseEach', '../internal/isLength', '../function/restParam']
* _.invoke([123, 456], String.prototype.split, ''); * _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']] * // => [['1', '2', '3'], ['4', '5', '6']]
*/ */
var invoke = restParam(function(collection, methodName, args) { var invoke = restParam(function(collection, path, args) {
var index = -1, var index = -1,
isFunc = typeof methodName == 'function', isFunc = typeof path == 'function',
length = collection ? collection.length : 0, isProp = isKey(path),
length = getLength(collection),
result = isLength(length) ? Array(length) : []; result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) { baseEach(collection, function(value) {
var func = isFunc ? methodName : (value != null && value[methodName]); var func = isFunc ? path : (isProp && value != null && value[path]);
result[++index] = func ? func.apply(value, args) : undefined; result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
}); });
return result; return result;
}); });

View File

@@ -32,7 +32,6 @@ define(['../internal/arrayMap', '../internal/baseCallback', '../internal/baseMap
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. * per iteration.
* create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
* @example * @example

View File

@@ -1,13 +1,13 @@
define(['../internal/baseProperty', './map'], function(baseProperty, map) { define(['./map', '../utility/property'], function(map, property) {
/** /**
* Gets the value of `key` from all elements in `collection`. * Gets the property value of `path` from all elements in `collection`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {string} key The key of the property to pluck. * @param {Array|string} path The path of the property to pluck.
* @returns {Array} Returns the property values. * @returns {Array} Returns the property values.
* @example * @example
* *
@@ -23,8 +23,8 @@ define(['../internal/baseProperty', './map'], function(baseProperty, map) {
* _.pluck(userIndex, 'age'); * _.pluck(userIndex, 'age');
* // => [36, 40] (iteration order is not guaranteed) * // => [36, 40] (iteration order is not guaranteed)
*/ */
function pluck(collection, key) { function pluck(collection, path) {
return map(collection, baseProperty(key)); return map(collection, property(path));
} }
return pluck; return pluck;

View File

@@ -25,8 +25,8 @@ define(['../internal/arrayReduce', '../internal/baseEach', '../internal/createRe
* @returns {*} Returns the accumulated value. * @returns {*} Returns the accumulated value.
* @example * @example
* *
* _.reduce([1, 2], function(sum, n) { * _.reduce([1, 2], function(total, n) {
* return sum + n; * return total + n;
* }); * });
* // => 3 * // => 3
* *

View File

@@ -1,4 +1,4 @@
define(['../internal/isLength', '../object/keys'], function(isLength, keys) { define(['../internal/getLength', '../internal/isLength', '../object/keys'], function(getLength, isLength, keys) {
/** /**
* Gets the size of `collection` by returning its length for array-like * Gets the size of `collection` by returning its length for array-like
@@ -21,7 +21,7 @@ define(['../internal/isLength', '../object/keys'], function(isLength, keys) {
* // => 7 * // => 7
*/ */
function size(collection) { function size(collection) {
var length = collection ? collection.length : 0; var length = collection ? getLength(collection) : 0;
return isLength(length) ? length : keys(collection).length; return isLength(length) ? length : keys(collection).length;
} }

View File

@@ -1,5 +1,8 @@
define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSome', '../lang/isArray', '../internal/isIterateeCall'], function(arraySome, baseCallback, baseSome, isArray, isIterateeCall) { define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSome', '../lang/isArray', '../internal/isIterateeCall'], function(arraySome, baseCallback, baseSome, isArray, isIterateeCall) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Checks if `predicate` returns truthy for **any** element of `collection`. * Checks if `predicate` returns truthy for **any** element of `collection`.
* The function returns as soon as it finds a passing value and does not iterate * The function returns as soon as it finds a passing value and does not iterate
@@ -54,7 +57,7 @@ define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSo
if (thisArg && isIterateeCall(collection, predicate, thisArg)) { if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null; predicate = null;
} }
if (typeof predicate != 'function' || typeof thisArg != 'undefined') { if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3); predicate = baseCallback(predicate, thisArg, 3);
} }
return func(collection, predicate); return func(collection, predicate);

View File

@@ -1,4 +1,4 @@
define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSortBy', '../internal/compareAscending', '../internal/isIterateeCall', '../internal/isLength'], function(baseCallback, baseEach, baseSortBy, compareAscending, isIterateeCall, isLength) { define(['../internal/baseCallback', '../internal/baseMap', '../internal/baseSortBy', '../internal/compareAscending', '../internal/isIterateeCall'], function(baseCallback, baseMap, baseSortBy, compareAscending, isIterateeCall) {
/** /**
* Creates an array of elements, sorted in ascending order by the results of * Creates an array of elements, sorted in ascending order by the results of
@@ -22,9 +22,8 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|Object|string} [iteratee=_.identity] The function * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* invoked per iteration. If a property name or an object is provided it is * per iteration.
* used to create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
* @example * @example
@@ -53,16 +52,14 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
if (collection == null) { if (collection == null) {
return []; return [];
} }
var index = -1,
length = collection.length,
result = isLength(length) ? Array(length) : [];
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null; iteratee = null;
} }
var index = -1;
iteratee = baseCallback(iteratee, thisArg, 3); iteratee = baseCallback(iteratee, thisArg, 3);
baseEach(collection, function(value, key, collection) {
result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value }; var result = baseMap(collection, function(value, key, collection) {
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
}); });
return baseSortBy(result, compareAscending); return baseSortBy(result, compareAscending);
} }

View File

@@ -1,47 +1,50 @@
define(['../internal/baseFlatten', '../internal/baseSortByOrder', '../internal/isIterateeCall'], function(baseFlatten, baseSortByOrder, isIterateeCall) { define(['../internal/baseFlatten', '../internal/baseSortByOrder', '../internal/isIterateeCall', '../function/restParam'], function(baseFlatten, baseSortByOrder, isIterateeCall, restParam) {
/** /**
* This method is like `_.sortBy` except that it sorts by property names * This method is like `_.sortBy` except that it can sort by multiple iteratees
* instead of an iteratee function. * or property names.
*
* If a property name is provided for an iteratee the created `_.property`
* style callback returns the property value of the given element.
*
* If an object is provided for an iteratee the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {...(string|string[])} props The property names to sort by, * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
* specified as individual property names or arrays of property names. * The iteratees to sort by, specified as individual values or arrays of values.
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 36 }, * { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }, * { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 26 }, * { 'user': 'barney', 'age': 34 }
* { 'user': 'fred', 'age': 30 }
* ]; * ];
* *
* _.map(_.sortByAll(users, ['user', 'age']), _.values); * _.map(_.sortByAll(users, ['user', 'age']), _.values);
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]] * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
*
* _.map(_.sortByAll(users, 'user', function(chr) {
* return Math.floor(chr.age / 10);
* }), _.values);
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/ */
function sortByAll() { var sortByAll = restParam(function(collection, iteratees) {
var args = arguments,
collection = args[0],
guard = args[3],
index = 0,
length = args.length - 1;
if (collection == null) { if (collection == null) {
return []; return [];
} }
var props = Array(length); var guard = iteratees[2];
while (index < length) { if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
props[index] = args[++index]; iteratees.length = 1;
} }
if (guard && isIterateeCall(args[1], args[2], guard)) { return baseSortByOrder(collection, baseFlatten(iteratees), []);
props = args[1]; });
}
return baseSortByOrder(collection, baseFlatten(props), []);
}
return sortByAll; return sortByAll;
}); });

View File

@@ -2,45 +2,52 @@ define(['../internal/baseSortByOrder', '../lang/isArray', '../internal/isIterate
/** /**
* This method is like `_.sortByAll` except that it allows specifying the * This method is like `_.sortByAll` except that it allows specifying the
* sort orders of the property names to sort by. A truthy value in `orders` * sort orders of the iteratees to sort by. A truthy value in `orders` will
* will sort the corresponding property name in ascending order while a * sort the corresponding property name in ascending order while a falsey
* falsey value will sort it in descending order. * value will sort it in descending order.
*
* If a property name is provided for an iteratee the created `_.property`
* style callback returns the property value of the given element.
*
* If an object is provided for an iteratee the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} orders The sort orders of `props`. * @param {boolean[]} orders The sort orders of `iteratees`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 26 }, * { 'user': 'fred', 'age': 48 },
* { 'user': 'fred', 'age': 40 }, * { 'user': 'barney', 'age': 34 },
* { 'user': 'barney', 'age': 36 }, * { 'user': 'fred', 'age': 42 },
* { 'user': 'fred', 'age': 30 } * { 'user': 'barney', 'age': 36 }
* ]; * ];
* *
* // sort by `user` in ascending order and by `age` in descending order * // sort by `user` in ascending order and by `age` in descending order
* _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values); * _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);
* // => [['barney', 36], ['barney', 26], ['fred', 40], ['fred', 30]] * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/ */
function sortByOrder(collection, props, orders, guard) { function sortByOrder(collection, iteratees, orders, guard) {
if (collection == null) { if (collection == null) {
return []; return [];
} }
if (guard && isIterateeCall(props, orders, guard)) { if (guard && isIterateeCall(iteratees, orders, guard)) {
orders = null; orders = null;
} }
if (!isArray(props)) { if (!isArray(iteratees)) {
props = props == null ? [] : [props]; iteratees = iteratees == null ? [] : [iteratees];
} }
if (!isArray(orders)) { if (!isArray(orders)) {
orders = orders == null ? [] : [orders]; orders = orders == null ? [] : [orders];
} }
return baseSortByOrder(collection, props, orders); return baseSortByOrder(collection, iteratees, orders);
} }
return sortByOrder; return sortByOrder;

View File

@@ -33,7 +33,8 @@ define([], function() {
return function() { return function() {
if (--n > 0) { if (--n > 0) {
result = func.apply(this, arguments); result = func.apply(this, arguments);
} else { }
if (n <= 1) {
func = null; func = null;
} }
return result; return result;

View File

@@ -12,7 +12,7 @@ define(['../internal/createWrapper', '../internal/replaceHolders', './restParam'
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for partially applied arguments. * may be used as a placeholder for partially applied arguments.
* *
* **Note:** Unlike native `Function#bind` this method does not set the `length` * **Note:** Unlike native `Function#bind` this method does not set the "length"
* property of bound functions. * property of bound functions.
* *
* @static * @static

View File

@@ -9,7 +9,7 @@ define(['../internal/baseFlatten', '../internal/createWrapper', '../object/funct
* of method names. If no method names are provided all enumerable function * of method names. If no method names are provided all enumerable function
* properties, own and inherited, of `object` are bound. * properties, own and inherited, of `object` are bound.
* *
* **Note:** This method does not set the `length` property of bound functions. * **Note:** This method does not set the "length" property of bound functions.
* *
* @static * @static
* @memberOf _ * @memberOf _

View File

@@ -11,7 +11,7 @@ define(['../internal/createWrapper', '../internal/replaceHolders', './restParam'
* *
* This method differs from `_.bind` by allowing bound functions to reference * This method differs from `_.bind` by allowing bound functions to reference
* methods that may be redefined or don't yet exist. * methods that may be redefined or don't yet exist.
* See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern) * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
* for more details. * for more details.
* *
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic

View File

@@ -13,7 +13,7 @@ define(['../internal/createCurry'], function(createCurry) {
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for provided arguments. * may be used as a placeholder for provided arguments.
* *
* **Note:** This method does not set the `length` property of curried functions. * **Note:** This method does not set the "length" property of curried functions.
* *
* @static * @static
* @memberOf _ * @memberOf _

View File

@@ -10,7 +10,7 @@ define(['../internal/createCurry'], function(createCurry) {
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for provided arguments. * builds, may be used as a placeholder for provided arguments.
* *
* **Note:** This method does not set the `length` property of curried functions. * **Note:** This method does not set the "length" property of curried functions.
* *
* @static * @static
* @memberOf _ * @memberOf _

View File

@@ -18,7 +18,7 @@ define(['./before'], function(before) {
* // `initialize` invokes `createApplication` once * // `initialize` invokes `createApplication` once
*/ */
function once(func) { function once(func) {
return before(func, 2); return before(2, func);
} }
return once; return once;

View File

@@ -11,7 +11,7 @@ define(['../internal/createPartial'], function(createPartial) {
* The `_.partial.placeholder` value, which defaults to `_` in monolithic * The `_.partial.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments. * builds, may be used as a placeholder for partially applied arguments.
* *
* **Note:** This method does not set the `length` property of partially * **Note:** This method does not set the "length" property of partially
* applied functions. * applied functions.
* *
* @static * @static

View File

@@ -10,7 +10,7 @@ define(['../internal/createPartial'], function(createPartial) {
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments. * builds, may be used as a placeholder for partially applied arguments.
* *
* **Note:** This method does not set the `length` property of partially * **Note:** This method does not set the "length" property of partially
* applied functions. * applied functions.
* *
* @static * @static

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -32,7 +35,7 @@ define([], function() {
if (typeof func != 'function') { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0); start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
return function() { return function() {
var args = arguments, var args = arguments,
index = -1, index = -1,

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Used by `_.defaults` to customize its `_.assign` use. * Used by `_.defaults` to customize its `_.assign` use.
* *
@@ -9,7 +12,7 @@ define([], function() {
* @returns {*} Returns the value to assign to the destination object. * @returns {*} Returns the value to assign to the destination object.
*/ */
function assignDefaults(objectValue, sourceValue) { function assignDefaults(objectValue, sourceValue) {
return typeof objectValue == 'undefined' ? sourceValue : objectValue; return objectValue === undefined ? sourceValue : objectValue;
} }
return assignDefaults; return assignDefaults;

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** Used for native method references. */ /** Used for native method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -9,7 +12,7 @@ define([], function() {
/** /**
* Used by `_.template` to customize its `_.assign` use. * Used by `_.template` to customize its `_.assign` use.
* *
* **Note:** This method is like `assignDefaults` except that it ignores * **Note:** This function is like `assignDefaults` except that it ignores
* inherited property values when checking if a property is `undefined`. * inherited property values when checking if a property is `undefined`.
* *
* @private * @private
@@ -20,7 +23,7 @@ define([], function() {
* @returns {*} Returns the value to assign to the destination object. * @returns {*} Returns the value to assign to the destination object.
*/ */
function assignOwnDefaults(objectValue, sourceValue, key, object) { function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key)) return (objectValue === undefined || !hasOwnProperty.call(object, key))
? sourceValue ? sourceValue
: objectValue; : objectValue;
} }

44
internal/assignWith.js Normal file
View File

@@ -0,0 +1,44 @@
define(['./getSymbols', '../object/keys'], function(getSymbols, 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`
* functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} customizer The function to customize assigned values.
* @returns {Object} Returns `object`.
*/
function assignWith(object, source, customizer) {
var props = keys(source);
push.apply(props, getSymbols(source));
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(value === undefined && !(key in object))) {
object[key] = result;
}
}
return object;
}
return assignWith;
});

View File

@@ -1,35 +1,38 @@
define(['./baseCopy', '../object/keys'], function(baseCopy, keys) { define(['./baseCopy', './getSymbols', '../lang/isNative', '../object/keys'], function(baseCopy, getSymbols, isNative, keys) {
/** Native method references. */
var preventExtensions = isNative(Object.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 in strict mode.
var object = { '1': 0 },
func = preventExtensions && isNative(func = Object.assign) && func;
try { func(preventExtensions(object), 'xo'); } catch(e) {}
return !object[1] && func;
}());
/** /**
* The base implementation of `_.assign` without support for argument juggling, * The base implementation of `_.assign` without support for argument juggling,
* multiple sources, and `this` binding `customizer` functions. * multiple sources, and `customizer` functions.
* *
* @private * @private
* @param {Object} object The destination object. * @param {Object} object The destination object.
* @param {Object} source The source object. * @param {Object} source The source object.
* @param {Function} [customizer] The function to customize assigning values. * @returns {Object} Returns `object`.
* @returns {Object} Returns the destination object.
*/ */
function baseAssign(object, source, customizer) { var baseAssign = nativeAssign || function(object, source) {
var props = keys(source); return source == null
if (!customizer) { ? object
return baseCopy(source, object, props); : baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
} };
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(typeof value == 'undefined' && !(key in object))) {
object[key] = result;
}
}
return object;
}
return baseAssign; return baseAssign;
}); });

View File

@@ -4,12 +4,12 @@ define(['./isIndex', './isLength'], function(isIndex, isLength) {
var undefined; var undefined;
/** /**
* The base implementation of `_.at` without support for strings and individual * The base implementation of `_.at` without support for string collections
* key arguments. * and individual key arguments.
* *
* @private * @private
* @param {Array|Object} collection The collection to iterate over. * @param {Array|Object} collection The collection to iterate over.
* @param {number[]|string[]} [props] The property names or indexes of elements to pick. * @param {number[]|string[]} props The property names or indexes of elements to pick.
* @returns {Array} Returns the new array of picked elements. * @returns {Array} Returns the new array of picked elements.
*/ */
function baseAt(collection, props) { function baseAt(collection, props) {
@@ -22,7 +22,6 @@ define(['./isIndex', './isLength'], function(isIndex, isLength) {
while(++index < propsLength) { while(++index < propsLength) {
var key = props[index]; var key = props[index];
if (isArr) { if (isArr) {
key = parseFloat(key);
result[index] = isIndex(key, length) ? collection[key] : undefined; result[index] = isIndex(key, length) ? collection[key] : undefined;
} else { } else {
result[index] = collection[key]; result[index] = collection[key];

View File

@@ -1,4 +1,7 @@
define(['./baseMatches', './baseMatchesProperty', './baseProperty', './bindCallback', '../utility/identity'], function(baseMatches, baseMatchesProperty, baseProperty, bindCallback, identity) { define(['./baseMatches', './baseMatchesProperty', './bindCallback', '../utility/identity', '../utility/property'], function(baseMatches, baseMatchesProperty, bindCallback, identity, property) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `_.callback` which supports specifying the * The base implementation of `_.callback` which supports specifying the
@@ -13,7 +16,7 @@ define(['./baseMatches', './baseMatchesProperty', './baseProperty', './bindCallb
function baseCallback(func, thisArg, argCount) { function baseCallback(func, thisArg, argCount) {
var type = typeof func; var type = typeof func;
if (type == 'function') { if (type == 'function') {
return typeof thisArg == 'undefined' return thisArg === undefined
? func ? func
: bindCallback(func, thisArg, argCount); : bindCallback(func, thisArg, argCount);
} }
@@ -23,9 +26,9 @@ define(['./baseMatches', './baseMatchesProperty', './baseProperty', './bindCallb
if (type == 'object') { if (type == 'object') {
return baseMatches(func); return baseMatches(func);
} }
return typeof thisArg == 'undefined' return thisArg === undefined
? baseProperty(func + '') ? property(func)
: baseMatchesProperty(func + '', thisArg); : baseMatchesProperty(func, thisArg);
} }
return baseCallback; return baseCallback;

View File

@@ -1,4 +1,7 @@
define(['./arrayCopy', './arrayEach', './baseCopy', './baseForOwn', './initCloneArray', './initCloneByTag', './initCloneObject', '../lang/isArray', '../lang/isObject', '../object/keys'], function(arrayCopy, arrayEach, baseCopy, baseForOwn, initCloneArray, initCloneByTag, initCloneObject, isArray, isObject, keys) { define(['./arrayCopy', './arrayEach', './baseAssign', './baseForOwn', './initCloneArray', './initCloneByTag', './initCloneObject', '../lang/isArray', '../lang/isObject'], function(arrayCopy, arrayEach, baseAssign, baseForOwn, initCloneArray, initCloneByTag, initCloneObject, isArray, isObject) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var argsTag = '[object Arguments]', var argsTag = '[object Arguments]',
@@ -69,7 +72,7 @@ define(['./arrayCopy', './arrayEach', './baseCopy', './baseForOwn', './initClone
if (customizer) { if (customizer) {
result = object ? customizer(value, key, object) : customizer(value); result = object ? customizer(value, key, object) : customizer(value);
} }
if (typeof result != 'undefined') { if (result !== undefined) {
return result; return result;
} }
if (!isObject(value)) { if (!isObject(value)) {
@@ -88,7 +91,7 @@ define(['./arrayCopy', './arrayEach', './baseCopy', './baseForOwn', './initClone
if (tag == objectTag || tag == argsTag || (isFunc && !object)) { if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
result = initCloneObject(isFunc ? {} : value); result = initCloneObject(isFunc ? {} : value);
if (!isDeep) { if (!isDeep) {
return baseCopy(value, result, keys(value)); return baseAssign(result, value);
} }
} else { } else {
return cloneableTags[tag] return cloneableTags[tag]

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `compareAscending` which compares values and * The base implementation of `compareAscending` which compares values and
* sorts them in ascending order without guaranteeing a stable sort. * sorts them in ascending order without guaranteeing a stable sort.
@@ -14,10 +17,10 @@ define([], function() {
var valIsReflexive = value === value, var valIsReflexive = value === value,
othIsReflexive = other === other; othIsReflexive = other === other;
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) { if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) {
return 1; return 1;
} }
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) { if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) {
return -1; return -1;
} }
} }

View File

@@ -1,19 +1,17 @@
define([], function() { define([], function() {
/** /**
* Copies the properties of `source` to `object`. * Copies properties of `source` to `object`.
* *
* @private * @private
* @param {Object} source The object to copy properties from. * @param {Object} source The object to copy properties from.
* @param {Object} [object={}] The object to copy properties to.
* @param {Array} props The property names to copy. * @param {Array} props The property names to copy.
* @param {Object} [object={}] The object to copy properties to.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseCopy(source, object, props) { function baseCopy(source, props, object) {
if (!props) { object || (object = {});
props = object;
object = {};
}
var index = -1, var index = -1,
length = props.length; length = props.length;

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `_.fill` without an iteratee call guard. * The base implementation of `_.fill` without an iteratee call guard.
* *
@@ -17,7 +20,7 @@ define([], function() {
if (start < 0) { if (start < 0) {
start = -start > length ? 0 : (length + start); start = -start > length ? 0 : (length + start);
} }
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) { if (end < 0) {
end += length; end += length;
} }

View File

@@ -3,7 +3,7 @@ define(['./createBaseFor'], function(createBaseFor) {
/** /**
* The base implementation of `baseForIn` and `baseForOwn` which iterates * The base implementation of `baseForIn` and `baseForOwn` which iterates
* over `object` properties returned by `keysFunc` invoking `iteratee` for * over `object` properties returned by `keysFunc` invoking `iteratee` for
* each property. Iterator functions may exit iteration early by explicitly * each property. Iteratee functions may exit iteration early by explicitly
* returning `false`. * returning `false`.
* *
* @private * @private

33
internal/baseGet.js Normal file
View File

@@ -0,0 +1,33 @@
define(['./toObject'], function(toObject) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* The base implementation of `get` without support for string paths
* and default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array} path The path of the property to get.
* @param {string} [pathKey] The key representation of path.
* @returns {*} Returns the resolved value.
*/
function baseGet(object, path, pathKey) {
if (object == null) {
return;
}
if (pathKey !== undefined && pathKey in toObject(object)) {
path = [pathKey];
}
var index = -1,
length = path.length;
while (object != null && ++index < length) {
var result = object = object[path[index]];
}
return result;
}
return baseGet;
});

View File

@@ -3,7 +3,6 @@ define(['./equalArrays', './equalByTag', './equalObjects', '../lang/isArray', '.
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var argsTag = '[object Arguments]', var argsTag = '[object Arguments]',
arrayTag = '[object Array]', arrayTag = '[object Array]',
funcTag = '[object Function]',
objectTag = '[object Object]'; objectTag = '[object Object]';
/** Used for native method references. */ /** Used for native method references. */
@@ -55,27 +54,23 @@ define(['./equalArrays', './equalByTag', './equalObjects', '../lang/isArray', '.
othIsArr = isTypedArray(other); othIsArr = isTypedArray(other);
} }
} }
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)), var objIsObj = objTag == objectTag,
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)), othIsObj = othTag == objectTag,
isSameTag = objTag == othTag; isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) { if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag); return equalByTag(object, other, objTag);
} }
if (isLoose) { if (!isLoose) {
if (!isSameTag && !(objIsObj && othIsObj)) {
return false;
}
} else {
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (valWrapped || othWrapped) { if (valWrapped || othWrapped) {
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB); return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
} }
if (!isSameTag) { }
return false; if (!isSameTag) {
} return false;
} }
// Assume cyclic values are equal. // Assume cyclic values are equal.
// For more information on detecting circular references see https://es5.github.io/#JO. // For more information on detecting circular references see https://es5.github.io/#JO.

View File

@@ -35,10 +35,10 @@ define(['./baseIsEqual'], function(baseIsEqual) {
srcValue = values[index]; srcValue = values[index];
if (noCustomizer && strictCompareFlags[index]) { if (noCustomizer && strictCompareFlags[index]) {
var result = typeof objValue != 'undefined' || (key in object); var result = objValue !== undefined || (key in object);
} else { } else {
result = customizer ? customizer(objValue, srcValue, key) : undefined; result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (typeof result == 'undefined') { if (result === undefined) {
result = baseIsEqual(srcValue, objValue, customizer, true); result = baseIsEqual(srcValue, objValue, customizer, true);
} }
} }

View File

@@ -1,4 +1,4 @@
define(['./baseEach'], function(baseEach) { define(['./baseEach', './getLength', './isLength'], function(baseEach, getLength, isLength) {
/** /**
* The base implementation of `_.map` without support for callback shorthands * The base implementation of `_.map` without support for callback shorthands
@@ -10,9 +10,12 @@ define(['./baseEach'], function(baseEach) {
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
*/ */
function baseMap(collection, iteratee) { function baseMap(collection, iteratee) {
var result = []; var index = -1,
length = getLength(collection),
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value, key, collection) { baseEach(collection, function(value, key, collection) {
result.push(iteratee(value, key, collection)); result[++index] = iteratee(value, key, collection);
}); });
return result; return result;
} }

View File

@@ -1,5 +1,8 @@
define(['./baseIsMatch', '../utility/constant', './isStrictComparable', '../object/keys', './toObject'], function(baseIsMatch, constant, isStrictComparable, keys, toObject) { define(['./baseIsMatch', '../utility/constant', './isStrictComparable', '../object/keys', './toObject'], function(baseIsMatch, constant, isStrictComparable, keys, toObject) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `_.matches` which does not clone `source`. * The base implementation of `_.matches` which does not clone `source`.
* *
@@ -20,8 +23,10 @@ define(['./baseIsMatch', '../utility/constant', './isStrictComparable', '../obje
if (isStrictComparable(value)) { if (isStrictComparable(value)) {
return function(object) { return function(object) {
return object != null && object[key] === value && if (object == null) {
(typeof value != 'undefined' || (key in toObject(object))); return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
}; };
} }
} }

View File

@@ -1,23 +1,40 @@
define(['./baseIsEqual', './isStrictComparable', './toObject'], function(baseIsEqual, isStrictComparable, toObject) { define(['./baseGet', './baseIsEqual', './baseSlice', '../lang/isArray', './isKey', './isStrictComparable', '../array/last', './toObject', './toPath'], function(baseGet, baseIsEqual, baseSlice, isArray, isKey, isStrictComparable, last, toObject, toPath) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `_.matchesProperty` which does not coerce `key` * The base implementation of `_.matchesProperty` which does not which does
* to a string. * not clone `value`.
* *
* @private * @private
* @param {string} key The key of the property to get. * @param {string} path The path of the property to get.
* @param {*} value The value to compare. * @param {*} value The value to compare.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
*/ */
function baseMatchesProperty(key, value) { function baseMatchesProperty(path, value) {
if (isStrictComparable(value)) { var isArr = isArray(path),
return function(object) { isCommon = isKey(path) && isStrictComparable(value),
return object != null && object[key] === value && pathKey = (path + '');
(typeof value != 'undefined' || (key in toObject(object)));
}; path = toPath(path);
}
return function(object) { return function(object) {
return object != null && baseIsEqual(value, object[key], null, true); if (object == null) {
return false;
}
var key = pathKey;
object = toObject(object);
if ((isArr || !isCommon) && !(key in object)) {
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
if (object == null) {
return false;
}
key = last(path);
object = toObject(object);
}
return object[key] === value
? (value !== undefined || (key in object))
: baseIsEqual(value, object[key], null, true);
}; };
} }

View File

@@ -1,8 +1,14 @@
define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './isLength', '../lang/isObject', './isObjectLike', '../lang/isTypedArray'], function(arrayEach, baseForOwn, baseMergeDeep, isArray, isLength, isObject, isObjectLike, isTypedArray) { define(['./arrayEach', './baseMergeDeep', './getSymbols', '../lang/isArray', './isLength', '../lang/isObject', './isObjectLike', '../lang/isTypedArray', '../object/keys'], function(arrayEach, baseMergeDeep, getSymbols, isArray, isLength, isObject, isObjectLike, isTypedArray, keys) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */ /** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined; 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, * The base implementation of `_.merge` without support for argument juggling,
* multiple sources, and `this` binding `customizer` functions. * multiple sources, and `this` binding `customizer` functions.
@@ -13,29 +19,39 @@ define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './
* @param {Function} [customizer] The function to customize merging properties. * @param {Function} [customizer] The function to customize merging properties.
* @param {Array} [stackA=[]] Tracks traversed source objects. * @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates values with source counterparts. * @param {Array} [stackB=[]] Associates values with source counterparts.
* @returns {Object} Returns the destination object. * @returns {Object} Returns `object`.
*/ */
function baseMerge(object, source, customizer, stackA, stackB) { function baseMerge(object, source, customizer, stackA, stackB) {
if (!isObject(object)) { if (!isObject(object)) {
return object; return object;
} }
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source)); var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) { if (!isSrcArr) {
var props = keys(source);
push.apply(props, getSymbols(source));
}
arrayEach(props || source, function(srcValue, key) {
if (props) {
key = srcValue;
srcValue = source[key];
}
if (isObjectLike(srcValue)) { if (isObjectLike(srcValue)) {
stackA || (stackA = []); stackA || (stackA = []);
stackB || (stackB = []); stackB || (stackB = []);
return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB); baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
} }
var value = object[key], else {
result = customizer ? customizer(value, srcValue, key, object, source) : undefined, var value = object[key],
isCommon = typeof result == 'undefined'; result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = result === undefined;
if (isCommon) { if (isCommon) {
result = srcValue; result = srcValue;
} }
if ((isSrcArr || typeof result != 'undefined') && if ((isSrcArr || result !== undefined) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) { (isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result; object[key] = result;
}
} }
}); });
return object; return object;

View File

@@ -1,4 +1,4 @@
define(['./arrayCopy', '../lang/isArguments', '../lang/isArray', './isLength', '../lang/isPlainObject', '../lang/isTypedArray', '../lang/toPlainObject'], function(arrayCopy, isArguments, isArray, isLength, isPlainObject, isTypedArray, toPlainObject) { define(['./arrayCopy', './getLength', '../lang/isArguments', '../lang/isArray', './isLength', '../lang/isPlainObject', '../lang/isTypedArray', '../lang/toPlainObject'], function(arrayCopy, getLength, isArguments, isArray, isLength, isPlainObject, isTypedArray, toPlainObject) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */ /** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined; var undefined;
@@ -30,14 +30,14 @@ define(['./arrayCopy', '../lang/isArguments', '../lang/isArray', './isLength', '
} }
var value = object[key], var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined, result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined'; isCommon = result === undefined;
if (isCommon) { if (isCommon) {
result = srcValue; result = srcValue;
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) { if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value) result = isArray(value)
? value ? value
: ((value && value.length) ? arrayCopy(value) : []); : (getLength(value) ? arrayCopy(value) : []);
} }
else if (isPlainObject(srcValue) || isArguments(srcValue)) { else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value) result = isArguments(value)

View File

@@ -4,7 +4,7 @@ define([], function() {
var undefined; var undefined;
/** /**
* The base implementation of `_.property` which does not coerce `key` to a string. * The base implementation of `_.property` without support for deep paths.
* *
* @private * @private
* @param {string} key The key of the property to get. * @param {string} key The key of the property to get.

View File

@@ -0,0 +1,19 @@
define(['./baseGet', './toPath'], function(baseGet, toPath) {
/**
* A specialized version of `baseProperty` which supports deep paths.
*
* @private
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function.
*/
function basePropertyDeep(path) {
var pathKey = (path + '');
path = toPath(path);
return function(object) {
return baseGet(object, path, pathKey);
};
}
return basePropertyDeep;
});

31
internal/basePullAt.js Normal file
View File

@@ -0,0 +1,31 @@
define(['./isIndex'], function(isIndex) {
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/**
* The base implementation of `_.pullAt` without support for individual
* index arguments and capturing the removed elements.
*
* @private
* @param {Array} array The array to modify.
* @param {number[]} indexes The indexes of elements to remove.
* @returns {Array} Returns `array`.
*/
function basePullAt(array, indexes) {
var length = indexes.length;
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return array;
}
return basePullAt;
});

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `_.slice` without an iteratee call guard. * The base implementation of `_.slice` without an iteratee call guard.
* *
@@ -17,7 +20,7 @@ define([], function() {
if (start < 0) { if (start < 0) {
start = -start > length ? 0 : (length + start); start = -start > length ? 0 : (length + start);
} }
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) { if (end < 0) {
end += length; end += length;
} }

View File

@@ -1,30 +1,22 @@
define(['./baseEach', './baseSortBy', './compareMultiple', './isLength'], function(baseEach, baseSortBy, compareMultiple, isLength) { define(['./arrayMap', './baseCallback', './baseMap', './baseSortBy', './compareMultiple'], function(arrayMap, baseCallback, baseMap, baseSortBy, compareMultiple) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* The base implementation of `_.sortByOrder` without param guards. * The base implementation of `_.sortByOrder` without param guards.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} orders The sort orders of `props`. * @param {boolean[]} orders The sort orders of `iteratees`.
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
*/ */
function baseSortByOrder(collection, props, orders) { function baseSortByOrder(collection, iteratees, orders) {
var index = -1, var index = -1;
length = collection.length,
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) { iteratees = arrayMap(iteratees, function(iteratee) { return baseCallback(iteratee); });
var length = props.length,
criteria = Array(length);
while (length--) { var result = baseMap(collection, function(value) {
criteria[length] = value == null ? undefined : value[props[length]]; var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
} return { 'criteria': criteria, 'index': ++index, 'value': value };
result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
}); });
return baseSortBy(result, function(object, other) { return baseSortBy(result, function(object, other) {

View File

@@ -3,7 +3,7 @@ define([], function() {
/** /**
* The base implementation of `_.values` and `_.valuesIn` which creates an * The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names * array of `object` property values corresponding to the property names
* returned by `keysFunc`. * of `props`.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} object The object to query.

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** Native method references. */ /** Native method references. */
var floor = Math.floor; var floor = Math.floor;
@@ -29,7 +32,7 @@ define([], function() {
var low = 0, var low = 0,
high = array ? array.length : 0, high = array ? array.length : 0,
valIsNaN = value !== value, valIsNaN = value !== value,
valIsUndef = typeof value == 'undefined'; valIsUndef = value === undefined;
while (low < high) { while (low < high) {
var mid = floor((low + high) / 2), var mid = floor((low + high) / 2),
@@ -39,7 +42,7 @@ define([], function() {
if (valIsNaN) { if (valIsNaN) {
var setLow = isReflexive || retHighest; var setLow = isReflexive || retHighest;
} else if (valIsUndef) { } else if (valIsUndef) {
setLow = isReflexive && (retHighest || typeof computed != 'undefined'); setLow = isReflexive && (retHighest || computed !== undefined);
} else { } else {
setLow = retHighest ? (computed <= value) : (computed < value); setLow = retHighest ? (computed <= value) : (computed < value);
} }

View File

@@ -1,5 +1,8 @@
define(['../utility/identity'], function(identity) { define(['../utility/identity'], function(identity) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* A specialized version of `baseCallback` which only supports `this` binding * A specialized version of `baseCallback` which only supports `this` binding
* and specifying the number of arguments to provide to `func`. * and specifying the number of arguments to provide to `func`.
@@ -14,7 +17,7 @@ define(['../utility/identity'], function(identity) {
if (typeof func != 'function') { if (typeof func != 'function') {
return identity; return identity;
} }
if (typeof thisArg == 'undefined') { if (thisArg === undefined) {
return func; return func;
} }
switch (argCount) { switch (argCount) {

View File

@@ -4,7 +4,7 @@ define(['./baseCompareAscending'], function(baseCompareAscending) {
* Used by `_.sortByOrder` to compare multiple properties of each element * Used by `_.sortByOrder` to compare multiple properties of each element
* in a collection and stable sort them in the following order: * in a collection and stable sort them in the following order:
* *
* If orders is unspecified, sort in ascending order for all properties. * If `orders` is unspecified, sort in ascending order for all properties.
* Otherwise, for each property, sort in ascending order if its corresponding value in * Otherwise, for each property, sort in ascending order if its corresponding value in
* orders is true, and descending order if false. * orders is true, and descending order if false.
* *

View File

@@ -1,4 +1,4 @@
define(['./bindCallback', './isIterateeCall'], function(bindCallback, isIterateeCall) { define(['./bindCallback', './isIterateeCall', '../function/restParam'], function(bindCallback, isIterateeCall, restParam) {
/** /**
* Creates a function that assigns properties of source object(s) to a given * Creates a function that assigns properties of source object(s) to a given
@@ -11,38 +11,32 @@ define(['./bindCallback', './isIterateeCall'], function(bindCallback, isIteratee
* @returns {Function} Returns the new assigner function. * @returns {Function} Returns the new assigner function.
*/ */
function createAssigner(assigner) { function createAssigner(assigner) {
return function() { return restParam(function(object, sources) {
var args = arguments, var index = -1,
length = args.length, length = object == null ? 0 : sources.length,
object = args[0]; customizer = length > 2 && sources[length - 2],
guard = length > 2 && sources[2],
thisArg = length > 1 && sources[length - 1];
if (length < 2 || object == null) { if (typeof customizer == 'function') {
return object;
}
var customizer = args[length - 2],
thisArg = args[length - 1],
guard = args[3];
if (length > 3 && typeof customizer == 'function') {
customizer = bindCallback(customizer, thisArg, 5); customizer = bindCallback(customizer, thisArg, 5);
length -= 2; length -= 2;
} else { } else {
customizer = (length > 2 && typeof thisArg == 'function') ? thisArg : null; customizer = typeof thisArg == 'function' ? thisArg : null;
length -= (customizer ? 1 : 0); length -= (customizer ? 1 : 0);
} }
if (guard && isIterateeCall(args[1], args[2], guard)) { if (guard && isIterateeCall(sources[0], sources[1], guard)) {
customizer = length == 3 ? null : customizer; customizer = length < 3 ? null : customizer;
length = 2; length = 1;
} }
var index = 0;
while (++index < length) { while (++index < length) {
var source = args[index]; var source = sources[index];
if (source) { if (source) {
assigner(object, source, customizer); assigner(object, source, customizer);
} }
} }
return object; return object;
}; });
} }
return createAssigner; return createAssigner;

View File

@@ -1,4 +1,4 @@
define(['./isLength', './toObject'], function(isLength, toObject) { define(['./getLength', './isLength', './toObject'], function(getLength, isLength, toObject) {
/** /**
* Creates a `baseEach` or `baseEachRight` function. * Creates a `baseEach` or `baseEachRight` function.
@@ -10,7 +10,7 @@ define(['./isLength', './toObject'], function(isLength, toObject) {
*/ */
function createBaseEach(eachFunc, fromRight) { function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) { return function(collection, iteratee) {
var length = collection ? collection.length : 0; var length = collection ? getLength(collection) : 0;
if (!isLength(length)) { if (!isLength(length)) {
return eachFunc(collection, iteratee); return eachFunc(collection, iteratee);
} }

View File

@@ -1,5 +1,8 @@
define(['./bindCallback', '../lang/isArray'], function(bindCallback, isArray) { define(['./bindCallback', '../lang/isArray'], function(bindCallback, isArray) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Creates a function for `_.forEach` or `_.forEachRight`. * Creates a function for `_.forEach` or `_.forEachRight`.
* *
@@ -10,7 +13,7 @@ define(['./bindCallback', '../lang/isArray'], function(bindCallback, isArray) {
*/ */
function createForEach(arrayFunc, eachFunc) { function createForEach(arrayFunc, eachFunc) {
return function(collection, iteratee, thisArg) { return function(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection)) return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee) ? arrayFunc(collection, iteratee)
: eachFunc(collection, bindCallback(iteratee, thisArg, 3)); : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
}; };

View File

@@ -1,5 +1,8 @@
define(['./bindCallback', '../object/keysIn'], function(bindCallback, keysIn) { define(['./bindCallback', '../object/keysIn'], function(bindCallback, keysIn) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Creates a function for `_.forIn` or `_.forInRight`. * Creates a function for `_.forIn` or `_.forInRight`.
* *
@@ -9,7 +12,7 @@ define(['./bindCallback', '../object/keysIn'], function(bindCallback, keysIn) {
*/ */
function createForIn(objectFunc) { function createForIn(objectFunc) {
return function(object, iteratee, thisArg) { return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') { if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3); iteratee = bindCallback(iteratee, thisArg, 3);
} }
return objectFunc(object, iteratee, keysIn); return objectFunc(object, iteratee, keysIn);

View File

@@ -1,5 +1,8 @@
define(['./bindCallback'], function(bindCallback) { define(['./bindCallback'], function(bindCallback) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Creates a function for `_.forOwn` or `_.forOwnRight`. * Creates a function for `_.forOwn` or `_.forOwnRight`.
* *
@@ -9,7 +12,7 @@ define(['./bindCallback'], function(bindCallback) {
*/ */
function createForOwn(objectFunc) { function createForOwn(objectFunc) {
return function(object, iteratee, thisArg) { return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') { if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3); iteratee = bindCallback(iteratee, thisArg, 3);
} }
return objectFunc(object, iteratee); return objectFunc(object, iteratee);

View File

@@ -1,5 +1,8 @@
define(['./baseCallback', './baseReduce', '../lang/isArray'], function(baseCallback, baseReduce, isArray) { define(['./baseCallback', './baseReduce', '../lang/isArray'], function(baseCallback, baseReduce, isArray) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Creates a function for `_.reduce` or `_.reduceRight`. * Creates a function for `_.reduce` or `_.reduceRight`.
* *
@@ -11,7 +14,7 @@ define(['./baseCallback', './baseReduce', '../lang/isArray'], function(baseCallb
function createReduce(arrayFunc, eachFunc) { function createReduce(arrayFunc, eachFunc) {
return function(collection, iteratee, accumulator, thisArg) { return function(collection, iteratee, accumulator, thisArg) {
var initFromArray = arguments.length < 3; var initFromArray = arguments.length < 3;
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection)) return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee, accumulator, initFromArray) ? arrayFunc(collection, iteratee, accumulator, initFromArray)
: baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc); : baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
}; };

View File

@@ -37,7 +37,7 @@ define([], function() {
? customizer(othValue, arrValue, index) ? customizer(othValue, arrValue, index)
: customizer(arrValue, othValue, index); : customizer(arrValue, othValue, index);
} }
if (typeof result == 'undefined') { if (result === undefined) {
// Recursively compare arrays (susceptible to call stack limits). // Recursively compare arrays (susceptible to call stack limits).
if (isLoose) { if (isLoose) {
var othIndex = othLength; var othIndex = othLength;

View File

@@ -49,7 +49,7 @@ define(['../object/keys'], function(keys) {
? customizer(othValue, objValue, key) ? customizer(othValue, objValue, key)
: customizer(objValue, othValue, key); : customizer(objValue, othValue, key);
} }
if (typeof result == 'undefined') { if (result === undefined) {
// Recursively compare objects (susceptible to call stack limits). // Recursively compare objects (susceptible to call stack limits).
result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB); result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
} }

16
internal/getLength.js Normal file
View File

@@ -0,0 +1,16 @@
define(['./baseProperty'], function(baseProperty) {
/**
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
* in Safari on iOS 8.1 ARM64.
*
* @private
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
var getLength = baseProperty('length');
return getLength;
});

18
internal/getSymbols.js Normal file
View File

@@ -0,0 +1,18 @@
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;
});

View File

@@ -27,7 +27,6 @@ define(['./bufferClone'], function(bufferClone) {
* **Note:** This function only supports cloning values with tags of * **Note:** This function only supports cloning values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
* *
*
* @private * @private
* @param {Object} object The object to clone. * @param {Object} object The object to clone.
* @param {string} tag The `toStringTag` of the object to clone. * @param {string} tag The `toStringTag` of the object to clone.

26
internal/invokePath.js Normal file
View File

@@ -0,0 +1,26 @@
define(['./baseGet', './baseSlice', './isKey', '../array/last', './toPath'], function(baseGet, baseSlice, isKey, last, toPath) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* Invokes the method at `path` on `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the method to invoke.
* @param {Array} args The arguments to invoke the method with.
* @returns {*} Returns the result of the invoked method.
*/
function invokePath(object, path, args) {
if (object != null && !isKey(path, object)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
path = last(path);
}
var func = object == null ? object : object[path];
return func == null ? undefined : func.apply(object, args);
}
return invokePath;
});

View File

@@ -1,4 +1,4 @@
define(['./isIndex', './isLength', '../lang/isObject'], function(isIndex, isLength, isObject) { define(['./getLength', './isIndex', './isLength', '../lang/isObject'], function(getLength, isIndex, isLength, isObject) {
/** /**
* Checks if the provided arguments are from an iteratee call. * Checks if the provided arguments are from an iteratee call.
@@ -15,7 +15,7 @@ define(['./isIndex', './isLength', '../lang/isObject'], function(isIndex, isLeng
} }
var type = typeof index; var type = typeof index;
if (type == 'number') { if (type == 'number') {
var length = object.length, var length = getLength(object),
prereq = isLength(length) && isIndex(index, length); prereq = isLength(length) && isIndex(index, length);
} else { } else {
prereq = type == 'string' && index in object; prereq = type == 'string' && index in object;

28
internal/isKey.js Normal file
View File

@@ -0,0 +1,28 @@
define(['../lang/isArray', './toObject'], function(isArray, toObject) {
/** Used to match property names within property paths. */
var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/,
reIsPlainProp = /^\w*$/;
/**
* Checks if `value` is a property name and not a property path.
*
* @private
* @param {*} value The value to check.
* @param {Object} [object] The object to query keys on.
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
*/
function isKey(value, object) {
var type = typeof value;
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
return true;
}
if (isArray(value)) {
return false;
}
var result = !reIsDeepProp.test(value);
return result || (object != null && value in toObject(object));
}
return isKey;
});

View File

@@ -1,7 +1,7 @@
define([], function() { define([], function() {
/** /**
* Adds `value` to `key` of the cache. * Sets `value` to `key` of the cache.
* *
* @private * @private
* @name set * @name set

View File

@@ -2,7 +2,7 @@ define(['./toObject'], function(toObject) {
/** /**
* A specialized version of `_.pick` that picks `object` properties specified * A specialized version of `_.pick` that picks `object` properties specified
* by the `props` array. * by `props`.
* *
* @private * @private
* @param {Object} object The source object. * @param {Object} object The source object.

View File

@@ -13,7 +13,7 @@ define([], function() {
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
/** Detect free variable `global` from Node.js. */ /** Detect free variable `global` from Node.js. */
var freeGlobal = freeExports && freeModule && typeof global == 'object' && global; var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
/** Detect free variable `self`. */ /** Detect free variable `self`. */
var freeSelf = objectTypes[typeof self] && self && self.Object && self; var freeSelf = objectTypes[typeof self] && self && self.Object && self;

View File

@@ -1,5 +1,8 @@
define(['./baseForIn', './isObjectLike'], function(baseForIn, isObjectLike) { define(['./baseForIn', './isObjectLike'], function(baseForIn, isObjectLike) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var objectTag = '[object Object]'; var objectTag = '[object Object]';
@@ -43,7 +46,7 @@ define(['./baseForIn', './isObjectLike'], function(baseForIn, isObjectLike) {
baseForIn(value, function(subValue, key) { baseForIn(value, function(subValue, key) {
result = key; result = key;
}); });
return typeof result == 'undefined' || hasOwnProperty.call(value, result); return result === undefined || hasOwnProperty.call(value, result);
} }
return shimIsPlainObject; return shimIsPlainObject;

View File

@@ -11,7 +11,7 @@ define(['../lang/isArguments', '../lang/isArray', './isIndex', './isLength', '..
* own enumerable property names of `object`. * own enumerable property names of `object`.
* *
* @private * @private
* @param {Object} object The object to inspect. * @param {Object} object The object to query.
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array of property names.
*/ */
function shimKeys(object) { function shimKeys(object) {

View File

@@ -1,4 +1,4 @@
define(['./isLength', '../lang/isObject', '../object/values'], function(isLength, isObject, values) { define(['./getLength', './isLength', '../lang/isObject', '../object/values'], function(getLength, isLength, isObject, values) {
/** /**
* Converts `value` to an array-like object if it is not one. * Converts `value` to an array-like object if it is not one.
@@ -11,7 +11,7 @@ define(['./isLength', '../lang/isObject', '../object/values'], function(isLength
if (value == null) { if (value == null) {
return []; return [];
} }
if (!isLength(value.length)) { if (!isLength(getLength(value))) {
return values(value); return values(value);
} }
return isObject(value) ? value : Object(value); return isObject(value) ? value : Object(value);

28
internal/toPath.js Normal file
View File

@@ -0,0 +1,28 @@
define(['./baseToString', '../lang/isArray'], function(baseToString, isArray) {
/** Used to match property names within property paths. */
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
/** Used to match backslashes in property paths. */
var reEscapeChar = /\\(\\)?/g;
/**
* Converts `value` to property path array if it is not one.
*
* @private
* @param {*} value The value to process.
* @returns {Array} Returns the property path array.
*/
function toPath(value) {
if (isArray(value)) {
return value;
}
var result = [];
baseToString(value).replace(rePropName, function(match, number, quote, string) {
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
});
return result;
}
return toPath;
});

View File

@@ -1,4 +1,4 @@
define(['./isArguments', './isArray', './isFunction', '../internal/isLength', '../internal/isObjectLike', './isString', '../object/keys'], function(isArguments, isArray, isFunction, isLength, isObjectLike, isString, keys) { define(['../internal/getLength', './isArguments', './isArray', './isFunction', '../internal/isLength', '../internal/isObjectLike', './isString', '../object/keys'], function(getLength, isArguments, isArray, isFunction, isLength, isObjectLike, isString, keys) {
/** /**
* Checks if `value` is empty. A value is considered empty unless it is an * Checks if `value` is empty. A value is considered empty unless it is an
@@ -31,7 +31,7 @@ define(['./isArguments', './isArray', './isFunction', '../internal/isLength', '.
if (value == null) { if (value == null) {
return true; return true;
} }
var length = value.length; var length = getLength(value);
if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) || if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
(isObjectLike(value) && isFunction(value.splice)))) { (isObjectLike(value) && isFunction(value.splice)))) {
return !length; return !length;

View File

@@ -21,7 +21,7 @@ define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isSt
* @category Lang * @category Lang
* @param {*} value The value to compare. * @param {*} value The value to compare.
* @param {*} other The other value to compare. * @param {*} other The other value to compare.
* @param {Function} [customizer] The function to customize comparing values. * @param {Function} [customizer] The function to customize value comparisons.
* @param {*} [thisArg] The `this` binding of `customizer`. * @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example * @example
@@ -52,7 +52,7 @@ define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isSt
return value === other; return value === other;
} }
var result = customizer ? customizer(value, other) : undefined; var result = customizer ? customizer(value, other) : undefined;
return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result; return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
} }
return isEqual; return isEqual;

View File

@@ -1,5 +1,8 @@
define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isStrictComparable', '../object/keys', '../internal/toObject'], function(baseIsMatch, bindCallback, isStrictComparable, keys, toObject) { define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isStrictComparable', '../object/keys', '../internal/toObject'], function(baseIsMatch, bindCallback, isStrictComparable, keys, toObject) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Performs a deep comparison between `object` and `source` to determine if * Performs a deep comparison between `object` and `source` to determine if
* `object` contains equivalent property values. If `customizer` is provided * `object` contains equivalent property values. If `customizer` is provided
@@ -17,7 +20,7 @@ define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isSt
* @category Lang * @category Lang
* @param {Object} object The object to inspect. * @param {Object} object The object to inspect.
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @param {Function} [customizer] The function to customize comparing values. * @param {Function} [customizer] The function to customize value comparisons.
* @param {*} [thisArg] The `this` binding of `customizer`. * @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {boolean} Returns `true` if `object` is a match, else `false`. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
* @example * @example
@@ -50,12 +53,13 @@ define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isSt
return false; return false;
} }
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
object = toObject(object);
if (!customizer && length == 1) { if (!customizer && length == 1) {
var key = props[0], var key = props[0],
value = source[key]; value = source[key];
if (isStrictComparable(value)) { if (isStrictComparable(value)) {
return value === object[key] && (typeof value != 'undefined' || (key in toObject(object))); return value === object[key] && (value !== undefined || (key in object));
} }
} }
var values = Array(length), var values = Array(length),
@@ -65,7 +69,7 @@ define(['../internal/baseIsMatch', '../internal/bindCallback', '../internal/isSt
value = values[length] = source[props[length]]; value = values[length] = source[props[length]];
strictCompareFlags[length] = isStrictComparable(value); strictCompareFlags[length] = isStrictComparable(value);
} }
return baseIsMatch(toObject(object), props, values, strictCompareFlags, customizer); return baseIsMatch(object, props, values, strictCompareFlags, customizer);
} }
return isMatch; return isMatch;

View File

@@ -4,7 +4,7 @@ define(['../string/escapeRegExp', '../internal/isObjectLike'], function(escapeRe
var funcTag = '[object Function]'; var funcTag = '[object Function]';
/** Used to detect host constructors (Safari > 5). */ /** Used to detect host constructors (Safari > 5). */
var reHostCtor = /^\[object .+?Constructor\]$/; var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used for native method references. */ /** Used for native method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -19,7 +19,7 @@ define(['../string/escapeRegExp', '../internal/isObjectLike'], function(escapeRe
var objToString = objectProto.toString; var objToString = objectProto.toString;
/** Used to detect if a method is native. */ /** Used to detect if a method is native. */
var reNative = RegExp('^' + var reIsNative = RegExp('^' +
escapeRegExp(objToString) escapeRegExp(objToString)
.replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
); );
@@ -45,9 +45,9 @@ define(['../string/escapeRegExp', '../internal/isObjectLike'], function(escapeRe
return false; return false;
} }
if (objToString.call(value) == funcTag) { if (objToString.call(value) == funcTag) {
return reNative.test(fnToString.call(value)); return reIsNative.test(fnToString.call(value));
} }
return isObjectLike(value) && reHostCtor.test(value); return isObjectLike(value) && reIsHostCtor.test(value);
} }
return isNative; return isNative;

View File

@@ -1,5 +1,8 @@
define([], function() { define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** /**
* Checks if `value` is `undefined`. * Checks if `value` is `undefined`.
* *
@@ -17,7 +20,7 @@ define([], function() {
* // => false * // => false
*/ */
function isUndefined(value) { function isUndefined(value) {
return typeof value == 'undefined'; return value === undefined;
} }
return isUndefined; return isUndefined;

View File

@@ -1,4 +1,4 @@
define(['../internal/arrayCopy', '../internal/isLength', '../object/values'], function(arrayCopy, isLength, values) { define(['../internal/arrayCopy', '../internal/getLength', '../internal/isLength', '../object/values'], function(arrayCopy, getLength, isLength, values) {
/** /**
* Converts `value` to an array. * Converts `value` to an array.
@@ -16,7 +16,7 @@ define(['../internal/arrayCopy', '../internal/isLength', '../object/values'], fu
* // => [2, 3] * // => [2, 3]
*/ */
function toArray(value) { function toArray(value) {
var length = value ? value.length : 0; var length = value ? getLength(value) : 0;
if (!isLength(length)) { if (!isLength(length)) {
return values(value); return values(value);
} }

1127
main.js

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,7 @@ define([], function() {
* // => 10 * // => 10
*/ */
function add(augend, addend) { function add(augend, addend) {
return augend + addend; return (+augend || 0) + (+addend || 0);
} }
return add; return add;

View File

@@ -1,5 +1,9 @@
define([], function() { define([], function() {
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
nativeMin = Math.min;
/** /**
* Checks if `n` is between `start` and up to but not including, `end`. If * Checks if `n` is between `start` and up to but not including, `end`. If
* `end` is not specified it is set to `start` with `start` then set to `0`. * `end` is not specified it is set to `start` with `start` then set to `0`.
@@ -39,7 +43,7 @@ define([], function() {
} else { } else {
end = +end || 0; end = +end || 0;
} }
return value >= start && value < end; return value >= nativeMin(start, end) && value < nativeMax(start, end);
} }
return inRange; return inRange;

View File

@@ -1,4 +1,4 @@
define(['./object/assign', './object/create', './object/defaults', './object/extend', './object/findKey', './object/findLastKey', './object/forIn', './object/forInRight', './object/forOwn', './object/forOwnRight', './object/functions', './object/has', './object/invert', './object/keys', './object/keysIn', './object/mapValues', './object/merge', './object/methods', './object/omit', './object/pairs', './object/pick', './object/result', './object/transform', './object/values', './object/valuesIn'], function(assign, create, defaults, extend, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, has, invert, keys, keysIn, mapValues, merge, methods, omit, pairs, pick, result, transform, values, valuesIn) { define(['./object/assign', './object/create', './object/defaults', './object/extend', './object/findKey', './object/findLastKey', './object/forIn', './object/forInRight', './object/forOwn', './object/forOwnRight', './object/functions', './object/get', './object/has', './object/invert', './object/keys', './object/keysIn', './object/mapValues', './object/merge', './object/methods', './object/omit', './object/pairs', './object/pick', './object/result', './object/set', './object/transform', './object/values', './object/valuesIn'], function(assign, create, defaults, extend, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, get, has, invert, keys, keysIn, mapValues, merge, methods, omit, pairs, pick, result, set, transform, values, valuesIn) {
return { return {
'assign': assign, 'assign': assign,
'create': create, 'create': create,
@@ -11,6 +11,7 @@ define(['./object/assign', './object/create', './object/defaults', './object/ext
'forOwn': forOwn, 'forOwn': forOwn,
'forOwnRight': forOwnRight, 'forOwnRight': forOwnRight,
'functions': functions, 'functions': functions,
'get': get,
'has': has, 'has': has,
'invert': invert, 'invert': invert,
'keys': keys, 'keys': keys,
@@ -22,6 +23,7 @@ define(['./object/assign', './object/create', './object/defaults', './object/ext
'pairs': pairs, 'pairs': pairs,
'pick': pick, 'pick': pick,
'result': result, 'result': result,
'set': set,
'transform': transform, 'transform': transform,
'values': values, 'values': values,
'valuesIn': valuesIn 'valuesIn': valuesIn

View File

@@ -1,4 +1,4 @@
define(['../internal/baseAssign', '../internal/createAssigner'], function(baseAssign, createAssigner) { define(['../internal/assignWith', '../internal/baseAssign', '../internal/createAssigner'], function(assignWith, baseAssign, createAssigner) {
/** /**
* Assigns own enumerable properties of source object(s) to the destination * Assigns own enumerable properties of source object(s) to the destination
@@ -7,13 +7,17 @@ define(['../internal/baseAssign', '../internal/createAssigner'], function(baseAs
* The `customizer` is bound to `thisArg` and invoked with five arguments: * The `customizer` is bound to `thisArg` and invoked with five arguments:
* (objectValue, sourceValue, key, object, source). * (objectValue, sourceValue, key, object, source).
* *
* **Note:** This method mutates `object` and is based on
* [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign).
*
*
* @static * @static
* @memberOf _ * @memberOf _
* @alias extend * @alias extend
* @category Object * @category Object
* @param {Object} object The destination object. * @param {Object} object The destination object.
* @param {...Object} [sources] The source objects. * @param {...Object} [sources] The source objects.
* @param {Function} [customizer] The function to customize assigning values. * @param {Function} [customizer] The function to customize assigned values.
* @param {*} [thisArg] The `this` binding of `customizer`. * @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
* @example * @example
@@ -23,13 +27,17 @@ define(['../internal/baseAssign', '../internal/createAssigner'], function(baseAs
* *
* // using a customizer callback * // using a customizer callback
* var defaults = _.partialRight(_.assign, function(value, other) { * var defaults = _.partialRight(_.assign, function(value, other) {
* return typeof value == 'undefined' ? other : value; * return _.isUndefined(value) ? other : value;
* }); * });
* *
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
* // => { 'user': 'barney', 'age': 36 } * // => { 'user': 'barney', 'age': 36 }
*/ */
var assign = createAssigner(baseAssign); var assign = createAssigner(function(object, source, customizer) {
return customizer
? assignWith(object, source, customizer)
: baseAssign(object, source);
});
return assign; return assign;
}); });

View File

@@ -1,4 +1,4 @@
define(['../internal/baseCopy', '../internal/baseCreate', '../internal/isIterateeCall', './keys'], function(baseCopy, baseCreate, isIterateeCall, keys) { define(['../internal/baseAssign', '../internal/baseCreate', '../internal/isIterateeCall'], function(baseAssign, baseCreate, isIterateeCall) {
/** /**
* Creates an object that inherits from the given `prototype` object. If a * Creates an object that inherits from the given `prototype` object. If a
@@ -39,7 +39,7 @@ define(['../internal/baseCopy', '../internal/baseCreate', '../internal/isIterate
if (guard && isIterateeCall(prototype, properties, guard)) { if (guard && isIterateeCall(prototype, properties, guard)) {
properties = null; properties = null;
} }
return properties ? baseCopy(properties, result, keys(properties)) : result; return properties ? baseAssign(result, properties) : result;
} }
return create; return create;

View File

@@ -8,6 +8,8 @@ define(['./assign', '../internal/assignDefaults', '../function/restParam'], func
* object for all destination properties that resolve to `undefined`. Once a * object for all destination properties that resolve to `undefined`. Once a
* property is set, additional values of the same property are ignored. * property is set, additional values of the same property are ignored.
* *
* **Note:** This method mutates `object`.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Object * @category Object

View File

@@ -3,7 +3,7 @@ define(['../internal/baseFor', '../internal/createForIn'], function(baseFor, cre
/** /**
* Iterates over own and inherited enumerable properties of an object invoking * Iterates over own and inherited enumerable properties of an object invoking
* `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
* with three arguments: (value, key, object). Iterator functions may exit * with three arguments: (value, key, object). Iteratee functions may exit
* iteration early by explicitly returning `false`. * iteration early by explicitly returning `false`.
* *
* @static * @static

View File

@@ -3,7 +3,7 @@ define(['../internal/baseForOwn', '../internal/createForOwn'], function(baseForO
/** /**
* Iterates over own enumerable properties of an object invoking `iteratee` * Iterates over own enumerable properties of an object invoking `iteratee`
* for each property. The `iteratee` is bound to `thisArg` and invoked with * for each property. The `iteratee` is bound to `thisArg` and invoked with
* three arguments: (value, key, object). Iterator functions may exit iteration * three arguments: (value, key, object). Iteratee functions may exit iteration
* early by explicitly returning `false`. * early by explicitly returning `false`.
* *
* @static * @static

36
object/get.js Normal file
View File

@@ -0,0 +1,36 @@
define(['../internal/baseGet', '../internal/toPath'], function(baseGet, toPath) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* Gets the property value of `path` on `object`. If the resolved value is
* `undefined` the `defaultValue` is used in its place.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
function get(object, path, defaultValue) {
var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
return result === undefined ? defaultValue : result;
}
return get;
});

View File

@@ -1,4 +1,4 @@
define([], function() { define(['../internal/baseGet', '../internal/baseSlice', '../internal/isKey', '../array/last', '../internal/toPath'], function(baseGet, baseSlice, isKey, last, toPath) {
/** Used for native method references. */ /** Used for native method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -7,24 +7,39 @@ define([], function() {
var hasOwnProperty = objectProto.hasOwnProperty; var hasOwnProperty = objectProto.hasOwnProperty;
/** /**
* Checks if `key` exists as a direct property of `object` instead of an * Checks if `path` is a direct property.
* inherited property.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Object * @category Object
* @param {Object} object The object to inspect. * @param {Object} object The object to query.
* @param {string} key The key to check. * @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`. * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
* @example * @example
* *
* var object = { 'a': 1, 'b': 2, 'c': 3 }; * var object = { 'a': { 'b': { 'c': 3 } } };
* *
* _.has(object, 'b'); * _.has(object, 'a');
* // => true
*
* _.has(object, 'a.b.c');
* // => true
*
* _.has(object, ['a', 'b', 'c']);
* // => true * // => true
*/ */
function has(object, key) { function has(object, path) {
return object ? hasOwnProperty.call(object, key) : false; if (object == null) {
return false;
}
var result = hasOwnProperty.call(object, path);
if (!result && !isKey(path)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
path = last(path);
result = object != null && hasOwnProperty.call(object, path);
}
return result;
} }
return has; return has;

View File

@@ -13,7 +13,7 @@ define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../inte
* @static * @static
* @memberOf _ * @memberOf _
* @category Object * @category Object
* @param {Object} object The object to inspect. * @param {Object} object The object to query.
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array of property names.
* @example * @example
* *
@@ -36,7 +36,7 @@ define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../inte
length = object.length; length = object.length;
} }
if ((typeof Ctor == 'function' && Ctor.prototype === object) || if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
(typeof object != 'function' && (length && isLength(length)))) { (typeof object != 'function' && isLength(length))) {
return shimKeys(object); return shimKeys(object);
} }
return isObject(object) ? nativeKeys(object) : []; return isObject(object) ? nativeKeys(object) : [];

View File

@@ -14,7 +14,7 @@ define(['../lang/isArguments', '../lang/isArray', '../internal/isIndex', '../int
* @static * @static
* @memberOf _ * @memberOf _
* @category Object * @category Object
* @param {Object} object The object to inspect. * @param {Object} object The object to query.
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array of property names.
* @example * @example
* *

View File

@@ -14,7 +14,7 @@ define(['../internal/baseMerge', '../internal/createAssigner'], function(baseMer
* @category Object * @category Object
* @param {Object} object The destination object. * @param {Object} object The destination object.
* @param {...Object} [sources] The source objects. * @param {...Object} [sources] The source objects.
* @param {Function} [customizer] The function to customize merging properties. * @param {Function} [customizer] The function to customize assigned values.
* @param {*} [thisArg] The `this` binding of `customizer`. * @param {*} [thisArg] The `this` binding of `customizer`.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
* @example * @example

Some files were not shown because too many files have changed in this diff Show More