From 9c3f297e9776c98bb5b47be5287bf10b2b8f8192 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 5 Jul 2014 11:51:51 -0500 Subject: [PATCH] Rebuild dist. --- dist/lodash.compat.js | 1020 +++++++++++++++++++-------------- dist/lodash.compat.min.js | 132 ++--- dist/lodash.js | 990 +++++++++++++++++++------------- dist/lodash.min.js | 126 ++-- dist/lodash.underscore.js | 586 +++++++++++-------- dist/lodash.underscore.min.js | 78 +-- 6 files changed, 1707 insertions(+), 1225 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index ccddd5914..919217b30 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -121,7 +121,7 @@ /** Used to make template sourceURLs easier to identify */ var templateCounter = 0; - /** `Object#toString` result shortcuts */ + /** `Object#toString` result references */ var argsClass = '[object Arguments]', arrayClass = '[object Array]', boolClass = '[object Boolean]', @@ -201,8 +201,8 @@ * See [Mathias' article](http://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * - * Backticks are escaped because in Internet Explorer < 9, they can be used to - * break out of attribute values or HTML comments. See [#102](http://html5sec.org/#102), + * Backticks are escaped because in Internet Explorer < 9, they can break out + * of attribute values or HTML comments. See [#102](http://html5sec.org/#102), * [#108](http://html5sec.org/#108), and [#133](http://html5sec.org/#133) of * the [HTML5 Security Cheatsheet](http://html5sec.org/) for more details. */ @@ -307,8 +307,8 @@ } /** - * The base implementation of `compareAscending` used to compare values and - * sort them in ascending order without guaranteeing a stable sort. + * The base implementation of `compareAscending` which compares values and + * sorts them in ascending order without guaranteeing a stable sort. * * @private * @param {*} value The value to compare to `other`. @@ -407,7 +407,7 @@ } /** - * Used by `_.sortBy` to compare transformed elements of a collection and stable + * Used by `_.sortBy` to compare transformed elements of `collection` and stable * sort them in ascending order. * * @private @@ -630,8 +630,11 @@ /** Used to resolve the decompiled source of functions */ var fnToString = Function.prototype.toString; + /** Used as a reference for the max length of an array */ + var maxArrayLength = Math.pow(2, 32) - 1; + /** - * Used as the maximum length of an array-like object. + * Used as the maximum length of an array-like value. * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * for more details. */ @@ -649,7 +652,7 @@ .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); - /** Native method shortcuts */ + /** Native method references */ var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer, bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice, ceil = Math.ceil, @@ -677,7 +680,7 @@ return result; }()); - /* Native method shortcuts for methods with the same name as other `lodash` methods */ + /* Native method references for those with the same name as other `lodash` methods */ var nativeContains = isNative(nativeContains = stringProto.contains) && nativeContains, nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate, nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray, @@ -732,14 +735,14 @@ * implicitly or explicitly included in the build. * * The chainable wrapper functions are: - * `after`, `assign`, `at`, `bind`, `bindAll`, `bindKey`, `callback`, `chain`, - * `chunk`, `compact`, `compose`, `concat`, `constant`, `countBy`, `create`, - * `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, `drop`, - * `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, `forEach`, - * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, - * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, - * `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, `mixin`, - * `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, + * `after`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, `callback`, + * `chain`, `chunk`, `compact`, `compose`, `concat`, `constant`, `countBy`, + * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, + * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, + * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, + * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, + * `invoke`, `keys`, `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, + * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, * `partition`, `pick`, `pluck`, `property`, `pull`, `pullAt`, `push`, `range`, * `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, * `splice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, @@ -748,17 +751,18 @@ * and `zipObject` * * The non-chainable wrapper functions are: - * `camelCase`, `capitalize`, `clone`, `cloneDeep`, `contains`, `endsWith`, - * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, + * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `contains`, + * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, - * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, + * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, isDate`, * `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, `isFunction`, * `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, * `isString`, `isUndefined`, `join`, `kebabCase`, `last`, `lastIndexOf`, * `max`, `min`, `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, - * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `startsWith`, `template`, - * `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, and `value` + * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, + * `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, + * `unescape`, `uniqueId`, and `value` * * The wrapper function `sample` will return a wrapped value when `n` is * provided, otherwise it will return an unwrapped value. @@ -813,7 +817,7 @@ } /** - * An object used to flag environments features. + * An object environment feature flags. * * @static * @memberOf _ @@ -904,7 +908,7 @@ /** * Detect if own properties are iterated after inherited properties - * (all but IE < 9). + * (IE < 9). * * @memberOf _.support * @type boolean @@ -1121,7 +1125,7 @@ */ function arrayMap(array, iterator) { var index = -1, - length = array ? array.length >>> 0 : 0, + length = array ? array.length : 0, result = Array(length); while (++index < length) { @@ -1178,6 +1182,30 @@ return accumulator; } + /** + * A specialized version of `_.reduceRight` for arrays without support for + * callback shorthands or `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iterator The function called per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initFromArray=false] Specify using the first element of + * `array` as the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduceRight(array, iterator, accumulator, initFromArray) { + var length = array.length; + + if (initFromArray && length) { + accumulator = array[--length]; + } + while (length--) { + accumulator = iterator(accumulator, array[length], length, array); + } + return accumulator; + } + /** * A specialized version of `_.some` for arrays without support for callback * shorthands or `this` binding. @@ -1209,7 +1237,9 @@ * @returns {*} Returns the value to assign to the destination object. */ function assignDefaults(objectValue, sourceValue) { - return typeof objectValue == 'undefined' ? sourceValue : objectValue; + return typeof objectValue == 'undefined' + ? sourceValue + : objectValue; } /** @@ -1226,9 +1256,9 @@ * @returns {*} Returns the value to assign to the destination object. */ function assignOwnDefaults(objectValue, sourceValue, key, object) { - return (!hasOwnProperty.call(object, key) || typeof objectValue == 'undefined') + return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key)) ? sourceValue - : objectValue + : objectValue; } /** @@ -1248,7 +1278,9 @@ while (++index < length) { var key = props[index]; - object[key] = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; + object[key] = customizer + ? customizer(object[key], source[key], key, object, source) + : source[key]; } return object; } @@ -1328,78 +1360,90 @@ if (typeof result != 'undefined') { return result; } - var isObj = isObject(value); - if (isObj) { + var isArr = isArray(value), + isShallow = !isDeep; + + if (isArr) { + result = isShallow ? slice(value) : value.constructor(value.length); + + // add array properties assigned by `RegExp#exec` + if (typeof value[0] == 'string' && hasOwnProperty.call(value, 'index')) { + result.index = value.index; + result.input = value.input; + } + if (isShallow) { + return result; + } + } + else { + if (!isObject(value)) { + return value; + } var className = toString.call(value); if (!cloneableClasses[className] || (!support.nodeClass && isNode(value))) { return value; } + var isArgs = className == argsClass || (!support.argsClass && isArguments(value)), + isObj = !isArgs && className == objectClass; + + if (isShallow && (isArgs || isObj)) { + result = baseAssign({}, value); + if (isObj) { + return result; + } + } var Ctor = value.constructor; if (className == objectClass && !(isFunction(Ctor) && (Ctor instanceof Ctor))) { Ctor = Object; } - switch (className) { - case arrayBufferClass: - return cloneBuffer(value); - - case boolClass: - case dateClass: - return new Ctor(+value); - - case float32Class: case float64Class: - case int8Class: case int16Class: case int32Class: - case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class: - // Safari 5 mobile incorrectly has `Object` as the constructor - if (Ctor instanceof Ctor) { - Ctor = ctorByClass[className]; - } - return new Ctor(cloneBuffer(value.buffer)); - - case numberClass: - case stringClass: - return new Ctor(value); - - case regexpClass: - result = Ctor(value.source, reFlags.exec(value)); - result.lastIndex = value.lastIndex; - return result; + if (isDeep && (isArgs || isObj)) { + result = new Ctor; } - } else { - return value; - } - var isArr = isArray(value); - if (isDeep) { - // check for circular references and return corresponding clone - stackA || (stackA = []); - stackB || (stackB = []); + else { + switch (className) { + case arrayBufferClass: + return cloneBuffer(value); - var length = stackA.length; - while (length--) { - if (stackA[length] == value) { - return stackB[length]; + case boolClass: + case dateClass: + return new Ctor(+value); + + case float32Class: case float64Class: + case int8Class: case int16Class: case int32Class: + case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class: + // Safari 5 mobile incorrectly has `Object` as the constructor + if (Ctor instanceof Ctor) { + Ctor = ctorByClass[className]; + } + return new Ctor(cloneBuffer(value.buffer)); + + case numberClass: + case stringClass: + return new Ctor(value); + + case regexpClass: + result = Ctor(value.source, reFlags.exec(value)); + result.lastIndex = value.lastIndex; + return result; } } - result = isArr ? Ctor(value.length) : new Ctor; } - else { - result = isArr ? slice(value) : baseAssign({}, value); - } - if (className == argsClass || (!support.argsClass && isArguments(value))) { + if (isArgs) { result.length = value.length; } - // add array properties assigned by `RegExp#exec` - else if (isArr) { - if (hasOwnProperty.call(value, 'index')) { - result.index = value.index; - } - if (hasOwnProperty.call(value, 'input')) { - result.input = value.input; - } - } - // exit for shallow clone - if (!isDeep) { + if (isShallow) { return result; } + // check for circular references and return corresponding clone + stackA || (stackA = []); + stackB || (stackB = []); + + var length = stackA.length; + while (length--) { + if (stackA[length] == value) { + return stackB[length]; + } + } // add the source value to the stack of traversed objects // and associate it with its clone stackA.push(value); @@ -1448,6 +1492,17 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {number} data[1] The bitmask of flags to compose. See `createWrapper` + * for more details. + * @param {number} data[2] The arity of `data[0]`. + * @param {*} [data[3]] The `this` binding of `data[0]`. + * @param {Array} [data[4]] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [data[5]] An array of arguments to append to those + * provided to the new function. + * @param {Array} [data[6]] An array of `data[4]` placeholder indexes. + * @param {Array} [data[7]] An array of `data[5]` placeholder indexes. * @returns {Function} Returns the new function. */ function baseCreateWrapper(data) { @@ -1589,21 +1644,17 @@ * @returns {Array|Object|string} Returns `collection`. */ function baseEach(collection, iterator) { + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return baseForOwn(collection, iterator); + } var index = -1, - iterable = collection, - length = collection ? collection.length : 0; + iterable = toIterable(collection); - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - if (support.unindexedChars && isString(iterable)) { - iterable = iterable.split(''); + while (++index < length) { + if (iterator(iterable[index], index, collection) === false) { + break; } - while (++index < length) { - if (iterator(iterable[index], index, collection) === false) { - break; - } - } - } else { - baseForOwn(collection, iterator); } return collection; } @@ -1618,20 +1669,15 @@ * @returns {Array|Object|string} Returns `collection`. */ function baseEachRight(collection, iterator) { - var iterable = collection, - length = collection ? collection.length : 0; - - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - if (support.unindexedChars && isString(iterable)) { - iterable = iterable.split(''); + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return baseForOwnRight(collection, iterator); + } + var iterable = toIterable(collection); + while (length--) { + if (iterator(iterable[length], length, collection) === false) { + break; } - while (length--) { - if (iterator(iterable[length], length, collection) === false) { - break; - } - } - } else { - baseForOwnRight(collection, iterator); } return collection; } @@ -1684,7 +1730,7 @@ * @private * @param {Array|Object|string} collection The collection to search. * @param {Function} predicate The function called per iteration. - * @param {Function} eachFunc The function to iterate over the collection. + * @param {Function} eachFunc The function to iterate over `collection`. * @param {boolean} [retKey=false] Specify returning the key of the found * element instead of the element itself. * @returns {*} Returns the found element or its key, else `undefined`. @@ -1898,38 +1944,18 @@ if (valClass != othClass) { return false; } - switch (valClass) { - case boolClass: - case dateClass: - // 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 +value == +other; - - case numberClass: - // treat `NaN` vs. `NaN` as equal - return (value != +value) - ? other != +other - // but treat `-0` vs. `+0` as not equal - : (value == 0 ? (1 / value == 1 / other) : value == +other); - - case regexpClass: - case stringClass: - // coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and - // treat strings primitives and string objects as equal - return value == String(other); - } var isArr = arrayLikeClasses[valClass], isErr = valClass == errorClass; - if (!support.argsClass) { - valIsArg = isArguments(value); - othIsArg = isArguments(other); - } - if (!isArr) { - // exit for things like functions and DOM nodes - if (!(isErr || valClass == objectClass) || (!support.nodeClass && (isNode(value) || isNode(other)))) { + if (isArr) { + var valLength = value.length, + othLength = other.length; + + if (valLength != othLength && !(isWhere && othLength > valLength)) { return false; } + } + else if (isErr || (valClass == objectClass && (support.nodeClass || !(isNode(value) || isNode(other))))) { // unwrap any `lodash` wrapped values var valWrapped = hasOwnProperty.call(value, '__wrapped__'), othWrapped = hasOwnProperty.call(other, '__wrapped__'); @@ -1937,80 +1963,36 @@ if (valWrapped || othWrapped) { return baseIsEqual(valWrapped ? value.__wrapped__ : value, othWrapped ? other.__wrapped__ : other, customizer, isWhere, stackA, stackB); } - var hasValCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'), - hasOthCtor = !othIsArg && hasOwnProperty.call(other, 'constructor'); - - if (hasValCtor != hasOthCtor) { - return false; + if (!support.argsClass) { + valIsArg = isArguments(value); + othIsArg = isArguments(other); } - if (!hasValCtor) { - // in older versions of Opera, `arguments` objects have `Array` constructors - var valCtor = valIsArg ? Object : value.constructor, - othCtor = othIsArg ? Object : other.constructor; + // in older versions of Opera, `arguments` objects have `Array` constructors + var valCtor = valIsArg ? Object : value.constructor, + othCtor = othIsArg ? Object : other.constructor; + if (isErr) { // error objects of different types are not equal - if (isErr && valCtor.prototype.name != othCtor.prototype.name) { + if (valCtor.prototype.name != othCtor.prototype.name) { return false; } - // non `Object` object instances with different constructors are not equal - if (valCtor != othCtor && - !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && - ('constructor' in value && 'constructor' in other) - ) { + } else { + var valHasCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'), + othHasCtor = !othIsArg && hasOwnProperty.call(other, 'constructor'); + + if (valHasCtor != othHasCtor) { return false; } - } - } - // assume cyclic structures are equal - // the algorithm for detecting cyclic structures is adapted from ES 5.1 - // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3) - stackA || (stackA = []); - stackB || (stackB = []); - - var length = stackA.length; - while (length--) { - if (stackA[length] == value) { - return stackB[length] == other; - } - } - var index = -1; - - // add `value` and `other` to the stack of traversed objects - stackA.push(value); - stackB.push(other); - - // recursively compare objects and arrays (susceptible to call stack limits) - if (isArr) { - var othLength = other.length; - length = value.length; - result = length == othLength; - - if (result || (isWhere && othLength > length)) { - // deep compare the contents, ignoring non-numeric properties - while (++index < length) { - var valValue = value[index]; - if (isWhere) { - var othIndex = othLength; - while (othIndex--) { - result = baseIsEqual(valValue, other[othIndex], customizer, isWhere, stackA, stackB); - if (result) { - break; - } - } - } else { - var othValue = other[index]; - result = customizer ? customizer(valValue, othValue, index) : undefined; - if (typeof result == 'undefined') { - result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); - } - } - if (!result) { - break; + if (!valHasCtor) { + // non `Object` object instances with different constructors are not equal + if (valCtor != othCtor && + !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && + ('constructor' in value && 'constructor' in other) + ) { + return false; } } } - } - else { var valProps = isErr ? ['message', 'name'] : keys(value), othProps = isErr ? valProps : keys(other); @@ -2020,24 +2002,85 @@ if (othIsArg) { othProps.push('length'); } - length = valProps.length; - result = length == othProps.length; + valLength = valProps.length; + othLength = othProps.length; + if (valLength != othLength && !isWhere) { + return false; + } + } + else { + switch (valClass) { + case boolClass: + case dateClass: + // 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 +value == +other; - if (result || isWhere) { - while (++index < length) { - var key = valProps[index]; - result = isErr || hasOwnProperty.call(other, key); + case numberClass: + // treat `NaN` vs. `NaN` as equal + return (value != +value) + ? other != +other + // but treat `-0` vs. `+0` as not equal + : (value == 0 ? (1 / value == 1 / other) : value == +other); - if (result) { - valValue = value[key]; - othValue = other[key]; - result = customizer ? customizer(valValue, othValue, key) : undefined; - if (typeof result == 'undefined') { - result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); + case regexpClass: + case stringClass: + // coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and + // treat strings primitives and string objects as equal + return value == String(other); + } + return false; + } + // assume cyclic structures are equal + // the algorithm for detecting cyclic structures is adapted from ES 5.1 + // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3) + stackA || (stackA = []); + stackB || (stackB = []); + + var index = stackA.length; + while (index--) { + if (stackA[index] == value) { + return stackB[index] == other; + } + } + // add `value` and `other` to the stack of traversed objects + stackA.push(value); + stackB.push(other); + + // recursively compare objects and arrays (susceptible to call stack limits) + result = true; + if (isArr) { + // deep compare the contents, ignoring non-numeric properties + while (result && ++index < valLength) { + var valValue = value[index]; + if (isWhere) { + var othIndex = othLength; + while (othIndex--) { + result = baseIsEqual(valValue, other[othIndex], customizer, isWhere, stackA, stackB); + if (result) { + break; } } - if (!result) { - break; + } else { + var othValue = other[index]; + result = customizer ? customizer(valValue, othValue, index) : undefined; + if (typeof result == 'undefined') { + result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); + } + } + } + } + else { + while (result && ++index < valLength) { + var key = valProps[index]; + result = isErr || hasOwnProperty.call(other, key); + + if (result) { + valValue = value[key]; + othValue = other[key]; + result = customizer ? customizer(valValue, othValue, key) : undefined; + if (typeof result == 'undefined') { + result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); } } } @@ -2062,9 +2105,12 @@ function baseInvoke(collection, methodName, args) { var index = -1, isFunc = typeof methodName == 'function', - length = collection && collection.length, - result = Array(length < 0 ? 0 : length >>> 0); + length = collection ? collection.length : 0, + result = []; + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + result.length = length; + } baseEach(collection, function(value) { var func = isFunc ? methodName : (value != null && value[methodName]); result[++index] = func ? func.apply(value, args) : undefined; @@ -2104,6 +2150,7 @@ */ function baseMerge(object, source, customizer, stackA, stackB) { var isSrcArr = isArrayLike(source); + (isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) { var isArr = srcValue && isArrayLike(srcValue), isObj = srcValue && isPlainObject(srcValue), @@ -2131,9 +2178,9 @@ } } var result = customizer ? customizer(value, srcValue, key, object, source) : undefined, - isShallow = typeof result != 'undefined'; + isDeep = typeof result == 'undefined'; - if (!isShallow) { + if (isDeep) { result = isArr ? (isArray(value) ? value : []) : (isPlainObject(value) ? value : {}); @@ -2144,7 +2191,7 @@ stackB.push(result); // recursively merge objects and arrays (susceptible to call stack limits) - if (!isShallow) { + if (isDeep) { baseMerge(result, srcValue, customizer, stackA, stackB); } object[key] = result; @@ -2246,19 +2293,21 @@ } /** - * The base implementation of `_.reduce` without support for callback - * shorthands or `this` binding. + * The base implementation of `_.reduce` and `_.reduceRight` without support + * for callback shorthands or `this` binding, which iterates over `collection` + * usingthe provided `eachFunc`. * * @private * @param {Array|Object|string} collection The collection to iterate over. * @param {Function} iterator The function called per iteration. - * @param {*} [accumulator] The initial value. - * @param {boolean} [initFromCollection=false] Specify using the first element + * @param {*} accumulator The initial value. + * @param {boolean} initFromCollection Specify using the first element * of `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the accumulated value. */ - function baseReduce(collection, iterator, accumulator, initFromCollection) { - baseEach(collection, function(value, index, collection) { + function baseReduce(collection, iterator, accumulator, initFromCollection, eachFunc) { + eachFunc(collection, function(value, index, collection) { accumulator = initFromCollection ? (initFromCollection = false, value) : iterator(accumulator, value, index, collection) @@ -2286,6 +2335,37 @@ return !!result; } + /** + * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` without + * support for callback shorthands and `this` binding. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iterator The function called per iteration. + * @param {boolean} [retHighest=false] Specify returning the highest, instead + * of the lowest, index at which a value should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndex(array, value, iterator, retHighest) { + var low = 0, + high = array ? array.length : low; + + value = iterator(value); + while (low < high) { + var mid = (low + high) >>> 1, + computed = iterator(array[mid]); + + if (retHighest ? computed <= value : computed < value) { + low = mid + 1; + } else { + high = mid; + } + } + return high; + } + /** * The base implementation of `_.uniq` without support for callback shorthands * and `this` binding. @@ -2369,32 +2449,6 @@ return result; } - /** - * Compiles a function from `source` using the `varNames` and `varValues` - * pairs to import free variables into the compiled function. If `sourceURL` - * is provided it is used as the sourceURL for the compiled function. - * - * @private - * @param {string} source The source to compile. - * @param {Array} varNames An array of free variable names. - * @param {Array} varValues An array of free variable values. - * @param {string} [sourceURL=''] The sourceURL of the source. - * @returns {Function} Returns the compiled function. - */ - function compileFunction(source, varNames, varValues, sourceURL) { - sourceURL = sourceURL ? ('\n/*\n//# sourceURL=' + sourceURL + '\n*/') : ''; - try { - // provide the compiled function's source by its `toString` method or - // the `source` property as a convenience for inlining compiled templates - var result = Function(varNames, 'return ' + source + sourceURL).apply(undefined, varValues); - result.source = source; - } catch(e) { - e.source = source; - throw e; - } - return result; - } - /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -2532,6 +2586,8 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {*} data[3] The `this` binding of `data[0]`. * @returns {Function} Returns the new bound function. */ function createBindWrapper(data) { @@ -2611,14 +2667,19 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {number} data[1] The bitmask of flags to compose. See `createWrapper` + * for more details. + * @param {*} [data[3]] The `this` binding of `data[0]`. + * @param {Array} data[4] An array of arguments to prepend to those + * provided to the new function. * @returns {Function} Returns the new bound function. */ function createPartialWrapper(data) { var func = data[0], bitmask = data[1], thisArg = data[3], - partialArgs = data[4], - partialHolders = data[6]; + partialArgs = data[4]; var isBind = bitmask & BIND_FLAG, Ctor = createCtorWrapper(func); @@ -2630,8 +2691,7 @@ argsLength = arguments.length, leftIndex = -1, leftLength = partialArgs.length, - args = Array(argsLength + leftLength), - thisBinding = isBind ? thisArg : this; + args = Array(argsLength + leftLength); while (++leftIndex < leftLength) { args[leftIndex] = partialArgs[leftIndex]; @@ -2639,7 +2699,7 @@ while (argsLength--) { args[leftIndex++] = arguments[argsIndex++]; } - return (this instanceof wrapper ? Ctor : func).apply(thisBinding, args); + return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args); } return wrapper; } @@ -2728,7 +2788,7 @@ } // merge flags data[1] |= bitmask; - return createWrapper.apply(null, data); + return createWrapper.apply(undefined, data); } if (isPartial) { var partialHolders = getHolders(partialArgs); @@ -2918,6 +2978,23 @@ return result; } + /** + * Converts `collection` to an array if it is not an array-like value. + * + * @private + * @param {Array|Object|string} collection The collection to inspect. + * @returns {Array|Object} Returns the iterable object. + */ + function toIterable(collection) { + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return values(collection); + } else if (support.unindexedChars && isString(collection)) { + return collection.split(''); + } + return collection || []; + } + /*--------------------------------------------------------------------------*/ /** @@ -3223,7 +3300,7 @@ /** * This method is like `_.findIndex` except that it iterates over elements - * of a collection from right to left. + * of `collection` from right to left. * * If a property name is provided for `predicate` the created "_.pluck" style * callback returns the property value of the given element. @@ -3329,9 +3406,10 @@ } /** - * Gets the index at which the first occurrence of `value` is found using - * strict equality for comparisons, i.e. `===`. If the array is already sorted - * providing `true` for `fromIndex` performs a faster binary search. + * Gets the index at which the first occurrence of `value` is found in `array` + * using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, + * it is used as the offset from the end of the collection. If `array` is + * sorted providing `true` for `fromIndex` performs a faster binary search. * * @static * @memberOf _ @@ -3351,11 +3429,12 @@ * // => 4 * * // performing a binary search - * _.indexOf([1, 1, 2, 2, 3, 3], 2, true); + * _.indexOf([4, 4, 5, 5, 6, 6], 5, true); * // => 2 */ function indexOf(array, value, fromIndex) { var length = array ? array.length : 0; + if (typeof fromIndex == 'number') { fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); } else if (fromIndex) { @@ -3459,16 +3538,16 @@ } /** - * Gets the index at which the last occurrence of `value` is found using - * strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, - * it is used as the offset from the end of the collection. + * 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. + * @param {boolean|number} [fromIndex=array.length-1] The index to search from + * or `true` to perform a binary search on a sorted array. * @returns {number} Returns the index of the matched value, else `-1`. * @example * @@ -3478,11 +3557,20 @@ * // using `fromIndex` * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); * // => 1 + * + * // performing a binary search + * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); + * // => 3 */ function lastIndexOf(array, value, fromIndex) { - var index = array ? array.length : 0; + var length = array ? array.length : 0, + index = length; + if (typeof fromIndex == 'number') { index = (fromIndex < 0 ? nativeMax(index + fromIndex, 0) : nativeMin(fromIndex || 0, index - 1)) + 1; + } else if (fromIndex) { + index = sortedLastIndex(array, value) - 1; + return (length && array[index] === value) ? index : -1; } while (index--) { if (array[index] === value) { @@ -3668,11 +3756,11 @@ } /** - * Uses a binary search to determine the smallest index at which a value - * should be inserted into a given sorted array in order to maintain the sort - * order of the array. If an iterator function is provided it is executed for - * `value` and each element of `array` to compute their sort ranking. The - * iterator function is bound to `thisArg` and invoked with one argument; (value). + * Uses a binary search to determine the lowest index at which a value should + * be inserted into a given sorted array in order to maintain the sort order + * of the array. If an iterator function is provided it is executed for `value` + * and each element of `array` to compute their sort ranking. The iterator + * function is bound to `thisArg` and invoked with one argument; (value). * * If a property name is provided for `iterator` the created "_.pluck" style * callback returns the property value of the given element. @@ -3694,38 +3782,53 @@ * into `array`. * @example * - * _.sortedIndex([20, 30, 50], 40); + * _.sortedIndex([30, 50], 40); + * // => 1 + * + * _.sortedIndex([4, 4, 5, 5, 6, 6], 5); * // => 2 * - * var dict = { - * 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'forty': 40, 'fifty': 50 } - * }; + * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; * * // using an iterator function - * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'forty', function(word) { - * return this.wordToNumber[word]; + * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) { + * return this.data[word]; * }, dict); - * // => 2 + * // => 1 * * // using "_.pluck" callback shorthand - * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); - * // => 2 + * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); + * // => 1 */ function sortedIndex(array, value, iterator, thisArg) { - var low = 0, - high = array ? array.length : low; + iterator = iterator == null ? identity : lodash.callback(iterator, thisArg, 1); + return baseSortedIndex(array, value, iterator); + } - // explicitly reference `identity` for better inlining in Firefox - iterator = iterator ? lodash.callback(iterator, thisArg, 1) : identity; - value = iterator(value); - - while (low < high) { - var mid = (low + high) >>> 1; - (iterator(array[mid]) < value) - ? (low = mid + 1) - : (high = mid); - } - return low; + /** + * This method is like `_.sortedIndex` except that it returns the highest + * index at which a value should be inserted into a given sorted array in + * order to maintain the sort order of the array. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to evaluate. + * @param {Function|Object|string} [iterator=identity] The function called + * per iteration. If a property name or object is provided it is used to + * create a "_.pluck" or "_.where" style callback respectively. + * @param {*} [thisArg] The `this` binding of `iterator`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5); + * // => 4 + */ + function sortedLastIndex(array, value, iterator, thisArg) { + iterator = iterator == null ? identity : lodash.callback(iterator, thisArg, 1); + return baseSortedIndex(array, value, iterator, true); } /** @@ -3970,6 +4073,35 @@ return baseUniq(array, isSorted, iterator); } + /** + * 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) { + var index = -1, + length = isObject(length = max(array, 'length')) && length.length || 0, + result = Array(length); + + while (++index < length) { + result[index] = pluck(array, index); + } + return result; + } + /** * Creates an array excluding all provided values using strict equality for * comparisons, i.e. `===`. @@ -4025,33 +4157,20 @@ /** * 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. If a zipped value is provided its corresponding - * unzipped value is returned. + * of the given arrays, and so on. * * @static * @memberOf _ - * @alias unzip * @category Array * @param {...Array} [arrays] The arrays to process. - * @returns {Array} Returns the array of grouped elements. + * @returns {Array} Returns the new array of grouped elements. * @example * * _.zip(['fred', 'barney'], [30, 40], [true, false]); * // => [['fred', 30, true], ['barney', 40, false]] - * - * _.unzip([['fred', 30, true], ['barney', 40, false]]); - * // => [['fred', 'barney'], [30, 40], [true, false]] */ function zip() { - var array = arguments.length > 1 ? arguments : arguments[0], - index = -1, - length = isObject(length = max(array, 'length')) && length.length || 0, - result = Array(length); - - while (++index < length) { - result[index] = pluck(array, index); - } - return result; + return unzip(arguments); } /** @@ -4234,8 +4353,10 @@ * // => ['fred', 'pebbles'] */ function at(collection) { - if (support.unindexedChars && isString(collection)) { - collection = collection.split(''); + var length = collection ? collection.length : 0; + + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + collection = toIterable(collection); } return baseAt(collection, baseFlatten(arguments, false, false, 1)); } @@ -4269,6 +4390,7 @@ */ function contains(collection, target, fromIndex) { var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { collection = values(collection); length = collection.length; @@ -4329,7 +4451,7 @@ }); /** - * Checks if the predicate returns truthy for **all** elements of a collection. + * Checks if the predicate returns truthy for **all** elements of `collection`. * The predicate is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * @@ -4378,7 +4500,7 @@ } /** - * Iterates over elements of a collection returning an array of all elements + * Iterates over elements of `collection` returning an array of all elements * the predicate returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * @@ -4425,7 +4547,7 @@ } /** - * Iterates over elements of a collection, returning the first element that + * Iterates over elements of `collection`, returning the first element that * the predicate returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * @@ -4477,8 +4599,8 @@ } /** - * This method is like `_.find` except that it iterates over elements of a - * collection from right to left. + * This method is like `_.find` except that it iterates over elements of + * `collection` from right to left. * * @static * @memberOf _ @@ -4528,7 +4650,7 @@ } /** - * Iterates over elements of a collection executing `iterator` for each + * Iterates over elements of `collection` executing `iterator` for each * element. The `iterator` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). Iterator functions may exit iteration early * by explicitly returning `false`. @@ -4547,8 +4669,8 @@ * @returns {Array|Object|string} Returns `collection`. * @example * - * _([1, 2, 3]).forEach(function(n) { console.log(n); }).join(','); - * // => logs each number and returns '1,2,3' + * _([1, 2, 3]).forEach(function(n) { console.log(n); }); + * // => logs each value and returns the array * * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); }); * // => logs each value-key pair and returns the object (property order is not guaranteed across environments) @@ -4561,7 +4683,7 @@ /** * This method is like `_.forEach` except that it iterates over elements of - * a collection from right to left. + * `collection` from right to left. * * @static * @memberOf _ @@ -4574,7 +4696,7 @@ * @example * * _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(','); - * // => logs each number from right to left and returns '3,2,1' + * // => logs each value from right to left and returns the array */ function forEachRight(collection, iterator, thisArg) { return (typeof iterator == 'function' && typeof thisArg == 'undefined' && isArray(collection)) @@ -4584,7 +4706,7 @@ /** * Creates an object composed of keys generated from the results of running - * each element of a collection through `iterator`. The corresponding + * each element of `collection` through `iterator`. The corresponding * value of each key is an array of the elements responsible for generating * the key. The `iterator` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). @@ -4741,7 +4863,7 @@ } /** - * Retrieves the maximum value of a collection. If the collection is empty + * Retrieves the maximum value of `collection`. If the collection is empty * or falsey `-Infinity` is returned. If an iterator function is provided it * is executed for each value in the collection to generate the criterion by * which the value is ranked. The `iterator` is bound to `thisArg` and invoked @@ -4819,7 +4941,7 @@ } /** - * Retrieves the minimum value of a collection. If the collection is empty + * Retrieves the minimum value of `collection`. If the collection is empty * or falsey `Infinity` is returned. If an iterator function is provided it * is executed for each value in the collection to generate the criterion by * which the value is ranked. The `iterator` is bound to `thisArg` and invoked @@ -4996,15 +5118,13 @@ * // => { 'a': 3, 'b': 6, 'c': 9 } */ function reduce(collection, iterator, accumulator, thisArg) { - iterator = lodash.callback(iterator, thisArg, 4); - var func = isArray(collection) ? arrayReduce : baseReduce; - return func(collection, iterator, accumulator, arguments.length < 3); + return func(collection, lodash.callback(iterator, thisArg, 4), accumulator, arguments.length < 3, baseEach); } /** - * This method is like `_.reduce` except that it iterates over elements of a - * collection from right to left. + * This method is like `_.reduce` except that it iterates over elements of + * `collection` from right to left. * * @static * @memberOf _ @@ -5022,19 +5142,12 @@ * // => [4, 5, 2, 3, 0, 1] */ function reduceRight(collection, iterator, accumulator, thisArg) { - var noaccum = arguments.length < 3; - iterator = lodash.callback(iterator, thisArg, 4); - - baseEachRight(collection, function(value, index, collection) { - accumulator = noaccum - ? (noaccum = false, value) - : iterator(accumulator, value, index, collection); - }); - return accumulator; + var func = isArray(collection) ? arrayReduceRight : baseReduce; + return func(collection, lodash.callback(iterator, thisArg, 4), accumulator, arguments.length < 3, baseEachRight); } /** - * The opposite of `_.filter`; this method returns the elements of a collection + * The opposite of `_.filter`; this method returns the elements of `collection` * the predicate does **not** return truthy for. * * If a property name is provided for `predicate` the created "_.pluck" style @@ -5095,14 +5208,9 @@ * // => [3, 1] */ function sample(collection, n, guard) { - var length = collection ? collection.length : 0; + collection = toIterable(collection); - if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { - collection = values(collection); - length = collection.length; - } else if (support.unindexedChars && isString(collection)) { - collection = collection.split(''); - } + var length = collection.length; if (n == null || guard) { return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } @@ -5127,21 +5235,25 @@ * // => [4, 1, 3, 2] */ function shuffle(collection) { - var index = -1, - length = collection && collection.length, - result = Array(length < 0 ? 0 : length >>> 0); + collection = toIterable(collection); + + var index = -1, + length = collection.length, + result = Array(length); + + while (++index < length) { + var value = collection[index], + rand = baseRandom(0, index); - baseEach(collection, function(value) { - var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; - }); + } return result; } /** - * Gets the size of the collection by returning `collection.length` for arrays - * and array-like objects or the number of own enumerable properties for objects. + * Gets the size of the collection by returning `collection.length` for + * array-like values or the number of own enumerable properties for objects. * * @static * @memberOf _ @@ -5167,7 +5279,7 @@ } /** - * Checks if the predicate returns truthy for **any** element of a collection. + * Checks if the predicate returns truthy for **any** element of `collection`. * The function returns as soon as it finds a passing value and does not iterate * over the entire collection. The predicate is bound to `thisArg` and invoked * with three arguments; (value, index|key, collection). @@ -5267,10 +5379,13 @@ */ function sortBy(collection, iterator, thisArg) { var index = -1, - length = collection && collection.length, + length = collection ? collection.length : 0, multi = iterator && isArray(iterator), - result = Array(length < 0 ? 0 : length >>> 0); + result = []; + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + result.length = length; + } if (!multi) { iterator = lodash.callback(iterator, thisArg, 3); } @@ -5310,14 +5425,8 @@ * // => [2, 3, 4] */ function toArray(collection) { - var length = collection ? collection.length : 0; - - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - return (support.unindexedChars && isString(collection)) - ? collection.split('') - : slice(collection); - } - return values(collection); + var iterable = toIterable(collection); + return iterable === collection ? slice(collection) : iterable; } /** @@ -5354,14 +5463,13 @@ /*--------------------------------------------------------------------------*/ /** - * Creates a function that executes `func`, with the `this` binding and - * arguments of the created function, only after being called `n` times. + * The opposite of `_.before`; this method creates a function that executes + * `func` only after it is called `n` times. * * @static * @memberOf _ * @category Function - * @param {number} n The number of times the function must be called before - * `func` is executed. + * @param {number} n The number of calls before `func` is executed. * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. * @example @@ -5369,13 +5477,13 @@ * var saves = ['profile', 'settings']; * * var done = _.after(saves.length, function() { - * console.log('Done saving!'); + * console.log('done saving!'); * }); * * _.forEach(saves, function(type) { * asyncSave({ 'type': type, 'complete': done }); * }); - * // => logs 'Done saving!', after all saves have completed + * // => logs 'done saving!' after all saves have completed */ function after(n, func) { if (!isFunction(func)) { @@ -5389,6 +5497,36 @@ }; } + /** + * Creates a function that executes `func`, with the `this` binding and + * arguments of the created function, until it is called `n` times. + * + * @static + * @memberOf _ + * @category Function + * @param {number} n The number of times `func` may be executed. + * @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 5 contacts to the list + */ + function before(n, func) { + var result; + if (!isFunction(func)) { + throw new TypeError(funcErrorText); + } + return function() { + if (--n > 0) { + result = func.apply(this, arguments); + } else { + func = null; + } + return result; + }; + } + /** * Creates a function that invokes `func` with the `this` binding of `thisArg` * and prepends any additional `bind` arguments to those provided to the bound @@ -5444,12 +5582,14 @@ * * _.bindAll(view); * jQuery('#docs').on('click', view.onClick); - * // => logs 'clicked docs', when the button is clicked + * // => logs 'clicked docs' when the element is clicked */ function bindAll(object) { - return baseBindAll(object, arguments.length > 1 - ? baseFlatten(arguments, false, false, 1) - : functions(object)); + return baseBindAll(object, + arguments.length > 1 + ? baseFlatten(arguments, false, false, 1) + : functions(object) + ); } /** @@ -5940,6 +6080,7 @@ * * @static * @memberOf _ + * @type Function * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. @@ -5950,25 +6091,7 @@ * initialize(); * // `initialize` executes `createApplication` once */ - function once(func) { - var ran, - result; - - if (!isFunction(func)) { - throw new TypeError(funcErrorText); - } - return function() { - if (ran) { - return result; - } - ran = true; - result = func.apply(this, arguments); - - // clear the `func` variable so the function may be garbage collected - func = null; - return result; - }; - } + var once = partial(before, 2); /** * Creates a function that invokes `func` with any additional `partial` arguments @@ -6315,7 +6438,7 @@ } var args = slice(arguments); args.push(assignDefaults); - return assign.apply(null, args); + return assign.apply(undefined, args); } /** @@ -6445,8 +6568,8 @@ } /** - * This method is like `_.forIn` except that it iterates over elements of a - * collection in the opposite order. + * This method is like `_.forIn` except that it iterates over properties of + * `object` in the opposite order. * * @static * @memberOf _ @@ -6502,8 +6625,8 @@ } /** - * This method is like `_.forOwn` except that it iterates over elements of a - * collection in the opposite order. + * This method is like `_.forOwn` except that it iterates over properties of + * `object` in the opposite order. * * @static * @memberOf _ @@ -6731,8 +6854,8 @@ /** * Checks if a collection is empty. A value is considered empty unless it is - * an array, array-like object, or string with a length greater than `0` or - * an object with own enumerable properties. + * an array-like value with a length greater than `0` or an object with own + * enumerable properties. * * @static * @memberOf _ @@ -6757,9 +6880,8 @@ * // => false */ function isEmpty(value) { - var result = true; if (value == null) { - return result; + return true; } var length = value.length; if ((typeof length == 'number' && length > -1 && length <= maxSafeInteger) && @@ -6767,11 +6889,7 @@ (typeof value == 'object' && isFunction(value.splice)))) { return !length; } - baseForOwn(value, function() { - result = false; - return result; - }); - return result; + return !keys(value).length; } /** @@ -6783,7 +6901,7 @@ * * Note: This method supports comparing arrays, booleans, `Date` objects, * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes - * are **not** supported. A customizer function may be used to extend support + * are **not** supported. Provide a customizer function to extend support * for comparing other values. * * @static @@ -7192,7 +7310,7 @@ var length = object.length; length = (typeof length == 'number' && length > 0 && (isArray(object) || (support.nonEnumStrings && isString(object)) || - (support.nonEnumArgs && isArguments(object))) && length) >>> 0; + (support.nonEnumArgs && isArguments(object))) && length) || 0; var keyIndex, Ctor = object.constructor, @@ -7207,7 +7325,7 @@ while (++index < length) { result[index] = String(index); } - // Lo-Dash skips the `constructor` property when it infers it's iterating + // Lo-Dash skips the `constructor` property when it infers it is iterating // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]` // attribute of an existing property and the `constructor` property of a // prototype defaults to non-enumerable. @@ -7432,9 +7550,11 @@ if (object == null) { return {}; } - return basePick(Object(object), typeof predicate == 'function' - ? lodash.callback(predicate, thisArg, 3) - : baseFlatten(arguments, false, false, 1)); + return basePick(Object(object), + typeof predicate == 'function' + ? lodash.callback(predicate, thisArg, 3) + : baseFlatten(arguments, false, false, 1) + ); } /** @@ -7470,6 +7590,7 @@ */ function transform(object, iterator, accumulator, thisArg) { var isArr = isArrayLike(object); + if (accumulator == null) { if (isArr) { accumulator = []; @@ -7936,7 +8057,7 @@ * compiled({ 'name': 'mustache' }); * // => 'hello mustache!' * - * // using the `imports` option to import jQuery + * // using the `imports` option to import `jQuery` as `jq` * var text = '<% jq.each(people, function(name) { %>
  • <%- name %>
  • <% }); %>'; * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); * compiled({ 'people': ['fred', 'barney'] }); @@ -7994,6 +8115,7 @@ // use a sourceURL for easier debugging // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl var sourceURL = options.sourceURL || ('/lodash/template/source[' + (templateCounter++) + ']'); + sourceURL = sourceURL ? ('\n/*\n//# sourceURL=' + sourceURL + '\n*/') : ''; string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { interpolateValue || (interpolateValue = esTemplateValue); @@ -8052,7 +8174,17 @@ source + 'return __p\n}'; - return compileFunction(source, importsKeys, importsValues, sourceURL); + var result = attempt(function() { + return Function(importsKeys, 'return ' + source + sourceURL).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 (result instanceof Error) { + throw result; + } + return result; } /** @@ -8153,7 +8285,7 @@ * @param {string} [string=''] The string to truncate. * @param {Object|number} [options] The options object or maximum string length. * @param {number} [options.length=30] The maximum string length. - * @param {string} [options.omission='...'] The string used to indicate text is omitted. + * @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 @@ -8249,6 +8381,34 @@ /*--------------------------------------------------------------------------*/ + /** + * Attempts to execute `func`, returning either the result or the caught + * error object. + * + * @static + * @memberOf _ + * @category Utility + * @param {*} func The function to attempt. + * @returns {*} Returns the `func` result or error object. + * @example + * + * // avoid throwing errors for invalid selectors + * var elements = _.attempt(function() { + * return document.querySelectorAll(selector); + * }); + * + * if (elements instanceof Error) { + * elements = []; + * } + */ + function attempt(func) { + try { + return func(); + } catch(e) { + return isError(e) ? e : Error(e); + } + } + /** * Creates a function bound to an optional `thisArg`. If `func` is a property * name the created callback returns the property value for a given element. @@ -8516,8 +8676,7 @@ * @category Utility * @example * - * var stamp = _.now(); - * _.defer(function() { console.log(_.now() - stamp); }); + * _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); * // => logs the number of milliseconds it took for the deferred function to be called */ var now = nativeNow || function() { @@ -8537,7 +8696,7 @@ * @memberOf _ * @category Utility * @param {string} value The value to parse. - * @param {number} [radix] The radix used to interpret the value to parse. + * @param {number} [radix] The radix to interpret `value` by. * @returns {number} Returns the converted integer. * @example * @@ -8761,14 +8920,18 @@ * // => also calls `mage.castSpell(n)` three times */ function times(n, iterator, thisArg) { - n = n < 0 ? 0 : n >>> 0; + n = nativeIsFinite(n = +n) && n > -1 ? n : 0; iterator = baseCallback(iterator, thisArg, 1); var index = -1, - result = Array(n); + result = Array(nativeMin(n, maxArrayLength)); while (++index < n) { - result[index] = iterator(index); + if (index < maxArrayLength) { + result[index] = iterator(index); + } else { + iterator(index); + } } return result; } @@ -8803,6 +8966,7 @@ lodash.after = after; lodash.assign = assign; lodash.at = at; + lodash.before = before; lodash.bind = bind; lodash.bindAll = bindAll; lodash.bindKey = bindKey; @@ -8878,6 +9042,7 @@ lodash.transform = transform; lodash.union = union; lodash.uniq = uniq; + lodash.unzip = unzip; lodash.values = values; lodash.valuesIn = valuesIn; lodash.where = where; @@ -8897,7 +9062,6 @@ lodash.select = filter; lodash.tail = rest; lodash.unique = uniq; - lodash.unzip = zip; // add functions to `lodash.prototype` mixin(lodash, baseAssign({}, lodash)); @@ -8905,6 +9069,7 @@ /*--------------------------------------------------------------------------*/ // add functions that return unwrapped values when chaining + lodash.attempt = attempt; lodash.camelCase = camelCase; lodash.capitalize = capitalize; lodash.clone = clone; @@ -8962,9 +9127,10 @@ lodash.result = result; lodash.runInContext = runInContext; lodash.size = size; + lodash.snakeCase = snakeCase; lodash.some = some; lodash.sortedIndex = sortedIndex; - lodash.snakeCase = snakeCase; + lodash.sortedLastIndex = sortedLastIndex; lodash.startsWith = startsWith; lodash.template = template; lodash.trim = trim; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 69e771dad..af5765df9 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,69 +5,69 @@ */ ;(function(){function n(n,t){for(var r=-1,e=t.length,u=Array(e);++rt||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202>>0:0,u=pe(e);++ri(t,f)&&c.push(f);return c}function Bt(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number"&&-1f)for(;++so?0:o>>>0);return Bt(n,function(n){var o=u?t:null!=n&&n[t];i[++e]=o?o.apply(n,r):m}),i}function nr(n,t){var r=[];return Bt(n,function(n,e,u){r.push(t(n,e,u))}),r}function tr(n,t,r,e,u){var o=br(t);return(o?At:Xt)(t,function(t,i,a){var f=t&&br(t),c=t&&du(t),l=n[i];if(f||c){for(e||(e=[]),u||(u=[]),c=e.length;c--;)if(e[c]==t)return void(n[i]=u[c]);a=r?r(l,t,i,n,a):m,(c=typeof a!="undefined")||(a=f?vu(l)?l:[]:du(l)?l:{}),e.push(t),u.push(a),c||tr(a,t,r,e,u),n[i]=a -}else a=r?r(l,t,i,n,a):m,typeof a=="undefined"&&(a=t),(o||typeof a!="undefined")&&(n[i]=a)}),n}function rr(n,t,r,e){if(n)var u=n[E]?n[E][2]:n.length,u=u-r.length;var o=t&x;return yr(n,t,u,e,o&&r,!o&&r)}function er(n,t){var r={};if(typeof t=="function")return Jt(n,function(n,e,u){t(n,e,u)&&(r[e]=n)}),r;for(var e=-1,u=t.length;++ea(s,h)&&((u||c)&&s.push(h),l.push(p))}return l}function fr(n,t){for(var r=-1,e=t(n),u=e.length,o=pe(u);++re)return t;var u=typeof r[2];if("number"!=u&&"string"!=u||!r[3]||r[3][r[2]]!==r[1]||(e=2),3e?Qe(u+e,0):e||0; -else if(e)return e=Ir(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Er(n){return Cr(n,1)}function Cr(n,t,r){var e=-1,u=n?n.length:0;for(t=null==t?0:+t||0,0>t?t=Qe(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=Qe(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=pe(u);++e>>1,r(n[e])r?Qe(e+r,0):r||0:0,typeof n=="string"||!vu(n)&&re(n)?ro&&(o=a)}else t=null==t&&re(n)?u:M.callback(t,r,3),Bt(n,function(n,r,u){r=t(n,r,u),(r>e||-1/0===r&&r===o)&&(e=r,o=n)});return o}function zr(n,t){return Br(n,se(t))}function qr(n,t,r,e){return t=M.callback(t,e,4),(vu(n)?Et:or)(n,t,r,3>arguments.length)}function Mr(n,t,r,e){var u=3>arguments.length; -return t=M.callback(t,e,4),Dt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Zr(n){var t=-1,r=n&&n.length,e=pe(0>r?0:r>>>0);return Bt(n,function(n){var r=ur(0,++t);e[t]=e[r],e[r]=n}),e}function Kr(n,t,r){return(typeof t!="function"||typeof r!="undefined")&&(t=M.callback(t,r,3)),(vu(n)?It:ir)(n,t)}function Vr(n,t,r){function e(){var r=t-(Au()-c);0>=r||r>t?(a&&Ne(a),r=p,a=s=p=m,r&&(h=Au(),f=n.apply(l,i),s||a||(i=l=null))):s=qe(e,r)}function u(){s&&Ne(s),a=s=p=m,(v||g!==t)&&(h=Au(),f=n.apply(l,i),s||a||(i=l=null)) -}function o(){if(i=arguments,c=Au(),l=this,p=v&&(s||!y),false===g)var r=y&&!s;else{a||y||(h=c);var o=g-(c-h),d=0>=o||o>g;d?(a&&(a=Ne(a)),h=c,f=n.apply(l,i)):a||(a=qe(u,o))}return d&&s?s=Ne(s):s||t===g||(s=qe(e,t)),r&&(d=true,f=n.apply(l,i)),!d||s||a||(i=l=null),f}var i,a,f,c,l,s,p,h=0,g=false,v=true;if(!Hr(n))throw new we(C);if(t=0>t?0:t,true===r)var y=true,v=false;else Qr(r)&&(y=r.leading,g="maxWait"in r&&Qe(+r.maxWait||0,t),v="trailing"in r?r.trailing:v);return o.cancel=function(){s&&Ne(s),a&&Ne(a),a=s=p=m},o}function Jr(n){if(!Hr(n))throw new we(C); -return function(){return!n.apply(this,arguments)}}function Xr(n){return Gt(n,ee)}function Yr(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Se.call(n)==Q||false}function Gr(n){return n&&typeof n=="object"&&1===n.nodeType&&(au.nodeClass?-1>>0,e=n.constructor,u=-1,o=e&&n===e.prototype,i=r-1,e=pe(r),a=0t||null==n||!Ge(t))return r;n=_e(n);do t%2&&(r+=n),t=We(t/2),n+=n;while(t);return r}function ae(n,t){return(n=null==n?"":_e(n))?null==t?n.slice(g(n),v(n)+1):(t=_e(t),n.slice(o(n,t),i(n,t)+1)):n}function fe(n){return n}function ce(n){var t=mu(n),r=t.length,e=t[0],u=r&&n[e]; -return 1!=r||u!==u||Qr(u)?function(e){var u=r;if(u&&null==e)return false;for(;u--;){var o=t[u];if(!Pe.call(e,o)||!Ht(n[o],e[o],null,true))return false}return true}:function(n){if(null==n)return false;var t=n[e];return u===t&&(0!==u||1/u==1/t)&&Pe.call(n,e)}}function le(n,t,r){var e=true,u=t&&Gt(t,mu);t&&(r||u.length)||(null==r&&(r=t),t=n,n=this,u=Gt(t,mu)),false===r?e=false:Qr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var o=Hr(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},M.assign=gu,M.at=function(t){return au.unindexedChars&&re(t)&&(t=t.split("")),n(t,Zt(arguments,false,false,1))},M.bind=function(n,t){return 3>arguments.length?yr(n,b,null,t):rr(n,b|x,Cr(arguments,2),t)},M.bindAll=function(n){for(var t=n,r=1arguments.length?yr(t,b|_,null,n):yr(t,b|_|x,null,n,Cr(arguments,2))},M.callback=function(n,t,r){var e=typeof n,u="function"==e;return u&&typeof t=="undefined"?n:u||null==n?Lt(n,t,r):"object"==e?ce(n):se(n)},M.chain=function(n){return n=M(n),n.__chain__=true,n},M.chunk=function(n,t){var r=0,e=n?n.length:0,u=[];for(t=Qe(+t||1,1);rt?0:t)},M.dropRight=function(n,t,r){var e=n?n.length:0; -return t=e-((null==t||r?1:t)||0),Cr(n,0,0>t?0:t)},M.dropRightWhile=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return Cr(n,0,e+1)},M.dropWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++e(p?e(p,f):i(s,f))){for(t=u;--t;){var h=o[t];if(0>(h?e(h,f):i(n[t],f)))continue n}p&&p.push(f),s.push(f)}return s},M.invert=function(n,t){for(var r=-1,e=mu(n),u=e.length,o={};++ru?0:u>>>0);for(o||(t=M.callback(t,r,3)),Bt(n,function(n,r,u){if(o)for(r=t.length,u=pe(r);r--;)u[r]=n[t[r]];else u=t(n,r,u);i[++e]={a:u,b:e,c:n}}),u=i.length,i.sort(o?f:a);u--;)i[u]=i[u].c;return i},M.take=function(n,t,r){return t=null==t||r?1:t,Cr(n,0,0>t?0:t)},M.takeRight=function(n,t,r){var e=n?n.length:0;return t=e-((null==t||r?1:t)||0),Cr(n,0>t?0:t)},M.takeRightWhile=function(n,t,r){var e=n?n.length:0; -for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return Cr(n,e+1)},M.takeWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++en?0:n>>>0,t=Lt(t,r,1),r=-1;for(var e=pe(n);++rr?0:+r||0,e))-t.length,0<=r&&n.indexOf(t,r)==r},M.escape=function(n){return null==n?"":_e(n).replace(N,s)},M.escapeRegExp=oe,M.every=Nr,M.find=Wr,M.findIndex=xr,M.findKey=function(n,t,r){return t=M.callback(t,r,3),Mt(n,t,Xt,true) -},M.findLast=function(n,t,r){return t=M.callback(t,r,3),Mt(n,t,Dt)},M.findLastIndex=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},M.findLastKey=function(n,t,r){return t=M.callback(t,r,3),Mt(n,t,Yt,true)},M.findWhere=function(n,t){return Wr(n,ce(t))},M.first=kr,M.has=function(n,t){return n?Pe.call(n,t):false},M.identity=fe,M.indexOf=Or,M.isArguments=Yr,M.isArray=vu,M.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&Se.call(n)==tt||false -},M.isDate=function(n){return n&&typeof n=="object"&&Se.call(n)==rt||false},M.isElement=Gr,M.isEmpty=function(n){var t=true;if(null==n)return t;var r=n.length;return typeof r=="number"&&-1r?Qe(e+r,0):nu(r||0,e-1))+1);e--;)if(n[e]===t)return e; -return-1},M.max=Dr,M.min=function(n,t,r){var e=1/0,o=e,i=typeof t;if("number"!=i&&"string"!=i||!r||r[t]!==n||(t=null),null==t&&vu(n))for(r=-1,i=n.length;++rr?0:+r||0,n.length),n.lastIndexOf(t,r)==r},M.template=function(n,t){var r=M.templateSettings;t=gu({},t,r,Ut),n=_e(null==n?"":n);var e,u,o=gu({},t.imports,r.imports,Ut),r=mu(o),o=ue(o),i=0,a=t.interpolate||Z,f="__p+='",a=be((t.escape||Z).source+"|"+a.source+"|"+(a===$?P:Z).source+"|"+(t.evaluate||Z).source+"|$","g"); -return n.replace(a,function(t,r,o,a,c,l){return o||(o=a),f+=n.slice(i,l).replace(J,p),r&&(e=true,f+="'+__e("+r+")+'"),c&&(u=true,f+="';"+c+";\n__p+='"),o&&(f+="'+((__t=("+o+"))==null?'':__t)+'"),i=l+t.length,t}),f+="';",(a=t.variable)||(f="with(obj){"+f+"}"),f=(u?f.replace(R,""):f).replace(U,"$1").replace(F,"$1;"),f="function("+(a||"obj")+"){"+(a?"":"obj||(obj={});")+"var __t,__p=''"+(e?",__e=_.escape":"")+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}",cr(f,r,o) -},M.trim=ae,M.trimLeft=function(n,t){return(n=null==n?"":_e(n))?null==t?n.slice(g(n)):(t=_e(t),n.slice(o(n,t))):n},M.trimRight=function(n,t){return(n=null==n?"":_e(n))?null==t?n.slice(0,v(n)+1):(t=_e(t),n.slice(0,i(n,t)+1)):n},M.trunc=function(n,t){var r=30,e="...";if(Qr(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?_e(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":_e(n),r>=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e; -if(te(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=be(u.source,(B.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index;r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(L,y))},M.uniqueId=function(n){var t=++I;return _e(null==n?"":n)+t},M.all=Nr,M.any=Kr,M.detect=Wr,M.foldl=qr,M.foldr=Mr,M.head=kr,M.include=Lr,M.inject=qr,le(M,function(){var n={}; -return Xt(M,function(t,r){M.prototype[r]||(n[r]=t)}),n}(),false),M.sample=function(n,t,r){var e=n?n.length:0;return typeof e=="number"&&-1t?0:+t||0,n.length),n)},Xt(M,function(n,t){var r="sample"!=t;M.prototype[t]||(M.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new X(o,u):o})}),M.VERSION=O,M.prototype.chain=function(){return this.__chain__=true,this -},M.prototype.toJSON=Fr,M.prototype.toString=function(){return _e(this.__wrapped__)},M.prototype.value=Fr,M.prototype.valueOf=Fr,At(["join","pop","shift"],function(n){var t=je[n];M.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments);return n?new X(r,n):r}}),At(["push","reverse","sort","unshift"],function(n){var t=je[n];M.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),At(["concat","splice"],function(n){var t=je[n];M.prototype[n]=function(){return new X(t.apply(this.__wrapped__,arguments),this.__chain__) -}}),au.spliceObjects||At(["pop","shift","splice"],function(n){var t=je[n],r="splice"==n;M.prototype[n]=function(){var n=this.__chain__,e=this.__wrapped__,u=t.apply(e,arguments);return 0===e.length&&delete e[0],n||r?new X(u,n):u}}),M}var m,b=1,_=2,w=4,j=8,A=16,x=32,k=64,O="3.0.0-pre",E="__lodash@"+O+"__",C="Expected a function",I=0,S=/^[A-Z]+$/,R=/\b__p\+='';/g,U=/\b(__p\+=)''\+/g,F=/(__e\(.*?\)|\b__t\))\+'';/g,L=/&(?:amp|lt|gt|quot|#39|#96);/g,N=/[&<>"'`]/g,T=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,P=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,B=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,z=/^0[xX]/,q=/^\[object .+?Constructor\]$/,M=/[\xC0-\xFF]/g,Z=/($^)/,K=/[.*+?^${}()|[\]\/\\]/g,V=/\bthis\b/,J=/['\n\r\u2028\u2029\\]/g,X=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Y=" \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",G="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q="[object Arguments]",nt="[object Array]",tt="[object Boolean]",rt="[object Date]",et="[object Error]",ut="[object Function]",ot="[object Number]",it="[object Object]",at="[object RegExp]",ft="[object String]",ct="[object ArrayBuffer]",lt="[object Float32Array]",st="[object Float64Array]",pt="[object Int8Array]",ht="[object Int16Array]",gt="[object Int32Array]",vt="[object Uint8Array]",yt="[object Uint8ClampedArray]",dt="[object Uint16Array]",mt="[object Uint32Array]",bt={}; -bt[Q]=bt[nt]=bt[lt]=bt[st]=bt[pt]=bt[ht]=bt[gt]=bt[vt]=bt[yt]=bt[dt]=bt[mt]=true,bt[ct]=bt[tt]=bt[rt]=bt[et]=bt[ut]=bt["[object Map]"]=bt[ot]=bt[it]=bt[at]=bt["[object Set]"]=bt[ft]=bt["[object WeakMap]"]=false;var _t={};_t[Q]=_t[nt]=_t[ct]=_t[tt]=_t[rt]=_t[lt]=_t[st]=_t[pt]=_t[ht]=_t[gt]=_t[ot]=_t[it]=_t[at]=_t[ft]=_t[vt]=_t[yt]=_t[dt]=_t[mt]=true,_t[et]=_t[ut]=_t["[object Map]"]=_t["[object Set]"]=_t["[object WeakMap]"]=false;var wt={leading:false,maxWait:0,trailing:false},jt={configurable:false,enumerable:false,value:null,writable:false},At={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},xt={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},kt={"\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","\xd7":" ","\xf7":" "},Ot={"function":true,object:true},Et={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Ct=Ot[typeof window]&&window||this,It=Ot[typeof exports]&&exports&&!exports.nodeType&&exports,Ot=Ot[typeof module]&&module&&!module.nodeType&&module,St=It&&Ot&&typeof global=="object"&&global; -!St||St.global!==St&&St.window!==St&&St.self!==St||(Ct=St);var St=Ot&&Ot.exports===It&&It,Rt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Ct._=Rt, define(function(){return Rt})):It&&Ot?St?(Ot.exports=Rt)._=Rt:It._=Rt:Ct._=Rt}).call(this); \ No newline at end of file +if((160e||13e||8202r||13r||8202i(t,f)&&c.push(f);return c}function Dt(n,t){var r=n?n.length:0;if(typeof r!="number"||-1>=r||r>Te)return Yt(n,t);for(var e=-1,u=kr(n);++e=r||r>Te)return Gt(n,t);for(var e=kr(n);r--&&false!==t(e[r],r,n););return n +}function qt(n,t){var r=true;return Dt(n,function(n,e,u){return r=!!t(n,e,u)}),r}function Mt(n,t){var r=[];return Dt(n,function(n,e,u){t(n,e,u)&&r.push(n)}),r}function Zt(n,t,r,e){var u;return r(n,function(n,r,o){return t(n,r,o)?(u=e?r:n,false):void 0}),u}function Kt(n,t,r,e){e=(e||0)-1;for(var u=n.length,o=0,i=[];++e>>1,a=r(n[i]);(e?a<=t:aa(s,h)&&((u||c)&&s.push(h),l.push(p))}return l}function lr(n,t){for(var r=-1,e=t(n),u=e.length,o=be(u);++re)return t;var u=typeof r[2];if("number"!=u&&"string"!=u||!r[3]||r[3][r[2]]!==r[1]||(e=2),3e?au(u+e,0):e||0;else if(e)return e=Rr(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Cr(n){return Sr(n,1)}function Sr(n,t,r){var e=-1,u=n?n.length:0;for(t=null==t?0:+t||0,0>t?t=au(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=au(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=be(u);++er?au(e+r,0):r||0:0,typeof n=="string"||!xu(n)&&fe(n)?ro&&(o=a)}else t=null==t&&fe(n)?u:M.callback(t,r,3),Dt(n,function(n,r,u){r=t(n,r,u),(r>e||-1/0===r&&r===o)&&(e=r,o=n)});return o}function Zr(n,t){return qr(n,de(t)) +}function Kr(n,t,r,e){return(xu(n)?Et:ir)(n,M.callback(t,e,4),r,3>arguments.length,Dt)}function Vr(n,t,r,e){return(xu(n)?Ct:ir)(n,M.callback(t,e,4),r,3>arguments.length,zt)}function Jr(n){n=kr(n);for(var t=-1,r=n.length,e=be(r);++t=r||r>t?(a&&qe(a),r=p,a=s=p=d,r&&(h=Uu(),f=n.apply(l,i),s||a||(i=l=null))):s=Ge(e,r)}function u(){s&&qe(s),a=s=p=d,(v||g!==t)&&(h=Uu(),f=n.apply(l,i),s||a||(i=l=null))}function o(){if(i=arguments,c=Uu(),l=this,p=v&&(s||!y),false===g)var r=y&&!s;else{a||y||(h=c);var o=g-(c-h),m=0>=o||o>g;m?(a&&(a=qe(a)),h=c,f=n.apply(l,i)):a||(a=Ge(u,o))}return m&&s?s=qe(s):s||t===g||(s=Ge(e,t)),r&&(m=true,f=n.apply(l,i)),!m||s||a||(i=l=null),f}var i,a,f,c,l,s,p,h=0,g=false,v=true; +if(!ue(n))throw new Ie(I);if(t=0>t?0:t,true===r)var y=true,v=false;else oe(r)&&(y=r.leading,g="maxWait"in r&&au(+r.maxWait||0,t),v="trailing"in r?r.trailing:v);return o.cancel=function(){s&&qe(s),a&&qe(a),a=s=p=d},o}function Hr(n){if(!ue(n))throw new Ie(I);return function(){return!n.apply(this,arguments)}}function Qr(n){return er(n,x,Sr(arguments,1))}function ne(n){return Ht(n,ce)}function te(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$e.call(n)==Q||false}function re(n){return n&&typeof n=="object"&&1===n.nodeType&&(vu.nodeClass?-1<$e.call(n).indexOf("Element"):h(n))||false +}function ee(n){return n&&typeof n=="object"&&$e.call(n)==et||false}function ue(n){return typeof n=="function"||false}function oe(n){var t=typeof n;return"function"==t||n&&"object"==t||false}function ie(n){var t=typeof n;return"number"==t||n&&"object"==t&&$e.call(n)==ot||false}function ae(n){return oe(n)&&$e.call(n)==at||false}function fe(n){return typeof n=="string"||n&&typeof n=="object"&&$e.call(n)==ft||false}function ce(n){if(null==n)return[];n=ke(n);for(var t,r=n.length,r=typeof r=="number"&&0t||null==n||!ou(t))return r;n=Ee(n);do t%2&&(r+=n),t=Ze(t/2),n+=n;while(t);return r}function he(n,t){return(n=null==n?"":Ee(n))?null==t?n.slice(g(n),v(n)+1):(t=Ee(t),n.slice(o(n,t),i(n,t)+1)):n +}function ge(n){try{return n()}catch(t){return ee(t)?t:we(t)}}function ve(n){return n}function ye(n){var t=Eu(n),r=t.length,e=t[0],u=r&&n[e];return 1!=r||u!==u||oe(u)?function(e){var u=r;if(u&&null==e)return false;for(;u--;){var o=t[u];if(!Ve.call(e,o)||!Qt(n[o],e[o],null,true))return false}return true}:function(n){if(null==n)return false;var t=n[e];return u===t&&(0!==u||1/u==1/t)&&Ve.call(n,e)}}function me(n,t,r){var e=true,u=t&&Ht(t,Eu);t&&(r||u.length)||(null==r&&(r=t),t=n,n=this,u=Ht(t,Eu)),false===r?e=false:oe(r)&&"chain"in r&&(e=r.chain),r=-1; +for(var o=ue(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},M.assign=Au,M.at=function(t){var r=t?t.length:0;return typeof r=="number"&&-1arguments.length?mr(n,b,null,t):er(n,b|x,Sr(arguments,2),t)},M.bindAll=function(n){for(var t=n,r=1arguments.length?mr(t,b|_,null,n):mr(t,b|_|x,null,n,Sr(arguments,2))},M.callback=function(n,t,r){var e=typeof n,u="function"==e;return u&&typeof t=="undefined"?n:u||null==n?Nt(n,t,r):"object"==e?ye(n):de(n)},M.chain=function(n){return n=M(n),n.__chain__=true,n},M.chunk=function(n,t){var r=0,e=n?n.length:0,u=[];for(t=au(+t||1,1);rt?0:t)},M.dropRight=function(n,t,r){var e=n?n.length:0; +return t=e-((null==t||r?1:t)||0),Sr(n,0,0>t?0:t)},M.dropRightWhile=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return Sr(n,0,e+1)},M.dropWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++e(p?e(p,f):i(s,f))){for(t=u;--t;){var h=o[t];if(0>(h?e(h,f):i(n[t],f)))continue n}p&&p.push(f),s.push(f)}return s},M.invert=function(n,t){for(var r=-1,e=Eu(n),u=e.length,o={};++rt?0:t)},M.takeRight=function(n,t,r){var e=n?n.length:0;return t=e-((null==t||r?1:t)||0),Sr(n,0>t?0:t)},M.takeRightWhile=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return Sr(n,e+1) +},M.takeWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++er?0:+r||0,e))-t.length,0<=r&&n.indexOf(t,r)==r},M.escape=function(n){return null==n?"":Ee(n).replace(N,s)},M.escapeRegExp=se,M.every=$r,M.find=Br,M.findIndex=Or,M.findKey=function(n,t,r){return t=M.callback(t,r,3),Zt(n,t,Yt,true)},M.findLast=function(n,t,r){return t=M.callback(t,r,3),Zt(n,t,zt)},M.findLastIndex=function(n,t,r){var e=n?n.length:0; +for(t=M.callback(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},M.findLastKey=function(n,t,r){return t=M.callback(t,r,3),Zt(n,t,Gt,true)},M.findWhere=function(n,t){return Br(n,ye(t))},M.first=Er,M.has=function(n,t){return n?Ve.call(n,t):false},M.identity=ve,M.indexOf=Ir,M.isArguments=te,M.isArray=xu,M.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&$e.call(n)==tt||false},M.isDate=function(n){return n&&typeof n=="object"&&$e.call(n)==rt||false},M.isElement=re,M.isEmpty=function(n){if(null==n)return true; +var t=n.length;return typeof t=="number"&&-1r?au(u+r,0):fu(r||0,u-1))+1;else if(r)return u=Ur(n,t)-1,e&&n[u]===t?u:-1;for(;u--;)if(n[u]===t)return u;return-1},M.max=Mr,M.min=function(n,t,r){var e=1/0,o=e,i=typeof t;if("number"!=i&&"string"!=i||!r||r[t]!==n||(t=null),null==t&&xu(n))for(r=-1,i=n.length;++rr?0:+r||0,n.length),n.lastIndexOf(t,r)==r},M.template=function(n,t){var r=M.templateSettings;t=Au({},t,r,Ft),n=Ee(null==n?"":n); +var e,u,o,r=Au({},t.imports,r.imports,Ft),i=Eu(r),a=le(r),f=0,r=t.interpolate||Z,c="__p+='",r=Oe((t.escape||Z).source+"|"+r.source+"|"+(r===$?P:Z).source+"|"+(t.evaluate||Z).source+"|$","g");if(o=o?"/*//# sourceURL="+o+"*/":"",n.replace(r,function(t,r,o,i,a,l){return o||(o=i),c+=n.slice(f,l).replace(J,p),r&&(e=true,c+="'+__e("+r+")+'"),a&&(u=true,c+="';"+a+";\n__p+='"),o&&(c+="'+((__t=("+o+"))==null?'':__t)+'"),f=l+t.length,t}),c+="';",(r=t.variable)||(c="with(obj){"+c+"}"),c=(u?c.replace(R,""):c).replace(U,"$1").replace(F,"$1;"),c="function("+(r||"obj")+"){"+(r?"":"obj||(obj={});")+"var __t,__p=''"+(e?",__e=_.escape":"")+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}",r=ge(function(){return je(i,"return "+c+o).apply(d,a) +}),r.source=c,r instanceof we)throw r;return r},M.trim=he,M.trimLeft=function(n,t){return(n=null==n?"":Ee(n))?null==t?n.slice(g(n)):(t=Ee(t),n.slice(o(n,t))):n},M.trimRight=function(n,t){return(n=null==n?"":Ee(n))?null==t?n.slice(0,v(n)+1):(t=Ee(t),n.slice(0,i(n,t)+1)):n},M.trunc=function(n,t){var r=30,e="...";if(oe(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Ee(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Ee(n),r>=n.length)return n;var o=r-e.length; +if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(ae(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Oe(u.source,(B.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index;r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(L,y))},M.uniqueId=function(n){var t=++C;return Ee(null==n?"":n)+t},M.all=$r,M.any=Xr,M.detect=Br,M.foldl=Kr,M.foldr=Vr,M.head=Er,M.include=Wr,M.inject=Kr,me(M,function(){var n={}; +return Yt(M,function(t,r){M.prototype[r]||(n[r]=t)}),n}(),false),M.sample=function(n,t,r){n=kr(n);var e=n.length;return null==t||r?0t?0:+t||0,n.length),n)},Yt(M,function(n,t){var r="sample"!=t;M.prototype[t]||(M.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new X(o,u):o})}),M.VERSION=O,M.prototype.chain=function(){return this.__chain__=true,this},M.prototype.toJSON=Tr,M.prototype.toString=function(){return Ee(this.__wrapped__) +},M.prototype.value=Tr,M.prototype.valueOf=Tr,At(["join","pop","shift"],function(n){var t=Ce[n];M.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments);return n?new X(r,n):r}}),At(["push","reverse","sort","unshift"],function(n){var t=Ce[n];M.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),At(["concat","splice"],function(n){var t=Ce[n];M.prototype[n]=function(){return new X(t.apply(this.__wrapped__,arguments),this.__chain__)}}),vu.spliceObjects||At(["pop","shift","splice"],function(n){var t=Ce[n],r="splice"==n; +M.prototype[n]=function(){var n=this.__chain__,e=this.__wrapped__,u=t.apply(e,arguments);return 0===e.length&&delete e[0],n||r?new X(u,n):u}}),M}var d,b=1,_=2,w=4,j=8,A=16,x=32,k=64,O="3.0.0-pre",E="__lodash@"+O+"__",I="Expected a function",C=0,S=/^[A-Z]+$/,R=/\b__p\+='';/g,U=/\b(__p\+=)''\+/g,F=/(__e\(.*?\)|\b__t\))\+'';/g,L=/&(?:amp|lt|gt|quot|#39|#96);/g,N=/[&<>"'`]/g,T=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,P=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,B=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,z=/^0[xX]/,q=/^\[object .+?Constructor\]$/,M=/[\xC0-\xFF]/g,Z=/($^)/,K=/[.*+?^${}()|[\]\/\\]/g,V=/\bthis\b/,J=/['\n\r\u2028\u2029\\]/g,X=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,Y=" \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",G="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Q="[object Arguments]",nt="[object Array]",tt="[object Boolean]",rt="[object Date]",et="[object Error]",ut="[object Function]",ot="[object Number]",it="[object Object]",at="[object RegExp]",ft="[object String]",ct="[object ArrayBuffer]",lt="[object Float32Array]",st="[object Float64Array]",pt="[object Int8Array]",ht="[object Int16Array]",gt="[object Int32Array]",vt="[object Uint8Array]",yt="[object Uint8ClampedArray]",mt="[object Uint16Array]",dt="[object Uint32Array]",bt={}; +bt[Q]=bt[nt]=bt[lt]=bt[st]=bt[pt]=bt[ht]=bt[gt]=bt[vt]=bt[yt]=bt[mt]=bt[dt]=true,bt[ct]=bt[tt]=bt[rt]=bt[et]=bt[ut]=bt["[object Map]"]=bt[ot]=bt[it]=bt[at]=bt["[object Set]"]=bt[ft]=bt["[object WeakMap]"]=false;var _t={};_t[Q]=_t[nt]=_t[ct]=_t[tt]=_t[rt]=_t[lt]=_t[st]=_t[pt]=_t[ht]=_t[gt]=_t[ot]=_t[it]=_t[at]=_t[ft]=_t[vt]=_t[yt]=_t[mt]=_t[dt]=true,_t[et]=_t[ut]=_t["[object Map]"]=_t["[object Set]"]=_t["[object WeakMap]"]=false;var wt={leading:false,maxWait:0,trailing:false},jt={configurable:false,enumerable:false,value:null,writable:false},At={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},xt={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},kt={"\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","\xd7":" ","\xf7":" "},Ot={"function":true,object:true},Et={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},It=Ot[typeof window]&&window||this,Ct=Ot[typeof exports]&&exports&&!exports.nodeType&&exports,Ot=Ot[typeof module]&&module&&!module.nodeType&&module,St=Ct&&Ot&&typeof global=="object"&&global; +!St||St.global!==St&&St.window!==St&&St.self!==St||(It=St);var St=Ot&&Ot.exports===Ct&&Ct,Rt=m();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(It._=Rt, define(function(){return Rt})):Ct&&Ot?St?(Ot.exports=Rt)._=Rt:Ct._=Rt:It._=Rt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index da682c5b6..0b6820c09 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -105,7 +105,7 @@ /** Used to assign default `context` object properties */ var contextProps = [ - 'Array', 'ArrayBuffer', 'Date', 'Float32Array', 'Float64Array', + 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number', 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document', 'isFinite', 'isNaN', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', @@ -115,7 +115,7 @@ /** Used to make template sourceURLs easier to identify */ var templateCounter = 0; - /** `Object#toString` result shortcuts */ + /** `Object#toString` result references */ var argsClass = '[object Arguments]', arrayClass = '[object Array]', boolClass = '[object Boolean]', @@ -195,8 +195,8 @@ * See [Mathias' article](http://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * - * Backticks are escaped because in Internet Explorer < 9, they can be used to - * break out of attribute values or HTML comments. See [#102](http://html5sec.org/#102), + * Backticks are escaped because in Internet Explorer < 9, they can break out + * of attribute values or HTML comments. See [#102](http://html5sec.org/#102), * [#108](http://html5sec.org/#108), and [#133](http://html5sec.org/#133) of * the [HTML5 Security Cheatsheet](http://html5sec.org/) for more details. */ @@ -301,8 +301,8 @@ } /** - * The base implementation of `compareAscending` used to compare values and - * sort them in ascending order without guaranteeing a stable sort. + * The base implementation of `compareAscending` which compares values and + * sorts them in ascending order without guaranteeing a stable sort. * * @private * @param {*} value The value to compare to `other`. @@ -401,7 +401,7 @@ } /** - * Used by `_.sortBy` to compare transformed elements of a collection and stable + * Used by `_.sortBy` to compare transformed elements of `collection` and stable * sort them in ascending order. * * @private @@ -590,6 +590,7 @@ /** Native constructor references */ var Array = context.Array, Date = context.Date, + Error = context.Error, Function = context.Function, Math = context.Math, Number = context.Number, @@ -609,8 +610,11 @@ /** Used to resolve the decompiled source of functions */ var fnToString = Function.prototype.toString; + /** Used as a reference for the max length of an array */ + var maxArrayLength = Math.pow(2, 32) - 1; + /** - * Used as the maximum length of an array-like object. + * Used as the maximum length of an array-like value. * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * for more details. */ @@ -628,7 +632,7 @@ .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); - /** Native method shortcuts */ + /** Native method references */ var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer, bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice, ceil = Math.ceil, @@ -656,7 +660,7 @@ return result; }()); - /* Native method shortcuts for methods with the same name as other `lodash` methods */ + /* Native method references for those with the same name as other `lodash` methods */ var nativeContains = isNative(nativeContains = stringProto.contains) && nativeContains, nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate, nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray, @@ -683,14 +687,14 @@ * implicitly or explicitly included in the build. * * The chainable wrapper functions are: - * `after`, `assign`, `at`, `bind`, `bindAll`, `bindKey`, `callback`, `chain`, - * `chunk`, `compact`, `compose`, `concat`, `constant`, `countBy`, `create`, - * `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, `drop`, - * `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, `forEach`, - * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, - * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, - * `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, `mixin`, - * `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, + * `after`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, `callback`, + * `chain`, `chunk`, `compact`, `compose`, `concat`, `constant`, `countBy`, + * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, + * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, + * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, + * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, + * `invoke`, `keys`, `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, + * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, * `partition`, `pick`, `pluck`, `property`, `pull`, `pullAt`, `push`, `range`, * `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, * `splice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, @@ -699,17 +703,18 @@ * and `zipObject` * * The non-chainable wrapper functions are: - * `camelCase`, `capitalize`, `clone`, `cloneDeep`, `contains`, `endsWith`, - * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, + * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `contains`, + * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, - * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, + * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, isDate`, * `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, `isFunction`, * `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, * `isString`, `isUndefined`, `join`, `kebabCase`, `last`, `lastIndexOf`, * `max`, `min`, `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, - * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `startsWith`, `template`, - * `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, and `value` + * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, + * `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, + * `unescape`, `uniqueId`, and `value` * * The wrapper function `sample` will return a wrapped value when `n` is * provided, otherwise it will return an unwrapped value. @@ -764,7 +769,7 @@ } /** - * An object used to flag environments features. + * An object environment feature flags. * * @static * @memberOf _ @@ -963,7 +968,7 @@ */ function arrayMap(array, iterator) { var index = -1, - length = array ? array.length >>> 0 : 0, + length = array ? array.length : 0, result = Array(length); while (++index < length) { @@ -1020,6 +1025,30 @@ return accumulator; } + /** + * A specialized version of `_.reduceRight` for arrays without support for + * callback shorthands or `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iterator The function called per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initFromArray=false] Specify using the first element of + * `array` as the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduceRight(array, iterator, accumulator, initFromArray) { + var length = array.length; + + if (initFromArray && length) { + accumulator = array[--length]; + } + while (length--) { + accumulator = iterator(accumulator, array[length], length, array); + } + return accumulator; + } + /** * A specialized version of `_.some` for arrays without support for callback * shorthands or `this` binding. @@ -1051,7 +1080,9 @@ * @returns {*} Returns the value to assign to the destination object. */ function assignDefaults(objectValue, sourceValue) { - return typeof objectValue == 'undefined' ? sourceValue : objectValue; + return typeof objectValue == 'undefined' + ? sourceValue + : objectValue; } /** @@ -1068,9 +1099,9 @@ * @returns {*} Returns the value to assign to the destination object. */ function assignOwnDefaults(objectValue, sourceValue, key, object) { - return (!hasOwnProperty.call(object, key) || typeof objectValue == 'undefined') + return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key)) ? sourceValue - : objectValue + : objectValue; } /** @@ -1090,7 +1121,9 @@ while (++index < length) { var key = props[index]; - object[key] = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; + object[key] = customizer + ? customizer(object[key], source[key], key, object, source) + : source[key]; } return object; } @@ -1170,74 +1203,86 @@ if (typeof result != 'undefined') { return result; } - var isObj = isObject(value); - if (isObj) { + var isArr = isArray(value), + isShallow = !isDeep; + + if (isArr) { + result = isShallow ? slice(value) : value.constructor(value.length); + + // add array properties assigned by `RegExp#exec` + if (typeof value[0] == 'string' && hasOwnProperty.call(value, 'index')) { + result.index = value.index; + result.input = value.input; + } + if (isShallow) { + return result; + } + } + else { + if (!isObject(value)) { + return value; + } var className = toString.call(value); if (!cloneableClasses[className]) { return value; } + var isArgs = className == argsClass, + isObj = !isArgs && className == objectClass; + + if (isShallow && (isArgs || isObj)) { + result = baseAssign({}, value); + if (isObj) { + return result; + } + } var Ctor = value.constructor; if (className == objectClass && !(isFunction(Ctor) && (Ctor instanceof Ctor))) { Ctor = Object; } - switch (className) { - case arrayBufferClass: - return cloneBuffer(value); - - case boolClass: - case dateClass: - return new Ctor(+value); - - case float32Class: case float64Class: - case int8Class: case int16Class: case int32Class: - case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class: - return new Ctor(cloneBuffer(value.buffer)); - - case numberClass: - case stringClass: - return new Ctor(value); - - case regexpClass: - result = Ctor(value.source, reFlags.exec(value)); - result.lastIndex = value.lastIndex; - return result; + if (isDeep && (isArgs || isObj)) { + result = new Ctor; } - } else { - return value; - } - var isArr = isArray(value); - if (isDeep) { - // check for circular references and return corresponding clone - stackA || (stackA = []); - stackB || (stackB = []); + else { + switch (className) { + case arrayBufferClass: + return cloneBuffer(value); - var length = stackA.length; - while (length--) { - if (stackA[length] == value) { - return stackB[length]; + case boolClass: + case dateClass: + return new Ctor(+value); + + case float32Class: case float64Class: + case int8Class: case int16Class: case int32Class: + case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class: + return new Ctor(cloneBuffer(value.buffer)); + + case numberClass: + case stringClass: + return new Ctor(value); + + case regexpClass: + result = Ctor(value.source, reFlags.exec(value)); + result.lastIndex = value.lastIndex; + return result; } } - result = isArr ? Ctor(value.length) : new Ctor; } - else { - result = isArr ? slice(value) : baseAssign({}, value); - } - if (className == argsClass) { + if (isArgs) { result.length = value.length; } - // add array properties assigned by `RegExp#exec` - else if (isArr) { - if (hasOwnProperty.call(value, 'index')) { - result.index = value.index; - } - if (hasOwnProperty.call(value, 'input')) { - result.input = value.input; - } - } - // exit for shallow clone - if (!isDeep) { + if (isShallow) { return result; } + // check for circular references and return corresponding clone + stackA || (stackA = []); + stackB || (stackB = []); + + var length = stackA.length; + while (length--) { + if (stackA[length] == value) { + return stackB[length]; + } + } // add the source value to the stack of traversed objects // and associate it with its clone stackA.push(value); @@ -1286,6 +1331,17 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {number} data[1] The bitmask of flags to compose. See `createWrapper` + * for more details. + * @param {number} data[2] The arity of `data[0]`. + * @param {*} [data[3]] The `this` binding of `data[0]`. + * @param {Array} [data[4]] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [data[5]] An array of arguments to append to those + * provided to the new function. + * @param {Array} [data[6]] An array of `data[4]` placeholder indexes. + * @param {Array} [data[7]] An array of `data[5]` placeholder indexes. * @returns {Function} Returns the new function. */ function baseCreateWrapper(data) { @@ -1427,18 +1483,17 @@ * @returns {Array|Object|string} Returns `collection`. */ function baseEach(collection, iterator) { + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return baseForOwn(collection, iterator); + } var index = -1, - iterable = collection, - length = collection ? collection.length : 0; + iterable = toIterable(collection); - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - while (++index < length) { - if (iterator(iterable[index], index, collection) === false) { - break; - } + while (++index < length) { + if (iterator(iterable[index], index, collection) === false) { + break; } - } else { - baseForOwn(collection, iterator); } return collection; } @@ -1453,17 +1508,15 @@ * @returns {Array|Object|string} Returns `collection`. */ function baseEachRight(collection, iterator) { - var iterable = collection, - length = collection ? collection.length : 0; - - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - while (length--) { - if (iterator(iterable[length], length, collection) === false) { - break; - } + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return baseForOwnRight(collection, iterator); + } + var iterable = toIterable(collection); + while (length--) { + if (iterator(iterable[length], length, collection) === false) { + break; } - } else { - baseForOwnRight(collection, iterator); } return collection; } @@ -1516,7 +1569,7 @@ * @private * @param {Array|Object|string} collection The collection to search. * @param {Function} predicate The function called per iteration. - * @param {Function} eachFunc The function to iterate over the collection. + * @param {Function} eachFunc The function to iterate over `collection`. * @param {boolean} [retKey=false] Specify returning the key of the found * element instead of the element itself. * @returns {*} Returns the found element or its key, else `undefined`. @@ -1730,34 +1783,18 @@ if (valClass != othClass) { return false; } - switch (valClass) { - case boolClass: - case dateClass: - // 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 +value == +other; - - case numberClass: - // treat `NaN` vs. `NaN` as equal - return (value != +value) - ? other != +other - // but treat `-0` vs. `+0` as not equal - : (value == 0 ? (1 / value == 1 / other) : value == +other); - - case regexpClass: - case stringClass: - // coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and - // treat strings primitives and string objects as equal - return value == String(other); - } var isArr = arrayLikeClasses[valClass], isErr = valClass == errorClass; - if (!isArr) { - // exit for things like functions and DOM nodes - if (!(isErr || valClass == objectClass)) { + if (isArr) { + var valLength = value.length, + othLength = other.length; + + if (valLength != othLength && !(isWhere && othLength > valLength)) { return false; } + } + else if (isErr || (valClass == objectClass)) { // unwrap any `lodash` wrapped values var valWrapped = hasOwnProperty.call(value, '__wrapped__'), othWrapped = hasOwnProperty.call(other, '__wrapped__'); @@ -1765,80 +1802,32 @@ if (valWrapped || othWrapped) { return baseIsEqual(valWrapped ? value.__wrapped__ : value, othWrapped ? other.__wrapped__ : other, customizer, isWhere, stackA, stackB); } - var hasValCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'), - hasOthCtor = !othIsArg && hasOwnProperty.call(other, 'constructor'); - - if (hasValCtor != hasOthCtor) { - return false; - } - if (!hasValCtor) { - // in older versions of Opera, `arguments` objects have `Array` constructors - var valCtor = valIsArg ? Object : value.constructor, - othCtor = othIsArg ? Object : other.constructor; + // in older versions of Opera, `arguments` objects have `Array` constructors + var valCtor = valIsArg ? Object : value.constructor, + othCtor = othIsArg ? Object : other.constructor; + if (isErr) { // error objects of different types are not equal - if (isErr && valCtor.prototype.name != othCtor.prototype.name) { + if (valCtor.prototype.name != othCtor.prototype.name) { return false; } - // non `Object` object instances with different constructors are not equal - if (valCtor != othCtor && - !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && - ('constructor' in value && 'constructor' in other) - ) { + } else { + var valHasCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'), + othHasCtor = !othIsArg && hasOwnProperty.call(other, 'constructor'); + + if (valHasCtor != othHasCtor) { return false; } - } - } - // assume cyclic structures are equal - // the algorithm for detecting cyclic structures is adapted from ES 5.1 - // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3) - stackA || (stackA = []); - stackB || (stackB = []); - - var length = stackA.length; - while (length--) { - if (stackA[length] == value) { - return stackB[length] == other; - } - } - var index = -1; - - // add `value` and `other` to the stack of traversed objects - stackA.push(value); - stackB.push(other); - - // recursively compare objects and arrays (susceptible to call stack limits) - if (isArr) { - var othLength = other.length; - length = value.length; - result = length == othLength; - - if (result || (isWhere && othLength > length)) { - // deep compare the contents, ignoring non-numeric properties - while (++index < length) { - var valValue = value[index]; - if (isWhere) { - var othIndex = othLength; - while (othIndex--) { - result = baseIsEqual(valValue, other[othIndex], customizer, isWhere, stackA, stackB); - if (result) { - break; - } - } - } else { - var othValue = other[index]; - result = customizer ? customizer(valValue, othValue, index) : undefined; - if (typeof result == 'undefined') { - result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); - } - } - if (!result) { - break; + if (!valHasCtor) { + // non `Object` object instances with different constructors are not equal + if (valCtor != othCtor && + !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && + ('constructor' in value && 'constructor' in other) + ) { + return false; } } } - } - else { var valProps = isErr ? ['message', 'name'] : keys(value), othProps = isErr ? valProps : keys(other); @@ -1848,24 +1837,85 @@ if (othIsArg) { othProps.push('length'); } - length = valProps.length; - result = length == othProps.length; + valLength = valProps.length; + othLength = othProps.length; + if (valLength != othLength && !isWhere) { + return false; + } + } + else { + switch (valClass) { + case boolClass: + case dateClass: + // 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 +value == +other; - if (result || isWhere) { - while (++index < length) { - var key = valProps[index]; - result = isErr || hasOwnProperty.call(other, key); + case numberClass: + // treat `NaN` vs. `NaN` as equal + return (value != +value) + ? other != +other + // but treat `-0` vs. `+0` as not equal + : (value == 0 ? (1 / value == 1 / other) : value == +other); - if (result) { - valValue = value[key]; - othValue = other[key]; - result = customizer ? customizer(valValue, othValue, key) : undefined; - if (typeof result == 'undefined') { - result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); + case regexpClass: + case stringClass: + // coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and + // treat strings primitives and string objects as equal + return value == String(other); + } + return false; + } + // assume cyclic structures are equal + // the algorithm for detecting cyclic structures is adapted from ES 5.1 + // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3) + stackA || (stackA = []); + stackB || (stackB = []); + + var index = stackA.length; + while (index--) { + if (stackA[index] == value) { + return stackB[index] == other; + } + } + // add `value` and `other` to the stack of traversed objects + stackA.push(value); + stackB.push(other); + + // recursively compare objects and arrays (susceptible to call stack limits) + result = true; + if (isArr) { + // deep compare the contents, ignoring non-numeric properties + while (result && ++index < valLength) { + var valValue = value[index]; + if (isWhere) { + var othIndex = othLength; + while (othIndex--) { + result = baseIsEqual(valValue, other[othIndex], customizer, isWhere, stackA, stackB); + if (result) { + break; } } - if (!result) { - break; + } else { + var othValue = other[index]; + result = customizer ? customizer(valValue, othValue, index) : undefined; + if (typeof result == 'undefined') { + result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); + } + } + } + } + else { + while (result && ++index < valLength) { + var key = valProps[index]; + result = isErr || hasOwnProperty.call(other, key); + + if (result) { + valValue = value[key]; + othValue = other[key]; + result = customizer ? customizer(valValue, othValue, key) : undefined; + if (typeof result == 'undefined') { + result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB); } } } @@ -1890,9 +1940,12 @@ function baseInvoke(collection, methodName, args) { var index = -1, isFunc = typeof methodName == 'function', - length = collection && collection.length, - result = Array(length < 0 ? 0 : length >>> 0); + length = collection ? collection.length : 0, + result = []; + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + result.length = length; + } baseEach(collection, function(value) { var func = isFunc ? methodName : (value != null && value[methodName]); result[++index] = func ? func.apply(value, args) : undefined; @@ -1932,6 +1985,7 @@ */ function baseMerge(object, source, customizer, stackA, stackB) { var isSrcArr = isArrayLike(source); + (isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) { var isArr = srcValue && isArrayLike(srcValue), isObj = srcValue && isPlainObject(srcValue), @@ -1959,9 +2013,9 @@ } } var result = customizer ? customizer(value, srcValue, key, object, source) : undefined, - isShallow = typeof result != 'undefined'; + isDeep = typeof result == 'undefined'; - if (!isShallow) { + if (isDeep) { result = isArr ? (isArray(value) ? value : []) : (isPlainObject(value) ? value : {}); @@ -1972,7 +2026,7 @@ stackB.push(result); // recursively merge objects and arrays (susceptible to call stack limits) - if (!isShallow) { + if (isDeep) { baseMerge(result, srcValue, customizer, stackA, stackB); } object[key] = result; @@ -2074,19 +2128,21 @@ } /** - * The base implementation of `_.reduce` without support for callback - * shorthands or `this` binding. + * The base implementation of `_.reduce` and `_.reduceRight` without support + * for callback shorthands or `this` binding, which iterates over `collection` + * usingthe provided `eachFunc`. * * @private * @param {Array|Object|string} collection The collection to iterate over. * @param {Function} iterator The function called per iteration. - * @param {*} [accumulator] The initial value. - * @param {boolean} [initFromCollection=false] Specify using the first element + * @param {*} accumulator The initial value. + * @param {boolean} initFromCollection Specify using the first element * of `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the accumulated value. */ - function baseReduce(collection, iterator, accumulator, initFromCollection) { - baseEach(collection, function(value, index, collection) { + function baseReduce(collection, iterator, accumulator, initFromCollection, eachFunc) { + eachFunc(collection, function(value, index, collection) { accumulator = initFromCollection ? (initFromCollection = false, value) : iterator(accumulator, value, index, collection) @@ -2114,6 +2170,37 @@ return !!result; } + /** + * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` without + * support for callback shorthands and `this` binding. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iterator The function called per iteration. + * @param {boolean} [retHighest=false] Specify returning the highest, instead + * of the lowest, index at which a value should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndex(array, value, iterator, retHighest) { + var low = 0, + high = array ? array.length : low; + + value = iterator(value); + while (low < high) { + var mid = (low + high) >>> 1, + computed = iterator(array[mid]); + + if (retHighest ? computed <= value : computed < value) { + low = mid + 1; + } else { + high = mid; + } + } + return high; + } + /** * The base implementation of `_.uniq` without support for callback shorthands * and `this` binding. @@ -2197,32 +2284,6 @@ return result; } - /** - * Compiles a function from `source` using the `varNames` and `varValues` - * pairs to import free variables into the compiled function. If `sourceURL` - * is provided it is used as the sourceURL for the compiled function. - * - * @private - * @param {string} source The source to compile. - * @param {Array} varNames An array of free variable names. - * @param {Array} varValues An array of free variable values. - * @param {string} [sourceURL=''] The sourceURL of the source. - * @returns {Function} Returns the compiled function. - */ - function compileFunction(source, varNames, varValues, sourceURL) { - sourceURL = sourceURL ? ('\n/*\n//# sourceURL=' + sourceURL + '\n*/') : ''; - try { - // provide the compiled function's source by its `toString` method or - // the `source` property as a convenience for inlining compiled templates - var result = Function(varNames, 'return ' + source + sourceURL).apply(undefined, varValues); - result.source = source; - } catch(e) { - e.source = source; - throw e; - } - return result; - } - /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -2360,6 +2421,8 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {*} data[3] The `this` binding of `data[0]`. * @returns {Function} Returns the new bound function. */ function createBindWrapper(data) { @@ -2439,14 +2502,19 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {number} data[1] The bitmask of flags to compose. See `createWrapper` + * for more details. + * @param {*} [data[3]] The `this` binding of `data[0]`. + * @param {Array} data[4] An array of arguments to prepend to those + * provided to the new function. * @returns {Function} Returns the new bound function. */ function createPartialWrapper(data) { var func = data[0], bitmask = data[1], thisArg = data[3], - partialArgs = data[4], - partialHolders = data[6]; + partialArgs = data[4]; var isBind = bitmask & BIND_FLAG, Ctor = createCtorWrapper(func); @@ -2458,8 +2526,7 @@ argsLength = arguments.length, leftIndex = -1, leftLength = partialArgs.length, - args = Array(argsLength + leftLength), - thisBinding = isBind ? thisArg : this; + args = Array(argsLength + leftLength); while (++leftIndex < leftLength) { args[leftIndex] = partialArgs[leftIndex]; @@ -2467,7 +2534,7 @@ while (argsLength--) { args[leftIndex++] = arguments[argsIndex++]; } - return (this instanceof wrapper ? Ctor : func).apply(thisBinding, args); + return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args); } return wrapper; } @@ -2556,7 +2623,7 @@ } // merge flags data[1] |= bitmask; - return createWrapper.apply(null, data); + return createWrapper.apply(undefined, data); } if (isPartial) { var partialHolders = getHolders(partialArgs); @@ -2733,6 +2800,21 @@ return result; } + /** + * Converts `collection` to an array if it is not an array-like value. + * + * @private + * @param {Array|Object|string} collection The collection to inspect. + * @returns {Array|Object} Returns the iterable object. + */ + function toIterable(collection) { + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return values(collection); + } + return collection || []; + } + /*--------------------------------------------------------------------------*/ /** @@ -3038,7 +3120,7 @@ /** * This method is like `_.findIndex` except that it iterates over elements - * of a collection from right to left. + * of `collection` from right to left. * * If a property name is provided for `predicate` the created "_.pluck" style * callback returns the property value of the given element. @@ -3144,9 +3226,10 @@ } /** - * Gets the index at which the first occurrence of `value` is found using - * strict equality for comparisons, i.e. `===`. If the array is already sorted - * providing `true` for `fromIndex` performs a faster binary search. + * Gets the index at which the first occurrence of `value` is found in `array` + * using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, + * it is used as the offset from the end of the collection. If `array` is + * sorted providing `true` for `fromIndex` performs a faster binary search. * * @static * @memberOf _ @@ -3166,11 +3249,12 @@ * // => 4 * * // performing a binary search - * _.indexOf([1, 1, 2, 2, 3, 3], 2, true); + * _.indexOf([4, 4, 5, 5, 6, 6], 5, true); * // => 2 */ function indexOf(array, value, fromIndex) { var length = array ? array.length : 0; + if (typeof fromIndex == 'number') { fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); } else if (fromIndex) { @@ -3274,16 +3358,16 @@ } /** - * Gets the index at which the last occurrence of `value` is found using - * strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, - * it is used as the offset from the end of the collection. + * 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. + * @param {boolean|number} [fromIndex=array.length-1] The index to search from + * or `true` to perform a binary search on a sorted array. * @returns {number} Returns the index of the matched value, else `-1`. * @example * @@ -3293,11 +3377,20 @@ * // using `fromIndex` * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); * // => 1 + * + * // performing a binary search + * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); + * // => 3 */ function lastIndexOf(array, value, fromIndex) { - var index = array ? array.length : 0; + var length = array ? array.length : 0, + index = length; + if (typeof fromIndex == 'number') { index = (fromIndex < 0 ? nativeMax(index + fromIndex, 0) : nativeMin(fromIndex || 0, index - 1)) + 1; + } else if (fromIndex) { + index = sortedLastIndex(array, value) - 1; + return (length && array[index] === value) ? index : -1; } while (index--) { if (array[index] === value) { @@ -3483,11 +3576,11 @@ } /** - * Uses a binary search to determine the smallest index at which a value - * should be inserted into a given sorted array in order to maintain the sort - * order of the array. If an iterator function is provided it is executed for - * `value` and each element of `array` to compute their sort ranking. The - * iterator function is bound to `thisArg` and invoked with one argument; (value). + * Uses a binary search to determine the lowest index at which a value should + * be inserted into a given sorted array in order to maintain the sort order + * of the array. If an iterator function is provided it is executed for `value` + * and each element of `array` to compute their sort ranking. The iterator + * function is bound to `thisArg` and invoked with one argument; (value). * * If a property name is provided for `iterator` the created "_.pluck" style * callback returns the property value of the given element. @@ -3509,38 +3602,53 @@ * into `array`. * @example * - * _.sortedIndex([20, 30, 50], 40); + * _.sortedIndex([30, 50], 40); + * // => 1 + * + * _.sortedIndex([4, 4, 5, 5, 6, 6], 5); * // => 2 * - * var dict = { - * 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'forty': 40, 'fifty': 50 } - * }; + * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; * * // using an iterator function - * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'forty', function(word) { - * return this.wordToNumber[word]; + * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) { + * return this.data[word]; * }, dict); - * // => 2 + * // => 1 * * // using "_.pluck" callback shorthand - * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); - * // => 2 + * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); + * // => 1 */ function sortedIndex(array, value, iterator, thisArg) { - var low = 0, - high = array ? array.length : low; + iterator = iterator == null ? identity : lodash.callback(iterator, thisArg, 1); + return baseSortedIndex(array, value, iterator); + } - // explicitly reference `identity` for better inlining in Firefox - iterator = iterator ? lodash.callback(iterator, thisArg, 1) : identity; - value = iterator(value); - - while (low < high) { - var mid = (low + high) >>> 1; - (iterator(array[mid]) < value) - ? (low = mid + 1) - : (high = mid); - } - return low; + /** + * This method is like `_.sortedIndex` except that it returns the highest + * index at which a value should be inserted into a given sorted array in + * order to maintain the sort order of the array. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to evaluate. + * @param {Function|Object|string} [iterator=identity] The function called + * per iteration. If a property name or object is provided it is used to + * create a "_.pluck" or "_.where" style callback respectively. + * @param {*} [thisArg] The `this` binding of `iterator`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5); + * // => 4 + */ + function sortedLastIndex(array, value, iterator, thisArg) { + iterator = iterator == null ? identity : lodash.callback(iterator, thisArg, 1); + return baseSortedIndex(array, value, iterator, true); } /** @@ -3785,6 +3893,35 @@ return baseUniq(array, isSorted, iterator); } + /** + * 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) { + var index = -1, + length = isObject(length = max(array, 'length')) && length.length || 0, + result = Array(length); + + while (++index < length) { + result[index] = pluck(array, index); + } + return result; + } + /** * Creates an array excluding all provided values using strict equality for * comparisons, i.e. `===`. @@ -3840,33 +3977,20 @@ /** * 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. If a zipped value is provided its corresponding - * unzipped value is returned. + * of the given arrays, and so on. * * @static * @memberOf _ - * @alias unzip * @category Array * @param {...Array} [arrays] The arrays to process. - * @returns {Array} Returns the array of grouped elements. + * @returns {Array} Returns the new array of grouped elements. * @example * * _.zip(['fred', 'barney'], [30, 40], [true, false]); * // => [['fred', 30, true], ['barney', 40, false]] - * - * _.unzip([['fred', 30, true], ['barney', 40, false]]); - * // => [['fred', 'barney'], [30, 40], [true, false]] */ function zip() { - var array = arguments.length > 1 ? arguments : arguments[0], - index = -1, - length = isObject(length = max(array, 'length')) && length.length || 0, - result = Array(length); - - while (++index < length) { - result[index] = pluck(array, index); - } - return result; + return unzip(arguments); } /** @@ -4049,6 +4173,11 @@ * // => ['fred', 'pebbles'] */ function at(collection) { + var length = collection ? collection.length : 0; + + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + collection = toIterable(collection); + } return baseAt(collection, baseFlatten(arguments, false, false, 1)); } @@ -4081,6 +4210,7 @@ */ function contains(collection, target, fromIndex) { var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { collection = values(collection); length = collection.length; @@ -4141,7 +4271,7 @@ }); /** - * Checks if the predicate returns truthy for **all** elements of a collection. + * Checks if the predicate returns truthy for **all** elements of `collection`. * The predicate is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * @@ -4190,7 +4320,7 @@ } /** - * Iterates over elements of a collection returning an array of all elements + * Iterates over elements of `collection` returning an array of all elements * the predicate returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * @@ -4237,7 +4367,7 @@ } /** - * Iterates over elements of a collection, returning the first element that + * Iterates over elements of `collection`, returning the first element that * the predicate returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * @@ -4289,8 +4419,8 @@ } /** - * This method is like `_.find` except that it iterates over elements of a - * collection from right to left. + * This method is like `_.find` except that it iterates over elements of + * `collection` from right to left. * * @static * @memberOf _ @@ -4340,7 +4470,7 @@ } /** - * Iterates over elements of a collection executing `iterator` for each + * Iterates over elements of `collection` executing `iterator` for each * element. The `iterator` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). Iterator functions may exit iteration early * by explicitly returning `false`. @@ -4359,8 +4489,8 @@ * @returns {Array|Object|string} Returns `collection`. * @example * - * _([1, 2, 3]).forEach(function(n) { console.log(n); }).join(','); - * // => logs each number and returns '1,2,3' + * _([1, 2, 3]).forEach(function(n) { console.log(n); }); + * // => logs each value and returns the array * * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); }); * // => logs each value-key pair and returns the object (property order is not guaranteed across environments) @@ -4373,7 +4503,7 @@ /** * This method is like `_.forEach` except that it iterates over elements of - * a collection from right to left. + * `collection` from right to left. * * @static * @memberOf _ @@ -4386,7 +4516,7 @@ * @example * * _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(','); - * // => logs each number from right to left and returns '3,2,1' + * // => logs each value from right to left and returns the array */ function forEachRight(collection, iterator, thisArg) { return (typeof iterator == 'function' && typeof thisArg == 'undefined' && isArray(collection)) @@ -4396,7 +4526,7 @@ /** * Creates an object composed of keys generated from the results of running - * each element of a collection through `iterator`. The corresponding + * each element of `collection` through `iterator`. The corresponding * value of each key is an array of the elements responsible for generating * the key. The `iterator` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). @@ -4553,7 +4683,7 @@ } /** - * Retrieves the maximum value of a collection. If the collection is empty + * Retrieves the maximum value of `collection`. If the collection is empty * or falsey `-Infinity` is returned. If an iterator function is provided it * is executed for each value in the collection to generate the criterion by * which the value is ranked. The `iterator` is bound to `thisArg` and invoked @@ -4631,7 +4761,7 @@ } /** - * Retrieves the minimum value of a collection. If the collection is empty + * Retrieves the minimum value of `collection`. If the collection is empty * or falsey `Infinity` is returned. If an iterator function is provided it * is executed for each value in the collection to generate the criterion by * which the value is ranked. The `iterator` is bound to `thisArg` and invoked @@ -4808,15 +4938,13 @@ * // => { 'a': 3, 'b': 6, 'c': 9 } */ function reduce(collection, iterator, accumulator, thisArg) { - iterator = lodash.callback(iterator, thisArg, 4); - var func = isArray(collection) ? arrayReduce : baseReduce; - return func(collection, iterator, accumulator, arguments.length < 3); + return func(collection, lodash.callback(iterator, thisArg, 4), accumulator, arguments.length < 3, baseEach); } /** - * This method is like `_.reduce` except that it iterates over elements of a - * collection from right to left. + * This method is like `_.reduce` except that it iterates over elements of + * `collection` from right to left. * * @static * @memberOf _ @@ -4834,19 +4962,12 @@ * // => [4, 5, 2, 3, 0, 1] */ function reduceRight(collection, iterator, accumulator, thisArg) { - var noaccum = arguments.length < 3; - iterator = lodash.callback(iterator, thisArg, 4); - - baseEachRight(collection, function(value, index, collection) { - accumulator = noaccum - ? (noaccum = false, value) - : iterator(accumulator, value, index, collection); - }); - return accumulator; + var func = isArray(collection) ? arrayReduceRight : baseReduce; + return func(collection, lodash.callback(iterator, thisArg, 4), accumulator, arguments.length < 3, baseEachRight); } /** - * The opposite of `_.filter`; this method returns the elements of a collection + * The opposite of `_.filter`; this method returns the elements of `collection` * the predicate does **not** return truthy for. * * If a property name is provided for `predicate` the created "_.pluck" style @@ -4907,12 +5028,9 @@ * // => [3, 1] */ function sample(collection, n, guard) { - var length = collection ? collection.length : 0; + collection = toIterable(collection); - if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { - collection = values(collection); - length = collection.length; - } + var length = collection.length; if (n == null || guard) { return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } @@ -4937,21 +5055,25 @@ * // => [4, 1, 3, 2] */ function shuffle(collection) { - var index = -1, - length = collection && collection.length, - result = Array(length < 0 ? 0 : length >>> 0); + collection = toIterable(collection); + + var index = -1, + length = collection.length, + result = Array(length); + + while (++index < length) { + var value = collection[index], + rand = baseRandom(0, index); - baseEach(collection, function(value) { - var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; - }); + } return result; } /** - * Gets the size of the collection by returning `collection.length` for arrays - * and array-like objects or the number of own enumerable properties for objects. + * Gets the size of the collection by returning `collection.length` for + * array-like values or the number of own enumerable properties for objects. * * @static * @memberOf _ @@ -4977,7 +5099,7 @@ } /** - * Checks if the predicate returns truthy for **any** element of a collection. + * Checks if the predicate returns truthy for **any** element of `collection`. * The function returns as soon as it finds a passing value and does not iterate * over the entire collection. The predicate is bound to `thisArg` and invoked * with three arguments; (value, index|key, collection). @@ -5077,10 +5199,13 @@ */ function sortBy(collection, iterator, thisArg) { var index = -1, - length = collection && collection.length, + length = collection ? collection.length : 0, multi = iterator && isArray(iterator), - result = Array(length < 0 ? 0 : length >>> 0); + result = []; + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + result.length = length; + } if (!multi) { iterator = lodash.callback(iterator, thisArg, 3); } @@ -5120,12 +5245,8 @@ * // => [2, 3, 4] */ function toArray(collection) { - var length = collection ? collection.length : 0; - - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - return slice(collection); - } - return values(collection); + var iterable = toIterable(collection); + return iterable === collection ? slice(collection) : iterable; } /** @@ -5162,14 +5283,13 @@ /*--------------------------------------------------------------------------*/ /** - * Creates a function that executes `func`, with the `this` binding and - * arguments of the created function, only after being called `n` times. + * The opposite of `_.before`; this method creates a function that executes + * `func` only after it is called `n` times. * * @static * @memberOf _ * @category Function - * @param {number} n The number of times the function must be called before - * `func` is executed. + * @param {number} n The number of calls before `func` is executed. * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. * @example @@ -5177,13 +5297,13 @@ * var saves = ['profile', 'settings']; * * var done = _.after(saves.length, function() { - * console.log('Done saving!'); + * console.log('done saving!'); * }); * * _.forEach(saves, function(type) { * asyncSave({ 'type': type, 'complete': done }); * }); - * // => logs 'Done saving!', after all saves have completed + * // => logs 'done saving!' after all saves have completed */ function after(n, func) { if (!isFunction(func)) { @@ -5197,6 +5317,36 @@ }; } + /** + * Creates a function that executes `func`, with the `this` binding and + * arguments of the created function, until it is called `n` times. + * + * @static + * @memberOf _ + * @category Function + * @param {number} n The number of times `func` may be executed. + * @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 5 contacts to the list + */ + function before(n, func) { + var result; + if (!isFunction(func)) { + throw new TypeError(funcErrorText); + } + return function() { + if (--n > 0) { + result = func.apply(this, arguments); + } else { + func = null; + } + return result; + }; + } + /** * Creates a function that invokes `func` with the `this` binding of `thisArg` * and prepends any additional `bind` arguments to those provided to the bound @@ -5252,12 +5402,14 @@ * * _.bindAll(view); * jQuery('#docs').on('click', view.onClick); - * // => logs 'clicked docs', when the button is clicked + * // => logs 'clicked docs' when the element is clicked */ function bindAll(object) { - return baseBindAll(object, arguments.length > 1 - ? baseFlatten(arguments, false, false, 1) - : functions(object)); + return baseBindAll(object, + arguments.length > 1 + ? baseFlatten(arguments, false, false, 1) + : functions(object) + ); } /** @@ -5748,6 +5900,7 @@ * * @static * @memberOf _ + * @type Function * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. @@ -5758,25 +5911,7 @@ * initialize(); * // `initialize` executes `createApplication` once */ - function once(func) { - var ran, - result; - - if (!isFunction(func)) { - throw new TypeError(funcErrorText); - } - return function() { - if (ran) { - return result; - } - ran = true; - result = func.apply(this, arguments); - - // clear the `func` variable so the function may be garbage collected - func = null; - return result; - }; - } + var once = partial(before, 2); /** * Creates a function that invokes `func` with any additional `partial` arguments @@ -6123,7 +6258,7 @@ } var args = slice(arguments); args.push(assignDefaults); - return assign.apply(null, args); + return assign.apply(undefined, args); } /** @@ -6253,8 +6388,8 @@ } /** - * This method is like `_.forIn` except that it iterates over elements of a - * collection in the opposite order. + * This method is like `_.forIn` except that it iterates over properties of + * `object` in the opposite order. * * @static * @memberOf _ @@ -6310,8 +6445,8 @@ } /** - * This method is like `_.forOwn` except that it iterates over elements of a - * collection in the opposite order. + * This method is like `_.forOwn` except that it iterates over properties of + * `object` in the opposite order. * * @static * @memberOf _ @@ -6532,8 +6667,8 @@ /** * Checks if a collection is empty. A value is considered empty unless it is - * an array, array-like object, or string with a length greater than `0` or - * an object with own enumerable properties. + * an array-like value with a length greater than `0` or an object with own + * enumerable properties. * * @static * @memberOf _ @@ -6558,9 +6693,8 @@ * // => false */ function isEmpty(value) { - var result = true; if (value == null) { - return result; + return true; } var length = value.length; if ((typeof length == 'number' && length > -1 && length <= maxSafeInteger) && @@ -6568,11 +6702,7 @@ (typeof value == 'object' && isFunction(value.splice)))) { return !length; } - baseForOwn(value, function() { - result = false; - return result; - }); - return result; + return !keys(value).length; } /** @@ -6584,7 +6714,7 @@ * * Note: This method supports comparing arrays, booleans, `Date` objects, * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes - * are **not** supported. A customizer function may be used to extend support + * are **not** supported. Provide a customizer function to extend support * for comparing other values. * * @static @@ -7202,9 +7332,11 @@ if (object == null) { return {}; } - return basePick(Object(object), typeof predicate == 'function' - ? lodash.callback(predicate, thisArg, 3) - : baseFlatten(arguments, false, false, 1)); + return basePick(Object(object), + typeof predicate == 'function' + ? lodash.callback(predicate, thisArg, 3) + : baseFlatten(arguments, false, false, 1) + ); } /** @@ -7240,6 +7372,7 @@ */ function transform(object, iterator, accumulator, thisArg) { var isArr = isArrayLike(object); + if (accumulator == null) { if (isArr) { accumulator = []; @@ -7706,7 +7839,7 @@ * compiled({ 'name': 'mustache' }); * // => 'hello mustache!' * - * // using the `imports` option to import jQuery + * // using the `imports` option to import `jQuery` as `jq` * var text = '<% jq.each(people, function(name) { %>
  • <%- name %>
  • <% }); %>'; * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); * compiled({ 'people': ['fred', 'barney'] }); @@ -7764,6 +7897,7 @@ // use a sourceURL for easier debugging // http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl var sourceURL = options.sourceURL || ('/lodash/template/source[' + (templateCounter++) + ']'); + sourceURL = sourceURL ? ('\n/*\n//# sourceURL=' + sourceURL + '\n*/') : ''; string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { interpolateValue || (interpolateValue = esTemplateValue); @@ -7822,7 +7956,17 @@ source + 'return __p\n}'; - return compileFunction(source, importsKeys, importsValues, sourceURL); + var result = attempt(function() { + return Function(importsKeys, 'return ' + source + sourceURL).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 (result instanceof Error) { + throw result; + } + return result; } /** @@ -7923,7 +8067,7 @@ * @param {string} [string=''] The string to truncate. * @param {Object|number} [options] The options object or maximum string length. * @param {number} [options.length=30] The maximum string length. - * @param {string} [options.omission='...'] The string used to indicate text is omitted. + * @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 @@ -8019,6 +8163,34 @@ /*--------------------------------------------------------------------------*/ + /** + * Attempts to execute `func`, returning either the result or the caught + * error object. + * + * @static + * @memberOf _ + * @category Utility + * @param {*} func The function to attempt. + * @returns {*} Returns the `func` result or error object. + * @example + * + * // avoid throwing errors for invalid selectors + * var elements = _.attempt(function() { + * return document.querySelectorAll(selector); + * }); + * + * if (elements instanceof Error) { + * elements = []; + * } + */ + function attempt(func) { + try { + return func(); + } catch(e) { + return isError(e) ? e : Error(e); + } + } + /** * Creates a function bound to an optional `thisArg`. If `func` is a property * name the created callback returns the property value for a given element. @@ -8286,8 +8458,7 @@ * @category Utility * @example * - * var stamp = _.now(); - * _.defer(function() { console.log(_.now() - stamp); }); + * _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); * // => logs the number of milliseconds it took for the deferred function to be called */ var now = nativeNow || function() { @@ -8307,7 +8478,7 @@ * @memberOf _ * @category Utility * @param {string} value The value to parse. - * @param {number} [radix] The radix used to interpret the value to parse. + * @param {number} [radix] The radix to interpret `value` by. * @returns {number} Returns the converted integer. * @example * @@ -8531,14 +8702,18 @@ * // => also calls `mage.castSpell(n)` three times */ function times(n, iterator, thisArg) { - n = n < 0 ? 0 : n >>> 0; + n = nativeIsFinite(n = +n) && n > -1 ? n : 0; iterator = baseCallback(iterator, thisArg, 1); var index = -1, - result = Array(n); + result = Array(nativeMin(n, maxArrayLength)); while (++index < n) { - result[index] = iterator(index); + if (index < maxArrayLength) { + result[index] = iterator(index); + } else { + iterator(index); + } } return result; } @@ -8573,6 +8748,7 @@ lodash.after = after; lodash.assign = assign; lodash.at = at; + lodash.before = before; lodash.bind = bind; lodash.bindAll = bindAll; lodash.bindKey = bindKey; @@ -8648,6 +8824,7 @@ lodash.transform = transform; lodash.union = union; lodash.uniq = uniq; + lodash.unzip = unzip; lodash.values = values; lodash.valuesIn = valuesIn; lodash.where = where; @@ -8667,7 +8844,6 @@ lodash.select = filter; lodash.tail = rest; lodash.unique = uniq; - lodash.unzip = zip; // add functions to `lodash.prototype` mixin(lodash, baseAssign({}, lodash)); @@ -8675,6 +8851,7 @@ /*--------------------------------------------------------------------------*/ // add functions that return unwrapped values when chaining + lodash.attempt = attempt; lodash.camelCase = camelCase; lodash.capitalize = capitalize; lodash.clone = clone; @@ -8732,9 +8909,10 @@ lodash.result = result; lodash.runInContext = runInContext; lodash.size = size; + lodash.snakeCase = snakeCase; lodash.some = some; lodash.sortedIndex = sortedIndex; - lodash.snakeCase = snakeCase; + lodash.sortedLastIndex = sortedLastIndex; lodash.startsWith = startsWith; lodash.template = template; lodash.trim = trim; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 53be29f6b..9bbc32898 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -4,66 +4,66 @@ * Build: `lodash modern -o ./dist/lodash.js` */ ;(function(){function n(n,t){for(var r=-1,e=t.length,u=Array(e);++rt||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202>>0:0,u=ce(e);++ri(t,f)&&c.push(f); -return c}function $t(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number"&&-1f)for(;++po?0:o>>>0); -return $t(n,function(n){var o=u?t:null!=n&&n[t];i[++e]=o?o.apply(n,r):d}),i}function Gt(n,t){var r=[];return $t(n,function(n,e,u){r.push(t(n,e,u))}),r}function Ht(n,t,r,e,u){var o=yr(t);return(o?_t:Kt)(t,function(t,i,a){var f=t&&yr(t),c=t&&lu(t),l=n[i];if(f||c){for(e||(e=[]),u||(u=[]),c=e.length;c--;)if(e[c]==t)return void(n[i]=u[c]);a=r?r(l,t,i,n,a):d,(c=typeof a!="undefined")||(a=f?fu(l)?l:[]:lu(l)?l:{}),e.push(t),u.push(a),c||Ht(a,t,r,e,u),n[i]=a}else a=r?r(l,t,i,n,a):d,typeof a=="undefined"&&(a=t),(o||typeof a!="undefined")&&(n[i]=a) -}),n}function Qt(n,t,r,e){if(n)var u=n[O]?n[O][2]:n.length,u=u-r.length;var o=t&A;return hr(n,t,u,e,o&&r,!o&&r)}function nr(n,t){var r={};if(typeof t=="function")return Pt(n,function(n,e,u){t(n,e,u)&&(r[e]=n)}),r;for(var e=-1,u=t.length;++ea(p,h)&&((u||c)&&p.push(h),l.push(s))}return l}function or(n,t){for(var r=-1,e=t(n),u=e.length,o=ce(u);++re)return t;var u=typeof r[2];if("number"!=u&&"string"!=u||!r[3]||r[3][r[2]]!==r[1]||(e=2),3e?Je(u+e,0):e||0;else if(e)return e=Or(n,t),u&&n[e]===t?e:-1; -return r(n,t,e)}function kr(n){return xr(n,1)}function xr(n,t,r){var e=-1,u=n?n.length:0;for(t=null==t?0:+t||0,0>t?t=Je(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=Je(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=ce(u);++e>>1,r(n[e])r?Je(e+r,0):r||0:0,typeof n=="string"||!fu(n)&&Qr(n)?ro&&(o=a)}else t=null==t&&Qr(n)?u:M.callback(t,r,3),$t(n,function(n,r,u){r=t(n,r,u),(r>e||-1/0===r&&r===o)&&(e=r,o=n)});return o}function Br(n,t){return $r(n,fe(t))}function Dr(n,t,r,e){return t=M.callback(t,e,4),(fu(n)?kt:rr)(n,t,r,3>arguments.length)}function zr(n,t,r,e){var u=3>arguments.length; -return t=M.callback(t,e,4),Lt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function qr(n){var t=-1,r=n&&n.length,e=ce(0>r?0:r>>>0);return $t(n,function(n){var r=tr(0,++t);e[t]=e[r],e[r]=n}),e}function Mr(n,t,r){return(typeof t!="function"||typeof r!="undefined")&&(t=M.callback(t,r,3)),(fu(n)?Ot:er)(n,t)}function Zr(n,t,r){function e(){var r=t-(yu()-c);0>=r||r>t?(a&&Ce(a),r=s,a=p=s=d,r&&(h=yu(),f=n.apply(l,i),p||a||(i=l=null))):p=Le(e,r)}function u(){p&&Ce(p),a=p=s=d,(v||g!==t)&&(h=yu(),f=n.apply(l,i),p||a||(i=l=null)) -}function o(){if(i=arguments,c=yu(),l=this,s=v&&(p||!y),false===g)var r=y&&!p;else{a||y||(h=c);var o=g-(c-h),d=0>=o||o>g;d?(a&&(a=Ce(a)),h=c,f=n.apply(l,i)):a||(a=Le(u,o))}return d&&p?p=Ce(p):p||t===g||(p=Le(e,t)),r&&(d=true,f=n.apply(l,i)),!d||p||a||(i=l=null),f}var i,a,f,c,l,p,s,h=0,g=false,v=true;if(!Xr(n))throw new de(I);if(t=0>t?0:t,true===r)var y=true,v=false;else Yr(r)&&(y=r.leading,g="maxWait"in r&&Je(+r.maxWait||0,t),v="trailing"in r?r.trailing:v);return o.cancel=function(){p&&Ce(p),a&&Ce(a),a=p=s=d},o}function Pr(n){if(!Xr(n))throw new de(I); -return function(){return!n.apply(this,arguments)}}function Kr(n){return Jt(n,ne)}function Vr(n){return n&&typeof n=="object"&&typeof n.length=="number"&&xe.call(n)==G||false}function Jr(n){return n&&typeof n=="object"&&1===n.nodeType&&-1>>0,e=n.constructor,u=-1,e=e&&n===e.prototype,o=r-1,i=ce(r),a=0t||null==n||!Ke(t))return r; -n=ye(n);do t%2&&(r+=n),t=Se(t/2),n+=n;while(t);return r}function ue(n,t){return(n=null==n?"":ye(n))?null==t?n.slice(h(n),g(n)+1):(t=ye(t),n.slice(o(n,t),i(n,t)+1)):n}function oe(n){return n}function ie(n){var t=pu(n),r=t.length,e=t[0],u=r&&n[e];return 1!=r||u!==u||Yr(u)?function(e){var u=r;if(u&&null==e)return false;for(;u--;){var o=t[u];if(!Ne.call(e,o)||!Xt(n[o],e[o],null,true))return false}return true}:function(n){if(null==n)return false;var t=n[e];return u===t&&(0!==u||1/u==1/t)&&Ne.call(n,e)}}function ae(n,t,r){var e=true,u=t&&Jt(t,pu); -t&&(r||u.length)||(null==r&&(r=t),t=n,n=this,u=Jt(t,pu)),false===r?e=false:Yr(r)&&"chain"in r&&(e=r.chain),r=-1;for(var o=Xr(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},M.assign=au,M.at=function(t){return n(t,qt(arguments,false,false,1))},M.bind=function(n,t){return 3>arguments.length?hr(n,m,null,t):Qt(n,m|A,xr(arguments,2),t)},M.bindAll=function(n){for(var t=n,r=1arguments.length?hr(t,m|b,null,n):hr(t,m|b|A,null,n,xr(arguments,2))},M.callback=function(n,t,r){var e=typeof n,u="function"==e;return u&&typeof t=="undefined"?n:u||null==n?Ft(n,t,r):"object"==e?ie(n):fe(n)},M.chain=function(n){return n=M(n),n.__chain__=true,n},M.chunk=function(n,t){var r=0,e=n?n.length:0,u=[];for(t=Je(+t||1,1);rt?0:t)},M.dropRight=function(n,t,r){var e=n?n.length:0; -return t=e-((null==t||r?1:t)||0),xr(n,0,0>t?0:t)},M.dropRightWhile=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return xr(n,0,e+1)},M.dropWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++e(s?e(s,f):i(p,f))){for(t=u;--t;){var h=o[t];if(0>(h?e(h,f):i(n[t],f)))continue n}s&&s.push(f),p.push(f)}return p},M.invert=function(n,t){for(var r=-1,e=pu(n),u=e.length,o={};++ru?0:u>>>0);for(o||(t=M.callback(t,r,3)),$t(n,function(n,r,u){if(o)for(r=t.length,u=ce(r);r--;)u[r]=n[t[r]];else u=t(n,r,u);i[++e]={a:u,b:e,c:n}}),u=i.length,i.sort(o?f:a);u--;)i[u]=i[u].c;return i},M.take=function(n,t,r){return t=null==t||r?1:t,xr(n,0,0>t?0:t)},M.takeRight=function(n,t,r){var e=n?n.length:0;return t=e-((null==t||r?1:t)||0),xr(n,0>t?0:t)},M.takeRightWhile=function(n,t,r){var e=n?n.length:0; -for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return xr(n,e+1)},M.takeWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++en?0:n>>>0,t=Ft(t,r,1),r=-1;for(var e=ce(n);++rr?0:+r||0,e))-t.length,0<=r&&n.indexOf(t,r)==r},M.escape=function(n){return null==n?"":ye(n).replace(N,p)},M.escapeRegExp=re,M.every=Sr,M.find=Nr,M.findIndex=wr,M.findKey=function(n,t,r){return t=M.callback(t,r,3),zt(n,t,Kt,true) -},M.findLast=function(n,t,r){return t=M.callback(t,r,3),zt(n,t,Lt)},M.findLastIndex=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},M.findLastKey=function(n,t,r){return t=M.callback(t,r,3),zt(n,t,Vt,true)},M.findWhere=function(n,t){return Nr(n,ie(t))},M.first=jr,M.has=function(n,t){return n?Ne.call(n,t):false},M.identity=oe,M.indexOf=Ar,M.isArguments=Vr,M.isArray=fu,M.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&xe.call(n)==Q||false},M.isDate=function(n){return n&&typeof n=="object"&&xe.call(n)==nt||false -},M.isElement=Jr,M.isEmpty=function(n){var t=true;if(null==n)return t;var r=n.length;return typeof r=="number"&&-1r?Je(e+r,0):Xe(r||0,e-1))+1);e--;)if(n[e]===t)return e;return-1},M.max=Lr,M.min=function(n,t,r){var e=1/0,o=e,i=typeof t; -if("number"!=i&&"string"!=i||!r||r[t]!==n||(t=null),null==t&&fu(n))for(r=-1,i=n.length;++rr?0:+r||0,n.length),n.lastIndexOf(t,r)==r},M.template=function(n,t){var r=M.templateSettings;t=au({},t,r,Rt),n=ye(null==n?"":n);var e,u,o=au({},t.imports,r.imports,Rt),r=pu(o),o=te(o),i=0,a=t.interpolate||Z,f="__p+='",a=ve((t.escape||Z).source+"|"+a.source+"|"+(a===$?L:Z).source+"|"+(t.evaluate||Z).source+"|$","g");return n.replace(a,function(t,r,o,a,c,l){return o||(o=a),f+=n.slice(i,l).replace(V,s),r&&(e=true,f+="'+__e("+r+")+'"),c&&(u=true,f+="';"+c+";\n__p+='"),o&&(f+="'+((__t=("+o+"))==null?'':__t)+'"),i=l+t.length,t -}),f+="';",(a=t.variable)||(f="with(obj){"+f+"}"),f=(u?f.replace(C,""):f).replace(F,"$1").replace(S,"$1;"),f="function("+(a||"obj")+"){"+(a?"":"obj||(obj={});")+"var __t,__p=''"+(e?",__e=_.escape":"")+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+f+"return __p}",ir(f,r,o)},M.trim=ue,M.trimLeft=function(n,t){return(n=null==n?"":ye(n))?null==t?n.slice(h(n)):(t=ye(t),n.slice(o(n,t))):n},M.trimRight=function(n,t){return(n=null==n?"":ye(n))?null==t?n.slice(0,g(n)+1):(t=ye(t),n.slice(0,i(n,t)+1)):n -},M.trunc=function(n,t){var r=30,e="...";if(Yr(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?ye(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":ye(n),r>=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(Hr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=ve(u.source,(B.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index;r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(U,v))},M.uniqueId=function(n){var t=++E;return ye(null==n?"":n)+t},M.all=Sr,M.any=Mr,M.detect=Nr,M.foldl=Dr,M.foldr=zr,M.head=jr,M.include=Fr,M.inject=Dr,ae(M,function(){var n={};return Kt(M,function(t,r){M.prototype[r]||(n[r]=t)}),n}(),false),M.sample=function(n,t,r){var e=n?n.length:0;return typeof e=="number"&&-1t?0:+t||0,n.length),n) -},Kt(M,function(n,t){var r="sample"!=t;M.prototype[t]||(M.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new J(o,u):o})}),M.VERSION=x,M.prototype.chain=function(){return this.__chain__=true,this},M.prototype.toJSON=Cr,M.prototype.toString=function(){return ye(this.__wrapped__)},M.prototype.value=Cr,M.prototype.valueOf=Cr,_t(["join","pop","shift"],function(n){var t=me[n];M.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); -return n?new J(r,n):r}}),_t(["push","reverse","sort","unshift"],function(n){var t=me[n];M.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),_t(["concat","splice"],function(n){var t=me[n];M.prototype[n]=function(){return new J(t.apply(this.__wrapped__,arguments),this.__chain__)}}),M}var d,m=1,b=2,_=4,w=8,j=16,A=32,k=64,x="3.0.0-pre",O="__lodash@"+x+"__",I="Expected a function",E=0,R=/^[A-Z]+$/,C=/\b__p\+='';/g,F=/\b(__p\+=)''\+/g,S=/(__e\(.*?\)|\b__t\))\+'';/g,U=/&(?:amp|lt|gt|quot|#39|#96);/g,N=/[&<>"'`]/g,T=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,L=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,B=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,z=/^0[xX]/,q=/^\[object .+?Constructor\]$/,M=/[\xC0-\xFF]/g,Z=/($^)/,P=/[.*+?^${}()|[\]\/\\]/g,K=/\bthis\b/,V=/['\n\r\u2028\u2029\\]/g,J=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,X=" \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",Y="Array ArrayBuffer Date Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array window WinRTError".split(" "),G="[object Arguments]",H="[object Array]",Q="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Number]",et="[object Object]",ut="[object RegExp]",ot="[object String]",it="[object ArrayBuffer]",at="[object Float32Array]",ft="[object Float64Array]",ct="[object Int8Array]",lt="[object Int16Array]",pt="[object Int32Array]",st="[object Uint8Array]",ht="[object Uint8ClampedArray]",gt="[object Uint16Array]",vt="[object Uint32Array]",yt={}; -yt[G]=yt[H]=yt[at]=yt[ft]=yt[ct]=yt[lt]=yt[pt]=yt[st]=yt[ht]=yt[gt]=yt[vt]=true,yt[it]=yt[Q]=yt[nt]=yt[tt]=yt["[object Function]"]=yt["[object Map]"]=yt[rt]=yt[et]=yt[ut]=yt["[object Set]"]=yt[ot]=yt["[object WeakMap]"]=false;var dt={};dt[G]=dt[H]=dt[it]=dt[Q]=dt[nt]=dt[at]=dt[ft]=dt[ct]=dt[lt]=dt[pt]=dt[rt]=dt[et]=dt[ut]=dt[ot]=dt[st]=dt[ht]=dt[gt]=dt[vt]=true,dt[tt]=dt["[object Function]"]=dt["[object Map]"]=dt["[object Set]"]=dt["[object WeakMap]"]=false;var mt={leading:false,maxWait:0,trailing:false},bt={configurable:false,enumerable:false,value:null,writable:false},_t={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},wt={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},jt={"\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","\xd7":" ","\xf7":" "},At={"function":true,object:true},kt={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},xt=At[typeof window]&&window||this,Ot=At[typeof exports]&&exports&&!exports.nodeType&&exports,At=At[typeof module]&&module&&!module.nodeType&&module,It=Ot&&At&&typeof global=="object"&&global; -!It||It.global!==It&&It.window!==It&&It.self!==It||(xt=It);var It=At&&At.exports===Ot&&Ot,Et=y();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(xt._=Et, define(function(){return Et})):Ot&&At?It?(At.exports=Et)._=Et:Ot._=Et:xt._=Et}).call(this); \ No newline at end of file +}function f(n,r){return t(n.a,r.a)||n.b-r.b}function a(n,r){for(var e=-1,u=n.a,o=r.a,i=u.length;++ee||13e||8202r||13r||8202i(t,a)&&c.push(a);return c}function $t(n,t){var r=n?n.length:0;if(typeof r!="number"||-1>=r||r>Se)return Vt(n,t);for(var e=-1,u=jr(n);++e=r||r>Se)return Jt(n,t);for(var e=jr(n);r--&&false!==t(e[r],r,n););return n +}function Dt(n,t){var r=true;return $t(n,function(n,e,u){return r=!!t(n,e,u)}),r}function zt(n,t){var r=[];return $t(n,function(n,e,u){t(n,e,u)&&r.push(n)}),r}function qt(n,t,r,e){var u;return r(n,function(n,r,o){return t(n,r,o)?(u=e?r:n,false):void 0}),u}function Mt(n,t,r,e){e=(e||0)-1;for(var u=n.length,o=0,i=[];++e>>1,f=r(n[i]);(e?f<=t:ff(p,h)&&((u||c)&&p.push(h),l.push(s))}return l}function fr(n,t){for(var r=-1,e=t(n),u=e.length,o=ye(u);++re)return t;var u=typeof r[2];if("number"!=u&&"string"!=u||!r[3]||r[3][r[2]]!==r[1]||(e=2),3e?eu(u+e,0):e||0;else if(e)return e=Ir(n,t),u&&n[e]===t?e:-1;return r(n,t,e)}function Or(n){return Er(n,1)}function Er(n,t,r){var e=-1,u=n?n.length:0;for(t=null==t?0:+t||0,0>t?t=eu(u+t,0):t>u&&(t=u),r=typeof r=="undefined"?u:+r||0,0>r?r=eu(u+r,0):r>u&&(r=u),u=t>r?0:r-t,r=ye(u);++er?eu(e+r,0):r||0:0,typeof n=="string"||!mu(n)&&oe(n)?ro&&(o=f)}else t=null==t&&oe(n)?u:M.callback(t,r,3),$t(n,function(n,r,u){r=t(n,r,u),(r>e||-1/0===r&&r===o)&&(e=r,o=n) +});return o}function qr(n,t){return Dr(n,ve(t))}function Mr(n,t,r,e){return(mu(n)?xt:er)(n,M.callback(t,e,4),r,3>arguments.length,$t)}function Zr(n,t,r,e){return(mu(n)?Ot:er)(n,M.callback(t,e,4),r,3>arguments.length,Bt)}function Pr(n){n=jr(n);for(var t=-1,r=n.length,e=ye(r);++t=r||r>t?(f&&Be(f),r=s,f=p=s=d,r&&(h=Ou(),a=n.apply(l,i),p||f||(i=l=null))):p=Ve(e,r)}function u(){p&&Be(p),f=p=s=d,(v||g!==t)&&(h=Ou(),a=n.apply(l,i),p||f||(i=l=null))}function o(){if(i=arguments,c=Ou(),l=this,s=v&&(p||!y),false===g)var r=y&&!p;else{f||y||(h=c);var o=g-(c-h),d=0>=o||o>g;d?(f&&(f=Be(f)),h=c,a=n.apply(l,i)):f||(f=Ve(u,o))}return d&&p?p=Be(p):p||t===g||(p=Ve(e,t)),r&&(d=true,a=n.apply(l,i)),!d||p||f||(i=l=null),a}var i,f,a,c,l,p,s,h=0,g=false,v=true; +if(!te(n))throw new ke(E);if(t=0>t?0:t,true===r)var y=true,v=false;else re(r)&&(y=r.leading,g="maxWait"in r&&eu(+r.maxWait||0,t),v="trailing"in r?r.trailing:v);return o.cancel=function(){p&&Be(p),f&&Be(f),f=p=s=d},o}function Xr(n){if(!te(n))throw new ke(E);return function(){return!n.apply(this,arguments)}}function Yr(n){return nr(n,A,Er(arguments,1))}function Gr(n){return Xt(n,ie)}function Hr(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ne.call(n)==G||false}function Qr(n){return n&&typeof n=="object"&&1===n.nodeType&&-1>>0,e=n.constructor,u=-1,e=e&&n===e.prototype,o=r-1,i=ye(r),f=0t||null==n||!tu(t))return r;n=xe(n);do t%2&&(r+=n),t=ze(t/2),n+=n;while(t);return r}function le(n,t){return(n=null==n?"":xe(n))?null==t?n.slice(h(n),g(n)+1):(t=xe(t),n.slice(o(n,t),i(n,t)+1)):n}function pe(n){try{return n()}catch(t){return ne(t)?t:me(t)}}function se(n){return n}function he(n){var t=wu(n),r=t.length,e=t[0],u=r&&n[e]; +return 1!=r||u!==u||re(u)?function(e){var u=r;if(u&&null==e)return false;for(;u--;){var o=t[u];if(!Me.call(e,o)||!Yt(n[o],e[o],null,true))return false}return true}:function(n){if(null==n)return false;var t=n[e];return u===t&&(0!==u||1/u==1/t)&&Me.call(n,e)}}function ge(n,t,r){var e=true,u=t&&Xt(t,wu);t&&(r||u.length)||(null==r&&(r=t),t=n,n=this,u=Xt(t,wu)),false===r?e=false:re(r)&&"chain"in r&&(e=r.chain),r=-1;for(var o=te(n),i=u?u.length:0;++r--n?t.apply(this,arguments):void 0}},M.assign=du,M.at=function(t){var r=t?t.length:0;return typeof r=="number"&&-1arguments.length?gr(n,m,null,t):nr(n,m|A,Er(arguments,2),t)},M.bindAll=function(n){for(var t=n,r=1arguments.length?gr(t,m|b,null,n):gr(t,m|b|A,null,n,Er(arguments,2))},M.callback=function(n,t,r){var e=typeof n,u="function"==e;return u&&typeof t=="undefined"?n:u||null==n?St(n,t,r):"object"==e?he(n):ve(n)},M.chain=function(n){return n=M(n),n.__chain__=true,n},M.chunk=function(n,t){var r=0,e=n?n.length:0,u=[];for(t=eu(+t||1,1);rt?0:t)},M.dropRight=function(n,t,r){var e=n?n.length:0; +return t=e-((null==t||r?1:t)||0),Er(n,0,0>t?0:t)},M.dropRightWhile=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return Er(n,0,e+1)},M.dropWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++e(s?e(s,a):i(p,a))){for(t=u;--t;){var h=o[t];if(0>(h?e(h,a):i(n[t],a)))continue n}s&&s.push(a),p.push(a)}return p},M.invert=function(n,t){for(var r=-1,e=wu(n),u=e.length,o={};++rt?0:t)},M.takeRight=function(n,t,r){var e=n?n.length:0;return t=e-((null==t||r?1:t)||0),Er(n,0>t?0:t)},M.takeRightWhile=function(n,t,r){var e=n?n.length:0;for(t=M.callback(t,r,3);e--&&t(n[e],e,n););return Er(n,e+1) +},M.takeWhile=function(n,t,r){var e=-1,u=n?n.length:0;for(t=M.callback(t,r,3);++er?0:+r||0,e))-t.length,0<=r&&n.indexOf(t,r)==r},M.escape=function(n){return null==n?"":xe(n).replace(N,p)},M.escapeRegExp=ae,M.every=Tr,M.find=Lr,M.findIndex=Ar,M.findKey=function(n,t,r){return t=M.callback(t,r,3),qt(n,t,Vt,true)},M.findLast=function(n,t,r){return t=M.callback(t,r,3),qt(n,t,Bt)},M.findLastIndex=function(n,t,r){var e=n?n.length:0; +for(t=M.callback(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},M.findLastKey=function(n,t,r){return t=M.callback(t,r,3),qt(n,t,Jt,true)},M.findWhere=function(n,t){return Lr(n,he(t))},M.first=xr,M.has=function(n,t){return n?Me.call(n,t):false},M.identity=se,M.indexOf=kr,M.isArguments=Hr,M.isArray=mu,M.isBoolean=function(n){return true===n||false===n||n&&typeof n=="object"&&Ne.call(n)==Q||false},M.isDate=function(n){return n&&typeof n=="object"&&Ne.call(n)==nt||false},M.isElement=Qr,M.isEmpty=function(n){if(null==n)return true; +var t=n.length;return typeof t=="number"&&-1r?eu(u+r,0):uu(r||0,u-1))+1;else if(r)return u=Rr(n,t)-1,e&&n[u]===t?u:-1;for(;u--;)if(n[u]===t)return u;return-1},M.max=zr,M.min=function(n,t,r){var e=1/0,o=e,i=typeof t;if("number"!=i&&"string"!=i||!r||r[t]!==n||(t=null),null==t&&mu(n))for(r=-1,i=n.length;++rr?0:+r||0,n.length),n.lastIndexOf(t,r)==r},M.template=function(n,t){var r=M.templateSettings;t=du({},t,r,Ct),n=xe(null==n?"":n); +var e,u,o,r=du({},t.imports,r.imports,Ct),i=wu(r),f=fe(r),a=0,r=t.interpolate||Z,c="__p+='",r=Ae((t.escape||Z).source+"|"+r.source+"|"+(r===L?$:Z).source+"|"+(t.evaluate||Z).source+"|$","g");if(o=o?"/*//# sourceURL="+o+"*/":"",n.replace(r,function(t,r,o,i,f,l){return o||(o=i),c+=n.slice(a,l).replace(V,s),r&&(e=true,c+="'+__e("+r+")+'"),f&&(u=true,c+="';"+f+";\n__p+='"),o&&(c+="'+((__t=("+o+"))==null?'':__t)+'"),a=l+t.length,t}),c+="';",(r=t.variable)||(c="with(obj){"+c+"}"),c=(u?c.replace(C,""):c).replace(F,"$1").replace(S,"$1;"),c="function("+(r||"obj")+"){"+(r?"":"obj||(obj={});")+"var __t,__p=''"+(e?",__e=_.escape":"")+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+c+"return __p}",r=pe(function(){return be(i,"return "+c+o).apply(d,f) +}),r.source=c,r instanceof me)throw r;return r},M.trim=le,M.trimLeft=function(n,t){return(n=null==n?"":xe(n))?null==t?n.slice(h(n)):(t=xe(t),n.slice(o(n,t))):n},M.trimRight=function(n,t){return(n=null==n?"":xe(n))?null==t?n.slice(0,g(n)+1):(t=xe(t),n.slice(0,i(n,t)+1)):n},M.trunc=function(n,t){var r=30,e="...";if(re(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?xe(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":xe(n),r>=n.length)return n;var o=r-e.length; +if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(ue(u)){if(n.slice(o).search(u)){var i,f,a=n.slice(0,o);for(u.global||(u=Ae(u.source,(B.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(a);)f=i.index;r=r.slice(0,null==f?o:f)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(U,v))},M.uniqueId=function(n){var t=++I;return xe(null==n?"":n)+t},M.all=Tr,M.any=Kr,M.detect=Lr,M.foldl=Mr,M.foldr=Zr,M.head=xr,M.include=Nr,M.inject=Mr,ge(M,function(){var n={}; +return Vt(M,function(t,r){M.prototype[r]||(n[r]=t)}),n}(),false),M.sample=function(n,t,r){n=jr(n);var e=n.length;return null==t||r?0t?0:+t||0,n.length),n)},Vt(M,function(n,t){var r="sample"!=t;M.prototype[t]||(M.prototype[t]=function(t,e){var u=this.__chain__,o=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new J(o,u):o})}),M.VERSION=k,M.prototype.chain=function(){return this.__chain__=true,this},M.prototype.toJSON=Ur,M.prototype.toString=function(){return xe(this.__wrapped__) +},M.prototype.value=Ur,M.prototype.valueOf=Ur,_t(["join","pop","shift"],function(n){var t=Oe[n];M.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments);return n?new J(r,n):r}}),_t(["push","reverse","sort","unshift"],function(n){var t=Oe[n];M.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),_t(["concat","splice"],function(n){var t=Oe[n];M.prototype[n]=function(){return new J(t.apply(this.__wrapped__,arguments),this.__chain__)}}),M}var d,m=1,b=2,_=4,w=8,j=16,A=32,x=64,k="3.0.0-pre",O="__lodash@"+k+"__",E="Expected a function",I=0,R=/^[A-Z]+$/,C=/\b__p\+='';/g,F=/\b(__p\+=)''\+/g,S=/(__e\(.*?\)|\b__t\))\+'';/g,U=/&(?:amp|lt|gt|quot|#39|#96);/g,N=/[&<>"'`]/g,T=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,L=/<%=([\s\S]+?)%>/g,$=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,B=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,z=/^0[xX]/,q=/^\[object .+?Constructor\]$/,M=/[\xC0-\xFF]/g,Z=/($^)/,P=/[.*+?^${}()|[\]\/\\]/g,K=/\bthis\b/,V=/['\n\r\u2028\u2029\\]/g,J=/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g,X=" \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",Y="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array window WinRTError".split(" "),G="[object Arguments]",H="[object Array]",Q="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Number]",et="[object Object]",ut="[object RegExp]",ot="[object String]",it="[object ArrayBuffer]",ft="[object Float32Array]",at="[object Float64Array]",ct="[object Int8Array]",lt="[object Int16Array]",pt="[object Int32Array]",st="[object Uint8Array]",ht="[object Uint8ClampedArray]",gt="[object Uint16Array]",vt="[object Uint32Array]",yt={}; +yt[G]=yt[H]=yt[ft]=yt[at]=yt[ct]=yt[lt]=yt[pt]=yt[st]=yt[ht]=yt[gt]=yt[vt]=true,yt[it]=yt[Q]=yt[nt]=yt[tt]=yt["[object Function]"]=yt["[object Map]"]=yt[rt]=yt[et]=yt[ut]=yt["[object Set]"]=yt[ot]=yt["[object WeakMap]"]=false;var dt={};dt[G]=dt[H]=dt[it]=dt[Q]=dt[nt]=dt[ft]=dt[at]=dt[ct]=dt[lt]=dt[pt]=dt[rt]=dt[et]=dt[ut]=dt[ot]=dt[st]=dt[ht]=dt[gt]=dt[vt]=true,dt[tt]=dt["[object Function]"]=dt["[object Map]"]=dt["[object Set]"]=dt["[object WeakMap]"]=false;var mt={leading:false,maxWait:0,trailing:false},bt={configurable:false,enumerable:false,value:null,writable:false},_t={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},wt={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},jt={"\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","\xd7":" ","\xf7":" "},At={"function":true,object:true},xt={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},kt=At[typeof window]&&window||this,Ot=At[typeof exports]&&exports&&!exports.nodeType&&exports,At=At[typeof module]&&module&&!module.nodeType&&module,Et=Ot&&At&&typeof global=="object"&&global; +!Et||Et.global!==Et&&Et.window!==Et&&Et.self!==Et||(kt=Et);var Et=At&&At.exports===Ot&&Ot,It=y();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(kt._=It, define(function(){return It})):Ot&&At?Et?(At.exports=It)._=It:Ot._=It:kt._=It}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 886379d2f..b4069c374 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -61,7 +61,7 @@ /** Used to match unescaped characters in compiled string literals */ var reUnescapedString = /['\n\r\u2028\u2029\\]/g; - /** `Object#toString` result shortcuts */ + /** `Object#toString` result references */ var argsClass = '[object Arguments]', arrayClass = '[object Array]', boolClass = '[object Boolean]', @@ -111,8 +111,8 @@ * See [Mathias' article](http://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * - * Backticks are escaped because in Internet Explorer < 9, they can be used to - * break out of attribute values or HTML comments. See [#102](http://html5sec.org/#102), + * Backticks are escaped because in Internet Explorer < 9, they can break out + * of attribute values or HTML comments. See [#102](http://html5sec.org/#102), * [#108](http://html5sec.org/#108), and [#133](http://html5sec.org/#133) of * the [HTML5 Security Cheatsheet](http://html5sec.org/) for more details. */ @@ -172,8 +172,8 @@ /*--------------------------------------------------------------------------*/ /** - * The base implementation of `compareAscending` used to compare values and - * sort them in ascending order without guaranteeing a stable sort. + * The base implementation of `compareAscending` which compares values and + * sorts them in ascending order without guaranteeing a stable sort. * * @private * @param {*} value The value to compare to `other`. @@ -214,7 +214,7 @@ } /** - * Used by `_.sortBy` to compare transformed elements of a collection and stable + * Used by `_.sortBy` to compare transformed elements of `collection` and stable * sort them in ascending order. * * @private @@ -269,8 +269,11 @@ /** Used to resolve the decompiled source of functions */ var fnToString = Function.prototype.toString; + /** Used as a reference for the max length of an array */ + var maxArrayLength = Math.pow(2, 32) - 1; + /** - * Used as the maximum length of an array-like object. + * Used as the maximum length of an array-like value. * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * for more details. */ @@ -288,7 +291,7 @@ .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); - /** Native method shortcuts */ + /** Native method references */ var ceil = Math.ceil, floor = Math.floor, hasOwnProperty = objectProto.hasOwnProperty, @@ -296,7 +299,7 @@ propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice; - /* Native method shortcuts for methods with the same name as other `lodash` methods */ + /* Native method references for those with the same name as other `lodash` methods */ var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate, nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsFinite = root.isFinite, @@ -321,14 +324,14 @@ * implicitly or explicitly included in the build. * * The chainable wrapper functions are: - * `after`, `assign`, `at`, `bind`, `bindAll`, `bindKey`, `callback`, `chain`, - * `chunk`, `compact`, `compose`, `concat`, `constant`, `countBy`, `create`, - * `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, `drop`, - * `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, `forEach`, - * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, - * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, - * `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, `mixin`, - * `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, + * `after`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, `callback`, + * `chain`, `chunk`, `compact`, `compose`, `concat`, `constant`, `countBy`, + * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, + * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, + * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, + * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, + * `invoke`, `keys`, `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, + * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, * `partition`, `pick`, `pluck`, `property`, `pull`, `pullAt`, `push`, `range`, * `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, * `splice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, @@ -337,17 +340,18 @@ * and `zipObject` * * The non-chainable wrapper functions are: - * `camelCase`, `capitalize`, `clone`, `cloneDeep`, `contains`, `endsWith`, - * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, + * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `contains`, + * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, - * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, + * `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, isDate`, * `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, `isFunction`, * `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, * `isString`, `isUndefined`, `join`, `kebabCase`, `last`, `lastIndexOf`, * `max`, `min`, `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, - * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `startsWith`, `template`, - * `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, and `value` + * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, + * `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, + * `unescape`, `uniqueId`, and `value` * * The wrapper function `sample` will return a wrapped value when `n` is * provided, otherwise it will return an unwrapped value. @@ -396,7 +400,7 @@ } /** - * An object used to flag environments features. + * An object environment feature flags. * * @static * @memberOf _ @@ -524,7 +528,7 @@ */ function arrayMap(array, iterator) { var index = -1, - length = array ? array.length >>> 0 : 0, + length = array ? array.length : 0, result = Array(length); while (++index < length) { @@ -581,6 +585,30 @@ return accumulator; } + /** + * A specialized version of `_.reduceRight` for arrays without support for + * callback shorthands or `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iterator The function called per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initFromArray=false] Specify using the first element of + * `array` as the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduceRight(array, iterator, accumulator, initFromArray) { + var length = array.length; + + if (initFromArray && length) { + accumulator = array[--length]; + } + while (length--) { + accumulator = iterator(accumulator, array[length], length, array); + } + return accumulator; + } + /** * A specialized version of `_.some` for arrays without support for callback * shorthands or `this` binding. @@ -671,6 +699,17 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {number} data[1] The bitmask of flags to compose. See `createWrapper` + * for more details. + * @param {number} data[2] The arity of `data[0]`. + * @param {*} [data[3]] The `this` binding of `data[0]`. + * @param {Array} [data[4]] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [data[5]] An array of arguments to append to those + * provided to the new function. + * @param {Array} [data[6]] An array of `data[4]` placeholder indexes. + * @param {Array} [data[7]] An array of `data[5]` placeholder indexes. * @returns {Function} Returns the new function. */ function baseCreateWrapper(data) { @@ -752,18 +791,17 @@ * @returns {Array|Object|string} Returns `collection`. */ function baseEach(collection, iterator) { + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return baseForOwn(collection, iterator); + } var index = -1, - iterable = collection, - length = collection ? collection.length : 0; + iterable = toIterable(collection); - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - while (++index < length) { - if (iterator(iterable[index], index, collection) === breakIndicator) { - break; - } + while (++index < length) { + if (iterator(iterable[index], index, collection) === breakIndicator) { + break; } - } else { - baseForOwn(collection, iterator); } return collection; } @@ -778,17 +816,15 @@ * @returns {Array|Object|string} Returns `collection`. */ function baseEachRight(collection, iterator) { - var iterable = collection, - length = collection ? collection.length : 0; - - if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { - while (length--) { - if (iterator(iterable[length], length, collection) === breakIndicator) { - break; - } + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return baseForOwnRight(collection, iterator); + } + var iterable = toIterable(collection); + while (length--) { + if (iterator(iterable[length], length, collection) === breakIndicator) { + break; } - } else { - baseForOwnRight(collection, iterator); } return collection; } @@ -841,7 +877,7 @@ * @private * @param {Array|Object|string} collection The collection to search. * @param {Function} predicate The function called per iteration. - * @param {Function} eachFunc The function to iterate over the collection. + * @param {Function} eachFunc The function to iterate over `collection`. * @param {boolean} [retKey=false] Specify returning the key of the found * element instead of the element itself. * @returns {*} Returns the found element or its key, else `undefined`. @@ -1143,9 +1179,12 @@ function baseInvoke(collection, methodName, args) { var index = -1, isFunc = typeof methodName == 'function', - length = collection && collection.length, - result = Array(length < 0 ? 0 : length >>> 0); + length = collection ? collection.length : 0, + result = []; + if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { + result.length = length; + } baseEach(collection, function(value) { var func = isFunc ? methodName : (value != null && value[methodName]); result[++index] = func ? func.apply(value, args) : undefined; @@ -1236,19 +1275,21 @@ } /** - * The base implementation of `_.reduce` without support for callback - * shorthands or `this` binding. + * The base implementation of `_.reduce` and `_.reduceRight` without support + * for callback shorthands or `this` binding, which iterates over `collection` + * usingthe provided `eachFunc`. * * @private * @param {Array|Object|string} collection The collection to iterate over. * @param {Function} iterator The function called per iteration. - * @param {*} [accumulator] The initial value. - * @param {boolean} [initFromCollection=false] Specify using the first element + * @param {*} accumulator The initial value. + * @param {boolean} initFromCollection Specify using the first element * of `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the accumulated value. */ - function baseReduce(collection, iterator, accumulator, initFromCollection) { - baseEach(collection, function(value, index, collection) { + function baseReduce(collection, iterator, accumulator, initFromCollection, eachFunc) { + eachFunc(collection, function(value, index, collection) { accumulator = initFromCollection ? (initFromCollection = false, value) : iterator(accumulator, value, index, collection) @@ -1276,6 +1317,37 @@ return !!result; } + /** + * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` without + * support for callback shorthands and `this` binding. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iterator The function called per iteration. + * @param {boolean} [retHighest=false] Specify returning the highest, instead + * of the lowest, index at which a value should be inserted into `array`. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndex(array, value, iterator, retHighest) { + var low = 0, + high = array ? array.length : low; + + value = iterator(value); + while (low < high) { + var mid = (low + high) >>> 1, + computed = iterator(array[mid]); + + if (retHighest ? computed <= value : computed < value) { + low = mid + 1; + } else { + high = mid; + } + } + return high; + } + /** * The base implementation of `_.uniq` without support for callback shorthands * and `this` binding. @@ -1338,32 +1410,6 @@ return result; } - /** - * Compiles a function from `source` using the `varNames` and `varValues` - * pairs to import free variables into the compiled function. If `sourceURL` - * is provided it is used as the sourceURL for the compiled function. - * - * @private - * @param {string} source The source to compile. - * @param {Array} varNames An array of free variable names. - * @param {Array} varValues An array of free variable values. - * @param {string} [sourceURL=''] The sourceURL of the source. - * @returns {Function} Returns the compiled function. - */ - function compileFunction(source, varNames, varValues, sourceURL) { - sourceURL = sourceURL ? ('\n/*\n//# sourceURL=' + sourceURL + '\n*/') : ''; - try { - // provide the compiled function's source by its `toString` method or - // the `source` property as a convenience for inlining compiled templates - var result = Function(varNames, 'return ' + source + sourceURL).apply(undefined, varValues); - result.source = source; - } catch(e) { - e.source = source; - throw e; - } - return result; - } - /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -1434,6 +1480,8 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {*} data[3] The `this` binding of `data[0]`. * @returns {Function} Returns the new bound function. */ function createBindWrapper(data) { @@ -1472,14 +1520,19 @@ * * @private * @param {Array} data The metadata array. + * @param {Function|string} data[0] The function or method name to reference. + * @param {number} data[1] The bitmask of flags to compose. See `createWrapper` + * for more details. + * @param {*} [data[3]] The `this` binding of `data[0]`. + * @param {Array} data[4] An array of arguments to prepend to those + * provided to the new function. * @returns {Function} Returns the new bound function. */ function createPartialWrapper(data) { var func = data[0], bitmask = data[1], thisArg = data[3], - partialArgs = data[4], - partialHolders = data[6]; + partialArgs = data[4]; var isBind = bitmask & BIND_FLAG, Ctor = createCtorWrapper(func); @@ -1491,8 +1544,7 @@ argsLength = arguments.length, leftIndex = -1, leftLength = partialArgs.length, - args = Array(argsLength + leftLength), - thisBinding = isBind ? thisArg : this; + args = Array(argsLength + leftLength); while (++leftIndex < leftLength) { args[leftIndex] = partialArgs[leftIndex]; @@ -1500,7 +1552,7 @@ while (argsLength--) { args[leftIndex++] = arguments[argsIndex++]; } - return (this instanceof wrapper ? Ctor : func).apply(thisBinding, args); + return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args); } return wrapper; } @@ -1621,6 +1673,21 @@ return result; } + /** + * Converts `collection` to an array if it is not an array-like value. + * + * @private + * @param {Array|Object|string} collection The collection to inspect. + * @returns {Array|Object} Returns the iterable object. + */ + function toIterable(collection) { + var length = collection ? collection.length : 0; + if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { + return values(collection); + } + return collection || []; + } + /*--------------------------------------------------------------------------*/ /** @@ -1819,9 +1886,10 @@ } /** - * Gets the index at which the first occurrence of `value` is found using - * strict equality for comparisons, i.e. `===`. If the array is already sorted - * providing `true` for `fromIndex` performs a faster binary search. + * Gets the index at which the first occurrence of `value` is found in `array` + * using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, + * it is used as the offset from the end of the collection. If `array` is + * sorted providing `true` for `fromIndex` performs a faster binary search. * * @static * @memberOf _ @@ -1841,11 +1909,12 @@ * // => 4 * * // performing a binary search - * _.indexOf([1, 1, 2, 2, 3, 3], 2, true); + * _.indexOf([4, 4, 5, 5, 6, 6], 5, true); * // => 2 */ function indexOf(array, value, fromIndex) { var length = array ? array.length : 0; + if (typeof fromIndex == 'number') { fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); } else if (fromIndex) { @@ -1948,16 +2017,16 @@ } /** - * Gets the index at which the last occurrence of `value` is found using - * strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, - * it is used as the offset from the end of the collection. + * 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. + * @param {boolean|number} [fromIndex=array.length-1] The index to search from + * or `true` to perform a binary search on a sorted array. * @returns {number} Returns the index of the matched value, else `-1`. * @example * @@ -1967,9 +2036,15 @@ * // using `fromIndex` * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); * // => 1 + * + * // performing a binary search + * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); + * // => 3 */ function lastIndexOf(array, value, fromIndex) { - var index = array ? array.length : 0; + var length = array ? array.length : 0, + index = length; + if (typeof fromIndex == 'number') { index = (fromIndex < 0 ? nativeMax(index + fromIndex, 0) : nativeMin(fromIndex || 0, index - 1)) + 1; } @@ -2044,11 +2119,11 @@ } /** - * Uses a binary search to determine the smallest index at which a value - * should be inserted into a given sorted array in order to maintain the sort - * order of the array. If an iterator function is provided it is executed for - * `value` and each element of `array` to compute their sort ranking. The - * iterator function is bound to `thisArg` and invoked with one argument; (value). + * Uses a binary search to determine the lowest index at which a value should + * be inserted into a given sorted array in order to maintain the sort order + * of the array. If an iterator function is provided it is executed for `value` + * and each element of `array` to compute their sort ranking. The iterator + * function is bound to `thisArg` and invoked with one argument; (value). * * If a property name is provided for `iterator` the created "_.pluck" style * callback returns the property value of the given element. @@ -2070,38 +2145,27 @@ * into `array`. * @example * - * _.sortedIndex([20, 30, 50], 40); + * _.sortedIndex([30, 50], 40); + * // => 1 + * + * _.sortedIndex([4, 4, 5, 5, 6, 6], 5); * // => 2 * - * var dict = { - * 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'forty': 40, 'fifty': 50 } - * }; + * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; * * // using an iterator function - * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'forty', function(word) { - * return this.wordToNumber[word]; + * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) { + * return this.data[word]; * }, dict); - * // => 2 + * // => 1 * * // using "_.pluck" callback shorthand - * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); - * // => 2 + * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); + * // => 1 */ function sortedIndex(array, value, iterator, thisArg) { - var low = 0, - high = array ? array.length : low; - - // explicitly reference `identity` for better inlining in Firefox - iterator = iterator ? callback(iterator, thisArg, 1) : identity; - value = iterator(value); - - while (low < high) { - var mid = (low + high) >>> 1; - (iterator(array[mid]) < value) - ? (low = mid + 1) - : (high = mid); - } - return low; + iterator = iterator == null ? identity : callback(iterator, thisArg, 1); + return baseSortedIndex(array, value, iterator); } /** @@ -2215,6 +2279,35 @@ return baseUniq(array, isSorted, iterator); } + /** + * 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) { + var index = -1, + length = isObject(length = max(array, 'length')) && length.length || 0, + result = Array(length); + + while (++index < length) { + result[index] = pluck(array, index); + } + return result; + } + /** * Creates an array excluding all provided values using strict equality for * comparisons, i.e. `===`. @@ -2237,32 +2330,20 @@ /** * 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. If a zipped value is provided its corresponding - * unzipped value is returned. + * of the given arrays, and so on. * * @static * @memberOf _ - * @alias unzip * @category Array * @param {...Array} [arrays] The arrays to process. - * @returns {Array} Returns the array of grouped elements. + * @returns {Array} Returns the new array of grouped elements. * @example * * _.zip(['fred', 'barney'], [30, 40], [true, false]); * // => [['fred', 30, true], ['barney', 40, false]] - * - * _.unzip([['fred', 30, true], ['barney', 40, false]]); - * // => [['fred', 'barney'], [30, 40], [true, false]] */ function zip() { - var index = -1, - length = isObject(length = max(arguments, 'length')) && length.length || 0, - result = Array(length); - - while (++index < length) { - result[index] = pluck(arguments, index); - } - return result; + return unzip(arguments); } /** @@ -2484,7 +2565,7 @@ }); /** - * Checks if the predicate returns truthy for **all** elements of a collection. + * Checks if the predicate returns truthy for **all** elements of `collection`. * The predicate is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * @@ -2533,7 +2614,7 @@ } /** - * Iterates over elements of a collection returning an array of all elements + * Iterates over elements of `collection` returning an array of all elements * the predicate returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * @@ -2580,7 +2661,7 @@ } /** - * Iterates over elements of a collection, returning the first element that + * Iterates over elements of `collection`, returning the first element that * the predicate returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * @@ -2660,7 +2741,7 @@ } /** - * Iterates over elements of a collection executing `iterator` for each + * Iterates over elements of `collection` executing `iterator` for each * element. The `iterator` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). Iterator functions may exit iteration early * by explicitly returning `false`. @@ -2679,8 +2760,8 @@ * @returns {Array|Object|string} Returns `collection`. * @example * - * _([1, 2, 3]).forEach(function(n) { console.log(n); }).join(','); - * // => logs each number and returns '1,2,3' + * _([1, 2, 3]).forEach(function(n) { console.log(n); }); + * // => logs each value and returns the array * * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); }); * // => logs each value-key pair and returns the object (property order is not guaranteed across environments) @@ -2693,7 +2774,7 @@ /** * Creates an object composed of keys generated from the results of running - * each element of a collection through `iterator`. The corresponding + * each element of `collection` through `iterator`. The corresponding * value of each key is an array of the elements responsible for generating * the key. The `iterator` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). @@ -2850,7 +2931,7 @@ } /** - * Retrieves the maximum value of a collection. If the collection is empty + * Retrieves the maximum value of `collection`. If the collection is empty * or falsey `-Infinity` is returned. If an iterator function is provided it * is executed for each value in the collection to generate the criterion by * which the value is ranked. The `iterator` is bound to `thisArg` and invoked @@ -2926,7 +3007,7 @@ } /** - * Retrieves the minimum value of a collection. If the collection is empty + * Retrieves the minimum value of `collection`. If the collection is empty * or falsey `Infinity` is returned. If an iterator function is provided it * is executed for each value in the collection to generate the criterion by * which the value is ranked. The `iterator` is bound to `thisArg` and invoked @@ -3101,15 +3182,13 @@ * // => { 'a': 3, 'b': 6, 'c': 9 } */ function reduce(collection, iterator, accumulator, thisArg) { - iterator = callback(iterator, thisArg, 4); - var func = isArray(collection) ? arrayReduce : baseReduce; - return func(collection, iterator, accumulator, arguments.length < 3); + return func(collection, callback(iterator, thisArg, 4), accumulator, arguments.length < 3, baseEach); } /** - * This method is like `_.reduce` except that it iterates over elements of a - * collection from right to left. + * This method is like `_.reduce` except that it iterates over elements of + * `collection` from right to left. * * @static * @memberOf _ @@ -3127,19 +3206,12 @@ * // => [4, 5, 2, 3, 0, 1] */ function reduceRight(collection, iterator, accumulator, thisArg) { - var noaccum = arguments.length < 3; - iterator = callback(iterator, thisArg, 4); - - baseEachRight(collection, function(value, index, collection) { - accumulator = noaccum - ? (noaccum = false, value) - : iterator(accumulator, value, index, collection); - }); - return accumulator; + var func = isArray(collection) ? arrayReduceRight : baseReduce; + return func(collection, callback(iterator, thisArg, 4), accumulator, arguments.length < 3, baseEachRight); } /** - * The opposite of `_.filter`; this method returns the elements of a collection + * The opposite of `_.filter`; this method returns the elements of `collection` * the predicate does **not** return truthy for. * * If a property name is provided for `predicate` the created "_.pluck" style @@ -3200,12 +3272,9 @@ * // => [3, 1] */ function sample(collection, n, guard) { - var length = collection ? collection.length : 0; + collection = toIterable(collection); - if (!(typeof length == 'number' && length > -1 && length <= maxSafeInteger)) { - collection = values(collection); - length = collection.length; - } + var length = collection.length; if (n == null || guard) { return length > 0 ? collection[baseRandom(0, length - 1)] : undefined; } @@ -3230,21 +3299,25 @@ * // => [4, 1, 3, 2] */ function shuffle(collection) { - var index = -1, - length = collection && collection.length, - result = Array(length < 0 ? 0 : length >>> 0); + collection = toIterable(collection); + + var index = -1, + length = collection.length, + result = Array(length); + + while (++index < length) { + var value = collection[index], + rand = baseRandom(0, index); - baseEach(collection, function(value) { - var rand = baseRandom(0, ++index); result[index] = result[rand]; result[rand] = value; - }); + } return result; } /** - * Gets the size of the collection by returning `collection.length` for arrays - * and array-like objects or the number of own enumerable properties for objects. + * Gets the size of the collection by returning `collection.length` for + * array-like values or the number of own enumerable properties for objects. * * @static * @memberOf _ @@ -3270,7 +3343,7 @@ } /** - * Checks if the predicate returns truthy for **any** element of a collection. + * Checks if the predicate returns truthy for **any** element of `collection`. * The function returns as soon as it finds a passing value and does not iterate * over the entire collection. The predicate is bound to `thisArg` and invoked * with three arguments; (value, index|key, collection). @@ -3404,13 +3477,8 @@ * // => [2, 3, 4] */ function toArray(collection) { - if (isArray(collection)) { - return slice(collection); - } - if (collection && typeof collection.length == 'number') { - return map(collection); - } - return values(collection); + var iterable = toIterable(collection); + return iterable === collection ? slice(collection) : iterable; } /** @@ -3447,14 +3515,13 @@ /*--------------------------------------------------------------------------*/ /** - * Creates a function that executes `func`, with the `this` binding and - * arguments of the created function, only after being called `n` times. + * The opposite of `_.before`; this method creates a function that executes + * `func` only after it is called `n` times. * * @static * @memberOf _ * @category Function - * @param {number} n The number of times the function must be called before - * `func` is executed. + * @param {number} n The number of calls before `func` is executed. * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. * @example @@ -3462,13 +3529,13 @@ * var saves = ['profile', 'settings']; * * var done = _.after(saves.length, function() { - * console.log('Done saving!'); + * console.log('done saving!'); * }); * * _.forEach(saves, function(type) { * asyncSave({ 'type': type, 'complete': done }); * }); - * // => logs 'Done saving!', after all saves have completed + * // => logs 'done saving!' after all saves have completed */ function after(n, func) { if (!isFunction(func)) { @@ -3482,6 +3549,36 @@ }; } + /** + * Creates a function that executes `func`, with the `this` binding and + * arguments of the created function, until it is called `n` times. + * + * @static + * @memberOf _ + * @category Function + * @param {number} n The number of times `func` may be executed. + * @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 5 contacts to the list + */ + function before(n, func) { + var result; + if (!isFunction(func)) { + throw new TypeError(funcErrorText); + } + return function() { + if (--n > 0) { + result = func.apply(this, arguments); + } else { + func = null; + } + return result; + }; + } + /** * Creates a function that invokes `func` with the `this` binding of `thisArg` * and prepends any additional `bind` arguments to those provided to the bound @@ -3537,12 +3634,14 @@ * * _.bindAll(view); * jQuery('#docs').on('click', view.onClick); - * // => logs 'clicked docs', when the button is clicked + * // => logs 'clicked docs' when the element is clicked */ function bindAll(object) { - return baseBindAll(object, arguments.length > 1 - ? baseFlatten(arguments, false, false, 1) - : functions(object)); + return baseBindAll(object, + arguments.length > 1 + ? baseFlatten(arguments, false, false, 1) + : functions(object) + ); } /** @@ -3925,6 +4024,7 @@ * * @static * @memberOf _ + * @type Function * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. @@ -3935,25 +4035,7 @@ * initialize(); * // `initialize` executes `createApplication` once */ - function once(func) { - var ran, - result; - - if (!isFunction(func)) { - throw new TypeError(funcErrorText); - } - return function() { - if (ran) { - return result; - } - ran = true; - result = func.apply(this, arguments); - - // clear the `func` variable so the function may be garbage collected - func = null; - return result; - }; - } + var once = partial(before, 2); /** * Creates a function that invokes `func` with any additional `partial` arguments @@ -4394,8 +4476,8 @@ /** * Checks if a collection is empty. A value is considered empty unless it is - * an array, array-like object, or string with a length greater than `0` or - * an object with own enumerable properties. + * an array-like value with a length greater than `0` or an object with own + * enumerable properties. * * @static * @memberOf _ @@ -4428,12 +4510,7 @@ (isArray(value) || isString(value) || isArguments(value))) { return !length; } - for (var key in value) { - if (hasOwnProperty.call(value, key)) { - return false; - } - } - return true; + return !keys(value).length; } /** @@ -4445,7 +4522,7 @@ * * Note: This method supports comparing arrays, booleans, `Date` objects, * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes - * are **not** supported. A customizer function may be used to extend support + * are **not** supported. Provide a customizer function to extend support * for comparing other values. * * @static @@ -4479,6 +4556,27 @@ return baseIsEqual(value, other); } + /** + * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, + * `SyntaxError`, `TypeError`, or `URIError` object. + * + * @static + * @memberOf _ + * @category Object + * @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 (value && typeof value == 'object' && toString.call(value) == errorClass) || false; + } + /** * Checks if `value` is a finite number. * @@ -4991,7 +5089,7 @@ * compiled({ 'name': 'mustache' }); * // => 'hello mustache!' * - * // using the `imports` option to import jQuery + * // using the `imports` option to import `jQuery` as `jq` * var text = '<% jq.each(people, function(name) { %>
  • <%- name %>
  • <% }); %>'; * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); * compiled({ 'people': ['fred', 'barney'] }); @@ -5061,7 +5159,14 @@ source + 'return __p\n}'; - var result = compileFunction(source, ['_'], [_]); + var result = attempt(function() { + return Function('_', 'return ' + source)(_); + }); + + result.source = source; + if (result instanceof Error) { + throw result; + } return data ? result(data) : result; } @@ -5093,6 +5198,34 @@ /*--------------------------------------------------------------------------*/ + /** + * Attempts to execute `func`, returning either the result or the caught + * error object. + * + * @static + * @memberOf _ + * @category Utility + * @param {*} func The function to attempt. + * @returns {*} Returns the `func` result or error object. + * @example + * + * // avoid throwing errors for invalid selectors + * var elements = _.attempt(function() { + * return document.querySelectorAll(selector); + * }); + * + * if (elements instanceof Error) { + * elements = []; + * } + */ + function attempt(func) { + try { + return func(); + } catch(e) { + return isError(e) ? e : Error(e); + } + } + /** * Creates a function bound to an optional `thisArg`. If `func` is a property * name the created callback returns the property value for a given element. @@ -5302,8 +5435,7 @@ * @category Utility * @example * - * var stamp = _.now(); - * _.defer(function() { console.log(_.now() - stamp); }); + * _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); * // => logs the number of milliseconds it took for the deferred function to be called */ var now = nativeNow || function() { @@ -5500,14 +5632,18 @@ * // => also calls `mage.castSpell(n)` three times */ function times(n, iterator, thisArg) { - n = n < 0 ? 0 : n >>> 0; + n = nativeIsFinite(n = +n) && n > -1 ? n : 0; iterator = baseCallback(iterator, thisArg, 1); var index = -1, - result = Array(n); + result = Array(nativeMin(n, maxArrayLength)); while (++index < n) { - result[index] = iterator(index); + if (index < maxArrayLength) { + result[index] = iterator(index); + } else { + iterator(index); + } } return result; } diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 6cef59fc2..60c16ae4b 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,41 +3,43 @@ * Lo-Dash 3.0.0-pre (Custom Build) lodash.com/license | Underscore.js 1.6.0 underscorejs.org/LICENSE * Build: `lodash underscore -o ./dist/lodash.underscore.js` */ -;(function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(t>>0:0,u=Array(e);++tu(r,i)&&o.push(i)}return o}function m(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number"&&-1o?0:o>>>0);return m(n,function(n){var o=u?r:null!=n&&n[r];i[++e]=o?o.apply(n,t):xr}),i}function O(n,r){var t=[];return m(n,function(n,e,u){t.push(r(n,e,u))}),t}function k(n,r,t,e){var u=r⩔return W(n,r,e,u&&t,!u&&t)}function S(n,r){var t={};if(typeof r=="function")return x(n,function(n,e,u){r(n,e,u)&&(t[e]=n)}),t;for(var e=-1,u=r.length;++eo(f,c)&&(t&&f.push(c),i.push(a))}return i}function q(n,r){var t,e=["_"];try{var u=Function(e,"return "+n+(t?"\n/*\n//# sourceURL="+t+"\n*/":"")).apply(xr,r);u.source=n}catch(o){throw o.source=n,o -}return u}function B(n,r){return function(t,e,u){var o=r?r():{};if(e=_r(e,u,3),St(t)){u=-1;for(var i=t.length;++ur?0:r)}function P(r,t,e){var u=r?r.length:0;if(typeof e=="number")e=0>e?bt(u+e,0):e||0;else if(e)return e=H(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function V(n,r,t){return G(n,null==r||t?1:0>r?0:r)}function G(n,r,t){var e=-1,u=n?n.length:0;for(r=null==r?0:+r||0,0>r?r=bt(u+r,0):r>u&&(r=u),t=typeof t=="undefined"?u:+t||0,0>t?t=bt(u+t,0):t>u&&(t=u),u=r>t?0:t-r,t=Array(u);++e>>1,t(n[e])u&&(u=i)}else r=_r(r,t,3),m(n,function(n,t,o){t=r(n,t,o),(t>e||-1/0===t&&t===u)&&(e=t,u=n)});return u}function tr(n,r){return nr(n,Ar(r))}function er(n,r,t,e){return r=_r(r,e,4),(St(n)?p:I)(n,r,t,3>arguments.length)}function ur(n,r,t,e){var u=3>arguments.length;return r=_r(r,e,4),b(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function or(n){var r=-1,t=n&&n.length,e=Array(0>t?0:t>>>0);return m(n,function(n){var t=F(++r);e[r]=e[t],e[t]=n}),e}function ir(n,r,t){return(typeof r!="function"||typeof t!="undefined")&&(r=_r(r,t,3)),(St(n)?s:M)(n,r) -}function fr(n,r,t){function e(){var t=r-(It()-c);0>=t||t>r?(f&&clearTimeout(f),t=s,f=p=s=xr,t&&(g=It(),a=n.apply(l,i),p||f||(i=l=null))):p=setTimeout(e,t)}function u(){p&&clearTimeout(p),f=p=s=xr,(v||h!==r)&&(g=It(),a=n.apply(l,i),p||f||(i=l=null))}function o(){if(i=arguments,c=It(),l=this,s=v&&(p||!y),false===h)var t=y&&!p;else{f||y||(g=c);var o=h-(c-g),m=0>=o||o>h;m?(f&&(f=clearTimeout(f)),g=c,a=n.apply(l,i)):f||(f=setTimeout(u,o))}return m&&p?p=clearTimeout(p):p||r===h||(p=setTimeout(e,r)),t&&(m=true,a=n.apply(l,i)),!m||p||f||(i=l=null),a -}var i,f,a,c,l,p,s,g=0,h=false,v=true;if(!gr(n))throw new TypeError(Sr);if(r=0>r?0:r,true===t)var y=true,v=false;else hr(t)&&(y=t.leading,h="maxWait"in t&&bt(+t.maxWait||0,r),v="trailing"in t?t.trailing:v);return o.cancel=function(){p&&clearTimeout(p),f&&clearTimeout(f),f=p=s=xr},o}function ar(n){if(!gr(n))throw new TypeError(Sr);return function(){return!n.apply(this,arguments)}}function cr(n){if(null==n)return n;var r=arguments,t=0,e=r.length,u=typeof r[2];for("number"!=u&&"string"!=u||!r[3]||r[3][r[2]]!==r[1]||(e=2);++t"'`]/g,Nr=/^\[object .+?Constructor\]$/,qr=/($^)/,Br=/[.*+?^${}()|[\]\/\\]/g,Rr=/['\n\r\u2028\u2029\\]/g,$r="[object Arguments]",Ur="[object Boolean]",Wr="[object Date]",Dr="[object Number]",zr="[object Object]",Cr="[object RegExp]",Lr="[object String]",Pr={}; -Pr[$r]=Pr["[object Array]"]=Pr["[object Float32Array]"]=Pr["[object Float64Array]"]=Pr["[object Int8Array]"]=Pr["[object Int16Array]"]=Pr["[object Int32Array]"]=Pr["[object Uint8Array]"]=Pr["[object Uint8ClampedArray]"]=Pr["[object Uint16Array]"]=Pr["[object Uint32Array]"]=true,Pr["[object ArrayBuffer]"]=Pr[Ur]=Pr[Wr]=Pr["[object Error]"]=Pr["[object Function]"]=Pr["[object Map]"]=Pr[Dr]=Pr[zr]=Pr[Cr]=Pr["[object Set]"]=Pr[Lr]=Pr["[object WeakMap]"]=false;var Vr={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Gr={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},Hr={"function":true,object:true},Jr={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Kr=Hr[typeof window]&&window||this,Qr=Hr[typeof exports]&&exports&&!exports.nodeType&&exports,Xr=Hr[typeof module]&&module&&!module.nodeType&&module,Yr=Qr&&Xr&&typeof global=="object"&&global; -!Yr||Yr.global!==Yr&&Yr.window!==Yr&&Yr.self!==Yr||(Kr=Yr);var Zr=Xr&&Xr.exports===Qr&&Qr,nt=Array.prototype,rt=Object.prototype,tt=Function.prototype.toString,et=Math.pow(2,53)-1,ut=Kr._,ot=rt.toString,it=RegExp("^"+(null==ot?"":(ot+"").replace(Br,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ft=Math.ceil,at=Math.floor,ct=rt.hasOwnProperty,lt=nt.push,pt=rt.propertyIsEnumerable,st=nt.splice,gt=z(gt=Object.create)&>,ht=z(ht=Array.isArray)&&ht,vt=Kr.isFinite,yt=Kr.isNaN,mt=z(mt=Object.keys)&&mt,bt=Math.max,_t=Math.min,dt=z(dt=Date.now)&&dt,jt=Math.random,wt={}; -!function(){var n={0:1,length:1};wt.spliceObjects=(st.call(n,0,1),!n[0])}(0,0),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},gt||(h=function(){function n(){}return function(r){if(hr(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Kr.Object()}}());var At=V,xt=L,Tt=B(function(n,r,t){ct.call(n,t)?n[t]++:n[t]=1}),Et=B(function(n,r,t){ct.call(n,t)?n[t].push(r):n[t]=[r]}),Ot=B(function(n,r,t){n[t]=r}),kt=B(function(n,r,t){n[t?0:1].push(r) -},function(){return[[],[]]});sr(arguments)||(sr=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ct.call(n,"callee")&&!pt.call(n,"callee")||false});var St=ht||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&"[object Array]"==ot.call(n)||false};gr(/x/)&&(gr=function(n){return typeof n=="function"&&"[object Function]"==ot.call(n)});var Ft=mt?function(n){return hr(n)?mt(n):[]}:C,It=dt||function(){return(new Date).getTime()};i.prototype=o.prototype,o.after=function(n,r){if(!gr(r))throw new TypeError(Sr); -return n=vt(n=+n)?n:0,function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=function(n,r){return 3>arguments.length?W(n,Tr,r):k(n,Tr|Or,G(arguments,2),r)},o.bindAll=function(n){for(var r=n,t=1r?0:r)},o.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=Ft(n),e=t.length,u={};++ro?0:o>>>0);for(t=_r(t,e,3),m(n,function(n,r,e){i[++u]={a:t(n,r,e),b:u,c:n}}),o=i.length,i.sort(r);o--;)i[o]=i[o].c;return i},o.take=xt,o.tap=function(n,r){return r(n),n},o.throttle=function(n,r,t){var e=true,u=true;if(!gr(n))throw new TypeError(Sr);return false===t?e=false:hr(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),fr(n,r,{leading:e,maxWait:r,trailing:u}) -},o.times=function(n,r,t){n=0>n?0:n>>>0,r=g(r,t,1),t=-1;for(var e=Array(n);++tr?0:r))},o.lastIndexOf=function(n,r,t){var e=n?n.length:0;for(typeof t=="number"&&(e=(0>t?bt(e+t,0):_t(t||0,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.max=rr,o.min=function(n,r,t){var e=1/0,u=e,o=typeof r;if("number"!=o&&"string"!=o||!t||t[r]!==n||(r=null),null==r&&St(n))for(t=-1,o=n.length;++tn.indexOf(";")?n:n.replace(Ir,u)) -},o.uniqueId=function(n){var r=++Fr+"";return n?n+r:r},o.all=Q,o.any=ir,o.detect=Y,o.foldl=er,o.foldr=ur,o.head=L,o.include=K,o.inject=er,o.sample=function(n,r,t){var e=n?n.length:0;return typeof e=="number"&&-1r?0:+r||0,n.length),n)},wr(cr({},o)),o.VERSION="3.0.0-pre",o.prototype.chain=function(){return this.__chain__=true,this},o.prototype.value=function(){return this.__wrapped__},f("pop push reverse shift sort splice unshift".split(" "),function(n){var r=nt[n]; -o.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),wt.spliceObjects||0!==n.length||delete n[0],this}}),f(["concat","join","slice"],function(n){var r=nt[n];o.prototype[n]=function(){var n=r.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new i(n),n.__chain__=true),n}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Kr._=o, define("underscore",function(){return o})):Qr&&Xr?Zr?(Xr.exports=o)._=o:Qr._=o:Kr._=o}).call(this); \ No newline at end of file +;(function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++te||typeof t=="undefined"){t=1;break n}if(tu(r,i)&&o.push(i)}return o}function b(n,r){var t=n?n.length:0;if(typeof t!="number"||-1>=t||t>at)return x(n,r,$t);for(var e=-1,u=P(n);++e=t||t>at){for(var t=$t(n),e=t.length;e--;){var u=t[e];if(r(n[u],u,n)===Mr)break}return n}for(e=P(n);t--&&r(e[t],t,n)!==Mr;);return n}function d(n,r){var t=true;return b(n,function(n,e,u){return(t=!!r(n,e,u))||Mr}),t}function j(n,r){var t=[];return b(n,function(n,e,u){r(n,e,u)&&t.push(n)}),t}function w(n,r,t){var e;return t(n,function(n,t,u){return r(n,t,u)?(e=n,Mr):void 0}),e}function A(n,r,t,e){e=(e||0)-1;for(var u=n.length,o=0,i=[];++eo(f,c)&&(t&&f.push(c),i.push(a))}return i}function B(n,r){return function(t,e,u){var o=r?r():{};if(e=wr(e,u,3),Bt(t)){u=-1;for(var i=t.length;++ur?0:r)}function G(r,t,e){var u=r?r.length:0;if(typeof e=="number")e=0>e?At(u+e,0):e||0;else if(e)return e=K(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function H(n,r,t){return J(n,null==r||t?1:0>r?0:r)}function J(n,r,t){var e=-1,u=n?n.length:0;for(r=null==r?0:+r||0,0>r?r=At(u+r,0):r>u&&(r=u),t=typeof t=="undefined"?u:+t||0,0>t?t=At(u+t,0):t>u&&(t=u),u=r>t?0:t-r,t=Array(u);++e>>1;t(n[o])u&&(u=i)}else r=wr(r,t,3),b(n,function(n,t,o){t=r(n,t,o),(t>e||-1/0===t&&t===u)&&(e=t,u=n)});return u}function er(n,r){return rr(n,Er(r))}function ur(n,r,t,e){return(Bt(n)?p:I)(n,wr(r,e,4),t,3>arguments.length,b)}function or(n,r,t,e){return(Bt(n)?s:I)(n,wr(r,e,4),t,3>arguments.length,_)}function ir(n){n=P(n);for(var r=-1,t=n.length,e=Array(t);++r=t||t>r?(f&&clearTimeout(f),t=s,f=p=s=Or,t&&(g=Rt(),a=n.apply(l,i),p||f||(i=l=null))):p=setTimeout(e,t)}function u(){p&&clearTimeout(p),f=p=s=Or,(v||h!==r)&&(g=Rt(),a=n.apply(l,i),p||f||(i=l=null))}function o(){if(i=arguments,c=Rt(),l=this,s=v&&(p||!y),false===h)var t=y&&!p;else{f||y||(g=c);var o=h-(c-g),m=0>=o||o>h;m?(f&&(f=clearTimeout(f)),g=c,a=n.apply(l,i)):f||(f=setTimeout(u,o))}return m&&p?p=clearTimeout(p):p||r===h||(p=setTimeout(e,r)),t&&(m=true,a=n.apply(l,i)),!m||p||f||(i=l=null),a +}var i,f,a,c,l,p,s,g=0,h=false,v=true;if(!vr(n))throw new TypeError(Ir);if(r=0>r?0:r,true===t)var y=true,v=false;else yr(t)&&(y=t.leading,h="maxWait"in t&&At(+t.maxWait||0,r),v="trailing"in t?t.trailing:v);return o.cancel=function(){p&&clearTimeout(p),f&&clearTimeout(f),f=p=s=Or},o}function cr(n){if(!vr(n))throw new TypeError(Ir);return function(){return!n.apply(this,arguments)}}function lr(n){return S(n,Fr,J(arguments,1))}function pr(n){if(null==n)return n;var r=arguments,t=0,e=r.length,u=typeof r[2];for("number"!=u&&"string"!=u||!r[3]||r[3][r[2]]!==r[1]||(e=2);++t"'`]/g,$r=/^\[object .+?Constructor\]$/,Rr=/($^)/,Ur=/[.*+?^${}()|[\]\/\\]/g,Wr=/['\n\r\u2028\u2029\\]/g,Dr="[object Arguments]",zr="[object Boolean]",Cr="[object Date]",Pr="[object Error]",Vr="[object Number]",Gr="[object Object]",Hr="[object RegExp]",Jr="[object String]",Kr={};Kr[Dr]=Kr["[object Array]"]=Kr["[object Float32Array]"]=Kr["[object Float64Array]"]=Kr["[object Int8Array]"]=Kr["[object Int16Array]"]=Kr["[object Int32Array]"]=Kr["[object Uint8Array]"]=Kr["[object Uint8ClampedArray]"]=Kr["[object Uint16Array]"]=Kr["[object Uint32Array]"]=true,Kr["[object ArrayBuffer]"]=Kr[zr]=Kr[Cr]=Kr[Pr]=Kr["[object Function]"]=Kr["[object Map]"]=Kr[Vr]=Kr[Gr]=Kr[Hr]=Kr["[object Set]"]=Kr[Jr]=Kr["[object WeakMap]"]=false; +var Lr={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Qr={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},Xr={"function":true,object:true},Yr={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Zr=Xr[typeof window]&&window||this,nt=Xr[typeof exports]&&exports&&!exports.nodeType&&exports,rt=Xr[typeof module]&&module&&!module.nodeType&&module,tt=nt&&rt&&typeof global=="object"&&global;!tt||tt.global!==tt&&tt.window!==tt&&tt.self!==tt||(Zr=tt); +var et=rt&&rt.exports===nt&&nt,ut=Array.prototype,ot=Object.prototype,it=Function.prototype.toString,ft=Math.pow(2,32)-1,at=Math.pow(2,53)-1,ct=Zr._,lt=ot.toString,pt=RegExp("^"+(null==lt?"":(lt+"").replace(Ur,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),st=Math.ceil,gt=Math.floor,ht=ot.hasOwnProperty,vt=ut.push,yt=ot.propertyIsEnumerable,mt=ut.splice,bt=z(bt=Object.create)&&bt,_t=z(_t=Array.isArray)&&_t,dt=Zr.isFinite,jt=Zr.isNaN,wt=z(wt=Object.keys)&&wt,At=Math.max,xt=Math.min,Tt=z(Tt=Date.now)&&Tt,Et=Math.random,Ot={}; +!function(){var n={0:1,length:1};Ot.spliceObjects=(mt.call(n,0,1),!n[0])}(0,0),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},bt||(v=function(){function n(){}return function(r){if(yr(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Zr.Object()}}());var kt=H,St=V,Ft=B(function(n,r,t){ht.call(n,t)?n[t]++:n[t]=1}),Mt=B(function(n,r,t){ht.call(n,t)?n[t].push(r):n[t]=[r]}),It=B(function(n,r,t){n[t]=r}),Nt=B(function(n,r,t){n[t?0:1].push(r) +},function(){return[[],[]]}),qt=lr(function(n,r){var t;if(!vr(r))throw new TypeError(Ir);return function(){return 0<--n?t=r.apply(this,arguments):r=null,t}},2);hr(arguments)||(hr=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&ht.call(n,"callee")&&!yt.call(n,"callee")||false});var Bt=_t||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&"[object Array]"==lt.call(n)||false};vr(/x/)&&(vr=function(n){return typeof n=="function"&&"[object Function]"==lt.call(n)});var $t=wt?function(n){return yr(n)?wt(n):[] +}:C,Rt=Tt||function(){return(new Date).getTime()};i.prototype=o.prototype,o.after=function(n,r){if(!vr(r))throw new TypeError(Ir);return n=dt(n=+n)?n:0,function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=function(n,r){return 3>arguments.length?W(n,kr,r):S(n,kr|Fr,J(arguments,2),r)},o.bindAll=function(n){for(var r=n,t=1r?0:r) +},o.intersection=function(){for(var n=[],r=-1,t=arguments.length;++ri(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},o.invert=function(n){for(var r=-1,t=$t(n),e=t.length,u={};++ro?0:o>>>0);for(t=wr(t,e,3),b(n,function(n,r,e){i[++u]={a:t(n,r,e),b:u,c:n}}),o=i.length,i.sort(r);o--;)i[o]=i[o].c;return i},o.take=St,o.tap=function(n,r){return r(n),n},o.throttle=function(n,r,t){var e=true,u=true;if(!vr(n))throw new TypeError(Ir);return false===t?e=false:yr(t)&&(e="leading"in t?t.leading:e,u="trailing"in t?t.trailing:u),ar(n,r,{leading:e,maxWait:r,trailing:u}) +},o.times=function(n,r,t){n=dt(n=+n)&&-1r?0:r))},o.lastIndexOf=function(n,r,t){var e=n?n.length:0;for(typeof t=="number"&&(e=(0>t?At(e+t,0):xt(t||0,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.max=tr,o.min=function(n,r,t){var e=1/0,u=e,o=typeof r;if("number"!=o&&"string"!=o||!t||t[r]!==n||(r=null),null==r&&Bt(n))for(t=-1,o=n.length;++tn.indexOf(";")?n:n.replace(qr,u))},o.uniqueId=function(n){var r=++Nr+"";return n?n+r:r},o.all=X,o.any=fr,o.detect=Z,o.foldl=ur,o.foldr=or,o.head=V,o.include=Q,o.inject=ur,o.sample=function(n,r,t){n=P(n);var e=n.length;return null==r||t?0r?0:+r||0,n.length),n)},Tr(pr({},o)),o.VERSION="3.0.0-pre",o.prototype.chain=function(){return this.__chain__=true,this +},o.prototype.value=function(){return this.__wrapped__},f("pop push reverse shift sort splice unshift".split(" "),function(n){var r=ut[n];o.prototype[n]=function(){var n=this.__wrapped__;return r.apply(n,arguments),Ot.spliceObjects||0!==n.length||delete n[0],this}}),f(["concat","join","slice"],function(n){var r=ut[n];o.prototype[n]=function(){var n=r.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new i(n),n.__chain__=true),n}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Zr._=o, define("underscore",function(){return o +})):nt&&rt?et?(rt.exports=o)._=o:nt._=o:Zr._=o}).call(this); \ No newline at end of file