diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 17794596c..71d0d9181 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -78,7 +78,7 @@ var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g; /** Used to match words to create compound words */ - var reWords = /[a-z0-9]+/g; + var reWords = /[a-zA-Z0-9][a-z0-9]*/g; /** Used to detect and test whitespace */ var whitespace = ( @@ -259,7 +259,7 @@ * @param {Array} array The array to search. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. - * @returns {number} Returns the index of the matched value or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. */ function baseIndexOf(array, value, fromIndex) { var index = (fromIndex || 0) - 1, @@ -292,7 +292,7 @@ * * @private * @param {string} value The character to inspect. - * @returns {number} Returns the code unit of given character. + * @returns {number} Returns the code unit of the given character. */ function charAtCallback(value) { return value.charCodeAt(0); @@ -991,71 +991,6 @@ /*--------------------------------------------------------------------------*/ - /** - * The template used to create iterator functions. - * - * @private - * @param {Object} data The data object used to populate the text. - * @returns {string} Returns the interpolated text. - */ - var iteratorTemplate = function(obj) { - - var __p = 'var result = ' + - (obj.init) + - ';\nif (!isObject(object)) {\n return result;\n}'; - if (support.nonEnumArgs) { - __p += '\nvar length = object.length;\nif (length && isArguments(object)) {\n key = -1;\n while (++key < length) {\n key += \'\';\n ' + - (obj.loop) + - ';\n }\n return result;\n}'; - } - - if (support.enumPrototypes) { - __p += '\nvar skipProto = typeof object == \'function\';\n'; - } - - if (support.enumErrorProps) { - __p += '\nvar skipErrorProps = object === errorProto || object instanceof Error;\n'; - } - - var conditions = []; - if (support.enumPrototypes) { conditions.push('!(skipProto && key == \'prototype\')'); } - if (support.enumErrorProps) { conditions.push('!(skipErrorProps && (key == \'message\' || key == \'name\'))'); } - __p += '\nfor (var key in object) {\n'; - if (obj.useHas) { conditions.push('hasOwnProperty.call(object, key)'); } - if (conditions.length) { - __p += ' if (' + - (conditions.join(' && ')) + - ') {\n '; - } - __p += - (obj.loop) + - '; '; - if (conditions.length) { - __p += '\n }'; - } - __p += '\n}\n'; - if (support.nonEnumShadows) { - __p += '\nif (object !== objectProto) {\n var ctor = object.constructor,\n isProto = object === (ctor && ctor.prototype),\n className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),\n nonEnum = nonEnumProps[className];\n '; - for (var index = 0; index < 7; index++) { - __p += '\n key = \'' + - (obj.shadowedProps[index]) + - '\';\n if ((!(isProto && nonEnum[key]) && hasOwnProperty.call(object, key))'; - if (!obj.useHas) { - __p += ' || (!nonEnum[key] && object[key] !== objectProto[key])'; - } - __p += ') {\n ' + - (obj.loop) + - ';\n } '; - } - __p += '\n}'; - } - __p += '\nreturn result;'; - - return __p - }; - - /*--------------------------------------------------------------------------*/ - /** * The base implementation of `_.bind` that creates the bound function and * sets its meta data. @@ -1222,7 +1157,7 @@ * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @param {number} [argCount] The number of arguments the callback accepts. - * @returns {Function} Returns a callback function. + * @returns {Function} Returns the new function. */ function baseCreateCallback(func, thisArg, argCount) { if (typeof func != 'function') { @@ -1340,7 +1275,7 @@ * @private * @param {Array} array The array to process. * @param {Array} [values] The array of values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. */ function baseDifference(array, values) { var length = array ? array.length : 0; @@ -1445,7 +1380,7 @@ * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects. * @param {number} [fromIndex=0] The index to start from. - * @returns {Array} Returns a new flattened array. + * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, isShallow, isStrict, fromIndex) { var index = (fromIndex || 0) - 1, @@ -1477,17 +1412,20 @@ } /** - * The base implementation of `_.forOwn` without support for callback - * shorthands or `thisArg` binding. + * The base implementation of `baseForIn` and `baseForOwn` which iterates + * over `object` properties returned by `keysFunc` executing the callback + * for each property. Callbacks may exit iteration early by explicitly + * returning `false`. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. * @returns {Object} Returns `object`. */ - function baseForOwn(object, callback) { + function baseFor(object, callback, keysFunc) { var index = -1, - props = keys(object), + props = keysFunc(object), length = props.length; while (++index < length) { @@ -1500,16 +1438,18 @@ } /** - * The base implementation of `_.forOwnRight` without support for callback - * shorthands or `thisArg` binding. + * This function is like `baseFor` except that it iterates over properties + * in the opposite order. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. * @returns {Object} Returns `object`. */ - function baseForOwnRight(object, callback) { - var props = keys(object), + function baseForRight(object, callback, keysFunc) { + var index = -1, + props = keysFunc(object), length = props.length; while (length--) { @@ -1522,8 +1462,47 @@ } /** - * The base implementation of `_.isEqual`, without support for `thisArg` binding, - * that allows partial "_.where" style comparisons. + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForIn(object, callback) { + return baseFor(object, callback, keysIn); + } + + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + return baseFor(object, callback, keys); + } + + /** + * The base implementation of `_.forOwnRight` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwnRight(object, callback) { + return baseForRight(object, callback, keys); + } + + /** + * The base implementation of `_.isEqual`, without support for `thisArg` + * binding, that allows partial "_.where" style comparisons. * * @private * @param {*} a The value to compare. @@ -1758,7 +1737,7 @@ * @private * @param {number} min The minimum possible value. * @param {number} max The maximum possible value. - * @returns {number} Returns a random number. + * @returns {number} Returns the random number. */ function baseRandom(min, max) { return min + floor(nativeRandom() * (max - min + 1)); @@ -1772,7 +1751,7 @@ * @param {Array} array The array to process. * @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted. * @param {Function} [callback] The function called per iteration. - * @returns {Array} Returns a duplicate-value-free array. + * @returns {Array} Returns the new duplicate-value-free array. */ function baseUniq(array, isSorted, callback) { var length = array ? array.length : 0; @@ -1825,6 +1804,28 @@ return result; } + /** + * The base implementation of `_.values` and `_.valuesIn` which creates an + * array of `object` property values corresponding to the property names + * returned by `keysFunc`. + * + * @private + * @param {Object} object The object to inspect. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns the array of property values. + */ + function baseValues(object, keysFunc) { + var index = -1, + props = keysFunc(object), + length = props.length, + result = Array(length); + + while (++index < length) { + result[index] = object[props[index]]; + } + return result; + } + /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -1833,7 +1834,7 @@ * @param {Array} partialArg An array of arguments to prepend to those provided. * @param {Array} partialHolders An array of `partialArgs` placeholder indexes. * @param {Array|Object} args The provided arguments. - * @returns {Array} Returns a new array of composed arguments. + * @returns {Array} Returns the new array of composed arguments. */ function composeArgs(partialArgs, partialHolders, args) { var holdersLength = partialHolders.length, @@ -1863,7 +1864,7 @@ * @param {Array} partialRightArg An array of arguments to append to those provided. * @param {Array} partialHolders An array of `partialRightArgs` placeholder indexes. * @param {Array|Object} args The provided arguments. - * @returns {Array} Returns a new array of composed arguments. + * @returns {Array} Returns the new array of composed arguments. */ function composeArgsRight(partialRightArgs, partialRightHolders, args) { var holdersIndex = -1, @@ -1889,9 +1890,9 @@ /** * Creates a function that aggregates a collection, creating an object or - * array composed from the results of running each element of the collection - * through a callback. The given setter function sets the keys and values - * of the composed object or array. + * array composed from the results of running each element in the collection + * through a callback. The given setter function sets the keys and values of + * the composed object or array. * * @private * @param {Function} setter The setter function. @@ -1926,7 +1927,7 @@ * * @private * @param {Array} [array=[]] The array to search. - * @returns {Object} Returns the cache object. + * @returns {Object} Returns the new cache object. */ var createCache = Set && function(array) { var cache = new Set, @@ -1963,8 +1964,8 @@ } /** - * Creates a function that, when called, either curries or invokes `func` - * with an optional `this` binding and partially applied arguments. + * Creates a function that either curries or invokes `func` with an optional + * `this` binding and partially applied arguments. * * @private * @param {Function|string} func The function or method name to reference. @@ -2067,37 +2068,9 @@ : baseCreateWrapper(data); } - /** - * Creates compiled iteration functions. - * - * @private - * @param {Object} [options] The compile options object. - * @param {string} [options.args] A comma separated string of iteration function arguments. - * @param {string} [options.init] The string representation of the initial `result` value. - * @param {string} [options.loop] Code to execute in the object loop. - * @param {boolean} [options.useHas] Specify using `hasOwnProperty` checks in the object loop. - * @returns {Function} Returns the compiled function. - */ - function createIterator(options) { - options.shadowedProps = shadowedProps; - - // create the function factory - var factory = Function( - 'errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, ' + - 'nonEnumProps, stringClass, stringProto, toString', - 'return function(' + options.args + ') {\n' + iteratorTemplate(options) + '\n}' - ); - - // return the compiled function - return factory( - errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, - nonEnumProps, stringClass, stringProto, toString - ); - } - /** * Gets the appropriate "indexOf" function. If the `_.indexOf` method is - * customized this method returns the custom method, otherwise it returns + * customized this function returns the custom method, otherwise it returns * the `baseIndexOf` function. * * @private @@ -2203,36 +2176,28 @@ } /** - * The base implementation of `_.forIn` without support for callback - * shorthands or `thisArg` binding. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} callback The function called per iteration. - * @returns {Object} Returns `object`. - */ - var baseForIn = createIterator({ - 'args': 'object, callback', - 'init': 'object', - 'loop': 'if (callback(object[key], key, object) === false) {\n return result;\n }', - 'useHas': false - }); - - /** - * A fallback implementation of `Object.keys` which produces an array of the - * given object's own enumerable property names. + * A fallback implementation of `Object.keys` which creates an array of the + * own enumerable property names of `object`. * * @private * @type Function * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names. + * @returns {Array} Returns the array of property names. */ - var shimKeys = createIterator({ - 'args': 'object', - 'init': '[]', - 'loop': 'result.push(key)', - 'useHas': true - }); + function shimKeys(object) { + var index = -1, + props = keysIn(object), + length = props.length, + result = []; + + while (++index < length) { + var key = props[index]; + if (hasOwnProperty.call(object, key)) { + result.push(key); + } + } + return result; + } /*--------------------------------------------------------------------------*/ @@ -2244,7 +2209,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -2274,7 +2239,7 @@ * @category Arrays * @param {Array} array The array to process. * @param {...Array} [values] The arrays of values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.difference([1, 2, 3], [5, 2, 10]); @@ -2285,7 +2250,7 @@ } /** - * Creates an array with `n` elements dropped from the beginning of `array`. + * Creates a slice of `array` with `n` elements dropped from the beginning. * * @static * @memberOf _ @@ -2311,7 +2276,7 @@ var drop = rest; /** - * Creates an array with `n` elements dropped from the end of `array`. + * Creates a slice of `array` with `n` elements dropped from the end. * * @static * @memberOf _ @@ -2337,9 +2302,9 @@ var dropRight = initial; /** - * Creates an array of elements excluding those dropped from the end of `array`. + * Creates a slice of `array` excluding elements dropped from the end. * Elements will be dropped until the predicate returns falsey. The predicate - * is bound to `thisArg`nand invoked with three arguments; (value, index, array). + * is bound to `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2380,10 +2345,9 @@ var dropRightWhile = initial; /** - * Creates an array of elements excluding those dropped from the beginning - * of `array`. Elements will be dropped until the predicate returns falsey. - * The predicate is bound to `thisArg` and invoked with three arguments; - * (value, index, array). + * Creates a slice of `array` excluding elements dropped from the beginning. + * Elements will be dropped until the predicate returns falsey. The predicate + * is bound to `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2479,7 +2443,7 @@ /** * This method is like `_.findIndex` except that it iterates over elements - * of a `collection` from right to left. + * of a collection from right to left. * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2589,7 +2553,7 @@ * If a property name or object is provided it will be used to create a "_.pluck" * or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new flattened array. + * @returns {Array} Returns the new flattened array. * @example * * _.flatten([1, [2], [3, [[4]]]]); @@ -2643,7 +2607,7 @@ * @param {*} value The value to search for. * @param {boolean|number} [fromIndex=0] 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 or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. * @example * * _.indexOf([1, 2, 3, 1, 2, 3], 2); @@ -2707,13 +2671,16 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of shared values. + * @returns {Array} Returns the new array of shared values. * @example * * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [1, 2] */ - function intersection() { + function intersection(array) { + if (!array) { + return []; + } var args = [], argsIndex = -1, argsLength = arguments.length, @@ -2727,9 +2694,10 @@ if (isArray(value) || isArguments(value)) { args.push(value); caches.push(prereq && value.length >= 120 && - createCache(argsIndex ? args[argsIndex] : seen)); + createCache(argsIndex ? value : seen)); } } + argsLength = args.length; var array = args[0], index = -1, length = array ? array.length : 0, @@ -2790,9 +2758,9 @@ } /** - * 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. + * 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. * * @static * @memberOf _ @@ -2800,7 +2768,7 @@ * @param {Array} array The array to search. * @param {*} value The value to search for. * @param {number} [fromIndex=array.length-1] The index to search from. - * @returns {number} Returns the index of the matched value or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. * @example * * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); @@ -2870,7 +2838,7 @@ * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns a new range array. + * @returns {Array} Returns the new array of numbers. * @example * * _.range(4); @@ -2932,7 +2900,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of removed elements. + * @returns {Array} Returns the array of removed elements. * @example * * var array = [1, 2, 3, 4, 5, 6]; @@ -3005,7 +2973,7 @@ * @param {Array} array The array to slice. * @param {number} [start=0] The start index. * @param {number} [end=array.length] The end index. - * @returns {Array} Returns the new array. + * @returns {Array} Returns the slice of `array`. */ function slice(array, start, end) { var index = -1, @@ -3102,7 +3070,7 @@ } /** - * Creates an array of the first `n` elements of `array`. + * Creates a slice of `array` with `n` elements taken from the beginning. * * @static * @memberOf _ @@ -3114,7 +3082,7 @@ * @example * * _.take([1, 2, 3], 1); - * // => [2] + * // => [1] * * _.take([1, 2, 3], 2); * // => [1, 2] @@ -3128,7 +3096,7 @@ var take = first; /** - * Creates an array of the last `n` elements of `array`. + * Creates a slice of `array` with `n` elements taken from the end. * * @static * @memberOf _ @@ -3154,9 +3122,9 @@ var takeRight = last; /** - * Creates an array of elements from the end of `array`. Elements will be - * taken until the predicate returns falsey. The predicate is bound to `thisArg` - * and invoked with three arguments; (value, index, array). + * Creates a slice of `array` with elements taken from the end. Elements will + * be taken until the predicate returns falsey. The predicate is bound to + * `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -3197,9 +3165,9 @@ var takeRightWhile = last; /** - * Creates an array of elements from the beginning of `array`. Elements will - * be taken until the predicate returns falsey. The predicate is bound to - * `thisArg` and invoked with three arguments; (value, index, array). + * Creates a slice of `array` with elements taken from the beginning. Elements + * will be taken until the predicate returns falsey. The predicate is bound + * to `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -3247,7 +3215,7 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of combined values. + * @returns {Array} Returns the new array of combined values. * @example * * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); @@ -3282,7 +3250,7 @@ * If a property name or object is provided it will be used to create a "_.pluck" * or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a duplicate-value-free array. + * @returns {Array} Returns the new duplicate-value-free array. * @example * * _.uniq([1, 2, 1, 3, 1]); @@ -3336,7 +3304,7 @@ * @category Arrays * @param {Array} array The array to filter. * @param {...*} [value] The values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -3355,7 +3323,7 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of values. + * @returns {Array} Returns the new array of values. * @example * * _.xor([1, 2, 3], [5, 2, 1, 4]); @@ -3390,7 +3358,7 @@ * @alias unzip * @category Arrays * @param {...Array} [array] The arrays to process. - * @returns {Array} Returns a new array of grouped elements. + * @returns {Array} Returns the array of grouped elements. * @example * * _.zip(['fred', 'barney'], [30, 40], [true, false]); @@ -3422,8 +3390,7 @@ * @category Arrays * @param {Array} keys The array of keys. * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. + * @returns {Object} Returns the new object. * @example * * _.zipObject(['fred', 'barney'], [30, 40]); @@ -3458,7 +3425,7 @@ * @memberOf _ * @category Chaining * @param {*} value The value to wrap. - * @returns {Object} Returns the wrapper object. + * @returns {Object} Returns the new wrapper object. * @example * * var characters = [ @@ -3537,12 +3504,12 @@ } /** - * Produces the `toString` result of the wrapped value. + * Produces the result of coercing the wrapped value to a string. * * @name toString * @memberOf _ * @category Chaining - * @returns {string} Returns the string result. + * @returns {string} Returns the coerced string value. * @example * * _([1, 2, 3]).toString(); @@ -3580,10 +3547,9 @@ * @memberOf _ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. - * @param {...(number|number[]|string|string[])} [index] The indexes of `collection` - * to retrieve, specified as individual indexes or arrays of indexes. - * @returns {Array} Returns a new array of elements corresponding to the - * provided indexes. + * @param {...(number|number[]|string|string[])} [index] The indexes to retrieve, + * specified as individual indexes or arrays of indexes. + * @returns {Array} Returns the array of picked elements. * @example * * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); @@ -3790,7 +3756,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of elements that passed the predicate check. + * @returns {Array} Returns the new filtered array. * @example * * var evens = _.filter([1, 2, 3, 4], function(num) { return num % 2 == 0; }); @@ -3901,8 +3867,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 a + * collection from right to left. * * @static * @memberOf _ @@ -3934,7 +3900,7 @@ } /** - * Iterates over elements of a collection, executing the callback for each + * Iterates over elements of a collection executing the callback for each * element. The callback is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). Callbacks may exit iteration early by * explicitly returning `false`. @@ -3976,8 +3942,8 @@ } /** - * This method is like `_.forEach` except that it iterates over elements - * of a `collection` from right to left. + * This method is like `_.forEach` except that it iterates over elements of + * a collection from right to left. * * @static * @memberOf _ @@ -4074,18 +4040,18 @@ * @returns {Object} Returns the composed aggregate object. * @example * - * var keys = [ + * var keyData = [ * { 'dir': 'left', 'code': 97 }, * { 'dir': 'right', 'code': 100 } * ]; * - * _.indexBy(keys, 'dir'); + * _.indexBy(keyData, 'dir'); * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); + * _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); }); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keys, function(key) { return this.fromCharCode(key.code); }, String); + * _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } */ var indexBy = createAggregator(function(result, value, key) { @@ -4105,7 +4071,7 @@ * @param {Function|string} methodName The name of the method to invoke or * the function invoked per iteration. * @param {...*} [args] Arguments to invoke the method with. - * @returns {Array} Returns a new array of the results of each invoked method. + * @returns {Array} Returns the array of results. * @example * * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); @@ -4115,22 +4081,15 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var index = -1, + var args = slice(arguments, 2), + index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - if (arguments.length < 3 && isArray(collection)) { - while (++index < length) { - var value = collection[index]; - result[index] = isFunc ? methodName.call(value) : value[methodName](); - } - } else { - var args = slice(arguments, 2); - baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); - }); - } + baseEach(collection, function(value) { + result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + }); return result; } @@ -4155,7 +4114,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new array of the results of each `callback` execution. + * @returns {Array} Returns the new mapped array. * @example * * _.map([1, 2, 3], function(num) { return num * 3; }); @@ -4362,7 +4321,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of grouped elements. + * @returns {Array} Returns the array of grouped elements. * @example * * _.partition([1, 2, 3], function(num) { return num % 2; }); @@ -4398,7 +4357,7 @@ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. * @param {string} key The name of the property to pluck. - * @returns {Array} Returns a new array of property values. + * @returns {Array} Returns the property values. * @example * * var characters = [ @@ -4466,8 +4425,8 @@ } /** - * 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 a + * collection from right to left. * * @static * @memberOf _ @@ -4515,7 +4474,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of elements that failed the predicate check. + * @returns {Array} Returns the new filtered array. * @example * * var odds = _.reject([1, 2, 3, 4], function(num) { return num % 2 == 0; }); @@ -4536,9 +4495,7 @@ */ function reject(collection, predicate, thisArg) { predicate = lodash.createCallback(predicate, thisArg, 3); - return filter(collection, function(value, index, collection) { - return !predicate(value, index, collection); - }); + return filter(collection, negate(predicate)); } /** @@ -4550,7 +4507,7 @@ * @param {Array|Object|string} collection The collection to sample. * @param {number} [n] The number of elements to sample. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`. - * @returns {*} Returns the random sample(s) of `collection`. + * @returns {*} Returns the random sample(s). * @example * * _.sample([1, 2, 3, 4]); @@ -4582,7 +4539,7 @@ * @memberOf _ * @category Collections * @param {Array|Object|string} collection The collection to shuffle. - * @returns {Array} Returns a new shuffled collection. + * @returns {Array} Returns the new shuffled array. * @example * * _.shuffle([1, 2, 3, 4]); @@ -4715,7 +4672,7 @@ * called per iteration. If a property name or object is provided it will * be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new array of sorted elements. + * @returns {Array} Returns the new sorted array. * @example * * _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); @@ -4803,7 +4760,7 @@ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. * @param {Object} source The object of property values to filter by. - * @returns {Array} Returns a new array of elements that have the given properties. + * @returns {Array} Returns the new filtered array. * @example * * var characters = [ @@ -4857,9 +4814,9 @@ } /** - * Creates a function that, when called, invokes `func` with the `this` - * binding of `thisArg` and prepends any additional `bind` arguments to those - * provided to the bound function. + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and prepends any additional `bind` arguments to those provided to the bound + * function. * * Note: Unlike native `Function#bind` this method does not set the `length` * property of bound functions. @@ -4933,10 +4890,10 @@ } /** - * Creates a function that, when called, invokes the method at `object[key]` - * and prepends any additional `bindKey` arguments to those provided to the bound - * function. This method differs from `_.bind` by allowing bound functions to - * reference methods that will be redefined or don't yet exist. + * Creates a function that invokes the method at `object[key]` and prepends + * any additional `bindKey` arguments to those provided to the bound function. + * This method differs from `_.bind` by allowing bound functions to reference + * methods that will be redefined or don't yet exist. * See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern) * for more details. * @@ -5260,7 +5217,7 @@ * @memberOf _ * @category Functions * @param {Function} func The function to have its output memoized. - * @param {Function} [resolver] A function used to resolve the cache key. + * @param {Function} [resolver] The function to resolve the cache key. * @returns {Function} Returns the new memoizing function. * @example * @@ -5339,9 +5296,9 @@ } /** - * Creates a function that, when called, invokes `func` with any additional - * `partial` arguments prepended to those provided to the new function. This - * method is similar to `_.bind` except it does **not** alter the `this` binding. + * Creates a function that invokes `func` with any additional `partial` arguments + * prepended to those provided to the new function. This method is similar to + * `_.bind` except it does **not** alter the `this` binding. * * Note: This method does not set the `length` property of partially applied * functions. @@ -5516,6 +5473,9 @@ * // => { 'name': 'barney', 'employer': 'slate' } */ function assign(object, source, guard) { + if (!object) { + return object; + } var args = arguments, argsIndex = 0, argsLength = args.length, @@ -5533,15 +5493,13 @@ } while (++argsIndex < argsLength) { source = args[argsIndex]; - if (isObject(source)) { - var index = -1, - props = keys(source), - length = props.length; + var index = -1, + props = keys(source), + length = props.length; - while (++index < length) { - var key = props[index]; - object[key] = callback ? callback(object[key], source[key]) : source[key]; - } + while (++index < length) { + var key = props[index]; + object[key] = callback ? callback(object[key], source[key]) : source[key]; } } return object; @@ -5712,6 +5670,9 @@ * // => { 'name': 'barney', 'employer': 'slate' } */ function defaults(object, source, guard) { + if (!object) { + return object; + } var args = arguments, argsIndex = 0, argsLength = args.length, @@ -5723,16 +5684,14 @@ } while (++argsIndex < argsLength) { source = args[argsIndex]; - if (isObject(source)) { - var index = -1, - props = keys(source), - length = props.length; + var index = -1, + props = keys(source), + length = props.length; - while (++index < length) { - var key = props[index]; - if (typeof object[key] == 'undefined') { - object[key] = source[key]; - } + while (++index < length) { + var key = props[index]; + if (typeof object[key] == 'undefined') { + object[key] = source[key]; } } } @@ -5794,8 +5753,8 @@ } /** - * This method is like `_.findKey` except that it iterates over elements - * of a `collection` in the opposite order. + * This method is like `_.findKey` except that it iterates over elements of + * a collection in the opposite order. * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -5848,10 +5807,10 @@ } /** - * Iterates over own and inherited enumerable properties of an object, - * executing the callback for each property. The callback is bound to `thisArg` - * and invoked with three arguments; (value, key, object). Callbacks may exit - * iteration early by explicitly returning `false`. + * Iterates over own and inherited enumerable properties of an object executing + * the callback for each property. The callback is bound to `thisArg` and invoked + * with three arguments; (value, key, object). Callbacks may exit iteration + * early by explicitly returning `false`. * * @static * @memberOf _ @@ -5868,24 +5827,21 @@ * this.y = 0; * } * - * Shape.prototype.move = function(x, y) { - * this.x += x; - * this.y += y; - * }; + * Shape.prototype.z = 0; * * _.forIn(new Shape, function(value, key) { * console.log(key); * }); - * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) + * // => logs 'x', 'y', and 'z' (property order is not guaranteed across environments) */ function forIn(object, callback, thisArg) { callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - return baseForIn(object, callback); + return baseFor(object, callback, keysIn); } /** - * 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 elements of a + * collection in the opposite order. * * @static * @memberOf _ @@ -5901,34 +5857,20 @@ * this.y = 0; * } * - * Shape.prototype.move = function(x, y) { - * this.x += x; - * this.y += y; - * }; + * Shape.prototype.z = 0; * * _.forInRight(new Shape, function(value, key) { * console.log(key); * }); - * // => logs 'move', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'move' + * // => logs 'z', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'z' */ function forInRight(object, callback, thisArg) { - var pairs = []; - baseForIn(object, function(value, key) { - pairs.push(key, value); - }); - - var length = pairs.length; callback = baseCreateCallback(callback, thisArg, 3); - while (length--) { - if (callback(pairs[length--], pairs[length], object) === false) { - break; - } - } - return object; + return baseForRight(object, callback, keysIn); } /** - * Iterates over own enumerable properties of an object, executing the callback + * Iterates over own enumerable properties of an object executing the callback * for each property. The callback is bound to `thisArg` and invoked with three * arguments; (value, key, object). Callbacks may exit iteration early by * explicitly returning `false`. @@ -5953,8 +5895,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 elements of a + * collection in the opposite order. * * @static * @memberOf _ @@ -5971,17 +5913,8 @@ * // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length' */ function forOwnRight(object, callback, thisArg) { - var props = keys(object), - length = props.length; - callback = baseCreateCallback(callback, thisArg, 3); - while (length--) { - var key = props[length]; - if (callback(object[key], key, object) === false) { - break; - } - } - return object; + return baseForRight(object, callback, keys); } /** @@ -5993,7 +5926,7 @@ * @alias methods * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names that have function values. + * @returns {Array} Returns the new sorted array of property names. * @example * * _.functions(_); @@ -6001,6 +5934,7 @@ */ function functions(object) { var result = []; + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); @@ -6039,7 +5973,7 @@ * @category Objects * @param {Object} object The object to invert. * @param {boolean} [multiValue=false] Allow multiple values per key. - * @returns {Object} Returns the created inverted object. + * @returns {Object} Returns the new inverted object. * @example * * _.invert({ 'first': 'fred', 'second': 'barney' }); @@ -6077,6 +6011,34 @@ return result; } + /** + * Checks if `value` is an `arguments` object. + * + * @static + * @memberOf _ + * @category Objects + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`. + * @example + * + * (function() { return _.isArguments(arguments); })(1, 2, 3); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + function isArguments(value) { + return value && typeof value == 'object' && typeof value.length == 'number' && + toString.call(value) == argsClass || false; + } + // fallback for environments that can't detect `arguments` objects by [[Class]] + if (!support.argsClass) { + isArguments = function(value) { + return value && typeof value == 'object' && typeof value.length == 'number' && + hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee') || false; + }; + } + /** * Checks if `value` is an array. * @@ -6508,29 +6470,93 @@ } /** - * Creates an array composed of the own enumerable property names of `object`. + * Creates an array of the own enumerable property names of `object`. * * @static * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names. + * @returns {Array} Returns the array of property names. * @example * - * _.keys({ 'one': 1, 'two': 2, 'three': 3 }); - * // => ['one', 'two', 'three'] (property order is not guaranteed across environments) + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * Shape.prototype.z = 0; + * + * _.keys(new Shape); + * // => ['x', 'y'] (property order is not guaranteed across environments) */ var keys = !nativeKeys ? shimKeys : function(object) { - if (!isObject(object)) { - return []; - } if ((support.enumPrototypes && typeof object == 'function') || - (support.nonEnumArgs && object.length && isArguments(object))) { + (support.nonEnumArgs && object && object.length && isArguments(object))) { return shimKeys(object); } - return nativeKeys(object); + return isObject(object) ? nativeKeys(object) : []; }; + /** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to inspect. + * @returns {Array} Returns the array of property names. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * Shape.prototype.z = 0; + * + * _.keysIn(new Shape); + * // => ['x', 'y', 'z'] (property order is not guaranteed across environments) + */ + function keysIn(object) { + var result = []; + if (!isObject(object)) { + return result; + } + if (support.nonEnumArgs && object.length && isArguments(object)) { + object = slice(object); + } + var skipProto = support.enumPrototypes && typeof object == 'function', + skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error); + + for (var key in object) { + if (!(skipProto && key == 'prototype') && + !(skipErrorProps && (key == 'message' || key == 'name'))) { + result.push(key); + } + } + // Lo-Dash skips the `constructor` property when it infers it's 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. + if (support.nonEnumShadows && object !== objectProto) { + var ctor = object.constructor, + index = -1, + length = shadowedProps.length; + + if (object === (ctor && ctor.prototype)) { + var className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object), + nonEnum = nonEnumProps[className]; + } + while (++index < length) { + key = shadowedProps[index]; + if (!(nonEnum && nonEnum[key]) && hasOwnProperty.call(object, key)) { + result.push(key); + } + } + } + return result; + } + /** * Creates an object with the same keys as `object` and values generated by * running each own enumerable property of `object` through the callback. @@ -6552,7 +6578,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Object} Returns a new object with values of the results of each `callback` execution. + * @returns {Object} Returns the new mapped object. * @example * * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; }); @@ -6629,7 +6655,7 @@ * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot] } */ function merge(object, source, guard) { - if (!isObject(object)) { + if (!object) { return object; } var args = arguments, @@ -6646,7 +6672,7 @@ } else if (length > 2 && typeof args[length - 1] == 'function') { callback = args[--length]; } - var sources = slice(arguments, 1, length), + var sources = slice(args, 1, length), index = -1, stackA = [], stackB = []; @@ -6673,7 +6699,7 @@ * iteration or property names to omit, specified as individual property * names or arrays of property names. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns an object without the omitted properties. + * @returns {Object} Returns the new object. * @example * * _.omit({ 'name': 'fred', 'age': 40 }, 'age'); @@ -6685,37 +6711,17 @@ * // => { 'name': 'fred' } */ function omit(object, predicate, thisArg) { - var result = {}; - - if (typeof predicate != 'function') { - var omitProps = baseFlatten(arguments, true, false, 1), - length = omitProps.length; - - while (length--) { - omitProps[length] = String(omitProps[length]); - } - var props = []; - baseForIn(object, function(value, key) { - props.push(key); - }); - - var index = -1; - props = baseDifference(props, omitProps); - length = props.length; - - while (++index < length) { - var key = props[index]; - result[key] = object[key]; - } - } else { + if (typeof predicate == 'function') { predicate = lodash.createCallback(predicate, thisArg, 3); - baseForIn(object, function(value, key, object) { - if (!predicate(value, key, object)) { - result[key] = value; - } - }); + return pick(object, negate(predicate)); } - return result; + var omitProps = baseFlatten(arguments, true, false, 1), + length = omitProps.length; + + while (length--) { + omitProps[length] = String(omitProps[length]); + } + return pick(object, baseDifference(keysIn(object), omitProps)); } /** @@ -6761,7 +6767,7 @@ * iteration or property names to pick, specified as individual property * names or arrays of property names. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns an object composed of the picked properties. + * @returns {Object} Returns the new object. * @example * * _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name'); @@ -6850,28 +6856,52 @@ } /** - * Creates an array composed of the own enumerable property values of `object`. + * Creates an array of the own enumerable property values of `object`. * * @static * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property values. + * @returns {Array} Returns the array of property values. * @example * - * _.values({ 'one': 1, 'two': 2, 'three': 3 }); - * // => [1, 2, 3] (property order is not guaranteed across environments) + * function Shape(x, y) { + * this.x = x; + * this.y = y; + * } + * + * Shape.prototype.z = 0; + * + * _.values(new Shape(2, 1)); + * // => [2, 1] (property order is not guaranteed across environments) */ function values(object) { - var index = -1, - props = keys(object), - length = props.length, - result = Array(length); + return baseValues(object, keys); + } - while (++index < length) { - result[index] = object[props[index]]; - } - return result; + /** + * Creates an array of the own and inherited enumerable property values + * of `object`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to inspect. + * @returns {Array} Returns the array of property values. + * @example + * + * function Shape(x, y) { + * this.x = x; + * this.y = y; + * } + * + * Shape.prototype.z = 0; + * + * _.valuesIn(new Shape(2, 1)); + * // => [2, 1, 0] (property order is not guaranteed across environments) + */ + function valuesIn(object) { + return baseValues(object, keysIn); } /*--------------------------------------------------------------------------*/ @@ -6896,8 +6926,8 @@ * _.camelCase('hello_world'); * // => 'helloWorld' */ - var camelCase = createCompounder(function(result, words, index) { - return result + words.charAt(0)[index ? 'toUpperCase' : 'toLowerCase']() + words.slice(1); + var camelCase = createCompounder(function(result, word, index) { + return result + word.charAt(0)[index ? 'toUpperCase' : 'toLowerCase']() + word.slice(1); }); /** @@ -6989,7 +7019,7 @@ * @example * * _.escapeRegExp('[lodash](http://lodash.com)'); - * // => '\[lodash]\(http://lodash\.com\)' + * // => '\[lodash\]\(http://lodash\.com\)' */ function escapeRegExp(string) { return string == null ? '' : String(string).replace(reRegExpChars, '\\$&'); @@ -7016,8 +7046,8 @@ * _.kebabCase('hello_world'); * // => 'hello-world' */ - var kebabCase = createCompounder(function(result, words, index) { - return result + (index ? '-' : '') + words.toLowerCase(); + var kebabCase = createCompounder(function(result, word, index) { + return result + (index ? '-' : '') + word.toLowerCase(); }); /** @@ -7143,13 +7173,13 @@ return result; } string = String(string); - while (n > 0) { + do { if (n % 2) { result += string; } n = floor(n / 2); - result += result; - } + string += string; + } while (n > 0); return result; } @@ -7173,8 +7203,8 @@ * _.snakeCase('helloWorld'); * // => 'hello_world' */ - var snakeCase = createCompounder(function(result, words, index) { - return result + (index ? '_' : '') + words.toLowerCase(); + var snakeCase = createCompounder(function(result, word, index) { + return result + (index ? '_' : '') + word.toLowerCase(); }); /** @@ -7237,7 +7267,7 @@ * @param {string} [options.sourceURL] The sourceURL of the template's compiled source. * @param {string} [options.variable] The data object variable name. * @returns {Function|string} Returns the interpolated string if a data object - * is provided, else it returns a template function. + * is provided, else the compiled template function. * @example * * // using the "interpolate" delimiter to create a compiled template @@ -7300,10 +7330,8 @@ // and Laura Doktorova's doT.js // https://github.com/olado/doT var settings = lodash.templateSettings; - string = String(string == null ? '' : string); - - // avoid missing dependencies when `iteratorTemplate` is not defined options = defaults({}, options, settings); + string = String(string == null ? '' : string); var imports = defaults({}, options.imports, settings.imports), importsKeys = keys(imports), @@ -7601,7 +7629,7 @@ } /** - * Produces a callback bound to an optional `thisArg`. If `func` is a property + * Creates a function bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. * If `func` is an object the created callback will return `true` for elements * that contain the equivalent object properties, otherwise it will return `false`. @@ -7613,7 +7641,7 @@ * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @param {number} [argCount] The number of arguments the callback accepts. - * @returns {Function} Returns a callback function. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -7798,6 +7826,33 @@ } } + /** + * Creates a function that negates the result of `func`. The `func` function + * is executed with the `this` binding and arguments of the created function. + * + * @static + * @memberOf _ + * @category Utilities + * @param {Function} func The function to negate. + * @returns {Function} Returns the new function. + * @example + * + * function isEven(num) { + * return num % 2 == 0; + * } + * + * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); + * // => [1, 3, 5] + */ + function negate(func) { + if (!isFunction(func)) { + throw new TypeError; + } + return function() { + return !func.apply(this, arguments); + }; + } + /** * Reverts the '_' variable to its previous value and returns a reference to * the `lodash` function. @@ -7862,7 +7917,7 @@ * @category Utilities * @param {string} value The value to parse. * @param {number} [radix] The radix used to interpret the value to parse. - * @returns {number} Returns the new integer value. + * @returns {number} Returns the converted integer value. * @example * * _.parseInt('08'); @@ -7918,7 +7973,7 @@ * @param {number} [min=0] The minimum possible value. * @param {number} [max=1] The maximum possible value. * @param {boolean} [floating=false] Specify returning a floating-point number. - * @returns {number} Returns a random number. + * @returns {number} Returns the random number. * @example * * _.random(0, 5); @@ -8017,7 +8072,7 @@ * @param {number} n The number of times to execute the callback. * @param {Function} [callback=identity] The function called per iteration. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns an array of the results of each `callback` execution. + * @returns {Array} Returns the array of results. * @example * * var diceRolls = _.times(3, _.partial(_.random, 1, 6)); @@ -8104,6 +8159,7 @@ lodash.invert = invert; lodash.invoke = invoke; lodash.keys = keys; + lodash.keysIn = keysIn; lodash.map = map; lodash.mapValues = mapValues; lodash.matches = matches; @@ -8111,6 +8167,7 @@ lodash.memoize = memoize; lodash.merge = merge; lodash.min = min; + lodash.negate = negate; lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; @@ -8136,6 +8193,7 @@ lodash.union = union; lodash.uniq = uniq; lodash.values = values; + lodash.valuesIn = valuesIn; lodash.where = where; lodash.without = without; lodash.wrap = wrap; @@ -8342,7 +8400,6 @@ }; }); } - return lodash; } diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 66957d0fe..0837edc8e 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -3,67 +3,67 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.6.0 underscorejs.org/LICENSE * Build: `lodash -o ./dist/lodash.compat.js` */ -;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(nt||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202a(e,l)&&f.push(l);return f}function st(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(ge.unindexedChars&&cr(e)&&(e=e.split(""));++ri(s,g)&&((u||f)&&s.push(g),c.push(p))}return c}function xt(n,t,r){for(var e=t.length,u=-1,o=ee(r.length-e,0),a=-1,i=n.length,l=_r(o+i);++ar&&(r=0),s&&(a=[]),p&&(i=[]),g=[n,t,r,e,u,o,a,i],t==w||t==(w|k)?f(g):X(g))}function Ot(n){n.d=H;var t=Cr,r="return function("+n.a+"){",e="var r="+n.b+";if(!j(p)){return r}";ge.nonEnumArgs&&(e+="var m=p.length;if(m&&i(p)){l=-1;while(++lu;u++)e+="l='"+n.d[u]+"';if((!(k&&n[l])&&g.call(p,l))",n.e||(e+="||(!n[l]&&p[l]!==q[l])"),e+="){"+n.c+"}";e+="}"}return t("e,f,g,i,j,q,o,u,v,w",r+(e+"return r;")+"}")(tt,Rr,Ur,It,ir,Nr,pe,at,Tr,Wr) -}function Et(){var n=(n=u.indexOf)===Nt?t:n;return n}function At(n){return typeof n=="function"&&Fr.test(Br.call(n))}function St(n){var t,r;return!n||Wr.call(n)!=ut||!Ur.call(n,"constructor")&&(t=n.constructor,ar(t)&&!(t instanceof t))||!ge.argsClass&&It(n)||!ge.nodeClass&&p(n)?false:ge.ownLast?(ye(n,function(n,t,e){return r=Ur.call(e,t),false}),false!==r):(ye(n,function(n,t){r=t}),typeof r=="undefined"||Ur.call(n,r))}function It(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Wr.call(n)==J||false -}function Rt(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,o=n?n.length:0,a=0;for(t=u.createCallback(t,r,3);++ee?ee(0,u+e):e||0;else if(e)return e=Ft(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Tt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,a=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)a++}else a=null==t||r?1:t;return a=e-a,Wt(n,0,0t?t=ee(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=ee(u+r,0):r>u&&(r=u),u=r-t||0,r=_r(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!Ce(n)&&cr(n))return Jr?Jr.call(n,t,r):-1r?ee(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&cr(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Ht(n,t,r,e){var o=3>arguments.length;if(t=u.createCallback(t,e,4),Ce(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),pt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Qt(n){var t=-1,r=n?n.length:0,e=_r(typeof r=="number"?r:0); -return st(n,function(n){var r=_t(0,++t);e[t]=e[r],e[r]=n}),e}function Zt(n,t,r){var e;if(t=u.createCallback(t,r,3),Ce(n)){r=-1;for(var o=n.length;++rarguments.length)return kt(n,w,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Wt(arguments,2),r=r-e.length;return kt(n,w|k,r,t,e)}function tr(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true;if(!ar(n))throw new Sr;if(t=0=r||r>t?(u&&$r(u),r=f,u=l=f=_,r&&(c=Ne(),o=n.apply(i,e),l||u||(e=i=null))):l=Xr(h,r)},v=function(){l&&$r(l),u=l=f=_,(p||s!==t)&&(c=Ne(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Ne(),i=this,f=p&&(l||!g),false===s)var r=g&&!l;else{u||g||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=$r(u)),c=a,o=n.apply(i,e)):u||(u=Xr(v,y))}return m&&l?l=$r(l):l||t===s||(l=Xr(h,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function rr(n,t,r){var e=arguments,u=0,o=e.length,a=typeof r; -if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;for(n=Ar(n);0--n?t.apply(this,arguments):void 0}},u.assign=rr,u.at=function(n,t){var r=arguments,e=-1,u=gt(r,true,false,1),o=u.length,a=typeof t;for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),ge.unindexedChars&&cr(n)&&(n=n.split("")),r=_r(o);++earguments.length?kt(t,w|x,null,n):kt(t,w|x|k,null,n,Wt(arguments,2))},u.chain=function(n){return n=new o(n),n.__chain__=true,n},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(g?r(g,f):a(l,f))){for(e=u,(g||l).push(f);--e;)if(g=o[e],0>(g?r(g,f):a(n[e],f)))continue n;p.push(f)}}return p},u.invert=function(n,t){for(var r=-1,e=ke(n),u=e.length,o={};++rarguments.length&&Ce(n))for(;++rr?ee(0,e+r):ue(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},u.mixin=mr,u.noConflict=function(){return n._=Pr,this},u.noop=dr,u.now=Ne,u.pad=function(n,t,r){n=null==n?"":Ar(n),t=+t||0;var e=n.length;return en.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(fr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Er(u.source,($.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; -r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Ar(null==n?"":n)+t},u.all=Ut,u.any=Zt,u.detect=Mt,u.findWhere=Mt,u.foldl=Ht,u.foldr=Jt,u.include=zt,u.inject=Ht,mr(function(){var n={};return ht(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Rt,u.last=Lt,u.sample=function(n,t,r){return n&&typeof n.length!="number"?n=sr(n):ge.unindexedChars&&cr(n)&&(n=n.split("")),null==t||r?n?n[_t(0,n.length-1)]:_:(n=Qt(n),n.length=ue(ee(0,t),n.length),n) -},u.take=Rt,u.takeRight=Lt,u.takeRightWhile=Lt,u.takeWhile=Rt,u.head=Rt,ht(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,a=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(a,u):a})}),u.VERSION=E,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Ar(this.__wrapped__)},u.prototype.value=Bt,u.prototype.valueOf=Bt,st(["join","pop","shift"],function(n){var t=Ir[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); -return n?new o(r,n):r}}),st(["push","reverse","sort","unshift"],function(n){var t=Ir[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),st(["concat","splice"],function(n){var t=Ir[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),ge.spliceObjects||st(["pop","shift","splice"],function(n){var t=Ir[n],r="splice"==n;u.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 o(u,n):u -}}),u}var _,w=1,x=2,C=4,j=8,k=16,O=32,E="2.4.1",A="__lodash@"+E+"__",S=0,I=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,T=/&(?:amp|lt|gt|quot|#39);/g,L=/[&<>"']/g,P=/<%-([\s\S]+?)%>/g,W=/<%([\s\S]+?)%>/g,F=/<%=([\s\S]+?)%>/g,q=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,$=/\w*$/,D=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,z=/[\xC0-\xFF]/g,U=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X=/[a-z0-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 Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="[object Arguments]",Q="[object Array]",Z="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; -it[rt]=false,it[J]=it[Q]=it[Z]=it[nt]=it[et]=it[ut]=it[ot]=it[at]=true;var lt={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},ct={"&":"&","<":"<",">":">",'"':""","'":"'"},st={"&":"&","<":"<",">":">",""":'"',"'":"'"},pt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":"","\xf7":""},gt={"function":true,object:true},ht={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},vt=gt[typeof window]&&window||this,yt=gt[typeof exports]&&exports&&!exports.nodeType&&exports,gt=gt[typeof module]&&module&&!module.nodeType&&module,mt=yt&>&&typeof global=="object"&&global; -!mt||mt.global!==mt&&mt.window!==mt&&mt.self!==mt||(vt=mt);var mt=gt&>.exports===yt&&yt,dt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(vt._=dt, define(function(){return dt})):yt&>?mt?(gt.exports=dt)._=dt:yt._=dt:vt._=dt}).call(this); \ No newline at end of file +}return t}function d(n){return st[n]}function b(n){function u(n){return n&&typeof n=="object"&&!Ee(n)&&Zr.call(n,"__wrapped__")?n:new o(n)}function o(n,t){this.__chain__=!!t,this.__wrapped__=n}function f(n){function t(){if(u){for(var n=-1,a=arguments.length,i=kr(a);++na(e,l)&&f.push(l);return f}function st(n,t){var r=-1,e=n,u=n?n.length:0;if(typeof u=="number")for(be.unindexedChars&&pr(e)&&(e=e.split(""));++ri(s,h)&&((u||f)&&s.push(h),c.push(p))}return c}function Ct(n,t){for(var r=-1,e=t(n),u=e.length,o=kr(u);++rr&&(r=0),s&&(a=[]),p&&(i=[]),h=[n,t,r,e,u,o,a,i],t==w||t==(w|k)?f(h):X(h)) +}function At(){var n=(n=u.indexOf)===Lt?t:n;return n}function St(n){return typeof n=="function"&&Ur.test(Xr.call(n))}function It(n){var t,r;return!n||qr.call(n)!=ut||!Zr.call(n,"constructor")&&(t=n.constructor,lr(t)&&!(t instanceof t))||!be.argsClass&&Rt(n)||!be.nodeClass&&p(n)?false:be.ownLast?(gt(n,function(n,t,e){return r=Zr.call(e,t),false},hr),false!==r):(gt(n,function(n,t){r=t},hr),typeof r=="undefined"||Zr.call(n,r))}function Rt(n){return n&&typeof n=="object"&&typeof n.length=="number"&&qr.call(n)==H||false +}function Nt(n){for(var t=-1,r=hr(n),e=r.length,u=[];++te?fe(0,u+e):e||0;else if(e)return e=Dt(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Wt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,a=0; +for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)a++}else a=null==t||r?1:t;return a=e-a,$t(n,0,0t?t=fe(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=fe(u+r,0):r>u&&(r=u),u=r-t||0,r=kr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!Ee(n)&&pr(n))return ee?ee.call(n,t,r):-1r?fe(0,e+r):r)||0,-1a&&(a=l)}else t=null==t&&pr(n)?e:u.createCallback(t,r,3),st(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,a=n)});return a}function Jt(n,t,r,e){var o=3>arguments.length;if(t=u.createCallback(t,e,4),Ee(n)){var a=-1,i=n.length;for(o&&i&&(r=n[++a]);++aarguments.length;return t=u.createCallback(t,e,4),pt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u) +}),r}function nr(n){var t=-1,r=n?n.length:0,e=kr(typeof r=="number"?r:0);return st(n,function(n){var r=wt(0,++t);e[t]=e[r],e[r]=n}),e}function tr(n,t,r){var e;if(t=u.createCallback(t,r,3),Ee(n)){r=-1;for(var o=n.length;++rarguments.length)return Et(n,w,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=$t(arguments,2),r=r-e.length;return Et(n,w|k,r,t,e)}function er(n,t,r){var e,u,o,a,i,l,f,c=0,s=false,p=true; +if(!lr(n))throw new Wr;if(t=0=r||r>t?(u&&Mr(u),r=f,u=l=f=_,r&&(c=Fe(),o=n.apply(i,e),l||u||(e=i=null))):l=Qr(g,r)},v=function(){l&&Mr(l),u=l=f=_,(p||s!==t)&&(c=Fe(),o=n.apply(i,e),l||u||(e=i=null))};return function(){if(e=arguments,a=Fe(),i=this,f=p&&(l||!h),false===s)var r=h&&!l;else{u||h||(c=a);var y=s-(a-c),m=0>=y||y>s;m?(u&&(u=Mr(u)),c=a,o=n.apply(i,e)):u||(u=Qr(v,y)) +}return m&&l?l=Mr(l):l||t===s||(l=Qr(g,t)),r&&(m=true,o=n.apply(i,e)),!m||l||u||(e=i=null),o}}function ur(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,a=typeof r;if("number"!=a&&"string"!=a||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Lr(n);do t%2&&(r+=n),t=Vr(t/2),n+=n;while(0--n?t.apply(this,arguments):void 0}},u.assign=ur,u.at=function(n,t){var r=arguments,e=-1,u=ht(r,true,false,1),o=u.length,a=typeof t; +for("number"!=a&&"string"!=a||!r[2]||r[2][t]!==n||(o=1),be.unindexedChars&&pr(n)&&(n=n.split("")),r=kr(o);++earguments.length?Et(t,w|x,null,n):Et(t,w|x|k,null,n,$t(arguments,2))},u.chain=function(n){return n=new o(n),n.__chain__=true,n},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,c):i(f,c))){for(u=o,(h||f).push(c);--u;)if(h=a[u],0>(h?r(h,c):i(e[u],c)))continue n;p.push(c)}}return p},u.invert=function(n,t){for(var r=-1,e=Se(n),u=e.length,o={};++rr?fe(0,e+r):ce(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=wr,u.noConflict=function(){return n._=Br,this +},u.noop=Cr,u.now=Fe,u.pad=function(n,t,r){n=null==n?"":Lr(n),t=+t||0;var e=n.length;return en.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(sr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Tr(u.source,(D.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; +r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Lr(null==n?"":n)+t},u.all=Mt,u.any=tr,u.detect=Xt,u.findWhere=Xt,u.foldl=Jt,u.foldr=Qt,u.include=Kt,u.inject=Jt,wr(function(){var n={};return mt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Tt,u.last=Ft,u.sample=function(n,t,r){return n&&typeof n.length!="number"?n=vr(n):be.unindexedChars&&pr(n)&&(n=n.split("")),null==t||r?n?n[wt(0,n.length-1)]:_:(n=nr(n),n.length=ce(fe(0,t),n.length),n) +},u.take=Tt,u.takeRight=Ft,u.takeRightWhile=Ft,u.takeWhile=Tt,u.head=Tt,mt(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,a=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(a,u):a})}),u.VERSION=E,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Lr(this.__wrapped__)},u.prototype.value=Ut,u.prototype.valueOf=Ut,st(["join","pop","shift"],function(n){var t=Fr[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); +return n?new o(r,n):r}}),st(["push","reverse","sort","unshift"],function(n){var t=Fr[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),st(["concat","splice"],function(n){var t=Fr[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),be.spliceObjects||st(["pop","shift","splice"],function(n){var t=Fr[n],r="splice"==n;u.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 o(u,n):u +}}),u}var _,w=1,x=2,C=4,j=8,k=16,O=32,E="2.4.1",A="__lodash@"+E+"__",S=0,I=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,T=/&(?:amp|lt|gt|quot|#39);/g,L=/[&<>"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,P=/<%=([\s\S]+?)%>/g,$=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,D=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/[\xC0-\xFF]/g,U=/($^)/,K=/[.*+?^${}()|[\]\\]/g,M=/\bthis\b/,V=/['\n\r\t\u2028\u2029\\]/g,X=/[a-zA-Z0-9][a-z0-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",Z="Array Boolean Date Error Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),H="[object Arguments]",J="[object Array]",Q="[object Boolean]",nt="[object Date]",tt="[object Error]",rt="[object Function]",et="[object Number]",ut="[object Object]",ot="[object RegExp]",at="[object String]",it={}; +it[rt]=false,it[H]=it[J]=it[Q]=it[nt]=it[et]=it[ut]=it[ot]=it[at]=true;var lt={leading:false,maxWait:0,trailing:false},ft={configurable:false,enumerable:false,value:null,writable:false},ct={"&":"&","<":"<",">":">",'"':""","'":"'"},st={"&":"&","<":"<",">":">",""":'"',"'":"'"},pt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":"","\xf7":""},ht={"function":true,object:true},gt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},vt=ht[typeof window]&&window||this,yt=ht[typeof exports]&&exports&&!exports.nodeType&&exports,ht=ht[typeof module]&&module&&!module.nodeType&&module,mt=yt&&ht&&typeof global=="object"&&global; +!mt||mt.global!==mt&&mt.window!==mt&&mt.self!==mt||(vt=mt);var mt=ht&&ht.exports===yt&&yt,dt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(vt._=dt, define(function(){return dt})):yt&&ht?mt?(ht.exports=dt)._=dt:yt._=dt:vt._=dt}).call(this); \ No newline at end of file diff --git a/dist/lodash.js b/dist/lodash.js index 72bdc0b91..b70fed6a2 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -78,7 +78,7 @@ var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g; /** Used to match words to create compound words */ - var reWords = /[a-z0-9]+/g; + var reWords = /[a-zA-Z0-9][a-z0-9]*/g; /** Used to detect and test whitespace */ var whitespace = ( @@ -252,7 +252,7 @@ * @param {Array} array The array to search. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. - * @returns {number} Returns the index of the matched value or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. */ function baseIndexOf(array, value, fromIndex) { var index = (fromIndex || 0) - 1, @@ -285,7 +285,7 @@ * * @private * @param {string} value The character to inspect. - * @returns {number} Returns the code unit of given character. + * @returns {number} Returns the code unit of the given character. */ function charAtCallback(value) { return value.charCodeAt(0); @@ -599,6 +599,7 @@ getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, hasOwnProperty = objectProto.hasOwnProperty, push = arrayRef.push, + propertyIsEnumerable = objectProto.propertyIsEnumerable, Set = isNative(Set = context.Set) && Set, setTimeout = context.setTimeout, splice = arrayRef.splice, @@ -1000,7 +1001,7 @@ * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @param {number} [argCount] The number of arguments the callback accepts. - * @returns {Function} Returns a callback function. + * @returns {Function} Returns the new function. */ function baseCreateCallback(func, thisArg, argCount) { if (typeof func != 'function') { @@ -1118,7 +1119,7 @@ * @private * @param {Array} array The array to process. * @param {Array} [values] The array of values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. */ function baseDifference(array, values) { var length = array ? array.length : 0; @@ -1217,7 +1218,7 @@ * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects. * @param {number} [fromIndex=0] The index to start from. - * @returns {Array} Returns a new flattened array. + * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, isShallow, isStrict, fromIndex) { var index = (fromIndex || 0) - 1, @@ -1249,17 +1250,20 @@ } /** - * The base implementation of `_.forOwn` without support for callback - * shorthands or `thisArg` binding. + * The base implementation of `baseForIn` and `baseForOwn` which iterates + * over `object` properties returned by `keysFunc` executing the callback + * for each property. Callbacks may exit iteration early by explicitly + * returning `false`. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. * @returns {Object} Returns `object`. */ - function baseForOwn(object, callback) { + function baseFor(object, callback, keysFunc) { var index = -1, - props = keys(object), + props = keysFunc(object), length = props.length; while (++index < length) { @@ -1272,16 +1276,18 @@ } /** - * The base implementation of `_.forOwnRight` without support for callback - * shorthands or `thisArg` binding. + * This function is like `baseFor` except that it iterates over properties + * in the opposite order. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. * @returns {Object} Returns `object`. */ - function baseForOwnRight(object, callback) { - var props = keys(object), + function baseForRight(object, callback, keysFunc) { + var index = -1, + props = keysFunc(object), length = props.length; while (length--) { @@ -1294,8 +1300,47 @@ } /** - * The base implementation of `_.isEqual`, without support for `thisArg` binding, - * that allows partial "_.where" style comparisons. + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForIn(object, callback) { + return baseFor(object, callback, keysIn); + } + + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + return baseFor(object, callback, keys); + } + + /** + * The base implementation of `_.forOwnRight` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwnRight(object, callback) { + return baseForRight(object, callback, keys); + } + + /** + * The base implementation of `_.isEqual`, without support for `thisArg` + * binding, that allows partial "_.where" style comparisons. * * @private * @param {*} a The value to compare. @@ -1530,7 +1575,7 @@ * @private * @param {number} min The minimum possible value. * @param {number} max The maximum possible value. - * @returns {number} Returns a random number. + * @returns {number} Returns the random number. */ function baseRandom(min, max) { return min + floor(nativeRandom() * (max - min + 1)); @@ -1544,7 +1589,7 @@ * @param {Array} array The array to process. * @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted. * @param {Function} [callback] The function called per iteration. - * @returns {Array} Returns a duplicate-value-free array. + * @returns {Array} Returns the new duplicate-value-free array. */ function baseUniq(array, isSorted, callback) { var length = array ? array.length : 0; @@ -1597,6 +1642,28 @@ return result; } + /** + * The base implementation of `_.values` and `_.valuesIn` which creates an + * array of `object` property values corresponding to the property names + * returned by `keysFunc`. + * + * @private + * @param {Object} object The object to inspect. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns the array of property values. + */ + function baseValues(object, keysFunc) { + var index = -1, + props = keysFunc(object), + length = props.length, + result = Array(length); + + while (++index < length) { + result[index] = object[props[index]]; + } + return result; + } + /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -1605,7 +1672,7 @@ * @param {Array} partialArg An array of arguments to prepend to those provided. * @param {Array} partialHolders An array of `partialArgs` placeholder indexes. * @param {Array|Object} args The provided arguments. - * @returns {Array} Returns a new array of composed arguments. + * @returns {Array} Returns the new array of composed arguments. */ function composeArgs(partialArgs, partialHolders, args) { var holdersLength = partialHolders.length, @@ -1635,7 +1702,7 @@ * @param {Array} partialRightArg An array of arguments to append to those provided. * @param {Array} partialHolders An array of `partialRightArgs` placeholder indexes. * @param {Array|Object} args The provided arguments. - * @returns {Array} Returns a new array of composed arguments. + * @returns {Array} Returns the new array of composed arguments. */ function composeArgsRight(partialRightArgs, partialRightHolders, args) { var holdersIndex = -1, @@ -1661,9 +1728,9 @@ /** * Creates a function that aggregates a collection, creating an object or - * array composed from the results of running each element of the collection - * through a callback. The given setter function sets the keys and values - * of the composed object or array. + * array composed from the results of running each element in the collection + * through a callback. The given setter function sets the keys and values of + * the composed object or array. * * @private * @param {Function} setter The setter function. @@ -1698,7 +1765,7 @@ * * @private * @param {Array} [array=[]] The array to search. - * @returns {Object} Returns the cache object. + * @returns {Object} Returns the new cache object. */ var createCache = Set && function(array) { var cache = new Set, @@ -1735,8 +1802,8 @@ } /** - * Creates a function that, when called, either curries or invokes `func` - * with an optional `this` binding and partially applied arguments. + * Creates a function that either curries or invokes `func` with an optional + * `this` binding and partially applied arguments. * * @private * @param {Function|string} func The function or method name to reference. @@ -1841,7 +1908,7 @@ /** * Gets the appropriate "indexOf" function. If the `_.indexOf` method is - * customized this method returns the custom method, otherwise it returns + * customized this function returns the custom method, otherwise it returns * the `baseIndexOf` function. * * @private @@ -1928,48 +1995,28 @@ } /** - * The base implementation of `_.forIn` without support for callback - * shorthands or `thisArg` binding. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} callback The function called per iteration. - * @returns {Object} Returns `object`. - */ - var baseForIn = function(object, callback) { - var result = object; - if (!isObject(object)) { - return result; - } - for (var key in object) { - if (callback(object[key], key, object) === false) { - return result; - } - } - return result; - }; - - /** - * A fallback implementation of `Object.keys` which produces an array of the - * given object's own enumerable property names. + * A fallback implementation of `Object.keys` which creates an array of the + * own enumerable property names of `object`. * * @private * @type Function * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names. + * @returns {Array} Returns the array of property names. */ - var shimKeys = function(object) { - var result = []; - if (!isObject(object)) { - return result; - } - for (var key in object) { + function shimKeys(object) { + var index = -1, + props = keysIn(object), + length = props.length, + result = []; + + while (++index < length) { + var key = props[index]; if (hasOwnProperty.call(object, key)) { result.push(key); } } return result; - }; + } /*--------------------------------------------------------------------------*/ @@ -1981,7 +2028,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -2011,7 +2058,7 @@ * @category Arrays * @param {Array} array The array to process. * @param {...Array} [values] The arrays of values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.difference([1, 2, 3], [5, 2, 10]); @@ -2022,7 +2069,7 @@ } /** - * Creates an array with `n` elements dropped from the beginning of `array`. + * Creates a slice of `array` with `n` elements dropped from the beginning. * * @static * @memberOf _ @@ -2048,7 +2095,7 @@ var drop = rest; /** - * Creates an array with `n` elements dropped from the end of `array`. + * Creates a slice of `array` with `n` elements dropped from the end. * * @static * @memberOf _ @@ -2074,9 +2121,9 @@ var dropRight = initial; /** - * Creates an array of elements excluding those dropped from the end of `array`. + * Creates a slice of `array` excluding elements dropped from the end. * Elements will be dropped until the predicate returns falsey. The predicate - * is bound to `thisArg`nand invoked with three arguments; (value, index, array). + * is bound to `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2117,10 +2164,9 @@ var dropRightWhile = initial; /** - * Creates an array of elements excluding those dropped from the beginning - * of `array`. Elements will be dropped until the predicate returns falsey. - * The predicate is bound to `thisArg` and invoked with three arguments; - * (value, index, array). + * Creates a slice of `array` excluding elements dropped from the beginning. + * Elements will be dropped until the predicate returns falsey. The predicate + * is bound to `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2216,7 +2262,7 @@ /** * This method is like `_.findIndex` except that it iterates over elements - * of a `collection` from right to left. + * of a collection from right to left. * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2326,7 +2372,7 @@ * If a property name or object is provided it will be used to create a "_.pluck" * or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new flattened array. + * @returns {Array} Returns the new flattened array. * @example * * _.flatten([1, [2], [3, [[4]]]]); @@ -2380,7 +2426,7 @@ * @param {*} value The value to search for. * @param {boolean|number} [fromIndex=0] 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 or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. * @example * * _.indexOf([1, 2, 3, 1, 2, 3], 2); @@ -2444,13 +2490,16 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of shared values. + * @returns {Array} Returns the new array of shared values. * @example * * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [1, 2] */ - function intersection() { + function intersection(array) { + if (!array) { + return []; + } var args = [], argsIndex = -1, argsLength = arguments.length, @@ -2464,9 +2513,10 @@ if (isArray(value) || isArguments(value)) { args.push(value); caches.push(prereq && value.length >= 120 && - createCache(argsIndex ? args[argsIndex] : seen)); + createCache(argsIndex ? value : seen)); } } + argsLength = args.length; var array = args[0], index = -1, length = array ? array.length : 0, @@ -2527,9 +2577,9 @@ } /** - * 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. + * 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. * * @static * @memberOf _ @@ -2537,7 +2587,7 @@ * @param {Array} array The array to search. * @param {*} value The value to search for. * @param {number} [fromIndex=array.length-1] The index to search from. - * @returns {number} Returns the index of the matched value or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. * @example * * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); @@ -2607,7 +2657,7 @@ * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns a new range array. + * @returns {Array} Returns the new array of numbers. * @example * * _.range(4); @@ -2669,7 +2719,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of removed elements. + * @returns {Array} Returns the array of removed elements. * @example * * var array = [1, 2, 3, 4, 5, 6]; @@ -2742,7 +2792,7 @@ * @param {Array} array The array to slice. * @param {number} [start=0] The start index. * @param {number} [end=array.length] The end index. - * @returns {Array} Returns the new array. + * @returns {Array} Returns the slice of `array`. */ function slice(array, start, end) { var index = -1, @@ -2839,7 +2889,7 @@ } /** - * Creates an array of the first `n` elements of `array`. + * Creates a slice of `array` with `n` elements taken from the beginning. * * @static * @memberOf _ @@ -2851,7 +2901,7 @@ * @example * * _.take([1, 2, 3], 1); - * // => [2] + * // => [1] * * _.take([1, 2, 3], 2); * // => [1, 2] @@ -2865,7 +2915,7 @@ var take = first; /** - * Creates an array of the last `n` elements of `array`. + * Creates a slice of `array` with `n` elements taken from the end. * * @static * @memberOf _ @@ -2891,9 +2941,9 @@ var takeRight = last; /** - * Creates an array of elements from the end of `array`. Elements will be - * taken until the predicate returns falsey. The predicate is bound to `thisArg` - * and invoked with three arguments; (value, index, array). + * Creates a slice of `array` with elements taken from the end. Elements will + * be taken until the predicate returns falsey. The predicate is bound to + * `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2934,9 +2984,9 @@ var takeRightWhile = last; /** - * Creates an array of elements from the beginning of `array`. Elements will - * be taken until the predicate returns falsey. The predicate is bound to - * `thisArg` and invoked with three arguments; (value, index, array). + * Creates a slice of `array` with elements taken from the beginning. Elements + * will be taken until the predicate returns falsey. The predicate is bound + * to `thisArg` and invoked with three arguments; (value, index, array). * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -2984,7 +3034,7 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of combined values. + * @returns {Array} Returns the new array of combined values. * @example * * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); @@ -3019,7 +3069,7 @@ * If a property name or object is provided it will be used to create a "_.pluck" * or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a duplicate-value-free array. + * @returns {Array} Returns the new duplicate-value-free array. * @example * * _.uniq([1, 2, 1, 3, 1]); @@ -3073,7 +3123,7 @@ * @category Arrays * @param {Array} array The array to filter. * @param {...*} [value] The values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -3092,7 +3142,7 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of values. + * @returns {Array} Returns the new array of values. * @example * * _.xor([1, 2, 3], [5, 2, 1, 4]); @@ -3127,7 +3177,7 @@ * @alias unzip * @category Arrays * @param {...Array} [array] The arrays to process. - * @returns {Array} Returns a new array of grouped elements. + * @returns {Array} Returns the array of grouped elements. * @example * * _.zip(['fred', 'barney'], [30, 40], [true, false]); @@ -3159,8 +3209,7 @@ * @category Arrays * @param {Array} keys The array of keys. * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. + * @returns {Object} Returns the new object. * @example * * _.zipObject(['fred', 'barney'], [30, 40]); @@ -3195,7 +3244,7 @@ * @memberOf _ * @category Chaining * @param {*} value The value to wrap. - * @returns {Object} Returns the wrapper object. + * @returns {Object} Returns the new wrapper object. * @example * * var characters = [ @@ -3274,12 +3323,12 @@ } /** - * Produces the `toString` result of the wrapped value. + * Produces the result of coercing the wrapped value to a string. * * @name toString * @memberOf _ * @category Chaining - * @returns {string} Returns the string result. + * @returns {string} Returns the coerced string value. * @example * * _([1, 2, 3]).toString(); @@ -3317,10 +3366,9 @@ * @memberOf _ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. - * @param {...(number|number[]|string|string[])} [index] The indexes of `collection` - * to retrieve, specified as individual indexes or arrays of indexes. - * @returns {Array} Returns a new array of elements corresponding to the - * provided indexes. + * @param {...(number|number[]|string|string[])} [index] The indexes to retrieve, + * specified as individual indexes or arrays of indexes. + * @returns {Array} Returns the array of picked elements. * @example * * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); @@ -3524,7 +3572,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of elements that passed the predicate check. + * @returns {Array} Returns the new filtered array. * @example * * var evens = _.filter([1, 2, 3, 4], function(num) { return num % 2 == 0; }); @@ -3635,8 +3683,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 a + * collection from right to left. * * @static * @memberOf _ @@ -3668,7 +3716,7 @@ } /** - * Iterates over elements of a collection, executing the callback for each + * Iterates over elements of a collection executing the callback for each * element. The callback is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). Callbacks may exit iteration early by * explicitly returning `false`. @@ -3711,8 +3759,8 @@ } /** - * This method is like `_.forEach` except that it iterates over elements - * of a `collection` from right to left. + * This method is like `_.forEach` except that it iterates over elements of + * a collection from right to left. * * @static * @memberOf _ @@ -3811,18 +3859,18 @@ * @returns {Object} Returns the composed aggregate object. * @example * - * var keys = [ + * var keyData = [ * { 'dir': 'left', 'code': 97 }, * { 'dir': 'right', 'code': 100 } * ]; * - * _.indexBy(keys, 'dir'); + * _.indexBy(keyData, 'dir'); * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); + * _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); }); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keys, function(key) { return this.fromCharCode(key.code); }, String); + * _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } */ var indexBy = createAggregator(function(result, value, key) { @@ -3842,7 +3890,7 @@ * @param {Function|string} methodName The name of the method to invoke or * the function invoked per iteration. * @param {...*} [args] Arguments to invoke the method with. - * @returns {Array} Returns a new array of the results of each invoked method. + * @returns {Array} Returns the array of results. * @example * * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); @@ -3852,22 +3900,15 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var index = -1, + var args = slice(arguments, 2), + index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - if (arguments.length < 3 && typeof length == 'number') { - while (++index < length) { - var value = collection[index]; - result[index] = isFunc ? methodName.call(value) : value[methodName](); - } - } else { - var args = slice(arguments, 2); - baseEach(collection, function(value) { - result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); - }); - } + baseEach(collection, function(value) { + result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); + }); return result; } @@ -3892,7 +3933,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new array of the results of each `callback` execution. + * @returns {Array} Returns the new mapped array. * @example * * _.map([1, 2, 3], function(num) { return num * 3; }); @@ -4100,7 +4141,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of grouped elements. + * @returns {Array} Returns the array of grouped elements. * @example * * _.partition([1, 2, 3], function(num) { return num % 2; }); @@ -4136,7 +4177,7 @@ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. * @param {string} key The name of the property to pluck. - * @returns {Array} Returns a new array of property values. + * @returns {Array} Returns the property values. * @example * * var characters = [ @@ -4204,8 +4245,8 @@ } /** - * 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 a + * collection from right to left. * * @static * @memberOf _ @@ -4253,7 +4294,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of elements that failed the predicate check. + * @returns {Array} Returns the new filtered array. * @example * * var odds = _.reject([1, 2, 3, 4], function(num) { return num % 2 == 0; }); @@ -4274,9 +4315,7 @@ */ function reject(collection, predicate, thisArg) { predicate = lodash.createCallback(predicate, thisArg, 3); - return filter(collection, function(value, index, collection) { - return !predicate(value, index, collection); - }); + return filter(collection, negate(predicate)); } /** @@ -4288,7 +4327,7 @@ * @param {Array|Object|string} collection The collection to sample. * @param {number} [n] The number of elements to sample. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`. - * @returns {*} Returns the random sample(s) of `collection`. + * @returns {*} Returns the random sample(s). * @example * * _.sample([1, 2, 3, 4]); @@ -4318,7 +4357,7 @@ * @memberOf _ * @category Collections * @param {Array|Object|string} collection The collection to shuffle. - * @returns {Array} Returns a new shuffled collection. + * @returns {Array} Returns the new shuffled array. * @example * * _.shuffle([1, 2, 3, 4]); @@ -4451,7 +4490,7 @@ * called per iteration. If a property name or object is provided it will * be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new array of sorted elements. + * @returns {Array} Returns the new sorted array. * @example * * _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); @@ -4537,7 +4576,7 @@ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. * @param {Object} source The object of property values to filter by. - * @returns {Array} Returns a new array of elements that have the given properties. + * @returns {Array} Returns the new filtered array. * @example * * var characters = [ @@ -4591,9 +4630,9 @@ } /** - * Creates a function that, when called, invokes `func` with the `this` - * binding of `thisArg` and prepends any additional `bind` arguments to those - * provided to the bound function. + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and prepends any additional `bind` arguments to those provided to the bound + * function. * * Note: Unlike native `Function#bind` this method does not set the `length` * property of bound functions. @@ -4667,10 +4706,10 @@ } /** - * Creates a function that, when called, invokes the method at `object[key]` - * and prepends any additional `bindKey` arguments to those provided to the bound - * function. This method differs from `_.bind` by allowing bound functions to - * reference methods that will be redefined or don't yet exist. + * Creates a function that invokes the method at `object[key]` and prepends + * any additional `bindKey` arguments to those provided to the bound function. + * This method differs from `_.bind` by allowing bound functions to reference + * methods that will be redefined or don't yet exist. * See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern) * for more details. * @@ -4994,7 +5033,7 @@ * @memberOf _ * @category Functions * @param {Function} func The function to have its output memoized. - * @param {Function} [resolver] A function used to resolve the cache key. + * @param {Function} [resolver] The function to resolve the cache key. * @returns {Function} Returns the new memoizing function. * @example * @@ -5073,9 +5112,9 @@ } /** - * Creates a function that, when called, invokes `func` with any additional - * `partial` arguments prepended to those provided to the new function. This - * method is similar to `_.bind` except it does **not** alter the `this` binding. + * Creates a function that invokes `func` with any additional `partial` arguments + * prepended to those provided to the new function. This method is similar to + * `_.bind` except it does **not** alter the `this` binding. * * Note: This method does not set the `length` property of partially applied * functions. @@ -5250,6 +5289,9 @@ * // => { 'name': 'barney', 'employer': 'slate' } */ function assign(object, source, guard) { + if (!object) { + return object; + } var args = arguments, argsIndex = 0, argsLength = args.length, @@ -5267,15 +5309,13 @@ } while (++argsIndex < argsLength) { source = args[argsIndex]; - if (isObject(source)) { - var index = -1, - props = keys(source), - length = props.length; + var index = -1, + props = keys(source), + length = props.length; - while (++index < length) { - var key = props[index]; - object[key] = callback ? callback(object[key], source[key]) : source[key]; - } + while (++index < length) { + var key = props[index]; + object[key] = callback ? callback(object[key], source[key]) : source[key]; } } return object; @@ -5446,6 +5486,9 @@ * // => { 'name': 'barney', 'employer': 'slate' } */ function defaults(object, source, guard) { + if (!object) { + return object; + } var args = arguments, argsIndex = 0, argsLength = args.length, @@ -5457,16 +5500,14 @@ } while (++argsIndex < argsLength) { source = args[argsIndex]; - if (isObject(source)) { - var index = -1, - props = keys(source), - length = props.length; + var index = -1, + props = keys(source), + length = props.length; - while (++index < length) { - var key = props[index]; - if (typeof object[key] == 'undefined') { - object[key] = source[key]; - } + while (++index < length) { + var key = props[index]; + if (typeof object[key] == 'undefined') { + object[key] = source[key]; } } } @@ -5528,8 +5569,8 @@ } /** - * This method is like `_.findKey` except that it iterates over elements - * of a `collection` in the opposite order. + * This method is like `_.findKey` except that it iterates over elements of + * a collection in the opposite order. * * If a property name is provided for `predicate` the created "_.pluck" style * callback will return the property value of the given element. @@ -5582,10 +5623,10 @@ } /** - * Iterates over own and inherited enumerable properties of an object, - * executing the callback for each property. The callback is bound to `thisArg` - * and invoked with three arguments; (value, key, object). Callbacks may exit - * iteration early by explicitly returning `false`. + * Iterates over own and inherited enumerable properties of an object executing + * the callback for each property. The callback is bound to `thisArg` and invoked + * with three arguments; (value, key, object). Callbacks may exit iteration + * early by explicitly returning `false`. * * @static * @memberOf _ @@ -5602,24 +5643,21 @@ * this.y = 0; * } * - * Shape.prototype.move = function(x, y) { - * this.x += x; - * this.y += y; - * }; + * Shape.prototype.z = 0; * * _.forIn(new Shape, function(value, key) { * console.log(key); * }); - * // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments) + * // => logs 'x', 'y', and 'z' (property order is not guaranteed across environments) */ function forIn(object, callback, thisArg) { callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); - return baseForIn(object, callback); + return baseFor(object, callback, keysIn); } /** - * 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 elements of a + * collection in the opposite order. * * @static * @memberOf _ @@ -5635,34 +5673,20 @@ * this.y = 0; * } * - * Shape.prototype.move = function(x, y) { - * this.x += x; - * this.y += y; - * }; + * Shape.prototype.z = 0; * * _.forInRight(new Shape, function(value, key) { * console.log(key); * }); - * // => logs 'move', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'move' + * // => logs 'z', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'z' */ function forInRight(object, callback, thisArg) { - var pairs = []; - baseForIn(object, function(value, key) { - pairs.push(key, value); - }); - - var length = pairs.length; callback = baseCreateCallback(callback, thisArg, 3); - while (length--) { - if (callback(pairs[length--], pairs[length], object) === false) { - break; - } - } - return object; + return baseForRight(object, callback, keysIn); } /** - * Iterates over own enumerable properties of an object, executing the callback + * Iterates over own enumerable properties of an object executing the callback * for each property. The callback is bound to `thisArg` and invoked with three * arguments; (value, key, object). Callbacks may exit iteration early by * explicitly returning `false`. @@ -5687,8 +5711,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 elements of a + * collection in the opposite order. * * @static * @memberOf _ @@ -5705,17 +5729,8 @@ * // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length' */ function forOwnRight(object, callback, thisArg) { - var props = keys(object), - length = props.length; - callback = baseCreateCallback(callback, thisArg, 3); - while (length--) { - var key = props[length]; - if (callback(object[key], key, object) === false) { - break; - } - } - return object; + return baseForRight(object, callback, keys); } /** @@ -5727,7 +5742,7 @@ * @alias methods * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names that have function values. + * @returns {Array} Returns the new sorted array of property names. * @example * * _.functions(_); @@ -5735,6 +5750,7 @@ */ function functions(object) { var result = []; + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); @@ -5773,7 +5789,7 @@ * @category Objects * @param {Object} object The object to invert. * @param {boolean} [multiValue=false] Allow multiple values per key. - * @returns {Object} Returns the created inverted object. + * @returns {Object} Returns the new inverted object. * @example * * _.invert({ 'first': 'fred', 'second': 'barney' }); @@ -5811,6 +5827,34 @@ return result; } + /** + * Checks if `value` is an `arguments` object. + * + * @static + * @memberOf _ + * @category Objects + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`. + * @example + * + * (function() { return _.isArguments(arguments); })(1, 2, 3); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + function isArguments(value) { + return value && typeof value == 'object' && typeof value.length == 'number' && + toString.call(value) == argsClass || false; + } + // fallback for environments that can't detect `arguments` objects by [[Class]] + if (!support.argsClass) { + isArguments = function(value) { + return value && typeof value == 'object' && typeof value.length == 'number' && + hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee') || false; + }; + } + /** * Checks if `value` is an array. * @@ -6233,25 +6277,60 @@ } /** - * Creates an array composed of the own enumerable property names of `object`. + * Creates an array of the own enumerable property names of `object`. * * @static * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names. + * @returns {Array} Returns the array of property names. * @example * - * _.keys({ 'one': 1, 'two': 2, 'three': 3 }); - * // => ['one', 'two', 'three'] (property order is not guaranteed across environments) + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * Shape.prototype.z = 0; + * + * _.keys(new Shape); + * // => ['x', 'y'] (property order is not guaranteed across environments) */ var keys = !nativeKeys ? shimKeys : function(object) { - if (!isObject(object)) { - return []; - } - return nativeKeys(object); + return isObject(object) ? nativeKeys(object) : []; }; + /** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to inspect. + * @returns {Array} Returns the array of property names. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * Shape.prototype.z = 0; + * + * _.keysIn(new Shape); + * // => ['x', 'y', 'z'] (property order is not guaranteed across environments) + */ + function keysIn(object) { + var result = []; + if (!isObject(object)) { + return result; + } + for (var key in object) { + result.push(key); + } + return result; + } + /** * Creates an object with the same keys as `object` and values generated by * running each own enumerable property of `object` through the callback. @@ -6273,7 +6352,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Object} Returns a new object with values of the results of each `callback` execution. + * @returns {Object} Returns the new mapped object. * @example * * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; }); @@ -6350,7 +6429,7 @@ * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot] } */ function merge(object, source, guard) { - if (!isObject(object)) { + if (!object) { return object; } var args = arguments, @@ -6367,7 +6446,7 @@ } else if (length > 2 && typeof args[length - 1] == 'function') { callback = args[--length]; } - var sources = slice(arguments, 1, length), + var sources = slice(args, 1, length), index = -1, stackA = [], stackB = []; @@ -6394,7 +6473,7 @@ * iteration or property names to omit, specified as individual property * names or arrays of property names. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns an object without the omitted properties. + * @returns {Object} Returns the new object. * @example * * _.omit({ 'name': 'fred', 'age': 40 }, 'age'); @@ -6406,37 +6485,17 @@ * // => { 'name': 'fred' } */ function omit(object, predicate, thisArg) { - var result = {}; - - if (typeof predicate != 'function') { - var omitProps = baseFlatten(arguments, true, false, 1), - length = omitProps.length; - - while (length--) { - omitProps[length] = String(omitProps[length]); - } - var props = []; - baseForIn(object, function(value, key) { - props.push(key); - }); - - var index = -1; - props = baseDifference(props, omitProps); - length = props.length; - - while (++index < length) { - var key = props[index]; - result[key] = object[key]; - } - } else { + if (typeof predicate == 'function') { predicate = lodash.createCallback(predicate, thisArg, 3); - baseForIn(object, function(value, key, object) { - if (!predicate(value, key, object)) { - result[key] = value; - } - }); + return pick(object, negate(predicate)); } - return result; + var omitProps = baseFlatten(arguments, true, false, 1), + length = omitProps.length; + + while (length--) { + omitProps[length] = String(omitProps[length]); + } + return pick(object, baseDifference(keysIn(object), omitProps)); } /** @@ -6482,7 +6541,7 @@ * iteration or property names to pick, specified as individual property * names or arrays of property names. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns an object composed of the picked properties. + * @returns {Object} Returns the new object. * @example * * _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name'); @@ -6571,28 +6630,52 @@ } /** - * Creates an array composed of the own enumerable property values of `object`. + * Creates an array of the own enumerable property values of `object`. * * @static * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property values. + * @returns {Array} Returns the array of property values. * @example * - * _.values({ 'one': 1, 'two': 2, 'three': 3 }); - * // => [1, 2, 3] (property order is not guaranteed across environments) + * function Shape(x, y) { + * this.x = x; + * this.y = y; + * } + * + * Shape.prototype.z = 0; + * + * _.values(new Shape(2, 1)); + * // => [2, 1] (property order is not guaranteed across environments) */ function values(object) { - var index = -1, - props = keys(object), - length = props.length, - result = Array(length); + return baseValues(object, keys); + } - while (++index < length) { - result[index] = object[props[index]]; - } - return result; + /** + * Creates an array of the own and inherited enumerable property values + * of `object`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to inspect. + * @returns {Array} Returns the array of property values. + * @example + * + * function Shape(x, y) { + * this.x = x; + * this.y = y; + * } + * + * Shape.prototype.z = 0; + * + * _.valuesIn(new Shape(2, 1)); + * // => [2, 1, 0] (property order is not guaranteed across environments) + */ + function valuesIn(object) { + return baseValues(object, keysIn); } /*--------------------------------------------------------------------------*/ @@ -6617,8 +6700,8 @@ * _.camelCase('hello_world'); * // => 'helloWorld' */ - var camelCase = createCompounder(function(result, words, index) { - return result + words.charAt(0)[index ? 'toUpperCase' : 'toLowerCase']() + words.slice(1); + var camelCase = createCompounder(function(result, word, index) { + return result + word.charAt(0)[index ? 'toUpperCase' : 'toLowerCase']() + word.slice(1); }); /** @@ -6710,7 +6793,7 @@ * @example * * _.escapeRegExp('[lodash](http://lodash.com)'); - * // => '\[lodash]\(http://lodash\.com\)' + * // => '\[lodash\]\(http://lodash\.com\)' */ function escapeRegExp(string) { return string == null ? '' : String(string).replace(reRegExpChars, '\\$&'); @@ -6737,8 +6820,8 @@ * _.kebabCase('hello_world'); * // => 'hello-world' */ - var kebabCase = createCompounder(function(result, words, index) { - return result + (index ? '-' : '') + words.toLowerCase(); + var kebabCase = createCompounder(function(result, word, index) { + return result + (index ? '-' : '') + word.toLowerCase(); }); /** @@ -6864,13 +6947,13 @@ return result; } string = String(string); - while (n > 0) { + do { if (n % 2) { result += string; } n = floor(n / 2); - result += result; - } + string += string; + } while (n > 0); return result; } @@ -6894,8 +6977,8 @@ * _.snakeCase('helloWorld'); * // => 'hello_world' */ - var snakeCase = createCompounder(function(result, words, index) { - return result + (index ? '_' : '') + words.toLowerCase(); + var snakeCase = createCompounder(function(result, word, index) { + return result + (index ? '_' : '') + word.toLowerCase(); }); /** @@ -6958,7 +7041,7 @@ * @param {string} [options.sourceURL] The sourceURL of the template's compiled source. * @param {string} [options.variable] The data object variable name. * @returns {Function|string} Returns the interpolated string if a data object - * is provided, else it returns a template function. + * is provided, else the compiled template function. * @example * * // using the "interpolate" delimiter to create a compiled template @@ -7021,10 +7104,8 @@ // and Laura Doktorova's doT.js // https://github.com/olado/doT var settings = lodash.templateSettings; - string = String(string == null ? '' : string); - - // avoid missing dependencies when `iteratorTemplate` is not defined options = defaults({}, options, settings); + string = String(string == null ? '' : string); var imports = defaults({}, options.imports, settings.imports), importsKeys = keys(imports), @@ -7322,7 +7403,7 @@ } /** - * Produces a callback bound to an optional `thisArg`. If `func` is a property + * Creates a function bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. * If `func` is an object the created callback will return `true` for elements * that contain the equivalent object properties, otherwise it will return `false`. @@ -7334,7 +7415,7 @@ * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @param {number} [argCount] The number of arguments the callback accepts. - * @returns {Function} Returns a callback function. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -7519,6 +7600,33 @@ } } + /** + * Creates a function that negates the result of `func`. The `func` function + * is executed with the `this` binding and arguments of the created function. + * + * @static + * @memberOf _ + * @category Utilities + * @param {Function} func The function to negate. + * @returns {Function} Returns the new function. + * @example + * + * function isEven(num) { + * return num % 2 == 0; + * } + * + * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); + * // => [1, 3, 5] + */ + function negate(func) { + if (!isFunction(func)) { + throw new TypeError; + } + return function() { + return !func.apply(this, arguments); + }; + } + /** * Reverts the '_' variable to its previous value and returns a reference to * the `lodash` function. @@ -7583,7 +7691,7 @@ * @category Utilities * @param {string} value The value to parse. * @param {number} [radix] The radix used to interpret the value to parse. - * @returns {number} Returns the new integer value. + * @returns {number} Returns the converted integer value. * @example * * _.parseInt('08'); @@ -7639,7 +7747,7 @@ * @param {number} [min=0] The minimum possible value. * @param {number} [max=1] The maximum possible value. * @param {boolean} [floating=false] Specify returning a floating-point number. - * @returns {number} Returns a random number. + * @returns {number} Returns the random number. * @example * * _.random(0, 5); @@ -7738,7 +7846,7 @@ * @param {number} n The number of times to execute the callback. * @param {Function} [callback=identity] The function called per iteration. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns an array of the results of each `callback` execution. + * @returns {Array} Returns the array of results. * @example * * var diceRolls = _.times(3, _.partial(_.random, 1, 6)); @@ -7825,6 +7933,7 @@ lodash.invert = invert; lodash.invoke = invoke; lodash.keys = keys; + lodash.keysIn = keysIn; lodash.map = map; lodash.mapValues = mapValues; lodash.matches = matches; @@ -7832,6 +7941,7 @@ lodash.memoize = memoize; lodash.merge = merge; lodash.min = min; + lodash.negate = negate; lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; @@ -7857,6 +7967,7 @@ lodash.union = union; lodash.uniq = uniq; lodash.values = values; + lodash.valuesIn = valuesIn; lodash.where = where; lodash.without = without; lodash.wrap = wrap; @@ -8041,7 +8152,6 @@ return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__); }; }); - return lodash; } diff --git a/dist/lodash.min.js b/dist/lodash.min.js index ad163b5e3..72f480934 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -3,62 +3,62 @@ * Lo-Dash 2.4.1 (Custom Build) lodash.com/license | Underscore.js 1.6.0 underscorejs.org/LICENSE * Build: `lodash modern -o ./dist/lodash.js` */ -;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202i(e,f)&&l.push(f);return l}function ct(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++ra(p,h)&&((u||l)&&p.push(h),c.push(s))}return c}function wt(n,t,r){for(var e=t.length,u=-1,o=Zr(r.length-e,0),i=-1,a=n.length,f=dr(o+a);++ir&&(r=0),c&&(i=[]),p&&(a=[]),s=[n,t,r,e,u,o,i,a],t==_||t==(_|j)?y(s):ft(s)) -}function Ct(){var n=(n=l.indexOf)===Rt?t:n;return n}function Ot(n){return typeof n=="function"&&Wr.test(Lr.call(n))}function At(n){var t,r;return n&&Tr.call(n)==tt&&(qr.call(n,"constructor")||(t=n.constructor,!ur(t)||t instanceof t))?(o(n,function(n,t){r=t}),typeof r=="undefined"||qr.call(n,r)):false}function Et(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Tr.call(n)==G||false}function It(n,t,r){if(typeof t!="number"&&null!=t){var e=-1,u=n?n.length:0,o=0;for(t=l.createCallback(t,r,3);++ee?Zr(0,u+e):e||0;else if(e)return e=Ft(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function Nt(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var u=e,o=0;for(t=l.createCallback(t,r,3);u--&&t(n[u],u,n);)o++}else o=null==t||r?1:t;return o=e-o,Wt(n,0,0t?t=Zr(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=Zr(u+r,0):r>u&&(r=u),u=r-t||0,r=dr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!me(n)&&fr(n))return Xr?Xr.call(n,t,r):-1r?Zr(0,e+r):r)||0,-1o&&(o=a) -}else t=null==t&&fr(n)?e:l.createCallback(t,r,3),ct(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function Yt(n,t,r,e){var u=3>arguments.length;t=l.createCallback(t,e,4);var o=-1,i=n?n.length:0;if(typeof i=="number")for(u&&i&&(r=n[++o]);++oarguments.length;return t=l.createCallback(t,e,4),pt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Ht(n){var t=-1,r=n?n.length:0,e=dr(typeof r=="number"?r:0); -return ct(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;t=l.createCallback(t,r,3),r=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++rarguments.length)return jt(n,_,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Wt(arguments,2),r=r-e.length;return jt(n,_|j,r,t,e)}function Zt(n,t,r){function e(){c&&$r(c),i=c=p=b,(g||h!==t)&&(s=Oe(),a=n.apply(l,o),c||i||(o=l=null)) -}function u(){var r=t-(Oe()-f);0>=r||r>t?(i&&$r(i),r=p,i=c=p=b,r&&(s=Oe(),a=n.apply(l,o),c||i||(o=l=null))):c=Pr(u,r)}var o,i,a,f,l,c,p,s=0,h=false,g=true;if(!ur(n))throw new Ar;if(t=0=y||y>h;m?(i&&(i=$r(i)),s=f,a=n.apply(l,o)):i||(i=Pr(e,y))}return m&&c?c=$r(c):c||t===h||(c=Pr(u,t)),r&&(m=true,a=n.apply(l,o)),!m||c||i||(o=l=null),a -}}function nr(n,t,r){var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;for(n=Or(n);0--n?t.apply(this,arguments):void 0 -}},l.assign=nr,l.at=function(n,t){var r=arguments,e=-1,u=ht(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=dr(o);++earguments.length?jt(t,_|w,null,n):jt(t,_|w|j,null,n,Wt(arguments,2))},l.chain=function(n){return n=new v(n),n.__chain__=true,n -},l.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,l):i(f,l))){for(e=u,(h||f).push(l);--e;)if(h=o[e],0>(h?r(h,l):i(n[e],l)))continue n;s.push(l)}}return s},l.invert=function(n,t){for(var r=-1,e=be(n),u=e.length,o={};++rarguments.length&&typeof u=="number")for(;++rr?Zr(0,e+r):ne(r,e-1))+1);e--;)if(n[e]===t)return e; -return-1},l.mixin=vr,l.noConflict=function(){return n._=Sr,this},l.noop=yr,l.now=Oe,l.pad=function(n,t,r){n=null==n?"":Or(n),t=+t||0;var e=n.length;return en.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(ar(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Cr(u.source,(L.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(S,m))},l.uniqueId=function(n){var t=++E;return Or(null==n?"":n)+t},l.all=zt,l.any=Jt,l.detect=Pt,l.findWhere=Pt,l.foldl=Yt,l.foldr=Gt,l.include=qt,l.inject=Yt,vr(function(){var n={};return gt(l,function(t,r){l.prototype[r]||(n[r]=t)}),n}(),false),l.first=It,l.last=St,l.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=lr(n)),null==t||r?n?n[bt(0,n.length-1)]:b:(n=Ht(n),n.length=ne(Zr(0,t),n.length),n) -},l.take=It,l.takeRight=St,l.takeRightWhile=St,l.takeWhile=It,l.head=It,gt(l,function(n,t){var r="sample"!==t;l.prototype[t]||(l.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 v(o,u):o})}),l.VERSION=O,l.prototype.chain=function(){return this.__chain__=true,this},l.prototype.toString=function(){return Or(this.__wrapped__)},l.prototype.value=Bt,l.prototype.valueOf=Bt,ct(["join","pop","shift"],function(n){var t=Er[n];l.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); -return n?new v(r,n):r}}),ct(["push","reverse","sort","unshift"],function(n){var t=Er[n];l.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ct(["concat","splice"],function(n){var t=Er[n];l.prototype[n]=function(){return new v(t.apply(this.__wrapped__,arguments),this.__chain__)}}),l}var b,_=1,w=2,x=4,k=8,j=16,C=32,O="2.4.1",A="__lodash@"+O+"__",E=0,I=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,S=/&(?:amp|lt|gt|quot|#39);/g,T=/[&<>"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,B=/^\s*function[ \n\r\t]+\w/,q=/^0[xX]/,z=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[a-z0-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 Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),G="[object Arguments]",H="[object Array]",J="[object Boolean]",Q="[object Date]",Z="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; -ut[Z]=false,ut[G]=ut[H]=ut[J]=ut[Q]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},at={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},lt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":"","\xf7":""},ct={"function":true,object:true},pt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ct[typeof window]&&window||this,ht=ct[typeof exports]&&exports&&!exports.nodeType&&exports,ct=ct[typeof module]&&module&&!module.nodeType&&module,gt=ht&&ct&&typeof global=="object"&&global; -!gt||gt.global!==gt&>.window!==gt&>.self!==gt||(st=gt);var gt=ct&&ct.exports===ht&&ht,vt=d();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(st._=vt, define(function(){return vt})):ht&&ct?gt?(ct.exports=vt)._=vt:ht._=vt:st._=vt}).call(this); \ No newline at end of file +;(function(){function n(n,t){if(n!==t){if(n>t||typeof n=="undefined")return 1;if(ne||13e||8202r||13r||8202i(e,f)&&l.push(f);return l}function ft(n,t){var r=-1,e=n?n.length:0;if(typeof e=="number")for(;++ra(p,h)&&((u||l)&&p.push(h),c.push(s))}return c}function _t(n,t){for(var r=-1,e=t(n),u=e.length,o=jr(u);++rr&&(r=0),p&&(i=[]),s&&(a=[]),h=[n,t,r,e,u,o,i,a],t==_||t==(_|k)?l(h):V(h)) +}function Ct(){var n=(n=u.indexOf)===Nt?t:n;return n}function Ot(n){return typeof n=="function"&&Lr.test(Ur.call(n))}function At(n){var t,r;return n&&Dr.call(n)==tt&&(Kr.call(n,"constructor")||(t=n.constructor,!or(t)||t instanceof t))?(pt(n,function(n,t){r=t},cr),typeof r=="undefined"||Kr.call(n,r)):false}function It(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Dr.call(n)==Z||false}function Et(n){for(var t=-1,r=cr(n),e=r.length,u=[];++te?ue(0,u+e):e||0;else if(e)return e=$t(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function St(n,t,r){var e=n?n.length:0;if(typeof t!="number"&&null!=t){var o=e,i=0;for(t=u.createCallback(t,r,3);o--&&t(n[o],o,n);)i++}else i=null==t||r?1:t;return i=e-i,Ft(n,0,0t?t=ue(u+t,0):t>u&&(t=u),typeof r=="undefined"?r=u:0>r?r=ue(u+r,0):r>u&&(r=u),u=r-t||0,r=jr(u);++e>>1,r(n[e])r?0:r);++t=e)return false;if(typeof n=="string"||!je(n)&&lr(n))return Jr?Jr.call(n,t,r):-1r?ue(0,e+r):r)||0,-1i&&(i=f)}else t=null==t&&lr(n)?e:u.createCallback(t,r,3),ft(n,function(n,r,e){r=t(n,r,e),r>o&&(o=r,i=n)});return i}function Zt(n,t,r,e){var o=3>arguments.length;t=u.createCallback(t,e,4);var i=-1,a=n?n.length:0;if(typeof a=="number")for(o&&a&&(r=n[++i]);++iarguments.length;return t=u.createCallback(t,e,4),lt(n,function(n,e,u){r=o?(o=false,n):t(r,n,e,u)}),r}function Ht(n){var t=-1,r=n?n.length:0,e=jr(typeof r=="number"?r:0); +return ft(n,function(n){var r=bt(0,++t);e[t]=e[r],e[r]=n}),e}function Jt(n,t,r){var e;t=u.createCallback(t,r,3),r=-1;var o=n?n.length:0;if(typeof o=="number"){for(;++rarguments.length)return kt(n,_,null,t);if(n)var r=n[A]?n[A][2]:n.length,e=Ft(arguments,2),r=r-e.length;return kt(n,_|k,r,t,e)}function nr(n,t,r){var e,u,o,i,a,f,l,c=0,p=false,s=true;if(!or(n))throw new Nr;if(t=0=r||r>t?(u&&Br(u),r=l,u=f=l=d,r&&(c=Ne(),o=n.apply(a,e),f||u||(e=a=null))):f=Yr(g,r)},v=function(){f&&Br(f),u=f=l=d,(s||p!==t)&&(c=Ne(),o=n.apply(a,e),f||u||(e=a=null))};return function(){if(e=arguments,i=Ne(),a=this,l=s&&(f||!h),false===p)var r=h&&!f;else{u||h||(c=i);var y=p-(i-c),m=0>=y||y>p;m?(u&&(u=Br(u)),c=i,o=n.apply(a,e)):u||(u=Yr(v,y))}return m&&f?f=Br(f):f||t===p||(f=Yr(g,t)),r&&(m=true,o=n.apply(a,e)),!m||f||u||(e=a=null),o +}}function tr(n,t,r){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof r;if("number"!=i&&"string"!=i||!e[3]||e[3][r]!==t||(o=2),3t||null==n)return r;n=Rr(n);do t%2&&(r+=n),t=qr(t/2),n+=n;while(0--n?t.apply(this,arguments):void 0}},u.assign=tr,u.at=function(n,t){var r=arguments,e=-1,u=ct(r,true,false,1),o=u.length,i=typeof t;for("number"!=i&&"string"!=i||!r[2]||r[2][t]!==n||(o=1),r=jr(o);++earguments.length?kt(t,_|w,null,n):kt(t,_|w|k,null,n,Ft(arguments,2)) +},u.chain=function(n){return n=new o(n),n.__chain__=true,n},u.compact=function(n){for(var t=-1,r=n?n.length:0,e=0,u=[];++t(h?r(h,c):a(l,c))){for(u=o,(h||l).push(c);--u;)if(h=i[u],0>(h?r(h,c):a(e[u],c)))continue n;s.push(c)}}return s},u.invert=function(n,t){for(var r=-1,e=ke(n),u=e.length,o={};++rr?ue(0,e+r):oe(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=br,u.noConflict=function(){return n._=$r,this},u.noop=_r,u.now=Ne,u.pad=function(n,t,r){n=null==n?"":Rr(n),t=+t||0; +var e=n.length;return en.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(fr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Er(u.source,(L.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(S,m))},u.uniqueId=function(n){var t=++I;return Rr(null==n?"":n)+t},u.all=Ut,u.any=Jt,u.detect=Kt,u.findWhere=Kt,u.foldl=Zt,u.foldr=Gt,u.include=qt,u.inject=Zt,br(function(){var n={};return gt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Rt,u.last=Tt,u.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=sr(n)),null==t||r?n?n[bt(0,n.length-1)]:d:(n=Ht(n),n.length=oe(ue(0,t),n.length),n) +},u.take=Rt,u.takeRight=Tt,u.takeRightWhile=Tt,u.takeWhile=Rt,u.head=Rt,gt(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,i=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(i,u):i})}),u.VERSION=O,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Rr(this.__wrapped__)},u.prototype.value=Bt,u.prototype.valueOf=Bt,ft(["join","pop","shift"],function(n){var t=Sr[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); +return n?new o(r,n):r}}),ft(["push","reverse","sort","unshift"],function(n){var t=Sr[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ft(["concat","splice"],function(n){var t=Sr[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),u}var d,_=1,w=2,j=4,x=8,k=16,C=32,O="2.4.1",A="__lodash@"+O+"__",I=0,E=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,S=/&(?:amp|lt|gt|quot|#39);/g,T=/[&<>"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[a-zA-Z0-9][a-z0-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 Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Z="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",Q="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; +ut[Q]=false,ut[Z]=ut[G]=ut[H]=ut[J]=ut[nt]=ut[tt]=ut[rt]=ut[et]=true;var ot={leading:false,maxWait:0,trailing:false},it={configurable:false,enumerable:false,value:null,writable:false},at={"&":"&","<":"<",">":">",'"':""","'":"'"},ft={"&":"&","<":"<",">":">",""":'"',"'":"'"},lt={\u00c0:"A",\u00c1:"A",\u00c2:"A",\u00c3:"A",\u00c4:"A",\u00c5:"A",\u00e0:"a",\u00e1:"a",\u00e2:"a",\u00e3:"a",\u00e4:"a",\u00e5:"a",\u00c7:"C",\u00e7:"c",\u00d0:"D",\u00f0:"d",\u00c8:"E",\u00c9:"E",\u00ca:"E",\u00cb:"E",\u00e8:"e",\u00e9:"e",\u00ea:"e",\u00eb:"e",\u00cc:"I",\u00cd:"I",\u00ce:"I",\u00cf:"I",\u00ec:"i",\u00ed:"i",\u00ee:"i",\u00ef:"i",\u00d1:"N",\u00f1:"n",\u00d2:"O",\u00d3:"O",\u00d4:"O",\u00d5:"O",\u00d6:"O",\u00d8:"O",\u00f2:"o",\u00f3:"o",\u00f4:"o",\u00f5:"o",\u00f6:"o",\u00f8:"o",\u00d9:"U",\u00da:"U",\u00db:"U",\u00dc:"U",\u00f9:"u",\u00fa:"u",\u00fb:"u",\u00fc:"u",\u00dd:"Y",\u00fd:"y",\u00ff:"y",\u00c6:"AE",\u00e6:"ae",\u00de:"Th",\u00fe:"th",\u00df:"ss","\xd7":"","\xf7":""},ct={"function":true,object:true},pt={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},st=ct[typeof window]&&window||this,ht=ct[typeof exports]&&exports&&!exports.nodeType&&exports,ct=ct[typeof module]&&module&&!module.nodeType&&module,gt=ht&&ct&&typeof global=="object"&&global; +!gt||gt.global!==gt&>.window!==gt&>.self!==gt||(st=gt);var gt=ct&&ct.exports===ht&&ht,vt=b();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(st._=vt, define(function(){return vt})):ht&&ct?gt?(ct.exports=vt)._=vt:ht._=vt:st._=vt}).call(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index 98df5d50d..840ddfe2a 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -156,7 +156,7 @@ * @param {Array} array The array to search. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. - * @returns {number} Returns the index of the matched value or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. */ function baseIndexOf(array, value, fromIndex) { var index = (fromIndex || 0) - 1, @@ -452,7 +452,7 @@ * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @param {number} [argCount] The number of arguments the callback accepts. - * @returns {Function} Returns a callback function. + * @returns {Function} Returns the new function. */ function baseCreateCallback(func, thisArg, argCount) { if (typeof func != 'function') { @@ -532,7 +532,7 @@ * @private * @param {Array} array The array to process. * @param {Array} [values] The array of values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. */ function baseDifference(array, values) { var length = array ? array.length : 0; @@ -612,7 +612,7 @@ * @param {boolean} [isShallow=false] A flag to restrict flattening to a single level. * @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects. * @param {number} [fromIndex=0] The index to start from. - * @returns {Array} Returns a new flattened array. + * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, isShallow, isStrict, fromIndex) { var index = (fromIndex || 0) - 1, @@ -644,17 +644,20 @@ } /** - * The base implementation of `_.forOwn` without support for callback - * shorthands or `thisArg` binding. + * The base implementation of `baseForIn` and `baseForOwn` which iterates + * over `object` properties returned by `keysFunc` executing the callback + * for each property. Callbacks may exit iteration early by explicitly + * returning `false`. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. * @returns {Object} Returns `object`. */ - function baseForOwn(object, callback) { + function baseFor(object, callback, keysFunc) { var index = -1, - props = keys(object), + props = keysFunc(object), length = props.length; while (++index < length) { @@ -667,16 +670,18 @@ } /** - * The base implementation of `_.forOwnRight` without support for callback - * shorthands or `thisArg` binding. + * This function is like `baseFor` except that it iterates over properties + * in the opposite order. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function called per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. * @returns {Object} Returns `object`. */ - function baseForOwnRight(object, callback) { - var props = keys(object), + function baseForRight(object, callback, keysFunc) { + var index = -1, + props = keysFunc(object), length = props.length; while (length--) { @@ -689,8 +694,47 @@ } /** - * The base implementation of `_.isEqual`, without support for `thisArg` binding, - * that allows partial "_.where" style comparisons. + * The base implementation of `_.forIn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForIn(object, callback) { + return baseFor(object, callback, keysIn); + } + + /** + * The base implementation of `_.forOwn` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, callback) { + return baseFor(object, callback, keys); + } + + /** + * The base implementation of `_.forOwnRight` without support for callback + * shorthands or `thisArg` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwnRight(object, callback) { + return baseForRight(object, callback, keys); + } + + /** + * The base implementation of `_.isEqual`, without support for `thisArg` + * binding, that allows partial "_.where" style comparisons. * * @private * @param {*} a The value to compare. @@ -816,7 +860,7 @@ * @private * @param {number} min The minimum possible value. * @param {number} max The maximum possible value. - * @returns {number} Returns a random number. + * @returns {number} Returns the random number. */ function baseRandom(min, max) { return min + floor(nativeRandom() * (max - min + 1)); @@ -830,7 +874,7 @@ * @param {Array} array The array to process. * @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted. * @param {Function} [callback] The function called per iteration. - * @returns {Array} Returns a duplicate-value-free array. + * @returns {Array} Returns the new duplicate-value-free array. */ function baseUniq(array, isSorted, callback) { var length = array ? array.length : 0; @@ -862,6 +906,28 @@ return result; } + /** + * The base implementation of `_.values` and `_.valuesIn` which creates an + * array of `object` property values corresponding to the property names + * returned by `keysFunc`. + * + * @private + * @param {Object} object The object to inspect. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns the array of property values. + */ + function baseValues(object, keysFunc) { + var index = -1, + props = keysFunc(object), + length = props.length, + result = Array(length); + + while (++index < length) { + result[index] = object[props[index]]; + } + return result; + } + /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -870,7 +936,7 @@ * @param {Array} partialArg An array of arguments to prepend to those provided. * @param {Array} partialHolders An array of `partialArgs` placeholder indexes. * @param {Array|Object} args The provided arguments. - * @returns {Array} Returns a new array of composed arguments. + * @returns {Array} Returns the new array of composed arguments. */ function composeArgs(partialArgs, partialHolders, args) { var holdersLength = partialHolders.length, @@ -894,9 +960,9 @@ /** * Creates a function that aggregates a collection, creating an object or - * array composed from the results of running each element of the collection - * through a callback. The given setter function sets the keys and values - * of the composed object or array. + * array composed from the results of running each element in the collection + * through a callback. The given setter function sets the keys and values of + * the composed object or array. * * @private * @param {Function} setter The setter function. @@ -927,8 +993,8 @@ } /** - * Creates a function that, when called, either curries or invokes `func` - * with an optional `this` binding and partially applied arguments. + * Creates a function that either curries or invokes `func` with an optional + * `this` binding and partially applied arguments. * * @private * @param {Function|string} func The function or method name to reference. @@ -976,7 +1042,7 @@ * * @private * @param {Array} array The array to inspect. - * @returns {Array} Returns a new array of placeholder indexes. + * @returns {Array} Returns the new array of placeholder indexes. */ function getHolders(array) { var index = -1, @@ -993,7 +1059,7 @@ /** * Gets the appropriate "indexOf" function. If the `_.indexOf` method is - * customized this method returns the custom method, otherwise it returns + * customized this function returns the custom method, otherwise it returns * the `baseIndexOf` function. * * @private @@ -1046,48 +1112,28 @@ } /** - * The base implementation of `_.forIn` without support for callback - * shorthands or `thisArg` binding. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} callback The function called per iteration. - * @returns {Object} Returns `object`. - */ - var baseForIn = function(object, callback) { - var result = object; - if (!isObject(object)) { - return result; - } - for (var key in object) { - if (callback(object[key], key, object) === breakIndicator) { - return result; - } - } - return result; - }; - - /** - * A fallback implementation of `Object.keys` which produces an array of the - * given object's own enumerable property names. + * A fallback implementation of `Object.keys` which creates an array of the + * own enumerable property names of `object`. * * @private * @type Function * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names. + * @returns {Array} Returns the array of property names. */ - var shimKeys = function(object) { - var result = []; - if (!isObject(object)) { - return result; - } - for (var key in object) { + function shimKeys(object) { + var index = -1, + props = keysIn(object), + length = props.length, + result = []; + + while (++index < length) { + var key = props[index]; if (hasOwnProperty.call(object, key)) { result.push(key); } } return result; - }; + } /*--------------------------------------------------------------------------*/ @@ -1099,7 +1145,7 @@ * @memberOf _ * @category Arrays * @param {Array} array The array to compact. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.compact([0, 1, false, 2, '', 3]); @@ -1129,7 +1175,7 @@ * @category Arrays * @param {Array} array The array to process. * @param {...Array} [values] The arrays of values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.difference([1, 2, 3], [5, 2, 10]); @@ -1140,7 +1186,7 @@ } /** - * Creates an array with `n` elements dropped from the beginning of `array`. + * Creates a slice of `array` with `n` elements dropped from the beginning. * * @static * @memberOf _ @@ -1212,7 +1258,7 @@ * If a property name or object is provided it will be used to create a "_.pluck" * or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new flattened array. + * @returns {Array} Returns the new flattened array. * @example * * _.flatten([1, [2], [3, [[4]]]]); @@ -1255,7 +1301,7 @@ * @param {*} value The value to search for. * @param {boolean|number} [fromIndex=0] 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 or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. * @example * * _.indexOf([1, 2, 3, 1, 2, 3], 2); @@ -1307,7 +1353,7 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of shared values. + * @returns {Array} Returns the new array of shared values. * @example * * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); @@ -1369,9 +1415,9 @@ } /** - * 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. + * 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. * * @static * @memberOf _ @@ -1379,7 +1425,7 @@ * @param {Array} array The array to search. * @param {*} value The value to search for. * @param {number} [fromIndex=array.length-1] The index to search from. - * @returns {number} Returns the index of the matched value or `-1`. + * @returns {number} Returns the index of the matched value, else `-1`. * @example * * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); @@ -1413,7 +1459,7 @@ * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. - * @returns {Array} Returns a new range array. + * @returns {Array} Returns the new array of numbers. * @example * * _.range(4); @@ -1490,7 +1536,7 @@ * @param {Array} array The array to slice. * @param {number} [start=0] The start index. * @param {number} [end=array.length] The end index. - * @returns {Array} Returns the new array. + * @returns {Array} Returns the slice of `array`. */ function slice(array, start, end) { var index = -1, @@ -1587,7 +1633,7 @@ } /** - * Creates an array of the first `n` elements of `array`. + * Creates a slice of `array` with `n` elements taken from the beginning. * * @static * @memberOf _ @@ -1599,7 +1645,7 @@ * @example * * _.take([1, 2, 3], 1); - * // => [2] + * // => [1] * * _.take([1, 2, 3], 2); * // => [1, 2] @@ -1620,7 +1666,7 @@ * @memberOf _ * @category Arrays * @param {...Array} [array] The arrays to inspect. - * @returns {Array} Returns an array of combined values. + * @returns {Array} Returns the new array of combined values. * @example * * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); @@ -1655,7 +1701,7 @@ * If a property name or object is provided it will be used to create a "_.pluck" * or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a duplicate-value-free array. + * @returns {Array} Returns the new duplicate-value-free array. * @example * * _.uniq([1, 2, 1, 3, 1]); @@ -1709,7 +1755,7 @@ * @category Arrays * @param {Array} array The array to filter. * @param {...*} [value] The values to exclude. - * @returns {Array} Returns a new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -1730,7 +1776,7 @@ * @alias unzip * @category Arrays * @param {...Array} [array] The arrays to process. - * @returns {Array} Returns a new array of grouped elements. + * @returns {Array} Returns the array of grouped elements. * @example * * _.zip(['fred', 'barney'], [30, 40], [true, false]); @@ -1761,8 +1807,7 @@ * @category Arrays * @param {Array} keys The array of keys. * @param {Array} [values=[]] The array of values. - * @returns {Object} Returns an object composed of the given keys and - * corresponding values. + * @returns {Object} Returns the new object. * @example * * _.zipObject(['fred', 'barney'], [30, 40]); @@ -1797,7 +1842,7 @@ * @memberOf _ * @category Chaining * @param {*} value The value to wrap. - * @returns {Object} Returns the wrapper object. + * @returns {Object} Returns the new wrapper object. * @example * * var characters = [ @@ -1932,7 +1977,6 @@ baseEach(collection, function(value) { return (result = value === target) && breakIndicator; }); - return result; } @@ -2057,7 +2101,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of elements that passed the predicate check. + * @returns {Array} Returns the new filtered array. * @example * * var evens = _.filter([1, 2, 3, 4], function(num) { return num % 2 == 0; }); @@ -2168,7 +2212,7 @@ } /** - * Iterates over elements of a collection, executing the callback for each + * Iterates over elements of a collection executing the callback for each * element. The callback is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). Callbacks may exit iteration early by * explicitly returning `false`. @@ -2278,18 +2322,18 @@ * @returns {Object} Returns the composed aggregate object. * @example * - * var keys = [ + * var keyData = [ * { 'dir': 'left', 'code': 97 }, * { 'dir': 'right', 'code': 100 } * ]; * - * _.indexBy(keys, 'dir'); + * _.indexBy(keyData, 'dir'); * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); + * _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); }); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keys, function(key) { return this.fromCharCode(key.code); }, String); + * _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } */ var indexBy = createAggregator(function(result, value, key) { @@ -2309,7 +2353,7 @@ * @param {Function|string} methodName The name of the method to invoke or * the function invoked per iteration. * @param {...*} [args] Arguments to invoke the method with. - * @returns {Array} Returns a new array of the results of each invoked method. + * @returns {Array} Returns the array of results. * @example * * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); @@ -2319,16 +2363,15 @@ * // => [['1', '2', '3'], ['4', '5', '6']] */ function invoke(collection, methodName) { - var index = -1, + var args = slice(arguments, 2), + index = -1, isFunc = typeof methodName == 'function', length = collection ? collection.length : 0, result = Array(typeof length == 'number' ? length : 0); - var args = slice(arguments, 2); baseEach(collection, function(value) { result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args); }); - return result; } @@ -2353,7 +2396,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new array of the results of each `callback` execution. + * @returns {Array} Returns the new mapped array. * @example * * _.map([1, 2, 3], function(num) { return num * 3; }); @@ -2557,7 +2600,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of grouped elements. + * @returns {Array} Returns the array of grouped elements. * @example * * _.partition([1, 2, 3], function(num) { return num % 2; }); @@ -2593,7 +2636,7 @@ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. * @param {string} key The name of the property to pluck. - * @returns {Array} Returns a new array of property values. + * @returns {Array} Returns the property values. * @example * * var characters = [ @@ -2661,8 +2704,8 @@ } /** - * 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 a + * collection from right to left. * * @static * @memberOf _ @@ -2710,7 +2753,7 @@ * per iteration. If a property name or object is provided it will be used * to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Array} Returns a new array of elements that failed the predicate check. + * @returns {Array} Returns the new filtered array. * @example * * var odds = _.reject([1, 2, 3, 4], function(num) { return num % 2 == 0; }); @@ -2731,9 +2774,7 @@ */ function reject(collection, predicate, thisArg) { predicate = createCallback(predicate, thisArg, 3); - return filter(collection, function(value, index, collection) { - return !predicate(value, index, collection); - }); + return filter(collection, negate(predicate)); } /** @@ -2745,7 +2786,7 @@ * @param {Array|Object|string} collection The collection to sample. * @param {number} [n] The number of elements to sample. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`. - * @returns {*} Returns the random sample(s) of `collection`. + * @returns {*} Returns the random sample(s). * @example * * _.sample([1, 2, 3, 4]); @@ -2775,7 +2816,7 @@ * @memberOf _ * @category Collections * @param {Array|Object|string} collection The collection to shuffle. - * @returns {Array} Returns a new shuffled collection. + * @returns {Array} Returns the new shuffled array. * @example * * _.shuffle([1, 2, 3, 4]); @@ -2908,7 +2949,7 @@ * called per iteration. If a property name or object is provided it will * be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns a new array of sorted elements. + * @returns {Array} Returns the new sorted array. * @example * * _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); @@ -2988,7 +3029,7 @@ * @category Collections * @param {Array|Object|string} collection The collection to iterate over. * @param {Object} source The object of property values to filter by. - * @returns {Array} Returns a new array of elements that have the given properties. + * @returns {Array} Returns the new filtered array. * @example * * var characters = [ @@ -3042,9 +3083,9 @@ } /** - * Creates a function that, when called, invokes `func` with the `this` - * binding of `thisArg` and prepends any additional `bind` arguments to those - * provided to the bound function. + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and prepends any additional `bind` arguments to those provided to the bound + * function. * * Note: Unlike native `Function#bind` this method does not set the `length` * property of bound functions. @@ -3360,7 +3401,7 @@ * @memberOf _ * @category Functions * @param {Function} func The function to have its output memoized. - * @param {Function} [resolver] A function used to resolve the cache key. + * @param {Function} [resolver] The function to resolve the cache key. * @returns {Function} Returns the new memoizing function. * @example * @@ -3433,9 +3474,9 @@ } /** - * Creates a function that, when called, invokes `func` with any additional - * `partial` arguments prepended to those provided to the new function. This - * method is similar to `_.bind` except it does **not** alter the `this` binding. + * Creates a function that invokes `func` with any additional `partial` arguments + * prepended to those provided to the new function. This method is similar to + * `_.bind` except it does **not** alter the `this` binding. * * Note: This method does not set the `length` property of partially applied * functions. @@ -3578,10 +3619,8 @@ } while (++argsIndex < argsLength) { source = args[argsIndex]; - if (source) { - for (var key in source) { - object[key] = source[key]; - } + for (var key in source) { + object[key] = source[key]; } } return object; @@ -3670,11 +3709,9 @@ } while (++argsIndex < argsLength) { source = args[argsIndex]; - if (source) { - for (var key in source) { - if (typeof object[key] == 'undefined') { - object[key] = source[key]; - } + for (var key in source) { + if (typeof object[key] == 'undefined') { + object[key] = source[key]; } } } @@ -3690,7 +3727,7 @@ * @alias methods * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names that have function values. + * @returns {Array} Returns the new sorted array of property names. * @example * * _.functions(_); @@ -3698,6 +3735,7 @@ */ function functions(object) { var result = []; + baseForIn(object, function(value, key) { if (isFunction(value)) { result.push(key); @@ -3736,7 +3774,7 @@ * @category Objects * @param {Object} object The object to invert. * @param {boolean} [multiValue=false] Allow multiple values per key. - * @returns {Object} Returns the created inverted object. + * @returns {Object} Returns the new inverted object. * @example * * _.invert({ 'first': 'fred', 'second': 'barney' }); @@ -3763,6 +3801,34 @@ return result; } + /** + * Checks if `value` is an `arguments` object. + * + * @static + * @memberOf _ + * @category Objects + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`. + * @example + * + * (function() { return _.isArguments(arguments); })(1, 2, 3); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + function isArguments(value) { + return value && typeof value == 'object' && typeof value.length == 'number' && + toString.call(value) == argsClass || false; + } + // fallback for environments that can't detect `arguments` objects by [[Class]] + if (!support.argsClass) { + isArguments = function(value) { + return value && typeof value == 'object' && typeof value.length == 'number' && + hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee') || false; + }; + } + /** * Checks if `value` is an array. * @@ -4088,9 +4154,7 @@ * // => true */ function isRegExp(value) { - var type = typeof value; - return value && (type == 'function' || type == 'object') && - toString.call(value) == regexpClass || false; + return value && typeof value == 'object' && toString.call(value) == regexpClass || false; } /** @@ -4129,25 +4193,60 @@ } /** - * Creates an array composed of the own enumerable property names of `object`. + * Creates an array of the own enumerable property names of `object`. * * @static * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property names. + * @returns {Array} Returns the array of property names. * @example * - * _.keys({ 'one': 1, 'two': 2, 'three': 3 }); - * // => ['one', 'two', 'three'] (property order is not guaranteed across environments) + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * Shape.prototype.z = 0; + * + * _.keys(new Shape); + * // => ['x', 'y'] (property order is not guaranteed across environments) */ var keys = !nativeKeys ? shimKeys : function(object) { - if (!isObject(object)) { - return []; - } - return nativeKeys(object); + return isObject(object) ? nativeKeys(object) : []; }; + /** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The object to inspect. + * @returns {Array} Returns the array of property names. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * Shape.prototype.z = 0; + * + * _.keysIn(new Shape); + * // => ['x', 'y', 'z'] (property order is not guaranteed across environments) + */ + function keysIn(object) { + var result = []; + if (!isObject(object)) { + return result; + } + for (var key in object) { + result.push(key); + } + return result; + } + /** * Creates a shallow clone of `object` excluding the specified properties. * Property names may be specified as individual arguments or as arrays of @@ -4164,7 +4263,7 @@ * iteration or property names to omit, specified as individual property * names or arrays of property names. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns an object without the omitted properties. + * @returns {Object} Returns the new object. * @example * * _.omit({ 'name': 'fred', 'age': 40 }, 'age'); @@ -4175,28 +4274,14 @@ * }); * // => { 'name': 'fred' } */ - function omit(object, guard) { + function omit(object) { var omitProps = baseFlatten(arguments, true, false, 1), - length = omitProps.length, - result = {}; + length = omitProps.length; while (length--) { omitProps[length] = String(omitProps[length]); } - var props = []; - baseForIn(object, function(value, key) { - props.push(key); - }); - - var index = -1; - props = baseDifference(props, omitProps); - length = props.length; - - while (++index < length) { - var key = props[index]; - result[key] = object[key]; - } - return result; + return pick(object, baseDifference(keysIn(object), omitProps)); } /** @@ -4242,7 +4327,7 @@ * iteration or property names to pick, specified as individual property * names or arrays of property names. * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns an object composed of the picked properties. + * @returns {Object} Returns the new object. * @example * * _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name'); @@ -4269,28 +4354,27 @@ } /** - * Creates an array composed of the own enumerable property values of `object`. + * Creates an array of the own enumerable property values of `object`. * * @static * @memberOf _ * @category Objects * @param {Object} object The object to inspect. - * @returns {Array} Returns an array of property values. + * @returns {Array} Returns the array of property values. * @example * - * _.values({ 'one': 1, 'two': 2, 'three': 3 }); - * // => [1, 2, 3] (property order is not guaranteed across environments) + * function Shape(x, y) { + * this.x = x; + * this.y = y; + * } + * + * Shape.prototype.z = 0; + * + * _.values(new Shape(2, 1)); + * // => [2, 1] (property order is not guaranteed across environments) */ function values(object) { - var index = -1, - props = keys(object), - length = props.length, - result = Array(length); - - while (++index < length) { - result[index] = object[props[index]]; - } - return result; + return baseValues(object, keys); } /*--------------------------------------------------------------------------*/ @@ -4332,7 +4416,7 @@ * @example * * _.escapeRegExp('[lodash](http://lodash.com)'); - * // => '\[lodash]\(http://lodash\.com\)' + * // => '\[lodash\]\(http://lodash\.com\)' */ function escapeRegExp(string) { return string == null ? '' : String(string).replace(reRegExpChars, '\\$&'); @@ -4370,7 +4454,7 @@ * @param {string} [options.sourceURL] The sourceURL of the template's compiled source. * @param {string} [options.variable] The data object variable name. * @returns {Function|string} Returns the interpolated string if a data object - * is provided, else it returns a template function. + * is provided, else the compiled template function. * @example * * // using the "interpolate" delimiter to create a compiled template @@ -4532,7 +4616,7 @@ } /** - * Produces a callback bound to an optional `thisArg`. If `func` is a property + * Creates a function bound to an optional `thisArg`. If `func` is a property * name the created callback will return the property value for a given element. * If `func` is an object the created callback will return `true` for elements * that contain the equivalent object properties, otherwise it will return `false`. @@ -4544,7 +4628,7 @@ * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @param {number} [argCount] The number of arguments the callback accepts. - * @returns {Function} Returns a callback function. + * @returns {Function} Returns the new function. * @example * * var characters = [ @@ -4688,6 +4772,33 @@ } } + /** + * Creates a function that negates the result of `func`. The `func` function + * is executed with the `this` binding and arguments of the created function. + * + * @static + * @memberOf _ + * @category Utilities + * @param {Function} func The function to negate. + * @returns {Function} Returns the new function. + * @example + * + * function isEven(num) { + * return num % 2 == 0; + * } + * + * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); + * // => [1, 3, 5] + */ + function negate(func) { + if (!isFunction(func)) { + throw new TypeError; + } + return function() { + return !func.apply(this, arguments); + }; + } + /** * Reverts the '_' variable to its previous value and returns a reference to * the `lodash` function. @@ -4780,7 +4891,7 @@ * @param {number} [min=0] The minimum possible value. * @param {number} [max=1] The maximum possible value. * @param {boolean} [floating=false] Specify returning a floating-point number. - * @returns {number} Returns a random number. + * @returns {number} Returns the random number. * @example * * _.random(0, 5); @@ -4860,7 +4971,7 @@ * @param {number} n The number of times to execute the callback. * @param {Function} [callback=identity] The function called per iteration. * @param {*} [thisArg] The `this` binding of `callback`. - * @returns {Array} Returns an array of the results of each `callback` execution. + * @returns {Array} Returns the array of results. * @example * * var diceRolls = _.times(3, _.partial(_.random, 1, 6)); diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 48ef28f00..8f51f95e1 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,37 +3,38 @@ * Lo-Dash 2.4.1 (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){var r=[];if(!H(n))return r;for(var t in n)Ir.call(n,t)&&r.push(t);return r}function r(n,r){if(H(n))for(var t in n)if(r(n[t],t,n)===ur)break}function t(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 g(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++to(f,c)&&(t&&f.push(c),i.push(a)) -}return i}function _(n,r){return function(t,e,u){var o=r?[[],[]]:{};e=Q(e,u,3),u=-1;var i=t?t.length:0;if(typeof i=="number")for(;++ue?Gr(0,u+e):e||0;else if(e)return e=O(n,r),u&&n[e]===r?e:-1;return t(n,r,e)}function T(n,r,t){return E(n,null==r||t?1:0r?r=Gr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Gr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=Q(r,t,3),g(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function I(n,r,t,e){var u=3>arguments.length;r=Q(r,e,4);var o=-1,i=n?n.length:0; -if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=Q(r,e,4),h(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function D(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return g(n,function(n){var t;t=++r,t=0+Rr(Kr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function W(n,r,t){var e;r=Q(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++targuments.length?b(n,tr,r):b(n,tr|er,r,E(arguments,2))}function C(n,r,t){function e(){l&&clearTimeout(l),i=l=p=rr,(h||g!==r)&&(s=ot(),f=n.apply(c,o),l||i||(o=c=null))}function u(){var t=r-(ot()-a);0>=t||t>r?(i&&clearTimeout(i),t=p,i=l=p=rr,t&&(s=ot(),f=n.apply(c,o),l||i||(o=c=null))):l=setTimeout(u,t)}var o,i,f,a,c,l,p,s=0,g=false,h=true;if(!G(n))throw new TypeError;if(r=0=y||y>g;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(c,o)):i||(i=setTimeout(e,y))}return m&&l?l=clearTimeout(l):l||r===g||(l=setTimeout(u,r)),t&&(m=true,f=n.apply(c,o)),!m||l||i||(o=c=null),f}}function P(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,ar=/($^)/,cr=/[.*+?^${}()|[\]\\]/g,lr=/['\n\r\t\u2028\u2029\\]/g,pr="[object Arguments]",sr="[object Array]",gr="[object Boolean]",hr="[object Date]",vr="[object Number]",yr="[object Object]",mr="[object RegExp]",_r="[object String]",br={"&":"&","<":"<",">":">",'"':""","'":"'"},dr={"&":"&","<":"<",">":">",""":'"',"'":"'"},wr={"function":true,object:true},jr={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},xr=wr[typeof window]&&window||this,Ar=wr[typeof exports]&&exports&&!exports.nodeType&&exports,Tr=wr[typeof module]&&module&&!module.nodeType&&module,Er=Ar&&Tr&&typeof global=="object"&&global; -!Er||Er.global!==Er&&Er.window!==Er&&Er.self!==Er||(xr=Er);var Or=Tr&&Tr.exports===Ar&&Ar,kr=Array.prototype,Sr=Object.prototype,Nr=xr._,qr=Sr.toString,Fr=RegExp("^"+(null==qr?"":(qr+"").replace(cr,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Br=Math.ceil,Rr=Math.floor,$r=Function.prototype.toString,Ir=Sr.hasOwnProperty,Mr=kr.push,Dr=Sr.propertyIsEnumerable,Wr=kr.splice,zr=w(zr=Object.create)&&zr,Cr=w(Cr=Array.isArray)&&Cr,Pr=xr.isFinite,Ur=xr.isNaN,Vr=w(Vr=Object.keys)&&Vr,Gr=Math.max,Hr=Math.min,Jr=w(Jr=Date.now)&&Jr,Kr=Math.random; -a.prototype=f.prototype;var Lr={};!function(){var n={0:1,length:1};Lr.spliceObjects=(Wr.call(n,0,1),!n[0])}(1),f.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},zr||(c=function(){function n(){}return function(r){if(H(r)){n.prototype=r;var t=new n;n.prototype=null}return t||xr.Object()}}()),j(arguments)||(j=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&Ir.call(n,"callee")&&!Dr.call(n,"callee")||false});var Qr=T,Xr=_(function(n,r,t){Ir.call(n,t)?n[t]++:n[t]=1 -}),Yr=_(function(n,r,t){Ir.call(n,t)?n[t].push(r):n[t]=[r]}),Zr=_(function(n,r,t){n[t]=r}),nt=_(function(n,r,t){n[t?0:1].push(r)},true),rt=R,tt=q,et=Cr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&qr.call(n)==sr||false};G(/x/)&&(G=function(n){return typeof n=="function"&&"[object Function]"==qr.call(n)});var ut=Vr?function(n){return H(n)?Vr(n):[]}:n,ot=Jr||function(){return(new Date).getTime()};f.after=function(n,r){if(!G(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0 -}},f.bind=z,f.bindAll=function(n){for(var r=1i(a,e)){for(r=t;--r;)if(0>i(n[r],e))continue n;a.push(e)}return a},f.invert=function(n){for(var r=-1,t=ut(n),e=t.length,u={};++rr?0:r);++nt?Gr(0,e+t):Hr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},f.mixin=Z,f.noConflict=function(){return xr._=Nr,this},f.now=ot,f.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Rr(Kr()*(r-n+1)) -},f.reduce=I,f.reduceRight=M,f.result=function(n,r){if(null!=n){var t=n[r];return G(t)?n[r]():t}},f.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:ut(n).length},f.some=W,f.sortedIndex=O,f.template=function(n,r,t){var e=f,u=e.templateSettings;n=(null==n?"":n)+"",t=U({},t,u);var i=0,a="__p+='",u=t.variable;n.replace(RegExp((t.escape||ar).source+"|"+(t.interpolate||ar).source+"|"+(t.evaluate||ar).source+"|$","g"),function(r,t,e,u,f){return a+=n.slice(i,f).replace(lr,o),t&&(a+="'+_.escape("+t+")+'"),u&&(a+="';"+u+";\n__p+='"),e&&(a+="'+((__t=("+e+"))==null?'':__t)+'"),i=f+r.length,r -}),a+="';",u||(a="with(obj||{}){"+a+"}"),a="function("+(u||"obj")+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var c=Function("_","return "+a)(e)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},f.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(ir,i))},f.uniqueId=function(n){var r=++or+"";return n?n+r:r},f.all=N,f.any=W,f.detect=F,f.findWhere=F,f.foldl=I,f.foldr=M,f.include=S,f.inject=I,f.first=x,f.last=function(n,r,t){var e=n?n.length:0; -return null==r||t?n?n[e-1]:rr:(r=e-r,E(n,0e||typeof t=="undefined"){t=1;break n}if(tu(r,i)&&o.push(i)}return o}function p(n,r){var t=-1,e=n?n.length:0;if(typeof e=="number")for(;++to(f,c)&&(t&&f.push(c),i.push(a))}return i}function b(n,r){return function(t,e,u){var o=r?[[],[]]:{}; +e=Z(e,u,3),u=-1;var i=t?t.length:0;if(typeof i=="number")for(;++ue?Lr(0,u+e):e||0;else if(e)return e=S(r,t),u&&r[e]===t?e:-1;return n(r,t,e)}function E(n,r,t){return O(n,null==r||t?1:0r?r=Lr(u+r,0):r>u&&(r=u),typeof t=="undefined"?t=u:0>t?t=Lr(u+t,0):t>u&&(t=u),u=t-r||0,t=Array(u);++e>>1,t(n[e])u&&(u=t);else r=Z(r,t,3),p(n,function(n,t,o){t=r(n,t,o),t>e&&(e=t,u=n)});return u}function M(n,r,t,e){var u=3>arguments.length;r=Z(r,e,4);var o=-1,i=n?n.length:0; +if(typeof i=="number")for(u&&i&&(t=n[++o]);++oarguments.length;return r=Z(r,e,4),s(n,function(n,e,o){t=u?(u=false,n):r(t,n,e,o)}),t}function W(n){var r=-1,t=n?n.length:0,e=Array(typeof t=="number"?t:0);return p(n,function(n){var t;t=++r,t=0+Dr(Yr()*(t-0+1)),e[r]=e[t],e[t]=n}),e}function z(n,r,t){var e;r=Z(r,t,3),t=-1;var u=n?n.length:0;if(typeof u=="number"){for(;++targuments.length?_(n,ir,r):_(n,ir|fr,r,O(arguments,2))}function P(n,r,t){function e(){l&&clearTimeout(l),i=l=p=or,(h||g!==r)&&(s=ct(),f=n.apply(c,o),l||i||(o=c=null))}function u(){var t=r-(ct()-a);0>=t||t>r?(i&&clearTimeout(i),t=p,i=l=p=or,t&&(s=ct(),f=n.apply(c,o),l||i||(o=c=null))):l=setTimeout(u,t)}var o,i,f,a,c,l,p,s=0,g=false,h=true;if(!H(n))throw new TypeError;if(r=0=y||y>g;m?(i&&(i=clearTimeout(i)),s=a,f=n.apply(c,o)):i||(i=setTimeout(e,y))}return m&&l?l=clearTimeout(l):l||r===g||(l=setTimeout(u,r)),t&&(m=true,f=n.apply(c,o)),!m||l||i||(o=c=null),f}}function U(n,r,t){if(!n)return n;var e=arguments,u=0,o=e.length,i=typeof t;for("number"!=i&&"string"!=i||!e[3]||e[3][t]!==r||(o=2);++u"']/g,sr=/($^)/,gr=/[.*+?^${}()|[\]\\]/g,hr=/['\n\r\t\u2028\u2029\\]/g,vr="[object Arguments]",yr="[object Array]",mr="[object Boolean]",br="[object Date]",_r="[object Number]",dr="[object Object]",wr="[object RegExp]",jr="[object String]",xr={"&":"&","<":"<",">":">",'"':""","'":"'"},Ar={"&":"&","<":"<",">":">",""":'"',"'":"'"},Tr={"function":true,object:true},Er={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},Or=Tr[typeof window]&&window||this,Sr=Tr[typeof exports]&&exports&&!exports.nodeType&&exports,kr=Tr[typeof module]&&module&&!module.nodeType&&module,Nr=Sr&&kr&&typeof global=="object"&&global; +!Nr||Nr.global!==Nr&&Nr.window!==Nr&&Nr.self!==Nr||(Or=Nr);var qr=kr&&kr.exports===Sr&&Sr,Fr=Array.prototype,Br=Object.prototype,Rr=Or._,$r=Br.toString,Ir=RegExp("^"+(null==$r?"":($r+"").replace(gr,"\\$&")).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mr=Math.ceil,Dr=Math.floor,Wr=Function.prototype.toString,zr=Br.hasOwnProperty,Cr=Fr.push,Pr=Br.propertyIsEnumerable,Ur=Fr.splice,Vr=w(Vr=Object.create)&&Vr,Gr=w(Gr=Array.isArray)&&Gr,Hr=Or.isFinite,Jr=Or.isNaN,Kr=w(Kr=Object.keys)&&Kr,Lr=Math.max,Qr=Math.min,Xr=w(Xr=Date.now)&&Xr,Yr=Math.random; +i.prototype=o.prototype;var Zr={};!function(){var n={0:1,length:1};Zr.spliceObjects=(Ur.call(n,0,1),!n[0])}(1),o.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},Vr||(f=function(){function n(){}return function(r){if(J(r)){n.prototype=r;var t=new n;n.prototype=null}return t||Or.Object()}}()),j(arguments)||(j=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n,"callee")&&!Pr.call(n,"callee")||false});var nt=E,rt=b(function(n,r,t){zr.call(n,t)?n[t]++:n[t]=1 +}),tt=b(function(n,r,t){zr.call(n,t)?n[t].push(r):n[t]=[r]}),et=b(function(n,r,t){n[t]=r}),ut=b(function(n,r,t){n[t?0:1].push(r)},true),ot=$,it=F;Zr.argsClass||(j=function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&zr.call(n,"callee")&&!Pr.call(n,"callee")||false});var ft=Gr||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&$r.call(n)==yr||false};H(/x/)&&(H=function(n){return typeof n=="function"&&"[object Function]"==$r.call(n)});var at=Kr?function(n){return J(n)?Kr(n):[] +}:x,ct=Xr||function(){return(new Date).getTime()};o.after=function(n,r){if(!H(r))throw new TypeError;return function(){return 1>--n?r.apply(this,arguments):void 0}},o.bind=C,o.bindAll=function(n){for(var r=1i(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=at(n),e=t.length,u={};++rr?0:r);++nt?Lr(0,e+t):Qr(t,e-1))+1);e--;)if(n[e]===r)return e;return-1},o.mixin=tr,o.noConflict=function(){return Or._=Rr,this},o.now=ct,o.random=function(n,r){return null==n&&null==r&&(r=1),n=+n||0,null==r?(r=n,n=0):r=+r||0,n+Dr(Yr()*(r-n+1)) +},o.reduce=M,o.reduceRight=D,o.result=function(n,r){if(null!=n){var t=n[r];return H(t)?n[r]():t}},o.size=function(n){var r=n?n.length:0;return typeof r=="number"?r:at(n).length},o.some=z,o.sortedIndex=S,o.template=function(n,r,t){var u=o,i=u.templateSettings;n=(null==n?"":n)+"",t=V({},t,i);var f=0,a="__p+='",i=t.variable;n.replace(RegExp((t.escape||sr).source+"|"+(t.interpolate||sr).source+"|"+(t.evaluate||sr).source+"|$","g"),function(r,t,u,o,i){return a+=n.slice(f,i).replace(hr,e),t&&(a+="'+_.escape("+t+")+'"),o&&(a+="';"+o+";\n__p+='"),u&&(a+="'+((__t=("+u+"))==null?'':__t)+'"),f=i+r.length,r +}),a+="';",i||(a="with(obj||{}){"+a+"}"),a="function("+(i||"obj")+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+a+"return __p}";try{var c=Function("_","return "+a)(u)}catch(l){throw l.source=a,l}return r?c(r):(c.source=a,c)},o.unescape=function(n){return null==n?"":(n+="",0>n.indexOf(";")?n:n.replace(lr,u))},o.uniqueId=function(n){var r=++cr+"";return n?n+r:r},o.all=q,o.any=z,o.detect=B,o.findWhere=B,o.foldl=M,o.foldr=D,o.include=N,o.inject=M,o.first=A,o.last=function(n,r,t){var e=n?n.length:0; +return null==r||t?n?n[e-1]:or:(r=e-r,O(n,0