mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Bump to v3.7.0.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
41
internal/assignWith.js
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
29
internal/baseGet.js
Normal 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;
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
19
internal/basePropertyDeep.js
Normal file
19
internal/basePropertyDeep.js
Normal 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
30
internal/basePullAt.js
Normal 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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
15
internal/getLength.js
Normal 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
19
internal/getSymbols.js
Normal 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;
|
||||
@@ -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
26
internal/invokePath.js
Normal 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;
|
||||
@@ -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
28
internal/isKey.js
Normal 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;
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Adds `value` to `key` of the cache.
|
||||
* Sets `value` to `key` of the cache.
|
||||
*
|
||||
* @private
|
||||
* @name set
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
28
internal/toPath.js
Normal 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;
|
||||
Reference in New Issue
Block a user