Comparing version 2.0.4 to 2.0.5
{ | ||
"name": "sift", | ||
"description": "mongodb query style array filtering", | ||
"version": "2.0.4", | ||
"repository": {}, | ||
"version": "2.0.5", | ||
"repository": "crcn/sift.js", | ||
"author": { | ||
"name": "Craig Condon", | ||
"email": "craig.j.condon@gmail.com", | ||
"url": "http://crcn.io" | ||
}, | ||
"license": "MIT", | ||
"engines": {}, | ||
@@ -7,0 +13,0 @@ "dependencies": {}, |
@@ -310,2 +310,3 @@ ## validate objects & filter arrays with mongodb queries | ||
sift({ $regex: /^f/i, $nin: ["frank"] }, ["frank", "fred", "sam", "frost"]); // ["fred", "frost"] | ||
sift({ $regex: "^f", $options: "i", $nin: ["frank"] }, ["frank", "fred", "sam", "frost"]); // ["fred", "frost"] | ||
``` | ||
@@ -312,0 +313,0 @@ |
14
sift.js
@@ -203,3 +203,3 @@ /* | ||
$regex: function(a, b) { | ||
return a.test(b); | ||
return b && a.test(b); | ||
}, | ||
@@ -291,4 +291,4 @@ | ||
$regex: function(a) { | ||
return new RegExp(a); | ||
$regex: function(a, options) { | ||
return new RegExp(a, options); | ||
}, | ||
@@ -384,3 +384,2 @@ | ||
function parse(query) { | ||
query = comparable(query); | ||
@@ -393,2 +392,6 @@ | ||
var options = query.$options; | ||
delete query.$options; | ||
var validators = []; | ||
@@ -399,5 +402,4 @@ | ||
if (operator[key]) { | ||
if (prepare[key]) a = prepare[key](a); | ||
if (prepare[key]) a = key === '$regex' ? prepare[key](a, options): prepare[key](a); | ||
validators.push(createValidator(comparable(a), operator[key])); | ||
@@ -404,0 +406,0 @@ } else { |
@@ -185,2 +185,27 @@ var sift = require(".."), | ||
}); | ||
it("$regex for nested object (one missing key)", function () { | ||
var persons = [{ | ||
id: 1, | ||
prof: 'Mr. Moriarty' | ||
}, { | ||
id: 2, | ||
prof: 'Mycroft Holmes' | ||
}, { | ||
id: 3, | ||
name: 'Dr. Watson', | ||
prof: 'Doctor' | ||
}, { | ||
id: 4, | ||
name: 'Mr. Holmes', | ||
prof: 'Detective' | ||
}]; | ||
var q = { "name": { "$regex": "n" } }; | ||
var sifted = sift(q, persons); | ||
assert.deepEqual(sifted, [{ | ||
id: 3, | ||
name: 'Dr. Watson', | ||
prof: 'Doctor' | ||
}]); | ||
}); | ||
}); | ||
@@ -187,0 +212,0 @@ |
@@ -112,2 +112,6 @@ var assert = require("assert"); | ||
[{$regex:"^a"},["a","ab","abc","bc","bcd"],["a","ab","abc"]], | ||
// $options | ||
[{$regex:"^a", $options: 'i'},["a","Ab","abc","bc","bcd"],["a","Ab","abc"]], | ||
// undefined | ||
[{$regex:"a"},[undefined, null, true, false, 0, "aa"],["aa"]], | ||
@@ -114,0 +118,0 @@ // $where |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
142714
1506
1
434