Permalink
Browse files

Pre-bake value testing functions for object matching.

  • Loading branch information...
1 parent 941a497 commit 03cd89474e525bc72b3f2a4a3ba4b7f51bdbb53b @timoxley timoxley committed Dec 16, 2012
Showing with 8 additions and 10 deletions.
  1. +8 −10 index.js
View
@@ -81,19 +81,17 @@ function stringToFunction(str) {
*/
function objectToFunction(obj) {
+ var match = {}
+ for (var key in obj) {
+ match[key] = typeof obj[key] === 'string'
+ ? defaultToFunction(obj[key])
+ : toFunction(obj[key])
+ }
return function(val){
if (typeof val !== 'object') return false;
- for (var key in obj) {
+ for (var key in match) {
if (!(key in val)) return false;
- switch ({}.toString.call(obj[key])) {
- case '[object Object]':
- case '[object RegExp]':
- case '[object Function]':
- if (!toFunction(obj[key])(val[key])) return false;
- break;
- default:
- if (obj[key] !== val[key]) return false;
- }
+ if (!match[key](val[key])) return false;
}
return true;
}

0 comments on commit 03cd894

Please sign in to comment.