mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Rebuild docs and files.
Former-commit-id: 94d3e29ccf0ba47599a9d662e5d4068713009c9b
This commit is contained in:
262
dist/lodash.js
vendored
262
dist/lodash.js
vendored
@@ -24,6 +24,10 @@
|
||||
window = freeGlobal;
|
||||
}
|
||||
|
||||
/** Used to pool arrays and objects used internally */
|
||||
var arrayPool = [],
|
||||
objectPool = [];
|
||||
|
||||
/** Used to generate unique IDs */
|
||||
var idCounter = 0;
|
||||
|
||||
@@ -36,6 +40,9 @@
|
||||
/** Used as the size when optimizations are enabled for large arrays */
|
||||
var largeArraySize = 75;
|
||||
|
||||
/** Used as the max size of the `arrayPool` and `objectPool` */
|
||||
var maxPoolSize = 10;
|
||||
|
||||
/** Used to match empty string literals in compiled template source */
|
||||
var reEmptyStringLeading = /\b__p \+= '';/g,
|
||||
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
||||
@@ -134,6 +141,72 @@
|
||||
'\u2029': 'u2029'
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an array from the array pool or creates a new one if the pool is empty.
|
||||
*
|
||||
* @private
|
||||
* @returns {Array} The array from the pool.
|
||||
*/
|
||||
function getArray() {
|
||||
return arrayPool.pop() || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the object pool or creates a new one if the pool is empty.
|
||||
*
|
||||
* @private
|
||||
* @returns {Object} The object from the pool.
|
||||
*/
|
||||
function getObject() {
|
||||
return objectPool.pop() || {
|
||||
'array': null,
|
||||
'contains': null,
|
||||
'criteria': null,
|
||||
'false': null,
|
||||
'function': null,
|
||||
'index': null,
|
||||
'indexOf': null,
|
||||
'initedArray': null,
|
||||
'null': null,
|
||||
'number': null,
|
||||
'object': null,
|
||||
'push': null,
|
||||
'release': null,
|
||||
'string': null,
|
||||
'true': null,
|
||||
'undefined': null,
|
||||
'value': null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the given `array` back to the array pool.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to release.
|
||||
*/
|
||||
function releaseArray(array) {
|
||||
if (arrayPool.length == maxPoolSize) {
|
||||
arrayPool.length = maxPoolSize - 1;
|
||||
}
|
||||
array.length = 0;
|
||||
arrayPool.push(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the given `object` back to the object pool.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} [object] The object to release.
|
||||
*/
|
||||
function releaseObject(object) {
|
||||
if (objectPool.length == maxPoolSize) {
|
||||
objectPool.length = maxPoolSize - 1;
|
||||
}
|
||||
object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
|
||||
objectPool.push(object);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
@@ -501,42 +574,28 @@
|
||||
* @param {Mixed} value The value to search for.
|
||||
* @returns {Boolean} Returns `true`, if `value` is found, else `false`.
|
||||
*/
|
||||
function createCache(array) {
|
||||
array || (array = []);
|
||||
|
||||
var bailout,
|
||||
index = -1,
|
||||
indexOf = getIndexOf(),
|
||||
length = array.length,
|
||||
isLarge = length >= largeArraySize && lodash.indexOf != indexOf,
|
||||
objCache = {};
|
||||
|
||||
var caches = {
|
||||
'false': false,
|
||||
'function': false,
|
||||
'null': false,
|
||||
'number': {},
|
||||
'object': objCache,
|
||||
'string': {},
|
||||
'true': false,
|
||||
'undefined': false
|
||||
};
|
||||
var createCache = (function() {
|
||||
|
||||
function basicContains(value) {
|
||||
return indexOf(array, value) > -1;
|
||||
return this.indexOf(this.array, value) > -1;
|
||||
}
|
||||
|
||||
function basicPush(value) {
|
||||
array.push(value);
|
||||
this.array.push(value);
|
||||
}
|
||||
|
||||
function cacheContains(value) {
|
||||
var type = typeof value;
|
||||
var cache = this.cache,
|
||||
type = typeof value;
|
||||
|
||||
if (type == 'boolean' || value == null) {
|
||||
return caches[value];
|
||||
return cache[value];
|
||||
}
|
||||
var cache = caches[type] || (type = 'object', objCache),
|
||||
key = type == 'number' ? value : keyPrefix + value;
|
||||
if (type != 'number' && type != 'string') {
|
||||
type = 'object';
|
||||
}
|
||||
var key = type == 'number' ? value : keyPrefix + value;
|
||||
cache = cache[type] || (cache[type] = {});
|
||||
|
||||
return type == 'object'
|
||||
? (cache[key] ? basicIndexOf(cache[key], value) > -1 : false)
|
||||
@@ -544,12 +603,17 @@
|
||||
}
|
||||
|
||||
function cachePush(value) {
|
||||
var type = typeof value;
|
||||
var cache = this.cache,
|
||||
type = typeof value;
|
||||
|
||||
if (type == 'boolean' || value == null) {
|
||||
caches[value] = true;
|
||||
cache[value] = true;
|
||||
} else {
|
||||
var cache = caches[type] || (type = 'object', objCache),
|
||||
key = type == 'number' ? value : keyPrefix + value;
|
||||
if (type != 'number' && type != 'string') {
|
||||
type = 'object';
|
||||
}
|
||||
var key = type == 'number' ? value : keyPrefix + value;
|
||||
cache = cache[type] || (cache[type] = {});
|
||||
|
||||
if (type == 'object') {
|
||||
bailout = (cache[key] || (cache[key] = [])).push(value) == length;
|
||||
@@ -559,18 +623,50 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (isLarge) {
|
||||
while (++index < length) {
|
||||
cachePush(array[index]);
|
||||
}
|
||||
if (bailout) {
|
||||
isLarge = caches = objCache = null;
|
||||
function release() {
|
||||
var cache = this.cache;
|
||||
if (cache.initedArray) {
|
||||
releaseArray(this.array);
|
||||
}
|
||||
releaseObject(cache);
|
||||
}
|
||||
return isLarge
|
||||
? { 'contains': cacheContains, 'push': cachePush }
|
||||
: { 'contains': basicContains, 'push': basicPush };
|
||||
}
|
||||
|
||||
return function(array) {
|
||||
var bailout,
|
||||
index = -1,
|
||||
indexOf = getIndexOf(),
|
||||
initedArray = !array && (array = getArray()),
|
||||
length = array.length,
|
||||
isLarge = length >= largeArraySize && lodash.indexOf !== indexOf;
|
||||
|
||||
var cache = getObject();
|
||||
cache.initedArray = initedArray;
|
||||
cache['false'] = cache['function'] = cache['null'] = cache['true'] = cache['undefined'] = false;
|
||||
|
||||
var result = getObject();
|
||||
result.array = array;
|
||||
result.cache = cache;
|
||||
result.contains = cacheContains;
|
||||
result.indexOf = indexOf;
|
||||
result.push = cachePush;
|
||||
result.release = release;
|
||||
|
||||
if (isLarge) {
|
||||
while (++index < length) {
|
||||
result.push(array[index]);
|
||||
}
|
||||
if (bailout) {
|
||||
isLarge = false;
|
||||
result.release();
|
||||
}
|
||||
}
|
||||
if (!isLarge) {
|
||||
result.contains = basicContains;
|
||||
result.push = basicPush;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}());
|
||||
|
||||
/**
|
||||
* Creates a new object with the specified `prototype`.
|
||||
@@ -615,7 +711,7 @@
|
||||
* @returns {Function} Returns the "indexOf" function.
|
||||
*/
|
||||
function getIndexOf(array, value, fromIndex) {
|
||||
var result = (result = lodash.indexOf) == indexOf ? basicIndexOf : result;
|
||||
var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -878,8 +974,8 @@
|
||||
iterable = args[argsIndex];
|
||||
if (iterable && objectTypes[typeof iterable]) {
|
||||
var ownIndex = -1,
|
||||
ownProps = objectTypes[typeof iterable] ? keys(iterable) : [],
|
||||
length = ownProps.length;
|
||||
ownProps = objectTypes[typeof iterable] && keys(iterable),
|
||||
length = ownProps ? ownProps.length : 0;
|
||||
|
||||
while (++ownIndex < length) {
|
||||
index = ownProps[ownIndex];
|
||||
@@ -982,8 +1078,9 @@
|
||||
return ctor(result.source, reFlags.exec(result));
|
||||
}
|
||||
// check for circular references and return corresponding clone
|
||||
stackA || (stackA = []);
|
||||
stackB || (stackB = []);
|
||||
var initedStack = !stackA;
|
||||
stackA || (stackA = getArray());
|
||||
stackB || (stackB = getArray());
|
||||
|
||||
var length = stackA.length;
|
||||
while (length--) {
|
||||
@@ -1013,6 +1110,10 @@
|
||||
result[key] = clone(objValue, deep, callback, undefined, stackA, stackB);
|
||||
});
|
||||
|
||||
if (initedStack) {
|
||||
releaseArray(stackA);
|
||||
releaseArray(stackB);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1091,8 +1192,8 @@
|
||||
iterable = args[argsIndex];
|
||||
if (iterable && objectTypes[typeof iterable]) {
|
||||
var ownIndex = -1,
|
||||
ownProps = objectTypes[typeof iterable] ? keys(iterable) : [],
|
||||
length = ownProps.length;
|
||||
ownProps = objectTypes[typeof iterable] && keys(iterable),
|
||||
length = ownProps ? ownProps.length : 0;
|
||||
|
||||
while (++ownIndex < length) {
|
||||
index = ownProps[ownIndex];
|
||||
@@ -1202,8 +1303,8 @@
|
||||
if (!objectTypes[typeof iterable]) return result;
|
||||
callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg);
|
||||
var ownIndex = -1,
|
||||
ownProps = objectTypes[typeof iterable] ? keys(iterable) : [],
|
||||
length = ownProps.length;
|
||||
ownProps = objectTypes[typeof iterable] && keys(iterable),
|
||||
length = ownProps ? ownProps.length : 0;
|
||||
|
||||
while (++ownIndex < length) {
|
||||
index = ownProps[ownIndex];
|
||||
@@ -1499,8 +1600,9 @@
|
||||
// assume cyclic structures are equal
|
||||
// the algorithm for detecting cyclic structures is adapted from ES 5.1
|
||||
// section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3)
|
||||
stackA || (stackA = []);
|
||||
stackB || (stackB = []);
|
||||
var initedStack = !stackA;
|
||||
stackA || (stackA = getArray());
|
||||
stackB || (stackB = getArray());
|
||||
|
||||
var length = stackA.length;
|
||||
while (length--) {
|
||||
@@ -1562,6 +1664,10 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
if (initedStack) {
|
||||
releaseArray(stackA);
|
||||
releaseArray(stackB);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1865,8 +1971,9 @@
|
||||
stackA = args[4],
|
||||
stackB = args[5];
|
||||
} else {
|
||||
stackA = [];
|
||||
stackB = [];
|
||||
var initedStack = true;
|
||||
stackA = getArray();
|
||||
stackB = getArray();
|
||||
|
||||
// allows working with `_.reduce` and `_.reduceRight` without
|
||||
// using their `callback` arguments, `index|key` and `collection`
|
||||
@@ -1932,6 +2039,11 @@
|
||||
object[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
if (initedStack) {
|
||||
releaseArray(stackA);
|
||||
releaseArray(stackB);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -3100,17 +3212,18 @@
|
||||
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
forEach(collection, function(value, key, collection) {
|
||||
result[++index] = {
|
||||
'criteria': callback(value, key, collection),
|
||||
'index': index,
|
||||
'value': value
|
||||
};
|
||||
var object = result[++index] = getObject();
|
||||
object.criteria = callback(value, key, collection);
|
||||
object.index = index;
|
||||
object.value = value;
|
||||
});
|
||||
|
||||
length = result.length;
|
||||
result.sort(compareAscending);
|
||||
while (length--) {
|
||||
result[length] = result[length].value;
|
||||
var object = result[length];
|
||||
result[length] = object.value;
|
||||
releaseObject(object);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -3210,15 +3323,16 @@
|
||||
var index = -1,
|
||||
length = array ? array.length : 0,
|
||||
flattened = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),
|
||||
contains = createCache(flattened).contains,
|
||||
cache = createCache(flattened),
|
||||
result = [];
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
if (!contains(value)) {
|
||||
if (!cache.contains(value)) {
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
cache.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3522,27 +3636,34 @@
|
||||
function intersection(array) {
|
||||
var args = arguments,
|
||||
argsLength = args.length,
|
||||
cache = createCache(),
|
||||
caches = {},
|
||||
index = -1,
|
||||
length = array ? array.length : 0,
|
||||
isLarge = length >= largeArraySize,
|
||||
result = [];
|
||||
|
||||
var caches = getArray();
|
||||
caches[0] = createCache();
|
||||
|
||||
outer:
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
var cache = caches[0],
|
||||
value = array[index];
|
||||
|
||||
if (!cache.contains(value)) {
|
||||
var argsIndex = argsLength;
|
||||
cache.push(value);
|
||||
while (--argsIndex) {
|
||||
if (!(caches[argsIndex] || (caches[argsIndex] = createCache(args[argsIndex]).contains))(value)) {
|
||||
cache = caches[argsIndex] || (caches[argsIndex] = createCache(args[argsIndex]));
|
||||
if (!cache.contains(value)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
while (argsLength--) {
|
||||
caches[argsLength].release();
|
||||
}
|
||||
releaseArray(caches);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3914,9 +4035,9 @@
|
||||
var index = -1,
|
||||
indexOf = getIndexOf(),
|
||||
length = array ? array.length : 0,
|
||||
isLarge = !isSorted && length >= largeArraySize,
|
||||
isLarge = !isSorted && length >= largeArraySize && lodash.indexOf !== indexOf,
|
||||
result = [],
|
||||
seen = isLarge ? createCache() : (callback ? [] : result);
|
||||
seen = isLarge ? createCache() : (callback ? getArray() : result);
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index],
|
||||
@@ -3932,6 +4053,11 @@
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
if (isLarge) {
|
||||
seen.release();
|
||||
} else if (callback) {
|
||||
releaseArray(seen);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user