vendor/assets/javascripts/lodash.core.js in lodash-rails-4.17.15 vs vendor/assets/javascripts/lodash.core.js in lodash-rails-4.17.21

- old
+ new

@@ -11,45 +11,45 @@ /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.17.15'; + var VERSION = '4.17.21'; /** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /** Used to compose bitmasks for value comparisons. */ var COMPARE_PARTIAL_FLAG = 1, - COMPARE_UNORDERED_FLAG = 2; + COMPARE_UNORDERED_FLAG = 2; /** Used to compose bitmasks for function metadata. */ var WRAP_BIND_FLAG = 1, - WRAP_PARTIAL_FLAG = 32; + WRAP_PARTIAL_FLAG = 32; /** Used as references for various `Number` constants. */ var INFINITY = 1 / 0, - MAX_SAFE_INTEGER = 9007199254740991; + MAX_SAFE_INTEGER = 9007199254740991; /** `Object#toString` result references. */ var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - asyncTag = '[object AsyncFunction]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - funcTag = '[object Function]', - genTag = '[object GeneratorFunction]', - numberTag = '[object Number]', - objectTag = '[object Object]', - proxyTag = '[object Proxy]', - regexpTag = '[object RegExp]', - stringTag = '[object String]'; + arrayTag = '[object Array]', + asyncTag = '[object AsyncFunction]', + boolTag = '[object Boolean]', + dateTag = '[object Date]', + errorTag = '[object Error]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + numberTag = '[object Number]', + objectTag = '[object Object]', + proxyTag = '[object Proxy]', + regexpTag = '[object RegExp]', + stringTag = '[object String]'; /** Used to match HTML entities and HTML characters. */ var reUnescapedHtml = /[&<>"']/g, - reHasUnescapedHtml = RegExp(reUnescapedHtml.source); + reHasUnescapedHtml = RegExp(reUnescapedHtml.source); /** Used to detect unsigned integer values. */ var reIsUint = /^(?:0|[1-9]\d*)$/; /** Used to map characters to HTML entities. */ @@ -102,11 +102,11 @@ * @param {boolean} [fromRight] Specify iterating from right to left. * @returns {number} Returns the index of the matched value, else `-1`. */ function baseFindIndex(array, predicate, fromIndex, fromRight) { var length = array.length, - index = fromIndex + (fromRight ? 1 : -1); + index = fromIndex + (fromRight ? 1 : -1); while ((fromRight ? index-- : ++index < length)) { if (predicate(array[index], index, array)) { return index; } @@ -203,11 +203,11 @@ /*--------------------------------------------------------------------------*/ /** Used for built-in method references. */ var arrayProto = Array.prototype, - objectProto = Object.prototype; + objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; /** Used to generate unique IDs. */ @@ -223,16 +223,16 @@ /** Used to restore the original `_` reference in `_.noConflict`. */ var oldDash = root._; /** Built-in value references. */ var objectCreate = Object.create, - propertyIsEnumerable = objectProto.propertyIsEnumerable; + propertyIsEnumerable = objectProto.propertyIsEnumerable; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeIsFinite = root.isFinite, - nativeKeys = overArg(Object.keys, Object), - nativeMax = Math.max; + nativeKeys = overArg(Object.keys, Object), + nativeMax = Math.max; /*------------------------------------------------------------------------*/ /** * Creates a `lodash` object which wraps `value` to enable implicit method @@ -410,11 +410,11 @@ * @param {*} value The value to assign. */ function assignValue(object, key, value) { var objValue = object[key]; if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || - (value === undefined && !(key in object))) { + (value === undefined && !(key in object))) { baseAssignValue(object, key, value); } } /** @@ -485,22 +485,22 @@ * @param {Function} comparator The comparator used to compare values. * @returns {*} Returns the extremum value. */ function baseExtremum(array, iteratee, comparator) { var index = -1, - length = array.length; + length = array.length; while (++index < length) { var value = array[index], - current = iteratee(value); + current = iteratee(value); if (current != null && (computed === undefined - ? (current === current && !false) - : comparator(current, computed) - )) { + ? (current === current && !false) + : comparator(current, computed) + )) { var computed = current, - result = value; + result = value; } } return result; } @@ -533,11 +533,11 @@ * @param {Array} [result=[]] The initial result value. * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, depth, predicate, isStrict, result) { var index = -1, - length = array.length; + length = array.length; predicate || (predicate = isFlattenable); result || (result = []); while (++index < length) { @@ -678,20 +678,20 @@ * @param {Object} [stack] Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { var objIsArr = isArray(object), - othIsArr = isArray(other), - objTag = objIsArr ? arrayTag : baseGetTag(object), - othTag = othIsArr ? arrayTag : baseGetTag(other); + othIsArr = isArray(other), + objTag = objIsArr ? arrayTag : baseGetTag(object), + othTag = othIsArr ? arrayTag : baseGetTag(other); objTag = objTag == argsTag ? objectTag : objTag; othTag = othTag == argsTag ? objectTag : othTag; var objIsObj = objTag == objectTag, - othIsObj = othTag == objectTag, - isSameTag = objTag == othTag; + othIsObj = othTag == objectTag, + isSameTag = objTag == othTag; stack || (stack = []); var objStack = find(stack, function(entry) { return entry[0] == object; }); @@ -710,15 +710,15 @@ stack.pop(); return result; } if (!(bitmask & COMPARE_PARTIAL_FLAG)) { var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); if (objIsWrapped || othIsWrapped) { var objUnwrapped = objIsWrapped ? object.value() : object, - othUnwrapped = othIsWrapped ? other.value() : other; + othUnwrapped = othIsWrapped ? other.value() : other; var result = equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); stack.pop(); return result; } @@ -780,11 +780,11 @@ * @param {Function} iteratee The function invoked per iteration. * @returns {Array} Returns the new mapped array. */ function baseMap(collection, iteratee) { var index = -1, - result = isArrayLike(collection) ? Array(collection.length) : []; + result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value, key, collection) { result[++index] = iteratee(value, key, collection); }); return result; @@ -806,12 +806,12 @@ } object = Object(object); while (length--) { var key = props[length]; if (!(key in object && - baseIsEqual(source[key], object[key], COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG) - )) { + baseIsEqual(source[key], object[key], COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG) + )) { return false; } } return true; }; @@ -857,11 +857,11 @@ * @param {number} [end=array.length] The end position. * @returns {Array} Returns the slice of `array`. */ function baseSlice(array, start, end) { var index = -1, - length = array.length; + length = array.length; if (start < 0) { start = -start > length ? 0 : (length + start); } end = end > length ? length : end; @@ -935,31 +935,31 @@ * @returns {number} Returns the sort order indicator for `value`. */ function compareAscending(value, other) { if (value !== other) { var valIsDefined = value !== undefined, - valIsNull = value === null, - valIsReflexive = value === value, - valIsSymbol = false; + valIsNull = value === null, + valIsReflexive = value === value, + valIsSymbol = false; var othIsDefined = other !== undefined, - othIsNull = other === null, - othIsReflexive = other === other, - othIsSymbol = false; + othIsNull = other === null, + othIsReflexive = other === other, + othIsSymbol = false; if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || - (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || - (valIsNull && othIsDefined && othIsReflexive) || - (!valIsDefined && othIsReflexive) || - !valIsReflexive) { + (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || + (valIsNull && othIsDefined && othIsReflexive) || + (!valIsDefined && othIsReflexive) || + !valIsReflexive) { return 1; } if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || - (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || - (othIsNull && valIsDefined && valIsReflexive) || - (!othIsDefined && valIsReflexive) || - !othIsReflexive) { + (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || + (othIsNull && valIsDefined && valIsReflexive) || + (!othIsDefined && valIsReflexive) || + !othIsReflexive) { return -1; } } return 0; } @@ -977,11 +977,11 @@ function copyObject(source, props, object, customizer) { var isNew = !object; object || (object = {}); var index = -1, - length = props.length; + length = props.length; while (++index < length) { var key = props[index]; var newValue = customizer @@ -1008,12 +1008,12 @@ * @returns {Function} Returns the new assigner function. */ function createAssigner(assigner) { return baseRest(function(object, sources) { var index = -1, - length = sources.length, - customizer = length > 1 ? sources[length - 1] : undefined; + length = sources.length, + customizer = length > 1 ? sources[length - 1] : undefined; customizer = (assigner.length > 3 && typeof customizer == 'function') ? (length--, customizer) : undefined; @@ -1043,12 +1043,12 @@ } if (!isArrayLike(collection)) { return eachFunc(collection, iteratee); } var length = collection.length, - index = fromRight ? length : -1, - iterable = Object(collection); + index = fromRight ? length : -1, + iterable = Object(collection); while ((fromRight ? index-- : ++index < length)) { if (iteratee(iterable[index], index, iterable) === false) { break; } @@ -1065,13 +1065,13 @@ * @returns {Function} Returns the new base function. */ function createBaseFor(fromRight) { return function(object, iteratee, keysFunc) { var index = -1, - iterable = Object(object), - props = keysFunc(object), - length = props.length; + iterable = Object(object), + props = keysFunc(object), + length = props.length; while (length--) { var key = props[fromRight ? length : ++index]; if (iteratee(iterable[key], key, iterable) === false) { break; @@ -1094,11 +1094,11 @@ // Use a `switch` statement to work with class constructors. See // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist // for more details. var args = arguments; var thisBinding = baseCreate(Ctor.prototype), - result = Ctor.apply(thisBinding, args); + result = Ctor.apply(thisBinding, args); // Mimic the constructor's `return` behavior. // See https://es5.github.io/#x13.2.2 for more details. return isObject(result) ? result : thisBinding; }; @@ -1139,19 +1139,19 @@ function createPartial(func, bitmask, thisArg, partials) { if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } var isBind = bitmask & WRAP_BIND_FLAG, - Ctor = createCtor(func); + Ctor = createCtor(func); function wrapper() { var argsIndex = -1, - argsLength = arguments.length, - leftIndex = -1, - leftLength = partials.length, - args = Array(leftLength + argsLength), - fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + argsLength = arguments.length, + leftIndex = -1, + leftLength = partials.length, + args = Array(leftLength + argsLength), + fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; while (++leftIndex < leftLength) { args[leftIndex] = partials[leftIndex]; } while (argsLength--) { @@ -1175,24 +1175,30 @@ * @param {Object} stack Tracks traversed `array` and `other` objects. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. */ function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { var isPartial = bitmask & COMPARE_PARTIAL_FLAG, - arrLength = array.length, - othLength = other.length; + arrLength = array.length, + othLength = other.length; if (arrLength != othLength && !(isPartial && othLength > arrLength)) { return false; } + // Check that cyclic values are equal. + var arrStacked = stack.get(array); + var othStacked = stack.get(other); + if (arrStacked && othStacked) { + return arrStacked == other && othStacked == array; + } var index = -1, - result = true, - seen = (bitmask & COMPARE_UNORDERED_FLAG) ? [] : undefined; + result = true, + seen = (bitmask & COMPARE_UNORDERED_FLAG) ? [] : undefined; // Ignore non-index properties. while (++index < arrLength) { var arrValue = array[index], - othValue = other[index]; + othValue = other[index]; var compared; if (compared !== undefined) { if (compared) { continue; @@ -1201,22 +1207,22 @@ break; } // Recursively compare arrays (susceptible to call stack limits). if (seen) { if (!baseSome(other, function(othValue, othIndex) { - if (!indexOf(seen, othIndex) && - (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { - return seen.push(othIndex); - } - })) { + if (!indexOf(seen, othIndex) && + (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { + return seen.push(othIndex); + } + })) { result = false; break; } } else if (!( - arrValue === othValue || - equalFunc(arrValue, othValue, bitmask, customizer, stack) - )) { + arrValue === othValue || + equalFunc(arrValue, othValue, bitmask, customizer, stack) + )) { result = false; break; } } return result; @@ -1276,14 +1282,14 @@ * @param {Object} stack Tracks traversed `object` and `other` objects. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { var isPartial = bitmask & COMPARE_PARTIAL_FLAG, - objProps = keys(object), - objLength = objProps.length, - othProps = keys(other), - othLength = othProps.length; + objProps = keys(object), + objLength = objProps.length, + othProps = keys(other), + othLength = othProps.length; if (objLength != othLength && !isPartial) { return false; } var index = objLength; @@ -1291,38 +1297,44 @@ var key = objProps[index]; if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { return false; } } + // Check that cyclic values are equal. + var objStacked = stack.get(object); + var othStacked = stack.get(other); + if (objStacked && othStacked) { + return objStacked == other && othStacked == object; + } var result = true; var skipCtor = isPartial; while (++index < objLength) { key = objProps[index]; var objValue = object[key], - othValue = other[key]; + othValue = other[key]; var compared; // Recursively compare objects (susceptible to call stack limits). if (!(compared === undefined - ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) - : compared - )) { + ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) + : compared + )) { result = false; break; } skipCtor || (skipCtor = key == 'constructor'); } if (result && !skipCtor) { var objCtor = object.constructor, - othCtor = other.constructor; + othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal. if (objCtor != othCtor && - ('constructor' in object && 'constructor' in other) && - !(typeof objCtor == 'function' && objCtor instanceof objCtor && - typeof othCtor == 'function' && othCtor instanceof othCtor)) { + ('constructor' in object && 'constructor' in other) && + !(typeof objCtor == 'function' && objCtor instanceof objCtor && + typeof othCtor == 'function' && othCtor instanceof othCtor)) { result = false; } } return result; } @@ -1362,11 +1374,11 @@ length = length == null ? MAX_SAFE_INTEGER : length; return !!length && (type == 'number' || (type != 'symbol' && reIsUint.test(value))) && - (value > -1 && value % 1 == 0 && value < length); + (value > -1 && value % 1 == 0 && value < length); } /** * Checks if the given arguments are from an iteratee call. * @@ -1381,13 +1393,13 @@ if (!isObject(object)) { return false; } var type = typeof index; if (type == 'number' - ? (isArrayLike(object) && isIndex(index, object.length)) - : (type == 'string' && index in object) - ) { + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { return eq(object[index], value); } return false; } @@ -1432,13 +1444,13 @@ */ function overRest(func, start, transform) { start = nativeMax(start === undefined ? (func.length - 1) : start, 0); return function() { var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - array = Array(length); + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); while (++index < length) { array[index] = args[start + index]; } index = -1; @@ -1508,12 +1520,12 @@ var length = arguments.length; if (!length) { return []; } var args = Array(length - 1), - array = arguments[0], - index = length; + array = arguments[0], + index = length; while (index--) { args[index - 1] = arguments[index]; } return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); @@ -1655,11 +1667,11 @@ fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex; } else { fromIndex = 0; } var index = (fromIndex || 0) - 1, - isReflexive = value === value; + isReflexive = value === value; while (++index < length) { var other = array[index]; if ((isReflexive ? other === value : other !== other)) { return index; @@ -1933,10 +1945,14 @@ * // => objects for ['fred'] * * // The `_.property` iteratee shorthand. * _.filter(users, 'active'); * // => objects for ['barney'] + * + * // Combining several predicates using `_.overEvery` or `_.overSome`. + * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]])); + * // => objects for ['fred', 'barney'] */ function filter(collection, predicate) { return baseFilter(collection, baseIteratee(predicate)); } @@ -2186,19 +2202,19 @@ * @example * * var users = [ * { 'user': 'fred', 'age': 48 }, * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 }, + * { 'user': 'fred', 'age': 30 }, * { 'user': 'barney', 'age': 34 } * ]; * * _.sortBy(users, [function(o) { return o.user; }]); - * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]] * * _.sortBy(users, ['user', 'age']); - * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]] + * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]] */ function sortBy(collection, iteratee) { var index = 0; iteratee = baseIteratee(iteratee); @@ -2603,12 +2619,12 @@ * _.isEmpty({ 'a': 1 }); * // => false */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || - isFunction(value.splice) || isArguments(value))) { + (isArray(value) || isString(value) || + isFunction(value.splice) || isArguments(value))) { return !value.length; } return !nativeKeys(value).length; } @@ -3203,11 +3219,11 @@ while (++propsIndex < propsLength) { var key = props[propsIndex]; var value = object[key]; if (value === undefined || - (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { + (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { object[key] = source[key]; } } } @@ -3501,10 +3517,13 @@ * * Partial comparisons will match empty array and empty object `source` * values against any array or object value, respectively. See `_.isEqual` * for a list of supported value comparisons. * + * **Note:** Multiple values can be checked by combining several matchers + * using `_.overSome` + * * @static * @memberOf _ * @since 3.0.0 * @category Util * @param {Object} source The object of property values to match. @@ -3516,10 +3535,14 @@ * { 'a': 4, 'b': 5, 'c': 6 } * ]; * * _.filter(objects, _.matches({ 'a': 4, 'c': 6 })); * // => [{ 'a': 4, 'b': 5, 'c': 6 }] + * + * // Checking for several possible values + * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })])); + * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }] */ function matches(source) { return baseMatches(assign({}, source)); } @@ -3559,31 +3582,31 @@ * _('fred').vowels(); * // => ['e'] */ function mixin(object, source, options) { var props = keys(source), - methodNames = baseFunctions(source, props); + methodNames = baseFunctions(source, props); if (options == null && - !(isObject(source) && (methodNames.length || !props.length))) { + !(isObject(source) && (methodNames.length || !props.length))) { options = source; source = object; object = this; methodNames = baseFunctions(source, keys(source)); } var chain = !(isObject(options) && 'chain' in options) || !!options.chain, - isFunc = isFunction(object); + isFunc = isFunction(object); baseEach(methodNames, function(methodName) { var func = source[methodName]; object[methodName] = func; if (isFunc) { object.prototype[methodName] = function() { var chainAll = this.__chain__; if (chain || chainAll) { var result = object(this.__wrapped__), - actions = result.__actions__ = copyArray(this.__actions__); + actions = result.__actions__ = copyArray(this.__actions__); actions.push({ 'func': func, 'args': arguments, 'thisArg': object }); result.__chain__ = chainAll; return result; } @@ -3804,11 +3827,11 @@ lodash.VERSION = VERSION; // Add `Array` methods to `lodash.prototype`. baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName], - chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', - retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName); + chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', + retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName); lodash.prototype[methodName] = function() { var args = arguments; if (retUnwrapped && !this.__chain__) { var value = this.value();