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

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 9.0.2 to 9.0.3

166

lib/index.js

@@ -6,20 +6,24 @@ "use strict";

});
exports["default"] = sift;
exports.compare = compare;
exports.comparable = comparable;
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;
};
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function _typeof(obj) {
return typeof obj;
};
} else {
_typeof = function _typeof(obj) {
return obj &&
typeof Symbol === "function" &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? "symbol"
: typeof obj;
};
}
return _typeof(obj);
}
exports.default = sift;
exports.compare = compare;
exports.comparable = comparable;
/*

@@ -32,3 +36,2 @@ *

*/
function typeChecker(type) {

@@ -40,3 +43,2 @@ var typeString = "[object " + type + "]";

}
/**

@@ -52,3 +54,2 @@ */

}
/**

@@ -62,9 +63,10 @@ */

}
for (var i = 0, n = value.length; i < n; i++) {
if (validator(validateOptions, get(value, i))) return true;
}
return false;
};
}
/**

@@ -78,5 +80,7 @@ */

}
for (var i = 0, n = value.length; i < n; i++) {
if (!validator(validateOptions, get(value, i))) return false;
}
return true;

@@ -93,3 +97,2 @@ };

*/
$eq: or(function(test, value) {

@@ -101,3 +104,2 @@ return test(value);

*/
$ne: and(function(test, value) {

@@ -109,3 +111,2 @@ return test(value);

*/
$gt: or(function(test, value) {

@@ -117,3 +118,2 @@ return test(value);

*/
$gte: or(function(test, value) {

@@ -125,3 +125,2 @@ return test(value);

*/
$lt: or(function(test, value) {

@@ -133,3 +132,2 @@ return test(value);

*/
$lte: or(function(test, value) {

@@ -141,3 +139,2 @@ return test(value);

*/
$mod: or(function(test, value) {

@@ -149,3 +146,2 @@ return test(value);

*/
$in: function $in(test, value) {

@@ -157,3 +153,2 @@ return test(value);

*/
$nin: function $nin(test, value) {

@@ -165,3 +160,2 @@ return test(value);

*/
$not: function $not(test, value, key, valueOwner) {

@@ -173,3 +167,2 @@ return test(value, key, valueOwner);

*/
$type: function $type(testType, value) {

@@ -181,3 +174,2 @@ return testType(value);

*/
$all: function $all(allOptions, value, key, valueOwner) {

@@ -189,3 +181,2 @@ return defaultExpressions.$and(allOptions, value, key, valueOwner);

*/
$size: function $size(sizeMatch, value) {

@@ -197,3 +188,2 @@ return value ? sizeMatch === value.length : false;

*/
$or: function $or(orOptions, value, key, valueOwner) {

@@ -205,2 +195,3 @@ for (var i = 0, n = orOptions.length; i < n; i++) {

}
return false;

@@ -211,3 +202,2 @@ },

*/
$nor: function $nor(validateOptions, value, key, valueOwner) {

@@ -219,3 +209,2 @@ return !defaultExpressions.$or(validateOptions, value, key, valueOwner);

*/
$and: function $and(validateOptions, value, key, valueOwner) {

@@ -227,2 +216,3 @@ for (var i = 0, n = validateOptions.length; i < n; i++) {

}
return true;

@@ -233,3 +223,2 @@ },

*/
$regex: or(function(validateOptions, value) {

@@ -241,3 +230,2 @@ return typeof value === "string" && validateOptions.test(value);

*/
$where: function $where(validateOptions, value, key, valueOwner) {

@@ -249,3 +237,2 @@ return validateOptions.call(value, value, key, valueOwner);

*/
$elemMatch: function $elemMatch(validateOptions, value, key, valueOwner) {

@@ -255,2 +242,3 @@ if (isArray(value)) {

}
return _validate(validateOptions, value, key, valueOwner);

@@ -261,3 +249,2 @@ },

*/
$exists: function $exists(validateOptions, value, key, valueOwner) {

@@ -267,3 +254,2 @@ return valueOwner.hasOwnProperty(key) === validateOptions;

};
/**

@@ -275,3 +261,2 @@ */

*/
$eq: function $eq(query, queryOwner, _ref) {

@@ -303,7 +288,5 @@ var comparable = _ref.comparable,

},
$gt: function $gt(query, queryOwner, _ref2) {
var comparable = _ref2.comparable,
compare = _ref2.compare;
return function(value) {

@@ -313,7 +296,5 @@ return compare(comparable(value), comparable(query)) > 0;

},
$gte: function $gte(query, queryOwner, _ref3) {
var comparable = _ref3.comparable,
compare = _ref3.compare;
return function(value) {

@@ -323,7 +304,5 @@ return compare(comparable(value), comparable(query)) >= 0;

},
$lt: function $lt(query, queryOwner, _ref4) {
var comparable = _ref4.comparable,
compare = _ref4.compare;
return function(value) {

@@ -336,3 +315,2 @@ return compare(comparable(value), comparable(query)) < 0;

compare = _ref5.compare;
return function(value) {

@@ -342,6 +320,4 @@ return compare(comparable(value), comparable(query)) <= 0;

},
$in: function $in(query, queryOwner, options) {
var comparable = options.comparable;
return function(value) {

@@ -356,7 +332,4 @@ if (value instanceof Array) {

var comparableValue = comparable(value);
if (
comparableValue === value &&
(typeof value === "undefined" ? "undefined" : _typeof(value)) ===
"object"
) {
if (comparableValue === value && _typeof(value) === "object") {
for (var i = query.length; i--; ) {

@@ -371,3 +344,2 @@ if (

}
/*

@@ -377,2 +349,3 @@ Handles documents that are undefined, whilst also

*/
if (typeof comparableValue == "undefined") {

@@ -385,9 +358,11 @@ for (var i = query.length; i--; ) {

}
/*
Handles the case of {'field': {$in: [/regexp1/, /regexp2/, ...]}}
*/
for (var i = query.length; i--; ) {
var validator = createRootValidator(get(query, i), options);
var result = _validate(validator, comparableValue, i, query);
if (

@@ -408,3 +383,2 @@ result &&

},
$nin: function $nin(query, queryOwner, options) {

@@ -416,3 +390,2 @@ var eq = prepare.$in(query, queryOwner, options);

},
$mod: function $mod(query) {

@@ -426,3 +399,2 @@ return function(value) {

*/
$ne: function $ne(query, queryOwner, options) {

@@ -437,3 +409,2 @@ var eq = prepare.$eq(query, queryOwner, options);

*/
$and: function $and(query, queryOwner, options) {

@@ -445,3 +416,2 @@ return query.map(parse(options));

*/
$all: function $all(query, queryOwner, options) {

@@ -453,3 +423,2 @@ return prepare.$and(query, queryOwner, options);

*/
$or: function $or(query, queryOwner, options) {

@@ -461,3 +430,2 @@ return query.map(parse(options));

*/
$nor: function $nor(query, queryOwner, options) {

@@ -469,3 +437,2 @@ return query.map(parse(options));

*/
$not: function $not(query, queryOwner, options) {

@@ -477,3 +444,2 @@ var validateOptions = parse(options)(query);

},
$type: function $type(query) {

@@ -489,3 +455,2 @@ return function(value, key, valueOwner) {

*/
$regex: function $regex(query, queryOwner) {

@@ -497,3 +462,2 @@ return new RegExp(query, queryOwner.$options);

*/
$where: function $where(query) {

@@ -515,3 +479,2 @@ if (typeof query === "function") {

*/
$elemMatch: function $elemMatch(query, queryOwner, options) {

@@ -523,3 +486,2 @@ return parse(options)(query);

*/
$exists: function $exists(query) {

@@ -529,3 +491,2 @@ return !!query;

};
/**

@@ -537,2 +498,3 @@ */

var result = get(array, i);
if (_validate(validator, get(array, i))) {

@@ -545,3 +507,2 @@ return i;

}
/**

@@ -551,5 +512,7 @@ */

function createValidator(options, validate) {
return { options: options, validate: validate };
return {
options: options,
validate: validate
};
}
/**

@@ -562,3 +525,2 @@ */

query = _ref6.query;
var values = [];

@@ -570,10 +532,12 @@ findValues(value, keyPath, 0, value, values);

return _validate(child, first[0], first[1], first[2]);
}
} // If the query contains $ne, need to test all elements ANDed together
// If the query contains $ne, need to test all elements ANDed together
var inclusive = query && typeof query.$ne !== "undefined";
var allValid = inclusive;
for (var i = 0; i < values.length; i++) {
var result = values[i];
var isValid = _validate(child, result[0], result[1], result[2]);
if (inclusive) {

@@ -585,5 +549,5 @@ allValid &= isValid;

}
return allValid;
}
/**

@@ -598,7 +562,6 @@ */

var k = get(keypath, index);
// ensure that if current is an array, that the current key
var k = get(keypath, index); // ensure that if current is an array, that the current key
// is NOT an array index. This sort of thing needs to work:
// sift({'foo.0':42}, [{foo: [42]}]);
if (isArray(current) && isNaN(Number(k))) {

@@ -612,3 +575,2 @@ for (var i = 0, n = current.length; i < n; i++) {

}
/**

@@ -619,7 +581,10 @@ */

return createValidator(
{ keyPath: keyPath, child: child, query: query },
{
keyPath: keyPath,
child: child,
query: query
},
validatedNested
);
}
/**

@@ -646,4 +611,7 @@ * flatten the query

if (!query || !isVanillaObject(query)) {
query = { $eq: query };
query = {
$eq: query
};
}
return query;

@@ -654,3 +622,2 @@ };

query = comparable(query);
var validators = [];

@@ -672,2 +639,3 @@

}
validators.push(createValidator(comparable(queryValue), expression));

@@ -680,3 +648,2 @@ } else {

var keyParts = key.split(".");
validators.push(

@@ -695,5 +662,7 @@ createNestedValidator(keyParts, parseNested(queryValue), queryValue)

query = wrapQuery(query);
if (isExactObject(query)) {
return createValidator(query, isEqual);
}
return parseQuery(query);

@@ -730,2 +699,3 @@ };

}
for (var i = 0, n = a.length; i < n; i++) {

@@ -747,2 +717,3 @@ if (!isEqual(a[i], b[i])) {

}
for (var key in value) {

@@ -752,2 +723,3 @@ keys.push(key);

}
return keys;

@@ -760,3 +732,2 @@ }

}
/**

@@ -767,2 +738,3 @@ */

var validator = parse(options)(query);
if (options && options.select) {

@@ -781,5 +753,5 @@ validator = {

}
return validator;
}
/**

@@ -790,3 +762,6 @@ */

options = Object.assign(
{ compare: compare, comparable: comparable },
{
compare: compare,
comparable: comparable
},
options

@@ -799,3 +774,2 @@ );

}
/**

@@ -806,9 +780,8 @@ */

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

@@ -819,3 +792,2 @@ return -1;

}
/**

@@ -822,0 +794,0 @@ */

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

@@ -13,3 +13,6 @@ "author": {

"engines": {},
"dependencies": {},
"dependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5"
},
"typings": "./index.d.ts",

@@ -22,6 +25,4 @@ "husky": {

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-loose": "^8.0.0",
"@babel/preset-env": "^7.7.6",
"@babel/register": "^7.7.4",
"bson": "^3.0.2",

@@ -47,4 +48,4 @@ "eval": "^0.1.3",

"build:watch": "mkdir -p lib; babel --watch src/index.js --out-file=lib/index.js",
"test": "mocha ./test -R spec --compilers js:babel-core/register"
"test": "mocha ./test -R spec --compilers js:@babel/register"
}
}

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