Rebuild dist.

This commit is contained in:
John-David Dalton
2014-03-08 19:59:39 -08:00
parent 43efc930f4
commit 1d0f2e9d31
6 changed files with 1268 additions and 989 deletions

View File

@@ -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));