Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "sift", | ||
"description": "mongodb query style array filtering", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"repository": { | ||
@@ -18,3 +18,4 @@ "type": "git", | ||
"express": "*", | ||
"validator": "*" | ||
"validator": "*", | ||
"expect.js":"*" | ||
}, | ||
@@ -21,0 +22,0 @@ "main": "./sift.js", |
@@ -274,3 +274,3 @@ ## MongoDB inspired array filtering [![Build Status](https://secure.travis-ci.org/crcn/sift.js.png)](https://secure.travis-ci.org/crcn/sift.js) | ||
//filtered: [ { name: 'Tim', state: 'MN' }, { name: 'Joe', state: 'CA' }] | ||
sift({ $or: [ { name: 'Craig' }, { state: 'MN' } ] }, [ | ||
sift({ $nor: [ { name: 'Craig' }, { state: 'MN' } ] }, [ | ||
{ name: 'Craig', state: 'MN' }, | ||
@@ -329,4 +329,3 @@ { name: 'Tim', state: 'MN' }, | ||
//or | ||
var sifted = sift({'address.city': 'minneapolis', people});//count = 1 | ||
var sifted = sift({'address.city': 'minneapolis'}, people);//count = 1 | ||
``` | ||
@@ -274,6 +274,6 @@ /* | ||
for(var i = a.length; i--;) { | ||
if(b.indexOf(a[i]) == -1) return i; | ||
if(b.indexOf(a[i]) == -1) return -1; | ||
} | ||
return -1; | ||
return 0; | ||
}, | ||
@@ -280,0 +280,0 @@ |
(function(){var t=new function(){function h(a){return a?0:-1}var f=this.priority=function(a,b){for(var c=a.exprs,e=0,d=0,f=c.length;d<f;d++){var g=c[d];if(!~(g=g.e(g.v,b instanceof Date?b.getTime():b,b)))return-1;e+=g}return e},d=this.parse=function(a,b){a||(a={$eq:a});var c=[];if(a.constructor==Object)for(var e in a){var l=k[e]?e:"$trav",j=a[e],g=j;if(s[l]){if(~e.indexOf(".")){g=e.split(".");e=g.shift();for(var h={},p=h,n=0,m=g.length-1;n<m;n++)p=p[g[n]]={};p[g[n]]=j;g=j=h}if(j instanceof Array){g= | ||
[];for(h=j.length;h--;)g.push(d(j[h]))}else g=d(j,e)}c.push(r(l,e,g))}else c.push(r("$eq",e,a));var q={exprs:c,k:b,test:function(a){return!!~q.priority(a)},priority:function(a){return f(q,a)}};return q},s={$and:!0,$or:!0,$nor:!0,$trav:!0,$not:!0},k={$eq:function(a,b){return h(a.test(b))},$ne:function(a,b){return h(!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== | ||
!!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 h(~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 h(!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 c; | ||
return-1},$size:function(a,b){return b?a==b.length?0:-1:-1},$or:function(a,b){for(var c=a.length,e=c;c--;)if(~f(a[c],b))return c;return 0==e?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 e=b[c];if(e[a.k]&&~f(a,e[a.k]))return c}return-1}return b?f(a,b[a.k]):-1}},l={$eq:function(a){return a instanceof RegExp?a:{test:a instanceof | ||
!!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 h(~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 h(!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,e=c;c--;)if(~f(a[c],b))return c;return 0==e?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 e=b[c];if(e[a.k]&&~f(a,e[a.k]))return c}return-1}return b?f(a,b[a.k]):-1}},l={$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 l.$eq(a)}},r=function(a,b,c){c=c instanceof Date?c.getTime():c;return{k:b,v:l[a]?l[a](c):c,e:k[a]}}},m=function(h,f,d){"object"!=typeof f&&(d=f,f=void 0);if(d){if("function"!=typeof d)throw Error("Unknown sift selector "+d);}else d=function(d){return d};var m=d,k=t.parse(h);d=function(d){for(var f=[],a,b,c=0,e=d.length;c<e;c++)a=m(d[c]),~(b=k.priority(a))&&f.push({value:a,priority:b});f.sort(function(a,b){return a.priority> | ||
b.priority?-1:1});d=Array(f.length);for(c=f.length;c--;)d[c]=f[c].value;return d};d.test=k.test;d.score=k.priority;d.query=h;return f?d(f):d};"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=m:"undefined"!=typeof window&&(window.sift=m)})(); |
@@ -206,4 +206,6 @@ var sift = require('../'), | ||
assert.equal(sifted.length , 1); | ||
assert.equal(sifted.length, 1); | ||
assert.equal(sifted[0], topic[0]); | ||
}, | ||
@@ -210,0 +212,0 @@ |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
40308
16
1160
7
330
3