Update docs and builds.

Former-commit-id: 1f7bfb21276f1c871f4e6ce8a6bf168784509994
This commit is contained in:
John-David Dalton
2013-03-03 20:12:06 -08:00
parent 9638c393bb
commit d88da3589d
8 changed files with 479 additions and 440 deletions

186
dist/lodash.js vendored
View File

@@ -388,7 +388,7 @@
/** Reusable iterator options shared by `each`, `forIn`, and `forOwn` */
var eachIteratorOptions = {
'args': 'collection, callback, thisArg',
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)",
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg)",
'arrays': "typeof length == 'number'",
'loop': 'if (callback(iterable[index], index, collection) === false) return result'
};
@@ -532,64 +532,6 @@
return bound;
}
/**
* Produces a callback 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`.
*
* @private
* @param {Mixed} [func=identity] The value to convert to a callback.
* @param {Mixed} [thisArg] The `this` binding of the created callback.
* @param {Number} [argCount=3] The number of arguments the callback accepts.
* @returns {Function} Returns a callback function.
*/
function createCallback(func, thisArg, argCount) {
if (func == null) {
return identity;
}
var type = typeof func;
if (type != 'function') {
if (type != 'object') {
return function(object) {
return object[func];
};
}
var props = keys(func);
return function(object) {
var length = props.length,
result = false;
while (length--) {
if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) {
break;
}
}
return result;
};
}
if (typeof thisArg != 'undefined') {
if (argCount === 1) {
return function(value) {
return func.call(thisArg, value);
};
}
if (argCount === 2) {
return function(a, b) {
return func.call(thisArg, a, b);
};
}
if (argCount === 4) {
return function(accumulator, value, index, collection) {
return func.call(thisArg, accumulator, value, index, collection);
};
}
return function(value, index, collection) {
return func.call(thisArg, value, index, collection);
};
}
return func;
}
/**
* Creates compiled iteration functions.
*
@@ -627,13 +569,13 @@
// create the function factory
var factory = Function(
'createCallback, hasOwnProperty, isArguments, isArray, isString, ' +
'hasOwnProperty, isArguments, isArray, isString, lodash, ' +
'objectTypes, nativeKeys',
'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
);
// return the compiled function
return factory(
createCallback, hasOwnProperty, isArguments, isArray, isString,
hasOwnProperty, isArguments, isArray, isString, lodash,
objectTypes, nativeKeys
);
}
@@ -987,7 +929,7 @@
defaultsIteratorOptions.top.replace(';',
';\n' +
"if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {\n" +
' var callback = createCallback(args[--argsLength - 1], args[argsLength--], 2);\n' +
' var callback = lodash.createCallback(args[--argsLength - 1], args[argsLength--], 2);\n' +
"} else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {\n" +
' callback = args[--argsLength];\n' +
'}'
@@ -1048,9 +990,11 @@
deep = false;
}
if (typeof callback == 'function') {
callback = typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg, 1);
result = callback(result);
callback = (typeof thisArg == 'undefined')
? callback
: lodash.createCallback(callback, thisArg, 1);
result = callback(result);
if (typeof result != 'undefined') {
return result;
}
@@ -1361,8 +1305,8 @@
* @param {Mixed} b The other value to compare.
* @param {Function} [callback] The function to customize comparing values.
* @param {Mixed} [thisArg] The `this` binding of `callback`.
* @param- {Object} [stackA=[]] Internally used track traversed `a` objects.
* @param- {Object} [stackB=[]] Internally used track traversed `b` objects.
* @param- {Array} [stackA=[]] Internally used track traversed `a` objects.
* @param- {Array} [stackB=[]] Internally used track traversed `b` objects.
* @returns {Boolean} Returns `true`, if the values are equivalent, else `false`.
* @example
*
@@ -1391,7 +1335,10 @@
// used to indicate that when comparing objects, `a` has at least the properties of `b`
var whereIndicator = callback === indicatorObject;
if (callback && !whereIndicator) {
callback = typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg, 2);
callback = (typeof thisArg == 'undefined')
? callback
: lodash.createCallback(callback, thisArg, 2);
var result = callback(a, b);
if (typeof result != 'undefined') {
return !!result;
@@ -1850,7 +1797,7 @@
length = args.length;
}
if (length > 3 && typeof args[length - 2] == 'function') {
callback = createCallback(args[--length - 1], args[length--], 2);
callback = lodash.createCallback(args[--length - 1], args[length--], 2);
} else if (length > 2 && typeof args[length - 1] == 'function') {
callback = args[--length];
}
@@ -1940,7 +1887,7 @@
result = {};
if (isFunc) {
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
} else {
var props = concat.apply(arrayRef, arguments);
}
@@ -2042,7 +1989,7 @@
}
}
} else {
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
forIn(object, function(value, key, object) {
if (callback(value, key, object)) {
result[key] = value;
@@ -2195,7 +2142,7 @@
*/
function countBy(collection, callback, thisArg) {
var result = {};
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) {
key = callback(value, key, collection) + '';
@@ -2247,7 +2194,7 @@
*/
function every(collection, callback, thisArg) {
var result = true;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
if (isArray(collection)) {
var index = -1,
@@ -2308,7 +2255,7 @@
*/
function filter(collection, callback, thisArg) {
var result = [];
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
if (isArray(collection)) {
var index = -1,
@@ -2375,7 +2322,7 @@
*/
function find(collection, callback, thisArg) {
var result;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, index, collection) {
if (callback(value, index, collection)) {
@@ -2460,7 +2407,7 @@
*/
function groupBy(collection, callback, thisArg) {
var result = {};
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) {
key = callback(value, key, collection) + '';
@@ -2548,7 +2495,7 @@
length = collection ? collection.length : 0,
result = Array(typeof length == 'number' ? length : 0);
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
if (isArray(collection)) {
while (++index < length) {
result[index] = callback(collection[index], index, collection);
@@ -2617,7 +2564,7 @@
} else {
callback = (!callback && isString(collection))
? charAtCallback
: createCallback(callback, thisArg);
: lodash.createCallback(callback, thisArg);
each(collection, function(value, index, collection) {
var current = callback(value, index, collection);
@@ -2686,7 +2633,7 @@
} else {
callback = (!callback && isString(collection))
? charAtCallback
: createCallback(callback, thisArg);
: lodash.createCallback(callback, thisArg);
each(collection, function(value, index, collection) {
var current = callback(value, index, collection);
@@ -2753,7 +2700,7 @@
*/
function reduce(collection, callback, accumulator, thisArg) {
var noaccum = arguments.length < 3;
callback = createCallback(callback, thisArg, 4);
callback = lodash.createCallback(callback, thisArg, 4);
if (isArray(collection)) {
var index = -1,
@@ -2803,7 +2750,7 @@
var props = keys(collection);
length = props.length;
}
callback = createCallback(callback, thisArg, 4);
callback = lodash.createCallback(callback, thisArg, 4);
forEach(collection, function(value, index, collection) {
index = props ? props[--length] : --length;
accumulator = noaccum
@@ -2853,7 +2800,7 @@
* // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }]
*/
function reject(collection, callback, thisArg) {
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
return filter(collection, function(value, index, collection) {
return !callback(value, index, collection);
});
@@ -2955,7 +2902,7 @@
*/
function some(collection, callback, thisArg) {
var result;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
if (isArray(collection)) {
var index = -1,
@@ -3014,7 +2961,7 @@
length = collection ? collection.length : 0,
result = Array(typeof length == 'number' ? length : 0);
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
forEach(collection, function(value, key, collection) {
result[++index] = {
'criteria': callback(value, key, collection),
@@ -3202,7 +3149,7 @@
if (typeof callback != 'number' && callback != null) {
var index = -1;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
while (++index < length && callback(array[index], index, array)) {
n++;
}
@@ -3359,7 +3306,7 @@
if (typeof callback != 'number' && callback != null) {
var index = length;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
while (index-- && callback(array[index], index, array)) {
n++;
}
@@ -3483,7 +3430,7 @@
if (typeof callback != 'number' && callback != null) {
var index = length;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
while (index-- && callback(array[index], index, array)) {
n++;
}
@@ -3643,7 +3590,7 @@
index = -1,
length = array ? array.length : 0;
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
while (++index < length && callback(array[index], index, array)) {
n++;
}
@@ -3706,7 +3653,7 @@
high = array ? array.length : low;
// explicitly reference `identity` for better inlining in Firefox
callback = callback ? createCallback(callback, thisArg, 1) : identity;
callback = callback ? lodash.createCallback(callback, thisArg, 1) : identity;
value = callback(value);
while (low < high) {
@@ -3799,7 +3746,7 @@
}
if (callback != null) {
seen = [];
callback = createCallback(callback, thisArg);
callback = lodash.createCallback(callback, thisArg);
}
while (++index < length) {
var value = array[index],
@@ -4083,6 +4030,66 @@
};
}
/**
* Produces a callback 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`.
*
* @static
* @memberOf _
* @category Functions
* @param {Mixed} [func=identity] The value to convert to a callback.
* @param {Mixed} [thisArg] The `this` binding of the created callback.
* @param {Number} [argCount=3] The number of arguments the callback accepts.
* @returns {Function} Returns a callback function.
*/
function createCallback(func, thisArg, argCount) {
if (func == null) {
return identity;
}
var type = typeof func;
if (type != 'function') {
if (type != 'object') {
return function(object) {
return object[func];
};
}
var props = keys(func);
return function(object) {
var length = props.length,
result = false;
while (length--) {
if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) {
break;
}
}
return result;
};
}
if (typeof thisArg != 'undefined') {
if (argCount === 1) {
return function(value) {
return func.call(thisArg, value);
};
}
if (argCount === 2) {
return function(a, b) {
return func.call(thisArg, a, b);
};
}
if (argCount === 4) {
return function(accumulator, value, index, collection) {
return func.call(thisArg, accumulator, value, index, collection);
};
}
return function(value, index, collection) {
return func.call(thisArg, value, index, collection);
};
}
return func;
}
/**
* Creates a function that will delay the execution of `func` until after
* `wait` milliseconds have elapsed since the last time it was invoked. Pass
@@ -4857,6 +4864,7 @@
lodash.compact = compact;
lodash.compose = compose;
lodash.countBy = countBy;
lodash.createCallback = createCallback;
lodash.debounce = debounce;
lodash.defaults = defaults;
lodash.defer = defer;