mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Update vendors, rebuild minified files, update docs/license.
Former-commit-id: 689793b6e5c4bbae917e726dc646902c697ce3a7
This commit is contained in:
@@ -186,24 +186,25 @@
|
||||
* method chaining.
|
||||
*
|
||||
* The chainable wrapper functions are:
|
||||
* `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
|
||||
* `compose`, `countBy`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
|
||||
* `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`, `compose`,
|
||||
* `concat`, `countBy`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
|
||||
* `filter`, `flatten`, `forEach`, `forIn`, `forOwn`, `functions`, `groupBy`,
|
||||
* `initial`, `intersection`, `invert`, `invoke`, `keys`, `map`, `max`, `memoize`,
|
||||
* `merge`, `min`, `object`, `omit`, `once`, `pairs`, `partial`, `pick`, `pluck`,
|
||||
* `range`, `reject`, `rest`, `shuffle`, `sortBy`, `tap`, `throttle`, `times`,
|
||||
* `toArray`, `union`, `uniq`, `values`, `where`, `without`, `wrap`, and `zip`
|
||||
* `push`, `range`, `reject`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
|
||||
* `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `union`, `uniq`,
|
||||
* `unshift`, `values`, `where`, `without`, `wrap`, and `zip`
|
||||
*
|
||||
* The non-chainable wrapper functions are:
|
||||
* `clone`, `contains`, `escape`, `every`, `find`, `has`, `identity`, `indexOf`,
|
||||
* `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`,
|
||||
* `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`, `isObject`,
|
||||
* `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `lastIndexOf`, `mixin`,
|
||||
* `noConflict`, `random`, `reduce`, `reduceRight`, `result`, `size`, `some`,
|
||||
* `sortedIndex`, `template`, `unescape`, and `uniqueId`
|
||||
* `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`, `lastIndexOf`,
|
||||
* `mixin`, `noConflict`, `pop`, `random`, `reduce`, `reduceRight`, `result`,
|
||||
* `shift`, `size`, `some`, `sortedIndex`, `template`, `unescape`, and `uniqueId`
|
||||
*
|
||||
* The wrapper functions `first` and `last` return wrapped values when `n` is
|
||||
* passed, otherwise return unwrapped values.
|
||||
* passed, otherwise they return unwrapped values.
|
||||
*
|
||||
* @name _
|
||||
* @constructor
|
||||
@@ -272,6 +273,7 @@
|
||||
};
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/** Reusable iterator options for `assign` and `defaults` */
|
||||
var assignIteratorOptions = {
|
||||
'args': 'object, source, guard',
|
||||
@@ -283,9 +285,9 @@
|
||||
};
|
||||
|
||||
/**
|
||||
* Reusable iterator options shared by `forEach`, `forIn`, and `forOwn`.
|
||||
* Reusable iterator options shared by `each`, `forIn`, and `forOwn`.
|
||||
*/
|
||||
var forEachIteratorOptions = {
|
||||
var eachIteratorOptions = {
|
||||
'args': 'collection, callback, thisArg',
|
||||
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)",
|
||||
'arrayLoop': 'if (callback(iteratee[index], index, collection) === false) return result',
|
||||
@@ -462,6 +464,38 @@
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A function compiled to iterate `arguments` objects, arrays, objects, and
|
||||
* strings consistenly across environments, executing the `callback` for each
|
||||
* element in the `collection`. The `callback` is bound to `thisArg` and invoked
|
||||
* with three arguments; (value, index|key, collection). Callbacks may exit
|
||||
* iteration early by explicitly returning `false`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object|String} collection The collection to iterate over.
|
||||
* @param {Function} [callback=identity] The function called per iteration.
|
||||
* @param {Mixed} [thisArg] The `this` binding of `callback`.
|
||||
* @returns {Array|Object|String} Returns `collection`.
|
||||
*/
|
||||
var each = function (collection, callback, thisArg) {
|
||||
var index, iteratee = collection, result = collection;
|
||||
if (!collection) return result;
|
||||
callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg);
|
||||
var length = iteratee.length; index = -1;
|
||||
if (typeof length == 'number') {
|
||||
while (++index < length) {
|
||||
if (callback(iteratee[index], index, collection) === indicatorObject) return result
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (index in iteratee) {
|
||||
if (hasOwnProperty.call(iteratee, index)) {
|
||||
if (callback(iteratee[index], index, collection) === indicatorObject) return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by `template` to escape characters for inclusion in compiled
|
||||
* string literals.
|
||||
@@ -908,6 +942,8 @@
|
||||
* // => true
|
||||
*/
|
||||
var isArray = nativeIsArray || function(value) {
|
||||
// `instanceof` may cause a memory leak in IE 7 if `value` is a host object
|
||||
// http://ajaxian.com/archives/working-aroung-the-instanceof-memory-leak
|
||||
return value instanceof Array || toString.call(value) == arrayClass;
|
||||
};
|
||||
|
||||
@@ -1513,7 +1549,7 @@
|
||||
if (typeof length == 'number') {
|
||||
result = indexOf(collection, target) > -1;
|
||||
} else {
|
||||
forEach(collection, function(value) {
|
||||
each(collection, function(value) {
|
||||
return (result = value === target) && indicatorObject;
|
||||
});
|
||||
}
|
||||
@@ -1590,7 +1626,7 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
forEach(collection, function(value, index, collection) {
|
||||
each(collection, function(value, index, collection) {
|
||||
return !(result = !!callback(value, index, collection)) && indicatorObject;
|
||||
});
|
||||
}
|
||||
@@ -1630,7 +1666,7 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
forEach(collection, function(value, index, collection) {
|
||||
each(collection, function(value, index, collection) {
|
||||
if (callback(value, index, collection)) {
|
||||
result.push(value);
|
||||
}
|
||||
@@ -1694,25 +1730,23 @@
|
||||
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert);
|
||||
* // => alerts each number value (order is not guaranteed)
|
||||
*/
|
||||
var forEach = function (collection, callback, thisArg) {
|
||||
var index, iteratee = collection, result = collection;
|
||||
if (!collection) return result;
|
||||
callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg);
|
||||
var length = iteratee.length; index = -1;
|
||||
if (typeof length == 'number') {
|
||||
while (++index < length) {
|
||||
if (callback(iteratee[index], index, collection) === indicatorObject) return result
|
||||
function forEach(collection, callback, thisArg) {
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
length = collection.length;
|
||||
|
||||
if (!callback || typeof thisArg != 'undefined') {
|
||||
callback = createCallback(callback, thisArg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (index in iteratee) {
|
||||
if (hasOwnProperty.call(iteratee, index)) {
|
||||
if (callback(iteratee[index], index, collection) === indicatorObject) return result;
|
||||
while (++index < length) {
|
||||
if (callback(collection[index], index, collection) === indicatorObject) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
} else {
|
||||
each(collection, callback, thisArg);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an object composed of keys returned from running each element of
|
||||
@@ -1816,7 +1850,7 @@
|
||||
result[index] = callback(collection[index], index, collection);
|
||||
}
|
||||
} else {
|
||||
forEach(collection, function(value, key, collection) {
|
||||
each(collection, function(value, key, collection) {
|
||||
result[++index] = callback(value, key, collection);
|
||||
});
|
||||
}
|
||||
@@ -1856,7 +1890,7 @@
|
||||
if (callback || !isArray(collection)) {
|
||||
callback = createCallback(callback, thisArg);
|
||||
|
||||
forEach(collection, function(value, index, collection) {
|
||||
each(collection, function(value, index, collection) {
|
||||
var current = callback(value, index, collection);
|
||||
if (current > computed) {
|
||||
computed = current;
|
||||
@@ -1900,7 +1934,7 @@
|
||||
if (callback || !isArray(collection)) {
|
||||
callback = createCallback(callback, thisArg);
|
||||
|
||||
forEach(collection, function(value, index, collection) {
|
||||
each(collection, function(value, index, collection) {
|
||||
var current = callback(value, index, collection);
|
||||
if (current < computed) {
|
||||
computed = current;
|
||||
@@ -1977,7 +2011,7 @@
|
||||
accumulator = callback(accumulator, collection[index], index, collection);
|
||||
}
|
||||
} else {
|
||||
forEach(collection, function(value, index, collection) {
|
||||
each(collection, function(value, index, collection) {
|
||||
accumulator = noaccum
|
||||
? (noaccum = false, value)
|
||||
: callback(accumulator, value, index, collection)
|
||||
@@ -2132,7 +2166,7 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
forEach(collection, function(value, index, collection) {
|
||||
each(collection, function(value, index, collection) {
|
||||
return (result = callback(value, index, collection)) && indicatorObject;
|
||||
});
|
||||
}
|
||||
@@ -3633,7 +3667,7 @@
|
||||
* // => '1,2,3'
|
||||
*/
|
||||
function wrapperToString() {
|
||||
return String(this.__wrapped__);
|
||||
return this.__wrapped__ + '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3794,7 +3828,7 @@
|
||||
lodash.prototype.value = wrapperValueOf;
|
||||
|
||||
// add `Array` mutator functions to the wrapper
|
||||
forEach(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
|
||||
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
|
||||
var func = arrayRef[methodName];
|
||||
lodash.prototype[methodName] = function() {
|
||||
var value = this.__wrapped__;
|
||||
@@ -3810,7 +3844,7 @@
|
||||
});
|
||||
|
||||
// add `Array` accessor functions to the wrapper
|
||||
forEach(['concat', 'join', 'slice'], function(methodName) {
|
||||
each(['concat', 'join', 'slice'], function(methodName) {
|
||||
var func = arrayRef[methodName];
|
||||
lodash.prototype[methodName] = function() {
|
||||
var value = this.__wrapped__,
|
||||
|
||||
Reference in New Issue
Block a user