Comparing version 3.3.12 to 4.0.0
{ | ||
"name": "sift", | ||
"description": "mongodb query style array filtering", | ||
"version": "3.3.12", | ||
"version": "4.0.0", | ||
"repository": "crcn/sift.js", | ||
@@ -6,0 +6,0 @@ "author": { |
51
sift.js
@@ -34,4 +34,6 @@ /* | ||
return value.getTime(); | ||
} else if (value instanceof Array) { | ||
} else if (isArray(value)) { | ||
return value.map(comparable); | ||
} else if (value && typeof value.toJSON === 'function') { | ||
return value.toJSON(); | ||
} else { | ||
@@ -43,6 +45,3 @@ return value; | ||
function get(obj, key) { | ||
if (obj.get) { | ||
return obj.get(key); | ||
} | ||
return obj[key]; | ||
return isFunction(obj.get) ? obj.get(key) : obj[key]; | ||
} | ||
@@ -84,3 +83,3 @@ | ||
var operator = { | ||
var OPERATORS = { | ||
@@ -104,10 +103,2 @@ /** | ||
$or: function(a, b) { | ||
for (var i = 0, n = a.length; i < n; i++) if (validate(get(a, i), b)) return true; | ||
return false; | ||
}, | ||
/** | ||
*/ | ||
$gt: or(function(a, b) { | ||
@@ -189,3 +180,3 @@ return sift.compare(comparable(b), a) > 0; | ||
return Boolean(!!~a.indexOf(comparable(b))); | ||
return !!~a.indexOf(comparableB); | ||
} | ||
@@ -200,3 +191,3 @@ | ||
$nin: function(a, b) { | ||
return !operator.$in(a, b); | ||
return !OPERATORS.$in(a, b); | ||
}, | ||
@@ -222,3 +213,3 @@ | ||
$all: function(a, b) { | ||
return operator.$and(a, b); | ||
return OPERATORS.$and(a, b); | ||
}, | ||
@@ -236,10 +227,12 @@ | ||
$or: function(a, b) { | ||
for (var i = 0, n = a.length; i < n; i++) if (validate(get(a, i), b)) return true; | ||
return false; | ||
}, | ||
/** | ||
*/ | ||
$nor: function(a, b) { | ||
// todo - this suffice? return !operator.$in(a) | ||
for (var i = 0, n = a.length; i < n; i++) { | ||
if (validate(get(a, i), b)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
return !OPERATORS.$or(a, b); | ||
}, | ||
@@ -466,3 +459,3 @@ | ||
function isVanillaObject(value) { | ||
return String(value.constructor) === 'Object' || String(value.constructor).replace(/[\r\n\s\t]/g, '') === 'functionObject(){[nativecode]}'; | ||
return value && value.constructor === Object; | ||
} | ||
@@ -486,5 +479,5 @@ | ||
if (operator[key]) { | ||
if (OPERATORS[key]) { | ||
if (prepare[key]) a = prepare[key](a, query); | ||
validators.push(createValidator(comparable(a), operator[key])); | ||
validators.push(createValidator(comparable(a), OPERATORS[key])); | ||
} else { | ||
@@ -500,3 +493,3 @@ | ||
return validators.length === 1 ? validators[0] : createValidator(validators, operator.$and); | ||
return validators.length === 1 ? validators[0] : createValidator(validators, OPERATORS.$and); | ||
} | ||
@@ -551,3 +544,3 @@ | ||
if (key.charCodeAt(0) === 36) { | ||
operator[key] = plugin[key]; | ||
OPERATORS[key] = plugin[key]; | ||
} | ||
@@ -554,0 +547,0 @@ } |
@@ -26,4 +26,3 @@ var assert = require('assert'); | ||
// object is not exact - there is no match here unless ObjectID is a comparable. | ||
[ObjectID('54dd5546b1d296a54d152e84'),[ObjectID(),ObjectID('54dd5546b1d296a54d152e84')],[]], | ||
[ObjectID('54dd5546b1d296a54d152e84'),[ObjectID(),ObjectID('54dd5546b1d296a54d152e84')],[ObjectID('54dd5546b1d296a54d152e84')]], | ||
@@ -30,0 +29,0 @@ // $ne |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149441
2047