Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

sift

Package Overview
Dependencies
Maintainers
2
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sift - npm Package Compare versions

Comparing version 3.2.7 to 3.3.0

coverage/lcov-report/base.css

4

changelog.md

@@ -0,1 +1,5 @@

### 3.3.x
- `$in` now uses `toString()` when evaluating objects. Fixes #116.
#### 2.x

@@ -2,0 +6,0 @@

2

package.json
{
"name": "sift",
"description": "mongodb query style array filtering",
"version": "3.2.7",
"version": "3.3.0",
"repository": "crcn/sift.js",

@@ -6,0 +6,0 @@ "author": {

@@ -8,3 +8,3 @@ ## validate objects & filter arrays with mongodb queries

- Supported operators: [$in](#in), [$nin](#nin), [$exists](#exists), [$gte](#gte), [$gt](#gt), [$lte](#lte), [$lt](#lt), [$eq](#eq), [$ne](#ne), [$mod](#mod), [$all](#all), [$and](#and), [$or](#or), [$nor](#nor), [$not](#not), [$size](#size), [$type](#type), [$regex](#regex), [$where](#where), [$elemMatch](#elemMatch)
- Supported operators: [$in](#in), [$nin](#nin), [$exists](#exists), [$gte](#gte), [$gt](#gt), [$lte](#lte), [$lt](#lt), [$eq](#eq), [$ne](#ne), [$mod](#mod), [$all](#all), [$and](#and), [$or](#or), [$nor](#nor), [$not](#not), [$size](#size), [$type](#type), [$regex](#regex), [$where](#where), [$elemMatch](#elemmatch)
- Regexp searches

@@ -11,0 +11,0 @@ - Function filtering

@@ -42,3 +42,5 @@ /*

function get(obj, key) {
if (obj.get) return obj.get(key);
if (obj.get) {
return obj.get(key);
}
return obj[key];

@@ -52,4 +54,8 @@ }

return function(a, b) {
if (!isArray(b) || !b.length) return validator(a, b);
for (var i = 0, n = b.length; i < n; i++) if (validator(a, get(b,i))) return true;
if (!isArray(b) || !b.length) {
return validator(a, b);
}
for (var i = 0, n = b.length; i < n; i++) {
if (validator(a, get(b,i))) return true;
}
return false;

@@ -64,4 +70,8 @@ }

return function(a, b) {
if (!isArray(b) || !b.length) return validator(a, b);
for (var i = 0, n = b.length; i < n; i++) if (!validator(a, get(b, i))) return false;
if (!isArray(b) || !b.length) {
return validator(a, b);
}
for (var i = 0, n = b.length; i < n; i++) {
if (!validator(a, get(b, i))) return false;
}
return true;

@@ -141,5 +151,15 @@ };

for (var i = b.length; i--;) {
if (~a.indexOf(comparable(get(b, i)))) return true;
if (~a.indexOf(comparable(get(b, i)))) {
return true;
}
}
} else {
const comparableB = comparable(b);
if (comparableB === b && typeof b === 'object') {
for (var i = a.length; i--;) {
if (String(a[i]) === String(b)) {
return true;
}
}
}
return !!~a.indexOf(comparable(b));

@@ -191,3 +211,7 @@ }

// 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;
for (var i = 0, n = a.length; i < n; i++) {
if (validate(get(a, i), b)) {
return false;
}
}
return true;

@@ -200,4 +224,10 @@ },

$and: function(a, b) {
if (!b) b = [];
for (var i = 0, n = a.length; i < n; i++) if (!validate(get(a, i), b)) return false;
if (!b) {
b = [];
}
for (var i = 0, n = a.length; i < n; i++) {
if (!validate(get(a, i), b)) {
return false;
}
}
return true;

@@ -224,3 +254,5 @@ },

$elemMatch: function(a, b) {
if (isArray(b)) return !!~search(b, a);
if (isArray(b)) {
return !!~search(b, a);
}
return validate(a, b);

@@ -424,3 +456,5 @@ },

if (key === '$options') continue;
if (key === '$options') {
continue;
}

@@ -488,3 +522,5 @@ if (operator[key]) {

for (var key in plugin) {
if (key.charCodeAt(0) === 36) operator[key] = plugin[key];
if (key.charCodeAt(0) === 36) {
operator[key] = plugin[key];
}
}

@@ -506,4 +542,8 @@ };

if(typeof a === typeof b) {
if (a > b) return 1;
if (a < b) return -1;
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
}

@@ -510,0 +550,0 @@ };

@@ -156,2 +156,16 @@ var assert = require('assert');

[{foo:[{ name: 'baz' }, { name: 'bar' }]}]
],
// various comparisons
[
{ c: { d: 'd' }},
[{ a: 'b', b: 'c', c: { d: 'd', e: 'e' }}, { c: { d: 'e' }}],
[{ a: 'b', b: 'c', c: { d: 'd', e: 'e' }}]
],
// object.toString() tests
[
{ $in: [{ toString: function(){ return 'a'; }}]},
[{toString: function(){ return 'a'; }}, {toString: function(){ return 'b' }}],
[{toString: function(){ return 'a'; }}]
]

@@ -158,0 +172,0 @@ ].forEach(function (operation, i) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc