Socket
Socket
Sign inDemoInstall

sift

Package Overview
Dependencies
Maintainers
1
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 2.0.3 to 2.0.4

2

package.json
{
"name": "sift",
"description": "mongodb query style array filtering",
"version": "2.0.3",
"version": "2.0.4",
"repository": {},

@@ -6,0 +6,0 @@ "engines": {},

@@ -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)
- 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

@@ -326,2 +326,35 @@ - Function filtering

### $elemMatch
Matches elements of array
```javascript
var bills = [{
month: 'july',
casts: [{
id: 1,
value: 200
},{
id: 2,
value: 1000
}]
},
{
month: 'august',
casts: [{
id: 3,
value: 1000,
}, {
id: 4,
value: 4000
}]
}];
var result = sift({
casts: {$elemMatch:{
value: {$gt: 1000}
}}
}, bills); // {month:'august', casts:[{id:2, value: 1000},{id: 4, value: 4000}]}
```
### $not

@@ -328,0 +361,0 @@

@@ -96,3 +96,3 @@ /*

$gt: or(function(a, b) {
return comparable(b) > a;
return typeof comparable(b) === typeof a && comparable(b) > a;
}),

@@ -104,3 +104,3 @@

$gte: or(function(a, b) {
return comparable(b) >= a;
return typeof comparable(b) === typeof a && comparable(b) >= a;
}),

@@ -112,3 +112,3 @@

$lt: or(function(a, b) {
return comparable(b) < a;
return typeof comparable(b) === typeof a && comparable(b) < a;
}),

@@ -120,3 +120,3 @@

$lte: or(function(a, b) {
return comparable(b) <= a;
return typeof comparable(b) === typeof a && comparable(b) <= a;
}),

@@ -390,3 +390,3 @@

if (!query || (query.constructor.toString() !== "Object" &&
query.constructor.toString() !== "function Object() { [native code] }")) {
query.constructor.toString().replace(/\n/g,'').replace(/ /g, '') !== "functionObject(){[nativecode]}")) { // cross browser support
query = { $eq: query };

@@ -393,0 +393,0 @@ }

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

!function(){"use strict";function n(n){return"function"==typeof n}function t(n){return"[object Array]"===Object.prototype.toString.call(n)}function r(n){return n instanceof Date?n.getTime():n instanceof Array?n.map(r):n}function e(n){return function(r,e){if(!t(e))return n(r,e);for(var u=0,o=e.length;o>u;u++)if(n(r,e[u]))return!0;return!1}}function u(n){return function(r,e){if(!t(e))return n(r,e);for(var u=0,o=e.length;o>u;u++)if(!n(r,e[u]))return!1;return!0}}function o(n,t){return n.v(n.a,t)}function i(n,t){for(var r=0;r<n.length;r++)if(o(t,n[r]))return r;return-1}function f(n,t){return{a:n,v:t}}function c(n,t){var r=[];return a(t,n.k,0,r),1===r.length?o(n.nv,r[0]):!!~i(r,n.nv)}function a(n,r,e,u){if(e===r.length||void 0==n)return void u.push(n);if(t(n))for(var o=0,i=n.length;i>o;o++)a(n[o],r,e,u);else a(n[r[e]],r,e+1,u)}function $(n,t){return{a:{k:n,nv:t},v:c}}function l(n){n=r(n),(!n||"Object"!==n.constructor.toString()&&"function Object() { [native code] }"!==n.constructor.toString())&&(n={$eq:n});var t=[];for(var e in n){var u=n[e];if(d[e])g[e]&&(u=g[e](u)),t.push(f(r(u),d[e]));else{if(36===e.charCodeAt(0))throw new Error("Unknown operation "+e);t.push($(e.split("."),l(u)))}}return 1===t.length?t[0]:f(t,d.$and)}function v(n,t){var r=l(n);return t&&(r={a:r,v:function(n,r){return o(n,t(r))}}),r}function s(t,r,e){function u(n){return o(i,n)}n(r)&&(e=r,r=void 0);var i=v(t,e);return r?r.filter(u):u}var d={$eq:e(function(n,t){return n(t)}),$ne:u(function(n,t){return!n(t)}),$or:function(n,t){for(var r=0,e=n.length;e>r;r++)if(o(n[r],t))return!0;return!1},$gt:e(function(n,t){return r(t)>n}),$gte:e(function(n,t){return r(t)>=n}),$lt:e(function(n,t){return r(t)<n}),$lte:e(function(n,t){return r(t)<=n}),$mod:e(function(n,t){return t%n[0]==n[1]}),$in:function(n,t){if(!(t instanceof Array))return!!~n.indexOf(r(t));for(var e=t.length;e--;)if(~n.indexOf(r(t[e])))return!0;return!1},$nin:function(n,t){return!d.$in(n,t)},$not:function(n,t){return!o(n,t)},$type:function(n,t){return void 0!=t?t instanceof n||t.constructor==n:!1},$all:function(n,t){t||(t=[]);for(var e=n.length;e--;)if(!~r(t).indexOf(n[e]))return!1;return!0},$size:function(n,t){return t?n===t.length:!1},$nor:function(n,t){for(var r=0,e=n.length;e>r;r++)if(o(n[r],t))return!1;return!0},$and:function(n,t){for(var r=0,e=n.length;e>r;r++)if(!o(n[r],t))return!1;return!0},$regex:function(n,t){return n.test(t)},$where:function(n,t){return n.call(t,t)},$elemMatch:function(n,r){return t(r)?!!~i(r,n):o(n,r)},$exists:function(n,t){return void 0!=t===n}},g={$eq:function(n){return n instanceof RegExp?function(t){return n.test(r(t))}:n instanceof Function?n:function(t){return n===r(t)}},$ne:function(n){return g.$eq(n)},$and:function(n){return n.map(l)},$or:function(n){return n.map(l)},$nor:function(n){return n.map(l)},$not:function(n){return l(n)},$regex:function(n){return new RegExp(n)},$where:function(n){return"string"==typeof n?new Function("obj","return "+n):n},$elemMatch:function(n){return l(n)},$exists:function(n){return!!n}};s.use=function(t){if(n(t))return t(s);for(var r in t)36===r.charCodeAt(0)&&(d[r]=t[r])},s.indexOf=function(n,t,r){return i(t,v(n,r))},"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=s:"undefined"!=typeof window&&(window.sift=s)}();
!function(){"use strict";function n(n){return"function"==typeof n}function t(n){return"[object Array]"===Object.prototype.toString.call(n)}function r(n){return n instanceof Date?n.getTime():n instanceof Array?n.map(r):n}function e(n){return function(r,e){if(!t(e))return n(r,e);for(var u=0,o=e.length;o>u;u++)if(n(r,e[u]))return!0;return!1}}function u(n){return function(r,e){if(!t(e))return n(r,e);for(var u=0,o=e.length;o>u;u++)if(!n(r,e[u]))return!1;return!0}}function o(n,t){return n.v(n.a,t)}function i(n,t){for(var r=0;r<n.length;r++)if(o(t,n[r]))return r;return-1}function f(n,t){return{a:n,v:t}}function c(n,t){var r=[];return a(t,n.k,0,r),1===r.length?o(n.nv,r[0]):!!~i(r,n.nv)}function a(n,r,e,u){if(e===r.length||void 0==n)return void u.push(n);if(t(n))for(var o=0,i=n.length;i>o;o++)a(n[o],r,e,u);else a(n[r[e]],r,e+1,u)}function $(n,t){return{a:{k:n,nv:t},v:c}}function l(n){n=r(n),(!n||"Object"!==n.constructor.toString()&&"functionObject(){[nativecode]}"!==n.constructor.toString().replace(/\n/g,"").replace(/ /g,""))&&(n={$eq:n});var t=[];for(var e in n){var u=n[e];if(s[e])d[e]&&(u=d[e](u)),t.push(f(r(u),s[e]));else{if(36===e.charCodeAt(0))throw new Error("Unknown operation "+e);t.push($(e.split("."),l(u)))}}return 1===t.length?t[0]:f(t,s.$and)}function p(n,t){var r=l(n);return t&&(r={a:r,v:function(n,r){return o(n,t(r))}}),r}function v(t,r,e){function u(n){return o(i,n)}n(r)&&(e=r,r=void 0);var i=p(t,e);return r?r.filter(u):u}var s={$eq:e(function(n,t){return n(t)}),$ne:u(function(n,t){return!n(t)}),$or:function(n,t){for(var r=0,e=n.length;e>r;r++)if(o(n[r],t))return!0;return!1},$gt:e(function(n,t){return typeof r(t)==typeof n&&r(t)>n}),$gte:e(function(n,t){return typeof r(t)==typeof n&&r(t)>=n}),$lt:e(function(n,t){return typeof r(t)==typeof n&&r(t)<n}),$lte:e(function(n,t){return typeof r(t)==typeof n&&r(t)<=n}),$mod:e(function(n,t){return t%n[0]==n[1]}),$in:function(n,t){if(!(t instanceof Array))return!!~n.indexOf(r(t));for(var e=t.length;e--;)if(~n.indexOf(r(t[e])))return!0;return!1},$nin:function(n,t){return!s.$in(n,t)},$not:function(n,t){return!o(n,t)},$type:function(n,t){return void 0!=t?t instanceof n||t.constructor==n:!1},$all:function(n,t){t||(t=[]);for(var e=n.length;e--;)if(!~r(t).indexOf(n[e]))return!1;return!0},$size:function(n,t){return t?n===t.length:!1},$nor:function(n,t){for(var r=0,e=n.length;e>r;r++)if(o(n[r],t))return!1;return!0},$and:function(n,t){for(var r=0,e=n.length;e>r;r++)if(!o(n[r],t))return!1;return!0},$regex:function(n,t){return n.test(t)},$where:function(n,t){return n.call(t,t)},$elemMatch:function(n,r){return t(r)?!!~i(r,n):o(n,r)},$exists:function(n,t){return void 0!=t===n}},d={$eq:function(n){return n instanceof RegExp?function(t){return n.test(r(t))}:n instanceof Function?n:function(t){return n===r(t)}},$ne:function(n){return d.$eq(n)},$and:function(n){return n.map(l)},$or:function(n){return n.map(l)},$nor:function(n){return n.map(l)},$not:function(n){return l(n)},$regex:function(n){return new RegExp(n)},$where:function(n){return"string"==typeof n?new Function("obj","return "+n):n},$elemMatch:function(n){return l(n)},$exists:function(n){return!!n}};v.use=function(t){if(n(t))return t(v);for(var r in t)36===r.charCodeAt(0)&&(s[r]=t[r])},v.indexOf=function(n,t,r){return i(t,p(n,r))},"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=v:"undefined"!=typeof window&&(window.sift=v)}();

@@ -41,2 +41,3 @@ var assert = require("assert");

[{$lt:"c"}, ["a","b","c"],["a","b"]],
[{$lt:null}, [-3,-4], []],
[{$lt:new Date(3)}, [new Date(1), new Date(2), new Date(3)],[new Date(1), new Date(2)]],

@@ -50,2 +51,3 @@

[{$gt:5}, [3,4,5,6],[6]],
[{$gt:null}, [3,4], []],
[{groups:{$gt:5}}, [{groups:[1,2,3,4]}, {groups:[7,8]}], [{groups:[7,8]}]],

@@ -52,0 +54,0 @@

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