|
(function () { 'use strict'; |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var INFINITY = 1 / 0; |
|
var MAX_INTEGER = 1e308; |
|
/** |
|
* Converts `value` to an integer. |
|
* |
|
* **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to convert. |
|
* @returns {number} Returns the converted integer. |
|
* @example |
|
* |
|
* _.toInteger('3.14'); |
|
* // => 3 |
|
* |
|
* _.toInteger(NaN); |
|
* // => 0 |
|
* |
|
* _.toInteger(-Infinity) |
|
* // => -1e308 |
|
*/ |
|
function toInteger(value) { |
|
if (value === INFINITY || value === -INFINITY) { |
|
return (value < 0 ? -1 : 1) * MAX_INTEGER; |
|
} |
|
value = +value; |
|
var remainder = value % 1; |
|
return value === value ? (remainder ? value - remainder : value) : 0; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.slice` without an iteratee call guard. |
|
* |
|
* @private |
|
* @param {Array} array The array to slice. |
|
* @param {number} [start=0] The start position. |
|
* @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; |
|
|
|
start = start == null ? 0 : toInteger(start); |
|
if (start < 0) { |
|
start = -start > length ? 0 : (length + start); |
|
} |
|
end = (end === undefined || end > length) ? length : toInteger(end); |
|
if (end < 0) { |
|
end += length; |
|
} |
|
length = start > end ? 0 : ((end - start) >>> 0); |
|
start >>>= 0; |
|
|
|
var result = Array(length); |
|
while (++index < length) { |
|
result[index] = array[index + start]; |
|
} |
|
return result; |
|
} |
|
|
|
var nativeCeil = Math.ceil; |
|
var nativeMax = Math.max; |
|
/** |
|
* Creates an array of elements split into groups the length of `size`. |
|
* If `collection` can't be split evenly, the final chunk will be the remaining |
|
* elements. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to process. |
|
* @param {number} [size=0] The length of each chunk. |
|
* @returns {Array} Returns the new array containing chunks. |
|
* @example |
|
* |
|
* _.chunk(['a', 'b', 'c', 'd'], 2); |
|
* // => [['a', 'b'], ['c', 'd']] |
|
* |
|
* _.chunk(['a', 'b', 'c', 'd'], 3); |
|
* // => [['a', 'b', 'c'], ['d']] |
|
*/ |
|
function chunk(array, size) { |
|
size = nativeMax(toInteger(size), 0); |
|
|
|
var length = array ? array.length : 0; |
|
if (!length || size < 1) { |
|
return []; |
|
} |
|
var index = 0, |
|
resIndex = -1, |
|
result = Array(nativeCeil(length / size)); |
|
|
|
while (index < length) { |
|
result[++resIndex] = baseSlice(array, index, (index += size)); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Checks if `value` is classified as an `Array` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type Function |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isArray([1, 2, 3]); |
|
* // => true |
|
* |
|
* _.isArray(document.body.children); |
|
* // => false |
|
* |
|
* _.isArray('abc'); |
|
* // => false |
|
* |
|
* _.isArray(_.noop); |
|
* // => false |
|
*/ |
|
var isArray = Array.isArray; |
|
|
|
/** |
|
* The inverse of `_.pairs`; this method returns an object composed from arrays |
|
* of property names and values. Provide either a single two dimensional array, |
|
* e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names |
|
* and one of corresponding values. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} props The property names. |
|
* @param {Array} [values=[]] The property values. |
|
* @returns {Object} Returns the new object. |
|
* @example |
|
* |
|
* _.zipObject([['fred', 30], ['barney', 40]]); |
|
* // => { 'fred': 30, 'barney': 40 } |
|
* |
|
* _.zipObject(['fred', 'barney'], [30, 40]); |
|
* // => { 'fred': 30, 'barney': 40 } |
|
*/ |
|
function zipObject(props, values) { |
|
var index = -1, |
|
length = props ? props.length : 0, |
|
result = {}; |
|
|
|
if (length && !values && !isArray(props[0])) { |
|
values = []; |
|
} |
|
while (++index < length) { |
|
var key = props[index]; |
|
if (values) { |
|
result[key] = values[index]; |
|
} else if (key) { |
|
result[key[0]] = key[1]; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Adds two numbers. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {number} augend The first number to add. |
|
* @param {number} addend The second number to add. |
|
* @returns {number} Returns the sum. |
|
* @example |
|
* |
|
* _.add(6, 4); |
|
* // => 10 |
|
*/ |
|
function add(augend, addend) { |
|
var result; |
|
if (augend === augend && augend != null) { |
|
result = augend; |
|
} |
|
if (addend === addend && addend != null) { |
|
result = result === undefined ? addend : (result + addend); |
|
} |
|
return result; |
|
} |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT = 'Expected a function'; |
|
|
|
/** |
|
* The opposite of `_.before`; this method creates a function that invokes |
|
* `func` once it's called `n` or more times. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {number} n The number of calls before `func` is invoked. |
|
* @param {Function} func The function to restrict. |
|
* @returns {Function} Returns the new restricted function. |
|
* @example |
|
* |
|
* var saves = ['profile', 'settings']; |
|
* |
|
* var done = _.after(saves.length, function() { |
|
* console.log('done saving!'); |
|
* }); |
|
* |
|
* _.forEach(saves, function(type) { |
|
* asyncSave({ 'type': type, 'complete': done }); |
|
* }); |
|
* // => logs 'done saving!' after the two async saves have completed |
|
*/ |
|
function after(n, func) { |
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT); |
|
} |
|
n = toInteger(n); |
|
return function() { |
|
if (--n < 1) { |
|
return func.apply(this, arguments); |
|
} |
|
}; |
|
} |
|
|
|
/** |
|
* This method returns the first argument provided to it. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {*} value Any value. |
|
* @returns {*} Returns `value`. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred' }; |
|
* |
|
* _.identity(object) === object; |
|
* // => true |
|
*/ |
|
function identity(value) { |
|
return value; |
|
} |
|
|
|
/** |
|
* Checks if `value` is a global object. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @returns {null|Object} Returns `value` if it's a global object, else `null`. |
|
*/ |
|
function checkGlobal(value) { |
|
return (value && value.Object === Object) ? value : null; |
|
} |
|
|
|
/** Used to determine if values are of the language type `Object`. */ |
|
var objectTypes = { |
|
'function': true, |
|
'object': true |
|
}; |
|
|
|
/** Detect free variable `exports`. */ |
|
var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null; |
|
|
|
/** Detect free variable `module`. */ |
|
var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null; |
|
|
|
/** Detect free variable `global` from Node.js. */ |
|
var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global); |
|
|
|
/** Detect free variable `self`. */ |
|
var freeSelf = checkGlobal(objectTypes[typeof self] && self); |
|
|
|
/** Detect free variable `window`. */ |
|
var freeWindow = checkGlobal(objectTypes[typeof window] && window); |
|
|
|
/** Detect `this` as the global object. */ |
|
var thisGlobal = checkGlobal(objectTypes[typeof this] && this); |
|
|
|
/** |
|
* Used as a reference to the global object. |
|
* |
|
* The `this` value is used if it's the global object to avoid Greasemonkey's |
|
* restricted `window` object, otherwise the `window` object is used. |
|
*/ |
|
var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')(); |
|
|
|
/** |
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. |
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`. |
|
* @example |
|
* |
|
* _.isObject({}); |
|
* // => true |
|
* |
|
* _.isObject([1, 2, 3]); |
|
* // => true |
|
* |
|
* _.isObject(_.noop); |
|
* // => true |
|
* |
|
* _.isObject(null); |
|
* // => false |
|
*/ |
|
function isObject(value) { |
|
// Avoid a V8 JIT bug in Chrome 19-20. |
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details. |
|
var type = typeof value; |
|
return !!value && (type == 'object' || type == 'function'); |
|
} |
|
|
|
var funcTag = '[object Function]'; |
|
var genTag = '[object GeneratorFunction]'; |
|
/** Used for built-in method references. */ |
|
var objectProto$7 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$4 = objectProto$7.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a `Function` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isFunction(_); |
|
* // => true |
|
* |
|
* _.isFunction(/abc/); |
|
* // => false |
|
*/ |
|
function isFunction(value) { |
|
// The use of `Object#toString` avoids issues with the `typeof` operator |
|
// in Safari 8 which returns 'object' for typed array constructors, and |
|
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. |
|
var tag = isObject(value) ? objToString$4.call(value) : ''; |
|
return tag == funcTag || tag == genTag; |
|
} |
|
|
|
/** |
|
* Checks if `value` is a host object in IE < 9. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a host object, else `false`. |
|
*/ |
|
function isHostObject(value) { |
|
// Many host objects are `Object` objects that can coerce to strings |
|
// despite having improperly defined `toString` methods. |
|
var result = false; |
|
if (value != null && typeof value.toString != 'function') { |
|
try { |
|
result = !!(value + ''); |
|
} catch (e) {} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Checks if `value` is object-like. A value is object-like if it's not `null` |
|
* and has a `typeof` result of "object". |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. |
|
* @example |
|
* |
|
* _.isObjectLike({}); |
|
* // => true |
|
* |
|
* _.isObjectLike([1, 2, 3]); |
|
* // => true |
|
* |
|
* _.isObjectLike(_.noop); |
|
* // => false |
|
* |
|
* _.isObjectLike(null); |
|
* // => false |
|
*/ |
|
function isObjectLike(value) { |
|
return !!value && typeof value == 'object'; |
|
} |
|
|
|
/** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */ |
|
var reRegExpChar$1 = /[\\^$.*+?()[\]{}|]/g; |
|
|
|
/** Used to detect host constructors (Safari > 5). */ |
|
var reIsHostCtor = /^\[object .+?Constructor\]$/; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$8 = Object.prototype; |
|
|
|
/** Used to resolve the decompiled source of functions. */ |
|
var fnToString = Function.prototype.toString; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$4 = objectProto$8.hasOwnProperty; |
|
|
|
/** Used to detect if a method is native. */ |
|
var reIsNative = RegExp('^' + |
|
fnToString.call(hasOwnProperty$4).replace(reRegExpChar$1, '\\$&') |
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' |
|
); |
|
|
|
/** |
|
* Checks if `value` is a native function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a native function, else `false`. |
|
* @example |
|
* |
|
* _.isNative(Array.prototype.push); |
|
* // => true |
|
* |
|
* _.isNative(_); |
|
* // => false |
|
*/ |
|
function isNative(value) { |
|
if (value == null) { |
|
return false; |
|
} |
|
if (isFunction(value)) { |
|
return reIsNative.test(fnToString.call(value)); |
|
} |
|
return isObjectLike(value) && |
|
(isHostObject(value) ? reIsNative : reIsHostCtor).test(value); |
|
} |
|
|
|
/** |
|
* Gets the native function at `key` of `object`. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {string} key The key of the method to get. |
|
* @returns {*} Returns the function if it's native, else `undefined`. |
|
*/ |
|
function getNative(object, key) { |
|
var value = object == null ? undefined : object[key]; |
|
return isNative(value) ? value : undefined; |
|
} |
|
|
|
/* Built-in method references that are verified to be native. */ |
|
var WeakMap = getNative(root, 'WeakMap'); |
|
|
|
/** Used to store function metadata. */ |
|
var metaMap = WeakMap && new WeakMap; |
|
|
|
/** |
|
* The base implementation of `setData` without support for hot loop detection. |
|
* |
|
* @private |
|
* @param {Function} func The function to associate metadata with. |
|
* @param {*} data The metadata. |
|
* @returns {Function} Returns `func`. |
|
*/ |
|
var baseSetData = !metaMap ? identity : function(func, data) { |
|
metaMap.set(func, data); |
|
return func; |
|
}; |
|
|
|
/** |
|
* The base implementation of `_.create` without support for assigning |
|
* properties to the created object. |
|
* |
|
* @private |
|
* @param {Object} prototype The object to inherit from. |
|
* @returns {Object} Returns the new object. |
|
*/ |
|
var baseCreate = (function() { |
|
function object() {} |
|
return function(prototype) { |
|
if (isObject(prototype)) { |
|
object.prototype = prototype; |
|
var result = new object; |
|
object.prototype = undefined; |
|
} |
|
return result || {}; |
|
}; |
|
}()); |
|
|
|
/** |
|
* Creates a function that produces an instance of `Ctor` regardless of |
|
* whether it was invoked as part of a `new` expression or by `call` or `apply`. |
|
* |
|
* @private |
|
* @param {Function} Ctor The constructor to wrap. |
|
* @returns {Function} Returns the new wrapped function. |
|
*/ |
|
function createCtorWrapper(Ctor) { |
|
return function() { |
|
// Use a `switch` statement to work with class constructors. |
|
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist |
|
// for more details. |
|
var args = arguments; |
|
switch (args.length) { |
|
case 0: return new Ctor; |
|
case 1: return new Ctor(args[0]); |
|
case 2: return new Ctor(args[0], args[1]); |
|
case 3: return new Ctor(args[0], args[1], args[2]); |
|
case 4: return new Ctor(args[0], args[1], args[2], args[3]); |
|
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); |
|
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); |
|
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); |
|
} |
|
var thisBinding = baseCreate(Ctor.prototype), |
|
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; |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that wraps `func` and invokes it with the `this` |
|
* binding of `thisArg`. |
|
* |
|
* @private |
|
* @param {Function} func The function to bind. |
|
* @param {*} [thisArg] The `this` binding of `func`. |
|
* @returns {Function} Returns the new bound function. |
|
*/ |
|
function createBindWrapper(func, thisArg) { |
|
var Ctor = createCtorWrapper(func); |
|
|
|
function wrapper() { |
|
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; |
|
return fn.apply(thisArg, arguments); |
|
} |
|
return wrapper; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$12 = Math.max; |
|
|
|
/** |
|
* Creates an array that is the composition of partially applied arguments, |
|
* placeholders, and provided arguments into a single array of arguments. |
|
* |
|
* @private |
|
* @param {Array|Object} args The provided arguments. |
|
* @param {Array} partials The arguments to prepend to those provided. |
|
* @param {Array} holders The `partials` placeholder indexes. |
|
* @returns {Array} Returns the new array of composed arguments. |
|
*/ |
|
function composeArgs(args, partials, holders) { |
|
var holdersLength = holders.length, |
|
argsIndex = -1, |
|
argsLength = nativeMax$12(args.length - holdersLength, 0), |
|
leftIndex = -1, |
|
leftLength = partials.length, |
|
result = Array(leftLength + argsLength); |
|
|
|
while (++leftIndex < leftLength) { |
|
result[leftIndex] = partials[leftIndex]; |
|
} |
|
while (++argsIndex < holdersLength) { |
|
result[holders[argsIndex]] = args[argsIndex]; |
|
} |
|
while (argsLength--) { |
|
result[leftIndex++] = args[argsIndex++]; |
|
} |
|
return result; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$13 = Math.max; |
|
|
|
/** |
|
* This function is like `composeArgs` except that the arguments composition |
|
* is tailored for `_.partialRight`. |
|
* |
|
* @private |
|
* @param {Array|Object} args The provided arguments. |
|
* @param {Array} partials The arguments to append to those provided. |
|
* @param {Array} holders The `partials` placeholder indexes. |
|
* @returns {Array} Returns the new array of composed arguments. |
|
*/ |
|
function composeArgsRight(args, partials, holders) { |
|
var holdersIndex = -1, |
|
holdersLength = holders.length, |
|
argsIndex = -1, |
|
argsLength = nativeMax$13(args.length - holdersLength, 0), |
|
rightIndex = -1, |
|
rightLength = partials.length, |
|
result = Array(argsLength + rightLength); |
|
|
|
while (++argsIndex < argsLength) { |
|
result[argsIndex] = args[argsIndex]; |
|
} |
|
var offset = argsIndex; |
|
while (++rightIndex < rightLength) { |
|
result[offset + rightIndex] = partials[rightIndex]; |
|
} |
|
while (++holdersIndex < holdersLength) { |
|
result[offset + holders[holdersIndex]] = args[argsIndex++]; |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Copies the values of `source` to `array`. |
|
* |
|
* @private |
|
* @param {Array} source The array to copy values from. |
|
* @param {Array} [array=[]] The array to copy values to. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function copyArray(source, array) { |
|
var index = -1, |
|
length = source.length; |
|
|
|
array || (array = Array(length)); |
|
while (++index < length) { |
|
array[index] = source[index]; |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* The function whose prototype all chaining wrappers inherit from. |
|
* |
|
* @private |
|
*/ |
|
function baseLodash() { |
|
// No operation performed. |
|
} |
|
|
|
/** Used as references for the maximum length and index of an array. */ |
|
var MAX_ARRAY_LENGTH$3 = 4294967295; |
|
|
|
/** |
|
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. |
|
* |
|
* @private |
|
* @param {*} value The value to wrap. |
|
*/ |
|
function LazyWrapper(value) { |
|
this.__wrapped__ = value; |
|
this.__actions__ = []; |
|
this.__dir__ = 1; |
|
this.__filtered__ = false; |
|
this.__iteratees__ = []; |
|
this.__takeCount__ = MAX_ARRAY_LENGTH$3; |
|
this.__views__ = []; |
|
} |
|
|
|
LazyWrapper.prototype = baseCreate(baseLodash.prototype); |
|
LazyWrapper.prototype.constructor = LazyWrapper; |
|
|
|
/** |
|
* A no-operation function that returns `undefined` regardless of the |
|
* arguments it receives. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @example |
|
* |
|
* var object = { 'user': 'fred' }; |
|
* |
|
* _.noop(object) === undefined; |
|
* // => true |
|
*/ |
|
function noop() { |
|
// No operation performed. |
|
} |
|
|
|
/** |
|
* Gets metadata for `func`. |
|
* |
|
* @private |
|
* @param {Function} func The function to query. |
|
* @returns {*} Returns the metadata for `func`. |
|
*/ |
|
var getData = !metaMap ? noop : function(func) { |
|
return metaMap.get(func); |
|
}; |
|
|
|
/** Used to lookup unminified function names. */ |
|
var realNames = {}; |
|
|
|
/** |
|
* Gets the name of `func`. |
|
* |
|
* @private |
|
* @param {Function} func The function to query. |
|
* @returns {string} Returns the function name. |
|
*/ |
|
function getFuncName(func) { |
|
var result = (func.name + ''), |
|
array = realNames[result], |
|
length = array ? array.length : 0; |
|
|
|
while (length--) { |
|
var data = array[length], |
|
otherFunc = data.func; |
|
if (otherFunc == null || otherFunc == func) { |
|
return data.name; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base constructor for creating `lodash` wrapper objects. |
|
* |
|
* @private |
|
* @param {*} value The value to wrap. |
|
* @param {boolean} [chainAll] Enable chaining for all wrapper methods. |
|
*/ |
|
function LodashWrapper(value, chainAll) { |
|
this.__wrapped__ = value; |
|
this.__actions__ = []; |
|
this.__chain__ = !!chainAll; |
|
this.__index__ = 0; |
|
this.__values__ = undefined; |
|
} |
|
|
|
LodashWrapper.prototype = baseCreate(baseLodash.prototype); |
|
LodashWrapper.prototype.constructor = LodashWrapper; |
|
|
|
/** |
|
* Creates a clone of `wrapper`. |
|
* |
|
* @private |
|
* @param {Object} wrapper The wrapper to clone. |
|
* @returns {Object} Returns the cloned wrapper. |
|
*/ |
|
function wrapperClone(wrapper) { |
|
if (wrapper instanceof LazyWrapper) { |
|
return wrapper.clone(); |
|
} |
|
var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); |
|
result.__actions__ = copyArray(wrapper.__actions__); |
|
result.__index__ = wrapper.__index__; |
|
result.__values__ = wrapper.__values__; |
|
return result; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$15 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$6 = objectProto$15.hasOwnProperty; |
|
|
|
/** |
|
* Creates a `lodash` object which wraps `value` to enable implicit method |
|
* chaining. Methods that operate on and return arrays, collections, and |
|
* functions can be chained together. Methods that retrieve a single value or |
|
* may return a primitive value will automatically end the chain sequence and |
|
* return the unwrapped value. Otherwise, the value must be unwrapped with |
|
* `_#value`. |
|
* |
|
* Explicit chaining, which must be unwrapped with `_#value` in all cases, |
|
* may be enabled using `_.chain`. |
|
* |
|
* The execution of chained methods is lazy, that is, execution is deferred |
|
* until `_#value` is implicitly or explicitly called. |
|
* |
|
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut |
|
* fusion is an optimization strategy which merge iteratee calls; this can help |
|
* to avoid the creation of intermediate data structures and greatly reduce the |
|
* number of iteratee executions. |
|
* |
|
* Chaining is supported in custom builds as long as the `_#value` method is |
|
* directly or indirectly included in the build. |
|
* |
|
* In addition to lodash methods, wrappers have `Array` and `String` methods. |
|
* |
|
* The wrapper `Array` methods are: |
|
* `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` |
|
* |
|
* The wrapper `String` methods are: |
|
* `replace` and `split` |
|
* |
|
* The wrapper methods that support shortcut fusion are: |
|
* `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, `findLast`, |
|
* `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, `tail`, |
|
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` |
|
* |
|
* The chainable wrapper methods are: |
|
* `after`, `ary`, `assign`, `assignWith`, `at`, `before`, `bind`, `bindAll`, |
|
* `bindKey`, `chain`, `chunk`, `commit`, `compact`, `concat`, `conforms`, |
|
* `conj`, `constant`, `countBy`, `create`, `curry`, `debounce`, `defaults`, |
|
* `defaultsDeep`, `defer`, `delay`, `difference`, `differenceBy`, `disj`, |
|
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, |
|
* `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`, `flowRight`, |
|
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, |
|
* `functions`, `groupBy`, `initial`, `intersection`, `intersectionBy`, |
|
* `invert`, `invoke`, `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, |
|
* `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, |
|
* `method`, `methodOf`, `mixin`, `modArgs`, `modArgsSet', 'negate`, `nthArg`, |
|
* `omit`, `omitBy`, `once`, `pairs`, `partial`, `partialRight`, `partition`, |
|
* `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, |
|
* `pullAllBy`, `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, |
|
* `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, |
|
* `sortByOrder`, `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`, |
|
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPath`, |
|
* `toPlainObject`, `transform`, `union`, `unionBy`, `uniq`, `uniqBy`, `unset`, |
|
* `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, |
|
* `xor`, `xorBy`, `zip`, `zipObject`, and `zipWith` |
|
* |
|
* The wrapper methods that are **not** chainable by default are: |
|
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, |
|
* `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`, |
|
* `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, |
|
* `findLastIndex`, `findLastKey`, `floor`, `get`, `gt`, `gte`, `has`, `hasIn`, |
|
* `head`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`, |
|
* `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isDate`, `isElement`, |
|
* `isEmpty`, `isEqual`, `isEqualWith`, `isError`, `isFinite`, `isFunction`, |
|
* `isInteger`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, |
|
* `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, |
|
* `isSafeInteger`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`, |
|
* `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `min`, |
|
* `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, |
|
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`, `runInContext`, |
|
* `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, |
|
* `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `sum`, |
|
* `sumBy`, `template`, `toLower`, `toInteger`, `toSafeInteger`, `toString`, |
|
* `toUpper`, `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, |
|
* `upperCase`, `upperFirst`, `value`, and `words` |
|
* |
|
* @name _ |
|
* @constructor |
|
* @category Chain |
|
* @param {*} value The value to wrap in a `lodash` instance. |
|
* @returns {Object} Returns the new `lodash` wrapper instance. |
|
* @example |
|
* |
|
* function square(n) { |
|
* return n * n; |
|
* } |
|
* |
|
* var wrapped = _([1, 2, 3]); |
|
* |
|
* // returns an unwrapped value |
|
* wrapped.reduce(_.add); |
|
* // => 6 |
|
* |
|
* // returns a wrapped value |
|
* var squares = wrapped.map(square); |
|
* |
|
* _.isArray(squares); |
|
* // => false |
|
* |
|
* _.isArray(squares.value()); |
|
* // => true |
|
*/ |
|
function lodash(value) { |
|
if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { |
|
if (value instanceof LodashWrapper) { |
|
return value; |
|
} |
|
if (hasOwnProperty$6.call(value, '__wrapped__')) { |
|
return wrapperClone(value); |
|
} |
|
} |
|
return new LodashWrapper(value); |
|
} |
|
|
|
// Ensure wrappers are instances of `baseLodash`. |
|
lodash.prototype = baseLodash.prototype; |
|
|
|
/** |
|
* 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`. |
|
*/ |
|
function isLaziable(func) { |
|
var funcName = getFuncName(func), |
|
other = lodash[funcName]; |
|
|
|
if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { |
|
return false; |
|
} |
|
if (func === other) { |
|
return true; |
|
} |
|
var data = getData(other); |
|
return !!data && func === data[0]; |
|
} |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var MAX_SAFE_INTEGER$5 = 9007199254740991; |
|
|
|
/** Used to detect unsigned integer values. */ |
|
var reIsUint = /^\d+$/; |
|
|
|
/** |
|
* 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. |
|
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`. |
|
*/ |
|
function isIndex(value, length) { |
|
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; |
|
length = length == null ? MAX_SAFE_INTEGER$5 : length; |
|
return value > -1 && value % 1 == 0 && value < length; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMin$9 = Math.min; |
|
|
|
/** |
|
* Reorder `array` according to the specified indexes where the element at |
|
* the first index is assigned as the first element, the element at |
|
* the second index is assigned as the second element, and so on. |
|
* |
|
* @private |
|
* @param {Array} array The array to reorder. |
|
* @param {Array} indexes The arranged array indexes. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function reorder(array, indexes) { |
|
var arrLength = array.length, |
|
length = nativeMin$9(indexes.length, arrLength), |
|
oldArray = copyArray(array); |
|
|
|
while (length--) { |
|
var index = indexes[length]; |
|
array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined; |
|
} |
|
return array; |
|
} |
|
|
|
/** Used as the internal argument placeholder. */ |
|
var PLACEHOLDER = '__lodash_placeholder__'; |
|
|
|
/** |
|
* Replaces all `placeholder` elements in `array` with an internal placeholder |
|
* and returns an array of their indexes. |
|
* |
|
* @private |
|
* @param {Array} array The array to modify. |
|
* @param {*} placeholder The placeholder to replace. |
|
* @returns {Array} Returns the new array of placeholder indexes. |
|
*/ |
|
function replaceHolders(array, placeholder) { |
|
var index = -1, |
|
length = array.length, |
|
resIndex = -1, |
|
result = []; |
|
|
|
while (++index < length) { |
|
if (array[index] === placeholder) { |
|
array[index] = PLACEHOLDER; |
|
result[++resIndex] = index; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the timestamp of the number of milliseconds that have elapsed since |
|
* the Unix epoch (1 January 1970 00:00:00 UTC). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type Function |
|
* @category Date |
|
* @returns {number} Returns the timestamp. |
|
* @example |
|
* |
|
* _.defer(function(stamp) { |
|
* console.log(_.now() - stamp); |
|
* }, _.now()); |
|
* // => logs the number of milliseconds it took for the deferred function to be invoked |
|
*/ |
|
var now = Date.now; |
|
|
|
var HOT_COUNT = 150; |
|
var HOT_SPAN = 16; |
|
/** |
|
* Sets metadata for `func`. |
|
* |
|
* **Note:** If this function becomes hot, i.e. is invoked a lot in a short |
|
* period of time, it will trip its breaker and transition to an identity function |
|
* to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070) |
|
* for more details. |
|
* |
|
* @private |
|
* @param {Function} func The function to associate metadata with. |
|
* @param {*} data The metadata. |
|
* @returns {Function} Returns `func`. |
|
*/ |
|
var setData = (function() { |
|
var count = 0, |
|
lastCalled = 0; |
|
|
|
return function(key, value) { |
|
var stamp = now(), |
|
remaining = HOT_SPAN - (stamp - lastCalled); |
|
|
|
lastCalled = stamp; |
|
if (remaining > 0) { |
|
if (++count >= HOT_COUNT) { |
|
return key; |
|
} |
|
} else { |
|
count = 0; |
|
} |
|
return baseSetData(key, value); |
|
}; |
|
}()); |
|
|
|
var BIND_FLAG$3 = 1; |
|
var BIND_KEY_FLAG$3 = 2; |
|
var CURRY_BOUND_FLAG = 4; |
|
var CURRY_FLAG$2 = 8; |
|
var CURRY_RIGHT_FLAG$1 = 16; |
|
var PARTIAL_FLAG$5 = 32; |
|
var PARTIAL_RIGHT_FLAG$2 = 64; |
|
var ARY_FLAG$2 = 128; |
|
var FLIP_FLAG$1 = 512; |
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$11 = Math.max; |
|
|
|
/** |
|
* Creates a function that wraps `func` and invokes it with optional `this` |
|
* binding of, partial application, and currying. |
|
* |
|
* @private |
|
* @param {Function|string} func The function or method name to reference. |
|
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. |
|
* @param {*} [thisArg] The `this` binding of `func`. |
|
* @param {Array} [partials] The arguments to prepend to those provided to the new function. |
|
* @param {Array} [holders] The `partials` placeholder indexes. |
|
* @param {Array} [partialsRight] The arguments to append to those provided to the new function. |
|
* @param {Array} [holdersRight] The `partialsRight` placeholder indexes. |
|
* @param {Array} [argPos] The argument positions of the new function. |
|
* @param {number} [ary] The arity cap of `func`. |
|
* @param {number} [arity] The arity of `func`. |
|
* @returns {Function} Returns the new wrapped function. |
|
*/ |
|
function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { |
|
var isAry = bitmask & ARY_FLAG$2, |
|
isBind = bitmask & BIND_FLAG$3, |
|
isBindKey = bitmask & BIND_KEY_FLAG$3, |
|
isCurry = bitmask & CURRY_FLAG$2, |
|
isCurryBound = bitmask & CURRY_BOUND_FLAG, |
|
isCurryRight = bitmask & CURRY_RIGHT_FLAG$1, |
|
isFlip = bitmask & FLIP_FLAG$1, |
|
Ctor = isBindKey ? undefined : createCtorWrapper(func); |
|
|
|
function wrapper() { |
|
// Avoid `arguments` object use disqualifying optimizations by |
|
// converting it to an array before providing it to other functions. |
|
var length = arguments.length, |
|
index = length, |
|
args = Array(length); |
|
|
|
while (index--) { |
|
args[index] = arguments[index]; |
|
} |
|
if (partials) { |
|
args = composeArgs(args, partials, holders); |
|
} |
|
if (partialsRight) { |
|
args = composeArgsRight(args, partialsRight, holdersRight); |
|
} |
|
if (isCurry || isCurryRight) { |
|
var placeholder = wrapper.placeholder, |
|
argsHolders = replaceHolders(args, placeholder); |
|
|
|
length -= argsHolders.length; |
|
if (length < arity) { |
|
var newArgPos = argPos ? copyArray(argPos) : undefined, |
|
newArity = nativeMax$11(arity - length, 0), |
|
newsHolders = isCurry ? argsHolders : undefined, |
|
newHoldersRight = isCurry ? undefined : argsHolders, |
|
newPartials = isCurry ? args : undefined, |
|
newPartialsRight = isCurry ? undefined : args; |
|
|
|
bitmask |= (isCurry ? PARTIAL_FLAG$5 : PARTIAL_RIGHT_FLAG$2); |
|
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG$2 : PARTIAL_FLAG$5); |
|
|
|
if (!isCurryBound) { |
|
bitmask &= ~(BIND_FLAG$3 | BIND_KEY_FLAG$3); |
|
} |
|
var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity], |
|
result = createHybridWrapper.apply(undefined, newData); |
|
|
|
if (isLaziable(func)) { |
|
setData(result, newData); |
|
} |
|
result.placeholder = placeholder; |
|
return result; |
|
} |
|
} |
|
var thisBinding = isBind ? thisArg : this, |
|
fn = isBindKey ? thisBinding[func] : func; |
|
|
|
if (argPos) { |
|
args = reorder(args, argPos); |
|
} else if (isFlip && args.length > 1) { |
|
args.reverse(); |
|
} |
|
if (isAry && ary < args.length) { |
|
args.length = ary; |
|
} |
|
if (this && this !== root && this instanceof wrapper) { |
|
fn = Ctor || createCtorWrapper(func); |
|
} |
|
return fn.apply(thisBinding, args); |
|
} |
|
return wrapper; |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var BIND_FLAG$4 = 1; |
|
|
|
/** |
|
* Creates a function that wraps `func` and invokes it with the optional `this` |
|
* binding of `thisArg` and the `partials` prepended to those provided to |
|
* the wrapper. |
|
* |
|
* @private |
|
* @param {Function} func The function to partially apply arguments to. |
|
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details. |
|
* @param {*} thisArg The `this` binding of `func`. |
|
* @param {Array} partials The arguments to prepend to those provided to the new function. |
|
* @returns {Function} Returns the new bound function. |
|
*/ |
|
function createPartialWrapper(func, bitmask, thisArg, partials) { |
|
var isBind = bitmask & BIND_FLAG$4, |
|
Ctor = createCtorWrapper(func); |
|
|
|
function wrapper() { |
|
// Avoid `arguments` object use disqualifying optimizations by |
|
// converting it to an array before providing it `func`. |
|
var argsIndex = -1, |
|
argsLength = arguments.length, |
|
leftIndex = -1, |
|
leftLength = partials.length, |
|
args = Array(leftLength + argsLength); |
|
|
|
while (++leftIndex < leftLength) { |
|
args[leftIndex] = partials[leftIndex]; |
|
} |
|
while (argsLength--) { |
|
args[leftIndex++] = arguments[++argsIndex]; |
|
} |
|
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; |
|
return fn.apply(isBind ? thisArg : this, args); |
|
} |
|
return wrapper; |
|
} |
|
|
|
var BIND_FLAG$5 = 1; |
|
var CURRY_BOUND_FLAG$1 = 4; |
|
var CURRY_FLAG$3 = 8; |
|
var ARY_FLAG$3 = 128; |
|
var REARG_FLAG$2 = 256; |
|
/** Used as the internal argument placeholder. */ |
|
var PLACEHOLDER$1 = '__lodash_placeholder__'; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMin$8 = Math.min; |
|
|
|
/** |
|
* Merges the function metadata of `source` into `data`. |
|
* |
|
* Merging metadata reduces the number of wrappers used to invoke a function. |
|
* This is possible because methods like `_.bind`, `_.curry`, and `_.partial` |
|
* may be applied regardless of execution order. Methods like `_.ary` and `_.rearg` |
|
* modify function arguments, making the order in which they are executed important, |
|
* preventing the merging of metadata. However, we make an exception for a safe |
|
* common case where curried functions have `_.ary` and or `_.rearg` applied. |
|
* |
|
* @private |
|
* @param {Array} data The destination metadata. |
|
* @param {Array} source The source metadata. |
|
* @returns {Array} Returns `data`. |
|
*/ |
|
function mergeData(data, source) { |
|
var bitmask = data[1], |
|
srcBitmask = source[1], |
|
newBitmask = bitmask | srcBitmask, |
|
isCommon = newBitmask < ARY_FLAG$3; |
|
|
|
var isCombo = |
|
(srcBitmask == ARY_FLAG$3 && (bitmask == CURRY_FLAG$3)) || |
|
(srcBitmask == ARY_FLAG$3 && (bitmask == REARG_FLAG$2) && (data[7].length <= source[8])) || |
|
(srcBitmask == (ARY_FLAG$3 | REARG_FLAG$2) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG$3)); |
|
|
|
// Exit early if metadata can't be merged. |
|
if (!(isCommon || isCombo)) { |
|
return data; |
|
} |
|
// Use source `thisArg` if available. |
|
if (srcBitmask & BIND_FLAG$5) { |
|
data[2] = source[2]; |
|
// Set when currying a bound function. |
|
newBitmask |= (bitmask & BIND_FLAG$5) ? 0 : CURRY_BOUND_FLAG$1; |
|
} |
|
// Compose partial arguments. |
|
var value = source[3]; |
|
if (value) { |
|
var partials = data[3]; |
|
data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value); |
|
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER$1) : copyArray(source[4]); |
|
} |
|
// Compose partial right arguments. |
|
value = source[5]; |
|
if (value) { |
|
partials = data[5]; |
|
data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value); |
|
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER$1) : copyArray(source[6]); |
|
} |
|
// Use source `argPos` if available. |
|
value = source[7]; |
|
if (value) { |
|
data[7] = copyArray(value); |
|
} |
|
// Use source `ary` if it's smaller. |
|
if (srcBitmask & ARY_FLAG$3) { |
|
data[8] = data[8] == null ? source[8] : nativeMin$8(data[8], source[8]); |
|
} |
|
// Use source `arity` if one is not provided. |
|
if (data[9] == null) { |
|
data[9] = source[9]; |
|
} |
|
// Use source `func` and merge bitmasks. |
|
data[0] = source[0]; |
|
data[1] = newBitmask; |
|
|
|
return data; |
|
} |
|
|
|
var BIND_FLAG$2 = 1; |
|
var BIND_KEY_FLAG$2 = 2; |
|
var PARTIAL_FLAG$3 = 32; |
|
var PARTIAL_RIGHT_FLAG$1 = 64; |
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$8 = 'Expected a function'; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$10 = Math.max; |
|
|
|
/** |
|
* Creates a function that either curries or invokes `func` with optional |
|
* `this` binding and partially applied arguments. |
|
* |
|
* @private |
|
* @param {Function|string} func The function or method name to reference. |
|
* @param {number} bitmask The bitmask of wrapper flags. |
|
* The bitmask may be composed of the following flags: |
|
* 1 - `_.bind` |
|
* 2 - `_.bindKey` |
|
* 4 - `_.curry` or `_.curryRight` of a bound function |
|
* 8 - `_.curry` |
|
* 16 - `_.curryRight` |
|
* 32 - `_.partial` |
|
* 64 - `_.partialRight` |
|
* 128 - `_.rearg` |
|
* 256 - `_.ary` |
|
* @param {*} [thisArg] The `this` binding of `func`. |
|
* @param {Array} [partials] The arguments to be partially applied. |
|
* @param {Array} [holders] The `partials` placeholder indexes. |
|
* @param {Array} [argPos] The argument positions of the new function. |
|
* @param {number} [ary] The arity cap of `func`. |
|
* @param {number} [arity] The arity of `func`. |
|
* @returns {Function} Returns the new wrapped function. |
|
*/ |
|
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { |
|
var isBindKey = bitmask & BIND_KEY_FLAG$2; |
|
if (!isBindKey && typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$8); |
|
} |
|
var length = partials ? partials.length : 0; |
|
if (!length) { |
|
bitmask &= ~(PARTIAL_FLAG$3 | PARTIAL_RIGHT_FLAG$1); |
|
partials = holders = undefined; |
|
} |
|
length -= holders ? holders.length : 0; |
|
if (bitmask & PARTIAL_RIGHT_FLAG$1) { |
|
var partialsRight = partials, |
|
holdersRight = holders; |
|
|
|
partials = holders = undefined; |
|
} |
|
ary = ary == null ? ary : nativeMax$10(toInteger(ary), 0); |
|
arity = arity == null ? arity : toInteger(arity); |
|
|
|
var data = isBindKey ? undefined : getData(func), |
|
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity]; |
|
|
|
if (data) { |
|
mergeData(newData, data); |
|
bitmask = newData[1]; |
|
arity = newData[9]; |
|
} |
|
newData[9] = arity == null |
|
? (isBindKey ? 0 : func.length) |
|
: nativeMax$10(arity - length, 0); |
|
|
|
if (bitmask == BIND_FLAG$2) { |
|
var result = createBindWrapper(newData[0], newData[2]); |
|
} else if ((bitmask == PARTIAL_FLAG$3 || bitmask == (BIND_FLAG$2 | PARTIAL_FLAG$3)) && !newData[4].length) { |
|
result = createPartialWrapper.apply(undefined, newData); |
|
} else { |
|
result = createHybridWrapper.apply(undefined, newData); |
|
} |
|
var setter = data ? baseSetData : setData; |
|
return setter(result, newData); |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var ARY_FLAG = 128; |
|
|
|
/** |
|
* Creates a function that accepts up to `n` arguments ignoring any |
|
* additional arguments. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to cap arguments for. |
|
* @param {number} [n=func.length] The arity cap. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* _.map(['6', '8', '10'], _.ary(parseInt, 1)); |
|
* // => [6, 8, 10] |
|
*/ |
|
function ary(func, n, guard) { |
|
n = guard ? undefined : n; |
|
n = (func && n == null) ? func.length : n; |
|
return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n); |
|
} |
|
|
|
/** |
|
* 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]; |
|
}; |
|
} |
|
|
|
/** |
|
* 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) |
|
* that affects Safari on at least iOS 8.1-8.3 ARM64. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @returns {*} Returns the "length" value. |
|
*/ |
|
var getLength = baseProperty('length'); |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var MAX_SAFE_INTEGER$4 = 9007199254740991; |
|
|
|
/** |
|
* Checks if `value` is a valid array-like length. |
|
* |
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. |
|
*/ |
|
function isLength(value) { |
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$4; |
|
} |
|
|
|
/** |
|
* Checks if `value` is array-like. A value is considered array-like if it's |
|
* not a function and has a `value.length` that's an integer greater than or |
|
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type Function |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. |
|
* @example |
|
* |
|
* _.isArrayLike([1, 2, 3]); |
|
* // => true |
|
* |
|
* _.isArrayLike(document.body.children); |
|
* // => true |
|
* |
|
* _.isArrayLike('abc'); |
|
* // => true |
|
* |
|
* _.isArrayLike(_.noop); |
|
* // => false |
|
*/ |
|
function isArrayLike(value) { |
|
return value != null && |
|
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value)); |
|
} |
|
|
|
/** |
|
* Checks if the provided arguments are from an iteratee call. |
|
* |
|
* @private |
|
* @param {*} value The potential iteratee value argument. |
|
* @param {*} index The potential iteratee index or key argument. |
|
* @param {*} object The potential iteratee object argument. |
|
* @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`. |
|
*/ |
|
function isIterateeCall(value, index, object) { |
|
if (!isObject(object)) { |
|
return false; |
|
} |
|
var type = typeof index; |
|
if (type == 'number' |
|
? (isArrayLike(object) && isIndex(index, object.length)) |
|
: (type == 'string' && index in object)) { |
|
var other = object[index]; |
|
return value === value ? (value === other) : (other !== other); |
|
} |
|
return false; |
|
} |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$5 = 'Expected a function'; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$7 = Math.max; |
|
|
|
/** |
|
* Creates a function that invokes `func` with the `this` binding of the |
|
* created function and arguments from `start` and beyond provided as an array. |
|
* |
|
* **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to apply a rest parameter to. |
|
* @param {number} [start=func.length-1] The start position of the rest parameter. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var say = _.rest(function(what, names) { |
|
* return what + ' ' + _.initial(names).join(', ') + |
|
* (_.size(names) > 1 ? ', & ' : '') + _.last(names); |
|
* }); |
|
* |
|
* say('hello', 'fred', 'barney', 'pebbles'); |
|
* // => 'hello fred, barney, & pebbles' |
|
*/ |
|
function rest(func, start) { |
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$5); |
|
} |
|
start = nativeMax$7(start === undefined ? (func.length - 1) : toInteger(start), 0); |
|
return function() { |
|
var args = arguments, |
|
index = -1, |
|
length = nativeMax$7(args.length - start, 0), |
|
array = Array(length); |
|
|
|
while (++index < length) { |
|
array[index] = args[start + index]; |
|
} |
|
switch (start) { |
|
case 0: return func.call(this, array); |
|
case 1: return func.call(this, args[0], array); |
|
case 2: return func.call(this, args[0], args[1], array); |
|
} |
|
var otherArgs = Array(start + 1); |
|
index = -1; |
|
while (++index < start) { |
|
otherArgs[index] = args[index]; |
|
} |
|
otherArgs[start] = array; |
|
return func.apply(this, otherArgs); |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function like `_.assign`. |
|
* |
|
* @private |
|
* @param {Function} assigner The function to assign values. |
|
* @returns {Function} Returns the new assigner function. |
|
*/ |
|
function createAssigner(assigner) { |
|
return rest(function(object, sources) { |
|
var index = -1, |
|
length = object == null ? 0 : sources.length, |
|
customizer = length > 1 ? sources[length - 1] : undefined, |
|
guard = length > 2 ? sources[2] : undefined; |
|
|
|
customizer = typeof customizer == 'function' ? (length--, customizer) : undefined; |
|
if (guard && isIterateeCall(sources[0], sources[1], guard)) { |
|
customizer = length < 3 ? undefined : customizer; |
|
length = 1; |
|
} |
|
object = Object(object); |
|
while (++index < length) { |
|
var source = sources[index]; |
|
if (source) { |
|
assigner(object, source, customizer); |
|
} |
|
} |
|
return object; |
|
}); |
|
} |
|
|
|
/** |
|
* Assigns `value` to `key` of `object` if the existing value is not equivalent |
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. |
|
* |
|
* @private |
|
* @param {Object} object The object to modify. |
|
* @param {string} key The key of the property to assign. |
|
* @param {*} value The value to assign. |
|
*/ |
|
function assignValue(object, key, value) { |
|
var oldValue = object[key]; |
|
if ((value === value ? (value !== oldValue) : (oldValue === oldValue)) || |
|
(value === undefined && !(key in object))) { |
|
object[key] = value; |
|
} |
|
} |
|
|
|
/** |
|
* This function is like `copyObject` except that it accepts a function to |
|
* customize copied values. |
|
* |
|
* @private |
|
* @param {Object} source The object to copy properties from. |
|
* @param {Array} props The property names to copy. |
|
* @param {Object} [object={}] The object to copy properties to. |
|
* @param {Function} [customizer] The function to customize copied values. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function copyObjectWith(source, props, object, customizer) { |
|
object || (object = {}); |
|
|
|
var index = -1, |
|
length = props.length; |
|
|
|
while (++index < length) { |
|
var key = props[index], |
|
newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; |
|
|
|
assignValue(object, key, newValue); |
|
} |
|
return object; |
|
} |
|
|
|
/** |
|
* Copies properties of `source` to `object`. |
|
* |
|
* @private |
|
* @param {Object} source The object to copy properties from. |
|
* @param {Array} props The property names to copy. |
|
* @param {Object} [object={}] The object to copy properties to. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function copyObject(source, props, object) { |
|
return copyObjectWith(source, props, object); |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$17 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$8 = objectProto$17.hasOwnProperty; |
|
|
|
/** Built-in value references. */ |
|
var getPrototypeOf$1 = Object.getPrototypeOf; |
|
|
|
/** |
|
* The base implementation of `_.has` without support for deep paths. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {Array|string} key The key to check. |
|
* @returns {boolean} Returns `true` if `key` exists, else `false`. |
|
*/ |
|
function baseHas(object, key) { |
|
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`, |
|
// that are composed entirely of index properties, return `false` for |
|
// `hasOwnProperty` checks of them. |
|
return hasOwnProperty$8.call(object, key) || |
|
(typeof object == 'object' && key in object && getPrototypeOf$1(object) === null); |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeKeys = Object.keys; |
|
|
|
/** |
|
* The base implementation of `_.keys` which doesn't skip the constructor |
|
* property of prototypes or treat sparse arrays as dense. |
|
* |
|
* @private |
|
* @type Function |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the array of property names. |
|
*/ |
|
function baseKeys(object) { |
|
return nativeKeys(Object(object)); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.times` without support for callback shorthands |
|
* or max array length checks. |
|
* |
|
* @private |
|
* @param {number} n The number of times to invoke `iteratee`. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Array} Returns the array of results. |
|
*/ |
|
function baseTimes(n, iteratee) { |
|
var index = -1, |
|
result = Array(n); |
|
|
|
while (++index < n) { |
|
result[index] = iteratee(index); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* This method is like `_.isArrayLike` except that it also checks if `value` |
|
* is an object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type Function |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. |
|
* @example |
|
* |
|
* _.isArrayLikeObject([1, 2, 3]); |
|
* // => true |
|
* |
|
* _.isArrayLikeObject(document.body.children); |
|
* // => true |
|
* |
|
* _.isArrayLikeObject('abc'); |
|
* // => false |
|
* |
|
* _.isArrayLikeObject(_.noop); |
|
* // => false |
|
*/ |
|
function isArrayLikeObject(value) { |
|
return isObjectLike(value) && isArrayLike(value); |
|
} |
|
|
|
/** `Object#toString` result references. */ |
|
var argsTag = '[object Arguments]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$3 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$3 = objectProto$3.hasOwnProperty; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString = objectProto$3.toString; |
|
|
|
/** Built-in value references. */ |
|
var propertyIsEnumerable = objectProto$3.propertyIsEnumerable; |
|
|
|
/** |
|
* Checks if `value` is likely an `arguments` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isArguments(function() { return arguments; }()); |
|
* // => true |
|
* |
|
* _.isArguments([1, 2, 3]); |
|
* // => false |
|
*/ |
|
function isArguments(value) { |
|
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. |
|
return isArrayLikeObject(value) && hasOwnProperty$3.call(value, 'callee') && |
|
(!propertyIsEnumerable.call(value, 'callee') || objToString.call(value) == argsTag); |
|
} |
|
|
|
/** `Object#toString` result references. */ |
|
var stringTag = '[object String]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$12 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$8 = objectProto$12.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a `String` primitive or object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isString('abc'); |
|
* // => true |
|
* |
|
* _.isString(1); |
|
* // => false |
|
*/ |
|
function isString(value) { |
|
return typeof value == 'string' || |
|
(!isArray(value) && isObjectLike(value) && objToString$8.call(value) == stringTag); |
|
} |
|
|
|
/** |
|
* Initializes an array of property names based on `object`. If `object` is |
|
* an array, `arguments` object, or `string` its index keys are returned, |
|
* otherwise an empty array is returned. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the initialized array of property names. |
|
*/ |
|
function initKeys(object) { |
|
var length = object ? object.length : 0; |
|
length = (length && isLength(length) && |
|
(isArray(object) || isString(object) || isArguments(object)) && length) || 0; |
|
|
|
return baseTimes(length, String); |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$18 = Object.prototype; |
|
|
|
/** |
|
* Checks if `value` is likely a prototype object. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`. |
|
*/ |
|
function isPrototype(value) { |
|
var Ctor = value && value.constructor, |
|
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$18; |
|
|
|
return value === proto; |
|
} |
|
|
|
/** |
|
* Creates an array of the own enumerable property names of `object`. |
|
* |
|
* **Note:** Non-object values are coerced to objects. See the |
|
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) |
|
* for more details. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the array of property names. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.keys(new Foo); |
|
* // => ['a', 'b'] (iteration order is not guaranteed) |
|
* |
|
* _.keys('hi'); |
|
* // => ['0', '1'] |
|
*/ |
|
function keys(object) { |
|
var isProto = isPrototype(object); |
|
if (!(isProto || isArrayLike(object))) { |
|
return baseKeys(object); |
|
} |
|
var result = initKeys(object), |
|
length = result.length, |
|
skipIndexes = !!length; |
|
|
|
for (var key in object) { |
|
if (baseHas(object, key) && |
|
!(skipIndexes && isIndex(key, length)) && |
|
!(isProto && key == 'constructor')) { |
|
result.push(key); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Assigns own enumerable properties of source objects to the destination |
|
* object. Source objects are applied from left to right. Subsequent sources |
|
* overwrite property assignments of previous sources. |
|
* |
|
* **Note:** This method mutates `object` and is based on |
|
* [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} [sources] The source objects. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.c = 3; |
|
* } |
|
* |
|
* function Bar() { |
|
* this.e = 5; |
|
* } |
|
* |
|
* Foo.prototype.d = 4; |
|
* Bar.prototype.f = 6; |
|
* |
|
* _.assign({ 'a': 1 }, new Foo, new Bar); |
|
* // => { 'a': 1, 'c': 3, 'e': 5 } |
|
*/ |
|
var assign = createAssigner(function(object, source) { |
|
copyObject(source, keys(source), object); |
|
}); |
|
|
|
/** |
|
* This method is like `_.assign` except that it accepts `customizer` which |
|
* is invoked to produce the assigned values. If `customizer` returns `undefined` |
|
* assignment is handled by the method instead. The `customizer` is invoked |
|
* with five arguments: (objValue, srcValue, key, object, source). |
|
* |
|
* **Note:** This method mutates `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} sources The source objects. |
|
* @param {Function} [customizer] The function to customize assigned values. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function customizer(objValue, srcValue) { |
|
* return _.isUndefined(objValue) ? srcValue : objValue; |
|
* } |
|
* |
|
* var defaults = _.partialRight(_.assignWith, customizer); |
|
* |
|
* defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); |
|
* // => { 'a': 1, 'b': 2 } |
|
*/ |
|
var assignWith = createAssigner(function(object, source, customizer) { |
|
copyObjectWith(source, keys(source), object, customizer); |
|
}); |
|
|
|
/** |
|
* Converts `value` to a string if it's not one. |
|
* An empty string is returned for `null` and `undefined` values. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to process. |
|
* @returns {string} Returns the string. |
|
*/ |
|
function toString(value) { |
|
// Exit early for strings to avoid a performance hit in some environments. |
|
if (typeof value == 'string') { |
|
return value; |
|
} |
|
return value == null ? '' : (value + ''); |
|
} |
|
|
|
/** Used to match property names within property paths. */ |
|
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g; |
|
|
|
/** Used to match backslashes in property paths. */ |
|
var reEscapeChar = /\\(\\)?/g; |
|
|
|
/** |
|
* Converts `string` to a property path array. |
|
* |
|
* @private |
|
* @param {string} string The string to convert. |
|
* @returns {Array} Returns the property path array. |
|
*/ |
|
function stringToPath(string) { |
|
var result = []; |
|
toString(string).replace(rePropName, function(match, number, quote, string) { |
|
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.toPath` which only converts `value` to a |
|
* path if it's not one. |
|
* |
|
* @private |
|
* @param {*} value The value to process. |
|
* @returns {Array} Returns the property path array. |
|
*/ |
|
function baseToPath(value) { |
|
return isArray(value) ? value : stringToPath(value); |
|
} |
|
|
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/; |
|
var reIsPlainProp = /^\w*$/; |
|
/** |
|
* Checks if `value` is a property name and not a property path. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @param {Object} [object] The object to query keys on. |
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`. |
|
*/ |
|
function isKey(value, object) { |
|
if (typeof value == 'number') { |
|
return true; |
|
} |
|
return !isArray(value) && |
|
(reIsPlainProp.test(value) || !reIsDeepProp.test(value) || |
|
(object != null && value in Object(object))); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.get` without support for default values. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {Array|string} path The path of the property to get. |
|
* @returns {*} Returns the resolved value. |
|
*/ |
|
function baseGet(object, path) { |
|
path = isKey(path, object) ? [path + ''] : baseToPath(path); |
|
|
|
var index = 0, |
|
length = path.length; |
|
|
|
while (object != null && index < length) { |
|
object = object[path[index++]]; |
|
} |
|
return (index && index == length) ? object : undefined; |
|
} |
|
|
|
/** |
|
* Gets the value at `path` of `object`. If the resolved value is |
|
* `undefined` the `defaultValue` is used in its place. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to query. |
|
* @param {Array|string} path The path of the property to get. |
|
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`. |
|
* @returns {*} Returns the resolved value. |
|
* @example |
|
* |
|
* var object = { 'a': [{ 'b': { 'c': 3 } }] }; |
|
* |
|
* _.get(object, 'a[0].b.c'); |
|
* // => 3 |
|
* |
|
* _.get(object, ['a', '0', 'b', 'c']); |
|
* // => 3 |
|
* |
|
* _.get(object, 'a.b.c', 'default'); |
|
* // => 'default' |
|
*/ |
|
function get(object, path, defaultValue) { |
|
var result = object == null ? undefined : baseGet(object, path); |
|
return result === undefined ? defaultValue : result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.at` without support for individual path arguments. |
|
* |
|
* @private |
|
* @param {Object} object The object to iterate over. |
|
* @param {string[]} paths The property paths of elements to pick. |
|
* @returns {Array} Returns the new array of picked elements. |
|
*/ |
|
function baseAt(object, paths) { |
|
var index = -1, |
|
isNil = object == null, |
|
length = paths.length, |
|
result = Array(length); |
|
|
|
while (++index < length) { |
|
result[index] = isNil ? undefined : get(object, paths[index]); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Appends the elements of `values` to `array`. |
|
* |
|
* @private |
|
* @param {Array} array The array to modify. |
|
* @param {Array} values The values to append. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function arrayPush(array, values) { |
|
var index = -1, |
|
length = values.length, |
|
offset = array.length; |
|
|
|
while (++index < length) { |
|
array[offset + index] = values[index]; |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.flatten` with support for restricting flattening. |
|
* |
|
* @private |
|
* @param {Array} array The array to flatten. |
|
* @param {boolean} [isDeep] Specify a deep flatten. |
|
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects. |
|
* @param {Array} [result=[]] The initial result value. |
|
* @returns {Array} Returns the new flattened array. |
|
*/ |
|
function baseFlatten(array, isDeep, isStrict, result) { |
|
result || (result = []); |
|
|
|
var index = -1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
if (isArrayLikeObject(value) && |
|
(isStrict || isArray(value) || isArguments(value))) { |
|
if (isDeep) { |
|
// Recursively flatten arrays (susceptible to call stack limits). |
|
baseFlatten(value, isDeep, isStrict, result); |
|
} else { |
|
arrayPush(result, value); |
|
} |
|
} else if (!isStrict) { |
|
result[result.length] = value; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array of values corresponding to `paths` of `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {...(string|string[])} [paths] The property paths of elements to pick, |
|
* specified individually or in arrays. |
|
* @returns {Array} Returns the new array of picked elements. |
|
* @example |
|
* |
|
* var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; |
|
* |
|
* _.at(object, ['a[0].b.c', 'a[1]']); |
|
* // => [3, 4] |
|
* |
|
* _.at(['a', 'b', 'c'], 0, 2); |
|
* // => ['a', 'c'] |
|
*/ |
|
var at = rest(function(object, paths) { |
|
return baseAt(object, baseFlatten(paths)); |
|
}); |
|
|
|
/** `Object#toString` result references. */ |
|
var errorTag = '[object Error]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$6 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$3 = objectProto$6.toString; |
|
|
|
/** |
|
* Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, |
|
* `SyntaxError`, `TypeError`, or `URIError` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is an error object, else `false`. |
|
* @example |
|
* |
|
* _.isError(new Error); |
|
* // => true |
|
* |
|
* _.isError(Error); |
|
* // => false |
|
*/ |
|
function isError(value) { |
|
return isObjectLike(value) && |
|
typeof value.message == 'string' && objToString$3.call(value) == errorTag; |
|
} |
|
|
|
/** |
|
* Attempts to invoke `func`, returning either the result or the caught error |
|
* object. Any additional arguments are provided to `func` when it's invoked. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Function} func The function to attempt. |
|
* @returns {*} Returns the `func` result or error object. |
|
* @example |
|
* |
|
* // avoid throwing errors for invalid selectors |
|
* var elements = _.attempt(function(selector) { |
|
* return document.querySelectorAll(selector); |
|
* }, '>_>'); |
|
* |
|
* if (_.isError(elements)) { |
|
* elements = []; |
|
* } |
|
*/ |
|
var attempt = rest(function(func, args) { |
|
try { |
|
return func.apply(undefined, args); |
|
} catch (e) { |
|
return isError(e) ? e : new Error(e); |
|
} |
|
}); |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$1 = 'Expected a function'; |
|
|
|
/** |
|
* Creates a function that invokes `func`, with the `this` binding and arguments |
|
* of the created function, while it's called less than `n` times. Subsequent |
|
* calls to the created function return the result of the last `func` invocation. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {number} n The number of calls at which `func` is no longer invoked. |
|
* @param {Function} func The function to restrict. |
|
* @returns {Function} Returns the new restricted function. |
|
* @example |
|
* |
|
* jQuery('#add').on('click', _.before(5, addContactToList)); |
|
* // => allows adding up to 4 contacts to the list |
|
*/ |
|
function before(n, func) { |
|
var result; |
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$1); |
|
} |
|
n = toInteger(n); |
|
return function() { |
|
if (--n > 0) { |
|
result = func.apply(this, arguments); |
|
} |
|
if (n <= 1) { |
|
func = undefined; |
|
} |
|
return result; |
|
}; |
|
} |
|
|
|
var BIND_FLAG = 1; |
|
var PARTIAL_FLAG = 32; |
|
/** |
|
* Creates a function that invokes `func` with the `this` binding of `thisArg` |
|
* and prepends any additional `_.bind` arguments to those provided to the |
|
* 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 doesn't set the "length" |
|
* property of bound functions. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to bind. |
|
* @param {*} thisArg The `this` binding of `func`. |
|
* @param {...*} [partials] The arguments to be partially applied. |
|
* @returns {Function} Returns the new bound function. |
|
* @example |
|
* |
|
* var greet = function(greeting, punctuation) { |
|
* return greeting + ' ' + this.user + punctuation; |
|
* }; |
|
* |
|
* var object = { 'user': 'fred' }; |
|
* |
|
* var bound = _.bind(greet, object, 'hi'); |
|
* bound('!'); |
|
* // => 'hi fred!' |
|
* |
|
* // using placeholders |
|
* var bound = _.bind(greet, object, _, '!'); |
|
* bound('hi'); |
|
* // => 'hi fred!' |
|
*/ |
|
var bind = rest(function(func, thisArg, partials) { |
|
var bitmask = BIND_FLAG; |
|
if (partials.length) { |
|
var holders = replaceHolders(partials, bind.placeholder); |
|
bitmask |= PARTIAL_FLAG; |
|
} |
|
return createWrapper(func, bitmask, thisArg, partials, holders); |
|
}); |
|
|
|
/** |
|
* A specialized version of `_.forEach` for arrays without support for |
|
* callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function arrayEach(array, iteratee) { |
|
var index = -1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
if (iteratee(array[index], index, array) === false) { |
|
break; |
|
} |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* Binds methods of an object to the object itself, overwriting the existing |
|
* method. |
|
* |
|
* **Note:** This method doesn't set the "length" property of bound functions. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Object} object The object to bind and assign the bound methods to. |
|
* @param {...(string|string[])} methodNames The object method names to bind, |
|
* specified individually or in arrays. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* var view = { |
|
* 'label': 'docs', |
|
* 'onClick': function() { |
|
* console.log('clicked ' + this.label); |
|
* } |
|
* }; |
|
* |
|
* _.bindAll(view, 'onClick'); |
|
* jQuery('#docs').on('click', view.onClick); |
|
* // => logs 'clicked docs' when the element is clicked |
|
*/ |
|
var bindAll = rest(function(object, methodNames) { |
|
arrayEach(baseFlatten(methodNames), function(key) { |
|
object[key] = bind(object[key], object); |
|
}); |
|
return object; |
|
}); |
|
|
|
var BIND_FLAG$1 = 1; |
|
var BIND_KEY_FLAG = 2; |
|
var PARTIAL_FLAG$1 = 32; |
|
/** |
|
* 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://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. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Object} object The object the method belongs to. |
|
* @param {string} key The key of the method. |
|
* @param {...*} [partials] The arguments to be partially applied. |
|
* @returns {Function} Returns the new bound function. |
|
* @example |
|
* |
|
* var object = { |
|
* 'user': 'fred', |
|
* 'greet': function(greeting, punctuation) { |
|
* return greeting + ' ' + this.user + punctuation; |
|
* } |
|
* }; |
|
* |
|
* var bound = _.bindKey(object, 'greet', 'hi'); |
|
* bound('!'); |
|
* // => 'hi fred!' |
|
* |
|
* object.greet = function(greeting, punctuation) { |
|
* return greeting + 'ya ' + this.user + punctuation; |
|
* }; |
|
* |
|
* bound('!'); |
|
* // => 'hiya fred!' |
|
* |
|
* // using placeholders |
|
* var bound = _.bindKey(object, 'greet', _, '!'); |
|
* bound('hi'); |
|
* // => 'hiya fred!' |
|
*/ |
|
var bindKey = rest(function(object, key, partials) { |
|
var bitmask = BIND_FLAG$1 | BIND_KEY_FLAG; |
|
if (partials.length) { |
|
var holders = replaceHolders(partials, bindKey.placeholder); |
|
bitmask |= PARTIAL_FLAG$1; |
|
} |
|
return createWrapper(key, bitmask, object, partials, holders); |
|
}); |
|
|
|
/** |
|
* A specialized version of `_.reduce` for arrays without support for |
|
* callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @param {*} [accumulator] The initial value. |
|
* @param {boolean} [initFromArray] Specify using the first element of `array` as the initial value. |
|
* @returns {*} Returns the accumulated value. |
|
*/ |
|
function arrayReduce(array, iteratee, accumulator, initFromArray) { |
|
var index = -1, |
|
length = array.length; |
|
|
|
if (initFromArray && length) { |
|
accumulator = array[++index]; |
|
} |
|
while (++index < length) { |
|
accumulator = iteratee(accumulator, array[index], index, array); |
|
} |
|
return accumulator; |
|
} |
|
|
|
/** Used to map latin-1 supplementary letters to basic latin letters. */ |
|
var deburredLetters = { |
|
'\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', |
|
'\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', |
|
'\xc7': 'C', '\xe7': 'c', |
|
'\xd0': 'D', '\xf0': 'd', |
|
'\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', |
|
'\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', |
|
'\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', |
|
'\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', |
|
'\xd1': 'N', '\xf1': 'n', |
|
'\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', |
|
'\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', |
|
'\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', |
|
'\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', |
|
'\xdd': 'Y', '\xfd': 'y', '\xff': 'y', |
|
'\xc6': 'Ae', '\xe6': 'ae', |
|
'\xde': 'Th', '\xfe': 'th', |
|
'\xdf': 'ss' |
|
}; |
|
|
|
/** |
|
* Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters. |
|
* |
|
* @private |
|
* @param {string} letter The matched letter to deburr. |
|
* @returns {string} Returns the deburred letter. |
|
*/ |
|
function deburrLetter(letter) { |
|
return deburredLetters[letter]; |
|
} |
|
|
|
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */ |
|
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; |
|
|
|
/** Used to compose unicode character classes. */ |
|
var rsComboRange = '\\u0300-\\u036f\\ufe20-\\ufe23'; |
|
|
|
/** Used to compose unicode capture groups. */ |
|
var rsCombo = '[' + rsComboRange + ']'; |
|
|
|
/** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */ |
|
var reComboMark = RegExp(rsCombo, 'g'); |
|
|
|
/** |
|
* Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) |
|
* to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to deburr. |
|
* @returns {string} Returns the deburred string. |
|
* @example |
|
* |
|
* _.deburr('déjà vu'); |
|
* // => 'deja vu' |
|
*/ |
|
function deburr(string) { |
|
string = toString(string); |
|
return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, ''); |
|
} |
|
|
|
var rsAstralRange$1 = '\\ud800-\\udfff'; |
|
var rsDingbatRange = '\\u2700-\\u27bf'; |
|
var rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff'; |
|
var rsMathOpRange = '\\xac\\xb1\\xd7\\xf7'; |
|
var rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf'; |
|
var rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d'; |
|
var rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000'; |
|
var rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde'; |
|
var rsVarRange$1 = '\\ufe0e\\ufe0f'; |
|
var rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange; |
|
var rsBreak = '[' + rsBreakRange + ']'; |
|
var rsDigits = '\\d+'; |
|
var rsDingbat = '[' + rsDingbatRange + ']'; |
|
var rsLower = '[' + rsLowerRange + ']'; |
|
var rsMisc = '[^' + rsAstralRange$1 + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']'; |
|
var rsModifier = '(?:\\ud83c[\\udffb-\\udfff])'; |
|
var rsNonAstral = '[^' + rsAstralRange$1 + ']'; |
|
var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}'; |
|
var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]'; |
|
var rsUpper = '[' + rsUpperRange + ']'; |
|
var rsZWJ$1 = '\\u200d'; |
|
var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')'; |
|
var rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')'; |
|
var reOptMod = rsModifier + '?'; |
|
var rsOptVar = '[' + rsVarRange$1 + ']?'; |
|
var rsOptJoin = '(?:' + rsZWJ$1 + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*'; |
|
var rsSeq = rsOptVar + reOptMod + rsOptJoin; |
|
var rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; |
|
/** Used to match non-compound words composed of alphanumeric characters. */ |
|
var reBasicWord = /[a-zA-Z0-9]+/g; |
|
|
|
/** Used to match complex or compound words. */ |
|
var reComplexWord = RegExp([ |
|
rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', |
|
rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', |
|
rsUpper + '?' + rsLowerMisc + '+', |
|
rsDigits + '(?:' + rsLowerMisc + '+)?', |
|
rsEmoji |
|
].join('|'), 'g'); |
|
|
|
/** Used to detect strings that need a more robust regexp to match words. */ |
|
var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; |
|
|
|
/** |
|
* Splits `string` into an array of its words. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to inspect. |
|
* @param {RegExp|string} [pattern] The pattern to match words. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Array} Returns the words of `string`. |
|
* @example |
|
* |
|
* _.words('fred, barney, & pebbles'); |
|
* // => ['fred', 'barney', 'pebbles'] |
|
* |
|
* _.words('fred, barney, & pebbles', /[^, ]+/g); |
|
* // => ['fred', 'barney', '&', 'pebbles'] |
|
*/ |
|
function words(string, pattern, guard) { |
|
string = toString(string); |
|
pattern = guard ? undefined : pattern; |
|
|
|
if (pattern === undefined) { |
|
pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord; |
|
} |
|
return string.match(pattern) || []; |
|
} |
|
|
|
/** |
|
* Creates a function like `_.camelCase`. |
|
* |
|
* @private |
|
* @param {Function} callback The function to combine each word. |
|
* @returns {Function} Returns the new compounder function. |
|
*/ |
|
function createCompounder(callback) { |
|
return function(string) { |
|
return arrayReduce(words(deburr(string)), callback, ''); |
|
}; |
|
} |
|
|
|
/** Used to compose unicode character classes. */ |
|
var rsAstralRange$5 = '\\ud800-\\udfff'; |
|
var rsComboRange$5 = '\\u0300-\\u036f\\ufe20-\\ufe23'; |
|
var rsVarRange$5 = '\\ufe0e\\ufe0f'; |
|
var rsAstral$1 = '[' + rsAstralRange$5 + ']'; |
|
var rsCombo$2 = '[' + rsComboRange$5 + ']'; |
|
var rsModifier$2 = '(?:\\ud83c[\\udffb-\\udfff])'; |
|
var rsNonAstral$2 = '[^' + rsAstralRange$5 + ']'; |
|
var rsRegional$2 = '(?:\\ud83c[\\udde6-\\uddff]){2}'; |
|
var rsSurrPair$2 = '[\\ud800-\\udbff][\\udc00-\\udfff]'; |
|
var rsZWJ$5 = '\\u200d'; |
|
var reOptMod$2 = rsModifier$2 + '?'; |
|
var rsOptVar$2 = '[' + rsVarRange$5 + ']?'; |
|
var rsOptJoin$2 = '(?:' + rsZWJ$5 + '(?:' + [rsNonAstral$2, rsRegional$2, rsSurrPair$2].join('|') + ')' + rsOptVar$2 + reOptMod$2 + ')*'; |
|
var rsSeq$2 = rsOptVar$2 + reOptMod$2 + rsOptJoin$2; |
|
var rsSymbol$1 = '(?:' + [rsNonAstral$2 + rsCombo$2 + '?', rsCombo$2, rsRegional$2, rsSurrPair$2, rsAstral$1].join('|') + ')'; |
|
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ |
|
var reComplexSymbol$1 = RegExp(rsSymbol$1 + rsSeq$2, 'g'); |
|
|
|
/** |
|
* Converts `string` to an array. |
|
* |
|
* @private |
|
* @param {string} string The string to convert. |
|
* @returns {Array} Returns the converted array. |
|
*/ |
|
function stringToArray(string) { |
|
return string ? string.match(reComplexSymbol$1) : []; |
|
} |
|
|
|
var rsAstralRange$2 = '\\ud800-\\udfff'; |
|
var rsComboRange$2 = '\\u0300-\\u036f\\ufe20-\\ufe23'; |
|
var rsVarRange$2 = '\\ufe0e\\ufe0f'; |
|
/** Used to compose unicode capture groups. */ |
|
var rsZWJ$2 = '\\u200d'; |
|
|
|
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ |
|
var reHasComplexSymbol$1 = RegExp('[' + rsZWJ$2 + rsAstralRange$2 + rsComboRange$2 + rsVarRange$2 + ']'); |
|
|
|
/** |
|
* Creates a function like `_.lowerFirst`. |
|
* |
|
* @private |
|
* @param {string} methodName The name of the `String` case method to use. |
|
* @returns {Function} Returns the new function. |
|
*/ |
|
function createCaseFirst(methodName) { |
|
return function(string) { |
|
string = toString(string); |
|
|
|
var strSymbols = reHasComplexSymbol$1.test(string) ? stringToArray(string) : undefined, |
|
chr = strSymbols ? strSymbols[0] : string.charAt(0), |
|
trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1); |
|
|
|
return chr[methodName]() + trailing; |
|
}; |
|
} |
|
|
|
/** |
|
* Converts the first character of `string` to upper case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the converted string. |
|
* @example |
|
* |
|
* _.upperFirst('fred'); |
|
* // => 'Fred' |
|
* |
|
* _.upperFirst('FRED'); |
|
* // => 'FRED' |
|
*/ |
|
var upperFirst = createCaseFirst('toUpperCase'); |
|
|
|
/** |
|
* Converts the first character of `string` to upper case and the remaining |
|
* to lower case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to capitalize. |
|
* @returns {string} Returns the capitalized string. |
|
* @example |
|
* |
|
* _.capitalize('FRED'); |
|
* // => 'Fred' |
|
*/ |
|
function capitalize(string) { |
|
return upperFirst(toString(string).toLowerCase()); |
|
} |
|
|
|
/** |
|
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the camel cased string. |
|
* @example |
|
* |
|
* _.camelCase('Foo Bar'); |
|
* // => 'fooBar' |
|
* |
|
* _.camelCase('--foo-bar'); |
|
* // => 'fooBar' |
|
* |
|
* _.camelCase('__foo_bar__'); |
|
* // => 'fooBar' |
|
*/ |
|
var camelCase = createCompounder(function(result, word, index) { |
|
word = word.toLowerCase(); |
|
return result + (index ? capitalize(word) : word); |
|
}); |
|
|
|
/** |
|
* Creates a function like `_.round`. |
|
* |
|
* @private |
|
* @param {string} methodName The name of the `Math` method to use when rounding. |
|
* @returns {Function} Returns the new round function. |
|
*/ |
|
function createRound(methodName) { |
|
var func = Math[methodName]; |
|
return function(number, precision) { |
|
precision = precision ? toInteger(precision) : 0; |
|
if (precision) { |
|
// Shift with exponential notation to avoid floating-point issues. |
|
// See [MDN](https://mdn.io/round#Examples) for more details. |
|
var pair = (+number + 'e').split('e'), |
|
value = func(pair[0] + 'e' + (+pair[1] + precision)); |
|
|
|
pair = (value + 'e').split('e'); |
|
return +(pair[0] + 'e' + (pair[1] - precision)); |
|
} |
|
return func(number); |
|
}; |
|
} |
|
|
|
/** |
|
* Calculates `number` rounded up to `precision`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {number} number The number to round up. |
|
* @param {number} [precision=0] The precision to round up to. |
|
* @returns {number} Returns the rounded up number. |
|
* @example |
|
* |
|
* _.ceil(4.006); |
|
* // => 5 |
|
* |
|
* _.ceil(6.004, 2); |
|
* // => 6.01 |
|
* |
|
* _.ceil(6040, -2); |
|
* // => 6100 |
|
*/ |
|
var ceil = createRound('ceil'); |
|
|
|
/** |
|
* Creates a `lodash` object that wraps `value` with explicit method chaining enabled. |
|
* The result of such method chaining must be unwrapped with `_#value`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Chain |
|
* @param {*} value The value to wrap. |
|
* @returns {Object} Returns the new `lodash` wrapper instance. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 40 }, |
|
* { 'user': 'pebbles', 'age': 1 } |
|
* ]; |
|
* |
|
* var youngest = _ |
|
* .chain(users) |
|
* .sortBy('age') |
|
* .map(function(o) { |
|
* return o.user + ' is ' + o.age; |
|
* }) |
|
* .head() |
|
* .value(); |
|
* // => 'pebbles is 1' |
|
*/ |
|
function chain(value) { |
|
var result = lodash(value); |
|
result.__chain__ = true; |
|
return result; |
|
} |
|
|
|
/** |
|
* Returns a number whose value is limited to the given range specified |
|
* by `min` and `max`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Number |
|
* @param {number} number The number whose value is to be limited. |
|
* @param {number} [min] The minimum possible value. |
|
* @param {number} max The maximum possible value. |
|
* @returns {number} A number in the range [min, max]. |
|
* @example |
|
* |
|
* _.clamp(-10, -5, 5); |
|
* // => -5 |
|
* |
|
* _.clamp(10, -5, 5); |
|
* // => 5 |
|
*/ |
|
function clamp(number, min, max) { |
|
number = +number; |
|
if (number === number) { |
|
if (max === undefined) { |
|
max = min; |
|
min = undefined; |
|
} |
|
if (max !== undefined) { |
|
max = +max; |
|
max = max === max ? max : 0; |
|
number = number <= max ? number : max; |
|
} |
|
if (min !== undefined) { |
|
min = +min; |
|
min = min === min ? min : 0; |
|
number = number >= min ? number : min; |
|
} |
|
} |
|
return number; |
|
} |
|
|
|
/** |
|
* Gets the index at which the first occurrence of `key` is found in `array` |
|
* of key-value pairs. |
|
* |
|
* @private |
|
* @param {Array} array The array to search. |
|
* @param {*} key The key to search for. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
*/ |
|
function assocIndexOf(array, key) { |
|
var length = array.length; |
|
while (length--) { |
|
if (array[length][0] === key) { |
|
return length; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var arrayProto$4 = Array.prototype; |
|
|
|
/** Built-in value references. */ |
|
var splice$2 = arrayProto$4.splice; |
|
|
|
/** |
|
* Removes `key` and its value from the associative array. |
|
* |
|
* @private |
|
* @param {Array} array The array to query. |
|
* @param {string} key The key of the value to remove. |
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`. |
|
*/ |
|
function assocDelete(array, key) { |
|
var index = assocIndexOf(array, key); |
|
if (index < 0) { |
|
return false; |
|
} |
|
var lastIndex = array.length - 1; |
|
if (index == lastIndex) { |
|
array.pop(); |
|
} else { |
|
splice$2.call(array, index, 1); |
|
} |
|
return true; |
|
} |
|
|
|
/** |
|
* Removes `key` and its value from the stack. |
|
* |
|
* @private |
|
* @name delete |
|
* @memberOf Stack |
|
* @param {string} key The key of the value to remove. |
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`. |
|
*/ |
|
function stackDelete(key) { |
|
var data = this.__data__, |
|
array = data.array; |
|
|
|
return array ? assocDelete(array, key) : data.map['delete'](key); |
|
} |
|
|
|
/** |
|
* Gets the associative array value for `key`. |
|
* |
|
* @private |
|
* @param {Array} array The array to query. |
|
* @param {string} key The key of the value to get. |
|
* @returns {*} Returns the entry value. |
|
*/ |
|
function assocGet(array, key) { |
|
var index = assocIndexOf(array, key); |
|
return index < 0 ? undefined : array[index][1]; |
|
} |
|
|
|
/** |
|
* Gets the stack value for `key`. |
|
* |
|
* @private |
|
* @name get |
|
* @memberOf Stack |
|
* @param {string} key The key of the value to get. |
|
* @returns {*} Returns the entry value. |
|
*/ |
|
function stackGet(key) { |
|
var data = this.__data__, |
|
array = data.array; |
|
|
|
return array ? assocGet(array, key) : data.map.get(key); |
|
} |
|
|
|
/** |
|
* Checks if an associative array value for `key` exists. |
|
* |
|
* @private |
|
* @param {Array} array The array to query. |
|
* @param {string} key The key of the entry to check. |
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. |
|
*/ |
|
function assocHas(array, key) { |
|
return assocIndexOf(array, key) > -1; |
|
} |
|
|
|
/** |
|
* Checks if a stack value for `key` exists. |
|
* |
|
* @private |
|
* @name has |
|
* @memberOf Stack |
|
* @param {string} key The key of the entry to check. |
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. |
|
*/ |
|
function stackHas(key) { |
|
var data = this.__data__, |
|
array = data.array; |
|
|
|
return array ? assocHas(array, key) : data.map.has(key); |
|
} |
|
|
|
/* Built-in method references that are verified to be native. */ |
|
var Map = getNative(root, 'Map'); |
|
|
|
/* Built-in method references that are verified to be native. */ |
|
var nativeCreate = getNative(Object, 'create'); |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$25 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$12 = objectProto$25.hasOwnProperty; |
|
|
|
/** |
|
* Checks if a hash value for `key` exists. |
|
* |
|
* @private |
|
* @param {Object} hash The hash to query. |
|
* @param {string} key The key of the entry to check. |
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. |
|
*/ |
|
function hashHas(hash, key) { |
|
return nativeCreate ? hash[key] !== undefined : hasOwnProperty$12.call(hash, key); |
|
} |
|
|
|
/** |
|
* Removes `key` and its value from the hash. |
|
* |
|
* @private |
|
* @param {Object} hash The hash to modify. |
|
* @param {string} key The key of the value to remove. |
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`. |
|
*/ |
|
function hashDelete(hash, key) { |
|
return hashHas(hash, key) && delete hash[key]; |
|
} |
|
|
|
/** |
|
* Checks if `value` is suitable for use as unique object key. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is suitable, else `false`. |
|
*/ |
|
function isKeyable(value) { |
|
var type = typeof value; |
|
return type == 'number' || type == 'boolean' || |
|
(type == 'string' && value !== '__proto__') || value == null; |
|
} |
|
|
|
/** |
|
* Removes `key` and its value from the map. |
|
* |
|
* @private |
|
* @name delete |
|
* @memberOf MapCache |
|
* @param {string} key The key of the value to remove. |
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`. |
|
*/ |
|
function mapDelete(key) { |
|
var data = this.__data__; |
|
if (isKeyable(key)) { |
|
return hashDelete(typeof key == 'string' ? data.string : data.hash, key); |
|
} |
|
return Map ? data.map['delete'](key) : assocDelete(data.map, key); |
|
} |
|
|
|
/** Used to stand-in for `undefined` hash values. */ |
|
var HASH_UNDEFINED$2 = '__lodash_hash_undefined__'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$24 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$11 = objectProto$24.hasOwnProperty; |
|
|
|
/** |
|
* Gets the hash value for `key`. |
|
* |
|
* @private |
|
* @param {Object} hash The hash to query. |
|
* @param {string} key The key of the value to get. |
|
* @returns {*} Returns the entry value. |
|
*/ |
|
function hashGet(hash, key) { |
|
if (nativeCreate) { |
|
var result = hash[key]; |
|
return result === HASH_UNDEFINED$2 ? undefined : result; |
|
} |
|
return hasOwnProperty$11.call(hash, key) ? hash[key] : undefined; |
|
} |
|
|
|
/** |
|
* Gets the map value for `key`. |
|
* |
|
* @private |
|
* @name get |
|
* @memberOf MapCache |
|
* @param {string} key The key of the value to get. |
|
* @returns {*} Returns the entry value. |
|
*/ |
|
function mapGet(key) { |
|
var data = this.__data__; |
|
if (isKeyable(key)) { |
|
return hashGet(typeof key == 'string' ? data.string : data.hash, key); |
|
} |
|
return Map ? data.map.get(key) : assocGet(data.map, key); |
|
} |
|
|
|
/** |
|
* Checks if a map value for `key` exists. |
|
* |
|
* @private |
|
* @name has |
|
* @memberOf MapCache |
|
* @param {string} key The key of the entry to check. |
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. |
|
*/ |
|
function mapHas(key) { |
|
var data = this.__data__; |
|
if (isKeyable(key)) { |
|
return hashHas(typeof key == 'string' ? data.string : data.hash, key); |
|
} |
|
return Map ? data.map.has(key) : assocHas(data.map, key); |
|
} |
|
|
|
/** |
|
* Sets the associative array `key` to `value`. |
|
* |
|
* @private |
|
* @param {Array} array The array to modify. |
|
* @param {string} key The key of the value to set. |
|
* @param {*} value The value to set. |
|
*/ |
|
function assocSet(array, key, value) { |
|
var index = assocIndexOf(array, key); |
|
if (index < 0) { |
|
array.push([key, value]); |
|
} else { |
|
array[index][1] = value; |
|
} |
|
} |
|
|
|
/** Used to stand-in for `undefined` hash values. */ |
|
var HASH_UNDEFINED$3 = '__lodash_hash_undefined__'; |
|
|
|
/** |
|
* Sets the hash `key` to `value`. |
|
* |
|
* @private |
|
* @param {Object} hash The hash to modify. |
|
* @param {string} key The key of the value to set. |
|
* @param {*} value The value to set. |
|
*/ |
|
function hashSet(hash, key, value) { |
|
hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$3 : value; |
|
} |
|
|
|
/** |
|
* Sets the map `key` to `value`. |
|
* |
|
* @private |
|
* @name set |
|
* @memberOf MapCache |
|
* @param {string} key The key of the value to set. |
|
* @param {*} value The value to set. |
|
* @returns {Object} Returns the map cache object. |
|
*/ |
|
function mapSet(key, value) { |
|
var data = this.__data__; |
|
if (isKeyable(key)) { |
|
hashSet(typeof key == 'string' ? data.string : data.hash, key, value); |
|
} else if (Map) { |
|
data.map.set(key, value); |
|
} else { |
|
assocSet(data.map, key, value); |
|
} |
|
return this; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$23 = Object.prototype; |
|
|
|
/** |
|
* Creates an hash object. |
|
* |
|
* @private |
|
* @returns {Object} Returns the new hash object. |
|
*/ |
|
function Hash() {} |
|
|
|
// Avoid inheriting from `Object.prototype` when possible. |
|
Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto$23; |
|
|
|
/** |
|
* Creates a map cache object to store key-value pairs. |
|
* |
|
* @private |
|
* @param {Array} [values] The values to cache. |
|
*/ |
|
function MapCache(values) { |
|
var index = -1, |
|
length = values ? values.length : 0; |
|
|
|
this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash }; |
|
while (++index < length) { |
|
var entry = values[index]; |
|
this.set(entry[0], entry[1]); |
|
} |
|
} |
|
|
|
// Add functions to the `MapCache`. |
|
MapCache.prototype['delete'] = mapDelete; |
|
MapCache.prototype.get = mapGet; |
|
MapCache.prototype.has = mapHas; |
|
MapCache.prototype.set = mapSet; |
|
|
|
/** Used as the size to enable large array optimizations. */ |
|
var LARGE_ARRAY_SIZE$4 = 200; |
|
|
|
/** |
|
* Sets the stack `key` to `value`. |
|
* |
|
* @private |
|
* @name set |
|
* @memberOf Stack |
|
* @param {string} key The key of the value to set. |
|
* @param {*} value The value to set. |
|
* @returns {Object} Returns the stack cache object. |
|
*/ |
|
function stackSet(key, value) { |
|
var data = this.__data__, |
|
array = data.array; |
|
|
|
if (array) { |
|
if (array.length < (LARGE_ARRAY_SIZE$4 - 1)) { |
|
assocSet(array, key, value); |
|
} else { |
|
data.array = null; |
|
data.map = new MapCache(array); |
|
} |
|
} |
|
var map = data.map; |
|
if (map) { |
|
map.set(key, value); |
|
} |
|
return this; |
|
} |
|
|
|
/** |
|
* Creates a stack cache object to store key-value pairs. |
|
* |
|
* @private |
|
* @param {Array} [values] The values to cache. |
|
*/ |
|
function Stack(values) { |
|
var index = -1, |
|
length = values ? values.length : 0; |
|
|
|
this.__data__ = { 'array': [], 'map': null }; |
|
while (++index < length) { |
|
var entry = values[index]; |
|
this.set(entry[0], entry[1]); |
|
} |
|
} |
|
|
|
// Add functions to the `Stack` cache. |
|
Stack.prototype['delete'] = stackDelete; |
|
Stack.prototype.get = stackGet; |
|
Stack.prototype.has = stackHas; |
|
Stack.prototype.set = stackSet; |
|
|
|
/** |
|
* The base implementation of `_.assign` without support for multiple sources |
|
* or `customizer` functions. |
|
* |
|
* @private |
|
* @param {Object} object The destination object. |
|
* @param {Object} source The source object. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function baseAssign(object, source) { |
|
return object && copyObject(source, keys(source), object); |
|
} |
|
|
|
/** |
|
* Creates a base function for methods like `_.forIn`. |
|
* |
|
* @private |
|
* @param {boolean} [fromRight] Specify iterating from right to left. |
|
* @returns {Function} Returns the new base function. |
|
*/ |
|
function createBaseFor(fromRight) { |
|
return function(object, iteratee, keysFunc) { |
|
var iterable = Object(object), |
|
props = keysFunc(object), |
|
length = props.length, |
|
index = fromRight ? length : -1; |
|
|
|
while ((fromRight ? index-- : ++index < length)) { |
|
var key = props[index]; |
|
if (iteratee(iterable[key], key, iterable) === false) { |
|
break; |
|
} |
|
} |
|
return object; |
|
}; |
|
} |
|
|
|
/** |
|
* The base implementation of `baseForIn` and `baseForOwn` which iterates |
|
* over `object` properties returned by `keysFunc` invoking `iteratee` for |
|
* 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. |
|
* @param {Function} keysFunc The function to get the keys of `object`. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
var baseFor = createBaseFor(); |
|
|
|
/** |
|
* The base implementation of `_.forOwn` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function baseForOwn(object, iteratee) { |
|
return object && baseFor(object, iteratee, keys); |
|
} |
|
|
|
/* Built-in method references that are verified to be native. */ |
|
var Set = getNative(root, 'Set'); |
|
|
|
var mapTag$3 = '[object Map]'; |
|
var objectTag$3 = '[object Object]'; |
|
var setTag$3 = '[object Set]'; |
|
/** Used for built-in method references. */ |
|
var objectProto$20 = Object.prototype; |
|
|
|
/** Used to resolve the decompiled source of functions. */ |
|
var fnToString$2 = Function.prototype.toString; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$10 = objectProto$20.toString; |
|
|
|
/** Used to detect maps and sets. */ |
|
var mapCtorString = Map ? fnToString$2.call(Map) : ''; |
|
var setCtorString = Set ? fnToString$2.call(Set) : ''; |
|
/** |
|
* Gets the `toStringTag` of `value`. |
|
* |
|
* @private |
|
* @param {*} value The value to query. |
|
* @returns {string} Returns the `toStringTag`. |
|
*/ |
|
function getTag(value) { |
|
return objToString$10.call(value); |
|
} |
|
|
|
// Fallback for IE 11 providing `toStringTag` values for maps and sets. |
|
if ((Map && getTag(new Map) != mapTag$3) || (Set && getTag(new Set) != setTag$3)) { |
|
getTag = function(value) { |
|
var result = objToString$10.call(value), |
|
Ctor = result == objectTag$3 ? value.constructor : null, |
|
ctorString = typeof Ctor == 'function' ? fnToString$2.call(Ctor) : ''; |
|
|
|
return ctorString == mapCtorString |
|
? mapTag$3 |
|
: (ctorString == setCtorString ? setTag$3 : result); |
|
}; |
|
} |
|
|
|
var getTag$1 = getTag; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$21 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$9 = objectProto$21.hasOwnProperty; |
|
|
|
/** |
|
* Initializes an array clone. |
|
* |
|
* @private |
|
* @param {Array} array The array to clone. |
|
* @returns {Array} Returns the initialized clone. |
|
*/ |
|
function initCloneArray(array) { |
|
var length = array.length, |
|
result = new array.constructor(length); |
|
|
|
// Add array properties assigned by `RegExp#exec`. |
|
if (length && typeof array[0] == 'string' && hasOwnProperty$9.call(array, 'index')) { |
|
result.index = array.index; |
|
result.input = array.input; |
|
} |
|
return result; |
|
} |
|
|
|
/** Built-in value references. */ |
|
var Uint8Array = root.Uint8Array; |
|
|
|
/** |
|
* Creates a clone of `buffer`. |
|
* |
|
* @private |
|
* @param {ArrayBuffer} buffer The array buffer to clone. |
|
* @returns {ArrayBuffer} Returns the cloned array buffer. |
|
*/ |
|
function cloneBuffer(buffer) { |
|
var Ctor = buffer.constructor, |
|
result = new Ctor(buffer.byteLength), |
|
view = new Uint8Array(result); |
|
|
|
view.set(new Uint8Array(buffer)); |
|
return result; |
|
} |
|
|
|
/** |
|
* Adds the key-value `pair` to `map`. |
|
* |
|
* @private |
|
* @param {Object} map The map to modify. |
|
* @param {Array} pair The key-value pair to add. |
|
* @returns {Object} Returns `map`. |
|
*/ |
|
function addMapEntry(map, pair) { |
|
map.set(pair[0], pair[1]); |
|
return map; |
|
} |
|
|
|
/** |
|
* Converts `map` to an array. |
|
* |
|
* @private |
|
* @param {Object} map The map to convert. |
|
* @returns {Array} Returns the converted array. |
|
*/ |
|
function mapToArray(map) { |
|
var index = -1, |
|
result = Array(map.size); |
|
|
|
map.forEach(function(value, key) { |
|
result[++index] = [key, value]; |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a clone of `map`. |
|
* |
|
* @private |
|
* @param {Object} map The map to clone. |
|
* @returns {Object} Returns the cloned map. |
|
*/ |
|
function cloneMap(map) { |
|
var Ctor = map.constructor; |
|
return arrayReduce(mapToArray(map), addMapEntry, new Ctor); |
|
} |
|
|
|
/** Used to match `RegExp` flags from their coerced string values. */ |
|
var reFlags$1 = /\w*$/; |
|
|
|
/** |
|
* Creates a clone of `regexp`. |
|
* |
|
* @private |
|
* @param {Object} regexp The regexp to clone. |
|
* @returns {Object} Returns the cloned regexp. |
|
*/ |
|
function cloneRegExp(regexp) { |
|
var Ctor = regexp.constructor, |
|
result = new Ctor(regexp.source, reFlags$1.exec(regexp)); |
|
|
|
result.lastIndex = regexp.lastIndex; |
|
return result; |
|
} |
|
|
|
/** |
|
* Adds `value` to `set`. |
|
* |
|
* @private |
|
* @param {Object} set The set to modify. |
|
* @param {*} value The value to add. |
|
* @returns {Object} Returns `set`. |
|
*/ |
|
function addSetEntry(set, value) { |
|
set.add(value); |
|
return set; |
|
} |
|
|
|
/** |
|
* Converts `set` to an array. |
|
* |
|
* @private |
|
* @param {Object} set The set to convert. |
|
* @returns {Array} Returns the converted array. |
|
*/ |
|
function setToArray(set) { |
|
var index = -1, |
|
result = Array(set.size); |
|
|
|
set.forEach(function(value) { |
|
result[++index] = value; |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a clone of `set`. |
|
* |
|
* @private |
|
* @param {Object} set The set to clone. |
|
* @returns {Object} Returns the cloned set. |
|
*/ |
|
function cloneSet(set) { |
|
var Ctor = set.constructor; |
|
return arrayReduce(setToArray(set), addSetEntry, new Ctor); |
|
} |
|
|
|
/** |
|
* Creates a clone of `typedArray`. |
|
* |
|
* @private |
|
* @param {Object} typedArray The typed array to clone. |
|
* @param {boolean} [isDeep] Specify a deep clone. |
|
* @returns {Object} Returns the cloned typed array. |
|
*/ |
|
function cloneTypedArray(typedArray, isDeep) { |
|
var buffer = typedArray.buffer, |
|
Ctor = typedArray.constructor; |
|
|
|
return new Ctor(isDeep ? cloneBuffer(buffer) : buffer, typedArray.byteOffset, typedArray.length); |
|
} |
|
|
|
var boolTag$3 = '[object Boolean]'; |
|
var dateTag$3 = '[object Date]'; |
|
var mapTag$4 = '[object Map]'; |
|
var numberTag$3 = '[object Number]'; |
|
var regexpTag$3 = '[object RegExp]'; |
|
var setTag$4 = '[object Set]'; |
|
var stringTag$3 = '[object String]'; |
|
var arrayBufferTag$2 = '[object ArrayBuffer]'; |
|
var float32Tag$2 = '[object Float32Array]'; |
|
var float64Tag$2 = '[object Float64Array]'; |
|
var int8Tag$2 = '[object Int8Array]'; |
|
var int16Tag$2 = '[object Int16Array]'; |
|
var int32Tag$2 = '[object Int32Array]'; |
|
var uint8Tag$2 = '[object Uint8Array]'; |
|
var uint8ClampedTag$2 = '[object Uint8ClampedArray]'; |
|
var uint16Tag$2 = '[object Uint16Array]'; |
|
var uint32Tag$2 = '[object Uint32Array]'; |
|
/** |
|
* 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. |
|
*/ |
|
function initCloneByTag(object, tag, isDeep) { |
|
var Ctor = object.constructor; |
|
switch (tag) { |
|
case arrayBufferTag$2: |
|
return cloneBuffer(object); |
|
|
|
case boolTag$3: |
|
case dateTag$3: |
|
return new Ctor(+object); |
|
|
|
case float32Tag$2: case float64Tag$2: |
|
case int8Tag$2: case int16Tag$2: case int32Tag$2: |
|
case uint8Tag$2: case uint8ClampedTag$2: case uint16Tag$2: case uint32Tag$2: |
|
return cloneTypedArray(object, isDeep); |
|
|
|
case mapTag$4: |
|
return cloneMap(object); |
|
|
|
case numberTag$3: |
|
case stringTag$3: |
|
return new Ctor(object); |
|
|
|
case setTag$4: |
|
return cloneSet(object); |
|
|
|
case regexpTag$3: |
|
return cloneRegExp(object); |
|
} |
|
} |
|
|
|
/** |
|
* Initializes an object clone. |
|
* |
|
* @private |
|
* @param {Object} object The object to clone. |
|
* @returns {Object} Returns the initialized clone. |
|
*/ |
|
function initCloneObject(object) { |
|
var Ctor = object.constructor; |
|
return (typeof Ctor == 'function' && Ctor instanceof Ctor) ? new Ctor : {}; |
|
} |
|
|
|
var argsTag$2 = '[object Arguments]'; |
|
var arrayTag$1 = '[object Array]'; |
|
var boolTag$2 = '[object Boolean]'; |
|
var dateTag$2 = '[object Date]'; |
|
var errorTag$2 = '[object Error]'; |
|
var funcTag$2 = '[object Function]'; |
|
var mapTag$2 = '[object Map]'; |
|
var numberTag$2 = '[object Number]'; |
|
var objectTag$2 = '[object Object]'; |
|
var regexpTag$2 = '[object RegExp]'; |
|
var setTag$2 = '[object Set]'; |
|
var stringTag$2 = '[object String]'; |
|
var weakMapTag$1 = '[object WeakMap]'; |
|
var arrayBufferTag$1 = '[object ArrayBuffer]'; |
|
var float32Tag$1 = '[object Float32Array]'; |
|
var float64Tag$1 = '[object Float64Array]'; |
|
var int8Tag$1 = '[object Int8Array]'; |
|
var int16Tag$1 = '[object Int16Array]'; |
|
var int32Tag$1 = '[object Int32Array]'; |
|
var uint8Tag$1 = '[object Uint8Array]'; |
|
var uint8ClampedTag$1 = '[object Uint8ClampedArray]'; |
|
var uint16Tag$1 = '[object Uint16Array]'; |
|
var uint32Tag$1 = '[object Uint32Array]'; |
|
/** Used to identify `toStringTag` values supported by `_.clone`. */ |
|
var cloneableTags = {}; |
|
cloneableTags[argsTag$2] = cloneableTags[arrayTag$1] = |
|
cloneableTags[arrayBufferTag$1] = cloneableTags[boolTag$2] = |
|
cloneableTags[dateTag$2] = cloneableTags[float32Tag$1] = |
|
cloneableTags[float64Tag$1] = cloneableTags[int8Tag$1] = |
|
cloneableTags[int16Tag$1] = cloneableTags[int32Tag$1] = |
|
cloneableTags[mapTag$2] = cloneableTags[numberTag$2] = |
|
cloneableTags[objectTag$2] = cloneableTags[regexpTag$2] = |
|
cloneableTags[setTag$2] = cloneableTags[stringTag$2] = |
|
cloneableTags[uint8Tag$1] = cloneableTags[uint8ClampedTag$1] = |
|
cloneableTags[uint16Tag$1] = cloneableTags[uint32Tag$1] = true; |
|
cloneableTags[errorTag$2] = cloneableTags[funcTag$2] = |
|
cloneableTags[weakMapTag$1] = false; |
|
|
|
/** |
|
* The base implementation of `_.clone` and `_.cloneDeep` which tracks |
|
* traversed objects. |
|
* |
|
* @private |
|
* @param {*} value The value to clone. |
|
* @param {boolean} [isDeep] Specify a deep clone. |
|
* @param {Function} [customizer] The function to customize cloning. |
|
* @param {string} [key] The key of `value`. |
|
* @param {Object} [object] The object `value` belongs to. |
|
* @param {Array} [stack] Tracks traversed sources and their clone counterparts. |
|
* @returns {*} Returns the cloned value. |
|
*/ |
|
function baseClone(value, isDeep, customizer, key, object, stack) { |
|
var result; |
|
if (customizer) { |
|
result = object ? customizer(value, key, object, stack) : customizer(value); |
|
} |
|
if (result !== undefined) { |
|
return result; |
|
} |
|
if (!isObject(value)) { |
|
return value; |
|
} |
|
var isArr = isArray(value); |
|
if (isArr) { |
|
result = initCloneArray(value); |
|
if (!isDeep) { |
|
return copyArray(value, result); |
|
} |
|
} else { |
|
var tag = getTag$1(value), |
|
isFunc = tag == funcTag$2; |
|
|
|
if (tag == objectTag$2 || tag == argsTag$2 || (isFunc && !object)) { |
|
if (isHostObject(value)) { |
|
return object ? value : {}; |
|
} |
|
result = initCloneObject(isFunc ? {} : value); |
|
if (!isDeep) { |
|
return baseAssign(result, value); |
|
} |
|
} else { |
|
return cloneableTags[tag] |
|
? initCloneByTag(value, tag, isDeep) |
|
: (object ? value : {}); |
|
} |
|
} |
|
// Check for circular references and return its corresponding clone. |
|
stack || (stack = new Stack); |
|
var stacked = stack.get(value); |
|
if (stacked) { |
|
return stacked; |
|
} |
|
stack.set(value, result); |
|
|
|
// Recursively populate clone (susceptible to call stack limits). |
|
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) { |
|
result[key] = baseClone(subValue, isDeep, customizer, key, value, stack); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a shallow clone of `value`. |
|
* |
|
* **Note:** This method is loosely based on the |
|
* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm). |
|
* The enumerable properties of `arguments` objects and objects created by |
|
* constructors other than `Object` are cloned to plain `Object` objects. An |
|
* empty object is returned for uncloneable values such as functions, DOM nodes, |
|
* Maps, Sets, and WeakMaps. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to clone. |
|
* @returns {*} Returns the cloned value. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney' }, |
|
* { 'user': 'fred' } |
|
* ]; |
|
* |
|
* var shallow = _.clone(users); |
|
* console.log(shallow[0] === users[0]); |
|
* // => true |
|
*/ |
|
function clone(value) { |
|
return baseClone(value); |
|
} |
|
|
|
/** |
|
* This method is like `_.clone` except that it recursively clones `value`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to recursively clone. |
|
* @returns {*} Returns the deep cloned value. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney' }, |
|
* { 'user': 'fred' } |
|
* ]; |
|
* |
|
* var deep = _.cloneDeep(users); |
|
* console.log(deep[0] === users[0]); |
|
* // => false |
|
*/ |
|
function cloneDeep(value) { |
|
return baseClone(value, true); |
|
} |
|
|
|
/** |
|
* This method is like `_.cloneWith` except that it recursively clones `value`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to recursively clone. |
|
* @param {Function} [customizer] The function to customize cloning. |
|
* @returns {*} Returns the deep cloned value. |
|
* @example |
|
* |
|
* function customizer(value) { |
|
* if (_.isElement(value)) { |
|
* return value.cloneNode(true); |
|
* } |
|
* } |
|
* |
|
* var el = _.cloneDeep(document.body, customizer); |
|
* |
|
* console.log(el === document.body); |
|
* // => false |
|
* console.log(el.nodeName); |
|
* // => BODY |
|
* console.log(el.childNodes.length); |
|
* // => 20 |
|
*/ |
|
function cloneDeepWith(value, customizer) { |
|
return baseClone(value, true, customizer); |
|
} |
|
|
|
/** |
|
* This method is like `_.clone` except that it accepts `customizer` which |
|
* is invoked to produce the cloned value. If `customizer` returns `undefined` |
|
* cloning is handled by the method instead. The `customizer` is invoked with |
|
* up to five arguments; (value [, index|key, object, stack]). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to clone. |
|
* @param {Function} [customizer] The function to customize cloning. |
|
* @returns {*} Returns the cloned value. |
|
* @example |
|
* |
|
* function customizer(value) { |
|
* if (_.isElement(value)) { |
|
* return value.cloneNode(false); |
|
* } |
|
* } |
|
* |
|
* var el = _.clone(document.body, customizer); |
|
* |
|
* console.log(el === document.body); |
|
* // => false |
|
* console.log(el.nodeName); |
|
* // => BODY |
|
* console.log(el.childNodes.length); |
|
* // => 0 |
|
*/ |
|
function cloneWith(value, customizer) { |
|
return baseClone(value, false, customizer); |
|
} |
|
|
|
/** |
|
* Executes the chained sequence and returns the wrapped result. |
|
* |
|
* @name commit |
|
* @memberOf _ |
|
* @category Chain |
|
* @returns {Object} Returns the new `lodash` wrapper instance. |
|
* @example |
|
* |
|
* var array = [1, 2]; |
|
* var wrapped = _(array).push(3); |
|
* |
|
* console.log(array); |
|
* // => [1, 2] |
|
* |
|
* wrapped = wrapped.commit(); |
|
* console.log(array); |
|
* // => [1, 2, 3] |
|
* |
|
* wrapped.last(); |
|
* // => 3 |
|
* |
|
* console.log(array); |
|
* // => [1, 2, 3] |
|
*/ |
|
function wrapperCommit() { |
|
return new LodashWrapper(this.value(), this.__chain__); |
|
} |
|
|
|
/** |
|
* Creates an array with all falsey values removed. The values `false`, `null`, |
|
* `0`, `""`, `undefined`, and `NaN` are falsey. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to compact. |
|
* @returns {Array} Returns the new array of filtered values. |
|
* @example |
|
* |
|
* _.compact([0, 1, false, 2, '', 3]); |
|
* // => [1, 2, 3] |
|
*/ |
|
function compact(array) { |
|
var index = -1, |
|
length = array ? array.length : 0, |
|
resIndex = -1, |
|
result = []; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
if (value) { |
|
result[++resIndex] = value; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a new array joining `array` with `other`. |
|
* |
|
* @private |
|
* @param {Array} array The array to join. |
|
* @param {Array} other The other array to join. |
|
* @returns {Array} Returns the new concatenated array. |
|
*/ |
|
function arrayConcat(array, other) { |
|
var index = -1, |
|
length = array.length, |
|
othIndex = -1, |
|
othLength = other.length, |
|
result = Array(length + othLength); |
|
|
|
while (++index < length) { |
|
result[index] = array[index]; |
|
} |
|
while (++othIndex < othLength) { |
|
result[index++] = other[othIndex]; |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a new array joining a wrapped array with any additional arrays |
|
* and/or values. |
|
* |
|
* @name concat |
|
* @memberOf _ |
|
* @category Chain |
|
* @param {...*} [values] The values to concatenate. |
|
* @returns {Array} Returns the new concatenated array. |
|
* @example |
|
* |
|
* var array = [1]; |
|
* var wrapped = _(array).concat(2, [3], [[4]]); |
|
* |
|
* console.log(wrapped.value()); |
|
* // => [1, 2, 3, [4]] |
|
* |
|
* console.log(array); |
|
* // => [1] |
|
*/ |
|
var wrapperConcat = rest(function(values) { |
|
values = baseFlatten(values); |
|
return this.thru(function(array) { |
|
return arrayConcat(isArray(array) ? array : [Object(array)], values); |
|
}); |
|
}); |
|
|
|
/** |
|
* Converts `iterator` to an array. |
|
* |
|
* @private |
|
* @param {Object} iterator The iterator to convert. |
|
* @returns {Array} Returns the converted array. |
|
*/ |
|
function iteratorToArray(iterator) { |
|
var data, |
|
result = []; |
|
|
|
while (!(data = iterator.next()).done) { |
|
result.push(data.value); |
|
} |
|
return result; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$19 = Object.prototype; |
|
|
|
/** Built-in value references. */ |
|
var Reflect = root.Reflect; |
|
var enumerate = Reflect ? Reflect.enumerate : undefined; |
|
var propertyIsEnumerable$1 = objectProto$19.propertyIsEnumerable; |
|
/** |
|
* The base implementation of `_.keysIn` which doesn't skip the constructor |
|
* property of prototypes or treat sparse arrays as dense. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the array of property names. |
|
*/ |
|
function baseKeysIn(object) { |
|
object = object == null ? object : Object(object); |
|
|
|
var result = []; |
|
for (var key in object) { |
|
result.push(key); |
|
} |
|
return result; |
|
} |
|
|
|
// Fallback for IE < 9 with es6-shim. |
|
if (enumerate && !propertyIsEnumerable$1.call({ 'valueOf': 1 }, 'valueOf')) { |
|
baseKeysIn = function(object) { |
|
return iteratorToArray(enumerate(object)); |
|
}; |
|
} |
|
|
|
var baseKeysIn$1 = baseKeysIn; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$14 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$5 = objectProto$14.hasOwnProperty; |
|
|
|
/** |
|
* Creates an array of the own and inherited enumerable property names of `object`. |
|
* |
|
* **Note:** Non-object values are coerced to objects. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the array of property names. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.keysIn(new Foo); |
|
* // => ['a', 'b', 'c'] (iteration order is not guaranteed) |
|
*/ |
|
function keysIn(object) { |
|
var index = -1, |
|
isProto = isPrototype(object), |
|
props = baseKeysIn$1(object), |
|
propsLength = props.length, |
|
result = initKeys(object), |
|
length = result.length, |
|
skipIndexes = !!length; |
|
|
|
while (++index < propsLength) { |
|
var key = props[index]; |
|
if (!(skipIndexes && isIndex(key, length)) && |
|
!(key == 'constructor' && (isProto || !hasOwnProperty$5.call(object, key)))) { |
|
result.push(key); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.conforms` which doesn't clone `source`. |
|
* |
|
* @private |
|
* @param {Object} source The object of property predicates to conform to. |
|
* @returns {Function} Returns the new function. |
|
*/ |
|
function baseConforms(source) { |
|
var props = keysIn(source), |
|
length = props.length; |
|
|
|
return function(object) { |
|
if (object == null) { |
|
return !length; |
|
} |
|
var index = length; |
|
while (index--) { |
|
var key = props[index], |
|
predicate = source[key], |
|
value = object[key]; |
|
|
|
if ((value === undefined && !(key in Object(object))) || !predicate(value)) { |
|
return false; |
|
} |
|
} |
|
return true; |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that invokes the predicate properties of `source` with |
|
* the corresponding property values of a given object, returning `true` if |
|
* all predicates return truthy, else `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Object} source The object of property predicates to conform to. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 40 } |
|
* ]; |
|
* |
|
* _.filter(users, _.conforms({ 'age': _.partial(_.gt, _, 38) })); |
|
* // => [{ 'user': 'fred', 'age': 40 }] |
|
*/ |
|
function conforms(source) { |
|
return baseConforms(baseClone(source, true)); |
|
} |
|
|
|
/** |
|
* A specialized version of `_.every` for arrays without support for |
|
* callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. |
|
*/ |
|
function arrayEvery(array, predicate) { |
|
var index = -1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
if (!predicate(array[index], index, array)) { |
|
return false; |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
/** |
|
* A specialized version of `_.map` for arrays without support for callback |
|
* shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Array} Returns the new mapped array. |
|
*/ |
|
function arrayMap(array, iteratee) { |
|
var index = -1, |
|
length = array.length, |
|
result = Array(length); |
|
|
|
while (++index < length) { |
|
result[index] = iteratee(array[index], index, array); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* A specialized version of `_.some` for arrays without support for callback |
|
* shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. |
|
*/ |
|
function arraySome(array, predicate) { |
|
var index = -1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
if (predicate(array[index], index, array)) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
var UNORDERED_COMPARE_FLAG$2 = 1; |
|
var PARTIAL_COMPARE_FLAG$3 = 2; |
|
/** |
|
* A specialized version of `baseIsEqualDeep` for arrays with support for |
|
* partial deep comparisons. |
|
* |
|
* @private |
|
* @param {Array} array The array to compare. |
|
* @param {Array} other The other array to compare. |
|
* @param {Function} equalFunc The function to determine equivalents of values. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details. |
|
* @param {Array} [stack] Tracks traversed `value` and `other` objects. |
|
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. |
|
*/ |
|
function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { |
|
var index = -1, |
|
isPartial = bitmask & PARTIAL_COMPARE_FLAG$3, |
|
isUnordered = bitmask & UNORDERED_COMPARE_FLAG$2, |
|
arrLength = array.length, |
|
othLength = other.length; |
|
|
|
if (arrLength != othLength && !(isPartial && othLength > arrLength)) { |
|
return false; |
|
} |
|
// Ignore non-index properties. |
|
while (++index < arrLength) { |
|
var arrValue = array[index], |
|
othValue = other[index]; |
|
|
|
if (customizer) { |
|
var result = isPartial |
|
? customizer(othValue, arrValue, index, other, array, stack) |
|
: customizer(arrValue, othValue, index, array, other, stack); |
|
} |
|
if (result !== undefined) { |
|
if (result) { |
|
continue; |
|
} |
|
return false; |
|
} |
|
// Recursively compare arrays (susceptible to call stack limits). |
|
if (isUnordered) { |
|
if (!arraySome(other, function(othValue) { |
|
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack); |
|
})) { |
|
return false; |
|
} |
|
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) { |
|
return false; |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
var UNORDERED_COMPARE_FLAG$3 = 1; |
|
var PARTIAL_COMPARE_FLAG$4 = 2; |
|
var boolTag$4 = '[object Boolean]'; |
|
var dateTag$4 = '[object Date]'; |
|
var errorTag$3 = '[object Error]'; |
|
var mapTag$5 = '[object Map]'; |
|
var numberTag$4 = '[object Number]'; |
|
var regexpTag$4 = '[object RegExp]'; |
|
var setTag$5 = '[object Set]'; |
|
var stringTag$4 = '[object String]'; |
|
/** |
|
* A specialized version of `baseIsEqualDeep` for comparing objects of |
|
* the same `toStringTag`. |
|
* |
|
* **Note:** This function only supports comparing values with tags of |
|
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. |
|
* |
|
* @private |
|
* @param {Object} object The object to compare. |
|
* @param {Object} other The other object to compare. |
|
* @param {string} tag The `toStringTag` of the objects to compare. |
|
* @param {Function} equalFunc The function to determine equivalents of values. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details. |
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`. |
|
*/ |
|
function equalByTag(object, other, tag, equalFunc, customizer, bitmask) { |
|
switch (tag) { |
|
case boolTag$4: |
|
case dateTag$4: |
|
// Coerce dates and booleans to numbers, dates to milliseconds and booleans |
|
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal. |
|
return +object == +other; |
|
|
|
case errorTag$3: |
|
return object.name == other.name && object.message == other.message; |
|
|
|
case numberTag$4: |
|
// Treat `NaN` vs. `NaN` as equal. |
|
return (object != +object) ? other != +other : object == +other; |
|
|
|
case regexpTag$4: |
|
case stringTag$4: |
|
// Coerce regexes to strings and treat strings primitives and string |
|
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details. |
|
return object == (other + ''); |
|
|
|
case mapTag$5: |
|
var convert = mapToArray; |
|
|
|
case setTag$5: |
|
var isPartial = bitmask & PARTIAL_COMPARE_FLAG$4; |
|
convert || (convert = setToArray); |
|
|
|
// Recursively compare objects (susceptible to call stack limits). |
|
return (isPartial || object.size == other.size) && |
|
equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG$3); |
|
} |
|
return false; |
|
} |
|
|
|
var UNORDERED_COMPARE_FLAG$4 = 1; |
|
var PARTIAL_COMPARE_FLAG$5 = 2; |
|
/** |
|
* A specialized version of `baseIsEqualDeep` for objects with support for |
|
* partial deep comparisons. |
|
* |
|
* @private |
|
* @param {Object} object The object to compare. |
|
* @param {Object} other The other object to compare. |
|
* @param {Function} equalFunc The function to determine equivalents of values. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details. |
|
* @param {Array} [stack] Tracks traversed `value` and `other` objects. |
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`. |
|
*/ |
|
function equalObjects(object, other, equalFunc, customizer, bitmask, stack) { |
|
var isPartial = bitmask & PARTIAL_COMPARE_FLAG$5, |
|
isUnordered = bitmask & UNORDERED_COMPARE_FLAG$4, |
|
objProps = keys(object), |
|
objLength = objProps.length, |
|
othProps = keys(other), |
|
othLength = othProps.length; |
|
|
|
if (objLength != othLength && !isPartial) { |
|
return false; |
|
} |
|
var index = objLength; |
|
while (index--) { |
|
var key = objProps[index]; |
|
if (!(isPartial ? key in other : baseHas(other, key)) || |
|
!(isUnordered || key == othProps[index])) { |
|
return false; |
|
} |
|
} |
|
var skipCtor = isPartial; |
|
while (++index < objLength) { |
|
key = objProps[index]; |
|
var objValue = object[key], |
|
othValue = other[key]; |
|
|
|
if (customizer) { |
|
var result = isPartial |
|
? customizer(othValue, objValue, key, other, object, stack) |
|
: customizer(objValue, othValue, key, object, other, stack); |
|
} |
|
// Recursively compare objects (susceptible to call stack limits). |
|
if (!(result === undefined |
|
? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack)) |
|
: result |
|
)) { |
|
return false; |
|
} |
|
skipCtor || (skipCtor = key == 'constructor'); |
|
} |
|
if (!skipCtor) { |
|
var objCtor = object.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)) { |
|
return false; |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
var argsTag$1 = '[object Arguments]'; |
|
var arrayTag = '[object Array]'; |
|
var boolTag$1 = '[object Boolean]'; |
|
var dateTag$1 = '[object Date]'; |
|
var errorTag$1 = '[object Error]'; |
|
var funcTag$1 = '[object Function]'; |
|
var mapTag = '[object Map]'; |
|
var numberTag$1 = '[object Number]'; |
|
var objectTag$1 = '[object Object]'; |
|
var regexpTag$1 = '[object RegExp]'; |
|
var setTag = '[object Set]'; |
|
var stringTag$1 = '[object String]'; |
|
var weakMapTag = '[object WeakMap]'; |
|
var arrayBufferTag = '[object ArrayBuffer]'; |
|
var float32Tag = '[object Float32Array]'; |
|
var float64Tag = '[object Float64Array]'; |
|
var int8Tag = '[object Int8Array]'; |
|
var int16Tag = '[object Int16Array]'; |
|
var int32Tag = '[object Int32Array]'; |
|
var uint8Tag = '[object Uint8Array]'; |
|
var uint8ClampedTag = '[object Uint8ClampedArray]'; |
|
var uint16Tag = '[object Uint16Array]'; |
|
var uint32Tag = '[object Uint32Array]'; |
|
/** Used to identify `toStringTag` values of typed arrays. */ |
|
var typedArrayTags = {}; |
|
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = |
|
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = |
|
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = |
|
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = |
|
typedArrayTags[uint32Tag] = true; |
|
typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] = |
|
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag$1] = |
|
typedArrayTags[dateTag$1] = typedArrayTags[errorTag$1] = |
|
typedArrayTags[funcTag$1] = typedArrayTags[mapTag] = |
|
typedArrayTags[numberTag$1] = typedArrayTags[objectTag$1] = |
|
typedArrayTags[regexpTag$1] = typedArrayTags[setTag] = |
|
typedArrayTags[stringTag$1] = typedArrayTags[weakMapTag] = false; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$13 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$9 = objectProto$13.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a typed array. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isTypedArray(new Uint8Array); |
|
* // => true |
|
* |
|
* _.isTypedArray([]); |
|
* // => false |
|
*/ |
|
function isTypedArray(value) { |
|
return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString$9.call(value)]; |
|
} |
|
|
|
/** Used to compose bitmasks for comparison styles. */ |
|
var PARTIAL_COMPARE_FLAG$2 = 2; |
|
|
|
/** `Object#toString` result references. */ |
|
var argsTag$3 = '[object Arguments]'; |
|
var arrayTag$2 = '[object Array]'; |
|
var objectTag$4 = '[object Object]'; |
|
/** Used for built-in method references. */ |
|
var objectProto$22 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$10 = objectProto$22.hasOwnProperty; |
|
|
|
/** |
|
* A specialized version of `baseIsEqual` for arrays and objects which performs |
|
* deep comparisons and tracks traversed objects enabling objects with circular |
|
* references to be compared. |
|
* |
|
* @private |
|
* @param {Object} object The object to compare. |
|
* @param {Object} other The other object to compare. |
|
* @param {Function} equalFunc The function to determine equivalents of values. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details. |
|
* @param {Array} [stack] Tracks traversed `value` and `other` objects. |
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`. |
|
*/ |
|
function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) { |
|
var objIsArr = isArray(object), |
|
othIsArr = isArray(other), |
|
objTag = arrayTag$2, |
|
othTag = arrayTag$2; |
|
|
|
if (!objIsArr) { |
|
objTag = getTag$1(object); |
|
if (objTag == argsTag$3) { |
|
objTag = objectTag$4; |
|
} else if (objTag != objectTag$4) { |
|
objIsArr = isTypedArray(object); |
|
} |
|
} |
|
if (!othIsArr) { |
|
othTag = getTag$1(other); |
|
if (othTag == argsTag$3) { |
|
othTag = objectTag$4; |
|
} else if (othTag != objectTag$4) { |
|
othIsArr = isTypedArray(other); |
|
} |
|
} |
|
var objIsObj = objTag == objectTag$4 && !isHostObject(object), |
|
othIsObj = othTag == objectTag$4 && !isHostObject(other), |
|
isSameTag = objTag == othTag; |
|
|
|
if (isSameTag && !(objIsArr || objIsObj)) { |
|
return equalByTag(object, other, objTag, equalFunc, customizer, bitmask); |
|
} |
|
var isPartial = bitmask & PARTIAL_COMPARE_FLAG$2; |
|
if (!isPartial) { |
|
var objIsWrapped = objIsObj && hasOwnProperty$10.call(object, '__wrapped__'), |
|
othIsWrapped = othIsObj && hasOwnProperty$10.call(other, '__wrapped__'); |
|
|
|
if (objIsWrapped || othIsWrapped) { |
|
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack); |
|
} |
|
} |
|
if (!isSameTag) { |
|
return false; |
|
} |
|
// Assume cyclic values are equal. |
|
// For more information on detecting circular references see https://es5.github.io/#JO. |
|
stack || (stack = new Stack); |
|
var stacked = stack.get(object); |
|
if (stacked) { |
|
return stacked == other; |
|
} |
|
stack.set(object, other); |
|
|
|
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack); |
|
|
|
stack['delete'](object); |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.isEqual` which supports partial comparisons |
|
* and tracks traversed objects. |
|
* |
|
* @private |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @param {boolean} [bitmask] The bitmask of comparison flags. |
|
* The bitmask may be composed of the following flags: |
|
* 1 - Unordered comparison |
|
* 2 - Partial comparison |
|
* @param {Array} [stack] Tracks traversed `value` and `other` objects. |
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. |
|
*/ |
|
function baseIsEqual(value, other, customizer, bitmask, stack) { |
|
if (value === other) { |
|
return true; |
|
} |
|
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) { |
|
return value !== value && other !== other; |
|
} |
|
return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack); |
|
} |
|
|
|
var UNORDERED_COMPARE_FLAG = 1; |
|
var PARTIAL_COMPARE_FLAG = 2; |
|
/** |
|
* The base implementation of `_.isMatch` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Object} object The object to inspect. |
|
* @param {Object} source The object of property values to match. |
|
* @param {Array} matchData The property names, values, and compare flags to match. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`. |
|
*/ |
|
function baseIsMatch(object, source, matchData, customizer) { |
|
var index = matchData.length, |
|
length = index, |
|
noCustomizer = !customizer; |
|
|
|
if (object == null) { |
|
return !length; |
|
} |
|
object = Object(object); |
|
while (index--) { |
|
var data = matchData[index]; |
|
if ((noCustomizer && data[2]) |
|
? data[1] !== object[data[0]] |
|
: !(data[0] in object) |
|
) { |
|
return false; |
|
} |
|
} |
|
while (++index < length) { |
|
data = matchData[index]; |
|
var key = data[0], |
|
objValue = object[key], |
|
srcValue = data[1]; |
|
|
|
if (noCustomizer && data[2]) { |
|
if (objValue === undefined && !(key in object)) { |
|
return false; |
|
} |
|
} else { |
|
var stack = new Stack, |
|
result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined; |
|
|
|
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) { |
|
return false; |
|
} |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
/** |
|
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`. |
|
* |
|
* @private |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` if suitable for strict |
|
* equality comparisons, else `false`. |
|
*/ |
|
function isStrictComparable(value) { |
|
return value === value && !isObject(value); |
|
} |
|
|
|
/** |
|
* Creates an array of the key-value pairs for `object`, |
|
* e.g. `[[key1, value1], [key2, value2]]`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @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) |
|
*/ |
|
function pairs(object) { |
|
return arrayMap(keys(object), function(key) { |
|
return [key, object[key]]; |
|
}); |
|
} |
|
|
|
/** |
|
* Gets the property names, values, and compare flags of `object`. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the match data of `object`. |
|
*/ |
|
function getMatchData(object) { |
|
var result = pairs(object), |
|
length = result.length; |
|
|
|
while (length--) { |
|
result[length][2] = isStrictComparable(result[length][1]); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.matches` which doesn't clone `source`. |
|
* |
|
* @private |
|
* @param {Object} source The object of property values to match. |
|
* @returns {Function} Returns the new function. |
|
*/ |
|
function baseMatches(source) { |
|
var matchData = getMatchData(source); |
|
if (matchData.length == 1 && matchData[0][2]) { |
|
var key = matchData[0][0], |
|
value = matchData[0][1]; |
|
|
|
return function(object) { |
|
if (object == null) { |
|
return false; |
|
} |
|
return object[key] === value && |
|
(value !== undefined || (key in Object(object))); |
|
}; |
|
} |
|
return function(object) { |
|
return object === source || baseIsMatch(object, source, matchData); |
|
}; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.hasIn` without support for deep paths. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {Array|string} key The key to check. |
|
* @returns {boolean} Returns `true` if `key` exists, else `false`. |
|
*/ |
|
function baseHasIn(object, key) { |
|
return key in Object(object); |
|
} |
|
|
|
/** |
|
* Gets the last element of `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @returns {*} Returns the last element of `array`. |
|
* @example |
|
* |
|
* _.last([1, 2, 3]); |
|
* // => 3 |
|
*/ |
|
function last(array) { |
|
var length = array ? array.length : 0; |
|
return length ? array[length - 1] : undefined; |
|
} |
|
|
|
/** |
|
* Gets the parent value at `path` of `object`. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {Array} path The path to get the parent value of. |
|
* @returns {*} Returns the parent value. |
|
*/ |
|
function parent$1(object, path) { |
|
return path.length == 1 ? object : get(object, baseSlice(path, 0, -1)); |
|
} |
|
|
|
/** |
|
* Checks if `path` exists on `object`. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {Array|string} path The path to check. |
|
* @param {Function} hasFunc The function to check properties. |
|
* @returns {boolean} Returns `true` if `path` exists, else `false`. |
|
*/ |
|
function hasPath(object, path, hasFunc) { |
|
if (object == null) { |
|
return false; |
|
} |
|
var result = hasFunc(object, path); |
|
if (!result && !isKey(path)) { |
|
path = baseToPath(path); |
|
object = parent$1(object, path); |
|
if (object != null) { |
|
path = last(path); |
|
result = hasFunc(object, path); |
|
} |
|
} |
|
return result || (isLength(object && object.length) && isIndex(path, object.length) && |
|
(isArray(object) || isString(object) || isArguments(object))); |
|
} |
|
|
|
/** |
|
* Checks if `path` is a direct or inherited property of `object`. |
|
* |
|
* @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` exists, else `false`. |
|
* @example |
|
* |
|
* var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) }); |
|
* |
|
* _.hasIn(object, 'a'); |
|
* // => true |
|
* |
|
* _.hasIn(object, 'a.b.c'); |
|
* // => true |
|
* |
|
* _.hasIn(object, ['a', 'b', 'c']); |
|
* // => true |
|
* |
|
* _.hasIn(object, 'b'); |
|
* // => false |
|
*/ |
|
function hasIn(object, path) { |
|
return hasPath(object, path, baseHasIn); |
|
} |
|
|
|
var UNORDERED_COMPARE_FLAG$1 = 1; |
|
var PARTIAL_COMPARE_FLAG$1 = 2; |
|
/** |
|
* The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. |
|
* |
|
* @private |
|
* @param {string} path The path of the property to get. |
|
* @param {*} srcValue The value to match. |
|
* @returns {Function} Returns the new function. |
|
*/ |
|
function baseMatchesProperty(path, srcValue) { |
|
return function(object) { |
|
var objValue = get(object, path); |
|
return (objValue === undefined && objValue === srcValue) |
|
? hasIn(object, path) |
|
: baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG$1 | PARTIAL_COMPARE_FLAG$1); |
|
}; |
|
} |
|
|
|
/** |
|
* 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) { |
|
return function(object) { |
|
return baseGet(object, path); |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a function that returns the value at `path` of a given object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Array|string} path The path of the property to get. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var objects = [ |
|
* { 'a': { 'b': { 'c': 2 } } }, |
|
* { 'a': { 'b': { 'c': 1 } } } |
|
* ]; |
|
* |
|
* _.map(objects, _.property('a.b.c')); |
|
* // => [2, 1] |
|
* |
|
* _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c'); |
|
* // => [1, 2] |
|
*/ |
|
function property(path) { |
|
return isKey(path) ? baseProperty(path) : basePropertyDeep(path); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.iteratee`. |
|
* |
|
* @private |
|
* @param {*} [value=_.identity] The value to convert to an iteratee. |
|
* @returns {Function} Returns the iteratee. |
|
*/ |
|
function baseIteratee(value) { |
|
var type = typeof value; |
|
if (type == 'function') { |
|
return value; |
|
} |
|
if (value == null) { |
|
return identity; |
|
} |
|
if (type == 'object') { |
|
return isArray(value) |
|
? baseMatchesProperty(value[0], value[1]) |
|
: baseMatches(value); |
|
} |
|
return property(value); |
|
} |
|
|
|
/** |
|
* Creates a function like `_.conj`. |
|
* |
|
* @private |
|
* @param {Function} arrayFunc The function to iterate over iteratees. |
|
* @returns {Function} Returns the new invoker function. |
|
*/ |
|
function createInvoker(arrayFunc) { |
|
return rest(function(iteratees) { |
|
iteratees = arrayMap(baseFlatten(iteratees), baseIteratee); |
|
return rest(function(args) { |
|
var thisArg = this; |
|
return arrayFunc(iteratees, function(iteratee) { |
|
return iteratee.apply(thisArg, args); |
|
}); |
|
}); |
|
}); |
|
} |
|
|
|
/** |
|
* Creates a function that checks if **all** of the `predicates` return |
|
* truthy when invoked with the arguments provided to the created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {...(Function|Function[])} predicates The predicates to check. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var conjed = _.conj(Boolean, isFinite); |
|
* |
|
* conjed('1'); |
|
* // => true |
|
* |
|
* conjed(null); |
|
* // => false |
|
* |
|
* conjed(NaN); |
|
* // => false |
|
*/ |
|
var conj = createInvoker(arrayEvery); |
|
|
|
/** |
|
* Creates a function that returns `value`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {*} value The value to return from the new function. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred' }; |
|
* var getter = _.constant(object); |
|
* |
|
* getter() === object; |
|
* // => true |
|
*/ |
|
function constant(value) { |
|
return function() { |
|
return value; |
|
}; |
|
} |
|
|
|
/** |
|
* Creates a `baseEach` or `baseEachRight` function. |
|
* |
|
* @private |
|
* @param {Function} eachFunc The function to iterate over a collection. |
|
* @param {boolean} [fromRight] Specify iterating from right to left. |
|
* @returns {Function} Returns the new base function. |
|
*/ |
|
function createBaseEach(eachFunc, fromRight) { |
|
return function(collection, iteratee) { |
|
if (collection == null) { |
|
return collection; |
|
} |
|
if (!isArrayLike(collection)) { |
|
return eachFunc(collection, iteratee); |
|
} |
|
var length = collection.length, |
|
index = fromRight ? length : -1, |
|
iterable = Object(collection); |
|
|
|
while ((fromRight ? index-- : ++index < length)) { |
|
if (iteratee(iterable[index], index, iterable) === false) { |
|
break; |
|
} |
|
} |
|
return collection; |
|
}; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.forEach` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Array|Object} Returns `collection`. |
|
*/ |
|
var baseEach = createBaseEach(baseForOwn); |
|
|
|
/** |
|
* Creates a function like `_.groupBy`. |
|
* |
|
* @private |
|
* @param {Function} setter The function to set keys and values of the accumulator object. |
|
* @param {Function} [initializer] The function to initialize the accumulator object. |
|
* @returns {Function} Returns the new aggregator function. |
|
*/ |
|
function createAggregator(setter, initializer) { |
|
return function(collection, iteratee) { |
|
var result = initializer ? initializer() : {}; |
|
iteratee = baseIteratee(iteratee); |
|
|
|
if (isArray(collection)) { |
|
var index = -1, |
|
length = collection.length; |
|
|
|
while (++index < length) { |
|
var value = collection[index]; |
|
setter(result, value, iteratee(value), collection); |
|
} |
|
} else { |
|
baseEach(collection, function(value, key, collection) { |
|
setter(result, value, iteratee(value), collection); |
|
}); |
|
} |
|
return result; |
|
}; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty = objectProto.hasOwnProperty; |
|
|
|
/** |
|
* Creates an object composed of keys generated from the results of running |
|
* each element of `collection` through `iteratee`. The corresponding value |
|
* of each key is the number of times the key was returned by `iteratee`. |
|
* The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Object} Returns the composed aggregate object. |
|
* @example |
|
* |
|
* _.countBy([6.1, 4.2, 6.3], Math.floor); |
|
* // => { '4': 1, '6': 2 } |
|
* |
|
* _.countBy(['one', 'two', 'three'], 'length'); |
|
* // => { '3': 2, '5': 1 } |
|
*/ |
|
var countBy = createAggregator(function(result, value, key) { |
|
hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1); |
|
}); |
|
|
|
/** |
|
* 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. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} prototype The object to inherit from. |
|
* @param {Object} [properties] The properties to assign to the object. |
|
* @returns {Object} Returns the new object. |
|
* @example |
|
* |
|
* function Shape() { |
|
* this.x = 0; |
|
* this.y = 0; |
|
* } |
|
* |
|
* function Circle() { |
|
* Shape.call(this); |
|
* } |
|
* |
|
* Circle.prototype = _.create(Shape.prototype, { |
|
* 'constructor': Circle |
|
* }); |
|
* |
|
* var circle = new Circle; |
|
* circle instanceof Circle; |
|
* // => true |
|
* |
|
* circle instanceof Shape; |
|
* // => true |
|
*/ |
|
function create(prototype, properties) { |
|
var result = baseCreate(prototype); |
|
return properties ? baseAssign(result, properties) : result; |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var CURRY_FLAG = 8; |
|
|
|
/** |
|
* Creates a function that accepts one or more arguments of `func` that when |
|
* called either invokes `func` returning its result, if all `func` arguments |
|
* have been provided, or returns a function that accepts one or more of the |
|
* remaining `func` arguments, and so on. The arity of `func` may be specified |
|
* 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 doesn't set the "length" property of curried functions. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to curry. |
|
* @param {number} [arity=func.length] The arity of `func`. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Function} Returns the new curried function. |
|
* @example |
|
* |
|
* var abc = function(a, b, c) { |
|
* return [a, b, c]; |
|
* }; |
|
* |
|
* var curried = _.curry(abc); |
|
* |
|
* curried(1)(2)(3); |
|
* // => [1, 2, 3] |
|
* |
|
* curried(1, 2)(3); |
|
* // => [1, 2, 3] |
|
* |
|
* curried(1, 2, 3); |
|
* // => [1, 2, 3] |
|
* |
|
* // using placeholders |
|
* curried(1)(_, 3)(2); |
|
* // => [1, 2, 3] |
|
*/ |
|
function curry(func, arity, guard) { |
|
arity = guard ? undefined : arity; |
|
var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); |
|
result.placeholder = curry.placeholder; |
|
return result; |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var CURRY_RIGHT_FLAG = 16; |
|
|
|
/** |
|
* This method is like `_.curry` except that arguments are applied to `func` |
|
* 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 doesn't set the "length" property of curried functions. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to curry. |
|
* @param {number} [arity=func.length] The arity of `func`. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Function} Returns the new curried function. |
|
* @example |
|
* |
|
* var abc = function(a, b, c) { |
|
* return [a, b, c]; |
|
* }; |
|
* |
|
* var curried = _.curryRight(abc); |
|
* |
|
* curried(3)(2)(1); |
|
* // => [1, 2, 3] |
|
* |
|
* curried(2, 3)(1); |
|
* // => [1, 2, 3] |
|
* |
|
* curried(1, 2, 3); |
|
* // => [1, 2, 3] |
|
* |
|
* // using placeholders |
|
* curried(3)(1, _)(2); |
|
* // => [1, 2, 3] |
|
*/ |
|
function curryRight(func, arity, guard) { |
|
arity = guard ? undefined : arity; |
|
var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); |
|
result.placeholder = curryRight.placeholder; |
|
return result; |
|
} |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$2 = 'Expected a function'; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$1 = Math.max; |
|
|
|
/** |
|
* Creates a debounced function that delays invoking `func` until after `wait` |
|
* milliseconds have elapsed since the last time the debounced function was |
|
* invoked. The debounced function comes with a `cancel` method to cancel |
|
* delayed `func` invocations and a `flush` method to immediately invoke them. |
|
* Provide an options object to indicate that `func` should be invoked on the |
|
* leading and/or trailing edge of the `wait` timeout. Subsequent calls to the |
|
* debounced function return the result of the last `func` invocation. |
|
* |
|
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked |
|
* on the trailing edge of the timeout only if the the debounced function is |
|
* invoked more than once during the `wait` timeout. |
|
* |
|
* See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation) |
|
* for details over the differences between `_.debounce` and `_.throttle`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to debounce. |
|
* @param {number} [wait=0] The number of milliseconds to delay. |
|
* @param {Object} [options] The options object. |
|
* @param {boolean} [options.leading=false] Specify invoking on the leading |
|
* edge of the timeout. |
|
* @param {number} [options.maxWait] The maximum time `func` is allowed to be |
|
* delayed before it's invoked. |
|
* @param {boolean} [options.trailing=true] Specify invoking on the trailing |
|
* edge of the timeout. |
|
* @returns {Function} Returns the new debounced function. |
|
* @example |
|
* |
|
* // avoid costly calculations while the window size is in flux |
|
* jQuery(window).on('resize', _.debounce(calculateLayout, 150)); |
|
* |
|
* // invoke `sendMail` when the click event is fired, debouncing subsequent calls |
|
* jQuery('#postbox').on('click', _.debounce(sendMail, 300, { |
|
* 'leading': true, |
|
* 'trailing': false |
|
* })); |
|
* |
|
* // ensure `batchLog` is invoked once after 1 second of debounced calls |
|
* var source = new EventSource('/stream'); |
|
* jQuery(source).on('message', _.debounce(batchLog, 250, { |
|
* 'maxWait': 1000 |
|
* })); |
|
* |
|
* // cancel a debounced call |
|
* var todoChanges = _.debounce(batchLog, 1000); |
|
* Object.observe(models.todo, todoChanges); |
|
* |
|
* Object.observe(models, function(changes) { |
|
* if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) { |
|
* todoChanges.cancel(); |
|
* } |
|
* }, ['delete']); |
|
* |
|
* // ...at some point `models.todo` is changed |
|
* models.todo.completed = true; |
|
* |
|
* // ...before 1 second has passed `models.todo` is deleted |
|
* // which cancels the debounced `todoChanges` call |
|
* delete models.todo; |
|
*/ |
|
function debounce(func, wait, options) { |
|
var args, |
|
maxTimeoutId, |
|
result, |
|
stamp, |
|
thisArg, |
|
timeoutId, |
|
trailingCall, |
|
lastCalled = 0, |
|
leading = false, |
|
maxWait = false, |
|
trailing = true; |
|
|
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$2); |
|
} |
|
wait = wait < 0 ? 0 : (+wait || 0); |
|
if (isObject(options)) { |
|
leading = !!options.leading; |
|
maxWait = 'maxWait' in options && nativeMax$1(+options.maxWait || 0, wait); |
|
trailing = 'trailing' in options ? !!options.trailing : trailing; |
|
} |
|
|
|
function cancel() { |
|
if (timeoutId) { |
|
clearTimeout(timeoutId); |
|
} |
|
if (maxTimeoutId) { |
|
clearTimeout(maxTimeoutId); |
|
} |
|
lastCalled = 0; |
|
args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined; |
|
} |
|
|
|
function complete(isCalled, id) { |
|
if (id) { |
|
clearTimeout(id); |
|
} |
|
maxTimeoutId = timeoutId = trailingCall = undefined; |
|
if (isCalled) { |
|
lastCalled = now(); |
|
result = func.apply(thisArg, args); |
|
if (!timeoutId && !maxTimeoutId) { |
|
args = thisArg = undefined; |
|
} |
|
} |
|
} |
|
|
|
function delayed() { |
|
var remaining = wait - (now() - stamp); |
|
if (remaining <= 0 || remaining > wait) { |
|
complete(trailingCall, maxTimeoutId); |
|
} else { |
|
timeoutId = setTimeout(delayed, remaining); |
|
} |
|
} |
|
|
|
function flush() { |
|
if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) { |
|
result = func.apply(thisArg, args); |
|
} |
|
cancel(); |
|
return result; |
|
} |
|
|
|
function maxDelayed() { |
|
complete(trailing, timeoutId); |
|
} |
|
|
|
function debounced() { |
|
args = arguments; |
|
stamp = now(); |
|
thisArg = this; |
|
trailingCall = trailing && (timeoutId || !leading); |
|
|
|
if (maxWait === false) { |
|
var leadingCall = leading && !timeoutId; |
|
} else { |
|
if (!maxTimeoutId && !leading) { |
|
lastCalled = stamp; |
|
} |
|
var remaining = maxWait - (stamp - lastCalled), |
|
isCalled = remaining <= 0 || remaining > maxWait; |
|
|
|
if (isCalled) { |
|
if (maxTimeoutId) { |
|
maxTimeoutId = clearTimeout(maxTimeoutId); |
|
} |
|
lastCalled = stamp; |
|
result = func.apply(thisArg, args); |
|
} |
|
else if (!maxTimeoutId) { |
|
maxTimeoutId = setTimeout(maxDelayed, remaining); |
|
} |
|
} |
|
if (isCalled && timeoutId) { |
|
timeoutId = clearTimeout(timeoutId); |
|
} |
|
else if (!timeoutId && wait !== maxWait) { |
|
timeoutId = setTimeout(delayed, wait); |
|
} |
|
if (leadingCall) { |
|
isCalled = true; |
|
result = func.apply(thisArg, args); |
|
} |
|
if (isCalled && !timeoutId && !maxTimeoutId) { |
|
args = thisArg = undefined; |
|
} |
|
return result; |
|
} |
|
debounced.cancel = cancel; |
|
debounced.flush = flush; |
|
return debounced; |
|
} |
|
|
|
/** |
|
* Used by `_.defaults` to customize its `_.assign` use. |
|
* |
|
* @private |
|
* @param {*} objValue The destination object property value. |
|
* @param {*} srcValue The source object property value. |
|
* @returns {*} Returns the value to assign to the destination object. |
|
*/ |
|
function extendDefaults(objValue, srcValue) { |
|
return objValue === undefined ? srcValue : objValue; |
|
} |
|
|
|
/** |
|
* This method is like `_.assignWith` except that it iterates over own and |
|
* inherited source properties. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} sources The source objects. |
|
* @param {Function} [customizer] The function to customize assigned values. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function customizer(objValue, srcValue) { |
|
* return _.isUndefined(objValue) ? srcValue : objValue; |
|
* } |
|
* |
|
* var defaults = _.partialRight(_.extendWith, customizer); |
|
* |
|
* defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); |
|
* // => { 'a': 1, 'b': 2 } |
|
*/ |
|
var extendWith = createAssigner(function(object, source, customizer) { |
|
copyObjectWith(source, keysIn(source), object, customizer); |
|
}); |
|
|
|
/** |
|
* Assigns own and inherited enumerable properties of source objects to the |
|
* destination object for all destination properties that resolve to `undefined`. |
|
* Source objects are applied from left to right. 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. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); |
|
* // => { 'user': 'barney', 'age': 36 } |
|
*/ |
|
var defaults = rest(function(args) { |
|
args.push(undefined, extendDefaults); |
|
return extendWith.apply(undefined, args); |
|
}); |
|
|
|
/** |
|
* This function is like `assignValue` except that it doesn't assign `undefined` values. |
|
* |
|
* @private |
|
* @param {Object} object The object to modify. |
|
* @param {string} key The key of the property to assign. |
|
* @param {*} value The value to assign. |
|
*/ |
|
function assignMergeValue(object, key, value) { |
|
var oldValue = object[key]; |
|
if ((value !== undefined && |
|
(value === value ? (value !== oldValue) : (oldValue === oldValue))) || |
|
(typeof key == 'number' && |
|
value === undefined && !(key in object))) { |
|
object[key] = value; |
|
} |
|
} |
|
|
|
/** `Object#toString` result references. */ |
|
var objectTag = '[object Object]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$10 = Object.prototype; |
|
|
|
/** Used to resolve the decompiled source of functions. */ |
|
var fnToString$1 = Function.prototype.toString; |
|
|
|
/** Used to infer the `Object` constructor. */ |
|
var objCtorString = fnToString$1.call(Object); |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$6 = objectProto$10.toString; |
|
|
|
/** Built-in value references. */ |
|
var getPrototypeOf = Object.getPrototypeOf; |
|
|
|
/** |
|
* Checks if `value` is a plain object, that is, an object created by the |
|
* `Object` constructor or one with a `[[Prototype]]` of `null`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* } |
|
* |
|
* _.isPlainObject(new Foo); |
|
* // => false |
|
* |
|
* _.isPlainObject([1, 2, 3]); |
|
* // => false |
|
* |
|
* _.isPlainObject({ 'x': 0, 'y': 0 }); |
|
* // => true |
|
* |
|
* _.isPlainObject(Object.create(null)); |
|
* // => true |
|
*/ |
|
function isPlainObject(value) { |
|
if (!isObjectLike(value) || objToString$6.call(value) != objectTag || isHostObject(value)) { |
|
return false; |
|
} |
|
var proto = objectProto$10; |
|
if (typeof value.constructor == 'function') { |
|
proto = getPrototypeOf(value); |
|
} |
|
if (proto === null) { |
|
return true; |
|
} |
|
var Ctor = proto.constructor; |
|
return (typeof Ctor == 'function' && |
|
Ctor instanceof Ctor && fnToString$1.call(Ctor) == objCtorString); |
|
} |
|
|
|
/** |
|
* Converts `value` to a plain object flattening inherited enumerable |
|
* properties of `value` to own properties of the plain object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to convert. |
|
* @returns {Object} Returns the converted plain object. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.assign({ 'a': 1 }, new Foo); |
|
* // => { 'a': 1, 'b': 2 } |
|
* |
|
* _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); |
|
* // => { 'a': 1, 'b': 2, 'c': 3 } |
|
*/ |
|
function toPlainObject(value) { |
|
return copyObject(value, keysIn(value)); |
|
} |
|
|
|
/** |
|
* A specialized version of `baseMerge` for arrays and objects which performs |
|
* deep merges and tracks traversed objects enabling objects with circular |
|
* references to be merged. |
|
* |
|
* @private |
|
* @param {Object} object The destination object. |
|
* @param {Object} source The source object. |
|
* @param {string} key The key of the value to merge. |
|
* @param {Function} mergeFunc The function to merge values. |
|
* @param {Function} [customizer] The function to customize assigned values. |
|
* @param {Array} [stack] Tracks traversed sources and their value counterparts. |
|
*/ |
|
function baseMergeDeep(object, source, key, mergeFunc, customizer, stack) { |
|
var oldValue = object[key], |
|
srcValue = source[key], |
|
stacked = stack.get(oldValue) || stack.get(srcValue); |
|
|
|
if (stacked) { |
|
assignMergeValue(object, key, stacked); |
|
return; |
|
} |
|
var newValue = customizer ? customizer(oldValue, srcValue, (key + ''), object, source, stack) : undefined, |
|
isCommon = newValue === undefined; |
|
|
|
if (isCommon) { |
|
newValue = srcValue; |
|
if (isArray(srcValue) || isTypedArray(srcValue)) { |
|
newValue = isArray(oldValue) |
|
? oldValue |
|
: ((isArrayLikeObject(oldValue)) ? copyArray(oldValue) : baseClone(srcValue)); |
|
} |
|
else if (isPlainObject(srcValue) || isArguments(srcValue)) { |
|
newValue = isArguments(oldValue) |
|
? toPlainObject(oldValue) |
|
: (isObject(oldValue) ? oldValue : baseClone(srcValue)); |
|
} |
|
else { |
|
isCommon = isFunction(srcValue); |
|
} |
|
} |
|
stack.set(srcValue, newValue); |
|
|
|
if (isCommon) { |
|
// Recursively merge objects and arrays (susceptible to call stack limits). |
|
mergeFunc(newValue, srcValue, customizer, stack); |
|
} |
|
assignMergeValue(object, key, newValue); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.merge` without support for multiple sources. |
|
* |
|
* @private |
|
* @param {Object} object The destination object. |
|
* @param {Object} source The source object. |
|
* @param {Function} [customizer] The function to customize merged values. |
|
* @param {Array} [stack] Tracks traversed sources and their value counterparts. |
|
*/ |
|
function baseMerge(object, source, customizer, stack) { |
|
if (object === source) { |
|
return; |
|
} |
|
var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source); |
|
arrayEach(props || source, function(srcValue, key) { |
|
if (props) { |
|
key = srcValue; |
|
srcValue = source[key]; |
|
} |
|
if (isObject(srcValue)) { |
|
stack || (stack = new Stack); |
|
baseMergeDeep(object, source, key, baseMerge, customizer, stack); |
|
} |
|
else { |
|
var newValue = customizer ? customizer(object[key], srcValue, (key + ''), object, source, stack) : undefined; |
|
if (newValue === undefined) { |
|
newValue = srcValue; |
|
} |
|
assignMergeValue(object, key, newValue); |
|
} |
|
}); |
|
} |
|
|
|
/** |
|
* Used by `_.defaultsDeep` to customize its `_.merge` use. |
|
* |
|
* @private |
|
* @param {*} objValue The destination object property value. |
|
* @param {*} srcValue The source object property value. |
|
* @returns {*} Returns the value to assign to the destination object. |
|
*/ |
|
function mergeDefaults(objValue, srcValue, key, object, source, stack) { |
|
if (isObject(objValue) && isObject(srcValue)) { |
|
stack.set(srcValue, objValue); |
|
baseMerge(objValue, srcValue, mergeDefaults, stack); |
|
} |
|
return objValue === undefined ? baseClone(srcValue) : objValue; |
|
} |
|
|
|
/** |
|
* This method is like `_.merge` except that it accepts `customizer` which |
|
* is invoked to produce the merged values of the destination and source |
|
* properties. If `customizer` returns `undefined` merging is handled by the |
|
* method instead. The `customizer` is invoked with seven arguments: |
|
* (objValue, srcValue, key, object, source, stack). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} sources The source objects. |
|
* @param {Function} customizer The function to customize assigned values. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function customizer(objValue, srcValue) { |
|
* if (_.isArray(objValue)) { |
|
* return objValue.concat(srcValue); |
|
* } |
|
* } |
|
* |
|
* var object = { |
|
* 'fruits': ['apple'], |
|
* 'vegetables': ['beet'] |
|
* }; |
|
* |
|
* var other = { |
|
* 'fruits': ['banana'], |
|
* 'vegetables': ['carrot'] |
|
* }; |
|
* |
|
* _.mergeWith(object, other, customizer); |
|
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] } |
|
*/ |
|
var mergeWith = createAssigner(function(object, source, customizer) { |
|
baseMerge(object, source, customizer); |
|
}); |
|
|
|
/** |
|
* This method is like `_.defaults` except that it recursively assigns |
|
* default properties. |
|
* |
|
* **Note:** This method mutates `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} [sources] The source objects. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } }); |
|
* // => { 'user': { 'name': 'barney', 'age': 36 } } |
|
* |
|
*/ |
|
var defaultsDeep = rest(function(args) { |
|
args.push(undefined, mergeDefaults); |
|
return mergeWith.apply(undefined, args); |
|
}); |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$9 = 'Expected a function'; |
|
|
|
/** |
|
* The base implementation of `_.delay` and `_.defer` which accepts an array |
|
* of `func` arguments. |
|
* |
|
* @private |
|
* @param {Function} func The function to delay. |
|
* @param {number} wait The number of milliseconds to delay invocation. |
|
* @param {Object} args The arguments provide to `func`. |
|
* @returns {number} Returns the timer id. |
|
*/ |
|
function baseDelay(func, wait, args) { |
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$9); |
|
} |
|
return setTimeout(function() { func.apply(undefined, args); }, wait); |
|
} |
|
|
|
/** |
|
* Defers invoking the `func` until the current call stack has cleared. Any |
|
* additional arguments are provided to `func` when it's invoked. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to defer. |
|
* @param {...*} [args] The arguments to invoke the function with. |
|
* @returns {number} Returns the timer id. |
|
* @example |
|
* |
|
* _.defer(function(text) { |
|
* console.log(text); |
|
* }, 'deferred'); |
|
* // logs 'deferred' after one or more milliseconds |
|
*/ |
|
var defer = rest(function(func, args) { |
|
return baseDelay(func, 1, args); |
|
}); |
|
|
|
/** |
|
* Invokes `func` after `wait` milliseconds. Any additional arguments are |
|
* provided to `func` when it's invoked. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to delay. |
|
* @param {number} wait The number of milliseconds to delay invocation. |
|
* @param {...*} [args] The arguments to invoke the function with. |
|
* @returns {number} Returns the timer id. |
|
* @example |
|
* |
|
* _.delay(function(text) { |
|
* console.log(text); |
|
* }, 1000, 'later'); |
|
* // => logs 'later' after one second |
|
*/ |
|
var delay = rest(function(func, wait, args) { |
|
return baseDelay(func, wait, args); |
|
}); |
|
|
|
/** Used to stand-in for `undefined` hash values. */ |
|
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__'; |
|
|
|
/** |
|
* Adds `value` to the set cache. |
|
* |
|
* @private |
|
* @name push |
|
* @memberOf SetCache |
|
* @param {*} value The value to cache. |
|
*/ |
|
function cachePush(value) { |
|
var map = this.__data__; |
|
if (isKeyable(value)) { |
|
var data = map.__data__, |
|
hash = typeof value == 'string' ? data.string : data.hash; |
|
|
|
hash[value] = HASH_UNDEFINED$1; |
|
} |
|
else { |
|
map.set(value, HASH_UNDEFINED$1); |
|
} |
|
} |
|
|
|
/** |
|
* |
|
* Creates a set cache object to store unique values. |
|
* |
|
* @private |
|
* @param {Array} [values] The values to cache. |
|
*/ |
|
function SetCache(values) { |
|
var index = -1, |
|
length = values ? values.length : 0; |
|
|
|
this.__data__ = new MapCache; |
|
while (++index < length) { |
|
this.push(values[index]); |
|
} |
|
} |
|
|
|
// Add functions to the `SetCache`. |
|
SetCache.prototype.push = cachePush; |
|
|
|
/** |
|
* Gets the index at which the first occurrence of `NaN` is found in `array`. |
|
* |
|
* @private |
|
* @param {Array} array The array to search. |
|
* @param {number} fromIndex The index to search from. |
|
* @param {boolean} [fromRight] Specify iterating from right to left. |
|
* @returns {number} Returns the index of the matched `NaN`, else `-1`. |
|
*/ |
|
function indexOfNaN(array, fromIndex, fromRight) { |
|
var length = array.length, |
|
index = fromIndex + (fromRight ? 0 : -1); |
|
|
|
while ((fromRight ? index-- : ++index < length)) { |
|
var other = array[index]; |
|
if (other !== other) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.indexOf` without `fromIndex` bounds checks. |
|
* |
|
* @private |
|
* @param {Array} array The array to search. |
|
* @param {*} value The value to search for. |
|
* @param {number} fromIndex The index to search from. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
*/ |
|
function baseIndexOf(array, value, fromIndex) { |
|
if (value !== value) { |
|
return indexOfNaN(array, fromIndex); |
|
} |
|
var index = fromIndex - 1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
if (array[index] === value) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** Used to stand-in for `undefined` hash values. */ |
|
var HASH_UNDEFINED = '__lodash_hash_undefined__'; |
|
|
|
/** |
|
* Checks if `value` is in `cache` mimicking the return signature of |
|
* `_.indexOf` by returning `0` if `value` is found, else `-1`. |
|
* |
|
* @private |
|
* @param {Object} cache The set cache to search. |
|
* @param {*} value The value to search for. |
|
* @returns {number} Returns `0` if `value` is found, else `-1`. |
|
*/ |
|
function cacheIndexOf(cache, value) { |
|
var map = cache.__data__; |
|
if (isKeyable(value)) { |
|
var data = map.__data__, |
|
hash = typeof value == 'string' ? data.string : data.hash; |
|
|
|
return hash[value] === HASH_UNDEFINED ? 0 : -1; |
|
} |
|
return map.has(value) ? 0 : -1; |
|
} |
|
|
|
/** Used as the size to enable large array optimizations. */ |
|
var LARGE_ARRAY_SIZE = 200; |
|
|
|
/** |
|
* The base implementation of `_.differenceBy` without support for callback |
|
* shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to inspect. |
|
* @param {Array} values The values to exclude. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns the new array of filtered values. |
|
*/ |
|
function baseDifferenceBy(array, values, iteratee) { |
|
var index = -1, |
|
indexOf = baseIndexOf, |
|
isCommon = true, |
|
length = array.length, |
|
result = [], |
|
valuesLength = values.length; |
|
|
|
if (!length) { |
|
return result; |
|
} |
|
if (iteratee) { |
|
values = arrayMap(values, function(value) { return iteratee(value); }); |
|
} |
|
if (values.length >= LARGE_ARRAY_SIZE) { |
|
indexOf = cacheIndexOf; |
|
isCommon = false; |
|
values = new SetCache(values); |
|
} |
|
outer: |
|
while (++index < length) { |
|
var value = array[index], |
|
computed = iteratee ? iteratee(value) : value; |
|
|
|
if (isCommon && computed === computed) { |
|
var valuesIndex = valuesLength; |
|
while (valuesIndex--) { |
|
if (values[valuesIndex] === computed) { |
|
continue outer; |
|
} |
|
} |
|
result.push(value); |
|
} |
|
else if (indexOf(values, computed, 0) < 0) { |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.difference` without support for excluding |
|
* multiple arrays of values. |
|
* |
|
* @private |
|
* @param {Array} array The array to inspect. |
|
* @param {Array} values The values to exclude. |
|
* @returns {Array} Returns the new array of filtered values. |
|
*/ |
|
function baseDifference(array, values) { |
|
return baseDifferenceBy(array, values); |
|
} |
|
|
|
/** |
|
* Creates an array of unique `array` values not included in the other |
|
* provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to inspect. |
|
* @param {...Array} [values] The values to exclude. |
|
* @returns {Array} Returns the new array of filtered values. |
|
* @example |
|
* |
|
* _.difference([3, 2, 1], [4, 2]); |
|
* // => [3, 1] |
|
*/ |
|
var difference = rest(function(array, values) { |
|
return isArrayLikeObject(array) |
|
? baseDifference(array, baseFlatten(values, false, true)) |
|
: []; |
|
}); |
|
|
|
/** |
|
* This method is like `_.difference` except that it accepts `iteratee` which |
|
* is invoked for each element of `array` and `values` to generate the criterion |
|
* by which uniqueness is computed. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to inspect. |
|
* @param {...Array} [values] The values to exclude. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Array} Returns the new array of filtered values. |
|
* @example |
|
* |
|
* _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor); |
|
* // => [3.1, 1.3] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); |
|
* // => [{ 'x': 2 }] |
|
*/ |
|
var differenceBy = rest(function(array, values) { |
|
var iteratee = last(values); |
|
if (isArrayLikeObject(iteratee)) { |
|
iteratee = undefined; |
|
} |
|
return isArrayLikeObject(array) |
|
? baseDifferenceBy(array, baseFlatten(values, false, true), baseIteratee(iteratee)) |
|
: []; |
|
}); |
|
|
|
/** |
|
* Creates a function that checks if **any** of the `predicates` return |
|
* truthy when invoked with the arguments provided to the created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {...(Function|Function[])} predicates The predicates to check. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var disjed = _.disj(Boolean, isFinite); |
|
* |
|
* disjed('1'); |
|
* // => true |
|
* |
|
* disjed(null); |
|
* // => true |
|
* |
|
* disjed(NaN); |
|
* // => false |
|
*/ |
|
var disj = createInvoker(arraySome); |
|
|
|
/** |
|
* Creates a slice of `array` with `n` elements dropped from the beginning. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {number} [n=1] The number of elements to drop. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* _.drop([1, 2, 3]); |
|
* // => [2, 3] |
|
* |
|
* _.drop([1, 2, 3], 2); |
|
* // => [3] |
|
* |
|
* _.drop([1, 2, 3], 5); |
|
* // => [] |
|
* |
|
* _.drop([1, 2, 3], 0); |
|
* // => [1, 2, 3] |
|
*/ |
|
function drop(array, n, guard) { |
|
if (!(array && array.length)) { |
|
return []; |
|
} |
|
n = (guard || n === undefined) ? 1 : n; |
|
return baseSlice(array, n < 0 ? 0 : n); |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` with `n` elements dropped from the end. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {number} [n=1] The number of elements to drop. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* _.dropRight([1, 2, 3]); |
|
* // => [1, 2] |
|
* |
|
* _.dropRight([1, 2, 3], 2); |
|
* // => [1] |
|
* |
|
* _.dropRight([1, 2, 3], 5); |
|
* // => [] |
|
* |
|
* _.dropRight([1, 2, 3], 0); |
|
* // => [1, 2, 3] |
|
*/ |
|
function dropRight(array, n, guard) { |
|
var length = array ? array.length : 0; |
|
if (!length) { |
|
return []; |
|
} |
|
n = (guard || n === undefined) ? 1 : toInteger(n); |
|
n = length - n; |
|
return baseSlice(array, 0, n < 0 ? 0 : n); |
|
} |
|
|
|
/** |
|
* The base implementation of methods like `_.dropWhile` and `_.takeWhile` |
|
* without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to query. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @param {boolean} [isDrop] Specify dropping elements instead of taking them. |
|
* @param {boolean} [fromRight] Specify iterating from right to left. |
|
* @returns {Array} Returns the slice of `array`. |
|
*/ |
|
function baseWhile(array, predicate, isDrop, fromRight) { |
|
var length = array.length, |
|
index = fromRight ? length : -1; |
|
|
|
while ((fromRight ? index-- : ++index < length) && |
|
predicate(array[index], index, array)) {} |
|
|
|
return isDrop |
|
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) |
|
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` excluding elements dropped from the end. |
|
* Elements are dropped until `predicate` returns falsey. The predicate is |
|
* invoked with three arguments: (value, index, array). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': true }, |
|
* { 'user': 'fred', 'active': false }, |
|
* { 'user': 'pebbles', 'active': false } |
|
* ]; |
|
* |
|
* resolve( _.dropRightWhile(users, function(o) { return !o.active; }) ); |
|
* // => ['barney'] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }) ); |
|
* // => ['barney', 'fred'] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.dropRightWhile(users, ['active', false]) ); |
|
* // => ['barney'] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.dropRightWhile(users, 'active') ); |
|
* // => ['barney', 'fred', 'pebbles'] |
|
*/ |
|
function dropRightWhile(array, predicate) { |
|
return (array && array.length) |
|
? baseWhile(array, baseIteratee(predicate, 3), true, true) |
|
: []; |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` excluding elements dropped from the beginning. |
|
* Elements are dropped until `predicate` returns falsey. The predicate is |
|
* invoked with three arguments: (value, index, array). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': false }, |
|
* { 'user': 'fred', 'active': false }, |
|
* { 'user': 'pebbles', 'active': true } |
|
* ]; |
|
* |
|
* resolve( _.dropWhile(users, function(o) { return !o.active; }) ); |
|
* // => ['pebbles'] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.dropWhile(users, { 'user': 'barney', 'active': false }) ); |
|
* // => ['fred', 'pebbles'] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.dropWhile(users, ['active', false]) ); |
|
* // => ['pebbles'] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.dropWhile(users, 'active') ); |
|
* // => ['barney', 'fred', 'pebbles'] |
|
*/ |
|
function dropWhile(array, predicate) { |
|
return (array && array.length) |
|
? baseWhile(array, baseIteratee(predicate, 3), true) |
|
: []; |
|
} |
|
|
|
/** |
|
* Checks if `string` ends with the given target string. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to search. |
|
* @param {string} [target] The string to search for. |
|
* @param {number} [position=string.length] The position to search from. |
|
* @returns {boolean} Returns `true` if `string` ends with `target`, else `false`. |
|
* @example |
|
* |
|
* _.endsWith('abc', 'c'); |
|
* // => true |
|
* |
|
* _.endsWith('abc', 'b'); |
|
* // => false |
|
* |
|
* _.endsWith('abc', 'b', 2); |
|
* // => true |
|
*/ |
|
function endsWith(string, target, position) { |
|
string = toString(string); |
|
target = typeof target == 'string' ? target : (target + ''); |
|
|
|
var length = string.length; |
|
position = position === undefined |
|
? length |
|
: clamp(toInteger(position), 0, length); |
|
|
|
position -= target.length; |
|
return position >= 0 && string.indexOf(target, position) == position; |
|
} |
|
|
|
/** |
|
* Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* comparison between two values to determine if they are equivalent. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred' }; |
|
* var other = { 'user': 'fred' }; |
|
* |
|
* _.eq(object, object); |
|
* // => true |
|
* |
|
* _.eq(object, other); |
|
* // => false |
|
* |
|
* _.eq('a', 'a'); |
|
* // => true |
|
* |
|
* _.eq('a', Object('a')); |
|
* // => false |
|
* |
|
* _.eq(NaN, NaN); |
|
* // => true |
|
*/ |
|
function eq(value, other) { |
|
return value === other || (value !== value && other !== other); |
|
} |
|
|
|
/** Used to map characters to HTML entities. */ |
|
var htmlEscapes = { |
|
'&': '&', |
|
'<': '<', |
|
'>': '>', |
|
'"': '"', |
|
"'": ''', |
|
'`': '`' |
|
}; |
|
|
|
/** |
|
* Used by `_.escape` to convert characters to HTML entities. |
|
* |
|
* @private |
|
* @param {string} chr The matched character to escape. |
|
* @returns {string} Returns the escaped character. |
|
*/ |
|
function escapeHtmlChar(chr) { |
|
return htmlEscapes[chr]; |
|
} |
|
|
|
var reUnescapedHtml = /[&<>"'`]/g; |
|
var reHasUnescapedHtml = RegExp(reUnescapedHtml.source); |
|
/** |
|
* Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to |
|
* their corresponding HTML entities. |
|
* |
|
* **Note:** No other characters are escaped. To escape additional characters |
|
* use a third-party library like [_he_](https://mths.be/he). |
|
* |
|
* Though the ">" character is escaped for symmetry, characters like |
|
* ">" and "/" don't need escaping in HTML and have no special meaning |
|
* 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 [#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 |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to escape. |
|
* @returns {string} Returns the escaped string. |
|
* @example |
|
* |
|
* _.escape('fred, barney, & pebbles'); |
|
* // => 'fred, barney, & pebbles' |
|
*/ |
|
function escape(string) { |
|
string = toString(string); |
|
return (string && reHasUnescapedHtml.test(string)) |
|
? string.replace(reUnescapedHtml, escapeHtmlChar) |
|
: string; |
|
} |
|
|
|
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; |
|
var reHasRegExpChar = RegExp(reRegExpChar.source); |
|
/** |
|
* Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", |
|
* "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to escape. |
|
* @returns {string} Returns the escaped string. |
|
* @example |
|
* |
|
* _.escapeRegExp('[lodash](https://lodash.com/)'); |
|
* // => '\[lodash\]\(https://lodash\.com/\)' |
|
*/ |
|
function escapeRegExp(string) { |
|
string = toString(string); |
|
return (string && reHasRegExpChar.test(string)) |
|
? string.replace(reRegExpChar, '\\$&') |
|
: string; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.every` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @returns {boolean} Returns `true` if all elements pass the predicate check, else `false` |
|
*/ |
|
function baseEvery(collection, predicate) { |
|
var result = true; |
|
baseEach(collection, function(value, index, collection) { |
|
result = !!predicate(value, index, collection); |
|
return result; |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Checks if `predicate` returns truthy for **all** elements of `collection`. |
|
* Iteration is stopped once `predicate` returns falsey. The predicate is |
|
* invoked with three arguments: (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`. |
|
* @example |
|
* |
|
* _.every([true, 1, null, 'yes'], Boolean); |
|
* // => false |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': false }, |
|
* { 'user': 'fred', 'active': false } |
|
* ]; |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* _.every(users, { 'user': 'barney', 'active': false }); |
|
* // => false |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* _.every(users, ['active', false]); |
|
* // => true |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.every(users, 'active'); |
|
* // => false |
|
*/ |
|
function every(collection, predicate, guard) { |
|
var func = isArray(collection) ? arrayEvery : baseEvery; |
|
if (guard && isIterateeCall(collection, predicate, guard)) { |
|
predicate = undefined; |
|
} |
|
return func(collection, baseIteratee(predicate, 3)); |
|
} |
|
|
|
/** |
|
* This method is like `_.assign` except that it iterates over own and |
|
* inherited source properties. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} [sources] The source objects. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.b = 2; |
|
* } |
|
* |
|
* function Bar() { |
|
* this.d = 4; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* Bar.prototype.e = 5; |
|
* |
|
* _.extend({ 'a': 1 }, new Foo, new Bar); |
|
* // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 } |
|
*/ |
|
var extend = createAssigner(function(object, source) { |
|
copyObject(source, keysIn(source), object); |
|
}); |
|
|
|
/** |
|
* The base implementation of `_.fill` without an iteratee call guard. |
|
* |
|
* @private |
|
* @param {Array} array The array to fill. |
|
* @param {*} value The value to fill `array` with. |
|
* @param {number} [start=0] The start position. |
|
* @param {number} [end=array.length] The end position. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function baseFill(array, value, start, end) { |
|
var length = array.length; |
|
|
|
start = start == null ? 0 : toInteger(start); |
|
if (start < 0) { |
|
start = -start > length ? 0 : (length + start); |
|
} |
|
end = (end === undefined || end > length) ? length : toInteger(end); |
|
if (end < 0) { |
|
end += length; |
|
} |
|
length = start > end ? 0 : (end >>> 0); |
|
start >>>= 0; |
|
|
|
while (start < length) { |
|
array[start++] = value; |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* Fills elements of `array` with `value` from `start` up to, but not |
|
* including, `end`. |
|
* |
|
* **Note:** This method mutates `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to fill. |
|
* @param {*} value The value to fill `array` with. |
|
* @param {number} [start=0] The start position. |
|
* @param {number} [end=array.length] The end position. |
|
* @returns {Array} Returns `array`. |
|
* @example |
|
* |
|
* var array = [1, 2, 3]; |
|
* |
|
* _.fill(array, 'a'); |
|
* console.log(array); |
|
* // => ['a', 'a', 'a'] |
|
* |
|
* _.fill(Array(3), 2); |
|
* // => [2, 2, 2] |
|
* |
|
* _.fill([4, 6, 8, 10], '*', 1, 3); |
|
* // => [4, '*', '*', 10] |
|
*/ |
|
function fill(array, value, start, end) { |
|
var length = array ? array.length : 0; |
|
if (!length) { |
|
return []; |
|
} |
|
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { |
|
start = 0; |
|
end = length; |
|
} |
|
return baseFill(array, value, start, end); |
|
} |
|
|
|
/** |
|
* A specialized version of `_.filter` for arrays without support for |
|
* callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @returns {Array} Returns the new filtered array. |
|
*/ |
|
function arrayFilter(array, predicate) { |
|
var index = -1, |
|
length = array.length, |
|
resIndex = -1, |
|
result = []; |
|
|
|
while (++index < length) { |
|
var value = array[index]; |
|
if (predicate(value, index, array)) { |
|
result[++resIndex] = value; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.filter` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @returns {Array} Returns the new filtered array. |
|
*/ |
|
function baseFilter(collection, predicate) { |
|
var result = []; |
|
baseEach(collection, function(value, index, collection) { |
|
if (predicate(value, index, collection)) { |
|
result.push(value); |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Iterates over elements of `collection`, returning an array of all elements |
|
* `predicate` returns truthy for. The predicate is invoked with three arguments: |
|
* (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the new filtered array. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36, 'active': true }, |
|
* { 'user': 'fred', 'age': 40, 'active': false } |
|
* ]; |
|
* |
|
* resolve( _.filter(users, function(o) { return !o.active; }) ); |
|
* // => ['fred'] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.filter(users, { 'age': 36, 'active': true }) ); |
|
* // => ['barney'] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.filter(users, ['active', false]) ); |
|
* // => ['fred'] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.filter(users, 'active') ); |
|
* // => ['barney'] |
|
*/ |
|
function filter(collection, predicate) { |
|
var func = isArray(collection) ? arrayFilter : baseFilter; |
|
return func(collection, baseIteratee(predicate, 3)); |
|
} |
|
|
|
/** |
|
* The base implementation of methods like `_.find` and `_.findKey` without |
|
* support for callback shorthands, which iterates over `collection` using |
|
* the provided `eachFunc`. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to search. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @param {Function} eachFunc The function to iterate over `collection`. |
|
* @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself. |
|
* @returns {*} Returns the found element or its key, else `undefined`. |
|
*/ |
|
function baseFind(collection, predicate, eachFunc, retKey) { |
|
var result; |
|
eachFunc(collection, function(value, key, collection) { |
|
if (predicate(value, key, collection)) { |
|
result = retKey ? key : value; |
|
return false; |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.findIndex` and `_.findLastIndex` without |
|
* support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to search. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @param {boolean} [fromRight] Specify iterating from right to left. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
*/ |
|
function baseFindIndex(array, predicate, fromRight) { |
|
var length = array.length, |
|
index = fromRight ? length : -1; |
|
|
|
while ((fromRight ? index-- : ++index < length)) { |
|
if (predicate(array[index], index, array)) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* Iterates over elements of `collection`, returning the first element |
|
* `predicate` returns truthy for. The predicate is invoked with three arguments: |
|
* (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to search. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {*} Returns the matched element, else `undefined`. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.result, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36, 'active': true }, |
|
* { 'user': 'fred', 'age': 40, 'active': false }, |
|
* { 'user': 'pebbles', 'age': 1, 'active': true } |
|
* ]; |
|
* |
|
* resolve( _.find(users, function(o) { return o.age < 40; }) ); |
|
* // => 'barney' |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.find(users, { 'age': 1, 'active': true }) ); |
|
* // => 'pebbles' |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.find(users, ['active', false]) ); |
|
* // => 'fred' |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.find(users, 'active') ); |
|
* // => 'barney' |
|
*/ |
|
function find(collection, predicate) { |
|
predicate = baseIteratee(predicate, 3); |
|
if (isArray(collection)) { |
|
var index = baseFindIndex(collection, predicate); |
|
return index > -1 ? collection[index] : undefined; |
|
} |
|
return baseFind(collection, predicate, baseEach); |
|
} |
|
|
|
/** |
|
* This method is like `_.find` except that it returns the index of the first |
|
* element `predicate` returns truthy for instead of the element itself. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to search. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {number} Returns the index of the found element, else `-1`. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': false }, |
|
* { 'user': 'fred', 'active': false }, |
|
* { 'user': 'pebbles', 'active': true } |
|
* ]; |
|
* |
|
* _.findIndex(users, function(o) { return o.user == 'barney'; }); |
|
* // => 0 |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* _.findIndex(users, { 'user': 'fred', 'active': false }); |
|
* // => 1 |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* _.findIndex(users, ['active', false]); |
|
* // => 0 |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.findIndex(users, 'active'); |
|
* // => 2 |
|
*/ |
|
function findIndex(array, predicate) { |
|
return (array && array.length) |
|
? baseFindIndex(array, baseIteratee(predicate, 3)) |
|
: -1; |
|
} |
|
|
|
/** |
|
* This method is like `_.find` except that it returns the key of the first |
|
* element `predicate` returns truthy for instead of the element itself. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to search. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {string|undefined} Returns the key of the matched element, else `undefined`. |
|
* @example |
|
* |
|
* var users = { |
|
* 'barney': { 'age': 36, 'active': true }, |
|
* 'fred': { 'age': 40, 'active': false }, |
|
* 'pebbles': { 'age': 1, 'active': true } |
|
* }; |
|
* |
|
* _.findKey(users, function(o) { return o.age < 40; }); |
|
* // => 'barney' (iteration order is not guaranteed) |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* _.findKey(users, { 'age': 1, 'active': true }); |
|
* // => 'pebbles' |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* _.findKey(users, ['active', false]); |
|
* // => 'fred' |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.findKey(users, 'active'); |
|
* // => 'barney' |
|
*/ |
|
function findKey(object, predicate) { |
|
return baseFind(object, baseIteratee(predicate, 3), baseForOwn, true); |
|
} |
|
|
|
/** |
|
* This function is like `baseFor` except that it iterates over properties |
|
* in the opposite order. |
|
* |
|
* @private |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @param {Function} keysFunc The function to get the keys of `object`. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
var baseForRight = createBaseFor(true); |
|
|
|
/** |
|
* The base implementation of `_.forOwnRight` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function baseForOwnRight(object, iteratee) { |
|
return object && baseForRight(object, iteratee, keys); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.forEachRight` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Array|Object} Returns `collection`. |
|
*/ |
|
var baseEachRight = createBaseEach(baseForOwnRight, true); |
|
|
|
/** |
|
* This method is like `_.find` except that it iterates over elements of |
|
* `collection` from right to left. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to search. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {*} Returns the matched element, else `undefined`. |
|
* @example |
|
* |
|
* _.findLast([1, 2, 3, 4], function(n) { |
|
* return n % 2 == 1; |
|
* }); |
|
* // => 3 |
|
*/ |
|
function findLast(collection, predicate) { |
|
predicate = baseIteratee(predicate, 3); |
|
if (isArray(collection)) { |
|
var index = baseFindIndex(collection, predicate, true); |
|
return index > -1 ? collection[index] : undefined; |
|
} |
|
return baseFind(collection, predicate, baseEachRight); |
|
} |
|
|
|
/** |
|
* This method is like `_.findIndex` except that it iterates over elements |
|
* of `collection` from right to left. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to search. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {number} Returns the index of the found element, else `-1`. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': true }, |
|
* { 'user': 'fred', 'active': false }, |
|
* { 'user': 'pebbles', 'active': false } |
|
* ]; |
|
* |
|
* _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); |
|
* // => 2 |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* _.findLastIndex(users, { 'user': 'barney', 'active': true }); |
|
* // => 0 |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* _.findLastIndex(users, ['active', false]); |
|
* // => 2 |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.findLastIndex(users, 'active'); |
|
* // => 0 |
|
*/ |
|
function findLastIndex(array, predicate) { |
|
return (array && array.length) |
|
? baseFindIndex(array, baseIteratee(predicate, 3), true) |
|
: -1; |
|
} |
|
|
|
/** |
|
* This method is like `_.findKey` except that it iterates over elements of |
|
* a collection in the opposite order. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to search. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {string|undefined} Returns the key of the matched element, else `undefined`. |
|
* @example |
|
* |
|
* var users = { |
|
* 'barney': { 'age': 36, 'active': true }, |
|
* 'fred': { 'age': 40, 'active': false }, |
|
* 'pebbles': { 'age': 1, 'active': true } |
|
* }; |
|
* |
|
* _.findLastKey(users, function(o) { return o.age < 40; }); |
|
* // => returns 'pebbles' assuming `_.findKey` returns 'barney' |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* _.findLastKey(users, { 'age': 36, 'active': true }); |
|
* // => 'barney' |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* _.findLastKey(users, ['active', false]); |
|
* // => 'fred' |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.findLastKey(users, 'active'); |
|
* // => 'pebbles' |
|
*/ |
|
function findLastKey(object, predicate) { |
|
return baseFind(object, baseIteratee(predicate, 3), baseForOwnRight, true); |
|
} |
|
|
|
/** |
|
* Flattens `array` a single level. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to flatten. |
|
* @returns {Array} Returns the new flattened array. |
|
* @example |
|
* |
|
* _.flatten([1, [2, 3, [4]]]); |
|
* // => [1, 2, 3, [4]] |
|
*/ |
|
function flatten(array) { |
|
var length = array ? array.length : 0; |
|
return length ? baseFlatten(array) : []; |
|
} |
|
|
|
/** |
|
* This method is like `_.flatten` except that it recursively flattens `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to recursively flatten. |
|
* @returns {Array} Returns the new flattened array. |
|
* @example |
|
* |
|
* _.flattenDeep([1, [2, 3, [4]]]); |
|
* // => [1, 2, 3, 4] |
|
*/ |
|
function flattenDeep(array) { |
|
var length = array ? array.length : 0; |
|
return length ? baseFlatten(array, true) : []; |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var FLIP_FLAG = 512; |
|
|
|
/** |
|
* Creates a function that invokes `func` with arguments reversed. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to flip arguments for. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var flipped = _.flip(function() { |
|
* return _.toArray(arguments); |
|
* }); |
|
* |
|
* flipped('a', 'b', 'c', 'd'); |
|
* // => ['d', 'c', 'b', 'a'] |
|
*/ |
|
function flip(func) { |
|
return createWrapper(func, FLIP_FLAG); |
|
} |
|
|
|
/** |
|
* Calculates `number` rounded down to `precision`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {number} number The number to round down. |
|
* @param {number} [precision=0] The precision to round down to. |
|
* @returns {number} Returns the rounded down number. |
|
* @example |
|
* |
|
* _.floor(4.006); |
|
* // => 4 |
|
* |
|
* _.floor(0.046, 2); |
|
* // => 0.04 |
|
* |
|
* _.floor(4060, -2); |
|
* // => 4000 |
|
*/ |
|
var floor = createRound('floor'); |
|
|
|
var CURRY_FLAG$1 = 8; |
|
var PARTIAL_FLAG$4 = 32; |
|
var ARY_FLAG$1 = 128; |
|
var REARG_FLAG$1 = 256; |
|
/** Used as the size to enable large array optimizations. */ |
|
var LARGE_ARRAY_SIZE$1 = 200; |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$10 = 'Expected a function'; |
|
|
|
/** |
|
* Creates a `_.flow` or `_.flowRight` function. |
|
* |
|
* @private |
|
* @param {boolean} [fromRight] Specify iterating from right to left. |
|
* @returns {Function} Returns the new flow function. |
|
*/ |
|
function createFlow(fromRight) { |
|
return rest(function(funcs) { |
|
funcs = baseFlatten(funcs); |
|
|
|
var length = funcs.length, |
|
index = length, |
|
prereq = LodashWrapper.prototype.thru; |
|
|
|
if (fromRight) { |
|
funcs.reverse(); |
|
} |
|
while (index--) { |
|
var func = funcs[index]; |
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$10); |
|
} |
|
if (prereq && !wrapper && getFuncName(func) == 'wrapper') { |
|
var wrapper = new LodashWrapper([], true); |
|
} |
|
} |
|
index = wrapper ? index : length; |
|
while (++index < length) { |
|
func = funcs[index]; |
|
|
|
var funcName = getFuncName(func), |
|
data = funcName == 'wrapper' ? getData(func) : undefined; |
|
|
|
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG$1 | CURRY_FLAG$1 | PARTIAL_FLAG$4 | REARG_FLAG$1) && !data[4].length && data[9] == 1) { |
|
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); |
|
} else { |
|
wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func); |
|
} |
|
} |
|
return function() { |
|
var args = arguments, |
|
value = args[0]; |
|
|
|
if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE$1) { |
|
return wrapper.plant(value).value(); |
|
} |
|
var index = 0, |
|
result = length ? funcs[index].apply(this, args) : value; |
|
|
|
while (++index < length) { |
|
result = funcs[index].call(this, result); |
|
} |
|
return result; |
|
}; |
|
}); |
|
} |
|
|
|
/** |
|
* Creates a function that returns the result of invoking the provided |
|
* functions with the `this` binding of the created function, where each |
|
* successive invocation is supplied the return value of the previous. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {...(Function|Function[])} [funcs] Functions to invoke. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* function square(n) { |
|
* return n * n; |
|
* } |
|
* |
|
* var addSquare = _.flow(_.add, square); |
|
* addSquare(1, 2); |
|
* // => 9 |
|
*/ |
|
var flow = createFlow(); |
|
|
|
/** |
|
* This method is like `_.flow` except that it creates a function that |
|
* invokes the provided functions from right to left. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {...(Function|Function[])} [funcs] Functions to invoke. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* function square(n) { |
|
* return n * n; |
|
* } |
|
* |
|
* var addSquare = _.flowRight(square, _.add); |
|
* addSquare(1, 2); |
|
* // => 9 |
|
*/ |
|
var flowRight = createFlow(true); |
|
|
|
/** |
|
* Converts `value` to a function if it's not one. |
|
* |
|
* @private |
|
* @param {*} value The value to process. |
|
* @returns {Function} Returns the function. |
|
*/ |
|
function toFunction(value) { |
|
return typeof value == 'function' ? value : identity; |
|
} |
|
|
|
/** |
|
* Iterates over elements of `collection` invoking `iteratee` for each element. |
|
* The iteratee is invoked with three arguments: (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 |
|
* are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn` |
|
* for object iteration. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias each |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Array|Object} Returns `collection`. |
|
* @example |
|
* |
|
* _([1, 2]).forEach(function(value) { |
|
* console.log(value); |
|
* }); |
|
* // => logs `1` then `2` |
|
* |
|
* _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { |
|
* console.log(key); |
|
* }); |
|
* // => logs 'a' then 'b' (iteration order is not guaranteed) |
|
*/ |
|
function forEach(collection, iteratee) { |
|
return (typeof iteratee == 'function' && isArray(collection)) |
|
? arrayEach(collection, iteratee) |
|
: baseEach(collection, toFunction(iteratee)); |
|
} |
|
|
|
/** |
|
* A specialized version of `_.forEachRight` for arrays without support for |
|
* callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function arrayEachRight(array, iteratee) { |
|
var length = array.length; |
|
|
|
while (length--) { |
|
if (iteratee(array[length], length, array) === false) { |
|
break; |
|
} |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* This method is like `_.forEach` except that it iterates over elements of |
|
* `collection` from right to left. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias eachRight |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Array|Object} Returns `collection`. |
|
* @example |
|
* |
|
* _.forEachRight([1, 2], function(value) { |
|
* console.log(value); |
|
* }); |
|
* // => logs `2` then `1` |
|
*/ |
|
function forEachRight(collection, iteratee) { |
|
return (typeof iteratee == 'function' && isArray(collection)) |
|
? arrayEachRight(collection, iteratee) |
|
: baseEachRight(collection, toFunction(iteratee)); |
|
} |
|
|
|
/** |
|
* Iterates over own and inherited enumerable properties of an object invoking |
|
* `iteratee` for each property. The iteratee is invoked with three arguments: |
|
* (value, key, object). Iteratee functions may exit iteration early by explicitly |
|
* returning `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.forIn(new Foo, function(value, key) { |
|
* console.log(key); |
|
* }); |
|
* // => logs 'a', 'b', then 'c' (iteration order is not guaranteed) |
|
*/ |
|
function forIn(object, iteratee) { |
|
return object == null ? object : baseFor(object, toFunction(iteratee), keysIn); |
|
} |
|
|
|
/** |
|
* This method is like `_.forIn` except that it iterates over properties of |
|
* `object` in the opposite order. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.forInRight(new Foo, function(value, key) { |
|
* console.log(key); |
|
* }); |
|
* // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c' |
|
*/ |
|
function forInRight(object, iteratee) { |
|
return object == null ? object : baseForRight(object, toFunction(iteratee), keysIn); |
|
} |
|
|
|
/** |
|
* Iterates over own enumerable properties of an object invoking `iteratee` |
|
* for each property. The iteratee is invoked with three arguments: |
|
* (value, key, object). Iteratee functions may exit iteration early by |
|
* explicitly returning `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.forOwn(new Foo, function(value, key) { |
|
* console.log(key); |
|
* }); |
|
* // => logs 'a' then 'b' (iteration order is not guaranteed) |
|
*/ |
|
function forOwn(object, iteratee) { |
|
return object && baseForOwn(object, toFunction(iteratee)); |
|
} |
|
|
|
/** |
|
* This method is like `_.forOwn` except that it iterates over properties of |
|
* `object` in the opposite order. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.forOwnRight(new Foo, function(value, key) { |
|
* console.log(key); |
|
* }); |
|
* // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b' |
|
*/ |
|
function forOwnRight(object, iteratee) { |
|
return object && baseForOwnRight(object, toFunction(iteratee)); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.functions` which creates an array of |
|
* `object` function property names filtered from those provided. |
|
* |
|
* @private |
|
* @param {Object} object The object to inspect. |
|
* @param {Array} props The property names to filter. |
|
* @returns {Array} Returns the new array of filtered property names. |
|
*/ |
|
function baseFunctions(object, props) { |
|
return arrayFilter(props, function(key) { |
|
return isFunction(object[key]); |
|
}); |
|
} |
|
|
|
/** |
|
* Creates an array of function property names from all enumerable properties, |
|
* own and inherited, of `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to inspect. |
|
* @returns {Array} Returns the new array of property names. |
|
* @example |
|
* |
|
* _.functions(_); |
|
* // => ['after', 'ary', 'assign', ...] |
|
*/ |
|
function functions(object) { |
|
return object == null ? [] : baseFunctions(object, keysIn(object)); |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$1 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$1 = objectProto$1.hasOwnProperty; |
|
|
|
/** |
|
* Creates an object composed of keys generated from the results of running |
|
* each element of `collection` through `iteratee`. The corresponding value |
|
* of each key is an array of the elements responsible for generating the key. |
|
* The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Object} Returns the composed aggregate object. |
|
* @example |
|
* |
|
* _.groupBy([6.1, 4.2, 6.3], Math.floor); |
|
* // => { '4': [4.2], '6': [6.1, 6.3] } |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.groupBy(['one', 'two', 'three'], 'length'); |
|
* // => { '3': ['one', 'two'], '5': ['three'] } |
|
*/ |
|
var groupBy = createAggregator(function(result, value, key) { |
|
if (hasOwnProperty$1.call(result, key)) { |
|
result[key].push(value); |
|
} else { |
|
result[key] = [value]; |
|
} |
|
}); |
|
|
|
/** |
|
* Checks if `value` is greater than `other`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`. |
|
* @example |
|
* |
|
* _.gt(3, 1); |
|
* // => true |
|
* |
|
* _.gt(3, 3); |
|
* // => false |
|
* |
|
* _.gt(1, 3); |
|
* // => false |
|
*/ |
|
function gt(value, other) { |
|
return value > other; |
|
} |
|
|
|
/** |
|
* Checks if `value` is greater than or equal to `other`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`. |
|
* @example |
|
* |
|
* _.gte(3, 1); |
|
* // => true |
|
* |
|
* _.gte(3, 3); |
|
* // => true |
|
* |
|
* _.gte(1, 3); |
|
* // => false |
|
*/ |
|
function gte(value, other) { |
|
return value >= other; |
|
} |
|
|
|
/** |
|
* Checks if `path` is a direct property of `object`. |
|
* |
|
* @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` exists, else `false`. |
|
* @example |
|
* |
|
* var object = { 'a': { 'b': { 'c': 3 } } }; |
|
* var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) }); |
|
* |
|
* _.has(object, 'a'); |
|
* // => true |
|
* |
|
* _.has(object, 'a.b.c'); |
|
* // => true |
|
* |
|
* _.has(object, ['a', 'b', 'c']); |
|
* // => true |
|
* |
|
* _.has(other, 'a'); |
|
* // => false |
|
*/ |
|
function has(object, path) { |
|
return hasPath(object, path, baseHas); |
|
} |
|
|
|
/** |
|
* Gets the first element of `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @alias first |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @returns {*} Returns the first element of `array`. |
|
* @example |
|
* |
|
* _.head([1, 2, 3]); |
|
* // => 1 |
|
* |
|
* _.head([]); |
|
* // => undefined |
|
*/ |
|
function head(array) { |
|
return array ? array[0] : undefined; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$2 = Math.max; |
|
var nativeMin = Math.min; |
|
/** |
|
* Checks if `n` is between `start` and up to but not including, `end`. If |
|
* `end` is not specified it's set to `start` with `start` then set to `0`. |
|
* If `start` is greater than `end` the params are swapped to support |
|
* negative ranges. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Number |
|
* @param {number} number The number to check. |
|
* @param {number} [start=0] The start of the range. |
|
* @param {number} end The end of the range. |
|
* @returns {boolean} Returns `true` if `number` is in the range, else `false`. |
|
* @example |
|
* |
|
* _.inRange(3, 2, 4); |
|
* // => true |
|
* |
|
* _.inRange(4, 8); |
|
* // => true |
|
* |
|
* _.inRange(4, 2); |
|
* // => false |
|
* |
|
* _.inRange(2, 2); |
|
* // => false |
|
* |
|
* _.inRange(1.2, 2); |
|
* // => true |
|
* |
|
* _.inRange(5.2, 4); |
|
* // => false |
|
* |
|
* _.inRange(-3, -2, -6); |
|
* // => true |
|
*/ |
|
function inRange(number, start, end) { |
|
start = +start || 0; |
|
if (end === undefined) { |
|
end = start; |
|
start = 0; |
|
} else { |
|
end = +end || 0; |
|
} |
|
return number >= nativeMin(start, end) && number < nativeMax$2(start, end); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.values` and `_.valuesIn` which creates an |
|
* array of `object` property values corresponding to the property names |
|
* 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. |
|
*/ |
|
function baseValues(object, props) { |
|
return arrayMap(props, function(key) { |
|
return object[key]; |
|
}); |
|
} |
|
|
|
/** |
|
* Creates an array of the own enumerable property values of `object`. |
|
* |
|
* **Note:** Non-object values are coerced to objects. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the array of property values. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.values(new Foo); |
|
* // => [1, 2] (iteration order is not guaranteed) |
|
* |
|
* _.values('hi'); |
|
* // => ['h', 'i'] |
|
*/ |
|
function values(object) { |
|
return object ? baseValues(object, keys(object)) : []; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$3 = Math.max; |
|
|
|
/** |
|
* Checks if `target` is in `collection` using |
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. If `fromIndex` is negative, it's used as the offset |
|
* from the end of `collection`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object|string} collection The collection to search. |
|
* @param {*} target The value to search for. |
|
* @param {number} [fromIndex=0] The index to search from. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`. |
|
* @returns {boolean} Returns `true` if a matching element is found, else `false`. |
|
* @example |
|
* |
|
* _.includes([1, 2, 3], 1); |
|
* // => true |
|
* |
|
* _.includes([1, 2, 3], 1, 2); |
|
* // => false |
|
* |
|
* _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); |
|
* // => true |
|
* |
|
* _.includes('pebbles', 'eb'); |
|
* // => true |
|
*/ |
|
function includes(collection, target, fromIndex, guard) { |
|
collection = isArrayLike(collection) ? collection : values(collection); |
|
fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; |
|
|
|
var length = collection.length; |
|
if (fromIndex < 0) { |
|
fromIndex = nativeMax$3(length + fromIndex, 0); |
|
} |
|
return isString(collection) |
|
? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1) |
|
: (!!length && baseIndexOf(collection, target, fromIndex) > -1); |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$4 = Math.max; |
|
|
|
/** |
|
* Gets the index at which the first occurrence of `value` is found in `array` |
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. If `fromIndex` is negative, it's used as the offset |
|
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex` |
|
* performs a faster binary search. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to search. |
|
* @param {*} value The value to search for. |
|
* @param {number} [fromIndex=0] The index to search from. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
* @example |
|
* |
|
* _.indexOf([1, 2, 1, 2], 2); |
|
* // => 1 |
|
* |
|
* // using `fromIndex` |
|
* _.indexOf([1, 2, 1, 2], 2, 2); |
|
* // => 3 |
|
*/ |
|
function indexOf$1(array, value, fromIndex) { |
|
var length = array ? array.length : 0; |
|
if (!length) { |
|
return -1; |
|
} |
|
fromIndex = fromIndex ? toInteger(fromIndex) : 0; |
|
if (fromIndex < 0) { |
|
fromIndex = nativeMax$4(length + fromIndex, 0); |
|
} |
|
return baseIndexOf(array, value, fromIndex); |
|
} |
|
|
|
/** |
|
* Gets all but the last element of `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* _.initial([1, 2, 3]); |
|
* // => [1, 2] |
|
*/ |
|
function initial(array) { |
|
return dropRight(array, 1); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.intersectionBy` without support for callback |
|
* shorthands. |
|
* |
|
* @private |
|
* @param {Array} arrays The arrays to inspect. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns the new array of shared values. |
|
*/ |
|
function baseIntersectionBy(arrays, iteratee) { |
|
var othLength = arrays.length, |
|
othIndex = othLength, |
|
caches = Array(othLength), |
|
result = []; |
|
|
|
while (othIndex--) { |
|
var array = arrays[othIndex]; |
|
if (othIndex && iteratee) { |
|
array = arrayMap(array, function(value) { return iteratee(value); }); |
|
} |
|
caches[othIndex] = (iteratee || array.length >= 120) ? new SetCache(othIndex && array) : null; |
|
} |
|
array = arrays[0]; |
|
|
|
var index = -1, |
|
length = array ? array.length : 0, |
|
seen = caches[0]; |
|
|
|
outer: |
|
while (++index < length) { |
|
var value = array[index], |
|
computed = iteratee ? iteratee(value) : value; |
|
|
|
if ((seen ? cacheIndexOf(seen, computed) : baseIndexOf(result, computed, 0)) < 0) { |
|
var othIndex = othLength; |
|
while (--othIndex) { |
|
var cache = caches[othIndex]; |
|
if ((cache ? cacheIndexOf(cache, computed) : baseIndexOf(arrays[othIndex], computed, 0)) < 0) { |
|
continue outer; |
|
} |
|
} |
|
if (seen) { |
|
seen.push(computed); |
|
} |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.intersection` that accepts an array of arrays |
|
* to inspect. |
|
* |
|
* @private |
|
* @param {Array} arrays The arrays to inspect. |
|
* @returns {Array} Returns the new array of shared values. |
|
*/ |
|
function baseIntersection(arrays) { |
|
return baseIntersectionBy(arrays); |
|
} |
|
|
|
/** |
|
* Converts `value` to an array-like object if it's not one. |
|
* |
|
* @private |
|
* @param {*} value The value to process. |
|
* @returns {Array} Returns the array-like object. |
|
*/ |
|
function toArrayLikeObject(value) { |
|
return isArrayLikeObject(value) ? value : []; |
|
} |
|
|
|
/** |
|
* Creates an array of unique values that are included in all of the provided |
|
* arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to inspect. |
|
* @returns {Array} Returns the new array of shared values. |
|
* @example |
|
* _.intersection([2, 1], [4, 2], [1, 2]); |
|
* // => [2] |
|
*/ |
|
var intersection = rest(function(arrays) { |
|
var mapped = arrayMap(arrays, toArrayLikeObject); |
|
return (mapped.length && mapped[0] === arrays[0]) |
|
? baseIntersection(mapped) |
|
: []; |
|
}); |
|
|
|
/** |
|
* This method is like `_.intersection` except that it accepts `iteratee` |
|
* which is invoked for each element of each `arrays` to generate the criterion |
|
* by which uniqueness is computed. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to inspect. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Array} Returns the new array of shared values. |
|
* @example |
|
* |
|
* _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); |
|
* // => [2.1] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); |
|
* // => [{ 'x': 1 }] |
|
*/ |
|
var intersectionBy = rest(function(arrays) { |
|
var iteratee = last(arrays), |
|
mapped = arrayMap(arrays, toArrayLikeObject); |
|
|
|
if (iteratee === last(mapped)) { |
|
iteratee = undefined; |
|
} else { |
|
mapped.pop(); |
|
} |
|
return (mapped.length && mapped[0] === arrays[0]) |
|
? baseIntersectionBy(mapped, baseIteratee(iteratee)) |
|
: []; |
|
}); |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$2 = Object.prototype; |
|
|
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$2 = objectProto$2.hasOwnProperty; |
|
|
|
/** |
|
* Creates an object composed of the inverted keys and values of `object`. |
|
* If `object` contains duplicate values, subsequent values overwrite property |
|
* assignments of previous values unless `multiVal` is `true`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to invert. |
|
* @param {boolean} [multiVal] Allow multiple values per key. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Object} Returns the new inverted object. |
|
* @example |
|
* |
|
* var object = { 'a': 1, 'b': 2, 'c': 1 }; |
|
* |
|
* _.invert(object); |
|
* // => { '1': 'c', '2': 'b' } |
|
* |
|
* // with `multiVal` |
|
* _.invert(object, true); |
|
* // => { '1': ['a', 'c'], '2': ['b'] } |
|
*/ |
|
function invert(object, multiVal, guard) { |
|
return arrayReduce(keys(object), function(result, key) { |
|
var value = object[key]; |
|
if (multiVal && !guard) { |
|
if (hasOwnProperty$2.call(result, value)) { |
|
result[value].push(key); |
|
} else { |
|
result[value] = [key]; |
|
} |
|
} |
|
else { |
|
result[value] = key; |
|
} |
|
return result; |
|
}, {}); |
|
} |
|
|
|
/** |
|
* Invokes the method at `path` of `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 (!isKey(path, object)) { |
|
path = baseToPath(path); |
|
object = parent$1(object, path); |
|
path = last(path); |
|
} |
|
var func = object == null ? object : object[path]; |
|
return func == null ? undefined : func.apply(object, args); |
|
} |
|
|
|
/** |
|
* Invokes the method at `path` of 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's |
|
* invoked for, and `this` bound to, each element in `collection`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @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 |
|
* |
|
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); |
|
* // => [[1, 5, 7], [1, 2, 3]] |
|
* |
|
* _.invoke([123, 456], String.prototype.split, ''); |
|
* // => [['1', '2', '3'], ['4', '5', '6']] |
|
*/ |
|
var invoke = rest(function(collection, path, args) { |
|
var index = -1, |
|
isFunc = typeof path == 'function', |
|
isProp = isKey(path), |
|
result = isArrayLike(collection) ? Array(collection.length) : []; |
|
|
|
baseEach(collection, function(value) { |
|
var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined); |
|
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args); |
|
}); |
|
return result; |
|
}); |
|
|
|
/** `Object#toString` result references. */ |
|
var boolTag = '[object Boolean]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$4 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$1 = objectProto$4.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a boolean primitive or object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isBoolean(false); |
|
* // => true |
|
* |
|
* _.isBoolean(null); |
|
* // => false |
|
*/ |
|
function isBoolean(value) { |
|
return value === true || value === false || |
|
(isObjectLike(value) && objToString$1.call(value) == boolTag); |
|
} |
|
|
|
/** `Object#toString` result references. */ |
|
var dateTag = '[object Date]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$5 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$2 = objectProto$5.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a `Date` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isDate(new Date); |
|
* // => true |
|
* |
|
* _.isDate('Mon April 23 2012'); |
|
* // => false |
|
*/ |
|
function isDate(value) { |
|
return isObjectLike(value) && objToString$2.call(value) == dateTag; |
|
} |
|
|
|
/** |
|
* Checks if `value` is likely a DOM element. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. |
|
* @example |
|
* |
|
* _.isElement(document.body); |
|
* // => true |
|
* |
|
* _.isElement('<body>'); |
|
* // => false |
|
*/ |
|
function isElement(value) { |
|
return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value); |
|
} |
|
|
|
/** Used to compose unicode character classes. */ |
|
var rsAstralRange$4 = '\\ud800-\\udfff'; |
|
var rsComboRange$4 = '\\u0300-\\u036f\\ufe20-\\ufe23'; |
|
var rsVarRange$4 = '\\ufe0e\\ufe0f'; |
|
var rsAstral = '[' + rsAstralRange$4 + ']'; |
|
var rsCombo$1 = '[' + rsComboRange$4 + ']'; |
|
var rsModifier$1 = '(?:\\ud83c[\\udffb-\\udfff])'; |
|
var rsNonAstral$1 = '[^' + rsAstralRange$4 + ']'; |
|
var rsRegional$1 = '(?:\\ud83c[\\udde6-\\uddff]){2}'; |
|
var rsSurrPair$1 = '[\\ud800-\\udbff][\\udc00-\\udfff]'; |
|
var rsZWJ$4 = '\\u200d'; |
|
var reOptMod$1 = rsModifier$1 + '?'; |
|
var rsOptVar$1 = '[' + rsVarRange$4 + ']?'; |
|
var rsOptJoin$1 = '(?:' + rsZWJ$4 + '(?:' + [rsNonAstral$1, rsRegional$1, rsSurrPair$1].join('|') + ')' + rsOptVar$1 + reOptMod$1 + ')*'; |
|
var rsSeq$1 = rsOptVar$1 + reOptMod$1 + rsOptJoin$1; |
|
var rsSymbol = '(?:' + [rsNonAstral$1 + rsCombo$1 + '?', rsCombo$1, rsRegional$1, rsSurrPair$1, rsAstral].join('|') + ')'; |
|
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ |
|
var reComplexSymbol = RegExp(rsSymbol + rsSeq$1, 'g'); |
|
|
|
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ |
|
var reHasComplexSymbol$3 = RegExp('[' + rsZWJ$4 + rsAstralRange$4 + rsComboRange$4 + rsVarRange$4 + ']'); |
|
|
|
/** |
|
* Gets the number of symbols in `string`. |
|
* |
|
* @param {string} string The string to inspect. |
|
* @returns {number} Returns the string size. |
|
*/ |
|
function stringSize(string) { |
|
if (!(string && reHasComplexSymbol$3.test(string))) { |
|
return string.length; |
|
} |
|
var result = reComplexSymbol.lastIndex = 0; |
|
while (reComplexSymbol.test(string)) { |
|
result++; |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the size of `collection` by returning its length for array-like |
|
* values or the number of own enumerable properties for objects. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to inspect. |
|
* @returns {number} Returns the collection size. |
|
* @example |
|
* |
|
* _.size([1, 2, 3]); |
|
* // => 3 |
|
* |
|
* _.size({ 'a': 1, 'b': 2 }); |
|
* // => 2 |
|
* |
|
* _.size('pebbles'); |
|
* // => 7 |
|
*/ |
|
function size$1(collection) { |
|
if (collection == null) { |
|
return 0; |
|
} |
|
if (isArrayLike(collection)) { |
|
var result = collection.length; |
|
return (result && isString(collection)) ? stringSize(collection) : result; |
|
} |
|
return keys(collection).length; |
|
} |
|
|
|
/** |
|
* Checks if `value` is empty. A value is considered empty unless it's an |
|
* `arguments` object, array, string, or jQuery-like collection with a length |
|
* greater than `0` or an object with own enumerable properties. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {Array|Object|string} value The value to inspect. |
|
* @returns {boolean} Returns `true` if `value` is empty, else `false`. |
|
* @example |
|
* |
|
* _.isEmpty(null); |
|
* // => true |
|
* |
|
* _.isEmpty(true); |
|
* // => true |
|
* |
|
* _.isEmpty(1); |
|
* // => true |
|
* |
|
* _.isEmpty([1, 2, 3]); |
|
* // => false |
|
* |
|
* _.isEmpty({ 'a': 1 }); |
|
* // => false |
|
*/ |
|
function isEmpty(value) { |
|
return (!isObjectLike(value) || isFunction(value.splice)) |
|
? !size$1(value) |
|
: !keys(value).length; |
|
} |
|
|
|
/** |
|
* Performs a deep comparison between two values to determine if they are |
|
* equivalent. |
|
* |
|
* **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. Functions and DOM nodes |
|
* are **not** supported. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred' }; |
|
* var other = { 'user': 'fred' }; |
|
* |
|
* _.isEqual(object, other); |
|
* // => true |
|
* |
|
* object === other; |
|
* // => false |
|
*/ |
|
function isEqual(value, other) { |
|
return baseIsEqual(value, other); |
|
} |
|
|
|
/** |
|
* This method is like `_.isEqual` except that it accepts `customizer` which is |
|
* invoked to compare values. If `customizer` returns `undefined` comparisons are |
|
* handled by the method instead. The `customizer` is invoked with up to seven arguments: |
|
* (objValue, othValue [, index|key, object, other, stack]). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @param {Function} [customizer] The function to customize comparisons. |
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. |
|
* @example |
|
* |
|
* function isGreeting(value) { |
|
* return /^h(?:i|ello)$/.test(value); |
|
* } |
|
* |
|
* function customizer(objValue, othValue) { |
|
* if (isGreeting(objValue) && isGreeting(othValue)) { |
|
* return true; |
|
* } |
|
* } |
|
* |
|
* var array = ['hello', 'goodbye']; |
|
* var other = ['hi', 'goodbye']; |
|
* |
|
* _.isEqualWith(array, other, customizer); |
|
* // => true |
|
*/ |
|
function isEqualWith(value, other, customizer) { |
|
customizer = typeof customizer == 'function' ? customizer : undefined; |
|
var result = customizer ? customizer(value, other) : undefined; |
|
return result === undefined ? baseIsEqual(value, other, customizer) : !!result; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeIsFinite = root.isFinite; |
|
|
|
/** |
|
* Checks if `value` is a finite primitive number. |
|
* |
|
* **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a finite number, else `false`. |
|
* @example |
|
* |
|
* _.isFinite(3); |
|
* // => true |
|
* |
|
* _.isFinite(Number.MAX_VALUE); |
|
* // => true |
|
* |
|
* _.isFinite(3.14); |
|
* // => true |
|
* |
|
* _.isFinite(Infinity); |
|
* // => false |
|
*/ |
|
function isFinite(value) { |
|
return typeof value == 'number' && nativeIsFinite(value); |
|
} |
|
|
|
/** |
|
* Checks if `value` is an integer. |
|
* |
|
* **Note:** This method is based on [`Number.isInteger`](http://ecma-international.org/ecma-262/6.0/#sec-number.isinteger). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is an integer, else `false`. |
|
* @example |
|
* |
|
* _.isInteger(3); |
|
* // => true |
|
* |
|
* _.isInteger(Number.MAX_VALUE); |
|
* // => true |
|
* |
|
* _.isInteger(3.14); |
|
* // => false |
|
* |
|
* _.isInteger(Infinity); |
|
* // => false |
|
*/ |
|
function isInteger(value) { |
|
return typeof value == 'number' && value == toInteger(value); |
|
} |
|
|
|
/** |
|
* Performs a deep comparison between `object` and `source` to determine if |
|
* `object` contains equivalent property values. |
|
* |
|
* **Note:** This method supports comparing properties of arrays, booleans, |
|
* `Date` objects, numbers, `Object` objects, regexes, and strings. Functions |
|
* and DOM nodes are **not** supported. Provide a customizer function to extend |
|
* support for comparing other values. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {Object} object The object to inspect. |
|
* @param {Object} source The object of property values to match. |
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred', 'age': 40 }; |
|
* |
|
* _.isMatch(object, { 'age': 40 }); |
|
* // => true |
|
* |
|
* _.isMatch(object, { 'age': 36 }); |
|
* // => false |
|
*/ |
|
function isMatch(object, source) { |
|
return object === source || baseIsMatch(object, source, getMatchData(source)); |
|
} |
|
|
|
/** |
|
* This method is like `_.isMatch` except that it accepts `customizer` which |
|
* is invoked to compare values. If `customizer` returns `undefined` comparisons |
|
* are handled by the method instead. The `customizer` is invoked with three |
|
* arguments: (objValue, srcValue, index|key, object, source). |
|
* |
|
* @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 comparisons. |
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`. |
|
* @example |
|
* |
|
* function isGreeting(value) { |
|
* return /^h(?:i|ello)$/.test(value); |
|
* } |
|
* |
|
* function customizer(objValue, srcValue) { |
|
* if (isGreeting(objValue) && isGreeting(srcValue)) { |
|
* return true; |
|
* } |
|
* } |
|
* |
|
* var object = { 'greeting': 'hello' }; |
|
* var source = { 'greeting': 'hi' }; |
|
* |
|
* _.isMatchWith(object, source, customizer); |
|
* // => true |
|
*/ |
|
function isMatchWith(object, source, customizer) { |
|
customizer = typeof customizer == 'function' ? customizer : undefined; |
|
return baseIsMatch(object, source, getMatchData(source), customizer); |
|
} |
|
|
|
/** `Object#toString` result references. */ |
|
var numberTag = '[object Number]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$9 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$5 = objectProto$9.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a `Number` primitive or object. |
|
* |
|
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified |
|
* as numbers, use the `_.isFinite` method. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isNumber(8.4); |
|
* // => true |
|
* |
|
* _.isNumber(NaN); |
|
* // => true |
|
* |
|
* _.isNumber('8.4'); |
|
* // => false |
|
*/ |
|
function isNumber(value) { |
|
return typeof value == 'number' || |
|
(isObjectLike(value) && objToString$5.call(value) == numberTag); |
|
} |
|
|
|
/** |
|
* Checks if `value` is `NaN`. |
|
* |
|
* **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4) |
|
* which returns `true` for `undefined` and other non-numeric values. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. |
|
* @example |
|
* |
|
* _.isNaN(NaN); |
|
* // => true |
|
* |
|
* _.isNaN(new Number(NaN)); |
|
* // => true |
|
* |
|
* isNaN(undefined); |
|
* // => true |
|
* |
|
* _.isNaN(undefined); |
|
* // => false |
|
*/ |
|
function isNaN(value) { |
|
// An `NaN` primitive is the only value that is not equal to itself. |
|
// Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE. |
|
return isNumber(value) && value != +value; |
|
} |
|
|
|
/** |
|
* Checks if `value` is `null` or `undefined`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is nullish, else `false`. |
|
* @example |
|
* |
|
* _.isNil(null); |
|
* // => true |
|
* |
|
* _.isNil(void 0); |
|
* // => true |
|
* |
|
* _.isNil(NaN); |
|
* // => false |
|
*/ |
|
function isNil$1(value) { |
|
return value == null; |
|
} |
|
|
|
/** |
|
* Checks if `value` is `null`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is `null`, else `false`. |
|
* @example |
|
* |
|
* _.isNull(null); |
|
* // => true |
|
* |
|
* _.isNull(void 0); |
|
* // => false |
|
*/ |
|
function isNull(value) { |
|
return value === null; |
|
} |
|
|
|
/** `Object#toString` result references. */ |
|
var regexpTag = '[object RegExp]'; |
|
|
|
/** Used for built-in method references. */ |
|
var objectProto$11 = Object.prototype; |
|
|
|
/** |
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) |
|
* of values. |
|
*/ |
|
var objToString$7 = objectProto$11.toString; |
|
|
|
/** |
|
* Checks if `value` is classified as a `RegExp` object. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. |
|
* @example |
|
* |
|
* _.isRegExp(/abc/); |
|
* // => true |
|
* |
|
* _.isRegExp('/abc/'); |
|
* // => false |
|
*/ |
|
function isRegExp(value) { |
|
return isObject(value) && objToString$7.call(value) == regexpTag; |
|
} |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var MAX_SAFE_INTEGER = 9007199254740991; |
|
|
|
/** |
|
* Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 |
|
* double precision number which isn't the result of a rounded unsafe integer. |
|
* |
|
* **Note:** This method is based on [`Number.isSafeInteger`](http://ecma-international.org/ecma-262/6.0/#sec-number.issafeinteger). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. |
|
* @example |
|
* |
|
* _.isSafeInteger(3); |
|
* // => true |
|
* |
|
* _.isSafeInteger(Number.MAX_VALUE); |
|
* // => false |
|
* |
|
* _.isSafeInteger(3.14); |
|
* // => false |
|
* |
|
* _.isSafeInteger(Infinity); |
|
* // => false |
|
*/ |
|
function isSafeInteger(value) { |
|
return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER; |
|
} |
|
|
|
/** |
|
* Checks if `value` is `undefined`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to check. |
|
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. |
|
* @example |
|
* |
|
* _.isUndefined(void 0); |
|
* // => true |
|
* |
|
* _.isUndefined(null); |
|
* // => false |
|
*/ |
|
function isUndefined(value) { |
|
return value === undefined; |
|
} |
|
|
|
/** |
|
* Creates a function that performs a deep partial comparison between a given |
|
* object and `source`, returning `true` if the given object has equivalent |
|
* property values, else `false`. |
|
* |
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects, |
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by |
|
* their own and inherited enumerable properties. For comparing a single |
|
* value see `_.matchesProperty`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Object} source The object of property values to match. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36, 'active': true }, |
|
* { 'user': 'fred', 'age': 40, 'active': false } |
|
* ]; |
|
* |
|
* _.filter(users, _.matches({ 'age': 40, 'active': false })); |
|
* // => [{ 'user': 'fred', 'age': 40, 'active': false }] |
|
*/ |
|
function matches(source) { |
|
return baseMatches(baseClone(source, true)); |
|
} |
|
|
|
/** |
|
* Creates a function that invokes `func` with the arguments of the created |
|
* function. If `func` is a property name the created callback returns the |
|
* property value for a given element. If `func` is an object the created |
|
* callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {*} [func=_.identity] The value to convert to a callback. |
|
* @returns {Function} Returns the callback. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 40 } |
|
* ]; |
|
* |
|
* // wrap to create custom callback shorthands |
|
* _.iteratee = _.wrap(_.iteratee, function(callback, func, thisArg) { |
|
* var match = /^(.+?)__([gl]t)(.+)$/.exec(func); |
|
* if (!match) { |
|
* return callback(func, thisArg); |
|
* } |
|
* return function(object) { |
|
* return match[2] == 'gt' |
|
* ? object[match[1]] > match[3] |
|
* : object[match[1]] < match[3]; |
|
* }; |
|
* }); |
|
* |
|
* _.filter(users, 'age__gt36'); |
|
* // => [{ 'user': 'fred', 'age': 40 }] |
|
*/ |
|
function iteratee$1(func) { |
|
return (isObjectLike(func) && !isArray(func)) |
|
? matches(func) |
|
: baseIteratee(func); |
|
} |
|
|
|
/** |
|
* Creates a function that invokes `iteratees` with the arguments provided |
|
* to the created function and returns their results. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {...(Function|Function[])} iteratees The iteratees to invoke. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var juxted = _.juxt(Math.max, Math.min); |
|
* |
|
* juxted(1, 2, 3, 4); |
|
* // => [4, 1] |
|
*/ |
|
var juxt = createInvoker(arrayMap); |
|
|
|
/** |
|
* Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the kebab cased string. |
|
* @example |
|
* |
|
* _.kebabCase('Foo Bar'); |
|
* // => 'foo-bar' |
|
* |
|
* _.kebabCase('fooBar'); |
|
* // => 'foo-bar' |
|
* |
|
* _.kebabCase('__foo_bar__'); |
|
* // => 'foo-bar' |
|
*/ |
|
var kebabCase = createCompounder(function(result, word, index) { |
|
return result + (index ? '-' : '') + word.toLowerCase(); |
|
}); |
|
|
|
/** |
|
* Creates an object composed of keys generated from the results of running |
|
* each element of `collection` through `iteratee`. The corresponding value |
|
* of each key is the last element responsible for generating the key. The |
|
* iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Object} Returns the composed aggregate object. |
|
* @example |
|
* |
|
* var keyData = [ |
|
* { 'dir': 'left', 'code': 97 }, |
|
* { 'dir': 'right', 'code': 100 } |
|
* ]; |
|
* |
|
* _.keyBy(keyData, 'dir'); |
|
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } |
|
* |
|
* _.keyBy(keyData, function(o) { |
|
* return String.fromCharCode(o.code); |
|
* }); |
|
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } |
|
*/ |
|
var keyBy = createAggregator(function(result, value, key) { |
|
result[key] = value; |
|
}); |
|
|
|
var nativeMax$5 = Math.max; |
|
var nativeMin$1 = Math.min; |
|
/** |
|
* This method is like `_.indexOf` except that it iterates over elements of |
|
* `array` from right to left. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to search. |
|
* @param {*} value The value to search for. |
|
* @param {number} [fromIndex=array.length-1] The index to search from. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
* @example |
|
* |
|
* _.lastIndexOf([1, 2, 1, 2], 2); |
|
* // => 3 |
|
* |
|
* // using `fromIndex` |
|
* _.lastIndexOf([1, 2, 1, 2], 2, 2); |
|
* // => 1 |
|
*/ |
|
function lastIndexOf(array, value, fromIndex) { |
|
var length = array ? array.length : 0; |
|
if (!length) { |
|
return -1; |
|
} |
|
var index = length; |
|
if (fromIndex !== undefined) { |
|
index = toInteger(fromIndex); |
|
index = (index < 0 ? nativeMax$5(length + index, 0) : nativeMin$1(index, length - 1)) + 1; |
|
} |
|
if (value !== value) { |
|
return indexOfNaN(array, index, true); |
|
} |
|
while (index--) { |
|
if (array[index] === value) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* Converts `string`, as space separated words, to lower case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the lower cased string. |
|
* @example |
|
* |
|
* _.lowerCase('--Foo-Bar'); |
|
* // => 'foo bar' |
|
* |
|
* _.lowerCase('fooBar'); |
|
* // => 'foo bar' |
|
* |
|
* _.lowerCase('__FOO_BAR__'); |
|
* // => 'foo bar' |
|
*/ |
|
var lowerCase = createCompounder(function(result, word, index) { |
|
return result + (index ? ' ' : '') + word.toLowerCase(); |
|
}); |
|
|
|
/** |
|
* Converts the first character of `string` to lower case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the converted string. |
|
* @example |
|
* |
|
* _.lowerFirst('Fred'); |
|
* // => 'fred' |
|
* |
|
* _.lowerFirst('FRED'); |
|
* // => 'fRED' |
|
*/ |
|
var lowerFirst = createCaseFirst('toLowerCase'); |
|
|
|
/** |
|
* Checks if `value` is less than `other`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`. |
|
* @example |
|
* |
|
* _.lt(1, 3); |
|
* // => true |
|
* |
|
* _.lt(3, 3); |
|
* // => false |
|
* |
|
* _.lt(3, 1); |
|
* // => false |
|
*/ |
|
function lt(value, other) { |
|
return value < other; |
|
} |
|
|
|
/** |
|
* Checks if `value` is less than or equal to `other`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`. |
|
* @example |
|
* |
|
* _.lte(1, 3); |
|
* // => true |
|
* |
|
* _.lte(3, 3); |
|
* // => true |
|
* |
|
* _.lte(3, 1); |
|
* // => false |
|
*/ |
|
function lte(value, other) { |
|
return value <= other; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.map` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array|Object} 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 index = -1, |
|
result = isArrayLike(collection) ? Array(collection.length) : []; |
|
|
|
baseEach(collection, function(value, key, collection) { |
|
result[++index] = iteratee(value, key, collection); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an array of values by running each element in `collection` through |
|
* `iteratee`. The iteratee is invoked with three arguments: |
|
* (value, index|key, collection). |
|
* |
|
* Many lodash methods are guarded to work as iteratees for methods like |
|
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. |
|
* |
|
* The guarded methods are: |
|
* `ary`, `callback`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, |
|
* `fill`, `invert`, `parseInt`, `random`, `range`, `slice`, `some`, `sortBy`, |
|
* `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`, `uniq`, |
|
* and `words` |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the new mapped array. |
|
* @example |
|
* |
|
* function square(n) { |
|
* return n * n; |
|
* } |
|
* |
|
* _.map([1, 2], square); |
|
* // => [3, 6] |
|
* |
|
* _.map({ 'a': 1, 'b': 2 }, square); |
|
* // => [3, 6] (iteration order is not guaranteed) |
|
* |
|
* var users = [ |
|
* { 'user': 'barney' }, |
|
* { 'user': 'fred' } |
|
* ]; |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.map(users, 'user'); |
|
* // => ['barney', 'fred'] |
|
*/ |
|
function map(collection, iteratee) { |
|
var func = isArray(collection) ? arrayMap : baseMap; |
|
return func(collection, baseIteratee(iteratee, 3)); |
|
} |
|
|
|
/** |
|
* The opposite of `_.mapValues`; this method creates an object with the |
|
* same values as `object` and keys generated by running each own enumerable |
|
* property of `object` through `iteratee`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Object} Returns the new mapped object. |
|
* @example |
|
* |
|
* _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { |
|
* return key + value; |
|
* }); |
|
* // => { 'a1': 1, 'b2': 2 } |
|
*/ |
|
function mapKeys(object, iteratee) { |
|
var result = {}; |
|
iteratee = baseIteratee(iteratee, 3); |
|
|
|
baseForOwn(object, function(value, key, object) { |
|
result[iteratee(value, key, object)] = value; |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates an object with the same keys as `object` and values generated by |
|
* running each own enumerable property of `object` through `iteratee`. The |
|
* iteratee function is invoked with three arguments: (value, key, object). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Object} Returns the new mapped object. |
|
* @example |
|
* |
|
* var users = { |
|
* 'fred': { 'user': 'fred', 'age': 40 }, |
|
* 'pebbles': { 'user': 'pebbles', 'age': 1 } |
|
* }; |
|
* |
|
* _.mapValues(users, function(o) { return o.age; }); |
|
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.mapValues(users, 'age'); |
|
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) |
|
*/ |
|
function mapValues(object, iteratee) { |
|
var result = {}; |
|
iteratee = baseIteratee(iteratee, 3); |
|
|
|
baseForOwn(object, function(value, key, object) { |
|
result[key] = iteratee(value, key, object); |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* Creates a function that performs a deep partial comparison between the |
|
* value at `path` of a given object to `srcValue`, returning `true` if the |
|
* object value is equivalent, else `false`. |
|
* |
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects, |
|
* numbers, `Object` objects, regexes, and strings. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Array|string} path The path of the property to get. |
|
* @param {*} srcValue The value to match. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney' }, |
|
* { 'user': 'fred' } |
|
* ]; |
|
* |
|
* _.find(users, _.matchesProperty('user', 'fred')); |
|
* // => { 'user': 'fred' } |
|
*/ |
|
function matchesProperty(path, srcValue) { |
|
return baseMatchesProperty(path, baseClone(srcValue, true)); |
|
} |
|
|
|
/** |
|
* The base implementation of methods like `_.max` and `_.min` which accepts a |
|
* `comparator` to determine the extremum value. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @param {Function} comparator The function used to compare values. |
|
* @returns {*} Returns the extremum value. |
|
*/ |
|
function baseExtremum(array, iteratee, comparator) { |
|
var index = -1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
var value = array[index], |
|
current = iteratee(value); |
|
|
|
if (current != null && (computed === undefined |
|
? current === current |
|
: comparator(current, computed) |
|
)) { |
|
var computed = current, |
|
result = value; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the maximum value of `array`. If `array` is empty or falsey |
|
* `undefined` is returned. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {Array} array The array to iterate over. |
|
* @returns {*} Returns the maximum value. |
|
* @example |
|
* |
|
* _.max([4, 2, 8, 6]); |
|
* // => 8 |
|
* |
|
* _.max([]); |
|
* // => undefined |
|
*/ |
|
function max(array) { |
|
return (array && array.length) |
|
? baseExtremum(array, identity, gt) |
|
: undefined; |
|
} |
|
|
|
/** |
|
* This method is like `_.max` except that it accepts `iteratee` which is |
|
* invoked for each element in `array` to generate the criterion by which |
|
* the value is ranked. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {*} Returns the maximum value. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 40 } |
|
* ]; |
|
* |
|
* _.maxBy(users, function(o) { return o.age; }); |
|
* // => { 'user': 'fred', 'age': 40 } |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.maxBy(users, 'age'); |
|
* // => { 'user': 'fred', 'age': 40 } |
|
*/ |
|
function maxBy(array, iteratee) { |
|
return (array && array.length) |
|
? baseExtremum(array, baseIteratee(iteratee), gt) |
|
: undefined; |
|
} |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$3 = 'Expected a function'; |
|
|
|
/** |
|
* Creates a function that memoizes the result of `func`. If `resolver` is |
|
* provided it determines the cache key for storing the result based on the |
|
* arguments provided to the memoized function. By default, the first argument |
|
* provided to the memoized function is used as the map cache key. The `func` |
|
* is invoked with the `this` binding of the memoized function. |
|
* |
|
* **Note:** The cache is exposed as the `cache` property on the memoized |
|
* function. Its creation may be customized by replacing the `_.memoize.Cache` |
|
* constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object) |
|
* method interface of `get`, `has`, and `set`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to have its output memoized. |
|
* @param {Function} [resolver] The function to resolve the cache key. |
|
* @returns {Function} Returns the new memoizing function. |
|
* @example |
|
* |
|
* var object = { 'a': 1, 'b': 2 }; |
|
* var other = { 'c': 3, 'd': 4 }; |
|
* |
|
* var values = _.memoize(_.values); |
|
* values(object); |
|
* // => [1, 2] |
|
* |
|
* values(other); |
|
* // => [3, 4] |
|
* |
|
* object.a = 2; |
|
* values(object); |
|
* // => [1, 2] |
|
* |
|
* // modifying the result cache |
|
* values.cache.set(object, ['a', 'b']); |
|
* values(object); |
|
* // => ['a', 'b'] |
|
* |
|
* // replacing `_.memoize.Cache` |
|
* _.memoize.Cache = WeakMap; |
|
*/ |
|
function memoize(func, resolver) { |
|
if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { |
|
throw new TypeError(FUNC_ERROR_TEXT$3); |
|
} |
|
var memoized = function() { |
|
var args = arguments, |
|
key = resolver ? resolver.apply(this, args) : args[0], |
|
cache = memoized.cache; |
|
|
|
if (cache.has(key)) { |
|
return cache.get(key); |
|
} |
|
var result = func.apply(this, args); |
|
memoized.cache = cache.set(key, result); |
|
return result; |
|
}; |
|
memoized.cache = new memoize.Cache; |
|
return memoized; |
|
} |
|
|
|
// Assign cache to `_.memoize`. |
|
memoize.Cache = MapCache; |
|
|
|
/** |
|
* Recursively merges own and inherited enumerable properties of source |
|
* objects into the destination object, skipping source properties that resolve |
|
* to `undefined`. Array and plain object properties are merged recursively. |
|
* Other objects and value types are overriden by assignment. Source objects |
|
* are applied from left to right. Subsequent sources overwrite property |
|
* assignments of previous sources. |
|
* |
|
* **Note:** This method mutates `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The destination object. |
|
* @param {...Object} [sources] The source objects. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* var users = { |
|
* 'data': [{ 'user': 'barney' }, { 'user': 'fred' }] |
|
* }; |
|
* |
|
* var ages = { |
|
* 'data': [{ 'age': 36 }, { 'age': 40 }] |
|
* }; |
|
* |
|
* _.merge(users, ages); |
|
* // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] } |
|
*/ |
|
var merge = createAssigner(function(object, source) { |
|
baseMerge(object, source); |
|
}); |
|
|
|
/** |
|
* Creates a function that invokes the method at `path` of a given object. |
|
* Any additional arguments are provided to the invoked method. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Array|string} path The path of the method to invoke. |
|
* @param {...*} [args] The arguments to invoke the method with. |
|
* @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 = rest(function(path, args) { |
|
return function(object) { |
|
return invokePath(object, path, args); |
|
}; |
|
}); |
|
|
|
/** |
|
* The opposite of `_.method`; this method creates a function that invokes |
|
* the method at a given path of `object`. Any additional arguments are |
|
* provided to the invoked method. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Object} object The object to query. |
|
* @param {...*} [args] The arguments to invoke the method with. |
|
* @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 = rest(function(object, args) { |
|
return function(path) { |
|
return invokePath(object, path, args); |
|
}; |
|
}); |
|
|
|
/** |
|
* Gets the minimum value of `array`. If `array` is empty or falsey |
|
* `undefined` is returned. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {Array} array The array to iterate over. |
|
* @returns {*} Returns the minimum value. |
|
* @example |
|
* |
|
* _.min([4, 2, 8, 6]); |
|
* // => 2 |
|
* |
|
* _.min([]); |
|
* // => undefined |
|
*/ |
|
function min(array) { |
|
return (array && array.length) |
|
? baseExtremum(array, identity, lt) |
|
: undefined; |
|
} |
|
|
|
/** |
|
* This method is like `_.min` except that it accepts `iteratee` which is |
|
* invoked for each element in `array` to generate the criterion by which |
|
* the value is ranked. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {*} Returns the minimum value. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 40 } |
|
* ]; |
|
* |
|
* _.minBy(users, function(o) { return o.age; }); |
|
* // => { 'user': 'barney', 'age': 36 } |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.minBy(users, 'age'); |
|
* // => { 'user': 'barney', 'age': 36 } |
|
*/ |
|
function minBy(array, iteratee) { |
|
return (array && array.length) |
|
? baseExtremum(array, baseIteratee(iteratee), lt) |
|
: undefined; |
|
} |
|
|
|
/** |
|
* 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 to |
|
* avoid conflicts caused by modifying the original. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @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`. |
|
* @example |
|
* |
|
* function vowels(string) { |
|
* return _.filter(string, function(v) { |
|
* return /[aeiou]/i.test(v); |
|
* }); |
|
* } |
|
* |
|
* _.mixin({ 'vowels': vowels }); |
|
* _.vowels('fred'); |
|
* // => ['e'] |
|
* |
|
* _('fred').vowels().value(); |
|
* // => ['e'] |
|
* |
|
* _.mixin({ 'vowels': vowels }, { 'chain': false }); |
|
* _('fred').vowels(); |
|
* // => ['e'] |
|
*/ |
|
function mixin(object, source, options) { |
|
var props = keys(source), |
|
methodNames = baseFunctions(source, props); |
|
|
|
var chain = (isObject(options) && 'chain' in options) ? options.chain : true, |
|
isFunc = isFunction(object); |
|
|
|
arrayEach(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.push({ 'func': func, 'args': arguments, 'thisArg': object }); |
|
result.__chain__ = chainAll; |
|
return result; |
|
} |
|
return func.apply(object, arrayPush([this.value()], arguments)); |
|
}; |
|
} |
|
}); |
|
|
|
return object; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMin$5 = Math.min; |
|
|
|
/** |
|
* Creates a function like `_.modArgs`. |
|
* |
|
* @private |
|
* @param {Function} resolver The function to resolve which invocation |
|
* arguments are provided to each transform. |
|
* @returns {Function} Returns the new arguments modifier function. |
|
*/ |
|
function createModArgs(resolver) { |
|
return rest(function(func, transforms) { |
|
transforms = arrayMap(baseFlatten(transforms), baseIteratee); |
|
|
|
var funcsLength = transforms.length; |
|
return rest(function(args) { |
|
var index = -1, |
|
length = nativeMin$5(args.length, funcsLength), |
|
modded = copyArray(args); |
|
|
|
while (++index < length) { |
|
modded[index] = transforms[index].apply(this, resolver(args[index], index, args)); |
|
} |
|
return func.apply(this, modded); |
|
}); |
|
}); |
|
} |
|
|
|
/** |
|
* Creates a function that invokes `func` with arguments modified by |
|
* corresponding `transforms`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to wrap. |
|
* @param {...(Function|Function[])} [transforms] The functions to transform |
|
* arguments, specified individually or in arrays. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* function doubled(n) { |
|
* return n * 2; |
|
* } |
|
* |
|
* function square(n) { |
|
* return n * n; |
|
* } |
|
* |
|
* var modded = _.modArgs(function(x, y) { |
|
* return [x, y]; |
|
* }, square, doubled); |
|
* |
|
* modded(9, 3); |
|
* // => [81, 6] |
|
* |
|
* modded(10, 5); |
|
* // => [100, 10] |
|
*/ |
|
var modArgs = createModArgs(function(value) { |
|
return [value]; |
|
}); |
|
|
|
/** |
|
* This method is like `_.modArgs` except that each of the `transforms` is |
|
* provided the complete set of arguments the created function is invoked with. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to wrap. |
|
* @param {...(Function|Function[])} [transforms] The functions to transform |
|
* arguments, specified individually or in arrays. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* function divide(x, y) { |
|
* return x / y; |
|
* } |
|
* |
|
* function multiply(x, y) { |
|
* return x * y; |
|
* } |
|
* |
|
* var modded = _.modArgsSet(function(x, y) { |
|
* return [x, y]; |
|
* }, multiply, divide); |
|
* |
|
* modded(9, 3); |
|
* // => [27, 3] |
|
* |
|
* modded(10, 5); |
|
* // => [50, 2] |
|
*/ |
|
var modArgsSet = createModArgs(function(value, index, args) { |
|
return args; |
|
}); |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$4 = 'Expected a function'; |
|
|
|
/** |
|
* Creates a function that negates the result of the predicate `func`. The |
|
* `func` predicate is invoked with the `this` binding and arguments of the |
|
* created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} predicate The predicate to negate. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* function isEven(n) { |
|
* return n % 2 == 0; |
|
* } |
|
* |
|
* _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); |
|
* // => [1, 3, 5] |
|
*/ |
|
function negate(predicate) { |
|
if (typeof predicate != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$4); |
|
} |
|
return function() { |
|
return !predicate.apply(this, arguments); |
|
}; |
|
} |
|
|
|
var mapTag$1 = '[object Map]'; |
|
var setTag$1 = '[object Set]'; |
|
var Symbol = root.Symbol; |
|
var iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined; |
|
/** |
|
* Converts `value` to an array. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to convert. |
|
* @returns {Array} Returns the converted array. |
|
* @example |
|
* |
|
* (function() { |
|
* return _.toArray(arguments).slice(1); |
|
* }(1, 2, 3)); |
|
* // => [2, 3] |
|
*/ |
|
function toArray(value) { |
|
if (!value) { |
|
return []; |
|
} |
|
if (isArrayLike(value)) { |
|
return isString(value) ? stringToArray(value) : copyArray(value); |
|
} |
|
if (iteratorSymbol && value[iteratorSymbol]) { |
|
return iteratorToArray(value[iteratorSymbol]()); |
|
} |
|
var tag = getTag$1(value), |
|
func = tag == mapTag$1 ? mapToArray : (tag == setTag$1 ? setToArray : values); |
|
|
|
return func(value); |
|
} |
|
|
|
/** |
|
* Gets the next value on a wrapped object following the |
|
* [iterator protocol](https://mdn.io/iteration_protocols#iterator). |
|
* |
|
* @name next |
|
* @memberOf _ |
|
* @category Chain |
|
* @returns {Object} Returns the next iterator value. |
|
* @example |
|
* |
|
* var wrapped = _([1, 2]); |
|
* |
|
* wrapped.next(); |
|
* // => { 'done': false, 'value': 1 } |
|
* |
|
* wrapped.next(); |
|
* // => { 'done': false, 'value': 2 } |
|
* |
|
* wrapped.next(); |
|
* // => { 'done': true, 'value': undefined } |
|
*/ |
|
function wrapperNext() { |
|
if (this.__values__ === undefined) { |
|
this.__values__ = toArray(this.value()); |
|
} |
|
var done = this.__index__ >= this.__values__.length, |
|
value = done ? undefined : this.__values__[this.__index__++]; |
|
|
|
return { 'done': done, 'value': value }; |
|
} |
|
|
|
/** |
|
* Creates a function that returns its nth argument. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {number} [n=0] The index of the argument to return. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var func = _.nthArg(1); |
|
* |
|
* func('a', 'b', 'c'); |
|
* // => 'b' |
|
*/ |
|
function nthArg(n) { |
|
n = toInteger(n); |
|
return function() { |
|
return arguments[n]; |
|
}; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.pick` without support for individual |
|
* property names. |
|
* |
|
* @private |
|
* @param {Object} object The source object. |
|
* @param {string[]} props The property names to pick. |
|
* @returns {Object} Returns the new object. |
|
*/ |
|
function basePick(object, props) { |
|
object = Object(object); |
|
return arrayReduce(props, function(result, key) { |
|
if (key in object) { |
|
result[key] = object[key]; |
|
} |
|
return result; |
|
}, {}); |
|
} |
|
|
|
/** |
|
* The opposite of `_.pick`; this method creates an object composed of the |
|
* own and inherited enumerable properties of `object` that are not omitted. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The source object. |
|
* @param {...(string|string[])} [props] The property names to omit, specified |
|
* individually or in arrays.. |
|
* @returns {Object} Returns the new object. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred', 'age': 40 }; |
|
* |
|
* _.omit(object, 'user'); |
|
* // => { 'age': 40 } |
|
*/ |
|
var omit = rest(function(object, props) { |
|
if (object == null) { |
|
return {}; |
|
} |
|
props = arrayMap(baseFlatten(props), String); |
|
return basePick(object, baseDifference(keysIn(object), props)); |
|
}); |
|
|
|
/** |
|
* The base implementation of `_.forIn` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Object} object The object to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function baseForIn(object, iteratee) { |
|
return object == null ? object : baseFor(object, iteratee, keysIn); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.pickBy` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Object} object The source object. |
|
* @param {Function} predicate The function invoked per property. |
|
* @returns {Object} Returns the new object. |
|
*/ |
|
function basePickBy(object, predicate) { |
|
var result = {}; |
|
baseForIn(object, function(value, key) { |
|
if (predicate(value)) { |
|
result[key] = value; |
|
} |
|
}); |
|
return result; |
|
} |
|
|
|
/** |
|
* The opposite of `_.pickBy`; this method creates an object composed of the |
|
* own and inherited enumerable properties of `object` that `predicate` |
|
* doesn't return truthy for. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The source object. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per property. |
|
* @returns {Object} Returns the new object. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred', 'age': 40 }; |
|
* |
|
* _.omitBy(object, _.isNumber); |
|
* // => { 'user': 'fred' } |
|
*/ |
|
function omitBy(object, predicate) { |
|
predicate = baseIteratee(predicate); |
|
return basePickBy(object, function(value) { |
|
return !predicate(value); |
|
}); |
|
} |
|
|
|
/** |
|
* Creates a function that is restricted to invoking `func` once. Repeat calls |
|
* to the function return the value of the first call. The `func` is invoked |
|
* with the `this` binding and arguments of the created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to restrict. |
|
* @returns {Function} Returns the new restricted function. |
|
* @example |
|
* |
|
* var initialize = _.once(createApplication); |
|
* initialize(); |
|
* initialize(); |
|
* // `initialize` invokes `createApplication` once |
|
*/ |
|
function once(func) { |
|
return before(2, func); |
|
} |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var MAX_SAFE_INTEGER$1 = 9007199254740991; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeFloor$1 = Math.floor; |
|
|
|
/** |
|
* Repeats the given string `n` times. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to repeat. |
|
* @param {number} [n=0] The number of times to repeat the string. |
|
* @returns {string} Returns the repeated string. |
|
* @example |
|
* |
|
* _.repeat('*', 3); |
|
* // => '***' |
|
* |
|
* _.repeat('abc', 2); |
|
* // => 'abcabc' |
|
* |
|
* _.repeat('abc', 0); |
|
* // => '' |
|
*/ |
|
function repeat(string, n) { |
|
string = toString(string); |
|
n = toInteger(n); |
|
|
|
var result = ''; |
|
if (!string || n < 1 || n > MAX_SAFE_INTEGER$1) { |
|
return result; |
|
} |
|
// Leverage the exponentiation by squaring algorithm for a faster repeat. |
|
// See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. |
|
do { |
|
if (n % 2) { |
|
result += string; |
|
} |
|
n = nativeFloor$1(n / 2); |
|
string += string; |
|
} while (n); |
|
|
|
return result; |
|
} |
|
|
|
var rsAstralRange$3 = '\\ud800-\\udfff'; |
|
var rsComboRange$3 = '\\u0300-\\u036f\\ufe20-\\ufe23'; |
|
var rsVarRange$3 = '\\ufe0e\\ufe0f'; |
|
/** Used to compose unicode capture groups. */ |
|
var rsZWJ$3 = '\\u200d'; |
|
|
|
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ |
|
var reHasComplexSymbol$2 = RegExp('[' + rsZWJ$3 + rsAstralRange$3 + rsComboRange$3 + rsVarRange$3 + ']'); |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeCeil$3 = Math.ceil; |
|
|
|
/** |
|
* Creates the padding for `string` based on the given `length`. The `chars` |
|
* string is truncated if the number of characters exceeds `length`. |
|
* |
|
* @private |
|
* @param {string} string The string to create padding for. |
|
* @param {number} [length=0] The padding length. |
|
* @param {string} [chars=' '] The string used as padding. |
|
* @returns {string} Returns the padding for `string`. |
|
*/ |
|
function createPadding(string, length, chars) { |
|
length = toInteger(length); |
|
|
|
var strLength = stringSize(string); |
|
if (!length || strLength >= length) { |
|
return ''; |
|
} |
|
var padLength = length - strLength; |
|
chars = chars === undefined ? ' ' : (chars + ''); |
|
|
|
var result = repeat(chars, nativeCeil$3(padLength / stringSize(chars))); |
|
return reHasComplexSymbol$2.test(chars) |
|
? stringToArray(result).slice(0, padLength).join('') |
|
: result.slice(0, padLength); |
|
} |
|
|
|
var nativeCeil$1 = Math.ceil; |
|
var nativeFloor = Math.floor; |
|
/** |
|
* Pads `string` on the left and right sides if it's shorter than `length`. |
|
* Padding characters are truncated if they can't be evenly divided by `length`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to pad. |
|
* @param {number} [length=0] The padding length. |
|
* @param {string} [chars=' '] The string used as padding. |
|
* @returns {string} Returns the padded string. |
|
* @example |
|
* |
|
* _.pad('abc', 8); |
|
* // => ' abc ' |
|
* |
|
* _.pad('abc', 8, '_-'); |
|
* // => '_-abc_-_' |
|
* |
|
* _.pad('abc', 3); |
|
* // => 'abc' |
|
*/ |
|
function pad(string, length, chars) { |
|
string = toString(string); |
|
length = toInteger(length); |
|
|
|
var strLength = stringSize(string); |
|
if (!length || strLength >= length) { |
|
return string; |
|
} |
|
var mid = (length - strLength) / 2, |
|
leftLength = nativeFloor(mid), |
|
rightLength = nativeCeil$1(mid); |
|
|
|
return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars); |
|
} |
|
|
|
/** |
|
* Pads `string` on the left side if it's shorter than `length`. Padding |
|
* characters are truncated if they exceed `length`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to pad. |
|
* @param {number} [length=0] The padding length. |
|
* @param {string} [chars=' '] The string used as padding. |
|
* @returns {string} Returns the padded string. |
|
* @example |
|
* |
|
* _.padLeft('abc', 6); |
|
* // => ' abc' |
|
* |
|
* _.padLeft('abc', 6, '_-'); |
|
* // => '_-_abc' |
|
* |
|
* _.padLeft('abc', 3); |
|
* // => 'abc' |
|
*/ |
|
function padLeft(string, length, chars) { |
|
string = toString(string); |
|
return createPadding(string, length, chars) + string; |
|
} |
|
|
|
/** |
|
* Pads `string` on the right side if it's shorter than `length`. Padding |
|
* characters are truncated if they exceed `length`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to pad. |
|
* @param {number} [length=0] The padding length. |
|
* @param {string} [chars=' '] The string used as padding. |
|
* @returns {string} Returns the padded string. |
|
* @example |
|
* |
|
* _.padRight('abc', 6); |
|
* // => 'abc ' |
|
* |
|
* _.padRight('abc', 6, '_-'); |
|
* // => 'abc_-_' |
|
* |
|
* _.padRight('abc', 3); |
|
* // => 'abc' |
|
*/ |
|
function padRight(string, length, chars) { |
|
string = toString(string); |
|
return string + createPadding(string, length, chars); |
|
} |
|
|
|
/** |
|
* Used by `_.trim` and `_.trimLeft` to get the index of the first string symbol |
|
* that is not found in the character symbols. |
|
* |
|
* @private |
|
* @param {Array} strSymbols The string symbols to inspect. |
|
* @param {Array} chrSymbols The character symbols to find. |
|
* @returns {number} Returns the index of the first unmatched string symbol. |
|
*/ |
|
function charsLeftIndex(strSymbols, chrSymbols) { |
|
var index = -1, |
|
length = strSymbols.length; |
|
|
|
while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} |
|
return index; |
|
} |
|
|
|
/** |
|
* Used by `_.trim` and `_.trimRight` to get the index of the last string symbol |
|
* that is not found in the character symbols. |
|
* |
|
* @private |
|
* @param {Array} strSymbols The string symbols to inspect. |
|
* @param {Array} chrSymbols The character symbols to find. |
|
* @returns {number} Returns the index of the last unmatched string symbol. |
|
*/ |
|
function charsRightIndex(strSymbols, chrSymbols) { |
|
var index = strSymbols.length; |
|
|
|
while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} |
|
return index; |
|
} |
|
|
|
/** |
|
* Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a |
|
* character code is whitespace. |
|
* |
|
* @private |
|
* @param {number} charCode The character code to inspect. |
|
* @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`. |
|
*/ |
|
function isSpace(charCode) { |
|
return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 || |
|
(charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279))); |
|
} |
|
|
|
/** |
|
* Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace |
|
* character of `string`. |
|
* |
|
* @private |
|
* @param {string} string The string to inspect. |
|
* @returns {number} Returns the index of the first non-whitespace character. |
|
*/ |
|
function trimmedLeftIndex(string) { |
|
var index = -1, |
|
length = string.length; |
|
|
|
while (++index < length && isSpace(string.charCodeAt(index))) {} |
|
return index; |
|
} |
|
|
|
/** |
|
* Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace |
|
* character of `string`. |
|
* |
|
* @private |
|
* @param {string} string The string to inspect. |
|
* @returns {number} Returns the index of the last non-whitespace character. |
|
*/ |
|
function trimmedRightIndex(string) { |
|
var index = string.length; |
|
|
|
while (index-- && isSpace(string.charCodeAt(index))) {} |
|
return index; |
|
} |
|
|
|
/** |
|
* Removes leading and trailing whitespace or specified characters from `string`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to trim. |
|
* @param {string} [chars=whitespace] The characters to trim. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {string} Returns the trimmed string. |
|
* @example |
|
* |
|
* _.trim(' abc '); |
|
* // => 'abc' |
|
* |
|
* _.trim('-_-abc-_-', '_-'); |
|
* // => 'abc' |
|
* |
|
* _.map([' foo ', ' bar '], _.trim); |
|
* // => ['foo', 'bar'] |
|
*/ |
|
function trim(string, chars, guard) { |
|
string = toString(string); |
|
if (!string) { |
|
return string; |
|
} |
|
if (guard || chars === undefined) { |
|
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1); |
|
} |
|
chars = (chars + ''); |
|
if (!chars) { |
|
return string; |
|
} |
|
var strSymbols = stringToArray(string), |
|
chrSymbols = stringToArray(chars); |
|
|
|
return strSymbols.slice(charsLeftIndex(strSymbols, chrSymbols), charsRightIndex(strSymbols, chrSymbols) + 1).join(''); |
|
} |
|
|
|
/** Used to detect hexadecimal string values. */ |
|
var reHasHexPrefix = /^0[xX]/; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeParseInt = root.parseInt; |
|
|
|
/** |
|
* Converts `string` to an integer of the specified radix. If `radix` is |
|
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal, |
|
* in which case a `radix` of `16` is used. |
|
* |
|
* **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E) |
|
* of `parseInt`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} string The string to convert. |
|
* @param {number} [radix] The radix to interpret `value` by. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {number} Returns the converted integer. |
|
* @example |
|
* |
|
* _.parseInt('08'); |
|
* // => 8 |
|
* |
|
* _.map(['6', '08', '10'], _.parseInt); |
|
* // => [6, 8, 10] |
|
*/ |
|
function parseInt(string, radix, guard) { |
|
// Chrome fails to trim leading <BOM> whitespace characters. |
|
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details. |
|
if (guard || radix == null) { |
|
radix = 0; |
|
} else if (radix) { |
|
radix = +radix; |
|
} |
|
string = trim(string); |
|
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10)); |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var PARTIAL_FLAG$2 = 32; |
|
|
|
/** |
|
* 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 doesn't set the "length" property of partially |
|
* applied functions. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to partially apply arguments to. |
|
* @param {...*} [partials] The arguments to be partially applied. |
|
* @returns {Function} Returns the new partially applied function. |
|
* @example |
|
* |
|
* var greet = function(greeting, name) { |
|
* return greeting + ' ' + name; |
|
* }; |
|
* |
|
* var sayHelloTo = _.partial(greet, 'hello'); |
|
* sayHelloTo('fred'); |
|
* // => 'hello fred' |
|
* |
|
* // using placeholders |
|
* var greetFred = _.partial(greet, _, 'fred'); |
|
* greetFred('hi'); |
|
* // => 'hi fred' |
|
*/ |
|
var partial = rest(function(func, partials) { |
|
var holders = replaceHolders(partials, partial.placeholder); |
|
return createWrapper(func, PARTIAL_FLAG$2, undefined, partials, holders); |
|
}); |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var PARTIAL_RIGHT_FLAG = 64; |
|
|
|
/** |
|
* This method is like `_.partial` except that partially applied arguments |
|
* 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 doesn't set the "length" property of partially |
|
* applied functions. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to partially apply arguments to. |
|
* @param {...*} [partials] The arguments to be partially applied. |
|
* @returns {Function} Returns the new partially applied function. |
|
* @example |
|
* |
|
* var greet = function(greeting, name) { |
|
* return greeting + ' ' + name; |
|
* }; |
|
* |
|
* var greetFred = _.partialRight(greet, 'fred'); |
|
* greetFred('hi'); |
|
* // => 'hi fred' |
|
* |
|
* // using placeholders |
|
* var sayHelloTo = _.partialRight(greet, 'hello', _); |
|
* sayHelloTo('fred'); |
|
* // => 'hello fred' |
|
*/ |
|
var partialRight = rest(function(func, partials) { |
|
var holders = replaceHolders(partials, partialRight.placeholder); |
|
return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders); |
|
}); |
|
|
|
/** |
|
* Creates an array of elements split into two groups, the first of which |
|
* contains elements `predicate` returns truthy for, while the second of which |
|
* contains elements `predicate` returns falsey for. The predicate is invoked |
|
* with three arguments: (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the array of grouped elements. |
|
* @example |
|
* |
|
* var resolve = function(result) { |
|
* return _.map(result, function(array) { return _.map(array, 'user'); }); |
|
* }; |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36, 'active': false }, |
|
* { 'user': 'fred', 'age': 40, 'active': true }, |
|
* { 'user': 'pebbles', 'age': 1, 'active': false } |
|
* ]; |
|
* |
|
* resolve( _.partition(users, function(o) { return o.active; }) ); |
|
* // => [['fred'], ['barney', 'pebbles']] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.partition(users, { 'age': 1, 'active': false }) ); |
|
* // => [['pebbles'], ['barney', 'fred']] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.partition(users, ['active', false]) ); |
|
* // => [['barney', 'pebbles'], ['fred']] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.partition(users, 'active') ); |
|
* // => [['fred'], ['barney', 'pebbles']] |
|
*/ |
|
var partition = createAggregator(function(result, value, key) { |
|
result[key ? 0 : 1].push(value); |
|
}, function() { return [[], []]; }); |
|
|
|
/** |
|
* Creates an object composed of the picked `object` properties. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The source object. |
|
* @param {...(string|string[])} [props] The property names to pick, specified |
|
* individually or in arrays. |
|
* @returns {Object} Returns the new object. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred', 'age': 40 }; |
|
* |
|
* _.pick(object, 'user'); |
|
* // => { 'user': 'fred' } |
|
*/ |
|
var pick = rest(function(object, props) { |
|
return object == null ? {} : basePick(object, baseFlatten(props)); |
|
}); |
|
|
|
/** |
|
* Creates an object composed of the `object` properties `predicate` returns |
|
* truthy for. The predicate is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The source object. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per property. |
|
* @returns {Object} Returns the new object. |
|
* @example |
|
* |
|
* var object = { 'user': 'fred', 'age': 40 }; |
|
* |
|
* _.pickBy(object, _.isNumber); |
|
* // => { 'age': 40 } |
|
*/ |
|
function pickBy(object, predicate) { |
|
return object == null ? {} : basePickBy(object, baseIteratee(predicate)); |
|
} |
|
|
|
/** |
|
* Creates a clone of the chained sequence planting `value` as the wrapped value. |
|
* |
|
* @name plant |
|
* @memberOf _ |
|
* @category Chain |
|
* @param {*} value The value to plant. |
|
* @returns {Object} Returns the new `lodash` wrapper instance. |
|
* @example |
|
* |
|
* function square(n) { |
|
* return n * n; |
|
* } |
|
* |
|
* var wrapped = _([1, 2]).map(square); |
|
* var other = wrapped.plant([3, 4]); |
|
* |
|
* other.value(); |
|
* // => [9, 16] |
|
* |
|
* wrapped.value(); |
|
* // => [1, 4] |
|
*/ |
|
function wrapperPlant(value) { |
|
var result, |
|
parent = this; |
|
|
|
while (parent instanceof baseLodash) { |
|
var clone = wrapperClone(parent); |
|
clone.__index__ = 0; |
|
clone.__values__ = undefined; |
|
if (result) { |
|
previous.__wrapped__ = clone; |
|
} else { |
|
result = clone; |
|
} |
|
var previous = clone; |
|
parent = parent.__wrapped__; |
|
} |
|
previous.__wrapped__ = value; |
|
return result; |
|
} |
|
|
|
/** |
|
* The opposite of `_.property`; this method creates a function that returns |
|
* the value at a given path of `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {Object} object The object to query. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var array = [0, 1, 2], |
|
* object = { 'a': array, 'b': array, 'c': array }; |
|
* |
|
* _.map(['a[2]', 'c[0]'], _.propertyOf(object)); |
|
* // => [2, 0] |
|
* |
|
* _.map([['a', '2'], ['c', '0']], _.propertyOf(object)); |
|
* // => [2, 0] |
|
*/ |
|
function propertyOf(object) { |
|
return function(path) { |
|
return object == null ? undefined : baseGet(object, path); |
|
}; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var arrayProto$2 = Array.prototype; |
|
|
|
/** Built-in value references. */ |
|
var splice = arrayProto$2.splice; |
|
|
|
/** |
|
* The base implementation of `_.pullAllBy` without support for callback |
|
* shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to modify. |
|
* @param {Array} values The values to remove. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function basePullAllBy(array, values, iteratee) { |
|
var index = -1, |
|
length = values.length, |
|
seen = array; |
|
|
|
if (iteratee) { |
|
seen = arrayMap(array, function(value) { return iteratee(value); }); |
|
} |
|
while (++index < length) { |
|
var fromIndex = 0, |
|
value = values[index], |
|
computed = iteratee ? iteratee(value) : value; |
|
|
|
while ((fromIndex = baseIndexOf(seen, computed, fromIndex)) > -1) { |
|
if (seen !== array) { |
|
splice.call(seen, fromIndex, 1); |
|
} |
|
splice.call(array, fromIndex, 1); |
|
} |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.pullAll`. |
|
* |
|
* @private |
|
* @param {Array} array The array to modify. |
|
* @param {Array} values The values to remove. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function basePullAll(array, values) { |
|
return basePullAllBy(array, values); |
|
} |
|
|
|
/** |
|
* This method is like `_.pull` except that it accepts an array of values to remove. |
|
* |
|
* **Note:** Unlike `_.difference`, this method mutates `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to modify. |
|
* @param {Array} values The values to remove. |
|
* @returns {Array} Returns `array`. |
|
* @example |
|
* |
|
* var array = [1, 2, 3, 1, 2, 3]; |
|
* |
|
* _.pull(array, [2, 3]); |
|
* console.log(array); |
|
* // => [1, 1] |
|
*/ |
|
function pullAll(array, values) { |
|
return (array && array.length && values && values.length) |
|
? basePullAll(array, values) |
|
: array; |
|
} |
|
|
|
/** |
|
* Removes all provided values from `array` using |
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. |
|
* |
|
* **Note:** Unlike `_.without`, this method mutates `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to modify. |
|
* @param {...*} [values] The values to remove. |
|
* @returns {Array} Returns `array`. |
|
* @example |
|
* |
|
* var array = [1, 2, 3, 1, 2, 3]; |
|
* |
|
* _.pull(array, 2, 3); |
|
* console.log(array); |
|
* // => [1, 1] |
|
*/ |
|
var pull = rest(pullAll); |
|
|
|
/** |
|
* This method is like `_.pullAll` except that it accepts `iteratee` which is |
|
* invoked for each element of `array` and `values` to to generate the criterion |
|
* by which uniqueness is computed. The iteratee is invoked with one argument: (value). |
|
* |
|
* **Note:** Unlike `_.differenceBy`, this method mutates `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to modify. |
|
* @param {Array} values The values to remove. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Array} Returns `array`. |
|
* @example |
|
* |
|
* var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; |
|
* |
|
* _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(o) { return o.x; }); |
|
* console.log(array); |
|
* // => [{ 'x': 2 }] |
|
*/ |
|
function pullAllBy(array, values, iteratee) { |
|
return (array && array.length && values && values.length) |
|
? basePullAllBy(array, values, baseIteratee(iteratee)) |
|
: array; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var arrayProto$3 = Array.prototype; |
|
|
|
/** Built-in value references. */ |
|
var splice$1 = arrayProto$3.splice; |
|
|
|
/** |
|
* The base implementation of `_.pullAt` without support for individual |
|
* index arguments or 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 = array ? indexes.length : 0, |
|
lastIndex = length - 1; |
|
|
|
while (length--) { |
|
var index = indexes[length]; |
|
if (lastIndex == length || index != previous) { |
|
var previous = index; |
|
if (isIndex(index)) { |
|
splice$1.call(array, index, 1); |
|
} |
|
else if (!isKey(index, array)) { |
|
var path = baseToPath(index), |
|
object = parent$1(array, path); |
|
|
|
if (object != null) { |
|
delete object[last(path)]; |
|
} |
|
} |
|
else { |
|
delete array[index]; |
|
} |
|
} |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* Compares values to sort them in ascending order. |
|
* |
|
* @private |
|
* @param {*} value The value to compare. |
|
* @param {*} other The other value to compare. |
|
* @returns {number} Returns the sort order indicator for `value`. |
|
*/ |
|
function compareAscending(value, other) { |
|
if (value !== other) { |
|
var valIsNull = value === null, |
|
valIsUndef = value === undefined, |
|
valIsReflexive = value === value; |
|
|
|
var othIsNull = other === null, |
|
othIsUndef = other === undefined, |
|
othIsReflexive = other === other; |
|
|
|
if ((value > other && !othIsNull) || !valIsReflexive || |
|
(valIsNull && !othIsUndef && othIsReflexive) || |
|
(valIsUndef && othIsReflexive)) { |
|
return 1; |
|
} |
|
if ((value < other && !valIsNull) || !othIsReflexive || |
|
(othIsNull && !valIsUndef && valIsReflexive) || |
|
(othIsUndef && valIsReflexive)) { |
|
return -1; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
/** |
|
* Removes elements from `array` corresponding to `indexes` and returns an |
|
* array of removed elements. |
|
* |
|
* **Note:** Unlike `_.at`, this method mutates `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to modify. |
|
* @param {...(number|number[])} [indexes] The indexes of elements to remove, |
|
* specified individually or in arrays. |
|
* @returns {Array} Returns the new array of removed elements. |
|
* @example |
|
* |
|
* var array = [5, 10, 15, 20]; |
|
* var evens = _.pullAt(array, 1, 3); |
|
* |
|
* console.log(array); |
|
* // => [5, 15] |
|
* |
|
* console.log(evens); |
|
* // => [10, 20] |
|
*/ |
|
var pullAt = rest(function(array, indexes) { |
|
indexes = arrayMap(baseFlatten(indexes), String); |
|
|
|
var result = baseAt(array, indexes); |
|
basePullAt(array, indexes.sort(compareAscending)); |
|
return result; |
|
}); |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeFloor$2 = Math.floor; |
|
var nativeRandom$1 = Math.random; |
|
/** |
|
* The base implementation of `_.random` without support for returning |
|
* floating-point numbers. |
|
* |
|
* @private |
|
* @param {number} min The minimum possible value. |
|
* @param {number} max The maximum possible value. |
|
* @returns {number} Returns the random number. |
|
*/ |
|
function baseRandom(min, max) { |
|
return min + nativeFloor$2(nativeRandom$1() * (max - min + 1)); |
|
} |
|
|
|
var nativeMin$2 = Math.min; |
|
var nativeRandom = Math.random; |
|
/** |
|
* 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. |
|
* If `floating` is `true`, or either `min` or `max` are floats, a |
|
* floating-point number is returned instead of an integer. |
|
* |
|
* **Note:** JavaScript follows the IEEE-754 standard for resolving |
|
* floating-point values which can produce unexpected results. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Number |
|
* @param {number} [min=0] The minimum possible value. |
|
* @param {number} [max=1] The maximum possible value. |
|
* @param {boolean} [floating] Specify returning a floating-point number. |
|
* @returns {number} Returns the random number. |
|
* @example |
|
* |
|
* _.random(0, 5); |
|
* // => an integer between 0 and 5 |
|
* |
|
* _.random(5); |
|
* // => also an integer between 0 and 5 |
|
* |
|
* _.random(5, true); |
|
* // => a floating-point number between 0 and 5 |
|
* |
|
* _.random(1.2, 5.2); |
|
* // => a floating-point number between 1.2 and 5.2 |
|
*/ |
|
function random(min, max, floating) { |
|
if (floating && isIterateeCall(min, max, floating)) { |
|
max = floating = undefined; |
|
} |
|
var noMin = min === undefined, |
|
noMax = max === undefined; |
|
|
|
if (floating === undefined) { |
|
if (noMax && typeof min == 'boolean') { |
|
floating = min; |
|
min = 1; |
|
} |
|
else if (typeof max == 'boolean') { |
|
floating = max; |
|
noMax = true; |
|
} |
|
} |
|
if (noMin && noMax) { |
|
max = 1; |
|
noMax = false; |
|
} |
|
min = +min || 0; |
|
if (noMax) { |
|
max = min; |
|
min = 0; |
|
} else { |
|
max = +max || 0; |
|
} |
|
if (floating || min % 1 || max % 1) { |
|
var rand = nativeRandom(); |
|
return nativeMin$2(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max); |
|
} |
|
return baseRandom(min, max); |
|
} |
|
|
|
var nativeCeil$2 = Math.ceil; |
|
var nativeMax$6 = Math.max; |
|
/** |
|
* Creates an array of numbers (positive and/or negative) progressing from |
|
* `start` up to, but not including, `end`. If `end` is not specified it's |
|
* 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. |
|
* |
|
* **Note:** JavaScript follows the IEEE-754 standard for resolving |
|
* floating-point values which can produce unexpected results. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {number} [start=0] The start of the range. |
|
* @param {number} end The end of the range. |
|
* @param {number} [step=1] The value to increment or decrement by. |
|
* @returns {Array} Returns the new array of numbers. |
|
* @example |
|
* |
|
* _.range(4); |
|
* // => [0, 1, 2, 3] |
|
* |
|
* _.range(1, 5); |
|
* // => [1, 2, 3, 4] |
|
* |
|
* _.range(0, 20, 5); |
|
* // => [0, 5, 10, 15] |
|
* |
|
* _.range(0, -4, -1); |
|
* // => [0, -1, -2, -3] |
|
* |
|
* _.range(1, 4, 0); |
|
* // => [1, 1, 1] |
|
* |
|
* _.range(0); |
|
* // => [] |
|
*/ |
|
function range(start, end, step) { |
|
if (step && isIterateeCall(start, end, step)) { |
|
end = step = undefined; |
|
} |
|
start = +start; |
|
start = start === start ? start : 0; |
|
step = step === undefined ? 1 : (+step || 0); |
|
|
|
if (end === undefined) { |
|
end = start; |
|
start = 0; |
|
} else { |
|
end = +end || 0; |
|
} |
|
var n = nativeMax$6(nativeCeil$2((end - start) / (step || 1)), 0); |
|
return baseTimes(n, function(index) { |
|
return index ? (start += step) : start; |
|
}); |
|
} |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var REARG_FLAG = 256; |
|
|
|
/** |
|
* Creates a function that invokes `func` with arguments arranged according |
|
* to the specified indexes where the argument value at the first index is |
|
* provided as the first argument, the argument value at the second index is |
|
* provided as the second argument, and so on. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to rearrange arguments for. |
|
* @param {...(number|number[])} indexes The arranged argument indexes, |
|
* specified individually or in arrays. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var rearged = _.rearg(function(a, b, c) { |
|
* return [a, b, c]; |
|
* }, 2, 0, 1); |
|
* |
|
* rearged('b', 'c', 'a') |
|
* // => ['a', 'b', 'c'] |
|
*/ |
|
var rearg = rest(function(func, indexes) { |
|
return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes)); |
|
}); |
|
|
|
/** |
|
* The base implementation of `_.reduce` and `_.reduceRight` without support |
|
* for callback shorthands, which iterates over `collection` using the provided |
|
* `eachFunc`. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @param {*} accumulator The initial value. |
|
* @param {boolean} initFromCollection Specify using the first or last element of `collection` as the initial value. |
|
* @param {Function} eachFunc The function to iterate over `collection`. |
|
* @returns {*} Returns the accumulated value. |
|
*/ |
|
function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) { |
|
eachFunc(collection, function(value, index, collection) { |
|
accumulator = initFromCollection |
|
? (initFromCollection = false, value) |
|
: iteratee(accumulator, value, index, collection); |
|
}); |
|
return accumulator; |
|
} |
|
|
|
/** |
|
* Reduces `collection` to a value which is the accumulated result of running |
|
* each element in `collection` through `iteratee`, where each successive |
|
* invocation is supplied the return value of the previous. If `accumulator` |
|
* is not provided the first element of `collection` is used as the initial |
|
* value. The iteratee is invoked with four arguments: |
|
* (accumulator, value, index|key, collection). |
|
* |
|
* Many lodash methods are guarded to work as iteratees for methods like |
|
* `_.reduce`, `_.reduceRight`, and `_.transform`. |
|
* |
|
* The guarded methods are: |
|
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortBy`, |
|
* and `sortByOrder` |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @param {*} [accumulator] The initial value. |
|
* @returns {*} Returns the accumulated value. |
|
* @example |
|
* |
|
* _.reduce([1, 2], function(sum, n) { |
|
* return sum + n; |
|
* }); |
|
* // => 3 |
|
* |
|
* _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { |
|
* (result[value] || (result[value] = [])).push(key); |
|
* return result; |
|
* }, {}); |
|
* // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) |
|
*/ |
|
function reduce(collection, iteratee, accumulator) { |
|
var initFromCollection = arguments.length < 3; |
|
return (typeof iteratee == 'function' && isArray(collection)) |
|
? arrayReduce(collection, iteratee, accumulator, initFromCollection) |
|
: baseReduce(collection, baseIteratee(iteratee, 4), accumulator, initFromCollection, baseEach); |
|
} |
|
|
|
/** |
|
* A specialized version of `_.reduceRight` for arrays without support for |
|
* callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @param {*} [accumulator] The initial value. |
|
* @param {boolean} [initFromArray] Specify using the last element of `array` as the initial value. |
|
* @returns {*} Returns the accumulated value. |
|
*/ |
|
function arrayReduceRight(array, iteratee, accumulator, initFromArray) { |
|
var length = array.length; |
|
if (initFromArray && length) { |
|
accumulator = array[--length]; |
|
} |
|
while (length--) { |
|
accumulator = iteratee(accumulator, array[length], length, array); |
|
} |
|
return accumulator; |
|
} |
|
|
|
/** |
|
* This method is like `_.reduce` except that it iterates over elements of |
|
* `collection` from right to left. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @param {*} [accumulator] The initial value. |
|
* @returns {*} Returns the accumulated value. |
|
* @example |
|
* |
|
* var array = [[0, 1], [2, 3], [4, 5]]; |
|
* |
|
* _.reduceRight(array, function(flattened, other) { |
|
* return flattened.concat(other); |
|
* }, []); |
|
* // => [4, 5, 2, 3, 0, 1] |
|
*/ |
|
function reduceRight(collection, iteratee, accumulator) { |
|
var initFromCollection = arguments.length < 3; |
|
return (typeof iteratee == 'function' && isArray(collection)) |
|
? arrayReduceRight(collection, iteratee, accumulator, initFromCollection) |
|
: baseReduce(collection, baseIteratee(iteratee, 4), accumulator, initFromCollection, baseEachRight); |
|
} |
|
|
|
/** |
|
* The opposite of `_.filter`; this method returns the elements of `collection` |
|
* that `predicate` does **not** return truthy for. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the new filtered array. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36, 'active': false }, |
|
* { 'user': 'fred', 'age': 40, 'active': true } |
|
* ]; |
|
* |
|
* resolve( _.reject(users, function(o) { return !o.active; }) ); |
|
* // => ['fred'] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.reject(users, { 'age': 40, 'active': true }) ); |
|
* // => ['barney'] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.reject(users, ['active', false]) ); |
|
* // => ['fred'] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.reject(users, 'active') ); |
|
* // => ['barney'] |
|
*/ |
|
function reject(collection, predicate) { |
|
var func = isArray(collection) ? arrayFilter : baseFilter; |
|
predicate = baseIteratee(predicate, 3); |
|
return func(collection, function(value, index, collection) { |
|
return !predicate(value, index, collection); |
|
}); |
|
} |
|
|
|
/** |
|
* Removes all elements from `array` that `predicate` returns truthy for |
|
* and returns an array of the removed elements. The predicate is invoked with |
|
* three arguments: (value, index, array). |
|
* |
|
* **Note:** Unlike `_.filter`, this method mutates `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to modify. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the new array of removed elements. |
|
* @example |
|
* |
|
* var array = [1, 2, 3, 4]; |
|
* var evens = _.remove(array, function(n) { |
|
* return n % 2 == 0; |
|
* }); |
|
* |
|
* console.log(array); |
|
* // => [1, 3] |
|
* |
|
* console.log(evens); |
|
* // => [2, 4] |
|
*/ |
|
function remove(array, predicate) { |
|
var result = []; |
|
if (!(array && array.length)) { |
|
return result; |
|
} |
|
var index = -1, |
|
indexes = [], |
|
length = array.length; |
|
|
|
predicate = baseIteratee(predicate, 3); |
|
while (++index < length) { |
|
var value = array[index]; |
|
if (predicate(value, index, array)) { |
|
result.push(value); |
|
indexes.push(index); |
|
} |
|
} |
|
basePullAt(array, indexes); |
|
return result; |
|
} |
|
|
|
/** |
|
* This method is like `_.get` except that if the resolved value is a function |
|
* it's 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 {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 = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; |
|
* |
|
* _.result(object, 'a[0].b.c1'); |
|
* // => 3 |
|
* |
|
* _.result(object, 'a[0].b.c2'); |
|
* // => 4 |
|
* |
|
* _.result(object, 'a.b.c', 'default'); |
|
* // => 'default' |
|
* |
|
* _.result(object, 'a.b.c', _.constant('default')); |
|
* // => 'default' |
|
*/ |
|
function result$1(object, path, defaultValue) { |
|
if (!isKey(path, object)) { |
|
path = baseToPath(path); |
|
var result = get(object, path); |
|
object = parent$1(object, path); |
|
} else { |
|
result = object == null ? undefined : object[path]; |
|
} |
|
if (result === undefined) { |
|
result = defaultValue; |
|
} |
|
return isFunction(result) ? result.call(object) : result; |
|
} |
|
|
|
/** Used for built-in method references. */ |
|
var arrayProto = Array.prototype; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeReverse = arrayProto.reverse; |
|
|
|
/** |
|
* Reverses `array` so that the first element becomes the last, the second |
|
* element becomes the second to last, and so on. |
|
* |
|
* **Note:** This method mutates `array`. |
|
* |
|
* @memberOf _ |
|
* @category Array |
|
* @returns {Array} Returns `array`. |
|
* @example |
|
* |
|
* var array = [1, 2, 3]; |
|
* |
|
* _.reverse(array); |
|
* // => [3, 2, 1] |
|
* |
|
* console.log(array); |
|
* // => [3, 2, 1] |
|
*/ |
|
function reverse(array) { |
|
return array ? nativeReverse.call(array) : array; |
|
} |
|
|
|
/** |
|
* Calculates `number` rounded to `precision`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {number} number The number to round. |
|
* @param {number} [precision=0] The precision to round to. |
|
* @returns {number} Returns the rounded number. |
|
* @example |
|
* |
|
* _.round(4.006); |
|
* // => 4 |
|
* |
|
* _.round(4.006, 2); |
|
* // => 4.01 |
|
* |
|
* _.round(4060, -2); |
|
* // => 4100 |
|
*/ |
|
var round = createRound('round'); |
|
|
|
/** |
|
* Gets a random element from `collection`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to sample. |
|
* @returns {*} Returns the random element. |
|
* @example |
|
* |
|
* _.sample([1, 2, 3, 4]); |
|
* // => 2 |
|
*/ |
|
function sample(collection) { |
|
var array = isArrayLike(collection) ? collection : values(collection), |
|
length = array.length; |
|
|
|
return length > 0 ? array[baseRandom(0, length - 1)] : undefined; |
|
} |
|
|
|
/** |
|
* Gets `n` random elements from `collection`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to sample. |
|
* @param {number} [n=0] The number of elements to sample. |
|
* @returns {Array} Returns the random elements. |
|
* @example |
|
* |
|
* _.sampleSize([1, 2, 3, 4], 2); |
|
* // => [3, 1] |
|
*/ |
|
function sampleSize(collection, n) { |
|
var index = -1, |
|
result = toArray(collection), |
|
length = result.length, |
|
lastIndex = length - 1; |
|
|
|
n = clamp(toInteger(n), 0, length); |
|
while (++index < n) { |
|
var rand = baseRandom(index, lastIndex), |
|
value = result[rand]; |
|
|
|
result[rand] = result[index]; |
|
result[index] = value; |
|
} |
|
result.length = n; |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.set`. |
|
* |
|
* @private |
|
* @param {Object} object The object to query. |
|
* @param {Array|string} path The path of the property to set. |
|
* @param {*} value The value to set. |
|
* @param {Function} [customizer] The function to customize path creation. |
|
* @returns {Object} Returns `object`. |
|
*/ |
|
function baseSet(object, path, value, customizer) { |
|
path = isKey(path, object) ? [path + ''] : baseToPath(path); |
|
|
|
var index = -1, |
|
length = path.length, |
|
lastIndex = length - 1, |
|
nested = object; |
|
|
|
while (nested != null && ++index < length) { |
|
var key = path[index]; |
|
if (isObject(nested)) { |
|
var newValue = value; |
|
if (index != lastIndex) { |
|
var oldValue = nested[key]; |
|
newValue = customizer ? customizer(oldValue, key, nested) : undefined; |
|
if (newValue === undefined) { |
|
newValue = oldValue == null ? (isIndex(path[index + 1]) ? [] : {}) : oldValue; |
|
} |
|
} |
|
assignValue(nested, key, newValue); |
|
} |
|
nested = nested[key]; |
|
} |
|
return object; |
|
} |
|
|
|
/** |
|
* Sets the value at `path` of `object`. If a portion of `path` doesn't |
|
* exist it's created. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to modify. |
|
* @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) { |
|
return object == null ? object : baseSet(object, path, value); |
|
} |
|
|
|
/** |
|
* This method is like `_.set` except that it accepts `customizer` which is |
|
* invoked to produce the objects of `path`. If `customizer` returns `undefined` |
|
* path creation is handled by the method instead. The `customizer` is invoked |
|
* with three arguments: (nsValue, key, nsObject). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to modify. |
|
* @param {Array|string} path The path of the property to set. |
|
* @param {*} value The value to set. |
|
* @param {Function} [customizer] The function to customize assigned values. |
|
* @returns {Object} Returns `object`. |
|
* @example |
|
* |
|
* function customizer(nsValue) { |
|
* if (!_.isObject(nsValue)) { |
|
* return {}; |
|
* } |
|
* } |
|
* |
|
* _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, customizer); |
|
* // => { '0': { '1': { '2': 3 }, 'length': 2 } } |
|
*/ |
|
function setWith(object, path, value, customizer) { |
|
customizer = typeof customizer == 'function' ? customizer : undefined; |
|
return object == null ? object : baseSet(object, path, value, customizer); |
|
} |
|
|
|
/** Used as references for the maximum length and index of an array. */ |
|
var MAX_ARRAY_LENGTH = 4294967295; |
|
|
|
/** |
|
* Creates an array of shuffled values, using a version of the |
|
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to shuffle. |
|
* @returns {Array} Returns the new shuffled array. |
|
* @example |
|
* |
|
* _.shuffle([1, 2, 3, 4]); |
|
* // => [4, 1, 3, 2] |
|
*/ |
|
function shuffle(collection) { |
|
return sampleSize(collection, MAX_ARRAY_LENGTH); |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` from `start` up to, but not including, `end`. |
|
* |
|
* **Note:** This method is used instead of `Array#slice` to ensure dense |
|
* arrays are returned. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to slice. |
|
* @param {number} [start=0] The start position. |
|
* @param {number} [end=array.length] The end position. |
|
* @returns {Array} Returns the slice of `array`. |
|
*/ |
|
function slice(array, start, end) { |
|
var length = array ? array.length : 0; |
|
if (!length) { |
|
return []; |
|
} |
|
if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { |
|
start = 0; |
|
end = length; |
|
} |
|
return baseSlice(array, start, end); |
|
} |
|
|
|
/** |
|
* Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the snake cased string. |
|
* @example |
|
* |
|
* _.snakeCase('Foo Bar'); |
|
* // => 'foo_bar' |
|
* |
|
* _.snakeCase('fooBar'); |
|
* // => 'foo_bar' |
|
* |
|
* _.snakeCase('--foo-bar'); |
|
* // => 'foo_bar' |
|
*/ |
|
var snakeCase = createCompounder(function(result, word, index) { |
|
return result + (index ? '_' : '') + word.toLowerCase(); |
|
}); |
|
|
|
/** |
|
* The base implementation of `_.some` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function} predicate The function invoked per iteration. |
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. |
|
*/ |
|
function baseSome(collection, predicate) { |
|
var result; |
|
|
|
baseEach(collection, function(value, index, collection) { |
|
result = predicate(value, index, collection); |
|
return !result; |
|
}); |
|
return !!result; |
|
} |
|
|
|
/** |
|
* Checks if `predicate` returns truthy for **any** element of `collection`. |
|
* Iteration is stopped once `predicate` returns truthy. The predicate is |
|
* invoked with three arguments: (value, index|key, collection). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`. |
|
* @example |
|
* |
|
* _.some([null, 0, 'yes', false], Boolean); |
|
* // => true |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': true }, |
|
* { 'user': 'fred', 'active': false } |
|
* ]; |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* _.some(users, { 'user': 'barney', 'active': false }); |
|
* // => false |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* _.some(users, ['active', false]); |
|
* // => true |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.some(users, 'active'); |
|
* // => true |
|
*/ |
|
function some(collection, predicate, guard) { |
|
var func = isArray(collection) ? arraySome : baseSome; |
|
if (guard && isIterateeCall(collection, predicate, guard)) { |
|
predicate = undefined; |
|
} |
|
return func(collection, baseIteratee(predicate, 3)); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.sortBy` which uses `comparer` to define |
|
* the sort order of `array` and replaces criteria objects with their |
|
* corresponding values. |
|
* |
|
* @private |
|
* @param {Array} array The array to sort. |
|
* @param {Function} comparer The function to define sort order. |
|
* @returns {Array} Returns `array`. |
|
*/ |
|
function baseSortBy(array, comparer) { |
|
var length = array.length; |
|
|
|
array.sort(comparer); |
|
while (length--) { |
|
array[length] = array[length].value; |
|
} |
|
return array; |
|
} |
|
|
|
/** |
|
* Used by `_.sortByOrder` to compare multiple properties of a value to another |
|
* and stable sort them. |
|
* |
|
* If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise, |
|
* a value is sorted in ascending order if its corresponding order is "asc", and |
|
* descending if "desc". |
|
* |
|
* @private |
|
* @param {Object} object The object to compare. |
|
* @param {Object} other The other object to compare. |
|
* @param {boolean[]|string[]} orders The order to sort by for each property. |
|
* @returns {number} Returns the sort order indicator for `object`. |
|
*/ |
|
function compareMultiple(object, other, orders) { |
|
var index = -1, |
|
objCriteria = object.criteria, |
|
othCriteria = other.criteria, |
|
length = objCriteria.length, |
|
ordersLength = orders.length; |
|
|
|
while (++index < length) { |
|
var result = compareAscending(objCriteria[index], othCriteria[index]); |
|
if (result) { |
|
if (index >= ordersLength) { |
|
return result; |
|
} |
|
var order = orders[index]; |
|
return result * (order === 'asc' ? 1 : -1); |
|
} |
|
} |
|
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications |
|
// that causes it, under certain circumstances, to provide the same value for |
|
// `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 |
|
// for more details. |
|
// |
|
// This also ensures a stable sort in V8 and other engines. |
|
// See https://code.google.com/p/v8/issues/detail?id=90 for more details. |
|
return object.index - other.index; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.sortByOrder` without param guards. |
|
* |
|
* @private |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. |
|
* @param {string[]} orders The sort orders of `iteratees`. |
|
* @returns {Array} Returns the new sorted array. |
|
*/ |
|
function baseSortByOrder(collection, iteratees, orders) { |
|
var index = -1; |
|
|
|
iteratees = arrayMap(iteratees.length ? iteratees : Array(1), function(iteratee) { |
|
return baseIteratee(iteratee); |
|
}); |
|
|
|
var result = baseMap(collection, function(value, key, collection) { |
|
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); |
|
}); |
|
} |
|
|
|
/** |
|
* Creates an array of elements, sorted in ascending order by the results of |
|
* running each element in a collection through each iteratee. This method |
|
* performs a stable sort, that is, it preserves the original sort order of |
|
* equal elements. The iteratees are invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]] |
|
* The iteratees to sort by, specified individually or in arrays. |
|
* @returns {Array} Returns the new sorted array. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, _.values); |
|
* |
|
* var users = [ |
|
* { 'user': 'fred', 'age': 48 }, |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 42 }, |
|
* { 'user': 'barney', 'age': 34 } |
|
* ]; |
|
* |
|
* resolve( _.sortBy(users, function(o) { return o.user; }) ); |
|
* // => // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] |
|
* |
|
* resolve( _.sortBy(users, ['user', 'age']) ); |
|
* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]] |
|
* |
|
* resolve( _.sortBy(users, 'user', function(o) { |
|
* return Math.floor(o.age / 10); |
|
* }) ); |
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] |
|
*/ |
|
var sortBy = rest(function(collection, iteratees) { |
|
if (collection == null) { |
|
return []; |
|
} |
|
var length = iteratees.length; |
|
if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { |
|
iteratees = []; |
|
} else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { |
|
iteratees.length = 1; |
|
} |
|
return baseSortByOrder(collection, baseFlatten(iteratees), []); |
|
}); |
|
|
|
/** |
|
* This method is like `_.sortBy` except that it allows specifying the |
|
* sort orders of the iteratees to sort by. If `orders` is unspecified, all |
|
* values are sorted in ascending order. Otherwise, a value is sorted in |
|
* ascending order if its corresponding order is "asc", and descending if "desc". |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Collection |
|
* @param {Array|Object} collection The collection to iterate over. |
|
* @param {Function[]|Object[]|string[]} [iteratees=[_.identity]] The iteratees to sort by. |
|
* @param {string[]} [orders] The sort orders of `iteratees`. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`. |
|
* @returns {Array} Returns the new sorted array. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, _.values); |
|
* |
|
* var users = [ |
|
* { '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 |
|
* resolve( _.sortByOrder(users, ['user', 'age'], ['asc', 'desc']) ); |
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] |
|
*/ |
|
function sortByOrder(collection, iteratees, orders, guard) { |
|
if (collection == null) { |
|
return []; |
|
} |
|
if (!isArray(iteratees)) { |
|
iteratees = iteratees == null ? [] : [iteratees]; |
|
} |
|
orders = guard ? undefined : orders; |
|
if (!isArray(orders)) { |
|
orders = orders == null ? [] : [orders]; |
|
} |
|
return baseSortByOrder(collection, iteratees, orders); |
|
} |
|
|
|
/** Used as references for the maximum length and index of an array. */ |
|
var MAX_ARRAY_LENGTH$5 = 4294967295; |
|
var MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH$5 - 1; |
|
var nativeFloor$3 = Math.floor; |
|
var nativeMin$6 = Math.min; |
|
/** |
|
* This function is like `binaryIndex` except that it invokes `iteratee` for |
|
* `value` and each element of `array` to compute their sort ranking. The |
|
* iteratee is invoked with one argument; (value). |
|
* |
|
* @private |
|
* @param {Array} array The sorted array to inspect. |
|
* @param {*} value The value to evaluate. |
|
* @param {Function} iteratee The function invoked per element. |
|
* @param {boolean} [retHighest] Specify returning the highest qualified index. |
|
* @returns {number} Returns the index at which `value` should be inserted into `array`. |
|
*/ |
|
function binaryIndexBy(array, value, iteratee, retHighest) { |
|
value = iteratee(value); |
|
|
|
var low = 0, |
|
high = array ? array.length : 0, |
|
valIsNaN = value !== value, |
|
valIsNull = value === null, |
|
valIsUndef = value === undefined; |
|
|
|
while (low < high) { |
|
var mid = nativeFloor$3((low + high) / 2), |
|
computed = iteratee(array[mid]), |
|
isDef = computed !== undefined, |
|
isReflexive = computed === computed; |
|
|
|
if (valIsNaN) { |
|
var setLow = isReflexive || retHighest; |
|
} else if (valIsNull) { |
|
setLow = isReflexive && isDef && (retHighest || computed != null); |
|
} else if (valIsUndef) { |
|
setLow = isReflexive && (retHighest || isDef); |
|
} else if (computed == null) { |
|
setLow = false; |
|
} else { |
|
setLow = retHighest ? (computed <= value) : (computed < value); |
|
} |
|
if (setLow) { |
|
low = mid + 1; |
|
} else { |
|
high = mid; |
|
} |
|
} |
|
return nativeMin$6(high, MAX_ARRAY_INDEX); |
|
} |
|
|
|
var MAX_ARRAY_LENGTH$4 = 4294967295; |
|
var HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH$4 >>> 1; |
|
/** |
|
* Performs a binary search of `array` to determine the index at which `value` |
|
* should be inserted into `array` in order to maintain its sort order. |
|
* |
|
* @private |
|
* @param {Array} array The sorted array to inspect. |
|
* @param {*} value The value to evaluate. |
|
* @param {boolean} [retHighest] Specify returning the highest qualified index. |
|
* @returns {number} Returns the index at which `value` should be inserted |
|
* into `array`. |
|
*/ |
|
function binaryIndex(array, value, retHighest) { |
|
var low = 0, |
|
high = array ? array.length : low; |
|
|
|
if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { |
|
while (low < high) { |
|
var mid = (low + high) >>> 1, |
|
computed = array[mid]; |
|
|
|
if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) { |
|
low = mid + 1; |
|
} else { |
|
high = mid; |
|
} |
|
} |
|
return high; |
|
} |
|
return binaryIndexBy(array, value, identity, retHighest); |
|
} |
|
|
|
/** |
|
* Uses a binary search to determine the lowest index at which `value` should |
|
* be inserted into `array` in order to maintain its sort order. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The sorted array to inspect. |
|
* @param {*} value The value to evaluate. |
|
* @returns {number} Returns the index at which `value` should be inserted into `array`. |
|
* @example |
|
* |
|
* _.sortedIndex([30, 50], 40); |
|
* // => 1 |
|
* |
|
* _.sortedIndex([4, 5], 4); |
|
* // => 0 |
|
*/ |
|
function sortedIndex(array, value) { |
|
return binaryIndex(array, value); |
|
} |
|
|
|
/** |
|
* This method is like `_.sortedIndex` except that it accepts `iteratee` |
|
* which is invoked for `value` and each element of `array` to compute their |
|
* sort ranking. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The sorted array to inspect. |
|
* @param {*} value The value to evaluate. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {number} Returns the index at which `value` should be inserted into `array`. |
|
* @example |
|
* |
|
* var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 }; |
|
* |
|
* _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict)); |
|
* // => 1 |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); |
|
* // => 0 |
|
*/ |
|
function sortedIndexBy(array, value, iteratee) { |
|
return binaryIndexBy(array, value, baseIteratee(iteratee)); |
|
} |
|
|
|
/** |
|
* This method is like `_.indexOf` except that it performs a binary |
|
* search on a sorted `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to search. |
|
* @param {*} value The value to search for. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
* @example |
|
* |
|
* _.sortedIndexOf([1, 1, 2, 2], 2); |
|
* // => 2 |
|
*/ |
|
function sortedIndexOf(array, value) { |
|
var length = array ? array.length : 0; |
|
if (length) { |
|
var index = binaryIndex(array, value); |
|
if (index < length && |
|
(value === value ? (value === array[index]) : (array[index] !== array[index]))) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* This method is like `_.sortedIndex` except that it returns the highest |
|
* index at which `value` should be inserted into `array` in order to |
|
* maintain its sort order. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The sorted array to inspect. |
|
* @param {*} value The value to evaluate. |
|
* @returns {number} Returns the index at which `value` should be inserted into `array`. |
|
* @example |
|
* |
|
* _.sortedLastIndex([4, 5], 4); |
|
* // => 1 |
|
*/ |
|
function sortedLastIndex(array, value) { |
|
return binaryIndex(array, value, true); |
|
} |
|
|
|
/** |
|
* This method is like `_.sortedLastIndex` except that it accepts `iteratee` |
|
* which is invoked for `value` and each element of `array` to compute their |
|
* sort ranking. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The sorted array to inspect. |
|
* @param {*} value The value to evaluate. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {number} Returns the index at which `value` should be inserted into `array`. |
|
* @example |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); |
|
* // => 1 |
|
*/ |
|
function sortedLastIndexBy(array, value, iteratee) { |
|
return binaryIndexBy(array, value, baseIteratee(iteratee), true); |
|
} |
|
|
|
/** |
|
* This method is like `_.lastIndexOf` except that it performs a binary |
|
* search on a sorted `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to search. |
|
* @param {*} value The value to search for. |
|
* @returns {number} Returns the index of the matched value, else `-1`. |
|
* @example |
|
* |
|
* _.sortedLastIndexOf([1, 1, 2, 2], 2); |
|
* // => 3 |
|
*/ |
|
function sortedLastIndexOf(array, value) { |
|
var length = array ? array.length : 0; |
|
if (length) { |
|
var index = binaryIndex(array, value, true) - 1, |
|
other = array[index]; |
|
|
|
if (value === value ? (value === other) : (other !== other)) { |
|
return index; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.sortedUniqBy` without support for callback |
|
* shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to inspect. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns the new duplicate free array. |
|
*/ |
|
function baseSortedUniqBy(array, iteratee) { |
|
var index = 0, |
|
length = array.length, |
|
value = array[0], |
|
computed = iteratee ? iteratee(value) : value, |
|
seen = computed, |
|
resIndex = 0, |
|
result = [value]; |
|
|
|
while (++index < length) { |
|
value = array[index], |
|
computed = iteratee ? iteratee(value) : value; |
|
|
|
if ((seen === seen ? (seen !== computed) : (computed === computed))) { |
|
seen = computed; |
|
result[++resIndex] = value; |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.sortedUniq`. |
|
* |
|
* @private |
|
* @param {Array} array The array to inspect. |
|
* @returns {Array} Returns the new duplicate free array. |
|
*/ |
|
function baseSortedUniq(array) { |
|
return baseSortedUniqBy(array); |
|
} |
|
|
|
/** |
|
* This method is like `_.uniq` except that it's designed and optimized |
|
* for sorted arrays. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to inspect. |
|
* @returns {Array} Returns the new duplicate free array. |
|
* @example |
|
* |
|
* _.sortedUniq([1, 1, 2]); |
|
* // => [1, 2] |
|
*/ |
|
function sortedUniq(array) { |
|
return (array && array.length) |
|
? baseSortedUniq(array) |
|
: []; |
|
} |
|
|
|
/** |
|
* This method is like `_.uniqBy` except that it's designed and optimized |
|
* for sorted arrays. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to inspect. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns the new duplicate free array. |
|
* @example |
|
* |
|
* _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); |
|
* // => [1.1, 2.2] |
|
*/ |
|
function sortedUniqBy(array, iteratee) { |
|
return (array && array.length) |
|
? baseSortedUniqBy(array, baseIteratee(iteratee)) |
|
: []; |
|
} |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$6 = 'Expected a function'; |
|
|
|
/** |
|
* Creates a function that invokes `func` with the `this` binding of the created |
|
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3). |
|
* |
|
* **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to spread arguments over. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var say = _.spread(function(who, what) { |
|
* return who + ' says ' + what; |
|
* }); |
|
* |
|
* say(['fred', 'hello']); |
|
* // => 'fred says hello' |
|
* |
|
* // with a Promise |
|
* var numbers = Promise.all([ |
|
* Promise.resolve(40), |
|
* Promise.resolve(36) |
|
* ]); |
|
* |
|
* numbers.then(_.spread(function(x, y) { |
|
* return x + y; |
|
* })); |
|
* // => a Promise of 76 |
|
*/ |
|
function spread(func) { |
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$6); |
|
} |
|
return function(array) { |
|
return func.apply(this, array); |
|
}; |
|
} |
|
|
|
/** |
|
* Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the start cased string. |
|
* @example |
|
* |
|
* _.startCase('--foo-bar'); |
|
* // => 'Foo Bar' |
|
* |
|
* _.startCase('fooBar'); |
|
* // => 'Foo Bar' |
|
* |
|
* _.startCase('__foo_bar__'); |
|
* // => 'Foo Bar' |
|
*/ |
|
var startCase = createCompounder(function(result, word, index) { |
|
return result + (index ? ' ' : '') + capitalize(word); |
|
}); |
|
|
|
/** |
|
* Checks if `string` starts with the given target string. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to search. |
|
* @param {string} [target] The string to search for. |
|
* @param {number} [position=0] The position to search from. |
|
* @returns {boolean} Returns `true` if `string` starts with `target`, else `false`. |
|
* @example |
|
* |
|
* _.startsWith('abc', 'a'); |
|
* // => true |
|
* |
|
* _.startsWith('abc', 'b'); |
|
* // => false |
|
* |
|
* _.startsWith('abc', 'b', 1); |
|
* // => true |
|
*/ |
|
function startsWith(string, target, position) { |
|
string = toString(string); |
|
position = clamp(toInteger(position), 0, string.length); |
|
return string.lastIndexOf(target, position) == position; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.sum` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function} iteratee The function invoked per iteration. |
|
* @returns {number} Returns the sum. |
|
*/ |
|
function baseSum(array, iteratee) { |
|
var result, |
|
index = -1, |
|
length = array.length; |
|
|
|
while (++index < length) { |
|
var current = iteratee(array[index]); |
|
if (current === current && current != null) { |
|
result = result === undefined ? current : (result + current); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Gets the sum of the values in `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {Array} array The array to iterate over. |
|
* @returns {number} Returns the sum. |
|
* @example |
|
* |
|
* _.sum([4, 6]); |
|
* // => 10 |
|
*/ |
|
function sum(array) { |
|
return (array && array.length) |
|
? baseSum(array, identity) |
|
: undefined; |
|
} |
|
|
|
/** |
|
* This method is like `_.sum` except that it accepts `iteratee` which is |
|
* invoked for each element in `array` to generate the value to be summed. |
|
* The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Math |
|
* @param {Array} array The array to iterate over. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {number} Returns the sum. |
|
* @example |
|
* |
|
* var objects = [ |
|
* { 'n': 4 }, |
|
* { 'n': 6 } |
|
* ]; |
|
* |
|
* _.sum(objects, function(o) { return o.n; }); |
|
* // => 10 |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.sum(objects, 'n'); |
|
* // => 10 |
|
*/ |
|
function sumBy(array, iteratee) { |
|
return (array && array.length) |
|
? baseSum(array, baseIteratee(iteratee)) |
|
: undefined; |
|
} |
|
|
|
/** |
|
* Gets all but the first element of `array`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* _.tail([1, 2, 3]); |
|
* // => [2, 3] |
|
*/ |
|
function tail(array) { |
|
return drop(array, 1); |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` with `n` elements taken from the beginning. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {number} [n=1] The number of elements to take. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* _.take([1, 2, 3]); |
|
* // => [1] |
|
* |
|
* _.take([1, 2, 3], 2); |
|
* // => [1, 2] |
|
* |
|
* _.take([1, 2, 3], 5); |
|
* // => [1, 2, 3] |
|
* |
|
* _.take([1, 2, 3], 0); |
|
* // => [] |
|
*/ |
|
function take(array, n, guard) { |
|
if (!(array && array.length)) { |
|
return []; |
|
} |
|
n = (guard || n === undefined) ? 1 : n; |
|
return baseSlice(array, 0, n < 0 ? 0 : n); |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` with `n` elements taken from the end. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {number} [n=1] The number of elements to take. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* _.takeRight([1, 2, 3]); |
|
* // => [3] |
|
* |
|
* _.takeRight([1, 2, 3], 2); |
|
* // => [2, 3] |
|
* |
|
* _.takeRight([1, 2, 3], 5); |
|
* // => [1, 2, 3] |
|
* |
|
* _.takeRight([1, 2, 3], 0); |
|
* // => [] |
|
*/ |
|
function takeRight(array, n, guard) { |
|
var length = array ? array.length : 0; |
|
if (!length) { |
|
return []; |
|
} |
|
n = (guard || n === undefined) ? 1 : toInteger(n); |
|
n = length - n; |
|
return baseSlice(array, n < 0 ? 0 : n); |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` with elements taken from the end. Elements are |
|
* taken until `predicate` returns falsey. The predicate is invoked with three |
|
* arguments: (value, index, array). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': true }, |
|
* { 'user': 'fred', 'active': false }, |
|
* { 'user': 'pebbles', 'active': false } |
|
* ]; |
|
* |
|
* resolve( _.takeRightWhile(users, function(o) { return !o.active; }) ); |
|
* // => ['fred', 'pebbles'] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }) ); |
|
* // => ['pebbles'] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.takeRightWhile(users, ['active', false]) ); |
|
* // => ['fred', 'pebbles'] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.takeRightWhile(users, 'active') ); |
|
* // => [] |
|
*/ |
|
function takeRightWhile(array, predicate) { |
|
return (array && array.length) |
|
? baseWhile(array, baseIteratee(predicate, 3), false, true) |
|
: []; |
|
} |
|
|
|
/** |
|
* Creates a slice of `array` with elements taken from the beginning. Elements |
|
* are taken until `predicate` returns falsey. The predicate is invoked with |
|
* three arguments: (value, index, array). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to query. |
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the slice of `array`. |
|
* @example |
|
* |
|
* var resolve = _.partial(_.map, _, 'user'); |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'active': false }, |
|
* { 'user': 'fred', 'active': false}, |
|
* { 'user': 'pebbles', 'active': true } |
|
* ]; |
|
* |
|
* resolve( _.takeWhile(users, function(o) { return !o.active; }) ); |
|
* // => ['barney', 'fred'] |
|
* |
|
* // using the `_.matches` callback shorthand |
|
* resolve( _.takeWhile(users, { 'user': 'barney', 'active': false }) ); |
|
* // => ['barney'] |
|
* |
|
* // using the `_.matchesProperty` callback shorthand |
|
* resolve( _.takeWhile(users, ['active', false]) ); |
|
* // => ['barney', 'fred'] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* resolve( _.takeWhile(users, 'active') ); |
|
* // => [] |
|
*/ |
|
function takeWhile(array, predicate) { |
|
return (array && array.length) |
|
? baseWhile(array, baseIteratee(predicate, 3)) |
|
: []; |
|
} |
|
|
|
/** |
|
* This method invokes `interceptor` and returns `value`. The interceptor is |
|
* invoked with one argument; (value). The purpose of this method is to "tap into" |
|
* a method chain in order to perform operations on intermediate results within |
|
* the chain. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Chain |
|
* @param {*} value The value to provide to `interceptor`. |
|
* @param {Function} interceptor The function to invoke. |
|
* @returns {*} Returns `value`. |
|
* @example |
|
* |
|
* _([1, 2, 3]) |
|
* .tap(function(array) { |
|
* array.pop(); |
|
* }) |
|
* .reverse() |
|
* .value(); |
|
* // => [2, 1] |
|
*/ |
|
function tap(value, interceptor) { |
|
interceptor(value); |
|
return value; |
|
} |
|
|
|
/** Used to escape characters for inclusion in compiled string literals. */ |
|
var stringEscapes = { |
|
'\\': '\\', |
|
"'": "'", |
|
'\n': 'n', |
|
'\r': 'r', |
|
'\u2028': 'u2028', |
|
'\u2029': 'u2029' |
|
}; |
|
|
|
/** |
|
* Used by `_.template` to escape characters for inclusion in compiled string literals. |
|
* |
|
* @private |
|
* @param {string} chr The matched character to escape. |
|
* @returns {string} Returns the escaped character. |
|
*/ |
|
function escapeStringChar(chr) { |
|
return '\\' + stringEscapes[chr]; |
|
} |
|
|
|
/** Used to match template delimiters. */ |
|
var reInterpolate = /<%=([\s\S]+?)%>/g; |
|
|
|
/** Used to match template delimiters. */ |
|
var reEvaluate = /<%([\s\S]+?)%>/g; |
|
|
|
/** Used to match template delimiters. */ |
|
var reEscape = /<%-([\s\S]+?)%>/g; |
|
|
|
/** |
|
* By default, the template delimiters used by lodash are like those in |
|
* embedded Ruby (ERB). Change the following template settings to use |
|
* alternative delimiters. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type Object |
|
*/ |
|
var templateSettings = { |
|
|
|
/** |
|
* Used to detect `data` property values to be HTML-escaped. |
|
* |
|
* @memberOf _.templateSettings |
|
* @type RegExp |
|
*/ |
|
'escape': reEscape, |
|
|
|
/** |
|
* Used to detect code to be evaluated. |
|
* |
|
* @memberOf _.templateSettings |
|
* @type RegExp |
|
*/ |
|
'evaluate': reEvaluate, |
|
|
|
/** |
|
* Used to detect `data` property values to inject. |
|
* |
|
* @memberOf _.templateSettings |
|
* @type RegExp |
|
*/ |
|
'interpolate': reInterpolate, |
|
|
|
/** |
|
* Used to reference the data object in the template text. |
|
* |
|
* @memberOf _.templateSettings |
|
* @type string |
|
*/ |
|
'variable': '', |
|
|
|
/** |
|
* Used to import variables into the compiled template. |
|
* |
|
* @memberOf _.templateSettings |
|
* @type Object |
|
*/ |
|
'imports': { |
|
|
|
/** |
|
* A reference to the `lodash` function. |
|
* |
|
* @memberOf _.templateSettings.imports |
|
* @type Function |
|
*/ |
|
'_': { 'escape': escape } |
|
} |
|
}; |
|
|
|
var reEmptyStringLeading = /\b__p \+= '';/g; |
|
var reEmptyStringMiddle = /\b(__p \+=) '' \+/g; |
|
var reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; |
|
/** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */ |
|
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; |
|
|
|
/** Used to ensure capturing order of template delimiters. */ |
|
var reNoMatch = /($^)/; |
|
|
|
/** Used to match unescaped characters in compiled string literals. */ |
|
var reUnescapedString = /['\n\r\u2028\u2029\\]/g; |
|
|
|
/** |
|
* Creates a compiled template function that can interpolate data properties |
|
* in "interpolate" delimiters, HTML-escape interpolated data properties in |
|
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data |
|
* properties may be accessed as free variables in the template. If a setting |
|
* object is provided it takes precedence over `_.templateSettings` values. |
|
* |
|
* **Note:** In the development build `_.template` utilizes |
|
* [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) |
|
* for easier debugging. |
|
* |
|
* For more information on precompiling templates see |
|
* [lodash's custom builds documentation](https://lodash.com/custom-builds). |
|
* |
|
* For more information on Chrome extension sandboxes see |
|
* [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The template string. |
|
* @param {Object} [options] The options object. |
|
* @param {RegExp} [options.escape] The HTML "escape" delimiter. |
|
* @param {RegExp} [options.evaluate] The "evaluate" delimiter. |
|
* @param {Object} [options.imports] An object to import into the template as free variables. |
|
* @param {RegExp} [options.interpolate] The "interpolate" delimiter. |
|
* @param {string} [options.sourceURL] The sourceURL of the template's compiled source. |
|
* @param {string} [options.variable] The data object variable name. |
|
* @param- {Object} [otherOptions] Enables the legacy `options` param signature. |
|
* @returns {Function} Returns the compiled template function. |
|
* @example |
|
* |
|
* // using the "interpolate" delimiter to create a compiled template |
|
* var compiled = _.template('hello <%= user %>!'); |
|
* compiled({ 'user': 'fred' }); |
|
* // => 'hello fred!' |
|
* |
|
* // using the HTML "escape" delimiter to escape data property values |
|
* var compiled = _.template('<b><%- value %></b>'); |
|
* compiled({ 'value': '<script>' }); |
|
* // => '<b><script></b>' |
|
* |
|
* // using the "evaluate" delimiter to execute JavaScript and generate HTML |
|
* var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); |
|
* compiled({ 'users': ['fred', 'barney'] }); |
|
* // => '<li>fred</li><li>barney</li>' |
|
* |
|
* // using the internal `print` function in "evaluate" delimiters |
|
* var compiled = _.template('<% print("hello " + user); %>!'); |
|
* compiled({ 'user': 'barney' }); |
|
* // => 'hello barney!' |
|
* |
|
* // using the ES delimiter as an alternative to the default "interpolate" delimiter |
|
* var compiled = _.template('hello ${ user }!'); |
|
* compiled({ 'user': 'pebbles' }); |
|
* // => 'hello pebbles!' |
|
* |
|
* // using custom template delimiters |
|
* _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; |
|
* var compiled = _.template('hello {{ user }}!'); |
|
* compiled({ 'user': 'mustache' }); |
|
* // => 'hello mustache!' |
|
* |
|
* // using backslashes to treat delimiters as plain text |
|
* var compiled = _.template('<%= "\\<%- value %\\>" %>'); |
|
* compiled({ 'value': 'ignored' }); |
|
* // => '<%- value %>' |
|
* |
|
* // using the `imports` option to import `jQuery` as `jq` |
|
* var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; |
|
* var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); |
|
* compiled({ 'users': ['fred', 'barney'] }); |
|
* // => '<li>fred</li><li>barney</li>' |
|
* |
|
* // using the `sourceURL` option to specify a custom sourceURL for the template |
|
* var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); |
|
* compiled(data); |
|
* // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector |
|
* |
|
* // using the `variable` option to ensure a with-statement isn't used in the compiled template |
|
* var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); |
|
* compiled.source; |
|
* // => function(data) { |
|
* // var __t, __p = ''; |
|
* // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; |
|
* // return __p; |
|
* // } |
|
* |
|
* // using the `source` property to inline compiled templates for meaningful |
|
* // line numbers in error messages and a stack trace |
|
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\ |
|
* var JST = {\ |
|
* "main": ' + _.template(mainText).source + '\ |
|
* };\ |
|
* '); |
|
*/ |
|
function template(string, options, otherOptions) { |
|
// Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/) |
|
// and Laura Doktorova's doT.js (https://github.com/olado/doT). |
|
var settings = templateSettings.imports._.templateSettings || templateSettings; |
|
|
|
if (otherOptions && isIterateeCall(string, options, otherOptions)) { |
|
options = otherOptions = undefined; |
|
} |
|
string = toString(string); |
|
options = extendWith({}, otherOptions || options, settings, extendDefaults); |
|
|
|
var imports = extendWith({}, options.imports, settings.imports, extendDefaults), |
|
importsKeys = keys(imports), |
|
importsValues = baseValues(imports, importsKeys); |
|
|
|
var isEscaping, |
|
isEvaluating, |
|
index = 0, |
|
interpolate = options.interpolate || reNoMatch, |
|
source = "__p += '"; |
|
|
|
// Compile the regexp to match each delimiter. |
|
var reDelimiters = RegExp( |
|
(options.escape || reNoMatch).source + '|' + |
|
interpolate.source + '|' + |
|
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + |
|
(options.evaluate || reNoMatch).source + '|$' |
|
, 'g'); |
|
|
|
// Use a sourceURL for easier debugging. |
|
var sourceURL = 'sourceURL' in options ? '//# sourceURL=' + options.sourceURL + '\n' : ''; |
|
|
|
string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { |
|
interpolateValue || (interpolateValue = esTemplateValue); |
|
|
|
// Escape characters that can't be included in string literals. |
|
source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); |
|
|
|
// Replace delimiters with snippets. |
|
if (escapeValue) { |
|
isEscaping = true; |
|
source += "' +\n__e(" + escapeValue + ") +\n'"; |
|
} |
|
if (evaluateValue) { |
|
isEvaluating = true; |
|
source += "';\n" + evaluateValue + ";\n__p += '"; |
|
} |
|
if (interpolateValue) { |
|
source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; |
|
} |
|
index = offset + match.length; |
|
|
|
// The JS engine embedded in Adobe products needs `match` returned in |
|
// order to produce the correct `offset` value. |
|
return match; |
|
}); |
|
|
|
source += "';\n"; |
|
|
|
// If `variable` is not specified wrap a with-statement around the generated |
|
// code to add the data object to the top of the scope chain. |
|
var variable = options.variable; |
|
if (!variable) { |
|
source = 'with (obj) {\n' + source + '\n}\n'; |
|
} |
|
// Cleanup code by stripping empty strings. |
|
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) |
|
.replace(reEmptyStringMiddle, '$1') |
|
.replace(reEmptyStringTrailing, '$1;'); |
|
|
|
// Frame code as the function body. |
|
source = 'function(' + (variable || 'obj') + ') {\n' + |
|
(variable |
|
? '' |
|
: 'obj || (obj = {});\n' |
|
) + |
|
"var __t, __p = ''" + |
|
(isEscaping |
|
? ', __e = _.escape' |
|
: '' |
|
) + |
|
(isEvaluating |
|
? ', __j = Array.prototype.join;\n' + |
|
"function print() { __p += __j.call(arguments, '') }\n" |
|
: ';\n' |
|
) + |
|
source + |
|
'return __p\n}'; |
|
|
|
var result = attempt(function() { |
|
return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues); |
|
}); |
|
|
|
// Provide the compiled function's source by its `toString` method or |
|
// the `source` property as a convenience for inlining compiled templates. |
|
result.source = source; |
|
if (isError(result)) { |
|
throw result; |
|
} |
|
return result; |
|
} |
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */ |
|
var FUNC_ERROR_TEXT$7 = 'Expected a function'; |
|
|
|
/** |
|
* Creates a throttled function that only invokes `func` at most once per |
|
* every `wait` milliseconds. The throttled function comes with a `cancel` |
|
* method to cancel delayed invocations. Provide an options object to indicate |
|
* that `func` should be invoked on the leading and/or trailing edge of the |
|
* `wait` timeout. Subsequent calls to the throttled function return the |
|
* result of the last `func` call. |
|
* |
|
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked |
|
* on the trailing edge of the timeout only if the the throttled function is |
|
* invoked more than once during the `wait` timeout. |
|
* |
|
* See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation) |
|
* for details over the differences between `_.throttle` and `_.debounce`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {Function} func The function to throttle. |
|
* @param {number} [wait=0] The number of milliseconds to throttle invocations to. |
|
* @param {Object} [options] The options object. |
|
* @param {boolean} [options.leading=true] Specify invoking on the leading |
|
* edge of the timeout. |
|
* @param {boolean} [options.trailing=true] Specify invoking on the trailing |
|
* edge of the timeout. |
|
* @returns {Function} Returns the new throttled function. |
|
* @example |
|
* |
|
* // avoid excessively updating the position while scrolling |
|
* jQuery(window).on('scroll', _.throttle(updatePosition, 100)); |
|
* |
|
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes |
|
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, { |
|
* 'trailing': false |
|
* })); |
|
* |
|
* // cancel a trailing throttled call |
|
* jQuery(window).on('popstate', throttled.cancel); |
|
*/ |
|
function throttle(func, wait, options) { |
|
var leading = true, |
|
trailing = true; |
|
|
|
if (typeof func != 'function') { |
|
throw new TypeError(FUNC_ERROR_TEXT$7); |
|
} |
|
if (isObject(options)) { |
|
leading = 'leading' in options ? !!options.leading : leading; |
|
trailing = 'trailing' in options ? !!options.trailing : trailing; |
|
} |
|
return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing }); |
|
} |
|
|
|
/** |
|
* This method is like `_.tap` except that it returns the result of `interceptor`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Chain |
|
* @param {*} value The value to provide to `interceptor`. |
|
* @param {Function} interceptor The function to invoke. |
|
* @returns {*} Returns the result of `interceptor`. |
|
* @example |
|
* |
|
* _(' abc ') |
|
* .chain() |
|
* .trim() |
|
* .thru(function(value) { |
|
* return [value]; |
|
* }) |
|
* .value(); |
|
* // => ['abc'] |
|
*/ |
|
function thru(value, interceptor) { |
|
return interceptor(value); |
|
} |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var MAX_SAFE_INTEGER$2 = 9007199254740991; |
|
|
|
/** Used as references for the maximum length and index of an array. */ |
|
var MAX_ARRAY_LENGTH$1 = 4294967295; |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMin$3 = Math.min; |
|
|
|
/** |
|
* Invokes the iteratee function `n` times, returning an array of the results |
|
* of each invocation. The iteratee is invoked with one argument; (index). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {number} n The number of times to invoke `iteratee`. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @returns {Array} Returns the array of results. |
|
* @example |
|
* |
|
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false)); |
|
* // => [3, 6, 4] |
|
* |
|
* _.times(3, function(n) { |
|
* mage.castSpell(n); |
|
* }); |
|
* // => invokes `mage.castSpell` three times with `n` of `0`, `1`, and `2` |
|
*/ |
|
function times(n, iteratee) { |
|
n = toInteger(n); |
|
if (n < 1 || n > MAX_SAFE_INTEGER$2) { |
|
return []; |
|
} |
|
var index = MAX_ARRAY_LENGTH$1, |
|
length = nativeMin$3(n, MAX_ARRAY_LENGTH$1); |
|
|
|
iteratee = toFunction(iteratee); |
|
n -= MAX_ARRAY_LENGTH$1; |
|
|
|
var result = baseTimes(length, iteratee); |
|
while (++index < n) { |
|
iteratee(index); |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* Enables the wrapper to be iterable. |
|
* |
|
* @name Symbol.iterator |
|
* @memberOf _ |
|
* @category Chain |
|
* @returns {Object} Returns the wrapper object. |
|
* @example |
|
* |
|
* var wrapped = _([1, 2]); |
|
* |
|
* wrapped[Symbol.iterator]() === wrapped; |
|
* // => true |
|
* |
|
* Array.from(wrapped); |
|
* // => [1, 2] |
|
*/ |
|
function wrapperToIterator() { |
|
return this; |
|
} |
|
|
|
/** |
|
* Converts `string`, as a whole, to lower case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the lower cased string. |
|
* @example |
|
* |
|
* _.toLower('--Foo-Bar'); |
|
* // => '--foo-bar' |
|
* |
|
* _.toLower('fooBar'); |
|
* // => 'foobar' |
|
* |
|
* _.toLower('__FOO_BAR__'); |
|
* // => '__foo_bar__' |
|
*/ |
|
function toLower(value) { |
|
return toString(value).toLowerCase(); |
|
} |
|
|
|
/** |
|
* Converts `value` to a property path array. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {*} value The value to convert. |
|
* @returns {Array} Returns the new property path array. |
|
* @example |
|
* |
|
* _.toPath('a.b.c'); |
|
* // => ['a', 'b', 'c'] |
|
* |
|
* _.toPath('a[0].b.c'); |
|
* // => ['a', '0', 'b', 'c'] |
|
* |
|
* var path = ['a', 'b', 'c'], |
|
* newPath = _.toPath(path); |
|
* |
|
* console.log(newPath); |
|
* // => ['a', 'b', 'c'] |
|
* |
|
* console.log(path === newPath); |
|
* // => false |
|
*/ |
|
function toPath(value) { |
|
return isArray(value) ? arrayMap(value, String) : stringToPath(value); |
|
} |
|
|
|
/** Used as references for various `Number` constants. */ |
|
var MAX_SAFE_INTEGER$3 = 9007199254740991; |
|
|
|
/** |
|
* Converts `value` to a safe integer. A safe integer can be compared and |
|
* represented correctly. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Lang |
|
* @param {*} value The value to convert. |
|
* @returns {number} Returns the converted integer. |
|
* @example |
|
* |
|
* _.toSafeInteger('3.14'); |
|
* // => 3 |
|
* |
|
* _.toSafeInteger(NaN); |
|
* // => 0 |
|
* |
|
* _.toSafeInteger(Infinity) |
|
* // => 9007199254740991 |
|
* |
|
* _.toSafeInteger(-Infinity) |
|
* // => -9007199254740991 |
|
*/ |
|
function toSafeInteger(value) { |
|
return clamp(toInteger(value), -MAX_SAFE_INTEGER$3, MAX_SAFE_INTEGER$3); |
|
} |
|
|
|
/** |
|
* Converts `string`, as a whole, to upper case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the upper cased string. |
|
* @example |
|
* |
|
* _.toUpper('--foo-bar'); |
|
* // => '--FOO-BAR' |
|
* |
|
* _.toUpper('fooBar'); |
|
* // => 'FOOBAR' |
|
* |
|
* _.toUpper('__foo_bar__'); |
|
* // => '__FOO_BAR__' |
|
*/ |
|
function toUpper(value) { |
|
return toString(value).toUpperCase(); |
|
} |
|
|
|
/** |
|
* 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 invoked with four arguments: |
|
* (accumulator, value, key, object). Iteratee functions may exit iteration |
|
* early by explicitly returning `false`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Array|Object} object The object to iterate over. |
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration. |
|
* @param {*} [accumulator] The custom accumulator value. |
|
* @returns {*} Returns the accumulated value. |
|
* @example |
|
* |
|
* _.transform([2, 3, 4], function(result, n) { |
|
* result.push(n *= n); |
|
* return n % 2 == 0; |
|
* }); |
|
* // => [4, 9] |
|
* |
|
* _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { |
|
* (result[value] || (result[value] = [])).push(key); |
|
* }); |
|
* // => { '1': ['a', 'c'], '2': ['b'] } |
|
*/ |
|
function transform(object, iteratee, accumulator) { |
|
var isArr = isArray(object) || isTypedArray(object); |
|
iteratee = baseIteratee(iteratee, 4); |
|
|
|
if (accumulator == null) { |
|
if (isArr || isObject(object)) { |
|
var Ctor = object.constructor; |
|
if (isArr) { |
|
accumulator = isArray(object) ? new Ctor : []; |
|
} else { |
|
accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined); |
|
} |
|
} else { |
|
accumulator = {}; |
|
} |
|
} |
|
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) { |
|
return iteratee(accumulator, value, index, object); |
|
}); |
|
return accumulator; |
|
} |
|
|
|
/** |
|
* Removes leading whitespace or specified characters from `string`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to trim. |
|
* @param {string} [chars=whitespace] The characters to trim. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {string} Returns the trimmed string. |
|
* @example |
|
* |
|
* _.trimLeft(' abc '); |
|
* // => 'abc ' |
|
* |
|
* _.trimLeft('-_-abc-_-', '_-'); |
|
* // => 'abc-_-' |
|
*/ |
|
function trimLeft(string, chars, guard) { |
|
string = toString(string); |
|
if (!string) { |
|
return string; |
|
} |
|
if (guard || chars === undefined) { |
|
return string.slice(trimmedLeftIndex(string)); |
|
} |
|
chars = (chars + ''); |
|
if (!chars) { |
|
return string; |
|
} |
|
var strSymbols = stringToArray(string); |
|
return strSymbols.slice(charsLeftIndex(strSymbols, stringToArray(chars))).join(''); |
|
} |
|
|
|
/** |
|
* Removes trailing whitespace or specified characters from `string`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to trim. |
|
* @param {string} [chars=whitespace] The characters to trim. |
|
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. |
|
* @returns {string} Returns the trimmed string. |
|
* @example |
|
* |
|
* _.trimRight(' abc '); |
|
* // => ' abc' |
|
* |
|
* _.trimRight('-_-abc-_-', '_-'); |
|
* // => '-_-abc' |
|
*/ |
|
function trimRight(string, chars, guard) { |
|
string = toString(string); |
|
if (!string) { |
|
return string; |
|
} |
|
if (guard || chars === undefined) { |
|
return string.slice(0, trimmedRightIndex(string) + 1); |
|
} |
|
chars = (chars + ''); |
|
if (!chars) { |
|
return string; |
|
} |
|
var strSymbols = stringToArray(string); |
|
return strSymbols.slice(0, charsRightIndex(strSymbols, stringToArray(chars)) + 1).join(''); |
|
} |
|
|
|
var DEFAULT_TRUNC_LENGTH = 30; |
|
var DEFAULT_TRUNC_OMISSION = '...'; |
|
/** Used to match `RegExp` flags from their coerced string values. */ |
|
var reFlags = /\w*$/; |
|
|
|
/** Used to compose unicode character classes. */ |
|
var rsAstralRange = '\\ud800-\\udfff'; |
|
var rsComboRange$1 = '\\u0300-\\u036f\\ufe20-\\ufe23'; |
|
var rsVarRange = '\\ufe0e\\ufe0f'; |
|
/** Used to compose unicode capture groups. */ |
|
var rsZWJ = '\\u200d'; |
|
|
|
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ |
|
var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange$1 + rsVarRange + ']'); |
|
|
|
/** |
|
* Truncates `string` if it's longer than the given maximum string length. |
|
* The last characters of the truncated string are replaced with the omission |
|
* string which defaults to "...". |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to truncate. |
|
* @param {Object} [options] The options object. |
|
* @param {number} [options.length=30] The maximum string length. |
|
* @param {string} [options.omission='...'] The string to indicate text is omitted. |
|
* @param {RegExp|string} [options.separator] The separator pattern to truncate to. |
|
* @returns {string} Returns the truncated string. |
|
* @example |
|
* |
|
* _.trunc('hi-diddly-ho there, neighborino'); |
|
* // => 'hi-diddly-ho there, neighbo...' |
|
* |
|
* _.trunc('hi-diddly-ho there, neighborino', { |
|
* 'length': 24, |
|
* 'separator': ' ' |
|
* }); |
|
* // => 'hi-diddly-ho there,...' |
|
* |
|
* _.trunc('hi-diddly-ho there, neighborino', { |
|
* 'length': 24, |
|
* 'separator': /,? +/ |
|
* }); |
|
* // => 'hi-diddly-ho there...' |
|
* |
|
* _.trunc('hi-diddly-ho there, neighborino', { |
|
* 'omission': ' [...]' |
|
* }); |
|
* // => 'hi-diddly-ho there, neig [...]' |
|
*/ |
|
function trunc(string, options) { |
|
var length = DEFAULT_TRUNC_LENGTH, |
|
omission = DEFAULT_TRUNC_OMISSION; |
|
|
|
if (isObject(options)) { |
|
var separator = 'separator' in options ? options.separator : separator; |
|
length = 'length' in options ? toInteger(options.length) : length; |
|
omission = 'omission' in options ? toString(options.omission) : omission; |
|
} |
|
string = toString(string); |
|
|
|
var strLength = string.length; |
|
if (reHasComplexSymbol.test(string)) { |
|
var strSymbols = stringToArray(string); |
|
strLength = strSymbols.length; |
|
} |
|
if (length >= strLength) { |
|
return string; |
|
} |
|
var end = length - stringSize(omission); |
|
if (end < 1) { |
|
return omission; |
|
} |
|
var result = strSymbols |
|
? strSymbols.slice(0, end).join('') |
|
: string.slice(0, end); |
|
|
|
if (separator === undefined) { |
|
return result + omission; |
|
} |
|
if (strSymbols) { |
|
end += (result.length - end); |
|
} |
|
if (isRegExp(separator)) { |
|
if (string.slice(end).search(separator)) { |
|
var match, |
|
substring = result; |
|
|
|
if (!separator.global) { |
|
separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g'); |
|
} |
|
separator.lastIndex = 0; |
|
while ((match = separator.exec(substring))) { |
|
var newEnd = match.index; |
|
} |
|
result = result.slice(0, newEnd === undefined ? end : newEnd); |
|
} |
|
} else if (string.indexOf(separator, end) != end) { |
|
var index = result.lastIndexOf(separator); |
|
if (index > -1) { |
|
result = result.slice(0, index); |
|
} |
|
} |
|
return result + omission; |
|
} |
|
|
|
/** Used to map HTML entities to characters. */ |
|
var htmlUnescapes = { |
|
'&': '&', |
|
'<': '<', |
|
'>': '>', |
|
'"': '"', |
|
''': "'", |
|
'`': '`' |
|
}; |
|
|
|
/** |
|
* Used by `_.unescape` to convert HTML entities to characters. |
|
* |
|
* @private |
|
* @param {string} chr The matched character to unescape. |
|
* @returns {string} Returns the unescaped character. |
|
*/ |
|
function unescapeHtmlChar(chr) { |
|
return htmlUnescapes[chr]; |
|
} |
|
|
|
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g; |
|
var reHasEscapedHtml = RegExp(reEscapedHtml.source); |
|
/** |
|
* The inverse of `_.escape`; this method converts the HTML entities |
|
* `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their |
|
* corresponding characters. |
|
* |
|
* **Note:** No other HTML entities are unescaped. To unescape additional HTML |
|
* entities use a third-party library like [_he_](https://mths.be/he). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to unescape. |
|
* @returns {string} Returns the unescaped string. |
|
* @example |
|
* |
|
* _.unescape('fred, barney, & pebbles'); |
|
* // => 'fred, barney, & pebbles' |
|
*/ |
|
function unescape(string) { |
|
string = toString(string); |
|
return (string && reHasEscapedHtml.test(string)) |
|
? string.replace(reEscapedHtml, unescapeHtmlChar) |
|
: string; |
|
} |
|
|
|
/** Used as the size to enable large array optimizations. */ |
|
var LARGE_ARRAY_SIZE$2 = 200; |
|
|
|
/** |
|
* The base implementation of `_.uniqBy` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} array The array to inspect. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns the new duplicate free array. |
|
*/ |
|
function baseUniqBy(array, iteratee) { |
|
var index = -1, |
|
indexOf = baseIndexOf, |
|
length = array.length, |
|
isCommon = true, |
|
seen = length >= LARGE_ARRAY_SIZE$2 ? new SetCache : null, |
|
result = []; |
|
|
|
if (seen) { |
|
indexOf = cacheIndexOf; |
|
isCommon = false; |
|
} else { |
|
seen = iteratee ? [] : result; |
|
} |
|
outer: |
|
while (++index < length) { |
|
var value = array[index], |
|
computed = iteratee ? iteratee(value) : value; |
|
|
|
if (isCommon && computed === computed) { |
|
var seenIndex = seen.length; |
|
while (seenIndex--) { |
|
if (seen[seenIndex] === computed) { |
|
continue outer; |
|
} |
|
} |
|
if (iteratee) { |
|
seen.push(computed); |
|
} |
|
result.push(value); |
|
} |
|
else if (indexOf(seen, computed, 0) < 0) { |
|
if (seen !== result) { |
|
seen.push(computed); |
|
} |
|
result.push(value); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.uniq`. |
|
* |
|
* @private |
|
* @param {Array} array The array to inspect. |
|
* @param {Function} [iteratee] The function invoked per iteration. |
|
* @returns {Array} Returns the new duplicate free array. |
|
*/ |
|
function baseUniq(array) { |
|
return baseUniqBy(array); |
|
} |
|
|
|
/** |
|
* Creates an array of unique values, in order, from all of the provided arrays |
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to inspect. |
|
* @returns {Array} Returns the new array of combined values. |
|
* @example |
|
* |
|
* _.union([2, 1], [4, 2], [1, 2]); |
|
* // => [2, 1, 4] |
|
*/ |
|
var union = rest(function(arrays) { |
|
return baseUniq(baseFlatten(arrays, false, true)); |
|
}); |
|
|
|
/** |
|
* This method is like `_.union` except that it accepts `iteratee` which is |
|
* invoked for each element of each `arrays` to generate the criterion by which |
|
* uniqueness is computed. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to inspect. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Array} Returns the new array of combined values. |
|
* @example |
|
* |
|
* _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor); |
|
* // => [2.1, 1.2, 4.3] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); |
|
* // => [{ 'x': 1 }, { 'x': 2 }] |
|
*/ |
|
var unionBy = rest(function(arrays) { |
|
var iteratee = last(arrays); |
|
if (isArrayLikeObject(iteratee)) { |
|
iteratee = undefined; |
|
} |
|
return baseUniqBy(baseFlatten(arrays, false, true), baseIteratee(iteratee)); |
|
}); |
|
|
|
/** |
|
* Creates a duplicate-free version of an array, using |
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons, in which only the first occurrence of each element |
|
* is kept. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to inspect. |
|
* @returns {Array} Returns the new duplicate free array. |
|
* @example |
|
* |
|
* _.uniq([2, 1, 2]); |
|
* // => [2, 1] |
|
*/ |
|
function uniq(array) { |
|
return (array && array.length) |
|
? baseUniq(array) |
|
: []; |
|
} |
|
|
|
/** |
|
* This method is like `_.uniq` except that it accepts `iteratee` which is |
|
* invoked for each element in `array` to generate the criterion by which |
|
* uniqueness is computed. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to inspect. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Array} Returns the new duplicate free array. |
|
* @example |
|
* |
|
* _.uniqBy([2.1, 1.2, 2.3], Math.floor); |
|
* // => [2.1, 1.2] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); |
|
* // => [{ 'x': 1 }, { 'x': 2 }] |
|
*/ |
|
function uniqBy(array, iteratee) { |
|
return (array && array.length) |
|
? baseUniqBy(array, baseIteratee(iteratee)) |
|
: []; |
|
} |
|
|
|
/** Used to generate unique IDs. */ |
|
var idCounter = 0; |
|
|
|
/** |
|
* Generates a unique ID. If `prefix` is provided the ID is appended to it. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Utility |
|
* @param {string} [prefix] The value to prefix the ID with. |
|
* @returns {string} Returns the unique ID. |
|
* @example |
|
* |
|
* _.uniqueId('contact_'); |
|
* // => 'contact_104' |
|
* |
|
* _.uniqueId(); |
|
* // => '105' |
|
*/ |
|
function uniqueId(prefix) { |
|
var id = ++idCounter; |
|
return toString(prefix) + id; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.unset`. |
|
* |
|
* @private |
|
* @param {Object} object The object to modify. |
|
* @param {Array|string} path The path of the property to unset. |
|
* @returns {boolean} Returns `true` if the property is deleted, else `false`. |
|
*/ |
|
function baseUnset(object, path) { |
|
path = isKey(path, object) ? [path + ''] : baseToPath(path); |
|
object = parent$1(object, path); |
|
var key = last(path); |
|
return (object != null && has(object, key)) ? delete object[key] : true; |
|
} |
|
|
|
/** |
|
* Removes the property at `path` of `object`. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to modify. |
|
* @param {Array|string} path The path of the property to unset. |
|
* @returns {boolean} Returns `true` if the property is deleted, else `false`. |
|
* @example |
|
* |
|
* var object = { 'a': [{ 'b': { 'c': 7 } }] }; |
|
* _.unset(object, 'a[0].b.c'); |
|
* // => true |
|
* |
|
* console.log(object); |
|
* // => { 'a': [{ 'b': {} }] }; |
|
* |
|
* _.unset(object, 'a[0].b.c'); |
|
* // => true |
|
* |
|
* console.log(object); |
|
* // => { 'a': [{ 'b': {} }] }; |
|
*/ |
|
function unset(object, path) { |
|
return object == null ? true : baseUnset(object, path); |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$8 = Math.max; |
|
|
|
/** |
|
* This method is like `_.zip` except that it accepts an array of grouped |
|
* elements and creates an array regrouping the elements to their pre-zip |
|
* configuration. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array of grouped elements to process. |
|
* @returns {Array} Returns the new array of regrouped elements. |
|
* @example |
|
* |
|
* var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]); |
|
* // => [['fred', 30, true], ['barney', 40, false]] |
|
* |
|
* _.unzip(zipped); |
|
* // => [['fred', 'barney'], [30, 40], [true, false]] |
|
*/ |
|
function unzip(array) { |
|
if (!(array && array.length)) { |
|
return []; |
|
} |
|
var length = 0; |
|
array = arrayFilter(array, function(group) { |
|
if (isArrayLikeObject(group)) { |
|
length = nativeMax$8(group.length, length); |
|
return true; |
|
} |
|
}); |
|
return baseTimes(length, function(index) { |
|
return arrayMap(array, baseProperty(index)); |
|
}); |
|
} |
|
|
|
/** |
|
* This method is like `_.unzip` except that it accepts `iteratee` to specify |
|
* how regrouped values should be combined. The iteratee is invoked with four |
|
* arguments: (accumulator, value, index, group). The first element of each |
|
* group is used as the initial `accumulator` value. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array of grouped elements to process. |
|
* @param {Function} [iteratee=_.identity] The function to combine regrouped values. |
|
* @returns {Array} Returns the new array of regrouped elements. |
|
* @example |
|
* |
|
* var zipped = _.zip([1, 2], [10, 20], [100, 200]); |
|
* // => [[1, 10, 100], [2, 20, 200]] |
|
* |
|
* _.unzipWith(zipped, _.add); |
|
* // => [3, 30, 300] |
|
*/ |
|
function unzipWith(array, iteratee) { |
|
if (!(array && array.length)) { |
|
return []; |
|
} |
|
var result = unzip(array); |
|
if (iteratee == null) { |
|
return result; |
|
} |
|
return arrayMap(result, function(group) { |
|
return arrayReduce(group, iteratee, undefined, true); |
|
}); |
|
} |
|
|
|
/** |
|
* Converts `string`, as space separated words, to upper case. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category String |
|
* @param {string} [string=''] The string to convert. |
|
* @returns {string} Returns the upper cased string. |
|
* @example |
|
* |
|
* _.upperCase('--foo-bar'); |
|
* // => 'FOO BAR' |
|
* |
|
* _.upperCase('fooBar'); |
|
* // => 'FOO BAR' |
|
* |
|
* _.upperCase('__foo_bar__'); |
|
* // => 'FOO BAR' |
|
*/ |
|
var upperCase = createCompounder(function(result, word, index) { |
|
return result + (index ? ' ' : '') + word.toUpperCase(); |
|
}); |
|
|
|
/** |
|
* The base implementation of `wrapperValue` which returns the result of |
|
* performing a sequence of actions on the unwrapped `value`, where each |
|
* successive action is supplied the return value of the previous. |
|
* |
|
* @private |
|
* @param {*} value The unwrapped value. |
|
* @param {Array} actions Actions to peform to resolve the unwrapped value. |
|
* @returns {*} Returns the resolved value. |
|
*/ |
|
function baseWrapperValue(value, actions) { |
|
var result = value; |
|
if (result instanceof LazyWrapper) { |
|
result = result.value(); |
|
} |
|
return arrayReduce(actions, function(result, action) { |
|
return action.func.apply(action.thisArg, arrayPush([result], action.args)); |
|
}, result); |
|
} |
|
|
|
/** |
|
* Executes the chained sequence to extract the unwrapped value. |
|
* |
|
* @name value |
|
* @memberOf _ |
|
* @alias run, toJSON, valueOf |
|
* @category Chain |
|
* @returns {*} Returns the resolved unwrapped value. |
|
* @example |
|
* |
|
* _([1, 2, 3]).value(); |
|
* // => [1, 2, 3] |
|
*/ |
|
function wrapperValue() { |
|
return baseWrapperValue(this.__wrapped__, this.__actions__); |
|
} |
|
|
|
/** |
|
* Creates an array of the own and inherited enumerable property values |
|
* of `object`. |
|
* |
|
* **Note:** Non-object values are coerced to objects. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Object |
|
* @param {Object} object The object to query. |
|
* @returns {Array} Returns the array of property values. |
|
* @example |
|
* |
|
* function Foo() { |
|
* this.a = 1; |
|
* this.b = 2; |
|
* } |
|
* |
|
* Foo.prototype.c = 3; |
|
* |
|
* _.valuesIn(new Foo); |
|
* // => [1, 2, 3] (iteration order is not guaranteed) |
|
*/ |
|
function valuesIn(object) { |
|
return object == null ? baseValues(object, keysIn(object)) : []; |
|
} |
|
|
|
/** |
|
* Creates an array excluding all provided values using |
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) |
|
* for equality comparisons. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {Array} array The array to filter. |
|
* @param {...*} [values] The values to exclude. |
|
* @returns {Array} Returns the new array of filtered values. |
|
* @example |
|
* |
|
* _.without([1, 2, 1, 3], 1, 2); |
|
* // => [3] |
|
*/ |
|
var without = rest(function(array, values) { |
|
return isArrayLikeObject(array) |
|
? baseDifference(array, values) |
|
: []; |
|
}); |
|
|
|
/** |
|
* Creates a function that provides `value` to the wrapper function as its |
|
* first argument. Any additional arguments provided to the function are |
|
* appended to those provided to the wrapper function. The wrapper is invoked |
|
* with the `this` binding of the created function. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Function |
|
* @param {*} value The value to wrap. |
|
* @param {Function} wrapper The wrapper function. |
|
* @returns {Function} Returns the new function. |
|
* @example |
|
* |
|
* var p = _.wrap(_.escape, function(func, text) { |
|
* return '<p>' + func(text) + '</p>'; |
|
* }); |
|
* |
|
* p('fred, barney, & pebbles'); |
|
* // => '<p>fred, barney, & pebbles</p>' |
|
*/ |
|
function wrap(value, wrapper) { |
|
wrapper = wrapper == null ? identity : wrapper; |
|
return partial(wrapper, value); |
|
} |
|
|
|
/** |
|
* Enables explicit method chaining on the wrapper object. |
|
* |
|
* @name chain |
|
* @memberOf _ |
|
* @category Chain |
|
* @returns {Object} Returns the new `lodash` wrapper instance. |
|
* @example |
|
* |
|
* var users = [ |
|
* { 'user': 'barney', 'age': 36 }, |
|
* { 'user': 'fred', 'age': 40 } |
|
* ]; |
|
* |
|
* // without explicit chaining |
|
* _(users).head(); |
|
* // => { 'user': 'barney', 'age': 36 } |
|
* |
|
* // with explicit chaining |
|
* _(users) |
|
* .chain() |
|
* .head() |
|
* .pick('user') |
|
* .value(); |
|
* // => { 'user': 'barney' } |
|
*/ |
|
function wrapperChain() { |
|
return chain(this); |
|
} |
|
|
|
/** |
|
* The base implementation of `_.xorBy` without support for callback shorthands. |
|
* |
|
* @private |
|
* @param {Array} arrays The arrays to inspect. |
|
* @param {Function} [iteratee] The function invoked per element. |
|
* @returns {Array} Returns the new array of values. |
|
*/ |
|
function baseXorBy(arrays, iteratee) { |
|
var index = -1, |
|
length = arrays.length; |
|
|
|
while (++index < length) { |
|
var result = result |
|
? arrayPush(baseDifferenceBy(result, arrays[index], iteratee), baseDifferenceBy(arrays[index], result, iteratee)) |
|
: arrays[index]; |
|
} |
|
return (result && result.length) ? baseUniqBy(result, iteratee) : []; |
|
} |
|
|
|
/** |
|
* The base implementation of `_.xor` that accepts an array of arrays to inspect. |
|
* |
|
* @private |
|
* @param {Array} arrays The arrays to inspect. |
|
* @returns {Array} Returns the new array of values. |
|
*/ |
|
function baseXor(arrays) { |
|
return baseXorBy(arrays); |
|
} |
|
|
|
/** |
|
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) |
|
* of the provided arrays. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to inspect. |
|
* @returns {Array} Returns the new array of values. |
|
* @example |
|
* |
|
* _.xor([2, 1], [4, 2]); |
|
* // => [1, 4] |
|
*/ |
|
var xor = rest(function(arrays) { |
|
return baseXor(arrayFilter(arrays, isArrayLikeObject)); |
|
}); |
|
|
|
/** |
|
* This method is like `_.xor` except that it accepts `iteratee` which is |
|
* invoked for each element of each `arrays` to generate the criterion by which |
|
* uniqueness is computed. The iteratee is invoked with one argument: (value). |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to inspect. |
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per element. |
|
* @returns {Array} Returns the new array of values. |
|
* @example |
|
* |
|
* _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor); |
|
* // => [1.2, 4.3] |
|
* |
|
* // using the `_.property` callback shorthand |
|
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); |
|
* // => [{ 'x': 2 }] |
|
*/ |
|
var xorBy = rest(function(arrays) { |
|
var iteratee = last(arrays); |
|
if (isArrayLikeObject(iteratee)) { |
|
iteratee = undefined; |
|
} |
|
return baseXorBy(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee)); |
|
}); |
|
|
|
/** |
|
* Creates an array of grouped elements, the first of which contains the first |
|
* elements of the given arrays, the second of which contains the second elements |
|
* of the given arrays, and so on. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to process. |
|
* @returns {Array} Returns the new array of grouped elements. |
|
* @example |
|
* |
|
* _.zip(['fred', 'barney'], [30, 40], [true, false]); |
|
* // => [['fred', 30, true], ['barney', 40, false]] |
|
*/ |
|
var zip = rest(unzip); |
|
|
|
/** |
|
* This method is like `_.zip` except that it accepts `iteratee` to specify |
|
* how grouped values should be combined. The iteratee is invoked with four |
|
* arguments: (accumulator, value, index, group). The first element of each |
|
* group is used as the initial `accumulator` value. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @category Array |
|
* @param {...Array} [arrays] The arrays to process. |
|
* @param {Function} [iteratee=_.identity] The function to combine grouped values. |
|
* @returns {Array} Returns the new array of grouped elements. |
|
* @example |
|
* |
|
* _.zipWith([1, 2], [10, 20], [100, 200], _.add); |
|
* // => [111, 222] |
|
*/ |
|
var zipWith = rest(function(arrays) { |
|
var length = arrays.length, |
|
iteratee = length > 1 ? arrays[length - 1] : undefined; |
|
|
|
iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined; |
|
return unzipWith(arrays, iteratee); |
|
}); |
|
|
|
var func$1 = { |
|
after, ary, before, bind, bindAll, |
|
bindKey, curry, curryRight, debounce, defer, |
|
delay, flip, memoize, modArgs, modArgsSet, |
|
negate, once, partial, partialRight, rearg, |
|
rest, spread, throttle, wrap |
|
}; |
|
|
|
var object$1 = { |
|
assign, assignWith, create, defaults, defaultsDeep, |
|
extend, extendWith, findKey, findLastKey, forIn, |
|
forInRight, forOwn, forOwnRight, functions, get, |
|
has, hasIn, invert, keys, keysIn, |
|
mapKeys, mapValues, merge, mergeWith, omit, |
|
omitBy, pairs, pick, pickBy, result: result$1, |
|
set, setWith, transform, unset, values, |
|
valuesIn |
|
}; |
|
|
|
var collection = { |
|
at, countBy, each: forEach, eachRight: forEachRight, every, |
|
filter, find, findLast, forEach, forEachRight, |
|
groupBy, includes, invoke, keyBy, map, |
|
partition, reduce, reduceRight, reject, sample, |
|
sampleSize, shuffle, size: size$1, some, sortBy, |
|
sortByOrder |
|
}; |
|
|
|
/** |
|
* Reverses the wrapped array so that the first element becomes the last, |
|
* the second element becomes the second to last, and so on. |
|
* |
|
* **Note:** This method mutates the wrapped array. |
|
* |
|
* @name reverse |
|
* @memberOf _ |
|
* @category Chain |
|
* @returns {Object} Returns the new reversed `lodash` wrapper instance. |
|
* @example |
|
* |
|
* var array = [1, 2, 3]; |
|
* |
|
* _(array).reverse().value() |
|
* // => [3, 2, 1] |
|
* |
|
* console.log(array); |
|
* // => [3, 2, 1] |
|
*/ |
|
function wrapperReverse() { |
|
var value = this.__wrapped__; |
|
if (value instanceof LazyWrapper) { |
|
var wrapped = value; |
|
if (this.__actions__.length) { |
|
wrapped = new LazyWrapper(this); |
|
} |
|
wrapped = wrapped.reverse(); |
|
wrapped.__actions__.push({ 'func': thru, 'args': [reverse], 'thisArg': undefined }); |
|
return new LodashWrapper(wrapped, this.__chain__); |
|
} |
|
return this.thru(reverse); |
|
} |
|
|
|
var chain$1 = { |
|
chain, commit: wrapperCommit, concat: wrapperConcat, lodash, next: wrapperNext, |
|
plant: wrapperPlant, reverse: wrapperReverse, run: wrapperValue, tap, thru, |
|
toIterator: wrapperToIterator, toJSON: wrapperValue, value: wrapperValue, valueOf: wrapperValue, wrapperChain |
|
}; |
|
|
|
var array$1 = { |
|
chunk, compact, difference, differenceBy, drop, |
|
dropRight, dropRightWhile, dropWhile, fill, findIndex, |
|
findLastIndex, flatten, flattenDeep, head, indexOf: indexOf$1, |
|
initial, intersection, intersectionBy, last, lastIndexOf, |
|
pull, pullAll, pullAllBy, pullAt, remove, |
|
reverse, slice, sortedIndex, sortedIndexBy, sortedIndexOf, |
|
sortedLastIndex, sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy, |
|
tail, take, takeRight, takeRightWhile, takeWhile, |
|
union, unionBy, uniq, uniqBy, unzip, |
|
unzipWith, without, xor, xorBy, zip, |
|
zipObject, zipWith |
|
}; |
|
|
|
var utility = { |
|
attempt, conforms, conj, constant, disj, |
|
flow, flowRight, identity, iteratee: iteratee$1, juxt, |
|
matches, matchesProperty, method, methodOf, mixin, |
|
noop, nthArg, property, propertyOf, range, |
|
times, toPath, uniqueId |
|
}; |
|
|
|
var lang = { |
|
clone, cloneDeep, cloneDeepWith, cloneWith, eq, |
|
gt, gte, isArguments, isArray, isArrayLike, |
|
isArrayLikeObject, isBoolean, isDate, isElement, isEmpty, |
|
isEqual, isEqualWith, isError, isFinite, isFunction, |
|
isInteger, isMatch, isMatchWith, isNaN, isNative, |
|
isNil: isNil$1, isNull, isNumber, isObject, isObjectLike, |
|
isPlainObject, isRegExp, isSafeInteger, isString, isTypedArray, |
|
isUndefined, lt, lte, toArray, toInteger, |
|
toPlainObject, toSafeInteger, toString |
|
}; |
|
|
|
var string = { |
|
camelCase, capitalize, deburr, endsWith, escape, |
|
escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, |
|
padLeft, padRight, parseInt, repeat, snakeCase, |
|
startCase, startsWith, template, templateSettings, toLower, |
|
toUpper, trim, trimLeft, trimRight, trunc, |
|
unescape, upperCase, upperFirst, words |
|
}; |
|
|
|
var math = { |
|
add, ceil, floor, max, maxBy, |
|
min, minBy, round, sum, sumBy |
|
}; |
|
|
|
var number = { |
|
clamp, inRange, random |
|
}; |
|
|
|
var date = { |
|
now |
|
}; |
|
|
|
/** |
|
* Creates a clone of the lazy wrapper object. |
|
* |
|
* @private |
|
* @name clone |
|
* @memberOf LazyWrapper |
|
* @returns {Object} Returns the cloned `LazyWrapper` object. |
|
*/ |
|
function lazyClone() { |
|
var result = new LazyWrapper(this.__wrapped__); |
|
result.__actions__ = copyArray(this.__actions__); |
|
result.__dir__ = this.__dir__; |
|
result.__filtered__ = this.__filtered__; |
|
result.__iteratees__ = copyArray(this.__iteratees__); |
|
result.__takeCount__ = this.__takeCount__; |
|
result.__views__ = copyArray(this.__views__); |
|
return result; |
|
} |
|
|
|
/** |
|
* Reverses the direction of lazy iteration. |
|
* |
|
* @private |
|
* @name reverse |
|
* @memberOf LazyWrapper |
|
* @returns {Object} Returns the new reversed `LazyWrapper` object. |
|
*/ |
|
function lazyReverse() { |
|
if (this.__filtered__) { |
|
var result = new LazyWrapper(this); |
|
result.__dir__ = -1; |
|
result.__filtered__ = true; |
|
} else { |
|
result = this.clone(); |
|
result.__dir__ *= -1; |
|
} |
|
return result; |
|
} |
|
|
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMax$14 = Math.max; |
|
var nativeMin$10 = Math.min; |
|
/** |
|
* 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. |
|
* @param {Array} transforms The transformations to apply to the view. |
|
* @returns {Object} Returns an object containing the `start` and `end` |
|
* positions of the view. |
|
*/ |
|
function getView(start, end, transforms) { |
|
var index = -1, |
|
length = transforms.length; |
|
|
|
while (++index < length) { |
|
var data = transforms[index], |
|
size = data.size; |
|
|
|
switch (data.type) { |
|
case 'drop': start += size; break; |
|
case 'dropRight': end -= size; break; |
|
case 'take': end = nativeMin$10(end, start + size); break; |
|
case 'takeRight': start = nativeMax$14(start, end - size); break; |
|
} |
|
} |
|
return { 'start': start, 'end': end }; |
|
} |
|
|
|
/** Used as the size to enable large array optimizations. */ |
|
var LARGE_ARRAY_SIZE$3 = 200; |
|
|
|
/** Used to indicate the type of lazy iteratees. */ |
|
var LAZY_FILTER_FLAG = 1; |
|
var LAZY_MAP_FLAG$1 = 2; |
|
/* Built-in method references for those with the same name as other `lodash` methods. */ |
|
var nativeMin$7 = Math.min; |
|
|
|
/** |
|
* Extracts the unwrapped value from its lazy wrapper. |
|
* |
|
* @private |
|
* @name value |
|
* @memberOf LazyWrapper |
|
* @returns {*} Returns the unwrapped value. |
|
*/ |
|
function lazyValue() { |
|
var array = this.__wrapped__.value(), |
|
dir = this.__dir__, |
|
isArr = isArray(array), |
|
isRight = dir < 0, |
|
arrLength = isArr ? array.length : 0, |
|
view = getView(0, arrLength, this.__views__), |
|
start = view.start, |
|
end = view.end, |
|
length = end - start, |
|
index = isRight ? end : (start - 1), |
|
iteratees = this.__iteratees__, |
|
iterLength = iteratees.length, |
|
resIndex = 0, |
|
takeCount = nativeMin$7(length, this.__takeCount__); |
|
|
|
if (!isArr || arrLength < LARGE_ARRAY_SIZE$3 || (arrLength == length && takeCount == length)) { |
|
return baseWrapperValue(array, this.__actions__); |
|
} |
|
var result = []; |
|
|
|
outer: |
|
while (length-- && resIndex < takeCount) { |
|
index += dir; |
|
|
|
var iterIndex = -1, |
|
value = array[index]; |
|
|
|
while (++iterIndex < iterLength) { |
|
var data = iteratees[iterIndex], |
|
iteratee = data.iteratee, |
|
type = data.type, |
|
computed = iteratee(value); |
|
|
|
if (type == LAZY_MAP_FLAG$1) { |
|
value = computed; |
|
} else if (!computed) { |
|
if (type == LAZY_FILTER_FLAG) { |
|
continue outer; |
|
} else { |
|
break outer; |
|
} |
|
} |
|
} |
|
result[resIndex++] = value; |
|
} |
|
return result; |
|
} |
|
|
|
/** Used as the semantic version number. */ |
|
var VERSION = '4.0.0-pre'; |
|
|
|
/** Used to compose bitmasks for wrapper metadata. */ |
|
var BIND_KEY_FLAG$1 = 2; |
|
|
|
/** Used to indicate the type of lazy iteratees. */ |
|
var LAZY_MAP_FLAG = 2; |
|
|
|
/** Used as references for the maximum length and index of an array. */ |
|
var MAX_ARRAY_LENGTH$2 = 4294967295; |
|
|
|
/** Used for built-in method references. */ |
|
var arrayProto$1 = Array.prototype; |
|
var objectProto$16 = Object.prototype; |
|
var stringProto = String.prototype; |
|
/** Used to check objects for own properties. */ |
|
var hasOwnProperty$7 = objectProto$16.hasOwnProperty; |
|
|
|
/** Built-in value references. */ |
|
var Symbol$1 = root.Symbol; |
|
var iteratorSymbol$1 = typeof (iteratorSymbol$1 = Symbol$1 && Symbol$1.iterator) == 'symbol' ? iteratorSymbol$1 : undefined; |
|
var nativeMax$9 = Math.max; |
|
var nativeMin$4 = Math.min; |
|
// wrap `_.mixin` so it works when provided only one argument |
|
var mixin$1 = (function(func) { |
|
return function(object, source, options) { |
|
if (options == null) { |
|
var isObj = isObject(source), |
|
props = isObj && keys(source), |
|
methodNames = props && props.length && baseFunctions(source, props); |
|
|
|
if (!(methodNames ? methodNames.length : isObj)) { |
|
options = source; |
|
source = object; |
|
object = this; |
|
} |
|
} |
|
return func(object, source, options); |
|
}; |
|
}(mixin)); |
|
|
|
// Add functions that return wrapped values when chaining. |
|
lodash.after = func$1.after; |
|
lodash.ary = func$1.ary; |
|
lodash.assign = object$1.assign; |
|
lodash.assignWith = object$1.assignWith; |
|
lodash.at = collection.at; |
|
lodash.before = func$1.before; |
|
lodash.bind = func$1.bind; |
|
lodash.bindAll = func$1.bindAll; |
|
lodash.bindKey = func$1.bindKey; |
|
lodash.chain = chain$1.chain; |
|
lodash.chunk = array$1.chunk; |
|
lodash.compact = array$1.compact; |
|
lodash.conforms = utility.conforms; |
|
lodash.conj = utility.conj; |
|
lodash.constant = utility.constant; |
|
lodash.countBy = collection.countBy; |
|
lodash.create = object$1.create; |
|
lodash.curry = func$1.curry; |
|
lodash.curryRight = func$1.curryRight; |
|
lodash.debounce = func$1.debounce; |
|
lodash.defaults = object$1.defaults; |
|
lodash.defaultsDeep = object$1.defaultsDeep; |
|
lodash.defer = func$1.defer; |
|
lodash.delay = func$1.delay; |
|
lodash.difference = array$1.difference; |
|
lodash.differenceBy = array$1.differenceBy; |
|
lodash.disj = utility.disj; |
|
lodash.drop = array$1.drop; |
|
lodash.dropRight = array$1.dropRight; |
|
lodash.dropRightWhile = array$1.dropRightWhile; |
|
lodash.dropWhile = array$1.dropWhile; |
|
lodash.extend = object$1.extend; |
|
lodash.extendWith = object$1.extendWith; |
|
lodash.fill = array$1.fill; |
|
lodash.filter = collection.filter; |
|
lodash.flatten = array$1.flatten; |
|
lodash.flattenDeep = array$1.flattenDeep; |
|
lodash.flip = func$1.flip; |
|
lodash.flow = utility.flow; |
|
lodash.flowRight = utility.flowRight; |
|
lodash.functions = object$1.functions; |
|
lodash.groupBy = collection.groupBy; |
|
lodash.initial = array$1.initial; |
|
lodash.intersection = array$1.intersection; |
|
lodash.intersectionBy = array$1.intersectionBy; |
|
lodash.invert = object$1.invert; |
|
lodash.invoke = collection.invoke; |
|
lodash.iteratee = utility.iteratee; |
|
lodash.juxt = utility.juxt; |
|
lodash.keyBy = collection.keyBy; |
|
lodash.keys = keys; |
|
lodash.keysIn = object$1.keysIn; |
|
lodash.map = collection.map; |
|
lodash.mapKeys = object$1.mapKeys; |
|
lodash.mapValues = object$1.mapValues; |
|
lodash.matches = utility.matches; |
|
lodash.matchesProperty = utility.matchesProperty; |
|
lodash.memoize = func$1.memoize; |
|
lodash.merge = object$1.merge; |
|
lodash.mergeWith = object$1.mergeWith; |
|
lodash.method = utility.method; |
|
lodash.methodOf = utility.methodOf; |
|
lodash.mixin = mixin$1; |
|
lodash.modArgs = func$1.modArgs; |
|
lodash.modArgsSet = func$1.modArgsSet; |
|
lodash.negate = func$1.negate; |
|
lodash.nthArg = utility.nthArg; |
|
lodash.omit = object$1.omit; |
|
lodash.omitBy = object$1.omitBy; |
|
lodash.once = func$1.once; |
|
lodash.pairs = object$1.pairs; |
|
lodash.partial = func$1.partial; |
|
lodash.partialRight = func$1.partialRight; |
|
lodash.partition = collection.partition; |
|
lodash.pick = object$1.pick; |
|
lodash.pickBy = object$1.pickBy; |
|
lodash.property = utility.property; |
|
lodash.propertyOf = utility.propertyOf; |
|
lodash.pull = array$1.pull; |
|
lodash.pullAll = array$1.pullAll; |
|
lodash.pullAllBy = array$1.pullAllBy; |
|
lodash.pullAt = array$1.pullAt; |
|
lodash.range = utility.range; |
|
lodash.rearg = func$1.rearg; |
|
lodash.reject = collection.reject; |
|
lodash.remove = array$1.remove; |
|
lodash.rest = func$1.rest; |
|
lodash.reverse = array$1.reverse; |
|
lodash.sampleSize = collection.sampleSize; |
|
lodash.set = object$1.set; |
|
lodash.setWith = object$1.setWith; |
|
lodash.shuffle = collection.shuffle; |
|
lodash.slice = array$1.slice; |
|
lodash.sortBy = collection.sortBy; |
|
lodash.sortByOrder = collection.sortByOrder; |
|
lodash.sortedUniq = array$1.sortedUniq; |
|
lodash.sortedUniqBy = array$1.sortedUniqBy; |
|
lodash.spread = func$1.spread; |
|
lodash.tail = array$1.tail; |
|
lodash.take = array$1.take; |
|
lodash.takeRight = array$1.takeRight; |
|
lodash.takeRightWhile = array$1.takeRightWhile; |
|
lodash.takeWhile = array$1.takeWhile; |
|
lodash.tap = chain$1.tap; |
|
lodash.throttle = func$1.throttle; |
|
lodash.thru = thru; |
|
lodash.times = utility.times; |
|
lodash.toArray = lang.toArray; |
|
lodash.toPath = utility.toPath; |
|
lodash.toPlainObject = lang.toPlainObject; |
|
lodash.transform = object$1.transform; |
|
lodash.union = array$1.union; |
|
lodash.unionBy = array$1.unionBy; |
|
lodash.uniq = array$1.uniq; |
|
lodash.uniqBy = array$1.uniqBy; |
|
lodash.unset = object$1.unset; |
|
lodash.unzip = array$1.unzip; |
|
lodash.unzipWith = array$1.unzipWith; |
|
lodash.values = object$1.values; |
|
lodash.valuesIn = object$1.valuesIn; |
|
lodash.without = array$1.without; |
|
lodash.words = string.words; |
|
lodash.wrap = func$1.wrap; |
|
lodash.xor = array$1.xor; |
|
lodash.xorBy = array$1.xorBy; |
|
lodash.zip = array$1.zip; |
|
lodash.zipObject = array$1.zipObject; |
|
lodash.zipWith = array$1.zipWith; |
|
|
|
// Add aliases. |
|
lodash.each = collection.forEach; |
|
lodash.eachRight = collection.forEachRight; |
|
|
|
// Add functions to `lodash.prototype`. |
|
mixin$1(lodash, lodash); |
|
|
|
// Add functions that return unwrapped values when chaining. |
|
lodash.add = math.add; |
|
lodash.attempt = utility.attempt; |
|
lodash.camelCase = string.camelCase; |
|
lodash.capitalize = string.capitalize; |
|
lodash.ceil = math.ceil; |
|
lodash.clamp = number.clamp; |
|
lodash.clone = lang.clone; |
|
lodash.cloneDeep = lang.cloneDeep; |
|
lodash.cloneDeepWith = lang.cloneDeepWith; |
|
lodash.cloneWith = lang.cloneWith; |
|
lodash.deburr = string.deburr; |
|
lodash.endsWith = string.endsWith; |
|
lodash.eq = lang.eq; |
|
lodash.escape = string.escape; |
|
lodash.escapeRegExp = string.escapeRegExp; |
|
lodash.every = collection.every; |
|
lodash.find = collection.find; |
|
lodash.findIndex = array$1.findIndex; |
|
lodash.findKey = object$1.findKey; |
|
lodash.findLast = collection.findLast; |
|
lodash.findLastIndex = array$1.findLastIndex; |
|
lodash.findLastKey = object$1.findLastKey; |
|
lodash.floor = math.floor; |
|
lodash.forEach = collection.forEach; |
|
lodash.forEachRight = collection.forEachRight; |
|
lodash.forIn = object$1.forIn; |
|
lodash.forInRight = object$1.forInRight; |
|
lodash.forOwn = object$1.forOwn; |
|
lodash.forOwnRight = object$1.forOwnRight; |
|
lodash.get = object$1.get; |
|
lodash.gt = lang.gt; |
|
lodash.gte = lang.gte; |
|
lodash.has = object$1.has; |
|
lodash.hasIn = object$1.hasIn; |
|
lodash.head = array$1.head; |
|
lodash.identity = identity; |
|
lodash.includes = collection.includes; |
|
lodash.indexOf = array$1.indexOf; |
|
lodash.inRange = number.inRange; |
|
lodash.isArguments = lang.isArguments; |
|
lodash.isArray = isArray; |
|
lodash.isArrayLike = lang.isArrayLike; |
|
lodash.isArrayLikeObject = lang.isArrayLikeObject; |
|
lodash.isBoolean = lang.isBoolean; |
|
lodash.isDate = lang.isDate; |
|
lodash.isElement = lang.isElement; |
|
lodash.isEmpty = lang.isEmpty; |
|
lodash.isEqual = lang.isEqual; |
|
lodash.isEqualWith = lang.isEqualWith; |
|
lodash.isError = lang.isError; |
|
lodash.isFinite = lang.isFinite; |
|
lodash.isFunction = lang.isFunction; |
|
lodash.isInteger = lang.isInteger; |
|
lodash.isMatch = lang.isMatch; |
|
lodash.isMatchWith = lang.isMatchWith; |
|
lodash.isNaN = lang.isNaN; |
|
lodash.isNative = lang.isNative; |
|
lodash.isNil = lang.isNil; |
|
lodash.isNull = lang.isNull; |
|
lodash.isNumber = lang.isNumber; |
|
lodash.isObject = isObject; |
|
lodash.isObjectLike = lang.isObjectLike; |
|
lodash.isPlainObject = lang.isPlainObject; |
|
lodash.isRegExp = lang.isRegExp; |
|
lodash.isSafeInteger = lang.isSafeInteger; |
|
lodash.isString = lang.isString; |
|
lodash.isTypedArray = lang.isTypedArray; |
|
lodash.isUndefined = lang.isUndefined; |
|
lodash.kebabCase = string.kebabCase; |
|
lodash.last = last; |
|
lodash.lastIndexOf = array$1.lastIndexOf; |
|
lodash.lowerCase = string.lowerCase; |
|
lodash.lowerFirst = string.lowerFirst; |
|
lodash.lt = lang.lt; |
|
lodash.lte = lang.lte; |
|
lodash.max = math.max; |
|
lodash.maxBy = math.maxBy; |
|
lodash.min = math.min; |
|
lodash.minBy = math.minBy; |
|
lodash.noop = utility.noop; |
|
lodash.now = date.now; |
|
lodash.pad = string.pad; |
|
lodash.padLeft = string.padLeft; |
|
lodash.padRight = string.padRight; |
|
lodash.parseInt = string.parseInt; |
|
lodash.random = number.random; |
|
lodash.reduce = collection.reduce; |
|
lodash.reduceRight = collection.reduceRight; |
|
lodash.repeat = string.repeat; |
|
lodash.result = object$1.result; |
|
lodash.round = math.round; |
|
lodash.sample = collection.sample; |
|
lodash.size = collection.size; |
|
lodash.snakeCase = string.snakeCase; |
|
lodash.some = collection.some; |
|
lodash.sortedIndex = array$1.sortedIndex; |
|
lodash.sortedIndexBy = array$1.sortedIndexBy; |
|
lodash.sortedIndexOf = array$1.sortedIndexOf; |
|
lodash.sortedLastIndex = array$1.sortedLastIndex; |
|
lodash.sortedLastIndexBy = array$1.sortedLastIndexBy; |
|
lodash.sortedLastIndexOf = array$1.sortedLastIndexOf; |
|
lodash.startCase = string.startCase; |
|
lodash.startsWith = string.startsWith; |
|
lodash.sum = math.sum; |
|
lodash.sumBy = math.sumBy; |
|
lodash.template = string.template; |
|
lodash.toInteger = toInteger; |
|
lodash.toLower = string.toLower; |
|
lodash.toSafeInteger = lang.toSafeInteger; |
|
lodash.toString = lang.toString; |
|
lodash.toUpper = string.toUpper; |
|
lodash.trim = string.trim; |
|
lodash.trimLeft = string.trimLeft; |
|
lodash.trimRight = string.trimRight; |
|
lodash.trunc = string.trunc; |
|
lodash.unescape = string.unescape; |
|
lodash.uniqueId = utility.uniqueId; |
|
lodash.upperCase = string.upperCase; |
|
lodash.upperFirst = string.upperFirst; |
|
|
|
// Add aliases. |
|
lodash.first = array$1.head; |
|
|
|
mixin$1(lodash, (function() { |
|
var source = {}; |
|
baseForOwn(lodash, function(func, methodName) { |
|
if (!hasOwnProperty$7.call(lodash.prototype, methodName)) { |
|
source[methodName] = func; |
|
} |
|
}); |
|
return source; |
|
}()), { 'chain': false }); |
|
|
|
/** |
|
* The semantic version number. |
|
* |
|
* @static |
|
* @memberOf _ |
|
* @type string |
|
*/ |
|
lodash.VERSION = VERSION; |
|
(lodash.templateSettings = string.templateSettings).imports._ = lodash; |
|
|
|
// Assign default placeholders. |
|
arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) { |
|
lodash[methodName].placeholder = lodash; |
|
}); |
|
|
|
// Add `LazyWrapper` methods for `_.drop` and `_.take` variants. |
|
arrayEach(['drop', 'take'], function(methodName, index) { |
|
LazyWrapper.prototype[methodName] = function(n) { |
|
var filtered = this.__filtered__; |
|
if (filtered && !index) { |
|
return new LazyWrapper(this); |
|
} |
|
n = n === undefined ? 1 : nativeMax$9(toInteger(n), 0); |
|
|
|
var result = this.clone(); |
|
if (filtered) { |
|
result.__takeCount__ = nativeMin$4(n, result.__takeCount__); |
|
} else { |
|
result.__views__.push({ 'size': nativeMin$4(n, MAX_ARRAY_LENGTH$2), 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') }); |
|
} |
|
return result; |
|
}; |
|
|
|
LazyWrapper.prototype[methodName + 'Right'] = function(n) { |
|
return this.reverse()[methodName](n).reverse(); |
|
}; |
|
}); |
|
|
|
// Add `LazyWrapper` methods that accept an `iteratee` value. |
|
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { |
|
var type = index + 1, |
|
isFilter = type != LAZY_MAP_FLAG; |
|
|
|
LazyWrapper.prototype[methodName] = function(iteratee) { |
|
var result = this.clone(); |
|
result.__iteratees__.push({ 'iteratee': baseIteratee(iteratee, 3), 'type': type }); |
|
result.__filtered__ = result.__filtered__ || isFilter; |
|
return result; |
|
}; |
|
}); |
|
|
|
// Add `LazyWrapper` methods for `_.head` and `_.last`. |
|
arrayEach(['head', 'last'], function(methodName, index) { |
|
var takeName = 'take' + (index ? 'Right' : ''); |
|
|
|
LazyWrapper.prototype[methodName] = function() { |
|
return this[takeName](1).value()[0]; |
|
}; |
|
}); |
|
|
|
// Add `LazyWrapper` methods for `_.initial` and `_.tail`. |
|
arrayEach(['initial', 'tail'], function(methodName, index) { |
|
var dropName = 'drop' + (index ? '' : 'Right'); |
|
|
|
LazyWrapper.prototype[methodName] = function() { |
|
return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1); |
|
}; |
|
}); |
|
|
|
LazyWrapper.prototype.compact = function() { |
|
return this.filter(identity); |
|
}; |
|
|
|
LazyWrapper.prototype.find = function(predicate) { |
|
return this.filter(predicate).head(); |
|
}; |
|
|
|
LazyWrapper.prototype.findLast = function(predicate) { |
|
return this.reverse().find(predicate); |
|
}; |
|
|
|
LazyWrapper.prototype.reject = function(predicate) { |
|
predicate = baseIteratee(predicate, 3); |
|
return this.filter(function(value) { |
|
return !predicate(value); |
|
}); |
|
}; |
|
|
|
LazyWrapper.prototype.slice = function(start, end) { |
|
start = start ? toInteger(start) : 0; |
|
|
|
var result = this; |
|
if (result.__filtered__ && (start > 0 || end < 0)) { |
|
return new LazyWrapper(result); |
|
} |
|
if (start < 0) { |
|
result = result.takeRight(-start); |
|
} else if (start) { |
|
result = result.drop(start); |
|
} |
|
if (end !== undefined) { |
|
end = toInteger(end); |
|
result = end < 0 ? result.dropRight(-end) : result.take(end - start); |
|
} |
|
return result; |
|
}; |
|
|
|
LazyWrapper.prototype.takeRightWhile = function(predicate) { |
|
return this.reverse().takeWhile(predicate).reverse(); |
|
}; |
|
|
|
LazyWrapper.prototype.toArray = function() { |
|
return this.take(MAX_ARRAY_LENGTH$2); |
|
}; |
|
|
|
// Add `LazyWrapper` methods to `lodash.prototype`. |
|
baseForOwn(LazyWrapper.prototype, function(func, methodName) { |
|
var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName), |
|
isTaker = /^(?:head|last)$/.test(methodName), |
|
retUnwrapped = isTaker || /^find/.test(methodName), |
|
lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName]; |
|
|
|
if (!lodashFunc) { |
|
return; |
|
} |
|
lodash.prototype[methodName] = function() { |
|
var args = isTaker ? [1] : arguments, |
|
value = this.__wrapped__, |
|
isLazy = value instanceof LazyWrapper, |
|
iteratee = args[0], |
|
useLazy = isLazy || isArray(value); |
|
|
|
var interceptor = function(value) { |
|
var result = lodashFunc.apply(lodash, arrayPush([value], args)); |
|
return (isTaker && chainAll) ? result[0] : result; |
|
}; |
|
|
|
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) { |
|
// Avoid lazy use if the iteratee has a "length" value other than `1`. |
|
isLazy = useLazy = false; |
|
} |
|
var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined }, |
|
chainAll = this.__chain__, |
|
isHybrid = !!this.__actions__.length, |
|
isUnwrapped = retUnwrapped && !chainAll, |
|
onlyLazy = isLazy && !isHybrid; |
|
|
|
if (!retUnwrapped && useLazy) { |
|
value = onlyLazy ? value : new LazyWrapper(this); |
|
var result = func.apply(value, args); |
|
result.__actions__.push(action); |
|
return new LodashWrapper(result, chainAll); |
|
} |
|
if (isUnwrapped && onlyLazy) { |
|
return func.apply(this, args); |
|
} |
|
result = this.thru(interceptor); |
|
return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result; |
|
}; |
|
}); |
|
|
|
// Add `Array` and `String` methods to `lodash.prototype`. |
|
arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) { |
|
var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto$1)[methodName], |
|
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', |
|
retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName); |
|
|
|
lodash.prototype[methodName] = function() { |
|
var args = arguments; |
|
if (retUnwrapped && !this.__chain__) { |
|
return func.apply(this.value(), args); |
|
} |
|
return this[chainName](function(value) { |
|
return func.apply(value, args); |
|
}); |
|
}; |
|
}); |
|
|
|
// Map minified function names to their real names. |
|
baseForOwn(LazyWrapper.prototype, function(func, methodName) { |
|
var lodashFunc = lodash[methodName]; |
|
if (lodashFunc) { |
|
var key = (lodashFunc.name + ''), |
|
names = realNames[key] || (realNames[key] = []); |
|
|
|
names.push({ 'name': methodName, 'func': lodashFunc }); |
|
} |
|
}); |
|
|
|
realNames[createHybridWrapper(undefined, BIND_KEY_FLAG$1).name] = [{ 'name': 'wrapper', 'func': undefined }]; |
|
|
|
// Add functions to the lazy wrapper. |
|
LazyWrapper.prototype.clone = lazyClone; |
|
LazyWrapper.prototype.reverse = lazyReverse; |
|
LazyWrapper.prototype.value = lazyValue; |
|
|
|
// Add chaining functions to the `lodash` wrapper. |
|
lodash.prototype.chain = chain$1.wrapperChain; |
|
lodash.prototype.commit = chain$1.commit; |
|
lodash.prototype.concat = chain$1.concat; |
|
lodash.prototype.next = chain$1.next; |
|
lodash.prototype.plant = chain$1.plant; |
|
lodash.prototype.reverse = chain$1.reverse; |
|
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = chain$1.value; |
|
|
|
if (iteratorSymbol$1) { |
|
lodash.prototype[iteratorSymbol$1] = chain$1.toIterator; |
|
} |
|
|
|
console.log(zipObject(chunk(['a', 'b', 'c', 'd'], 2))); |
|
|
|
})(); |