mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Update docs and builds.
Former-commit-id: 1f7bfb21276f1c871f4e6ce8a6bf168784509994
This commit is contained in:
186
dist/lodash.compat.js
vendored
186
dist/lodash.compat.js
vendored
@@ -506,7 +506,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'
|
||||
};
|
||||
@@ -650,64 +650,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.
|
||||
*
|
||||
@@ -750,13 +692,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
|
||||
);
|
||||
}
|
||||
@@ -1130,7 +1072,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' +
|
||||
'}'
|
||||
@@ -1191,9 +1133,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;
|
||||
}
|
||||
@@ -1504,8 +1448,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
|
||||
*
|
||||
@@ -1534,7 +1478,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;
|
||||
@@ -1999,7 +1946,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];
|
||||
}
|
||||
@@ -2089,7 +2036,7 @@
|
||||
result = {};
|
||||
|
||||
if (isFunc) {
|
||||
callback = createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
} else {
|
||||
var props = concat.apply(arrayRef, arguments);
|
||||
}
|
||||
@@ -2191,7 +2138,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;
|
||||
@@ -2347,7 +2294,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) + '';
|
||||
@@ -2399,7 +2346,7 @@
|
||||
*/
|
||||
function every(collection, callback, thisArg) {
|
||||
var result = true;
|
||||
callback = createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -2460,7 +2407,7 @@
|
||||
*/
|
||||
function filter(collection, callback, thisArg) {
|
||||
var result = [];
|
||||
callback = createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -2527,7 +2474,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)) {
|
||||
@@ -2612,7 +2559,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) + '';
|
||||
@@ -2700,7 +2647,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);
|
||||
@@ -2769,7 +2716,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);
|
||||
@@ -2838,7 +2785,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);
|
||||
@@ -2905,7 +2852,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,
|
||||
@@ -2957,7 +2904,7 @@
|
||||
} else if (noCharByIndex && isString(collection)) {
|
||||
iterable = collection.split('');
|
||||
}
|
||||
callback = createCallback(callback, thisArg, 4);
|
||||
callback = lodash.createCallback(callback, thisArg, 4);
|
||||
forEach(collection, function(value, index, collection) {
|
||||
index = props ? props[--length] : --length;
|
||||
accumulator = noaccum
|
||||
@@ -3007,7 +2954,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);
|
||||
});
|
||||
@@ -3109,7 +3056,7 @@
|
||||
*/
|
||||
function some(collection, callback, thisArg) {
|
||||
var result;
|
||||
callback = createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
|
||||
if (isArray(collection)) {
|
||||
var index = -1,
|
||||
@@ -3168,7 +3115,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),
|
||||
@@ -3358,7 +3305,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++;
|
||||
}
|
||||
@@ -3515,7 +3462,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++;
|
||||
}
|
||||
@@ -3639,7 +3586,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++;
|
||||
}
|
||||
@@ -3799,7 +3746,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++;
|
||||
}
|
||||
@@ -3862,7 +3809,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) {
|
||||
@@ -3955,7 +3902,7 @@
|
||||
}
|
||||
if (callback != null) {
|
||||
seen = [];
|
||||
callback = createCallback(callback, thisArg);
|
||||
callback = lodash.createCallback(callback, thisArg);
|
||||
}
|
||||
while (++index < length) {
|
||||
var value = array[index],
|
||||
@@ -4239,6 +4186,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
|
||||
@@ -5013,6 +5020,7 @@
|
||||
lodash.compact = compact;
|
||||
lodash.compose = compose;
|
||||
lodash.countBy = countBy;
|
||||
lodash.createCallback = createCallback;
|
||||
lodash.debounce = debounce;
|
||||
lodash.defaults = defaults;
|
||||
lodash.defer = defer;
|
||||
|
||||
Reference in New Issue
Block a user