From a68337a900e7fa72290ae95fda6c943884632be7 Mon Sep 17 00:00:00 2001 From: Ben Ward Date: Mon, 28 Nov 2011 21:18:15 -0800 Subject: [PATCH] Rewrote excluded() to allow matching by RegExp, make whole function more graceful in handling of arrays, too. --- src/loadbuilder.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/loadbuilder.js b/src/loadbuilder.js index b3d83bf..034a95d 100644 --- a/src/loadbuilder.js +++ b/src/loadbuilder.js @@ -37,23 +37,33 @@ function isProvide(node) { return node[0] == 'call' && node[1] && node[1][1] == 'provide'; } +// Better typeof by Angus. See: http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/ +var toType = function(obj) { + return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() +} + function excluded(item, loadbuilder) { - var excluded = false; - loadbuilder.options.exclude.forEach(function(excl) { - if (typeof(excl)=='string' && excl==item) { - excluded = true; - return; + + function matchExclusion (pattern, item) { + var i, l, match = false; + + if (toType(pattern) == 'string' && pattern == item) { + return true; } - if (typeof(excl)=='object') { - excl.forEach(function(exclitem) { - if (exclitem == item) { - excluded = true; - return; + if (toType(pattern) == 'regexp' && pattern.test(item)) { + return true; + } + if (toType(pattern) == 'array') { + for (i = 0, l = pattern.length; i < l; i++) { + match = matchExclusion (pattern[i], item); + if (match) { + break; } - }); + } + return match; } - }); - return excluded; + } + return matchExclusion (loadbuilder.options.exclude, item); }