|
|
|
@ -302,26 +302,38 @@ matcherFunctions.$eq = function (objValue, value) { |
|
|
|
|
* @param {Object} query |
|
|
|
|
*/ |
|
|
|
|
function match (obj, query) { |
|
|
|
|
var match = true |
|
|
|
|
, objValue, arrayMatch |
|
|
|
|
, i, k; |
|
|
|
|
var queryKeys = Object.keys(query) |
|
|
|
|
, i |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < queryKeys.length; i += 1) { |
|
|
|
|
if (!matchQueryKey(obj, query, queryKeys[i])) { return false; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Object.keys(query).forEach(function (k) { |
|
|
|
|
objValue = getDotValue(obj, k); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Match a specific key of a given query |
|
|
|
|
*/ |
|
|
|
|
function matchQueryKey (obj, query, queryKey) { |
|
|
|
|
var objValue = getDotValue(obj, queryKey) |
|
|
|
|
, queryValue = query[queryKey] |
|
|
|
|
, i |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
if (util.isArray(objValue)) { |
|
|
|
|
arrayMatch = false; // We only need one match in the array for a success
|
|
|
|
|
for (i = 0; i < objValue.length; i += 1) { |
|
|
|
|
if (matcherFunctions.$eq(objValue[i], query[k])) { arrayMatch = true; } |
|
|
|
|
if (matcherFunctions.$eq(objValue[i], queryValue)) { return true; } |
|
|
|
|
} |
|
|
|
|
match = match && arrayMatch; |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
if (!matcherFunctions.$eq(objValue, query[k])) { match = false; } |
|
|
|
|
if (!matcherFunctions.$eq(objValue, queryValue)) { return false; } |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return match; |
|
|
|
|
}; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Interface
|
|
|
|
|