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 8.3.3 to 8.3.4

86

lib/index.js

@@ -7,3 +7,15 @@ "use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _typeof =
typeof Symbol === "function" && typeof Symbol.iterator === "symbol"
? function(obj) {
return typeof obj;
}
: function(obj) {
return obj &&
typeof Symbol === "function" &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? "symbol"
: typeof obj;
};

@@ -22,3 +34,3 @@ exports.default = sift;

var typeString = "[object " + type + "]";
return function (value) {
return function(value) {
return Object.prototype.toString.call(value) === typeString;

@@ -58,3 +70,3 @@ };

function or(validator) {
return function (a, b) {
return function(a, b) {
if (!isArray(b) || !b.length) {

@@ -74,3 +86,3 @@ return validator(a, b);

function and(validator) {
return function (a, b) {
return function(a, b) {
if (!isArray(b) || !b.length) {

@@ -94,3 +106,3 @@ return validator(a, b);

$eq: or(function (a, b) {
$eq: or(function(a, b) {
return a(b);

@@ -102,3 +114,3 @@ }),

$ne: and(function (a, b) {
$ne: and(function(a, b) {
return !a(b);

@@ -110,3 +122,3 @@ }),

$gt: or(function (a, b) {
$gt: or(function(a, b) {
return compare(comparable(b), a) > 0;

@@ -118,3 +130,3 @@ }),

$gte: or(function (a, b) {
$gte: or(function(a, b) {
return compare(comparable(b), a) >= 0;

@@ -126,3 +138,3 @@ }),

$lt: or(function (a, b) {
$lt: or(function(a, b) {
return compare(comparable(b), a) < 0;

@@ -134,3 +146,3 @@ }),

$lte: or(function (a, b) {
$lte: or(function(a, b) {
return compare(comparable(b), a) <= 0;

@@ -142,3 +154,3 @@ }),

$mod: or(function (a, b) {
$mod: or(function(a, b) {
return b % a[0] == a[1];

@@ -152,3 +164,3 @@ }),

if (b instanceof Array) {
for (var i = b.length; i--;) {
for (var i = b.length; i--; ) {
if (~a.indexOf(comparable(get(b, i)))) {

@@ -160,4 +172,7 @@ return true;

var comparableB = comparable(b);
if (comparableB === b && (typeof b === "undefined" ? "undefined" : _typeof(b)) === "object") {
for (var i = a.length; i--;) {
if (
comparableB === b &&
(typeof b === "undefined" ? "undefined" : _typeof(b)) === "object"
) {
for (var i = a.length; i--; ) {
if (String(a[i]) === String(b) && String(b) !== "[object Object]") {

@@ -174,3 +189,3 @@ return true;

if (typeof comparableB == "undefined") {
for (var i = a.length; i--;) {
for (var i = a.length; i--; ) {
if (a[i] == null) {

@@ -185,6 +200,10 @@ return true;

*/
for (var i = a.length; i--;) {
for (var i = a.length; i--; ) {
var validator = createRootValidator(get(a, i), undefined);
var result = validate(validator, b, i, a);
if (result && String(result) !== "[object Object]" && String(b) !== "[object Object]") {
if (
result &&
String(result) !== "[object Object]" &&
String(b) !== "[object Object]"
) {
return true;

@@ -269,3 +288,3 @@ }

$regex: or(function (a, b) {
$regex: or(function(a, b) {
return typeof b === "string" && a.test(b);

@@ -308,3 +327,3 @@ }),

if (a instanceof RegExp) {
return function (b) {
return function(b) {
return typeof b === "string" && a.test(b);

@@ -316,7 +335,7 @@ };

// Special case of a == []
return function (b) {
return function(b) {
return isArray(b) && !b.length;
};
} else if (a === null) {
return function (b) {
return function(b) {
//will match both null and undefined

@@ -326,3 +345,3 @@ return b == null;

}
return function (b) {
return function(b) {
return compare(comparable(b), comparable(a)) === 0;

@@ -486,3 +505,9 @@ };

function isVanillaObject(value) {
return value && (value.constructor === Object || value.constructor === Array);
return (
value &&
(value.constructor === Object ||
value.constructor.toString() === "function Object() { [native code] }" ||
value.constructor === Array ||
value.constructor.toString() === "function Array() { [native code] }")
);
}

@@ -510,3 +535,5 @@

var expression = expressions[key] || options && options.expressions && options.expressions[key];
var expression =
expressions[key] ||
(options && options.expressions && options.expressions[key]);

@@ -529,3 +556,5 @@ if (expression) {

return validators.length === 1 ? validators[0] : createValidator(validators, expressions.$and);
return validators.length === 1
? validators[0]
: createValidator(validators, expressions.$and);
};

@@ -618,3 +647,3 @@

var validator = createRootValidator(query, options);
return function (b, k, o) {
return function(b, k, o) {
return validate(validator, b, k, o);

@@ -629,3 +658,6 @@ };

if (isEqual(a, b)) return 0;
if ((typeof a === "undefined" ? "undefined" : _typeof(a)) === (typeof b === "undefined" ? "undefined" : _typeof(b))) {
if (
(typeof a === "undefined" ? "undefined" : _typeof(a)) ===
(typeof b === "undefined" ? "undefined" : _typeof(b))
) {
if (a > b) {

@@ -632,0 +664,0 @@ return 1;

{
"name": "sift",
"description": "mongodb query style array filtering",
"version": "8.3.3",
"version": "8.3.4",
"repository": "crcn/sift.js",

@@ -21,3 +21,2 @@ "author": {

"devDependencies": {
"prettier": "1.15.3",
"babel-cli": "^6.26.0",

@@ -28,5 +27,7 @@ "babel-core": "^6.26.3",

"bson": "^3.0.2",
"eval": "^0.1.3",
"husky": "^1.2.1",
"immutable": "^3.7.6",
"mocha": "^5.2.0",
"prettier": "1.15.3",
"pretty-quick": "^1.8.0",

@@ -33,0 +34,0 @@ "webpack": "^4.20.2",

@@ -56,4 +56,4 @@ ## validate objects & filter arrays with mongodb queries

//you can test *single values* against your custom sifter
testQuery({ name: "sarah" }); //true
testQuery({ name: "tim" }); //false\
testFilter({ name: "sarah" }); //true
testFilter({ name: "tim" }); //false
```

@@ -60,0 +60,0 @@

@@ -79,6 +79,6 @@ !(function(n, t) {

r.d(t, "default", function() {
return y;
return j;
}),
r.d(t, "compare", function() {
return j;
return O;
});

@@ -111,27 +111,27 @@ var u = e("Array"),

}
var s = {
var s,
p = {
$eq: a(function(n, t) {
return n(t);
}),
$ne: (function(n) {
return function(t, r) {
if (!u(r) || !r.length) return n(t, r);
for (var e = 0, o = r.length; e < o; e++)
if (!n(t, c(r, e))) return !1;
return !0;
};
})(function(n, t) {
$ne: ((s = function(n, t) {
return !n(t);
}),
function(n, t) {
if (!u(t) || !t.length) return s(n, t);
for (var r = 0, e = t.length; r < e; r++)
if (!s(n, c(t, r))) return !1;
return !0;
}),
$gt: a(function(n, t) {
return j(f(t), n) > 0;
return O(f(t), n) > 0;
}),
$gte: a(function(n, t) {
return j(f(t), n) >= 0;
return O(f(t), n) >= 0;
}),
$lt: a(function(n, t) {
return j(f(t), n) < 0;
return O(f(t), n) < 0;
}),
$lte: a(function(n, t) {
return j(f(t), n) <= 0;
return O(f(t), n) <= 0;
}),

@@ -154,3 +154,3 @@ $mod: a(function(n, t) {

for (u = n.length; u--; ) {
var e = l(b(c(n, u), void 0), t, u, n);
var e = l(y(c(n, u), void 0), t, u, n);
if (

@@ -169,3 +169,3 @@ e &&

$nin: function(n, t, r, e) {
return !s.$in(n, t, r, e);
return !p.$in(n, t, r, e);
},

@@ -176,6 +176,6 @@ $not: function(n, t, r, e) {

$type: function(n, t) {
return void 0 != t && (t instanceof n || t.constructor == n);
return null != t && (t instanceof n || t.constructor == n);
},
$all: function(n, t, r, e) {
return s.$and(n, t, r, e);
return p.$and(n, t, r, e);
},

@@ -191,3 +191,3 @@ $size: function(n, t) {

$nor: function(n, t, r, e) {
return !s.$or(n, t, r, e);
return !p.$or(n, t, r, e);
},

@@ -220,3 +220,3 @@ $and: function(n, t, r, e) {

},
p = {
g = {
$eq: function(n) {

@@ -238,22 +238,22 @@ return n instanceof RegExp

: function(t) {
return 0 === j(f(t), f(n));
return 0 === O(f(t), f(n));
};
},
$ne: function(n) {
return p.$eq(n);
return g.$eq(n);
},
$and: function(n, t, r) {
return n.map(d(r));
return n.map(h(r));
},
$all: function(n) {
return p.$and(n);
return g.$and(n);
},
$or: function(n, t, r) {
return n.map(d(r));
return n.map(h(r));
},
$nor: function(n, t, r) {
return n.map(d(r));
return n.map(h(r));
},
$not: function(n, t, r) {
return d(r)(n);
return h(r)(n);
},

@@ -269,3 +269,3 @@ $regex: function(n, t) {

$elemMatch: function(n, t, r) {
return d(r)(n);
return h(r)(n);
},

@@ -276,10 +276,10 @@ $exists: function(n) {

};
function g(n, t) {
function v(n, t) {
return { a: n, v: t };
}
function v(n, t) {
function $(n, t) {
var r = [];
if (
((function n(t, r, e, o, i) {
if (e === r.length || void 0 == t)
if (e === r.length || null == t)
return void i.push([t, r[e - 1], o]);

@@ -307,17 +307,9 @@ var f = c(r, e);

}
function $(n, t, r) {
return { a: { k: n, nv: t, q: r }, v: v };
function d(n, t, r) {
return { a: { k: n, nv: t, q: r }, v: $ };
}
function d(n) {
function h(n) {
var t = function(n) {
return (
(n &&
(function(n) {
return (
n && (n.constructor === Object || n.constructor === Array)
);
})(n)) ||
(n = { $eq: n }),
n
);
var t;
return (n && ((t = n) && (o(t) || u(t)))) || (n = { $eq: n }), n;
},

@@ -330,4 +322,4 @@ r = function(t) {

if ("$options" !== u) {
var i = s[u] || (n && n.expressions && n.expressions[u]);
if (i) p[u] && (o = p[u](o, t, n)), r.push(g(f(o), i));
var i = p[u] || (n && n.expressions && n.expressions[u]);
if (i) g[u] && (o = g[u](o, t, n)), r.push(v(f(o), i));
else {

@@ -337,23 +329,22 @@ if (36 === u.charCodeAt(0))

var c = u.split(".");
r.push($(c, e(o), o));
r.push(d(c, e(o), o));
}
}
}
return 1 === r.length ? r[0] : g(r, s.$and);
return 1 === r.length ? r[0] : v(r, p.$and);
},
e = function(n) {
return (function(n) {
return (
-1 ===
(function n(t, r) {
if (!o(t)) return r;
for (var e in t) r.push(e), n(t[e], r);
return r;
})(n, [])
.join(",")
.search(/[$.]/)
);
})((n = t(n)))
? g(n, h)
: r(n);
return (
(n = t(n)),
-1 ===
(function n(t, r) {
if (!o(t)) return r;
for (var e in t) r.push(e), n(t[e], r);
return r;
})(n, [])
.join(",")
.search(/[$.]/)
? v(n, b)
: r(n)
);
};

@@ -364,3 +355,3 @@ return function(n) {

}
function h(n, t) {
function b(n, t) {
if (

@@ -373,3 +364,3 @@ Object.prototype.toString.call(n) !==

if (Object.keys(n).length !== Object.keys(t).length) return !1;
for (var r in n) if (!h(n[r], t[r])) return !1;
for (var r in n) if (!b(n[r], t[r])) return !1;
return !0;

@@ -380,3 +371,3 @@ }

for (var e = 0, i = n.length; e < i; e++)
if (!h(n[e], t[e])) return !1;
if (!b(n[e], t[e])) return !1;
return !0;

@@ -386,4 +377,4 @@ }

}
function b(n, t) {
var r = d(t)(n);
function y(n, t) {
var r = h(t)(n);
return (

@@ -401,4 +392,4 @@ t &&

}
function y(n, t) {
var r = b(n, t);
function j(n, t) {
var r = y(n, t);
return function(n, t, e) {

@@ -408,4 +399,4 @@ return l(r, n, t, e);

}
function j(n, t) {
if (h(n, t)) return 0;
function O(n, t) {
if (b(n, t)) return 0;
if (typeof n == typeof t) {

@@ -412,0 +403,0 @@ if (n > t) return 1;

@@ -461,3 +461,3 @@ /*

function isVanillaObject(value) {
return value && (value.constructor === Object || value.constructor === Array);
return value && (isObject(value) || isArray(value)); // (value.constructor === Object || value.constructor === Array);
}

@@ -464,0 +464,0 @@

import * as assert from "assert";
import { default as _eval } from "eval";
import sift, { indexOf as siftIndexOf } from "..";

@@ -212,2 +213,30 @@

});
it("works with new Function()", () => {
const fn = new Function(
"sift",
`
const sifter = sift({ a: 'a1' });
const arr = [{ a: 'a1', b: 'b1' }, { a: 'a2', b: 'b2' }];
return arr.filter(sifter);
`
);
const results = fn(sift);
assert.equal(results.length, 1);
});
it("works with eval (node sandbox)", () => {
const code = `
const sifter = sift({ a: 'a1' });
const arr = [{ a: 'a1', b: 'b1' }, { a: 'a2', b: 'b2' }];
module.exports = arr.filter(sifter);
`;
const results = _eval(code, "filename", {
sift,
console: { log: console.log.bind(console) }
});
assert.equal(results.length, 1);
});
});

@@ -59,2 +59,3 @@ import * as assert from "assert";

],
[

@@ -61,0 +62,0 @@ { a: { c: 1 } },

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