diff --git a/lib/common.coffee b/lib/common.coffee index ab753bf..7edf83c 100644 --- a/lib/common.coffee +++ b/lib/common.coffee @@ -63,19 +63,6 @@ exports.getParamValueFromPath = (obj, path) -> return undefined -exports.matchType = (src, dst) -> - switch typeOf(src) - when STRING_TYPE - String(dst) - when NUMBER_TYPE - Number(dst) - when BOOLEAN_TYPE - v = String(dst).trim().toLowerCase() - v == 'true' or v == 'on' or v == 'yes' or v == '1' - else - dst - - pathOverlap = (a, b, start) -> if a.length == b.length res = 3 diff --git a/lib/query.coffee b/lib/query.coffee index 3dd89fa..74a0963 100644 --- a/lib/query.coffee +++ b/lib/query.coffee @@ -244,10 +244,28 @@ test = (params, query) -> return true +matchType = (src, dst) -> + if typeof src is 'string' + return String(dst) + else if typeof src is 'number' + if +dst == parseFloat(dst) + return +dst + else if not isNaN(Date.parse(dst)) + return Date.parse(dst) + else if typeof src is 'boolean' + v = String(dst).trim() + if v is 'true' or v is 'TRUE' or v is 'True' or v is '1' + return true + else if v is 'false' or v is 'FALSE' or v is 'False' or v is '0' + return false + + return dst + + testFilter = (obj, filter) -> for k, v of filter [param, op] = k.split(/([^a-zA-Z0-9\-\_\.].*)/, 2) - val = common.matchType(obj[param], v) + val = matchType(obj[param], v) switch op when '=', undefined return false if obj[param] != val