From 9763b6e2cf9ee8064974670c2d643cf536b2c7be Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 30 Jan 2013 00:39:33 -0800 Subject: [PATCH] Update build to add `_.findWhere` as an alias of `_.find` for the `underscore` build. Former-commit-id: 0b772c30749c9af6ddc20b7b786f282ea93b63ce --- build.js | 20 +++++++++++++++++--- build/pre-compile.js | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/build.js b/build.js index 21aa482a7..0ef6d0a7e 100755 --- a/build.js +++ b/build.js @@ -42,7 +42,10 @@ 'select': 'filter', 'tail': 'rest', 'take': 'first', - 'unique': 'uniq' + 'unique': 'uniq', + + // method used by the `backbone` and `underscore` builds + 'findWhere': 'find' }; /** Used to associate real names with their aliases */ @@ -51,7 +54,7 @@ 'contains': ['include'], 'every': ['all'], 'filter': ['select'], - 'find': ['detect'], + 'find': ['detect', 'findWhere'], 'first': ['head', 'take'], 'forEach': ['each'], 'functions': ['methods'], @@ -248,7 +251,6 @@ 'forOwn', 'isPlainObject', 'merge', - 'partial', 'partialRight' ])); @@ -1850,6 +1852,13 @@ ' }' ].join('\n')); + // replace `_.where` + source = replaceFunction(source, 'where', [ + ' function where(collection, properties, first) {', + ' return (first ? find : filter)(collection, properties);', + ' }' + ].join('\n')); + // replace `_.without` source = replaceFunction(source, 'without', [ ' function without(array) {', @@ -1867,6 +1876,11 @@ ' }' ].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` source = source.replace(matchFunction(source, 'createCallback'), function(match) { return match.replace(/isEqual\(([^,]+), *([^,]+)[^)]+\)/, '$1 === $2'); diff --git a/build/pre-compile.js b/build/pre-compile.js index ec3ae9454..e727e3dfc 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -193,7 +193,8 @@ // properties used by the `backbone` and `underscore` builds '__chain__', - 'chain' + 'chain', + 'findWhere' ]; /*--------------------------------------------------------------------------*/