vendor/assets/javascripts/lodash.compat.js in lodash-rails-3.6.0 vs vendor/assets/javascripts/lodash.compat.js in lodash-rails-3.7.0
- old
+ new
@@ -1,21 +1,21 @@
/**
* @license
- * lodash 3.6.0 (Custom Build) <https://lodash.com/>
+ * lodash 3.7.0 (Custom Build) <https://lodash.com/>
* Build: `lodash compat -o ./lodash.js`
* 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>
*/
;(function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** 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_FLAG = 1,
BIND_KEY_FLAG = 2,
CURRY_BOUND_FLAG = 4,
@@ -85,43 +85,47 @@
/** Used to match template delimiters. */
var reEscape = /<%-([\s\S]+?)%>/g,
reEvaluate = /<%([\s\S]+?)%>/g,
reInterpolate = /<%=([\s\S]+?)%>/g;
- /**
- * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
- */
- var reComboMarks = /[\u0300-\u036f\ufe20-\ufe23]/g;
+ /** Used to match property names within property paths. */
+ var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/,
+ reIsPlainProp = /^\w*$/,
+ rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
/**
- * Used to match [ES template delimiters](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components).
+ * Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
+ * In addition to special characters the forward slash is escaped to allow for
+ * easier `eval` use and `Function` compilation.
*/
+ var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
+ reHasRegExpChars = RegExp(reRegExpChars.source);
+
+ /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
+ var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
+
+ /** Used to match backslashes in property paths. */
+ var reEscapeChar = /\\(\\)?/g;
+
+ /** Used to match [ES template delimiters](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components). */
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
/** Used to match `RegExp` flags from their coerced string values. */
var reFlags = /\w*$/;
/** Used to detect hexadecimal string values. */
- var reHexPrefix = /^0[xX]/;
+ var reHasHexPrefix = /^0[xX]/;
/** Used to detect host constructors (Safari > 5). */
- var reHostCtor = /^\[object .+?Constructor\]$/;
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
/** Used to ensure capturing order of template delimiters. */
var reNoMatch = /($^)/;
- /**
- * Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
- * In addition to special characters the forward slash is escaped to allow for
- * easier `eval` use and `Function` compilation.
- */
- var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
- reHasRegExpChars = RegExp(reRegExpChars.source);
-
/** Used to match unescaped characters in compiled string literals. */
var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
/** Used to match words to create compound words. */
var reWords = (function() {
@@ -261,11 +265,11 @@
/** Detect free variable `module`. */
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;
/** Detect free variable `window`. */
@@ -296,14 +300,14 @@
function baseCompareAscending(value, other) {
if (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;
}
}
return 0;
}
@@ -442,11 +446,11 @@
/**
* 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.
*
* @private
* @param {Object} object The object to compare to `other`.
@@ -740,13 +744,10 @@
var document = (document = context.window) && document.document;
/** Used to resolve the decompiled source of functions. */
var fnToString = Function.prototype.toString;
- /** Used to the length of n-tuples for `_.unzip`. */
- var getLength = baseProperty('length');
-
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to generate unique IDs. */
var idCounter = 0;
@@ -759,23 +760,25 @@
/** Used to restore the original `_` reference in `_.noConflict`. */
var oldDash = context._;
/** Used to detect if a method is native. */
- var reNative = RegExp('^' +
+ var reIsNative = RegExp('^' +
escapeRegExp(objToString)
.replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
/** Native method references. */
var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer,
bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
ceil = Math.ceil,
clearTimeout = context.clearTimeout,
floor = Math.floor,
+ getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols,
getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
push = arrayProto.push,
+ preventExtensions = isNative(Object.preventExtensions = Object.preventExtensions) && preventExtensions,
propertyIsEnumerable = objectProto.propertyIsEnumerable,
Set = isNative(Set = context.Set) && Set,
setTimeout = context.setTimeout,
splice = arrayProto.splice,
Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
@@ -791,10 +794,26 @@
result = new func(new ArrayBuffer(10), 0, 1) && func;
} catch(e) {}
return result;
}());
+ /** Used as `baseAssign`. */
+ var nativeAssign = (function() {
+ // Avoid `Object.assign` in Firefox 34-37 which have an early implementation
+ // with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344
+ // for more details.
+ //
+ // Use `Object.preventExtensions` on a plain object instead of simply using
+ // `Object('x')` because Chrome and IE fail to throw an error when attempting
+ // to assign values to readonly indexes of strings 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;
+ }());
+
/* Native method references for those with the same name as other `lodash` methods. */
var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
nativeIsFinite = context.isFinite,
nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
@@ -896,12 +915,12 @@
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
* `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
* `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`,
* `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
* `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
@@ -911,19 +930,19 @@
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
- * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
- * `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
- * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
- * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
- * `noConflict`, `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.
*
* @name _
@@ -934,12 +953,12 @@
* @example
*
* 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
*
* // returns a wrapped value
* var squares = wrapped.map(function(n) {
@@ -995,15 +1014,15 @@
* @type Object
*/
var support = lodash.support = {};
(function(x) {
- var Ctor = function() { this.x = 1; },
- object = { '0': 1, 'length': 1 },
+ var Ctor = function() { this.x = x; },
+ object = { '0': x, 'length': x },
props = [];
- Ctor.prototype = { 'valueOf': 1, 'y': 1 };
+ Ctor.prototype = { 'valueOf': x, 'y': x };
for (var key in new Ctor) { props.push(key); }
/**
* Detect if the `toStringTag` of `arguments` objects is resolvable
* (all but Firefox < 4, IE < 9).
@@ -1061,21 +1080,19 @@
* @type boolean
*/
support.nodeTag = objToString.call(document) != objectTag;
/**
- * Detect if string indexes are non-enumerable
- * (IE < 9, RingoJS, Rhino, Narwhal).
+ * Detect if string indexes are non-enumerable (IE < 9, RingoJS, Rhino, Narwhal).
*
* @memberOf _.support
* @type boolean
*/
support.nonEnumStrings = !propertyIsEnumerable.call('x', 0);
/**
- * Detect if properties shadowing those on `Object.prototype` are
- * non-enumerable.
+ * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
*
* In IE < 9 an object's own properties, shadowing non-enumerable ones,
* are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
*
* @memberOf _.support
@@ -1093,15 +1110,15 @@
/**
* Detect if `Array#shift` and `Array#splice` augment array-like objects
* correctly.
*
- * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array `shift()`
- * and `splice()` functions that fail to remove the last element, `value[0]`,
- * of array-like objects even though the `length` property is set to `0`.
- * The `shift()` method is buggy in compatibility modes of IE 8, while `splice()`
- * is buggy regardless of mode in IE < 9.
+ * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array
+ * `shift()` and `splice()` functions that fail to remove the last element,
+ * `value[0]`, of array-like objects even though the "length" property is
+ * set to `0`. The `shift()` method is buggy in compatibility modes of IE 8,
+ * while `splice()` is buggy regardless of mode in IE < 9.
*
* @memberOf _.support
* @type boolean
*/
support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
@@ -1133,22 +1150,22 @@
* Detect if `arguments` object indexes are non-enumerable.
*
* In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
* indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
* `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
- * checks for indexes that exceed their function's formal parameters with
- * associated values of `0`.
+ * checks for indexes that exceed the number of function parameters and
+ * whose associated argument values are `0`.
*
* @memberOf _.support
* @type boolean
*/
try {
support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
} catch(e) {
support.nonEnumArgs = true;
}
- }(0, 0));
+ }(1, 0));
/**
* By default, the template delimiters used by lodash are like those in
* embedded Ruby (ERB). Change the following template settings to use
* alternative delimiters.
@@ -1391,11 +1408,11 @@
function mapHas(key) {
return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
}
/**
- * Adds `value` to `key` of the cache.
+ * Sets `value` to `key` of the cache.
*
* @private
* @name set
* @memberOf _.memoize.Cache
* @param {string} key The key of the value to cache.
@@ -1724,70 +1741,85 @@
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @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;
}
/**
* 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
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @param {string} key The key associated with the object and source values.
* @param {Object} object The destination object.
* @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;
}
/**
- * The base implementation of `_.assign` without support for argument juggling,
- * multiple sources, and `this` binding `customizer` functions.
+ * 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 assigning values.
- * @returns {Object} Returns the destination object.
+ * @param {Function} customizer The function to customize assigned values.
+ * @returns {Object} Returns `object`.
*/
- function baseAssign(object, source, customizer) {
+ function assignWith(object, source, customizer) {
var props = keys(source);
- if (!customizer) {
- return baseCopy(source, object, props);
- }
+ 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)) ||
- (typeof value == 'undefined' && !(key in object))) {
+ (value === undefined && !(key in object))) {
object[key] = result;
}
}
return object;
}
/**
- * The base implementation of `_.at` without support for strings and individual
- * key arguments.
+ * The base implementation of `_.assign` without support for argument juggling,
+ * multiple sources, and `customizer` functions.
*
* @private
+ * @param {Object} object The destination object.
+ * @param {Object} source The source object.
+ * @returns {Object} Returns `object`.
+ */
+ var baseAssign = nativeAssign || function(object, source) {
+ return source == null
+ ? object
+ : baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
+ };
+
+ /**
+ * 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) {
var index = -1,
length = collection.length,
@@ -1796,33 +1828,30 @@
result = Array(propsLength);
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];
}
}
return result;
}
/**
- * 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;
while (++index < length) {
var key = props[index];
@@ -1842,23 +1871,23 @@
* @returns {Function} Returns the callback.
*/
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
- return typeof thisArg == 'undefined'
+ return thisArg === undefined
? func
: bindCallback(func, thisArg, argCount);
}
if (func == null) {
return identity;
}
if (type == 'object') {
return baseMatches(func);
}
- return typeof thisArg == 'undefined'
- ? baseProperty(func + '')
- : baseMatchesProperty(func + '', thisArg);
+ return thisArg === undefined
+ ? property(func)
+ : baseMatchesProperty(func, thisArg);
}
/**
* The base implementation of `_.clone` without support for argument juggling
* and `this` binding `customizer` functions.
@@ -1876,11 +1905,11 @@
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
var result;
if (customizer) {
result = object ? customizer(value, key, object) : customizer(value);
}
- if (typeof result != 'undefined') {
+ if (result !== undefined) {
return result;
}
if (!isObject(value)) {
return value;
}
@@ -1898,11 +1927,11 @@
if (isHostObject(value)) {
return object ? value : {};
}
result = initCloneObject(isFunc ? {} : value);
if (!isDeep) {
- return baseCopy(value, result, keys(value));
+ return baseAssign(result, value);
}
} else {
return cloneableTags[tag]
? initCloneByTag(value, tag, isDeep)
: (object ? value : {});
@@ -2069,11 +2098,11 @@
start = start == null ? 0 : (+start || 0);
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;
}
length = start > end ? 0 : (end >>> 0);
start >>>= 0;
@@ -2166,11 +2195,11 @@
}
/**
* 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
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
@@ -2253,10 +2282,37 @@
}
return result;
}
/**
+ * 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;
+ }
+ object = toObject(object);
+ if (pathKey !== undefined && pathKey in object) {
+ path = [pathKey];
+ }
+ var index = -1,
+ length = path.length;
+
+ while (object != null && ++index < length) {
+ var result = object = toObject(object)[path[index]];
+ }
+ return result;
+ }
+
+ /**
* The base implementation of `_.isEqual` without support for `this` binding
* `customizer` functions.
*
* @private
* @param {*} value The value to compare.
@@ -2320,32 +2376,28 @@
othTag = objectTag;
} else if (othTag != objectTag) {
othIsArr = isTypedArray(other);
}
}
- var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)) && !isHostObject(object),
- othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)) && !isHostObject(other),
+ var objIsObj = objTag == objectTag && !isHostObject(object),
+ othIsObj = othTag == objectTag && !isHostObject(other),
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.
stackA || (stackA = []);
stackB || (stackB = []);
@@ -2397,14 +2449,14 @@
var key = props[index],
objValue = object[key],
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);
}
}
if (!result) {
return false;
@@ -2421,13 +2473,16 @@
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @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;
}
/**
@@ -2448,12 +2503,15 @@
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return function(object) {
- return object != null && object[key] === value &&
- (typeof value != 'undefined' || (key in toObject(object)));
+ if (object == null) {
+ return false;
+ }
+ object = toObject(object);
+ return object[key] === value && (value !== undefined || (key in object));
};
}
}
var values = Array(length),
strictCompareFlags = Array(length);
@@ -2467,27 +2525,41 @@
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
};
}
/**
- * 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);
};
}
/**
* The base implementation of `_.merge` without support for argument juggling,
@@ -2497,34 +2569,44 @@
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @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 (isCommon) {
+ result = srcValue;
+ }
+ if ((isSrcArr || result !== undefined) &&
+ (isCommon || (result === result ? (result !== value) : (value === value)))) {
+ object[key] = result;
+ }
}
- if ((isSrcArr || typeof result != 'undefined') &&
- (isCommon || (result === result ? (result !== value) : (value === value)))) {
- object[key] = result;
- }
});
return object;
}
/**
@@ -2552,18 +2634,18 @@
return;
}
}
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)
? toPlainObject(value)
: (isPlainObject(value) ? value : {});
@@ -2584,23 +2666,59 @@
object[key] = result;
}
}
/**
- * 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.
* @returns {Function} Returns the new function.
*/
function baseProperty(key) {
return function(object) {
- return object == null ? undefined : object[key];
+ return object == null ? undefined : toObject(object)[key];
};
}
/**
+ * 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);
+ };
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
* The base implementation of `_.random` without support for argument juggling
* and returning floating-point numbers.
*
* @private
* @param {number} min The minimum possible value.
@@ -2662,11 +2780,11 @@
start = start == null ? 0 : (+start || 0);
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;
}
length = start > end ? 0 : ((end - start) >>> 0);
start >>>= 0;
@@ -2721,27 +2839,23 @@
/**
* 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 callback = getCallback(),
+ index = -1;
- baseEach(collection, function(value) {
- var length = props.length,
- criteria = Array(length);
+ iteratees = arrayMap(iteratees, function(iteratee) { return callback(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) {
return compareMultiple(object, other, orders);
});
@@ -2817,11 +2931,11 @@
}
/**
* 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.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
@@ -2934,21 +3048,21 @@
value = iteratee(value);
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),
computed = iteratee(array[mid]),
isReflexive = computed === computed;
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);
}
if (setLow) {
low = mid + 1;
@@ -2971,11 +3085,11 @@
*/
function bindCallback(func, thisArg, argCount) {
if (typeof func != 'function') {
return identity;
}
- if (typeof thisArg == 'undefined') {
+ if (thisArg === undefined) {
return func;
}
switch (argCount) {
case 1: return function(value) {
return func.call(thisArg, value);
@@ -3131,42 +3245,36 @@
* @private
* @param {Function} assigner The function to assign values.
* @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;
- };
+ });
}
/**
* Creates a `baseEach` or `baseEachRight` function.
*
@@ -3175,11 +3283,11 @@
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
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);
}
var index = fromRight ? length : -1,
iterable = toObject(collection);
@@ -3452,11 +3560,11 @@
* @param {Function} eachFunc The function to iterate over a collection.
* @returns {Function} Returns the new each function.
*/
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));
};
}
@@ -3467,11 +3575,11 @@
* @param {Function} objectFunc The function to iterate over an object.
* @returns {Function} Returns the new each function.
*/
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);
};
}
@@ -3483,11 +3591,11 @@
* @param {Function} objectFunc The function to iterate over an object.
* @returns {Function} Returns the new each function.
*/
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);
};
}
@@ -3530,11 +3638,11 @@
* @returns {Function} Returns the new each function.
*/
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, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
};
}
@@ -3799,11 +3907,11 @@
if (customizer) {
result = isLoose
? 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;
while (othIndex--) {
othValue = other[othIndex];
@@ -3898,11 +4006,11 @@
if (customizer) {
result = isLoose
? 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);
}
}
if (!result) {
@@ -4024,10 +4132,33 @@
result = result === indexOf ? baseIndexOf : result;
return collection ? result(collection, target, fromIndex) : result;
}
/**
+ * 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');
+
+ /**
+ * 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));
+ };
+
+ /**
* Gets the view, applying any `transforms` to the `start` and `end` positions.
*
* @private
* @param {number} start The start of the view.
* @param {number} end The end of the view.
@@ -4091,11 +4222,10 @@
* Initializes an object clone based on its `toStringTag`.
*
* **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.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the initialized clone.
@@ -4130,10 +4260,29 @@
}
return result;
}
/**
+ * 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);
+ }
+
+ /**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
@@ -4158,11 +4307,11 @@
if (!isObject(object)) {
return false;
}
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;
}
if (prereq) {
@@ -4171,10 +4320,30 @@
}
return false;
}
/**
+ * 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));
+ }
+
+ /**
* Checks if `func` has a lazy counterpart.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
@@ -4279,11 +4448,11 @@
return data;
}
/**
* A specialized version of `_.pick` that picks `object` properties specified
- * by the `props` array.
+ * by `props`.
*
* @private
* @param {Object} object The source object.
* @param {string[]} props The property names to pick.
* @returns {Object} Returns the new object.
@@ -4413,19 +4582,19 @@
// its inherited properties. If the last iterated property is an object's
// own property then there are no inherited enumerable properties.
baseForIn(value, function(subValue, key) {
result = key;
});
- return typeof result == 'undefined' || hasOwnProperty.call(value, result);
+ return result === undefined || hasOwnProperty.call(value, result);
}
/**
* A fallback implementation of `Object.keys` which creates an array of the
* 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) {
var props = keysIn(object),
propsLength = props.length,
@@ -4457,11 +4626,11 @@
*/
function toIterable(value) {
if (value == null) {
return [];
}
- if (!isLength(value.length)) {
+ if (!isLength(getLength(value))) {
return values(value);
}
if (lodash.support.unindexedChars && isString(value)) {
return value.split('');
}
@@ -4488,10 +4657,28 @@
}
return isObject(value) ? value : Object(value);
}
/**
+ * 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;
+ }
+
+ /**
* Creates a clone of `wrapper`.
*
* @private
* @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the cloned wrapper.
@@ -5071,24 +5258,27 @@
var args = [],
argsIndex = -1,
argsLength = arguments.length,
caches = [],
indexOf = getIndexOf(),
- isCommon = indexOf == baseIndexOf;
+ isCommon = indexOf == baseIndexOf,
+ result = [];
while (++argsIndex < argsLength) {
var value = arguments[argsIndex];
if (isArray(value) || isArguments(value)) {
args.push(value);
caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
}
}
argsLength = args.length;
+ if (argsLength < 2) {
+ return result;
+ }
var array = args[0],
index = -1,
length = array ? array.length : 0,
- result = [],
seen = caches[0];
outer:
while (++index < length) {
value = array[index];
@@ -5252,21 +5442,12 @@
*/
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;
});
/**
* Removes all elements from `array` that `predicate` returns truthy for
@@ -5306,23 +5487,27 @@
*
* console.log(evens);
* // => [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 = getCallback(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;
}
/**
* Gets all but the first element of `array`.
@@ -5343,11 +5528,11 @@
}
/**
* 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
* @memberOf _
* @category Array
@@ -5642,16 +5827,17 @@
var union = restParam(function(arrays) {
return baseUniq(baseFlatten(arrays, false, true));
});
/**
- * 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.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -5675,12 +5861,12 @@
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @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);
* // => [1, 2]
*
@@ -6126,11 +6312,11 @@
*
* _.at(['barney', 'fred', 'pebbles'], 0, 2);
* // => ['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);
}
return baseAt(collection, baseFlatten(props));
});
@@ -6231,11 +6417,11 @@
function every(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayEvery : baseEvery;
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
- if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
+ if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
@@ -6401,14 +6587,14 @@
}
/**
* 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.
*
* @static
* @memberOf _
@@ -6534,11 +6720,11 @@
*
* _.includes('pebbles', 'eb');
* // => 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;
}
if (!length) {
@@ -6603,20 +6789,20 @@
var indexBy = createAggregator(function(result, value, key) {
result[key] = value;
});
/**
- * 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.
* @example
*
@@ -6624,19 +6810,20 @@
* // => [[1, 5, 7], [1, 2, 3]]
*
* _.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;
});
/**
@@ -6669,11 +6856,10 @@
* @alias collect
* @category Collection
* @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
*
* function timesThree(n) {
@@ -6763,17 +6949,17 @@
var partition = createAggregator(function(result, value, key) {
result[key ? 0 : 1].push(value);
}, function() { return [[], []]; });
/**
- * 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
*
* var users = [
* { 'user': 'barney', 'age': 36 },
@@ -6785,12 +6971,12 @@
*
* var userIndex = _.indexBy(users, 'user');
* _.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));
}
/**
* Reduces `collection` to a value which is the accumulated result of running
* each element in `collection` through `iteratee`, where each successive
@@ -6814,12 +7000,12 @@
* @param {*} [accumulator] The initial value.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @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
*
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3;
@@ -6987,11 +7173,11 @@
*
* _.size('pebbles');
* // => 7
*/
function size(collection) {
- var length = collection ? collection.length : 0;
+ var length = collection ? getLength(collection) : 0;
return isLength(length) ? length : keys(collection).length;
}
/**
* Checks if `predicate` returns truthy for **any** element of `collection`.
@@ -7045,11 +7231,11 @@
function some(collection, predicate, thisArg) {
var func = isArray(collection) ? arraySome : baseSome;
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
- if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
+ if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
@@ -7073,13 +7259,12 @@
*
* @static
* @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
*
* _.sortBy([1, 2, 3], function(n) {
@@ -7104,108 +7289,116 @@
*/
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 = getCallback(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);
}
/**
- * 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), []);
+ });
/**
* 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);
}
/**
* Performs a deep comparison between each element in `collection` and the
* source object, returning an array of all elements that have equivalent
@@ -7354,11 +7547,12 @@
}
}
return function() {
if (--n > 0) {
result = func.apply(this, arguments);
- } else {
+ }
+ if (n <= 1) {
func = null;
}
return result;
};
}
@@ -7369,11 +7563,11 @@
* bound function.
*
* 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
* @memberOf _
* @category Function
@@ -7411,11 +7605,11 @@
* Binds methods of an object to the object itself, overwriting the existing
* method. Method names may be specified as individual arguments or as arrays
* 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 _
* @category Function
* @param {Object} object The object to bind and assign the bound methods to.
@@ -7452,11 +7646,11 @@
* Creates a function that invokes the method at `object[key]` and prepends
* any additional `_.bindKey` arguments to those provided to the bound function.
*
* 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
* builds, may be used as a placeholder for partially applied arguments.
*
@@ -7509,11 +7703,11 @@
* if `func.length` is not sufficient.
*
* 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 _
* @category Function
* @param {Function} func The function to curry.
@@ -7548,11 +7742,11 @@
* in the manner of `_.partialRight` instead of `_.partial`.
*
* 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 _
* @category Function
* @param {Function} func The function to curry.
@@ -7960,22 +8154,22 @@
* initialize();
* initialize();
* // `initialize` invokes `createApplication` once
*/
function once(func) {
- return before(func, 2);
+ return before(2, func);
}
/**
* Creates a function that invokes `func` with `partial` arguments prepended
* to those provided to the new function. This method is like `_.bind` except
* it does **not** alter the `this` binding.
*
* 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
* @memberOf _
* @category Function
@@ -8004,11 +8198,11 @@
* are appended to those provided to the new function.
*
* 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
* @memberOf _
* @category Function
@@ -8088,11 +8282,11 @@
*/
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,
length = nativeMax(args.length - start, 0),
rest = Array(length);
@@ -8500,11 +8694,11 @@
*/
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;
}
return !keys(value).length;
@@ -8526,11 +8720,11 @@
* @static
* @memberOf _
* @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
*
* var object = { 'user': 'fred' };
@@ -8557,11 +8751,11 @@
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
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;
}
/**
* Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
* `SyntaxError`, `TypeError`, or `URIError` object.
@@ -8679,11 +8873,11 @@
* @static
* @memberOf _
* @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
*
* var object = { 'user': 'fred', 'age': 40 };
@@ -8712,26 +8906,27 @@
}
if (object == null) {
return false;
}
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
+ object = toObject(object);
if (!customizer && length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
- return value === object[key] && (typeof value != 'undefined' || (key in toObject(object)));
+ return value === object[key] && (value !== undefined || (key in object));
}
}
var values = Array(length),
strictCompareFlags = Array(length);
while (length--) {
value = values[length] = source[props[length]];
strictCompareFlags[length] = isStrictComparable(value);
}
- return baseIsMatch(toObject(object), props, values, strictCompareFlags, customizer);
+ return baseIsMatch(object, props, values, strictCompareFlags, customizer);
}
/**
* Checks if `value` is `NaN`.
*
@@ -8782,13 +8977,13 @@
function isNative(value) {
if (value == null) {
return false;
}
if (objToString.call(value) == funcTag) {
- return reNative.test(fnToString.call(value));
+ return reIsNative.test(fnToString.call(value));
}
- return isObjectLike(value) && (isHostObject(value) ? reNative : reHostCtor).test(value);
+ return isObjectLike(value) && (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
}
/**
* Checks if `value` is `null`.
*
@@ -8952,11 +9147,11 @@
*
* _.isUndefined(null);
* // => false
*/
function isUndefined(value) {
- return typeof value == 'undefined';
+ return value === undefined;
}
/**
* Converts `value` to an array.
*
@@ -8971,11 +9166,11 @@
* return _.toArray(arguments).slice(1);
* }(1, 2, 3));
* // => [2, 3]
*/
function toArray(value) {
- var length = value ? value.length : 0;
+ var length = value ? getLength(value) : 0;
if (!isLength(length)) {
return values(value);
}
if (!length) {
return [];
@@ -9019,33 +9214,41 @@
* object. Subsequent sources overwrite property assignments of previous sources.
* If `customizer` is provided it is invoked to produce the assigned values.
* 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
*
* _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
* // => { 'user': 'fred', 'age': 40 }
*
* // 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);
+ });
/**
* Creates an object that inherits from the given `prototype` object. If a
* `properties` object is provided its own enumerable properties are assigned
* to the created object.
@@ -9082,18 +9285,20 @@
function create(prototype, properties, guard) {
var result = baseCreate(prototype);
if (guard && isIterateeCall(prototype, properties, guard)) {
properties = null;
}
- return properties ? baseCopy(properties, result, keys(properties)) : result;
+ return properties ? baseAssign(result, properties) : result;
}
/**
* Assigns own enumerable properties of source object(s) to the destination
* 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
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
@@ -9213,11 +9418,11 @@
var findLastKey = createFindKey(baseForOwnRight);
/**
* 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
* @memberOf _
* @category Object
@@ -9269,11 +9474,11 @@
var forInRight = createForIn(baseForRight);
/**
* 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
* @memberOf _
* @category Object
@@ -9342,28 +9547,72 @@
function functions(object) {
return baseFunctions(object, keysIn(object));
}
/**
- * Checks if `key` exists as a direct property of `object` instead of an
- * inherited property.
+ * 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 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 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': 1, 'b': 2, 'c': 3 };
+ * var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
- * _.has(object, 'b');
+ * _.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;
+ }
+
+ /**
+ * Checks if `path` is a direct property.
+ *
+ * @static
+ * @memberOf _
+ * @category Object
+ * @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': { 'b': { 'c': 3 } } };
+ *
+ * _.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 || (lodash.support.nonEnumStrings && isString(object) && isIndex(path, object.length));
}
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite property
@@ -9422,11 +9671,11 @@
* for more details.
*
* @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
*
* function Foo() {
* this.a = 1;
@@ -9445,11 +9694,11 @@
if (object) {
var Ctor = object.constructor,
length = object.length;
}
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
- (typeof object == 'function' ? lodash.support.enumPrototypes : (length && isLength(length)))) {
+ (typeof object == 'function' ? lodash.support.enumPrototypes : isLength(length))) {
return shimKeys(object);
}
return isObject(object) ? nativeKeys(object) : [];
};
@@ -9459,11 +9708,11 @@
* **Note:** Non-object values are coerced to objects.
*
* @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
*
* function Foo() {
* this.a = 1;
@@ -9596,11 +9845,11 @@
* @static
* @memberOf _
* @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
*
* var users = {
@@ -9681,11 +9930,11 @@
* e.g. `[[key1, value1], [key2, value2]]`.
*
* @static
* @memberOf _
* @category Object
- * @param {Object} object The object to inspect.
+ * @param {Object} object The object to query.
* @returns {Array} Returns the new array of key-value pairs.
* @example
*
* _.pairs({ 'barney': 36, 'fred': 40 });
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
@@ -9737,53 +9986,105 @@
? pickByCallback(object, bindCallback(props[0], props[1], 3))
: pickByArray(object, baseFlatten(props));
});
/**
- * Resolves the value of property `key` on `object`. If the value of `key` is
- * a function it is invoked with the `this` binding of `object` and its result
- * is returned, else the property value is returned. If the property value is
- * `undefined` the `defaultValue` is used in its place.
+ * This method is like `_.get` except that if the resolved value is a function
+ * it is invoked with the `this` binding of its parent object and its result
+ * is returned.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
- * @param {string} key The key of the property to resolve.
- * @param {*} [defaultValue] The value returned if the property value
- * resolves to `undefined`.
+ * @param {Array|string} path The path of the property to resolve.
+ * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
- * var object = { 'user': 'fred', 'age': _.constant(40) };
+ * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
*
- * _.result(object, 'user');
- * // => 'fred'
+ * _.result(object, 'a[0].b.c1');
+ * // => 3
*
- * _.result(object, 'age');
- * // => 40
+ * _.result(object, 'a[0].b.c2');
+ * // => 4
*
- * _.result(object, 'status', 'busy');
- * // => 'busy'
+ * _.result(object, 'a.b.c', 'default');
+ * // => 'default'
*
- * _.result(object, 'status', _.constant('busy'));
- * // => 'busy'
+ * _.result(object, 'a.b.c', _.constant('default'));
+ * // => 'default'
*/
- function result(object, key, defaultValue) {
- var value = object == null ? undefined : object[key];
- if (typeof value == 'undefined') {
- value = defaultValue;
+ function result(object, path, defaultValue) {
+ var result = object == null ? undefined : toObject(object)[path];
+ if (result === undefined) {
+ if (object != null && !isKey(path, object)) {
+ path = toPath(path);
+ object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
+ result = object == null ? undefined : toObject(object)[last(path)];
+ }
+ result = result === undefined ? defaultValue : result;
}
- return isFunction(value) ? value.call(object) : value;
+ return isFunction(result) ? result.call(object) : result;
}
/**
+ * Sets the property value of `path` on `object`. If a portion of `path`
+ * does not exist it is created.
+ *
+ * @static
+ * @memberOf _
+ * @category Object
+ * @param {Object} object The object to augment.
+ * @param {Array|string} path The path of the property to set.
+ * @param {*} value The value to set.
+ * @returns {Object} Returns `object`.
+ * @example
+ *
+ * var object = { 'a': [{ 'b': { 'c': 3 } }] };
+ *
+ * _.set(object, 'a[0].b.c', 4);
+ * console.log(object.a[0].b.c);
+ * // => 4
+ *
+ * _.set(object, 'x[0].y.z', 5);
+ * console.log(object.x[0].y.z);
+ * // => 5
+ */
+ function set(object, path, value) {
+ if (object == null) {
+ return object;
+ }
+ var pathKey = (path + '');
+ path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
+
+ var index = -1,
+ length = path.length,
+ endIndex = length - 1,
+ nested = object;
+
+ while (nested != null && ++index < length) {
+ var key = path[index];
+ if (isObject(nested)) {
+ if (index == endIndex) {
+ nested[key] = value;
+ } else if (nested[key] == null) {
+ nested[key] = isIndex(path[index + 1]) ? [] : {};
+ }
+ }
+ nested = nested[key];
+ }
+ return object;
+ }
+
+ /**
* An alternative to `_.reduce`; this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own enumerable
* properties through `iteratee`, with each invocation potentially mutating
* the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
- * with four arguments: (accumulator, value, key, object). Iterator functions
+ * with four arguments: (accumulator, value, key, object). Iteratee functions
* may exit iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
@@ -9922,11 +10223,11 @@
end = start;
start = 0;
} else {
end = +end || 0;
}
- return value >= start && value < end;
+ return value >= nativeMin(start, end) && value < nativeMax(start, end);
}
/**
* Produces a random number between `min` and `max` (inclusive). If only one
* argument is provided a number between `0` and the given number is returned.
@@ -10047,11 +10348,11 @@
* _.deburr('déjà vu');
* // => 'deja vu'
*/
function deburr(string) {
string = baseToString(string);
- return string && string.replace(reLatin1, deburrLetter).replace(reComboMarks, '');
+ return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
}
/**
* Checks if `string` ends with the given target string.
*
@@ -10076,11 +10377,11 @@
function endsWith(string, target, position) {
string = baseToString(string);
target = (target + '');
var length = string.length;
- position = typeof position == 'undefined'
+ position = position === undefined
? length
: nativeMin(position < 0 ? 0 : (+position || 0), length);
position -= target.length;
return position >= 0 && string.indexOf(target, position) == position;
@@ -10098,13 +10399,14 @@
* unless they're part of a tag or unquoted attribute value.
* See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
* (under "semi-related fun fact") for more details.
*
* Backticks are escaped because in Internet Explorer < 9, they can break out
- * of attribute values or HTML comments. See [#102](https://html5sec.org/#102),
- * [#108](https://html5sec.org/#108), and [#133](https://html5sec.org/#133) of
- * the [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
+ * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
+ * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
+ * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
+ * for more details.
*
* When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
* to reduce XSS vectors.
*
* @static
@@ -10294,11 +10596,11 @@
radix = 0;
} else if (radix) {
radix = +radix;
}
string = trim(string);
- return nativeParseInt(string, radix || (reHexPrefix.test(string) ? 16 : 10));
+ return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
};
}
/**
* Repeats the given string `n` times.
@@ -10519,13 +10821,13 @@
if (otherOptions && isIterateeCall(string, options, otherOptions)) {
options = otherOptions = null;
}
string = baseToString(string);
- options = baseAssign(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
+ options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
- var imports = baseAssign(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
+ var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
importsKeys = keys(imports),
importsValues = baseValues(imports, importsKeys);
var isEscaping,
isEvaluating,
@@ -10925,13 +11227,11 @@
*/
function callback(func, thisArg, guard) {
if (guard && isIterateeCall(func, thisArg, guard)) {
thisArg = null;
}
- return isObjectLike(func)
- ? matches(func)
- : baseCallback(func, thisArg);
+ return baseCallback(func, thisArg);
}
/**
* Creates a function that returns `value`.
*
@@ -11001,21 +11301,21 @@
function matches(source) {
return baseMatches(baseClone(source, true));
}
/**
- * Creates a function which compares the property value of `key` on a given
+ * Creates a function which compares the property value of `path` on a given
* object to `value`.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties.
*
* @static
* @memberOf _
* @category Utility
- * @param {string} key The key of the property to get.
+ * @param {Array|string} path The path of the property to get.
* @param {*} value The value to compare.
* @returns {Function} Returns the new function.
* @example
*
* var users = [
@@ -11024,26 +11324,79 @@
* ];
*
* _.find(users, _.matchesProperty('user', 'fred'));
* // => { 'user': 'fred' }
*/
- function matchesProperty(key, value) {
- return baseMatchesProperty(key + '', baseClone(value, true));
+ function matchesProperty(path, value) {
+ return baseMatchesProperty(path, baseClone(value, true));
}
/**
+ * Creates a function which invokes the method at `path` on a given object.
+ *
+ * @static
+ * @memberOf _
+ * @category Utility
+ * @param {Array|string} path The path of the method to invoke.
+ * @returns {Function} Returns the new function.
+ * @example
+ *
+ * var objects = [
+ * { 'a': { 'b': { 'c': _.constant(2) } } },
+ * { 'a': { 'b': { 'c': _.constant(1) } } }
+ * ];
+ *
+ * _.map(objects, _.method('a.b.c'));
+ * // => [2, 1]
+ *
+ * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
+ * // => [1, 2]
+ */
+ var method = restParam(function(path, args) {
+ return function(object) {
+ return invokePath(object, path, args);
+ }
+ });
+
+ /**
+ * The opposite of `_.method`; this method creates a function which invokes
+ * the method at a given path on `object`.
+ *
+ * @static
+ * @memberOf _
+ * @category Utility
+ * @param {Object} object The object to query.
+ * @returns {Function} Returns the new function.
+ * @example
+ *
+ * var array = _.times(3, _.constant),
+ * object = { 'a': array, 'b': array, 'c': array };
+ *
+ * _.map(['a[2]', 'c[0]'], _.methodOf(object));
+ * // => [2, 0]
+ *
+ * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
+ * // => [2, 0]
+ */
+ var methodOf = restParam(function(object, args) {
+ return function(path) {
+ return invokePath(object, path, args);
+ };
+ });
+
+ /**
* Adds all own enumerable function properties of a source object to the
* destination object. If `object` is a function then methods are added to
* its prototype as well.
*
- * **Note:** Use `_.runInContext` to create a pristine `lodash` function
- * for mixins to avoid conflicts caused by modifying the original.
+ * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
+ * avoid conflicts caused by modifying the original.
*
* @static
* @memberOf _
* @category Utility
- * @param {Function|Object} [object=this] object The destination object.
+ * @param {Function|Object} [object=lodash] The destination object.
* @param {Object} source The object of functions to add.
* @param {Object} [options] The options object.
* @param {boolean} [options.chain=true] Specify whether the functions added
* are chainable.
* @returns {Function|Object} Returns `object`.
@@ -11156,65 +11509,65 @@
function noop() {
// No operation performed.
}
/**
- * Creates a function which returns the property value of `key` on a given object.
+ * Creates a function which returns the property value at `path` on a
+ * given object.
*
* @static
* @memberOf _
* @category Utility
- * @param {string} key The key of the property to get.
+ * @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function.
* @example
*
- * var users = [
- * { 'user': 'fred' },
- * { 'user': 'barney' }
+ * var objects = [
+ * { 'a': { 'b': { 'c': 2 } } },
+ * { 'a': { 'b': { 'c': 1 } } }
* ];
*
- * var getName = _.property('user');
+ * _.map(objects, _.property('a.b.c'));
+ * // => [2, 1]
*
- * _.map(users, getName);
- * // => ['fred', 'barney']
- *
- * _.pluck(_.sortBy(users, getName), 'user');
- * // => ['barney', 'fred']
+ * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
+ * // => [1, 2]
*/
- function property(key) {
- return baseProperty(key + '');
+ function property(path) {
+ return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
}
/**
* The opposite of `_.property`; this method creates a function which returns
- * the property value of a given key on `object`.
+ * the property value at a given path on `object`.
*
* @static
* @memberOf _
* @category Utility
- * @param {Object} object The object to inspect.
+ * @param {Object} object The object to query.
* @returns {Function} Returns the new function.
* @example
*
- * var object = { 'a': 3, 'b': 1, 'c': 2 };
+ * var array = [0, 1, 2],
+ * object = { 'a': array, 'b': array, 'c': array };
*
- * _.map(['a', 'c'], _.propertyOf(object));
- * // => [3, 2]
+ * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
+ * // => [2, 0]
*
- * _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
- * // => ['b', 'c', 'a']
+ * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
+ * // => [2, 0]
*/
function propertyOf(object) {
- return function(key) {
- return object == null ? undefined : object[key];
+ return function(path) {
+ return baseGet(object, toPath(path), path + '');
};
}
/**
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to, but not including, `end`. If `end` is not specified it is
- * set to `start` with `start` then set to `0`. If `start` is less than `end`
+ * set to `start` with `start` then set to `0`. If `end` is less than `start`
* a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
* @category Utility
@@ -11286,19 +11639,19 @@
* // => [3, 6, 4]
*
* _.times(3, function(n) {
* mage.castSpell(n);
* });
- * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
+ * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
*
* _.times(3, function(n) {
* this.cast(n);
* }, mage);
* // => also invokes `mage.castSpell(n)` three times
*/
function times(n, iteratee, thisArg) {
- n = +n;
+ n = floor(n);
// Exit early to avoid a JSC JIT bug in Safari 8
// where `Array(0)` is treated as `Array(1)`.
if (n < 1 || !nativeIsFinite(n)) {
return [];
@@ -11353,11 +11706,11 @@
*
* _.add(6, 4);
* // => 10
*/
function add(augend, addend) {
- return augend + addend;
+ return (+augend || 0) + (+addend || 0);
}
/**
* Gets the maximum value of `collection`. If `collection` is empty or falsey
* `-Infinity` is returned. If an iteratee function is provided it is invoked
@@ -11579,10 +11932,12 @@
lodash.mapValues = mapValues;
lodash.matches = matches;
lodash.matchesProperty = matchesProperty;
lodash.memoize = memoize;
lodash.merge = merge;
+ lodash.method = method;
+ lodash.methodOf = methodOf;
lodash.mixin = mixin;
lodash.negate = negate;
lodash.omit = omit;
lodash.once = once;
lodash.pairs = pairs;
@@ -11599,10 +11954,11 @@
lodash.rearg = rearg;
lodash.reject = reject;
lodash.remove = remove;
lodash.rest = rest;
lodash.restParam = restParam;
+ lodash.set = set;
lodash.shuffle = shuffle;
lodash.slice = slice;
lodash.sortBy = sortBy;
lodash.sortByAll = sortByAll;
lodash.sortByOrder = sortByOrder;
@@ -11667,10 +12023,11 @@
lodash.findLast = findLast;
lodash.findLastIndex = findLastIndex;
lodash.findLastKey = findLastKey;
lodash.findWhere = findWhere;
lodash.first = first;
+ lodash.get = get;
lodash.has = has;
lodash.identity = identity;
lodash.includes = includes;
lodash.indexOf = indexOf;
lodash.inRange = inRange;
@@ -11855,11 +12212,11 @@
});
// 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));
};
});
@@ -11877,11 +12234,11 @@
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);
}
return result;
};
@@ -11908,10 +12265,10 @@
isLazy = value instanceof LazyWrapper,
iteratee = args[0],
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;
if (retUnwrapped && !chainAll) {
return onlyLazy