Update build to add _.findWhere as an alias of _.find for the underscore build.

Former-commit-id: 0b772c30749c9af6ddc20b7b786f282ea93b63ce
This commit is contained in:
John-David Dalton
2013-01-30 00:39:33 -08:00
parent 812b848daf
commit 9763b6e2cf
2 changed files with 19 additions and 4 deletions

View File

@@ -42,7 +42,10 @@
'select': 'filter', 'select': 'filter',
'tail': 'rest', 'tail': 'rest',
'take': 'first', 'take': 'first',
'unique': 'uniq' 'unique': 'uniq',
// method used by the `backbone` and `underscore` builds
'findWhere': 'find'
}; };
/** Used to associate real names with their aliases */ /** Used to associate real names with their aliases */
@@ -51,7 +54,7 @@
'contains': ['include'], 'contains': ['include'],
'every': ['all'], 'every': ['all'],
'filter': ['select'], 'filter': ['select'],
'find': ['detect'], 'find': ['detect', 'findWhere'],
'first': ['head', 'take'], 'first': ['head', 'take'],
'forEach': ['each'], 'forEach': ['each'],
'functions': ['methods'], 'functions': ['methods'],
@@ -248,7 +251,6 @@
'forOwn', 'forOwn',
'isPlainObject', 'isPlainObject',
'merge', 'merge',
'partial',
'partialRight' 'partialRight'
])); ]));
@@ -1850,6 +1852,13 @@
' }' ' }'
].join('\n')); ].join('\n'));
// replace `_.where`
source = replaceFunction(source, 'where', [
' function where(collection, properties, first) {',
' return (first ? find : filter)(collection, properties);',
' }'
].join('\n'));
// replace `_.without` // replace `_.without`
source = replaceFunction(source, 'without', [ source = replaceFunction(source, 'without', [
' function without(array) {', ' function without(array) {',
@@ -1867,6 +1876,11 @@
' }' ' }'
].join('\n')); ].join('\n'));
// add `_.findWhere` alias of `_.find`
source = source.replace(getMethodAssignments(source), function(match) {
return match.replace(/^( *)lodash.find *=.+/m, '$&\n$1lodash.findWhere = find;');
});
// remove `_.isEqual` use from `createCallback` // remove `_.isEqual` use from `createCallback`
source = source.replace(matchFunction(source, 'createCallback'), function(match) { source = source.replace(matchFunction(source, 'createCallback'), function(match) {
return match.replace(/isEqual\(([^,]+), *([^,]+)[^)]+\)/, '$1 === $2'); return match.replace(/isEqual\(([^,]+), *([^,]+)[^)]+\)/, '$1 === $2');

View File

@@ -193,7 +193,8 @@
// properties used by the `backbone` and `underscore` builds // properties used by the `backbone` and `underscore` builds
'__chain__', '__chain__',
'chain' 'chain',
'findWhere'
]; ];
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/