Compare commits

...

1 Commits

Author SHA1 Message Date
jdalton
5eb8db31d7 Bump to v3.7.0. 2015-04-15 20:56:31 -07:00
121 changed files with 897 additions and 413 deletions

View File

@@ -1,4 +1,4 @@
# lodash-es v3.6.0
# lodash-es v3.7.0
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [ES](https://people.mozilla.org/~jorendorff/es6-draft.html) modules.
@@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli):
$ lodash modularize modern exports=es -o ./
```
See the [package source](https://github.com/lodash/lodash/tree/3.6.0-es) for more details.
See the [package source](https://github.com/lodash/lodash/tree/3.7.0-es) for more details.

View File

@@ -27,7 +27,8 @@ function intersection() {
argsLength = arguments.length,
caches = [],
indexOf = baseIndexOf,
isCommon = true;
isCommon = true,
result = [];
while (++argsIndex < argsLength) {
var value = arguments[argsIndex];
@@ -37,10 +38,12 @@ function intersection() {
}
}
argsLength = args.length;
if (argsLength < 2) {
return result;
}
var array = args[0],
index = -1,
length = array ? array.length : 0,
result = [],
seen = caches[0];
outer:

View File

@@ -1,15 +1,9 @@
import baseAt from '../internal/baseAt';
import baseCompareAscending from '../internal/baseCompareAscending';
import baseFlatten from '../internal/baseFlatten';
import isIndex from '../internal/isIndex';
import basePullAt from '../internal/basePullAt';
import restParam from '../function/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
* an array of the removed elements. Indexes may be specified as an array of
@@ -39,17 +33,8 @@ var pullAt = restParam(function(array, indexes) {
array || (array = []);
indexes = baseFlatten(indexes);
var length = indexes.length,
result = baseAt(array, indexes);
indexes.sort(baseCompareAscending);
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
var result = baseAt(array, indexes);
basePullAt(array, indexes.sort(baseCompareAscending));
return result;
});

View File

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

View File

@@ -4,7 +4,7 @@ import isIterateeCall from '../internal/isIterateeCall';
/**
* 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.
*
* @static

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
import baseAt from '../internal/baseAt';
import baseFlatten from '../internal/baseFlatten';
import getLength from '../internal/getLength';
import isLength from '../internal/isLength';
import restParam from '../function/restParam';
import toIterable from '../internal/toIterable';
@@ -25,7 +26,7 @@ import toIterable from '../internal/toIterable';
* // => ['barney', 'pebbles']
*/
var at = restParam(function(collection, props) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
if (isLength(length)) {
collection = toIterable(collection);
}

View File

@@ -57,7 +57,7 @@ function every(collection, predicate, thisArg) {
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3);
}
return func(collection, predicate);

View File

@@ -5,10 +5,10 @@ import createForEach from '../internal/createForEach';
/**
* Iterates over elements of `collection` invoking `iteratee` for each element.
* 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`.
*
* **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`
* may be used for object iteration.
*

View File

@@ -1,4 +1,5 @@
import baseIndexOf from '../internal/baseIndexOf';
import getLength from '../internal/getLength';
import isArray from '../lang/isArray';
import isIterateeCall from '../internal/isIterateeCall';
import isLength from '../internal/isLength';
@@ -41,7 +42,7 @@ var nativeMax = Math.max;
* // => true
*/
function includes(collection, target, fromIndex, guard) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
collection = values(collection);
length = collection.length;

View File

@@ -1,18 +1,21 @@
import baseEach from '../internal/baseEach';
import getLength from '../internal/getLength';
import invokePath from '../internal/invokePath';
import isKey from '../internal/isKey';
import isLength from '../internal/isLength';
import restParam from '../function/restParam';
/**
* Invokes the method named by `methodName` on each element in `collection`,
* returning an array of the results of each invoked method. Any additional
* arguments are provided to each invoked method. If `methodName` is a function
* it is invoked for, and `this` bound to, each element in `collection`.
* Invokes the method at `path` on each element in `collection`, returning
* an array of the results of each invoked method. Any additional arguments
* are provided to each invoked method. If `methodName` is a function it is
* invoked for, and `this` bound to, each element in `collection`.
*
* @static
* @memberOf _
* @category Collection
* @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.
* @param {...*} [args] The arguments to invoke the method with.
* @returns {Array} Returns the array of results.
@@ -24,15 +27,16 @@ import restParam from '../function/restParam';
* _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']]
*/
var invoke = restParam(function(collection, methodName, args) {
var invoke = restParam(function(collection, path, args) {
var index = -1,
isFunc = typeof methodName == 'function',
length = collection ? collection.length : 0,
isFunc = typeof path == 'function',
isProp = isKey(path),
length = getLength(collection),
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) {
var func = isFunc ? methodName : (value != null && value[methodName]);
result[++index] = func ? func.apply(value, args) : undefined;
var func = isFunc ? path : (isProp && value != null && value[path]);
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
});
return result;
});

View File

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

View File

@@ -1,14 +1,14 @@
import baseProperty from '../internal/baseProperty';
import map from './map';
import property from '../utility/property';
/**
* Gets the value of `key` from all elements in `collection`.
* Gets the property value of `path` from all elements in `collection`.
*
* @static
* @memberOf _
* @category Collection
* @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.
* @example
*
@@ -24,8 +24,8 @@ import map from './map';
* _.pluck(userIndex, 'age');
* // => [36, 40] (iteration order is not guaranteed)
*/
function pluck(collection, key) {
return map(collection, baseProperty(key));
function pluck(collection, path) {
return map(collection, property(path));
}
export default pluck;

View File

@@ -27,8 +27,8 @@ import createReduce from '../internal/createReduce';
* @returns {*} Returns the accumulated value.
* @example
*
* _.reduce([1, 2], function(sum, n) {
* return sum + n;
* _.reduce([1, 2], function(total, n) {
* return total + n;
* });
* // => 3
*

View File

@@ -1,3 +1,4 @@
import getLength from '../internal/getLength';
import isLength from '../internal/isLength';
import keys from '../object/keys';
@@ -22,7 +23,7 @@ import keys from '../object/keys';
* // => 7
*/
function size(collection) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
return isLength(length) ? length : keys(collection).length;
}

View File

@@ -58,7 +58,7 @@ function some(collection, predicate, thisArg) {
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3);
}
return func(collection, predicate);

View File

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

View File

@@ -1,48 +1,52 @@
import baseFlatten from '../internal/baseFlatten';
import baseSortByOrder from '../internal/baseSortByOrder';
import isIterateeCall from '../internal/isIterateeCall';
import restParam from '../function/restParam';
/**
* This method is like `_.sortBy` except that it sorts by property names
* instead of an iteratee function.
* This method is like `_.sortBy` except that it can sort by multiple iteratees
* 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
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {...(string|string[])} props The property names to sort by,
* specified as individual property names or arrays of property names.
* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
* The iteratees to sort by, specified as individual values or arrays of values.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 26 },
* { 'user': 'fred', 'age': 30 }
* { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 34 }
* ];
*
* _.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 args = arguments,
collection = args[0],
guard = args[3],
index = 0,
length = args.length - 1;
var sortByAll = restParam(function(collection, iteratees) {
if (collection == null) {
return [];
}
var props = Array(length);
while (index < length) {
props[index] = args[++index];
var guard = iteratees[2];
if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
iteratees.length = 1;
}
if (guard && isIterateeCall(args[1], args[2], guard)) {
props = args[1];
}
return baseSortByOrder(collection, baseFlatten(props), []);
}
return baseSortByOrder(collection, baseFlatten(iteratees), []);
});
export default sortByAll;

View File

@@ -4,45 +4,52 @@ import isIterateeCall from '../internal/isIterateeCall';
/**
* 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`
* will sort the corresponding property name in ascending order while a
* falsey value will sort it in descending order.
* sort orders of the iteratees to sort by. A truthy value in `orders` will
* sort the corresponding property name in ascending order while a falsey
* 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
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by.
* @param {boolean[]} orders The sort orders of `props`.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} orders The sort orders of `iteratees`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 26 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 30 }
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 34 },
* { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 36 }
* ];
*
* // sort by `user` in ascending order and by `age` in descending order
* _.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) {
return [];
}
if (guard && isIterateeCall(props, orders, guard)) {
if (guard && isIterateeCall(iteratees, orders, guard)) {
orders = null;
}
if (!isArray(props)) {
props = props == null ? [] : [props];
if (!isArray(iteratees)) {
iteratees = iteratees == null ? [] : [iteratees];
}
if (!isArray(orders)) {
orders = orders == null ? [] : [orders];
}
return baseSortByOrder(collection, props, orders);
return baseSortByOrder(collection, iteratees, orders);
}
export default sortByOrder;

View File

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

View File

@@ -14,7 +14,7 @@ var BIND_FLAG = 1,
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
* 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.
*
* @static

View File

@@ -12,7 +12,7 @@ var BIND_FLAG = 1;
* of method names. If no method names are provided all enumerable function
* 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
* @memberOf _

View File

@@ -13,7 +13,7 @@ var BIND_FLAG = 1,
*
* This method differs from `_.bind` by allowing bound functions to reference
* 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.
*
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic

View File

@@ -13,7 +13,7 @@ var CURRY_FLAG = 8;
* The `_.curry.placeholder` value, which defaults to `_` in monolithic 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
* @memberOf _

View File

@@ -10,7 +10,7 @@ var CURRY_RIGHT_FLAG = 16;
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
* 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
* @memberOf _

View File

@@ -18,7 +18,7 @@ import before from './before';
* // `initialize` invokes `createApplication` once
*/
function once(func) {
return before(func, 2);
return before(2, func);
}
export default once;

View File

@@ -11,7 +11,7 @@ var PARTIAL_FLAG = 32;
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
* 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.
*
* @static

View File

@@ -10,7 +10,7 @@ var PARTIAL_RIGHT_FLAG = 64;
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
* 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.
*
* @static

View File

@@ -30,7 +30,7 @@ function restParam(func, start) {
if (typeof func != 'function') {
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() {
var args = arguments,
index = -1,

View File

@@ -7,7 +7,7 @@
* @returns {*} Returns the value to assign to the destination object.
*/
function assignDefaults(objectValue, sourceValue) {
return typeof objectValue == 'undefined' ? sourceValue : objectValue;
return objectValue === undefined ? sourceValue : objectValue;
}
export default assignDefaults;

View File

@@ -7,7 +7,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
/**
* 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`.
*
* @private
@@ -18,7 +18,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {*} Returns the value to assign to the destination object.
*/
function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
return (objectValue === undefined || !hasOwnProperty.call(object, key))
? sourceValue
: objectValue;
}

41
internal/assignWith.js Normal file
View File

@@ -0,0 +1,41 @@
import getSymbols from './getSymbols';
import keys from '../object/keys';
/** 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;
}
export default assignWith;

View File

@@ -1,35 +1,40 @@
import baseCopy from './baseCopy';
import getSymbols from './getSymbols';
import isNative from '../lang/isNative';
import keys from '../object/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,
* multiple sources, and `this` binding `customizer` functions.
* multiple sources, and `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} [customizer] The function to customize assigning values.
* @returns {Object} Returns the destination object.
* @returns {Object} Returns `object`.
*/
function baseAssign(object, source, customizer) {
var props = keys(source);
if (!customizer) {
return baseCopy(source, object, props);
}
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;
}
var baseAssign = nativeAssign || function(object, source) {
return source == null
? object
: baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
};
export default baseAssign;

View File

@@ -2,12 +2,12 @@ import isIndex from './isIndex';
import isLength from './isLength';
/**
* The base implementation of `_.at` without support for strings and individual
* key arguments.
* The base implementation of `_.at` without support for string collections
* and individual key arguments.
*
* @private
* @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.
*/
function baseAt(collection, props) {
@@ -20,7 +20,6 @@ function baseAt(collection, props) {
while(++index < propsLength) {
var key = props[index];
if (isArr) {
key = parseFloat(key);
result[index] = isIndex(key, length) ? collection[key] : undefined;
} else {
result[index] = collection[key];

View File

@@ -1,8 +1,8 @@
import baseMatches from './baseMatches';
import baseMatchesProperty from './baseMatchesProperty';
import baseProperty from './baseProperty';
import bindCallback from './bindCallback';
import identity from '../utility/identity';
import property from '../utility/property';
/**
* The base implementation of `_.callback` which supports specifying the
@@ -17,7 +17,7 @@ import identity from '../utility/identity';
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
return typeof thisArg == 'undefined'
return thisArg === undefined
? func
: bindCallback(func, thisArg, argCount);
}
@@ -27,9 +27,9 @@ function baseCallback(func, thisArg, argCount) {
if (type == 'object') {
return baseMatches(func);
}
return typeof thisArg == 'undefined'
? baseProperty(func + '')
: baseMatchesProperty(func + '', thisArg);
return thisArg === undefined
? property(func)
: baseMatchesProperty(func, thisArg);
}
export default baseCallback;

View File

@@ -1,13 +1,12 @@
import arrayCopy from './arrayCopy';
import arrayEach from './arrayEach';
import baseCopy from './baseCopy';
import baseAssign from './baseAssign';
import baseForOwn from './baseForOwn';
import initCloneArray from './initCloneArray';
import initCloneByTag from './initCloneByTag';
import initCloneObject from './initCloneObject';
import isArray from '../lang/isArray';
import isObject from '../lang/isObject';
import keys from '../object/keys';
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
@@ -78,7 +77,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
if (customizer) {
result = object ? customizer(value, key, object) : customizer(value);
}
if (typeof result != 'undefined') {
if (result !== undefined) {
return result;
}
if (!isObject(value)) {
@@ -97,7 +96,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
result = initCloneObject(isFunc ? {} : value);
if (!isDeep) {
return baseCopy(value, result, keys(value));
return baseAssign(result, value);
}
} else {
return cloneableTags[tag]

View File

@@ -12,10 +12,10 @@ function baseCompareAscending(value, other) {
var valIsReflexive = value === value,
othIsReflexive = other === other;
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) {
return 1;
}
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) {
return -1;
}
}

View File

@@ -1,17 +1,15 @@
/**
* Copies the properties of `source` to `object`.
* Copies properties of `source` to `object`.
*
* @private
* @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 {Object} [object={}] The object to copy properties to.
* @returns {Object} Returns `object`.
*/
function baseCopy(source, object, props) {
if (!props) {
props = object;
object = {};
}
function baseCopy(source, props, object) {
object || (object = {});
var index = -1,
length = props.length;

View File

@@ -15,7 +15,7 @@ function baseFill(array, value, start, end) {
if (start < 0) {
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) {
end += length;
}

View File

@@ -3,7 +3,7 @@ import createBaseFor from './createBaseFor';
/**
* The base implementation of `baseForIn` and `baseForOwn` which iterates
* 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`.
*
* @private

29
internal/baseGet.js Normal file
View File

@@ -0,0 +1,29 @@
import toObject from './toObject';
/**
* 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;
}
export default baseGet;

View File

@@ -7,7 +7,6 @@ import isTypedArray from '../lang/isTypedArray';
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
funcTag = '[object Function]',
objectTag = '[object Object]';
/** Used for native method references. */
@@ -59,27 +58,23 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA,
othIsArr = isTypedArray(other);
}
}
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)),
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)),
var objIsObj = objTag == objectTag,
othIsObj = othTag == objectTag,
isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag);
}
if (isLoose) {
if (!isSameTag && !(objIsObj && othIsObj)) {
return false;
}
} else {
if (!isLoose) {
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (valWrapped || othWrapped) {
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.
// For more information on detecting circular references see https://es5.github.io/#JO.

View File

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

View File

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

View File

@@ -24,8 +24,10 @@ function baseMatches(source) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
if (object == null) {
return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
};
}
}

View File

@@ -1,25 +1,45 @@
import baseGet from './baseGet';
import baseIsEqual from './baseIsEqual';
import baseSlice from './baseSlice';
import isArray from '../lang/isArray';
import isKey from './isKey';
import isStrictComparable from './isStrictComparable';
import last from '../array/last';
import toObject from './toObject';
import toPath from './toPath';
/**
* The base implementation of `_.matchesProperty` which does not coerce `key`
* to a string.
* The base implementation of `_.matchesProperty` which does not which does
* not clone `value`.
*
* @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.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
function baseMatchesProperty(path, value) {
var isArr = isArray(path),
isCommon = isKey(path) && isStrictComparable(value),
pathKey = (path + '');
path = toPath(path);
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,11 +1,18 @@
import arrayEach from './arrayEach';
import baseForOwn from './baseForOwn';
import baseMergeDeep from './baseMergeDeep';
import getSymbols from './getSymbols';
import isArray from '../lang/isArray';
import isLength from './isLength';
import isObject from '../lang/isObject';
import isObjectLike from './isObjectLike';
import isTypedArray from '../lang/isTypedArray';
import keys from '../object/keys';
/** 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,
@@ -17,29 +24,39 @@ import isTypedArray from '../lang/isTypedArray';
* @param {Function} [customizer] The function to customize merging properties.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @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) {
if (!isObject(object)) {
return object;
}
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)) {
stackA || (stackA = []);
stackB || (stackB = []);
return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
}
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined';
else {
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = result === undefined;
if (isCommon) {
result = srcValue;
}
if ((isSrcArr || typeof result != 'undefined') &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
if (isCommon) {
result = srcValue;
}
if ((isSrcArr || result !== undefined) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
}
});
return object;

View File

@@ -1,4 +1,5 @@
import arrayCopy from './arrayCopy';
import getLength from './getLength';
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isLength from './isLength';
@@ -33,14 +34,14 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
}
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined';
isCommon = result === undefined;
if (isCommon) {
result = srcValue;
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value)
? value
: ((value && value.length) ? arrayCopy(value) : []);
: (getLength(value) ? arrayCopy(value) : []);
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value)

View File

@@ -1,5 +1,5 @@
/**
* The base implementation of `_.property` which does not coerce `key` to a string.
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.

View File

@@ -0,0 +1,19 @@
import baseGet from './baseGet';
import toPath from './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);
};
}
export default basePropertyDeep;

30
internal/basePullAt.js Normal file
View File

@@ -0,0 +1,30 @@
import isIndex from './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;
}
export default basePullAt;

View File

@@ -15,7 +15,7 @@ function baseSlice(array, start, end) {
if (start < 0) {
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) {
end += length;
}

View File

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

View File

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

View File

@@ -27,7 +27,7 @@ function binaryIndexBy(array, value, iteratee, retHighest) {
var low = 0,
high = array ? array.length : 0,
valIsNaN = value !== value,
valIsUndef = typeof value == 'undefined';
valIsUndef = value === undefined;
while (low < high) {
var mid = floor((low + high) / 2),
@@ -37,7 +37,7 @@ function binaryIndexBy(array, value, iteratee, retHighest) {
if (valIsNaN) {
var setLow = isReflexive || retHighest;
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || typeof computed != 'undefined');
setLow = isReflexive && (retHighest || computed !== undefined);
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}

View File

@@ -14,7 +14,7 @@ function bindCallback(func, thisArg, argCount) {
if (typeof func != 'function') {
return identity;
}
if (typeof thisArg == 'undefined') {
if (thisArg === undefined) {
return func;
}
switch (argCount) {

View File

@@ -4,7 +4,7 @@ import baseCompareAscending from './baseCompareAscending';
* Used by `_.sortByOrder` to compare multiple properties of each element
* 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
* orders is true, and descending order if false.
*

View File

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

View File

@@ -1,3 +1,4 @@
import getLength from './getLength';
import isLength from './isLength';
import toObject from './toObject';
@@ -11,7 +12,7 @@ import toObject from './toObject';
*/
function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
return eachFunc(collection, iteratee);
}

View File

@@ -11,7 +11,7 @@ import isArray from '../lang/isArray';
*/
function createForEach(arrayFunc, eachFunc) {
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)
: eachFunc(collection, bindCallback(iteratee, thisArg, 3));
};

View File

@@ -10,7 +10,7 @@ import keysIn from '../object/keysIn';
*/
function createForIn(objectFunc) {
return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3);
}
return objectFunc(object, iteratee, keysIn);

View File

@@ -9,7 +9,7 @@ import bindCallback from './bindCallback';
*/
function createForOwn(objectFunc) {
return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3);
}
return objectFunc(object, iteratee);

View File

@@ -13,7 +13,7 @@ import isArray from '../lang/isArray';
function createReduce(arrayFunc, eachFunc) {
return function(collection, iteratee, accumulator, thisArg) {
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)
: baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
};

View File

@@ -32,7 +32,7 @@ function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stack
? customizer(othValue, arrValue, index)
: customizer(arrValue, othValue, index);
}
if (typeof result == 'undefined') {
if (result === undefined) {
// Recursively compare arrays (susceptible to call stack limits).
if (isLoose) {
var othIndex = othLength;

View File

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

15
internal/getLength.js Normal file
View File

@@ -0,0 +1,15 @@
import baseProperty from './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');
export default getLength;

19
internal/getSymbols.js Normal file
View File

@@ -0,0 +1,19 @@
import constant from '../utility/constant';
import isNative from '../lang/isNative';
import toObject from './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));
};
export default getSymbols;

View File

@@ -27,7 +27,6 @@ var reFlags = /\w*$/;
* **Note:** This function only supports cloning values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
*
* @private
* @param {Object} object 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 @@
import baseGet from './baseGet';
import baseSlice from './baseSlice';
import isKey from './isKey';
import last from '../array/last';
import toPath from './toPath';
/**
* 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);
}
export default invokePath;

View File

@@ -1,3 +1,4 @@
import getLength from './getLength';
import isIndex from './isIndex';
import isLength from './isLength';
import isObject from '../lang/isObject';
@@ -17,7 +18,7 @@ function isIterateeCall(value, index, object) {
}
var type = typeof index;
if (type == 'number') {
var length = object.length,
var length = getLength(object),
prereq = isLength(length) && isIndex(index, length);
} else {
prereq = type == 'string' && index in object;

28
internal/isKey.js Normal file
View File

@@ -0,0 +1,28 @@
import isArray from '../lang/isArray';
import toObject from './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));
}
export default isKey;

View File

@@ -1,5 +1,5 @@
/**
* Adds `value` to `key` of the cache.
* Sets `value` to `key` of the cache.
*
* @private
* @name set

View File

@@ -2,7 +2,7 @@ import toObject from './toObject';
/**
* A specialized version of `_.pick` that picks `object` properties specified
* by the `props` array.
* by `props`.
*
* @private
* @param {Object} object The source object.

View File

@@ -11,7 +11,7 @@ var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType &&
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
/** 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`. */
var freeSelf = objectTypes[typeof self] && self && self.Object && self;

View File

@@ -44,7 +44,7 @@ function shimIsPlainObject(value) {
baseForIn(value, function(subValue, key) {
result = key;
});
return typeof result == 'undefined' || hasOwnProperty.call(value, result);
return result === undefined || hasOwnProperty.call(value, result);
}
export default shimIsPlainObject;

View File

@@ -16,7 +16,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* own enumerable property names of `object`.
*
* @private
* @param {Object} object The object to inspect.
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function shimKeys(object) {

View File

@@ -1,3 +1,4 @@
import getLength from './getLength';
import isLength from './isLength';
import isObject from '../lang/isObject';
import values from '../object/values';
@@ -13,7 +14,7 @@ function toIterable(value) {
if (value == null) {
return [];
}
if (!isLength(value.length)) {
if (!isLength(getLength(value))) {
return values(value);
}
return isObject(value) ? value : Object(value);

28
internal/toPath.js Normal file
View File

@@ -0,0 +1,28 @@
import baseToString from './baseToString';
import isArray from '../lang/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;
}
export default toPath;

View File

@@ -1,3 +1,4 @@
import getLength from '../internal/getLength';
import isArguments from './isArguments';
import isArray from './isArray';
import isFunction from './isFunction';
@@ -37,7 +38,7 @@ function isEmpty(value) {
if (value == null) {
return true;
}
var length = value.length;
var length = getLength(value);
if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
(isObjectLike(value) && isFunction(value.splice)))) {
return !length;

View File

@@ -20,7 +20,7 @@ import isStrictComparable from '../internal/isStrictComparable';
* @category Lang
* @param {*} value The 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`.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
@@ -51,7 +51,7 @@ function isEqual(value, other, customizer, thisArg) {
return value === other;
}
var result = customizer ? customizer(value, other) : undefined;
return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result;
return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
}
export default isEqual;

View File

@@ -21,7 +21,7 @@ import toObject from '../internal/toObject';
* @category Lang
* @param {Object} object The object to inspect.
* @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`.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
* @example
@@ -54,12 +54,13 @@ function isMatch(object, source, customizer, thisArg) {
return false;
}
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
object = toObject(object);
if (!customizer && length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return value === object[key] && (typeof value != 'undefined' || (key in toObject(object)));
return value === object[key] && (value !== undefined || (key in object));
}
}
var values = Array(length),
@@ -69,7 +70,7 @@ function isMatch(object, source, customizer, thisArg) {
value = values[length] = source[props[length]];
strictCompareFlags[length] = isStrictComparable(value);
}
return baseIsMatch(toObject(object), props, values, strictCompareFlags, customizer);
return baseIsMatch(object, props, values, strictCompareFlags, customizer);
}
export default isMatch;

View File

@@ -5,7 +5,7 @@ import isObjectLike from '../internal/isObjectLike';
var funcTag = '[object Function]';
/** Used to detect host constructors (Safari > 5). */
var reHostCtor = /^\[object .+?Constructor\]$/;
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used for native method references. */
var objectProto = Object.prototype;
@@ -20,7 +20,7 @@ var fnToString = Function.prototype.toString;
var objToString = objectProto.toString;
/** Used to detect if a method is native. */
var reNative = RegExp('^' +
var reIsNative = RegExp('^' +
escapeRegExp(objToString)
.replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
@@ -46,9 +46,9 @@ function isNative(value) {
return false;
}
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);
}
export default isNative;

View File

@@ -15,7 +15,7 @@
* // => false
*/
function isUndefined(value) {
return typeof value == 'undefined';
return value === undefined;
}
export default isUndefined;

View File

@@ -1,4 +1,5 @@
import arrayCopy from '../internal/arrayCopy';
import getLength from '../internal/getLength';
import isLength from '../internal/isLength';
import values from '../object/values';
@@ -18,7 +19,7 @@ import values from '../object/values';
* // => [2, 3]
*/
function toArray(value) {
var length = value ? value.length : 0;
var length = value ? getLength(value) : 0;
if (!isLength(length)) {
return values(value);
}

View File

@@ -1,9 +1,9 @@
/**
* @license
* lodash 3.6.0 (Custom Build) <https://lodash.com/>
* lodash 3.7.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize modern exports="es" -o ./`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
@@ -25,7 +25,6 @@ import baseCallback from './internal/baseCallback';
import baseForOwn from './internal/baseForOwn';
import baseFunctions from './internal/baseFunctions';
import baseMatches from './internal/baseMatches';
import baseProperty from './internal/baseProperty';
import createHybridWrapper from './internal/createHybridWrapper';
import identity from './utility/identity';
import isArray from './lang/isArray';
@@ -37,12 +36,13 @@ import lazyReverse from './internal/lazyReverse';
import lazyValue from './internal/lazyValue';
import lodash from './chain/lodash';
import _mixin from './utility/mixin';
import property from './utility/property';
import realNames from './internal/realNames';
import support from './support';
import thru from './chain/thru';
/** Used as the semantic version number. */
var VERSION = '3.6.0';
var VERSION = '3.7.0';
/** Used to compose bitmasks for wrapper metadata. */
var BIND_KEY_FLAG = 2;
@@ -135,6 +135,8 @@ lodash.matches = utility.matches;
lodash.matchesProperty = utility.matchesProperty;
lodash.memoize = func.memoize;
lodash.merge = object.merge;
lodash.method = utility.method;
lodash.methodOf = utility.methodOf;
lodash.mixin = mixin;
lodash.negate = func.negate;
lodash.omit = object.omit;
@@ -145,7 +147,7 @@ lodash.partialRight = func.partialRight;
lodash.partition = collection.partition;
lodash.pick = object.pick;
lodash.pluck = collection.pluck;
lodash.property = utility.property;
lodash.property = property;
lodash.propertyOf = utility.propertyOf;
lodash.pull = array.pull;
lodash.pullAt = array.pullAt;
@@ -155,6 +157,7 @@ lodash.reject = collection.reject;
lodash.remove = array.remove;
lodash.rest = array.rest;
lodash.restParam = func.restParam;
lodash.set = object.set;
lodash.shuffle = collection.shuffle;
lodash.slice = array.slice;
lodash.sortBy = collection.sortBy;
@@ -221,6 +224,7 @@ lodash.findLastIndex = array.findLastIndex;
lodash.findLastKey = object.findLastKey;
lodash.findWhere = collection.findWhere;
lodash.first = array.first;
lodash.get = object.get;
lodash.has = object.has;
lodash.identity = identity;
lodash.includes = collection.includes;
@@ -406,7 +410,7 @@ arrayEach(['initial', 'rest'], function(methodName, index) {
// Add `LazyWrapper` methods for `_.pluck` and `_.where`.
arrayEach(['pluck', 'where'], function(methodName, index) {
var operationName = index ? 'filter' : 'map',
createCallback = index ? baseMatches : baseProperty;
createCallback = index ? baseMatches : property;
LazyWrapper.prototype[methodName] = function(value) {
return this[operationName](createCallback(value));
@@ -428,7 +432,7 @@ LazyWrapper.prototype.slice = function(start, end) {
start = start == null ? 0 : (+start || 0);
var result = start < 0 ? this.takeRight(-start) : this.drop(start);
if (typeof end != 'undefined') {
if (end !== undefined) {
end = (+end || 0);
result = end < 0 ? result.dropRight(-end) : result.take(end - start);
}
@@ -459,7 +463,7 @@ baseForOwn(LazyWrapper.prototype, function(func, methodName) {
useLazy = isLazy || isArray(value);
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
// avoid lazy use if the iteratee has a `length` other than `1`
// avoid lazy use if the iteratee has a "length" value other than `1`
isLazy = useLazy = false;
}
var onlyLazy = isLazy && !isHybrid;

View File

@@ -13,7 +13,7 @@
* // => 10
*/
function add(augend, addend) {
return augend + addend;
return (+augend || 0) + (+addend || 0);
}
export default add;

View File

@@ -1,3 +1,7 @@
/* 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
* `end` is not specified it is set to `start` with `start` then set to `0`.
@@ -37,7 +41,7 @@ function inRange(value, start, end) {
} else {
end = +end || 0;
}
return value >= start && value < end;
return value >= nativeMin(start, end) && value < nativeMax(start, end);
}
export default inRange;

View File

@@ -9,6 +9,7 @@ import forInRight from './object/forInRight';
import forOwn from './object/forOwn';
import forOwnRight from './object/forOwnRight';
import functions from './object/functions';
import get from './object/get';
import has from './object/has';
import invert from './object/invert';
import keys from './object/keys';
@@ -20,6 +21,7 @@ import omit from './object/omit';
import pairs from './object/pairs';
import pick from './object/pick';
import result from './object/result';
import set from './object/set';
import transform from './object/transform';
import values from './object/values';
import valuesIn from './object/valuesIn';
@@ -36,6 +38,7 @@ export default {
'forOwn': forOwn,
'forOwnRight': forOwnRight,
'functions': functions,
'get': get,
'has': has,
'invert': invert,
'keys': keys,
@@ -47,6 +50,7 @@ export default {
'pairs': pairs,
'pick': pick,
'result': result,
'set': set,
'transform': transform,
'values': values,
'valuesIn': valuesIn

View File

@@ -1,3 +1,4 @@
import assignWith from '../internal/assignWith';
import baseAssign from '../internal/baseAssign';
import createAssigner from '../internal/createAssigner';
@@ -8,13 +9,17 @@ import createAssigner from '../internal/createAssigner';
* The `customizer` is bound to `thisArg` and invoked with five arguments:
* (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
* @memberOf _
* @alias extend
* @category Object
* @param {Object} object The destination object.
* @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`.
* @returns {Object} Returns `object`.
* @example
@@ -24,12 +29,16 @@ import createAssigner from '../internal/createAssigner';
*
* // using a customizer callback
* 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' });
* // => { 'user': 'barney', 'age': 36 }
*/
var assign = createAssigner(baseAssign);
var assign = createAssigner(function(object, source, customizer) {
return customizer
? assignWith(object, source, customizer)
: baseAssign(object, source);
});
export default assign;

View File

@@ -1,7 +1,6 @@
import baseCopy from '../internal/baseCopy';
import baseAssign from '../internal/baseAssign';
import baseCreate from '../internal/baseCreate';
import isIterateeCall from '../internal/isIterateeCall';
import keys from './keys';
/**
* Creates an object that inherits from the given `prototype` object. If a
@@ -42,7 +41,7 @@ function create(prototype, properties, guard) {
if (guard && isIterateeCall(prototype, properties, guard)) {
properties = null;
}
return properties ? baseCopy(properties, result, keys(properties)) : result;
return properties ? baseAssign(result, properties) : result;
}
export default create;

View File

@@ -7,6 +7,8 @@ import restParam from '../function/restParam';
* object for all destination properties that resolve to `undefined`. Once a
* property is set, additional values of the same property are ignored.
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @category Object

View File

@@ -4,7 +4,7 @@ import createForIn from '../internal/createForIn';
/**
* Iterates over own and inherited enumerable properties of an object invoking
* `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`.
*
* @static

View File

@@ -4,7 +4,7 @@ import createForOwn from '../internal/createForOwn';
/**
* Iterates over own enumerable properties of an object invoking `iteratee`
* 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`.
*
* @static

33
object/get.js Normal file
View File

@@ -0,0 +1,33 @@
import baseGet from '../internal/baseGet';
import toPath from '../internal/toPath';
/**
* 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;
}
export default get;

View File

@@ -1,3 +1,9 @@
import baseGet from '../internal/baseGet';
import baseSlice from '../internal/baseSlice';
import isKey from '../internal/isKey';
import last from '../array/last';
import toPath from '../internal/toPath';
/** Used for native method references. */
var objectProto = Object.prototype;
@@ -5,24 +11,39 @@ var objectProto = Object.prototype;
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Checks if `key` exists as a direct property of `object` instead of an
* inherited property.
* Checks if `path` is a direct property.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to inspect.
* @param {string} key The key to check.
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
* @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
*/
function has(object, key) {
return object ? hasOwnProperty.call(object, key) : false;
function has(object, path) {
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;
}
export default has;

View File

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

View File

@@ -19,7 +19,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to inspect.
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*

View File

@@ -15,7 +15,7 @@ import createAssigner from '../internal/createAssigner';
* @category Object
* @param {Object} object The destination object.
* @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`.
* @returns {Object} Returns `object`.
* @example

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