mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Add unofficial _.where like support for methods like _.find. [closes #159]
Former-commit-id: c6106035af3f3d676cbd3f0a5c785b2c00ad1e9d
This commit is contained in:
39
build.js
39
build.js
@@ -76,23 +76,23 @@
|
|||||||
'compact': [],
|
'compact': [],
|
||||||
'compose': [],
|
'compose': [],
|
||||||
'contains': ['indexOf', 'isString'],
|
'contains': ['indexOf', 'isString'],
|
||||||
'countBy': ['forEach'],
|
'countBy': ['forEach', 'keys'],
|
||||||
'debounce': [],
|
'debounce': [],
|
||||||
'defaults': ['isArguments'],
|
'defaults': ['isArguments'],
|
||||||
'defer': [],
|
'defer': [],
|
||||||
'delay': [],
|
'delay': [],
|
||||||
'difference': ['indexOf'],
|
'difference': ['indexOf'],
|
||||||
'escape': [],
|
'escape': [],
|
||||||
'every': ['isArray'],
|
'every': ['isArray', 'keys'],
|
||||||
'filter': ['isArray'],
|
'filter': ['isArray', 'keys'],
|
||||||
'find': ['forEach'],
|
'find': ['forEach', 'keys'],
|
||||||
'first': [],
|
'first': [],
|
||||||
'flatten': ['isArray'],
|
'flatten': ['isArray'],
|
||||||
'forEach': ['identity', 'isArguments', 'isArray', 'isString'],
|
'forEach': ['identity', 'isArguments', 'isArray', 'isString'],
|
||||||
'forIn': ['identity', 'isArguments'],
|
'forIn': ['identity', 'isArguments'],
|
||||||
'forOwn': ['identity', 'isArguments'],
|
'forOwn': ['identity', 'isArguments'],
|
||||||
'functions': ['forIn', 'isFunction'],
|
'functions': ['forIn', 'isFunction'],
|
||||||
'groupBy': ['forEach'],
|
'groupBy': ['forEach', 'keys'],
|
||||||
'has': [],
|
'has': [],
|
||||||
'identity': [],
|
'identity': [],
|
||||||
'indexOf': ['sortedIndex'],
|
'indexOf': ['sortedIndex'],
|
||||||
@@ -120,11 +120,11 @@
|
|||||||
'keys': ['forOwn', 'isArguments', 'isObject'],
|
'keys': ['forOwn', 'isArguments', 'isObject'],
|
||||||
'last': [],
|
'last': [],
|
||||||
'lastIndexOf': [],
|
'lastIndexOf': [],
|
||||||
'map': ['isArray'],
|
'map': ['isArray', 'keys'],
|
||||||
'max': ['isArray', 'isString'],
|
'max': ['isArray', 'isString', 'keys'],
|
||||||
'memoize': [],
|
'memoize': [],
|
||||||
'merge': ['forOwn', 'isArray', 'isPlainObject'],
|
'merge': ['forOwn', 'isArray', 'isPlainObject'],
|
||||||
'min': ['isArray', 'isString'],
|
'min': ['isArray', 'isString', 'keys'],
|
||||||
'mixin': ['forEach', 'forOwn', 'functions'],
|
'mixin': ['forEach', 'forOwn', 'functions'],
|
||||||
'noConflict': [],
|
'noConflict': [],
|
||||||
'object': [],
|
'object': [],
|
||||||
@@ -136,16 +136,16 @@
|
|||||||
'pluck': ['map'],
|
'pluck': ['map'],
|
||||||
'random': [],
|
'random': [],
|
||||||
'range': [],
|
'range': [],
|
||||||
'reduce': ['isArray'],
|
'reduce': ['isArray', 'keys'],
|
||||||
'reduceRight': ['forEach', 'isString', 'keys'],
|
'reduceRight': ['forEach', 'isString', 'keys'],
|
||||||
'reject': ['filter'],
|
'reject': ['filter'],
|
||||||
'rest': [],
|
'rest': [],
|
||||||
'result': ['isFunction'],
|
'result': ['isFunction'],
|
||||||
'shuffle': ['forEach'],
|
'shuffle': ['forEach'],
|
||||||
'size': ['keys'],
|
'size': ['keys'],
|
||||||
'some': ['isArray'],
|
'some': ['isArray', 'keys'],
|
||||||
'sortBy': ['forEach'],
|
'sortBy': ['forEach', 'keys'],
|
||||||
'sortedIndex': ['identity'],
|
'sortedIndex': ['identity', 'keys'],
|
||||||
'tap': ['mixin'],
|
'tap': ['mixin'],
|
||||||
'template': ['defaults', 'escape', 'keys', 'values'],
|
'template': ['defaults', 'escape', 'keys', 'values'],
|
||||||
'throttle': [],
|
'throttle': [],
|
||||||
@@ -153,11 +153,11 @@
|
|||||||
'toArray': ['isString', 'values'],
|
'toArray': ['isString', 'values'],
|
||||||
'unescape': [],
|
'unescape': [],
|
||||||
'union': ['uniq'],
|
'union': ['uniq'],
|
||||||
'uniq': ['identity', 'indexOf'],
|
'uniq': ['identity', 'indexOf', 'keys'],
|
||||||
'uniqueId': [],
|
'uniqueId': [],
|
||||||
'value': ['mixin'],
|
'value': ['mixin'],
|
||||||
'values': ['keys'],
|
'values': ['keys'],
|
||||||
'where': ['filter', 'keys'],
|
'where': ['filter'],
|
||||||
'without': ['indexOf'],
|
'without': ['indexOf'],
|
||||||
'wrap': [],
|
'wrap': [],
|
||||||
'zip': ['max', 'pluck'],
|
'zip': ['max', 'pluck'],
|
||||||
@@ -1336,6 +1336,12 @@
|
|||||||
exposeForOwn = !isUnderscore,
|
exposeForOwn = !isUnderscore,
|
||||||
exposeIsPlainObject = !isUnderscore;
|
exposeIsPlainObject = !isUnderscore;
|
||||||
|
|
||||||
|
// flags used to specify export options
|
||||||
|
var isAMD = exportsOptions.indexOf('amd') > -1,
|
||||||
|
isCommonJS = exportsOptions.indexOf('commonjs') > -1,
|
||||||
|
isGlobal = exportsOptions.indexOf('global') > -1,
|
||||||
|
isNode = exportsOptions.indexOf('node') > -1;
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// names of methods to include in the build
|
// names of methods to include in the build
|
||||||
@@ -2004,11 +2010,6 @@
|
|||||||
|
|
||||||
// customize Lo-Dash's export bootstrap
|
// customize Lo-Dash's export bootstrap
|
||||||
(function() {
|
(function() {
|
||||||
var isAMD = exportsOptions.indexOf('amd') > -1,
|
|
||||||
isCommonJS = exportsOptions.indexOf('commonjs') > -1,
|
|
||||||
isGlobal = exportsOptions.indexOf('global') > -1,
|
|
||||||
isNode = exportsOptions.indexOf('node') > -1;
|
|
||||||
|
|
||||||
if (!isAMD) {
|
if (!isAMD) {
|
||||||
source = source.replace(/(?: *\/\/.*\n)*( *)if *\(typeof +define[\s\S]+?else /, '$1');
|
source = source.replace(/(?: *\/\/.*\n)*( *)if *\(typeof +define[\s\S]+?else /, '$1');
|
||||||
}
|
}
|
||||||
|
|||||||
30
lodash.js
30
lodash.js
@@ -633,9 +633,23 @@
|
|||||||
if (!func) {
|
if (!func) {
|
||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
if (typeof func != 'function') {
|
var type = typeof func;
|
||||||
|
if (type != 'function') {
|
||||||
|
if (type != 'object') {
|
||||||
|
return function(object) {
|
||||||
|
return object[func];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var props = keys(func);
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return object[func];
|
var length = props.length;
|
||||||
|
while (length--) {
|
||||||
|
var result = object[props[length]] === func[props[length]];
|
||||||
|
if (!result) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !!result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (typeof thisArg != 'undefined') {
|
if (typeof thisArg != 'undefined') {
|
||||||
@@ -2748,17 +2762,7 @@
|
|||||||
* // => [{ 'name': 'moe', 'age': 40 }]
|
* // => [{ 'name': 'moe', 'age': 40 }]
|
||||||
*/
|
*/
|
||||||
function where(collection, properties) {
|
function where(collection, properties) {
|
||||||
var props = keys(properties);
|
return filter(collection, properties);
|
||||||
return filter(collection, function(object) {
|
|
||||||
var length = props.length;
|
|
||||||
while (length--) {
|
|
||||||
var result = object[props[length]] === properties[props[length]];
|
|
||||||
if (!result) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !!result;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user