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 0.0.12 to 0.0.13

test/selector-test.js

2

benchmark/benchmark.js

@@ -79,3 +79,3 @@ var sift = require('../');

on('cycle', function(event, bench) {
console.log(String(event));
console.log(String(event.target));
}).

@@ -82,0 +82,0 @@ on('complete', function() {

{
"name": "sift",
"description": "mongodb query style array filtering",
"version": "0.0.12",
"repository": {
"type": "git",
"url": "git://github.com/crcn/sift.js.git"
},
"version": "0.0.13",
"repository": {},

@@ -20,3 +16,4 @@ "engines": {},

"sardines": "0.4.x",
"karma": "0.8.x"
"karma": "0.8.x",
"browserify": "~3.31.2"
},

@@ -23,0 +20,0 @@ "main": "./sift.js",

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

for(var i = a.length; i--;) {
if(b.indexOf(a[i]) == -1) return -1;
var a1 = a[i];
var indexInB = ~b.indexOf(a1);
if(!indexInB) return -1;
}

@@ -353,3 +355,13 @@

return priority(a, b ? b[a.k] : undefined);
},
/**
*/
$regex: function(a, b) {
var aRE = new RegExp(a);
return aRE.test(b) ? 0 : -1;
}
}

@@ -442,3 +454,3 @@

var sifted = [], results = [], value, priority;
var sifted = [], results = [], testValue, value, priority;

@@ -449,6 +461,7 @@ //I'll typically start from the end, but in this case we need to keep the order

value = selector(target[i]);
value = target[i];
testValue = selector(value);
//priority = -1? it's not something we can use.
if(!~(priority = filter.priority( value ))) continue;
if(!~(priority = filter.priority( testValue ))) continue;

@@ -480,3 +493,3 @@ //push all the sifted values to be sorted later. This is important particularly for statements

self.test = filter.test;
self.score = filter.priority;
self.score = filter.priority;
self.query = query;

@@ -483,0 +496,0 @@

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

(function(){var l=new function(){function d(a){return a?0:-1}var f=this.priority=function(a,b){for(var c=a.exprs,e=0,f=0,d=c.length;f<d;f++){var g=c[f];if(!~(g=g.e(g.v,b instanceof Date?b.getTime():b,b)))return-1;e+=g}return e},e=this.parse=function(a,b){a||(a={$eq:a});var c=[];if(a.constructor==Object)for(var d in a){var m=k[d]?d:"$trav",j=a[d],g=j;if(h[m]){if(~d.indexOf(".")){g=d.split(".");d=g.shift();for(var n={},l=n,p=0,s=g.length-1;p<s;p++)l=l[g[p]]={};l[g[p]]=j;g=j=n}if(j instanceof Array){g=
[];for(n=j.length;n--;)g.push(e(j[n]))}else g=e(j,d)}c.push(r(m,d,g))}else c.push(r("$eq",d,a));var q={exprs:c,k:b,test:function(a){return!!~q.priority(a)},priority:function(a){return f(q,a)}};return q},h=this.traversable={$and:!0,$or:!0,$nor:!0,$trav:!0,$not:!0},k=this.testers={$eq:function(a,b){return d(a.test(b))},$ne:function(a,b){return d(!a.test(b))},$lt:function(a,b){return a>b?0:-1},$gt:function(a,b){return a<b?0:-1},$lte:function(a,b){return a>=b?0:-1},$gte:function(a,b){return a<=b?0:-1},
$exists:function(a,b){return a===(null!=b)?0:-1},$in:function(a,b){if(b instanceof Array)for(var c=b.length;c--;){if(~a.indexOf(b[c]))return c}else return d(~a.indexOf(b));return-1},$not:function(a,b){if(!a.test)throw Error("$not test should include an expression, not a value. Use $ne instead.");return d(!a.test(b))},$type:function(a,b,c){return c?c instanceof a||c.constructor==a?0:-1:-1},$nin:function(a,b){return~k.$in(a,b)?-1:0},$mod:function(a,b){return b%a[0]==a[1]?0:-1},$all:function(a,b){for(var c=
a.length;c--;)if(-1==b.indexOf(a[c]))return-1;return 0},$size:function(a,b){return b?a==b.length?0:-1:-1},$or:function(a,b){for(var c=a.length,d=c;c--;)if(~f(a[c],b))return c;return 0==d?0:-1},$nor:function(a,b){for(var c=a.length;c--;)if(~f(a[c],b))return-1;return 0},$and:function(a,b){for(var c=a.length;c--;)if(!~f(a[c],b))return-1;return 0},$trav:function(a,b){if(b instanceof Array){for(var c=b.length;c--;){var d=b[c];if(d[a.k]&&~f(a,d[a.k]))return c}return-1}return f(a,b?b[a.k]:void 0)}},m={$eq:function(a){return a instanceof
RegExp?a:{test:a instanceof Function?a:function(b){return b instanceof Array?~b.indexOf(a):a==b}}},$ne:function(a){return m.$eq(a)}},r=function(a,b,c){c=c instanceof Date?c.getTime():c;return{k:b,v:m[a]?m[a](c):c,e:k[a]}}},h=function(d,f,e){"object"!=typeof f&&(e=f,f=void 0);if(e){if("function"!=typeof e)throw Error("Unknown sift selector "+e);}else e=function(d){return d};var h=e,k=l.parse(d);e=function(d){for(var e=[],a,b,c=0,f=d.length;c<f;c++)a=h(d[c]),~(b=k.priority(a))&&e.push({value:a,priority:b});
e.sort(function(a,b){return a.priority>b.priority?-1:1});d=Array(e.length);for(c=e.length;c--;)d[c]=e[c].value;return d};e.test=k.test;e.score=k.priority;e.query=d;return f?e(f):e};h.use=function(d){d.operators&&h.useOperators(d.operators)};h.useOperators=function(d){for(var f in d)h.useOperator(f,d[f])};h.useOperator=function(d,f){var e={},e="object"==typeof f?f:{test:f},h="$"+d;l.testers[h]=e.test;if(e.traversable||e.traverse)l.traversable[h]=!0};"undefined"!=typeof module&&"undefined"!=typeof module.exports?
module.exports=h:"undefined"!=typeof window&&(window.sift=h)})();
(function(){var m=new function(){function g(a){return a?0:-1}var e=this.priority=function(a,b){for(var c=a.exprs,f=0,d=0,e=c.length;d<e;d++){var h=c[d];if(!~(h=h.e(h.v,b instanceof Date?b.getTime():b,b)))return-1;f+=h}return f},d=this.parse=function(a,b){a||(a={$eq:a});var c=[];if(a.constructor==Object)for(var f in a){var g=l[f]?f:"$trav",k=a[f],h=k;if(j[g]){if(~f.indexOf(".")){h=f.split(".");f=h.shift();for(var n={},m=n,p=0,s=h.length-1;p<s;p++)m=m[h[p]]={};m[h[p]]=k;h=k=n}if(k instanceof Array){h=
[];for(n=k.length;n--;)h.push(d(k[n]))}else h=d(k,f)}c.push(r(g,f,h))}else c.push(r("$eq",f,a));var q={exprs:c,k:b,test:function(a){return!!~q.priority(a)},priority:function(a){return e(q,a)}};return q},j=this.traversable={$and:!0,$or:!0,$nor:!0,$trav:!0,$not:!0},l=this.testers={$eq:function(a,b){return g(a.test(b))},$ne:function(a,b){return g(!a.test(b))},$lt:function(a,b){return a>b?0:-1},$gt:function(a,b){return a<b?0:-1},$lte:function(a,b){return a>=b?0:-1},$gte:function(a,b){return a<=b?0:-1},
$exists:function(a,b){return a===(null!=b)?0:-1},$in:function(a,b){if(b instanceof Array)for(var c=b.length;c--;){if(~a.indexOf(b[c]))return c}else return g(~a.indexOf(b));return-1},$not:function(a,b){if(!a.test)throw Error("$not test should include an expression, not a value. Use $ne instead.");return g(!a.test(b))},$type:function(a,b,c){return c?c instanceof a||c.constructor==a?0:-1:-1},$nin:function(a,b){return~l.$in(a,b)?-1:0},$mod:function(a,b){return b%a[0]==a[1]?0:-1},$all:function(a,b){for(var c=
a.length;c--;)if(!~b.indexOf(a[c]))return-1;return 0},$size:function(a,b){return b?a==b.length?0:-1:-1},$or:function(a,b){for(var c=a.length,f=c;c--;)if(~e(a[c],b))return c;return 0==f?0:-1},$nor:function(a,b){for(var c=a.length;c--;)if(~e(a[c],b))return-1;return 0},$and:function(a,b){for(var c=a.length;c--;)if(!~e(a[c],b))return-1;return 0},$trav:function(a,b){if(b instanceof Array){for(var c=b.length;c--;){var f=b[c];if(f[a.k]&&~e(a,f[a.k]))return c}return-1}return e(a,b?b[a.k]:void 0)},$regex:function(a,
b){return RegExp(a).test(b)?0:-1}},k={$eq:function(a){return a instanceof RegExp?a:{test:a instanceof Function?a:function(b){return b instanceof Array?~b.indexOf(a):a==b}}},$ne:function(a){return k.$eq(a)}},r=function(a,b,c){c=c instanceof Date?c.getTime():c;return{k:b,v:k[a]?k[a](c):c,e:l[a]}}},j=function(g,e,d){"object"!=typeof e&&(d=e,e=void 0);if(d){if("function"!=typeof d)throw Error("Unknown sift selector "+d);}else d=function(d){return d};var j=d,l=m.parse(g);d=function(d){for(var e=[],a,b,
c,f=0,g=d.length;f<g;f++)b=d[f],a=j(b),~(c=l.priority(a))&&e.push({value:b,priority:c});e.sort(function(a,b){return a.priority>b.priority?-1:1});d=Array(e.length);for(f=e.length;f--;)d[f]=e[f].value;return d};d.test=l.test;d.score=l.priority;d.query=g;return e?d(e):d};j.use=function(g){g.operators&&j.useOperators(g.operators)};j.useOperators=function(g){for(var e in g)j.useOperator(e,g[e])};j.useOperator=function(g,e){var d={},d="object"==typeof e?e:{test:e},j="$"+g;m.testers[j]=d.test;if(d.traversable||
d.traverse)m.traversable[j]=!0};"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=j:"undefined"!=typeof window&&(window.sift=j)})();

Sorry, the diff of this file is not supported yet

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