Rebuild files and docs.

Former-commit-id: 1e3b1e236e15e4248247a4b20288ab2e153ce753
This commit is contained in:
John-David Dalton
2013-06-07 08:39:08 -07:00
parent b928abb956
commit d77e4ed581
7 changed files with 894 additions and 858 deletions

572
dist/lodash.compat.js vendored
View File

@@ -147,6 +147,166 @@
'\u2029': 'u2029'
};
/*--------------------------------------------------------------------------*/
/**
* A basic implementation of `_.indexOf` without support for binary searches
* or `fromIndex` constraints.
*
* @private
* @param {Array} array The array to search.
* @param {Mixed} 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`.
*/
function basicIndexOf(array, value, fromIndex) {
var index = (fromIndex || 0) - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* An implementation of `_.contains` for cache objects that mimics the return
* signature of `_.indexOf` by returning `0` if the value is found, else `-1`.
*
* @private
* @param {Object} cache The cache object to inspect.
* @param {Mixed} value The value to search for.
* @returns {Number} Returns `0` if `value` is found, else `-1`.
*/
function cacheIndexOf(cache, value) {
var type = typeof value;
cache = cache.cache;
if (type == 'boolean' || value == null) {
return cache[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 ? 0 : -1)
: (cache[key] ? 0 : -1);
}
/**
* Adds a given `value` to the corresponding cache object.
*
* @private
* @param {Mixed} value The value to add to the cache.
*/
function cachePush(value) {
var cache = this.cache,
type = typeof value;
if (type == 'boolean' || value == null) {
cache[value] = true;
} else {
if (type != 'number' && type != 'string') {
type = 'object';
}
var key = type == 'number' ? value : keyPrefix + value,
typeCache = cache[type] || (cache[type] = {});
if (type == 'object') {
if ((typeCache[key] || (typeCache[key] = [])).push(value) == this.array.length) {
cache[type] = false;
}
} else {
typeCache[key] = true;
}
}
}
/**
* Used by `_.max` and `_.min` as the default `callback` when a given
* `collection` is a string value.
*
* @private
* @param {String} value The character to inspect.
* @returns {Number} Returns the code unit of given character.
*/
function charAtCallback(value) {
return value.charCodeAt(0);
}
/**
* Used by `sortBy` to compare transformed `collection` values, stable sorting
* them in ascending order.
*
* @private
* @param {Object} a The object to compare to `b`.
* @param {Object} b The object to compare to `a`.
* @returns {Number} Returns the sort order indicator of `1` or `-1`.
*/
function compareAscending(a, b) {
var ai = a.index,
bi = b.index;
a = a.criteria;
b = b.criteria;
// ensure a stable sort in V8 and other engines
// http://code.google.com/p/v8/issues/detail?id=90
if (a !== b) {
if (a > b || typeof a == 'undefined') {
return 1;
}
if (a < b || typeof b == 'undefined') {
return -1;
}
}
return ai < bi ? -1 : 1;
}
/**
* Creates a cache object to optimize linear searches of large arrays.
*
* @private
* @param {Array} [array=[]] The array to search.
* @returns {Null|Object} Returns the cache object or `null` if caching should not be used.
*/
function createCache(array) {
var index = -1,
length = array.length;
var cache = getObject();
cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false;
var result = getObject();
result.array = array;
result.cache = cache;
result.push = cachePush;
while (++index < length) {
result.push(array[index]);
}
return cache.object === false
? (releaseObject(result), null)
: result;
}
/**
* Used by `template` to escape characters for inclusion in compiled
* string literals.
*
* @private
* @param {String} match The matched character to escape.
* @returns {String} Returns the escaped character.
*/
function escapeStringChar(match) {
return '\\' + stringEscapes[match];
}
/**
* Gets an array from the array pool or creates a new one if the pool is empty.
*
@@ -167,23 +327,17 @@
return objectPool.pop() || {
'args': null,
'array': null,
'arrays': null,
'bottom': null,
'contains': null,
'criteria': null,
'false': null,
'firstArg': null,
'function': null,
'index': null,
'indexOf': null,
'init': null,
'initedArray': null,
'loop': null,
'null': null,
'number': null,
'object': null,
'push': null,
'release': null,
'shadowedProps': null,
'string': null,
'top': null,
@@ -195,6 +349,28 @@
};
}
/**
* Checks if `value` is a DOM node in IE < 9.
*
* @private
* @param {Mixed} value The value to check.
* @returns {Boolean} Returns `true` if the `value` is a DOM node, else `false`.
*/
function isNode(value) {
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
// methods that are `typeof` "string" and still can coerce nodes to strings
return typeof value.toString != 'function' && typeof (value + '') == 'string';
}
/**
* A no-operation function.
*
* @private
*/
function noop() {
// no operation performed
}
/**
* Releases the given `array` back to the array pool.
*
@@ -216,6 +392,10 @@
* @param {Object} [object] The object to release.
*/
function releaseObject(object) {
var cache = object.cache;
if (cache) {
releaseObject(cache);
}
if (objectPool.length == maxPoolSize) {
objectPool.length = maxPoolSize - 1;
}
@@ -223,6 +403,34 @@
objectPool.push(object);
}
/**
* Slices the `collection` from the `start` index up to, but not including,
* the `end` index.
*
* Note: This function is used, instead of `Array#slice`, to support node lists
* in IE < 9 and to ensure dense arrays are returned.
*
* @private
* @param {Array|Object|String} collection The collection to slice.
* @param {Number} start The start index.
* @param {Number} end The end index.
* @returns {Array} Returns the new array.
*/
function slice(array, start, end) {
start || (start = 0);
if (typeof end == 'undefined') {
end = array ? array.length : 0;
}
var index = -1,
length = end - start || 0,
result = Array(length < 0 ? 0 : length);
while (++index < length) {
result[index] = array[start + index];
}
return result;
}
/*--------------------------------------------------------------------------*/
/**
@@ -401,6 +609,19 @@
: new lodashWrapper(value);
}
/**
* A fast path for creating `lodash` wrapper objects.
*
* @private
* @param {Mixed} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance.
*/
function lodashWrapper(value) {
this.__wrapped__ = value;
}
// ensure `new lodashWrapper` is an instance of `lodash`
lodashWrapper.prototype = lodash.prototype;
/**
* An object used to flag environments features.
*
@@ -612,9 +833,9 @@
';\nif (!iterable) return result;\n' +
(obj.top) +
';';
if (obj.arrays) {
if (obj.array) {
__p += '\nvar length = iterable.length; index = -1;\nif (' +
(obj.arrays) +
(obj.array) +
') { ';
if (support.unindexedChars) {
__p += '\n if (isString(iterable)) {\n iterable = iterable.split(\'\')\n } ';
@@ -684,7 +905,7 @@
}
if (obj.arrays || support.nonEnumArgs) {
if (obj.array || support.nonEnumArgs) {
__p += '\n}';
}
__p +=
@@ -712,81 +933,18 @@
var eachIteratorOptions = {
'args': 'collection, callback, thisArg',
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg)",
'arrays': "typeof length == 'number'",
'array': "typeof length == 'number'",
'loop': 'if (callback(iterable[index], index, collection) === false) return result'
};
/** Reusable iterator options for `forIn` and `forOwn` */
var forOwnIteratorOptions = {
'top': 'if (!objectTypes[typeof iterable]) return result;\n' + eachIteratorOptions.top,
'arrays': false
'array': false
};
/*--------------------------------------------------------------------------*/
/**
* A basic version of `_.indexOf` without support for binary searches
* or `fromIndex` constraints.
*
* @private
* @param {Array} array The array to search.
* @param {Mixed} 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`.
*/
function basicIndexOf(array, value, fromIndex) {
var index = (fromIndex || 0) - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* Used by `_.max` and `_.min` as the default `callback` when a given
* `collection` is a string value.
*
* @private
* @param {String} value The character to inspect.
* @returns {Number} Returns the code unit of given character.
*/
function charAtCallback(value) {
return value.charCodeAt(0);
}
/**
* Used by `sortBy` to compare transformed `collection` values, stable sorting
* them in ascending order.
*
* @private
* @param {Object} a The object to compare to `b`.
* @param {Object} b The object to compare to `a`.
* @returns {Number} Returns the sort order indicator of `1` or `-1`.
*/
function compareAscending(a, b) {
var ai = a.index,
bi = b.index;
a = a.criteria;
b = b.criteria;
// ensure a stable sort in V8 and other engines
// http://code.google.com/p/v8/issues/detail?id=90
if (a !== b) {
if (a > b || typeof a == 'undefined') {
return 1;
}
if (a < b || typeof b == 'undefined') {
return -1;
}
}
return ai < bi ? -1 : 1;
}
/**
* Creates a function that, when called, invokes `func` with the `this` binding
* of `thisArg` and prepends any `partialArgs` to the arguments passed to the
@@ -845,115 +1003,12 @@
return bound;
}
/**
* Creates a function optimized to search large arrays for a given `value`,
* starting at `fromIndex`, using strict equality for comparisons, i.e. `===`.
*
* @private
* @param {Array} [array=[]] The array to search.
* @param {Mixed} value The value to search for.
* @returns {Boolean} Returns `true`, if `value` is found, else `false`.
*/
var createCache = (function() {
function basicContains(value) {
return this.indexOf(this.array, value) > -1;
}
function basicPush(value) {
this.array.push(value);
}
function cacheContains(value) {
var cache = this.cache,
type = typeof value;
if (type == 'boolean' || value == null) {
return cache[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)
: !!cache[key];
}
function cachePush(value) {
var cache = this.cache,
type = typeof value;
if (type == 'boolean' || value == null) {
cache[value] = true;
} else {
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;
} else {
cache[key] = true;
}
}
}
function release() {
var cache = this.cache;
if (cache.initedArray) {
releaseArray(this.array);
}
releaseObject(cache);
}
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 compiled iteration functions.
*
* @private
* @param {Object} [options1, options2, ...] The compile options object(s).
* arrays - A string of code to determine if the iterable is an array or array-like.
* array - A string of code to determine if the iterable is an array or array-like.
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
* useKeys - A boolean to specify using `_.keys` for own property iteration.
* args - A string of comma separated arguments the iteration function will accept.
@@ -968,7 +1023,7 @@
// data properties
data.shadowedProps = shadowedProps;
// iterator options
data.arrays = data.bottom = data.loop = data.top = '';
data.array = data.bottom = data.loop = data.top = '';
data.init = 'iterable';
data.useHas = true;
data.useKeys = !!keys;
@@ -1033,18 +1088,6 @@
return htmlEscapes[match];
}
/**
* Used by `template` to escape characters for inclusion in compiled
* string literals.
*
* @private
* @param {String} match The matched character to escape.
* @returns {String} Returns the escaped character.
*/
function escapeStringChar(match) {
return '\\' + stringEscapes[match];
}
/**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
* customized, this method returns the custom method, otherwise it returns
@@ -1058,41 +1101,6 @@
return result;
}
/**
* Checks if `value` is a DOM node in IE < 9.
*
* @private
* @param {Mixed} value The value to check.
* @returns {Boolean} Returns `true` if the `value` is a DOM node, else `false`.
*/
function isNode(value) {
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
// methods that are `typeof` "string" and still can coerce nodes to strings
return typeof value.toString != 'function' && typeof (value + '') == 'string';
}
/**
* A fast path for creating `lodash` wrapper objects.
*
* @private
* @param {Mixed} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance.
*/
function lodashWrapper(value) {
this.__wrapped__ = value;
}
// ensure `new lodashWrapper` is an instance of `lodash`
lodashWrapper.prototype = lodash.prototype;
/**
* A no-operation function.
*
* @private
*/
function noop() {
// no operation performed
}
/**
* Creates a function that juggles arguments, allowing argument overloading
* for `_.flatten` and `_.uniq`, before passing them to the given `func`.
@@ -1156,34 +1164,6 @@
return result === undefined || hasOwnProperty.call(value, result);
}
/**
* Slices the `collection` from the `start` index up to, but not including,
* the `end` index.
*
* Note: This function is used, instead of `Array#slice`, to support node lists
* in IE < 9 and to ensure dense arrays are returned.
*
* @private
* @param {Array|Object|String} collection The collection to slice.
* @param {Number} start The start index.
* @param {Number} end The end index.
* @returns {Array} Returns the new array.
*/
function slice(array, start, end) {
start || (start = 0);
if (typeof end == 'undefined') {
end = array ? array.length : 0;
}
var index = -1,
length = end - start || 0,
result = Array(length < 0 ? 0 : length);
while (++index < length) {
result[index] = array[start + index];
}
return result;
}
/**
* Used by `unescape` to convert HTML entities to characters.
*
@@ -1500,7 +1480,7 @@
* `undefined`, cloning will be handled by the method instead. The `callback`
* is bound to `thisArg` and invoked with one argument; (value).
*
* Note: This function is loosely based on the structured clone algorithm. Functions
* Note: This method is loosely based on the structured clone algorithm. Functions
* and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and
* objects created by constructors other than `Object` are cloned to plain `Object` objects.
* See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
@@ -3657,18 +3637,31 @@
*/
function difference(array) {
var index = -1,
indexOf = getIndexOf(),
length = array ? array.length : 0,
flattened = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),
cache = createCache(flattened),
seen = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),
result = [];
var isLarge = length >= largeArraySize && indexOf === basicIndexOf;
if (isLarge) {
var cache = createCache(seen);
if (cache) {
indexOf = cacheIndexOf;
seen = cache;
} else {
isLarge = false;
}
}
while (++index < length) {
var value = array[index];
if (!cache.contains(value)) {
if (indexOf(seen, value) < 0) {
result.push(value);
}
}
cache.release();
if (isLarge) {
releaseObject(seen);
}
return result;
}
@@ -3972,24 +3965,31 @@
function intersection(array) {
var args = arguments,
argsLength = args.length,
argsIndex = -1,
caches = getArray(),
index = -1,
indexOf = getIndexOf(),
length = array ? array.length : 0,
result = [];
var caches = getArray();
caches[0] = createCache();
result = [],
seen = getArray();
while (++argsIndex < argsLength) {
var value = args[argsIndex];
caches[argsIndex] = indexOf === basicIndexOf &&
(value ? value.length : 0) >= largeArraySize &&
createCache(argsIndex ? args[argsIndex] : seen);
}
outer:
while (++index < length) {
var cache = caches[0],
value = array[index];
var cache = caches[0];
value = array[index];
if (!cache.contains(value)) {
var argsIndex = argsLength;
cache.push(value);
if ((cache ? cacheIndexOf(cache, value) : indexOf(seen, value)) < 0) {
argsIndex = argsLength;
(cache || seen).push(value);
while (--argsIndex) {
cache = caches[argsIndex] || (caches[argsIndex] = createCache(args[argsIndex]));
if (!cache.contains(value)) {
cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) {
continue outer;
}
}
@@ -3997,9 +3997,13 @@
}
}
while (argsLength--) {
caches[argsLength].release();
cache = caches[argsLength];
if (cache) {
releaseObject(cache);
}
}
releaseArray(caches);
releaseArray(seen);
return result;
}
@@ -4371,17 +4375,28 @@
var index = -1,
indexOf = getIndexOf(),
length = array ? array.length : 0,
isLarge = !isSorted && length >= largeArraySize && lodash.indexOf !== indexOf,
result = [],
seen = isLarge ? createCache() : (callback ? getArray() : result);
result = [];
var isLarge = !isSorted && length >= largeArraySize && indexOf === basicIndexOf,
seen = (callback || isLarge) ? getArray() : result;
if (isLarge) {
var cache = createCache(seen);
if (cache) {
indexOf = cacheIndexOf;
seen = cache;
} else {
isLarge = false;
seen = callback ? seen : (releaseArray(seen), result);
}
}
while (++index < length) {
var value = array[index],
computed = callback ? callback(value, index, array) : value;
if (isSorted
? !index || seen[seen.length - 1] !== computed
: (isLarge ? !seen.contains(computed) : indexOf(seen, computed) < 0)
: indexOf(seen, computed) < 0
) {
if (callback || isLarge) {
seen.push(computed);
@@ -4390,7 +4405,8 @@
}
}
if (isLarge) {
seen.release();
releaseArray(seen.array);
releaseObject(seen);
} else if (callback) {
releaseArray(seen);
}
@@ -5114,7 +5130,7 @@
}
/**
* This function returns the first argument passed to it.
* This method returns the first argument passed to it.
*
* @static
* @memberOf _
@@ -5163,7 +5179,7 @@
push.apply(args, arguments);
var result = func.apply(lodash, args);
return (value && typeof value == 'object' && value == result)
return (value && typeof value == 'object' && value === result)
? this
: new lodashWrapper(result);
};