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 11.0.0 to 11.0.1

472

lib/core.js
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
var __extends =
(this && this.__extends) ||
(function() {
var extendStatics = function(d, b) {
extendStatics =
Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array &&
function(d, b) {
d.__proto__ = b;
}) ||
function(d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
return function(d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype =
b === null
? Object.create(b)
: ((__.prototype = b.prototype), new __());
};
})();
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
})();
var __spreadArrays =
(this && this.__spreadArrays) ||
function() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -28,210 +44,262 @@ var utils_1 = require("./utils");

*/
var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
var currentKey = keyPath[depth];
// if array, then try matching. Might fall through for cases like:
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
if (utils_1.isArray(item) && isNaN(Number(currentKey))) {
for (var i = 0, length_1 = item.length; i < length_1; i++) {
// if FALSE is returned, then terminate walker. For operations, this simply
// means that the search critera was met.
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
return false;
}
}
var walkKeyPathValues = function(item, keyPath, next, depth, key, owner) {
var currentKey = keyPath[depth];
// if array, then try matching. Might fall through for cases like:
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
if (utils_1.isArray(item) && isNaN(Number(currentKey))) {
for (var i = 0, length_1 = item.length; i < length_1; i++) {
// if FALSE is returned, then terminate walker. For operations, this simply
// means that the search critera was met.
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
return false;
}
}
if (depth === keyPath.length || item == null) {
return next(item, key, owner);
}
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
}
if (depth === keyPath.length || item == null) {
return next(item, key, owner);
}
return walkKeyPathValues(
item[currentKey],
keyPath,
next,
depth + 1,
currentKey,
item
);
};
var BaseOperation = /** @class */ (function () {
function BaseOperation(params, owneryQuery, options) {
this.params = params;
this.owneryQuery = owneryQuery;
this.options = options;
this.init();
}
BaseOperation.prototype.init = function () { };
BaseOperation.prototype.reset = function () {
this.done = false;
this.success = false;
};
return BaseOperation;
}());
var BaseOperation = /** @class */ (function() {
function BaseOperation(params, owneryQuery, options) {
this.params = params;
this.owneryQuery = owneryQuery;
this.options = options;
this.init();
}
BaseOperation.prototype.init = function() {};
BaseOperation.prototype.reset = function() {
this.done = false;
this.success = false;
};
return BaseOperation;
})();
exports.BaseOperation = BaseOperation;
var GroupOperation = /** @class */ (function (_super) {
__extends(GroupOperation, _super);
function GroupOperation(params, owneryQuery, options, _children) {
var _this = _super.call(this, params, owneryQuery, options) || this;
_this._children = _children;
return _this;
var GroupOperation = /** @class */ (function(_super) {
__extends(GroupOperation, _super);
function GroupOperation(params, owneryQuery, options, _children) {
var _this = _super.call(this, params, owneryQuery, options) || this;
_this._children = _children;
return _this;
}
/**
*/
GroupOperation.prototype.reset = function() {
this.success = false;
this.done = false;
for (var i = 0, length_2 = this._children.length; i < length_2; i++) {
this._children[i].reset();
}
/**
*/
GroupOperation.prototype.reset = function () {
this.success = false;
this.done = false;
for (var i = 0, length_2 = this._children.length; i < length_2; i++) {
this._children[i].reset();
};
/**
*/
GroupOperation.prototype.childrenNext = function(item, key, owner) {
var done = true;
var success = true;
for (var i = 0, length_3 = this._children.length; i < length_3; i++) {
var childOperation = this._children[i];
childOperation.next(item, key, owner);
if (!childOperation.success) {
success = false;
}
if (childOperation.done) {
if (!childOperation.success) {
break;
}
};
/**
*/
GroupOperation.prototype.childrenNext = function (item, key, owner) {
var done = true;
var success = true;
for (var i = 0, length_3 = this._children.length; i < length_3; i++) {
var childOperation = this._children[i];
childOperation.next(item, key, owner);
if (!childOperation.success) {
success = false;
}
if (childOperation.done) {
if (!childOperation.success) {
break;
}
}
else {
done = false;
}
}
this.done = done;
this.success = success;
};
return GroupOperation;
}(BaseOperation));
} else {
done = false;
}
}
this.done = done;
this.success = success;
};
return GroupOperation;
})(BaseOperation);
exports.GroupOperation = GroupOperation;
var QueryOperation = /** @class */ (function (_super) {
__extends(QueryOperation, _super);
function QueryOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
*/
QueryOperation.prototype.next = function (item, key, parent) {
this.childrenNext(item, key, parent);
};
return QueryOperation;
}(GroupOperation));
var QueryOperation = /** @class */ (function(_super) {
__extends(QueryOperation, _super);
function QueryOperation() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
/**
*/
QueryOperation.prototype.next = function(item, key, parent) {
this.childrenNext(item, key, parent);
};
return QueryOperation;
})(GroupOperation);
exports.QueryOperation = QueryOperation;
var NestedOperation = /** @class */ (function (_super) {
__extends(NestedOperation, _super);
function NestedOperation(keyPath, params, owneryQuery, options, children) {
var _this = _super.call(this, params, owneryQuery, options, children) || this;
_this.keyPath = keyPath;
/**
*/
_this._nextNestedValue = function (value, key, owner) {
_this.childrenNext(value, key, owner);
return !_this.done;
};
return _this;
}
var NestedOperation = /** @class */ (function(_super) {
__extends(NestedOperation, _super);
function NestedOperation(keyPath, params, owneryQuery, options, children) {
var _this =
_super.call(this, params, owneryQuery, options, children) || this;
_this.keyPath = keyPath;
/**
*/
NestedOperation.prototype.next = function (item, key, parent) {
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
_this._nextNestedValue = function(value, key, owner) {
_this.childrenNext(value, key, owner);
return !_this.done;
};
return NestedOperation;
}(GroupOperation));
return _this;
}
/**
*/
NestedOperation.prototype.next = function(item, key, parent) {
walkKeyPathValues(
item,
this.keyPath,
this._nextNestedValue,
0,
key,
parent
);
};
return NestedOperation;
})(GroupOperation);
exports.NestedOperation = NestedOperation;
exports.createTester = function (a, compare) {
if (a instanceof Function) {
return a;
}
if (a instanceof RegExp) {
return function (b) { return typeof b === "string" && a.test(b); };
}
var comparableA = utils_1.comparable(a);
return function (b) { return compare(comparableA, utils_1.comparable(b)); };
exports.createTester = function(a, compare) {
if (a instanceof Function) {
return a;
}
if (a instanceof RegExp) {
return function(b) {
return typeof b === "string" && a.test(b);
};
}
var comparableA = utils_1.comparable(a);
return function(b) {
return compare(comparableA, utils_1.comparable(b));
};
};
var EqualsOperation = /** @class */ (function (_super) {
__extends(EqualsOperation, _super);
function EqualsOperation() {
return _super !== null && _super.apply(this, arguments) || this;
var EqualsOperation = /** @class */ (function(_super) {
__extends(EqualsOperation, _super);
function EqualsOperation() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
EqualsOperation.prototype.init = function() {
this._test = exports.createTester(this.params, this.options.compare);
};
EqualsOperation.prototype.next = function(item, key, parent) {
if (this._test(item, key, parent)) {
this.done = true;
this.success = true;
}
EqualsOperation.prototype.init = function () {
this._test = exports.createTester(this.params, this.options.compare);
};
EqualsOperation.prototype.next = function (item, key, parent) {
if (this._test(item, key, parent)) {
this.done = true;
this.success = true;
}
};
return EqualsOperation;
}(BaseOperation));
};
return EqualsOperation;
})(BaseOperation);
exports.EqualsOperation = EqualsOperation;
var NopeOperation = /** @class */ (function (_super) {
__extends(NopeOperation, _super);
function NopeOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
NopeOperation.prototype.next = function () {
this.done = true;
this.success = false;
};
return NopeOperation;
}(BaseOperation));
var NopeOperation = /** @class */ (function(_super) {
__extends(NopeOperation, _super);
function NopeOperation() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
NopeOperation.prototype.next = function() {
this.done = true;
this.success = false;
};
return NopeOperation;
})(BaseOperation);
exports.NopeOperation = NopeOperation;
exports.numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options) {
exports.numericalOperationCreator = function(createNumericalOperation) {
return function(params, owneryQuery, options) {
return params == null
? new NopeOperation(params, owneryQuery, options)
: createNumericalOperation(params, owneryQuery, options);
}; };
var createOperation = function (name, params, parentQuery, options) {
var operationCreator = options.operations[name];
if (!operationCreator) {
throw new Error("Unsupported operation: " + name);
}
return operationCreator(params, parentQuery, options);
? new NopeOperation(params, owneryQuery, options)
: createNumericalOperation(params, owneryQuery, options);
};
};
var containsOperation = function (query) {
for (var key in query) {
if (key.charAt(0) === "$")
return true;
}
return false;
var createOperation = function(name, params, parentQuery, options) {
var operationCreator = options.operations[name];
if (!operationCreator) {
throw new Error("Unsupported operation: " + name);
}
return operationCreator(params, parentQuery, options);
};
var createNestedOperation = function (keyPath, nestedQuery, owneryQuery, options) {
if (containsOperation(nestedQuery)) {
var _a = createQueryOperations(nestedQuery, options), selfOperations = _a[0], nestedOperations = _a[1];
if (nestedOperations.length) {
throw new Error("Property queries must contain only operations, or exact objects.");
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
new EqualsOperation(nestedQuery, owneryQuery, options)
]);
var containsOperation = function(query) {
for (var key in query) {
if (key.charAt(0) === "$") return true;
}
return false;
};
exports.createQueryOperation = function (query, owneryQuery, options) {
var _a = createQueryOperations(query, options), selfOperations = _a[0], nestedOperations = _a[1];
var ops = __spreadArrays([
new NestedOperation([], query, owneryQuery, options, selfOperations)
], nestedOperations);
if (ops.length === 1) {
return ops[0];
var createNestedOperation = function(
keyPath,
nestedQuery,
owneryQuery,
options
) {
if (containsOperation(nestedQuery)) {
var _a = createQueryOperations(nestedQuery, options),
selfOperations = _a[0],
nestedOperations = _a[1];
if (nestedOperations.length) {
throw new Error(
"Property queries must contain only operations, or exact objects."
);
}
return new QueryOperation(query, owneryQuery, options, ops);
return new NestedOperation(
keyPath,
nestedQuery,
owneryQuery,
options,
selfOperations
);
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
new EqualsOperation(nestedQuery, owneryQuery, options)
]);
};
var createQueryOperations = function (query, options) {
var selfOperations = [];
var nestedOperations = [];
if (!utils_1.isVanillaObject(query)) {
query = { $eq: query };
exports.createQueryOperation = function(query, owneryQuery, options) {
var _a = createQueryOperations(query, options),
selfOperations = _a[0],
nestedOperations = _a[1];
var ops = __spreadArrays(
[new NestedOperation([], query, owneryQuery, options, selfOperations)],
nestedOperations
);
if (ops.length === 1) {
return ops[0];
}
return new QueryOperation(query, owneryQuery, options, ops);
};
var createQueryOperations = function(query, options) {
var selfOperations = [];
var nestedOperations = [];
if (!utils_1.isVanillaObject(query)) {
query = { $eq: query };
}
for (var key in query) {
if (key.charAt(0) === "$") {
var op = createOperation(key, query[key], query, options);
// probably just a flag for another operation (like $options)
if (op != null) {
selfOperations.push(op);
}
} else {
nestedOperations.push(
createNestedOperation(key.split("."), query[key], query, options)
);
}
for (var key in query) {
if (key.charAt(0) === "$") {
var op = createOperation(key, query[key], query, options);
// probably just a flag for another operation (like $options)
if (op != null) {
selfOperations.push(op);
}
}
else {
nestedOperations.push(createNestedOperation(key.split("."), query[key], query, options));
}
}
return [selfOperations, nestedOperations];
}
return [selfOperations, nestedOperations];
};
exports.createQueryTester = function(query, _a) {
var _b = _a === void 0 ? {} : _a,
compare = _b.compare,
operations = _b.operations;
var operation = exports.createQueryOperation(query, null, {
compare: compare || utils_1.equals,
operations: Object.assign({}, operations || {})
});
return function(item, key, owner) {
operation.reset();
operation.next(item, key, owner);
return operation.success;
};
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var operations_1 = require("./operations");
var defaultOperations = require("./operations");
var core_1 = require("./core");
exports.EqualsOperation = core_1.EqualsOperation;
var utils_1 = require("./utils");
var createRootTester = function (query, _a) {
var createDefaultQueryTester = function (query, _a) {
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
var operation = core_1.createQueryOperation(query, null, {
compare: compare || utils_1.equals,
operations: Object.assign({}, operations_1.creators, operations || {})
return core_1.createQueryTester(query, {
compare: compare,
operations: Object.assign({}, defaultOperations, operations || {})
});
return function (item, key, owner) {
operation.reset();
operation.next(item, key, owner);
return operation.success;
};
};
exports.default = createRootTester;
module.exports = createDefaultQueryTester;
exports.default = createDefaultQueryTester;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
var __extends =
(this && this.__extends) ||
(function() {
var extendStatics = function(d, b) {
extendStatics =
Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array &&
function(d, b) {
d.__proto__ = b;
}) ||
function(d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
return function(d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype =
b === null
? Object.create(b)
: ((__.prototype = b.prototype), new __());
};
})();
})();
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("./core");
var utils_1 = require("./utils");
var $Ne = /** @class */ (function (_super) {
__extends($Ne, _super);
function $Ne() {
return _super !== null && _super.apply(this, arguments) || this;
var $Ne = /** @class */ (function(_super) {
__extends($Ne, _super);
function $Ne() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
$Ne.prototype.init = function() {
this._test = core_1.createTester(this.params, this.options.compare);
};
$Ne.prototype.reset = function() {
_super.prototype.reset.call(this);
this.success = true;
};
$Ne.prototype.next = function(item) {
if (this._test(item)) {
this.done = true;
this.success = false;
}
$Ne.prototype.init = function () {
this._test = core_1.createTester(this.params, this.options.compare);
};
$Ne.prototype.reset = function () {
_super.prototype.reset.call(this);
this.success = true;
};
$Ne.prototype.next = function (item) {
if (this._test(item)) {
this.done = true;
this.success = false;
}
};
return $Ne;
}(core_1.BaseOperation));
var $ElemMatch = /** @class */ (function (_super) {
__extends($ElemMatch, _super);
function $ElemMatch() {
return _super !== null && _super.apply(this, arguments) || this;
};
return $Ne;
})(core_1.BaseOperation);
var $ElemMatch = /** @class */ (function(_super) {
__extends($ElemMatch, _super);
function $ElemMatch() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
$ElemMatch.prototype.init = function() {
this._queryOperation = core_1.createQueryOperation(
this.params,
this.owneryQuery,
this.options
);
};
$ElemMatch.prototype.reset = function() {
this._queryOperation.reset();
};
$ElemMatch.prototype.next = function(item, key, owner) {
this._queryOperation.next(item, key, owner);
this.done = this._queryOperation.done;
this.success = this._queryOperation.success;
};
return $ElemMatch;
})(core_1.BaseOperation);
var $Not = /** @class */ (function(_super) {
__extends($Not, _super);
function $Not() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
$Not.prototype.next = function(item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Not;
})($ElemMatch);
var $Or = /** @class */ (function(_super) {
__extends($Or, _super);
function $Or() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
$Or.prototype.init = function() {
var _this = this;
this._ops = this.params.map(function(op) {
return core_1.createQueryOperation(op, null, _this.options);
});
};
$Or.prototype.reset = function() {
this.done = false;
this.success = false;
for (var i = 0, length_1 = this._ops.length; i < length_1; i++) {
this._ops[i].reset();
}
$ElemMatch.prototype.init = function () {
this._queryOperation = core_1.createQueryOperation(this.params, this.owneryQuery, this.options);
};
$ElemMatch.prototype.reset = function () {
this._queryOperation.reset();
};
$ElemMatch.prototype.next = function (item, key, owner) {
this._queryOperation.next(item, key, owner);
this.done = this._queryOperation.done;
this.success = this._queryOperation.success;
};
return $ElemMatch;
}(core_1.BaseOperation));
var $Not = /** @class */ (function (_super) {
__extends($Not, _super);
function $Not() {
return _super !== null && _super.apply(this, arguments) || this;
};
$Or.prototype.next = function(item, key, owner) {
var done = false;
var success = false;
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
var op = this._ops[i];
op.next(item, key, owner);
if (op.success) {
done = true;
success = op.success;
break;
}
}
$Not.prototype.next = function (item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Not;
}($ElemMatch));
var $Or = /** @class */ (function (_super) {
__extends($Or, _super);
function $Or() {
return _super !== null && _super.apply(this, arguments) || this;
this.success = success;
this.done = done;
};
return $Or;
})(core_1.BaseOperation);
var $Nor = /** @class */ (function(_super) {
__extends($Nor, _super);
function $Nor() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
$Nor.prototype.next = function(item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Nor;
})($Or);
var $Exists = /** @class */ (function(_super) {
__extends($Exists, _super);
function $Exists() {
return (_super !== null && _super.apply(this, arguments)) || this;
}
$Exists.prototype.next = function(item, key, owner) {
if (owner.hasOwnProperty(key) === this.params) {
this.done = true;
this.success = true;
}
$Or.prototype.init = function () {
var _this = this;
this._ops = this.params.map(function (op) {
return core_1.createQueryOperation(op, null, _this.options);
});
};
$Or.prototype.reset = function () {
this.done = false;
this.success = false;
for (var i = 0, length_1 = this._ops.length; i < length_1; i++) {
this._ops[i].reset();
}
};
$Or.prototype.next = function (item, key, owner) {
var done = false;
var success = false;
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
var op = this._ops[i];
op.next(item, key, owner);
if (op.success) {
done = true;
success = op.success;
break;
}
}
this.success = success;
this.done = done;
};
return $Or;
}(core_1.BaseOperation));
var $Nor = /** @class */ (function (_super) {
__extends($Nor, _super);
function $Nor() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Nor.prototype.next = function (item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Nor;
}($Or));
var $Exists = /** @class */ (function (_super) {
__extends($Exists, _super);
function $Exists() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Exists.prototype.next = function (item, key, owner) {
if (owner.hasOwnProperty(key) === this.params) {
this.done = true;
this.success = true;
}
};
return $Exists;
}(core_1.BaseOperation));
var $And = /** @class */ (function (_super) {
__extends($And, _super);
function $And(params, owneryQuery, options) {
return _super.call(this, params, owneryQuery, options, params.map(function (query) { return core_1.createQueryOperation(query, owneryQuery, options); })) || this;
}
$And.prototype.next = function (item, key, owner) {
this.childrenNext(item, key, owner);
};
return $And;
}(core_1.GroupOperation));
var $eq = function (params, owneryQuery, options) {
return new core_1.EqualsOperation(params, owneryQuery, options);
};
return $Exists;
})(core_1.BaseOperation);
var $And = /** @class */ (function(_super) {
__extends($And, _super);
function $And(params, owneryQuery, options) {
return (
_super.call(
this,
params,
owneryQuery,
options,
params.map(function(query) {
return core_1.createQueryOperation(query, owneryQuery, options);
})
) || this
);
}
$And.prototype.next = function(item, key, owner) {
this.childrenNext(item, key, owner);
};
return $And;
})(core_1.GroupOperation);
exports.$eq = function(params, owneryQuery, options) {
return new core_1.EqualsOperation(params, owneryQuery, options);
};
var $ne = function (params, owneryQuery, options) {
return new $Ne(params, owneryQuery, options);
exports.$ne = function(params, owneryQuery, options) {
return new $Ne(params, owneryQuery, options);
};
var $or = function (params, owneryQuery, options) {
return new $Or(params, owneryQuery, options);
exports.$or = function(params, owneryQuery, options) {
return new $Or(params, owneryQuery, options);
};
var $nor = function (params, owneryQuery, options) {
return new $Nor(params, owneryQuery, options);
exports.$nor = function(params, owneryQuery, options) {
return new $Nor(params, owneryQuery, options);
};
var $elemMatch = function (params, owneryQuery, options) {
return new $ElemMatch(params, owneryQuery, options);
exports.$elemMatch = function(params, owneryQuery, options) {
return new $ElemMatch(params, owneryQuery, options);
};
var $nin = function (params, owneryQuery, options) {
return new $Nor(params, owneryQuery, options);
exports.$nin = function(params, owneryQuery, options) {
return new $Nor(params, owneryQuery, options);
};
var $in = function (params, owneryQuery, options) {
return new $Or(params, owneryQuery, options);
exports.$in = function(params, owneryQuery, options) {
return new $Or(params, owneryQuery, options);
};
var $lt = core_1.numericalOperationCreator(function (params, owneryQuery, options) {
return new core_1.EqualsOperation(function (b) { return b < params; }, owneryQuery, options);
exports.$lt = core_1.numericalOperationCreator(function(
params,
owneryQuery,
options
) {
return new core_1.EqualsOperation(
function(b) {
return b < params;
},
owneryQuery,
options
);
});
var $lte = core_1.numericalOperationCreator(function (params, owneryQuery, options) {
return new core_1.EqualsOperation(function (b) { return b <= params; }, owneryQuery, options);
exports.$lte = core_1.numericalOperationCreator(function(
params,
owneryQuery,
options
) {
return new core_1.EqualsOperation(
function(b) {
return b <= params;
},
owneryQuery,
options
);
});
var $gt = core_1.numericalOperationCreator(function (params, owneryQuery, options) {
return new core_1.EqualsOperation(function (b) { return b > params; }, owneryQuery, options);
exports.$gt = core_1.numericalOperationCreator(function(
params,
owneryQuery,
options
) {
return new core_1.EqualsOperation(
function(b) {
return b > params;
},
owneryQuery,
options
);
});
var $gte = core_1.numericalOperationCreator(function (params, owneryQuery, options) {
return new core_1.EqualsOperation(function (b) { return b >= params; }, owneryQuery, options);
exports.$gte = core_1.numericalOperationCreator(function(
params,
owneryQuery,
options
) {
return new core_1.EqualsOperation(
function(b) {
return b >= params;
},
owneryQuery,
options
);
});
var $mod = function (_a, owneryQuery, options) {
var mod = _a[0], equalsValue = _a[1];
return new core_1.EqualsOperation(function (b) { return utils_1.comparable(b) % mod === equalsValue; }, owneryQuery, options);
exports.$mod = function(_a, owneryQuery, options) {
var mod = _a[0],
equalsValue = _a[1];
return new core_1.EqualsOperation(
function(b) {
return utils_1.comparable(b) % mod === equalsValue;
},
owneryQuery,
options
);
};
var $exists = function (params, owneryQuery, options) {
return new $Exists(params, owneryQuery, options);
exports.$exists = function(params, owneryQuery, options) {
return new $Exists(params, owneryQuery, options);
};
var $regex = function (pattern, owneryQuery, options) {
return new core_1.EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
exports.$regex = function(pattern, owneryQuery, options) {
return new core_1.EqualsOperation(
new RegExp(pattern, owneryQuery.$options),
owneryQuery,
options
);
};
var $not = function (params, owneryQuery, options) {
return new $Not(params, owneryQuery, options);
exports.$not = function(params, owneryQuery, options) {
return new $Not(params, owneryQuery, options);
};
var $type = function (clazz, owneryQuery, options) {
return new core_1.EqualsOperation(function (b) { return (b != null ? b instanceof clazz || b.constructor === clazz : false); }, owneryQuery, options);
exports.$type = function(clazz, owneryQuery, options) {
return new core_1.EqualsOperation(
function(b) {
return b != null ? b instanceof clazz || b.constructor === clazz : false;
},
owneryQuery,
options
);
};
var $and = function (params, ownerQuery, options) {
return new $And(params, ownerQuery, options);
exports.$and = function(params, ownerQuery, options) {
return new $And(params, ownerQuery, options);
};
var $all = $and;
var $size = function (params, ownerQuery, options) {
return new core_1.EqualsOperation(function (b) { return b && b.length === params; }, ownerQuery, options);
exports.$all = exports.$and;
exports.$size = function(params, ownerQuery, options) {
return new core_1.EqualsOperation(
function(b) {
return b && b.length === params;
},
ownerQuery,
options
);
};
var $options = function () { return null; };
var $where = function (params, ownerQuery, options) {
var test;
if (utils_1.isFunction(params)) {
test = params;
}
else if (!process.env.CSP_ENABLED) {
test = new Function("obj", "return " + params);
}
else {
throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
}
return new core_1.EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
exports.$options = function() {
return null;
};
exports.creators = {
$lt: $lt,
$lte: $lte,
$mod: $mod,
$gt: $gt,
$gte: $gte,
$eq: $eq,
$or: $or,
$nor: $nor,
$and: $and,
$options: $options,
$regex: $regex,
$ne: $ne,
$nin: $nin,
$all: $all,
$size: $size,
$in: $in,
$type: $type,
$elemMatch: $elemMatch,
$exists: $exists,
$not: $not,
$where: $where
exports.$where = function(params, ownerQuery, options) {
var test;
if (utils_1.isFunction(params)) {
test = params;
} else if (!process.env.CSP_ENABLED) {
test = new Function("obj", "return " + params);
} else {
throw new Error(
'In CSP mode, sift does not support strings in "$where" condition'
);
}
return new core_1.EqualsOperation(
function(b) {
return test.bind(b)(b);
},
ownerQuery,
options
);
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.typeChecker = function (type) {
var typeString = "[object " + type + "]";
return function (value) {
return getClassName(value) === typeString;
};
exports.typeChecker = function(type) {
var typeString = "[object " + type + "]";
return function(value) {
return getClassName(value) === typeString;
};
};
var getClassName = function (value) { return Object.prototype.toString.call(value); };
exports.comparable = function (value) {
if (value instanceof Date) {
return value.getTime();
}
else if (exports.isArray(value)) {
return value.map(exports.comparable);
}
else if (value && typeof value.toJSON === "function") {
return value.toJSON();
}
return value;
var getClassName = function(value) {
return Object.prototype.toString.call(value);
};
exports.comparable = function(value) {
if (value instanceof Date) {
return value.getTime();
} else if (exports.isArray(value)) {
return value.map(exports.comparable);
} else if (value && typeof value.toJSON === "function") {
return value.toJSON();
}
return value;
};
exports.isArray = exports.typeChecker("Array");
exports.isObject = exports.typeChecker("Object");
exports.isFunction = exports.typeChecker("Function");
exports.isVanillaObject = function (value) {
return (value &&
(value.constructor === Object ||
value.constructor === Array ||
value.constructor.toString() === "function Object() { [native code] }" ||
value.constructor.toString() === "function Array() { [native code] }") &&
!value.toJSON);
exports.isVanillaObject = function(value) {
return (
value &&
(value.constructor === Object ||
value.constructor === Array ||
value.constructor.toString() === "function Object() { [native code] }" ||
value.constructor.toString() === "function Array() { [native code] }") &&
!value.toJSON
);
};
exports.equals = function (a, b) {
if (a == null && a == b) {
return true;
exports.equals = function(a, b) {
if (a == null && a == b) {
return true;
}
if (a === b) {
return true;
}
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
return false;
}
if (exports.isArray(a)) {
if (a.length !== b.length) {
return false;
}
if (a === b) {
return true;
for (var i = 0, length_1 = a.length; i < length_1; i++) {
if (!exports.equals(a[i], b[i])) return false;
}
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
return false;
return true;
} else if (exports.isObject(a)) {
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
if (exports.isArray(a)) {
if (a.length !== b.length) {
return false;
}
for (var i = 0, length_1 = a.length; i < length_1; i++) {
if (!exports.equals(a[i], b[i]))
return false;
}
return true;
for (var key in a) {
if (!exports.equals(a[key], b[key])) return false;
}
else if (exports.isObject(a)) {
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
for (var key in a) {
if (!exports.equals(a[key], b[key]))
return false;
}
return true;
}
return false;
return true;
}
return false;
};
{
"name": "sift",
"description": "mongodb query style array filtering",
"version": "11.0.0",
"version": "11.0.1",
"repository": "crcn/sift.js",

@@ -21,5 +21,5 @@ "author": {

"devDependencies": {
"@babel/register": "^7.7.4",
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"@babel/register": "^7.7.4",
"@types/node": "^13.1.5",

@@ -26,0 +26,0 @@ "bson": "^3.0.2",

@@ -105,19 +105,2 @@ **Installation**: `npm install sift`, or `yarn add sift`

With a selector:
```javascript
var omitNameFilter = sift({ $exists: true }, function(user) {
return !!user.name;
});
[
{
name: "Craig"
},
{
name: null
}
].filter(omitNameFilter);
```
With your sifter, you can also **test** values:

@@ -416,8 +399,4 @@

## MongoDB behavior differences
## Custom behavior
There are some cases where Sift behaves a bit differently than Mongodb.
## Adding custom behavior
Sift works like MongoDB out of the box, but you're also able to modify the behavior to suite your needs.

@@ -427,6 +406,6 @@

Sift comes with expressions like `$not`, `$eq`, and others, but you can also add your own.
You can register your own custom operations. Here's an example:
```javascript
import { EqualsOperation } from "sift";
import sift, { EqualsOperation } from "sift";

@@ -453,11 +432,17 @@ var filter = sift(

<!--#### Custom compare
If you're looking to create a filter _without_ the standard operations, you can also do that:
```javascript
const filter = sift()
import { createQueryTester } from "sift/lib/core";
import * as operations from "sift/lib/operations";
const test = createQueryTester(
{
$eq: 10
},
{ operations }
);
[1, 2, 3, 4, 10].filter(test);
```
#### Custom comparable-->
#### Date comparison

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

@@ -68,60 +68,2 @@ !(function(t, n) {

"use strict";
Object.defineProperty(n, "__esModule", { value: !0 }),
(n.typeChecker = function(t) {
var n = "[object " + t + "]";
return function(t) {
return r(t) === n;
};
});
var r = function(t) {
return Object.prototype.toString.call(t);
};
(n.comparable = function(t) {
return t instanceof Date
? t.getTime()
: n.isArray(t)
? t.map(n.comparable)
: t && "function" == typeof t.toJSON
? t.toJSON()
: t;
}),
(n.isArray = n.typeChecker("Array")),
(n.isObject = n.typeChecker("Object")),
(n.isFunction = n.typeChecker("Function")),
(n.isVanillaObject = function(t) {
return (
t &&
(t.constructor === Object ||
t.constructor === Array ||
"function Object() { [native code] }" ===
t.constructor.toString() ||
"function Array() { [native code] }" ===
t.constructor.toString()) &&
!t.toJSON
);
}),
(n.equals = function(t, e) {
if (null == t && t == e) return !0;
if (t === e) return !0;
if (
Object.prototype.toString.call(t) !==
Object.prototype.toString.call(e)
)
return !1;
if (n.isArray(t)) {
if (t.length !== e.length) return !1;
for (var r = 0, o = t.length; r < o; r++)
if (!n.equals(t[r], e[r])) return !1;
return !0;
}
if (n.isObject(t)) {
if (Object.keys(t).length !== Object.keys(e).length) return !1;
for (var i in t) if (!n.equals(t[i], e[i])) return !1;
return !0;
}
return !1;
});
},
function(t, n, e) {
"use strict";
var r,

@@ -164,3 +106,3 @@ o =

Object.defineProperty(n, "__esModule", { value: !0 });
var u = e(0),
var u = e(1),
s = function(t, n, e, r, o, i) {

@@ -337,4 +279,74 @@ var c = n[r];

};
n.createQueryTester = function(t, e) {
var r = void 0 === e ? {} : e,
o = r.compare,
i = r.operations,
s = n.createQueryOperation(t, null, {
compare: o || u.equals,
operations: Object.assign({}, i || {})
});
return function(t, n, e) {
return s.reset(), s.next(t, n, e), s.success;
};
};
},
function(t, n, e) {
"use strict";
Object.defineProperty(n, "__esModule", { value: !0 }),
(n.typeChecker = function(t) {
var n = "[object " + t + "]";
return function(t) {
return r(t) === n;
};
});
var r = function(t) {
return Object.prototype.toString.call(t);
};
(n.comparable = function(t) {
return t instanceof Date
? t.getTime()
: n.isArray(t)
? t.map(n.comparable)
: t && "function" == typeof t.toJSON
? t.toJSON()
: t;
}),
(n.isArray = n.typeChecker("Array")),
(n.isObject = n.typeChecker("Object")),
(n.isFunction = n.typeChecker("Function")),
(n.isVanillaObject = function(t) {
return (
t &&
(t.constructor === Object ||
t.constructor === Array ||
"function Object() { [native code] }" ===
t.constructor.toString() ||
"function Array() { [native code] }" ===
t.constructor.toString()) &&
!t.toJSON
);
}),
(n.equals = function(t, e) {
if (null == t && t == e) return !0;
if (t === e) return !0;
if (
Object.prototype.toString.call(t) !==
Object.prototype.toString.call(e)
)
return !1;
if (n.isArray(t)) {
if (t.length !== e.length) return !1;
for (var r = 0, o = t.length; r < o; r++)
if (!n.equals(t[r], e[r])) return !1;
return !0;
}
if (n.isObject(t)) {
if (Object.keys(t).length !== Object.keys(e).length) return !1;
for (var i in t) if (!n.equals(t[i], e[i])) return !1;
return !0;
}
return !1;
});
},
function(t, n, e) {
t.exports = e(3);

@@ -346,17 +358,14 @@ },

var r = e(4),
o = e(1);
o = e(0);
n.EqualsOperation = o.EqualsOperation;
var i = e(0);
n.default = function(t, n) {
var i = function(t, n) {
var e = void 0 === n ? {} : n,
u = e.compare,
s = e.operations,
c = o.createQueryOperation(t, null, {
compare: u || i.equals,
operations: Object.assign({}, r.creators, s || {})
});
return function(t, n, e) {
return c.reset(), c.next(t, n, e), c.success;
};
i = e.compare,
u = e.operations;
return o.createQueryTester(t, {
compare: i,
operations: Object.assign({}, { $and: r.$and }, u || {})
});
};
(t.exports = i), (n.default = i);
},

@@ -390,4 +399,4 @@ function(t, n, e) {

Object.defineProperty(n, "__esModule", { value: !0 });
var i = e(1),
u = e(0),
var i = e(0),
u = e(1),
s = (function(t) {

@@ -529,4 +538,25 @@ function n() {

);
})(i.GroupOperation),
y = i.numericalOperationCreator(function(t, n, e) {
})(i.GroupOperation);
(n.$eq = function(t, n, e) {
return new i.EqualsOperation(t, n, e);
}),
(n.$ne = function(t, n, e) {
return new s(t, n, e);
}),
(n.$or = function(t, n, e) {
return new p(t, n, e);
}),
(n.$nor = function(t, n, e) {
return new f(t, n, e);
}),
(n.$elemMatch = function(t, n, e) {
return new c(t, n, e);
}),
(n.$nin = function(t, n, e) {
return new f(t, n, e);
}),
(n.$in = function(t, n, e) {
return new p(t, n, e);
}),
(n.$lt = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -539,4 +569,4 @@ function(n) {

);
}),
O = i.numericalOperationCreator(function(t, n, e) {
})),
(n.$lte = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -549,4 +579,4 @@ function(n) {

);
}),
d = i.numericalOperationCreator(function(t, n, e) {
})),
(n.$gt = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -559,4 +589,4 @@ function(n) {

);
}),
v = i.numericalOperationCreator(function(t, n, e) {
})),
(n.$gte = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -569,11 +599,4 @@ function(n) {

);
}),
_ = function(t, n, e) {
return new h(t, n, e);
},
b = _;
n.creators = {
$lt: y,
$lte: O,
$mod: function(t, n, e) {
})),
(n.$mod = function(t, n, e) {
var r = t[0],

@@ -588,32 +611,16 @@ o = t[1];

);
},
$gt: d,
$gte: v,
$eq: function(t, n, e) {
return new i.EqualsOperation(t, n, e);
},
$or: function(t, n, e) {
return new p(t, n, e);
},
$nor: function(t, n, e) {
return new f(t, n, e);
},
$and: _,
$options: function() {
return null;
},
$regex: function(t, n, e) {
}),
(n.$exists = function(t, n, e) {
return new l(t, n, e);
}),
(n.$regex = function(t, n, e) {
return new i.EqualsOperation(new RegExp(t, n.$options), n, e);
},
$ne: function(t, n, e) {
return new s(t, n, e);
},
$nin: function(t, n, e) {
return new f(t, n, e);
},
$all: b,
$size: function(t, n, e) {
}),
(n.$not = function(t, n, e) {
return new a(t, n, e);
}),
(n.$type = function(t, n, e) {
return new i.EqualsOperation(
function(n) {
return n && n.length === t;
return null != n && (n instanceof t || n.constructor === t);
},

@@ -623,10 +630,11 @@ n,

);
},
$in: function(t, n, e) {
return new p(t, n, e);
},
$type: function(t, n, e) {
}),
(n.$and = function(t, n, e) {
return new h(t, n, e);
}),
(n.$all = n.$and),
(n.$size = function(t, n, e) {
return new i.EqualsOperation(
function(n) {
return null != n && (n instanceof t || n.constructor === t);
return n && n.length === t;
},

@@ -636,13 +644,7 @@ n,

);
},
$elemMatch: function(t, n, e) {
return new c(t, n, e);
},
$exists: function(t, n, e) {
return new l(t, n, e);
},
$not: function(t, n, e) {
return new a(t, n, e);
},
$where: function(t, n, e) {
}),
(n.$options = function() {
return null;
}),
(n.$where = function(t, n, e) {
var r;

@@ -663,4 +665,3 @@ if (!u.isFunction(t))

);
}
};
});
}

@@ -667,0 +668,0 @@ ]);

@@ -68,60 +68,2 @@ !(function(t, n) {

"use strict";
Object.defineProperty(n, "__esModule", { value: !0 }),
(n.typeChecker = function(t) {
var n = "[object " + t + "]";
return function(t) {
return r(t) === n;
};
});
var r = function(t) {
return Object.prototype.toString.call(t);
};
(n.comparable = function(t) {
return t instanceof Date
? t.getTime()
: n.isArray(t)
? t.map(n.comparable)
: t && "function" == typeof t.toJSON
? t.toJSON()
: t;
}),
(n.isArray = n.typeChecker("Array")),
(n.isObject = n.typeChecker("Object")),
(n.isFunction = n.typeChecker("Function")),
(n.isVanillaObject = function(t) {
return (
t &&
(t.constructor === Object ||
t.constructor === Array ||
"function Object() { [native code] }" ===
t.constructor.toString() ||
"function Array() { [native code] }" ===
t.constructor.toString()) &&
!t.toJSON
);
}),
(n.equals = function(t, e) {
if (null == t && t == e) return !0;
if (t === e) return !0;
if (
Object.prototype.toString.call(t) !==
Object.prototype.toString.call(e)
)
return !1;
if (n.isArray(t)) {
if (t.length !== e.length) return !1;
for (var r = 0, o = t.length; r < o; r++)
if (!n.equals(t[r], e[r])) return !1;
return !0;
}
if (n.isObject(t)) {
if (Object.keys(t).length !== Object.keys(e).length) return !1;
for (var i in t) if (!n.equals(t[i], e[i])) return !1;
return !0;
}
return !1;
});
},
function(t, n, e) {
"use strict";
var r,

@@ -164,3 +106,3 @@ o =

Object.defineProperty(n, "__esModule", { value: !0 });
var u = e(0),
var u = e(1),
s = function(t, n, e, r, o, i) {

@@ -337,4 +279,74 @@ var c = n[r];

};
n.createQueryTester = function(t, e) {
var r = void 0 === e ? {} : e,
o = r.compare,
i = r.operations,
s = n.createQueryOperation(t, null, {
compare: o || u.equals,
operations: Object.assign({}, i || {})
});
return function(t, n, e) {
return s.reset(), s.next(t, n, e), s.success;
};
};
},
function(t, n, e) {
"use strict";
Object.defineProperty(n, "__esModule", { value: !0 }),
(n.typeChecker = function(t) {
var n = "[object " + t + "]";
return function(t) {
return r(t) === n;
};
});
var r = function(t) {
return Object.prototype.toString.call(t);
};
(n.comparable = function(t) {
return t instanceof Date
? t.getTime()
: n.isArray(t)
? t.map(n.comparable)
: t && "function" == typeof t.toJSON
? t.toJSON()
: t;
}),
(n.isArray = n.typeChecker("Array")),
(n.isObject = n.typeChecker("Object")),
(n.isFunction = n.typeChecker("Function")),
(n.isVanillaObject = function(t) {
return (
t &&
(t.constructor === Object ||
t.constructor === Array ||
"function Object() { [native code] }" ===
t.constructor.toString() ||
"function Array() { [native code] }" ===
t.constructor.toString()) &&
!t.toJSON
);
}),
(n.equals = function(t, e) {
if (null == t && t == e) return !0;
if (t === e) return !0;
if (
Object.prototype.toString.call(t) !==
Object.prototype.toString.call(e)
)
return !1;
if (n.isArray(t)) {
if (t.length !== e.length) return !1;
for (var r = 0, o = t.length; r < o; r++)
if (!n.equals(t[r], e[r])) return !1;
return !0;
}
if (n.isObject(t)) {
if (Object.keys(t).length !== Object.keys(e).length) return !1;
for (var i in t) if (!n.equals(t[i], e[i])) return !1;
return !0;
}
return !1;
});
},
function(t, n, e) {
t.exports = e(3);

@@ -346,17 +358,14 @@ },

var r = e(4),
o = e(1);
o = e(0);
n.EqualsOperation = o.EqualsOperation;
var i = e(0);
n.default = function(t, n) {
var i = function(t, n) {
var e = void 0 === n ? {} : n,
u = e.compare,
s = e.operations,
c = o.createQueryOperation(t, null, {
compare: u || i.equals,
operations: Object.assign({}, r.creators, s || {})
});
return function(t, n, e) {
return c.reset(), c.next(t, n, e), c.success;
};
i = e.compare,
u = e.operations;
return o.createQueryTester(t, {
compare: i,
operations: Object.assign({}, { $and: r.$and }, u || {})
});
};
(t.exports = i), (n.default = i);
},

@@ -390,4 +399,4 @@ function(t, n, e) {

Object.defineProperty(n, "__esModule", { value: !0 });
var i = e(1),
u = e(0),
var i = e(0),
u = e(1),
s = (function(t) {

@@ -529,4 +538,25 @@ function n() {

);
})(i.GroupOperation),
y = i.numericalOperationCreator(function(t, n, e) {
})(i.GroupOperation);
(n.$eq = function(t, n, e) {
return new i.EqualsOperation(t, n, e);
}),
(n.$ne = function(t, n, e) {
return new s(t, n, e);
}),
(n.$or = function(t, n, e) {
return new p(t, n, e);
}),
(n.$nor = function(t, n, e) {
return new f(t, n, e);
}),
(n.$elemMatch = function(t, n, e) {
return new c(t, n, e);
}),
(n.$nin = function(t, n, e) {
return new f(t, n, e);
}),
(n.$in = function(t, n, e) {
return new p(t, n, e);
}),
(n.$lt = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -539,4 +569,4 @@ function(n) {

);
}),
O = i.numericalOperationCreator(function(t, n, e) {
})),
(n.$lte = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -549,4 +579,4 @@ function(n) {

);
}),
d = i.numericalOperationCreator(function(t, n, e) {
})),
(n.$gt = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -559,4 +589,4 @@ function(n) {

);
}),
v = i.numericalOperationCreator(function(t, n, e) {
})),
(n.$gte = i.numericalOperationCreator(function(t, n, e) {
return new i.EqualsOperation(

@@ -569,11 +599,4 @@ function(n) {

);
}),
_ = function(t, n, e) {
return new h(t, n, e);
},
b = _;
n.creators = {
$lt: y,
$lte: O,
$mod: function(t, n, e) {
})),
(n.$mod = function(t, n, e) {
var r = t[0],

@@ -588,32 +611,16 @@ o = t[1];

);
},
$gt: d,
$gte: v,
$eq: function(t, n, e) {
return new i.EqualsOperation(t, n, e);
},
$or: function(t, n, e) {
return new p(t, n, e);
},
$nor: function(t, n, e) {
return new f(t, n, e);
},
$and: _,
$options: function() {
return null;
},
$regex: function(t, n, e) {
}),
(n.$exists = function(t, n, e) {
return new l(t, n, e);
}),
(n.$regex = function(t, n, e) {
return new i.EqualsOperation(new RegExp(t, n.$options), n, e);
},
$ne: function(t, n, e) {
return new s(t, n, e);
},
$nin: function(t, n, e) {
return new f(t, n, e);
},
$all: b,
$size: function(t, n, e) {
}),
(n.$not = function(t, n, e) {
return new a(t, n, e);
}),
(n.$type = function(t, n, e) {
return new i.EqualsOperation(
function(n) {
return n && n.length === t;
return null != n && (n instanceof t || n.constructor === t);
},

@@ -623,10 +630,11 @@ n,

);
},
$in: function(t, n, e) {
return new p(t, n, e);
},
$type: function(t, n, e) {
}),
(n.$and = function(t, n, e) {
return new h(t, n, e);
}),
(n.$all = n.$and),
(n.$size = function(t, n, e) {
return new i.EqualsOperation(
function(n) {
return null != n && (n instanceof t || n.constructor === t);
return n && n.length === t;
},

@@ -636,13 +644,7 @@ n,

);
},
$elemMatch: function(t, n, e) {
return new c(t, n, e);
},
$exists: function(t, n, e) {
return new l(t, n, e);
},
$not: function(t, n, e) {
return new a(t, n, e);
},
$where: function(t, n, e) {
}),
(n.$options = function() {
return null;
}),
(n.$where = function(t, n, e) {
var r;

@@ -659,4 +661,3 @@ return (

);
}
};
});
}

@@ -663,0 +664,0 @@ ]);

@@ -1,2 +0,9 @@

import { isArray, Key, Comparator, isVanillaObject, comparable } from "./utils";
import {
isArray,
Key,
Comparator,
isVanillaObject,
comparable,
equals
} from "./utils";

@@ -18,2 +25,20 @@ export interface Operation {

export type Query = {
[identifier: string]: Query | Object;
$eq?: any;
$ne?: any;
$elemMatch?: Query;
$lt?: number;
$gt?: number;
$lte?: number;
$gte?: number;
$mod?: [number, number];
$exists?: boolean;
$regex?: string;
$options?: "i" | "g" | "m" | "u";
$type: Function;
$or?: Query[];
$nor?: Query[];
};
/**

@@ -309,1 +334,16 @@ * Walks through each value given the context - used for nested operations. E.g:

};
export const createQueryTester = (
query: Query,
{ compare, operations }: Partial<Options> = {}
) => {
const operation = createQueryOperation(query, null, {
compare: compare || equals,
operations: Object.assign({}, operations || {})
});
return (item, key?: Key, owner?: any) => {
operation.reset();
operation.next(item, key, owner);
return operation.success;
};
};

@@ -1,27 +0,18 @@

import { Query, creators } from "./operations";
import {
Options,
createQueryOperation,
EqualsOperation,
BaseOperation
} from "./core";
import { equals, Key } from "./utils";
import * as defaultOperations from "./operations";
import { Query, Options, createQueryTester, EqualsOperation } from "./core";
const createRootTester = (
const createDefaultQueryTester = (
query: Query,
{ compare, operations }: Partial<Options> = {}
) => {
const operation = createQueryOperation(query, null, {
compare: compare || equals,
operations: Object.assign({}, creators, operations || {})
return createQueryTester(query, {
compare: compare,
operations: Object.assign({}, defaultOperations, operations || {})
});
return (item, key?: Key, owner?: any) => {
operation.reset();
operation.next(item, key, owner);
return operation.success;
};
};
module.exports = createDefaultQueryTester;
export { Query, EqualsOperation };
export default createRootTester;
export default createDefaultQueryTester;

@@ -11,2 +11,3 @@ import {

Operation,
Query,
GroupOperation

@@ -121,51 +122,33 @@ } from "./core";

export type Query = {
[identifier: string]: Query | Object;
$eq?: any;
$ne?: any;
$elemMatch?: Query;
$lt?: number;
$gt?: number;
$lte?: number;
$gte?: number;
$mod?: [number, number];
$exists?: boolean;
$regex?: string;
$options?: "i" | "g" | "m" | "u";
$type: Function;
$or?: Query[];
$nor?: Query[];
};
const $eq = (params: any, owneryQuery: Query, options: Options) =>
export const $eq = (params: any, owneryQuery: Query, options: Options) =>
new EqualsOperation(params, owneryQuery, options);
const $ne = (params: any, owneryQuery: Query, options: Options) =>
export const $ne = (params: any, owneryQuery: Query, options: Options) =>
new $Ne(params, owneryQuery, options);
const $or = (params: Query[], owneryQuery: Query, options: Options) =>
export const $or = (params: Query[], owneryQuery: Query, options: Options) =>
new $Or(params, owneryQuery, options);
const $nor = (params: Query[], owneryQuery: Query, options: Options) =>
export const $nor = (params: Query[], owneryQuery: Query, options: Options) =>
new $Nor(params, owneryQuery, options);
const $elemMatch = (params: any, owneryQuery: Query, options: Options) =>
export const $elemMatch = (params: any, owneryQuery: Query, options: Options) =>
new $ElemMatch(params, owneryQuery, options);
const $nin = (params: any, owneryQuery: Query, options: Options) =>
export const $nin = (params: any, owneryQuery: Query, options: Options) =>
new $Nor(params, owneryQuery, options);
const $in = (params: any, owneryQuery: Query, options: Options) =>
export const $in = (params: any, owneryQuery: Query, options: Options) =>
new $Or(params, owneryQuery, options);
const $lt = numericalOperationCreator(
export const $lt = numericalOperationCreator(
(params: any, owneryQuery: Query, options: Options) =>
new EqualsOperation(b => b < params, owneryQuery, options)
);
const $lte = numericalOperationCreator(
export const $lte = numericalOperationCreator(
(params: any, owneryQuery: Query, options: Options) =>
new EqualsOperation(b => b <= params, owneryQuery, options)
);
const $gt = numericalOperationCreator(
export const $gt = numericalOperationCreator(
(params: any, owneryQuery: Query, options: Options) =>
new EqualsOperation(b => b > params, owneryQuery, options)
);
const $gte = numericalOperationCreator(
export const $gte = numericalOperationCreator(
(params: any, owneryQuery: Query, options: Options) =>
new EqualsOperation(b => b >= params, owneryQuery, options)
);
const $mod = (
export const $mod = (
[mod, equalsValue]: number[],

@@ -180,5 +163,8 @@ owneryQuery: Query,

);
const $exists = (params: boolean, owneryQuery: Query, options: Options) =>
new $Exists(params, owneryQuery, options);
const $regex = (pattern: string, owneryQuery: Query, options: Options) =>
export const $exists = (
params: boolean,
owneryQuery: Query,
options: Options
) => new $Exists(params, owneryQuery, options);
export const $regex = (pattern: string, owneryQuery: Query, options: Options) =>
new EqualsOperation(

@@ -189,5 +175,5 @@ new RegExp(pattern, owneryQuery.$options),

);
const $not = (params: any, owneryQuery: Query, options: Options) =>
export const $not = (params: any, owneryQuery: Query, options: Options) =>
new $Not(params, owneryQuery, options);
const $type = (clazz: Function, owneryQuery: Query, options: Options) =>
export const $type = (clazz: Function, owneryQuery: Query, options: Options) =>
new EqualsOperation(

@@ -198,9 +184,9 @@ b => (b != null ? b instanceof clazz || b.constructor === clazz : false),

);
const $and = (params: Query[], ownerQuery: Query, options: Options) =>
export const $and = (params: Query[], ownerQuery: Query, options: Options) =>
new $And(params, ownerQuery, options);
const $all = $and;
const $size = (params: number, ownerQuery: Query, options: Options) =>
export const $all = $and;
export const $size = (params: number, ownerQuery: Query, options: Options) =>
new EqualsOperation(b => b && b.length === params, ownerQuery, options);
const $options = () => null;
const $where = (
export const $options = () => null;
export const $where = (
params: string | Function,

@@ -224,25 +210,1 @@ ownerQuery: Query,

};
export const creators = {
$lt,
$lte,
$mod,
$gt,
$gte,
$eq,
$or,
$nor,
$and,
$options,
$regex,
$ne,
$nin,
$all,
$size,
$in,
$type,
$elemMatch,
$exists,
$not,
$where
};

@@ -349,3 +349,17 @@ import * as assert from "assert";

],
[
{
"array.value": 1
},
[
{
array: [{ value: 1 }, { value: 2 }]
}
],
[
{
array: [{ value: 1 }, { value: 2 }]
}
]
],
// $size

@@ -352,0 +366,0 @@ [{ $size: 3 }, ["123", [1, 2, 3], "1"], ["123", [1, 2, 3]]],

@@ -24,5 +24,3 @@ const { DefinePlugin } = require("webpack");

exclude: /(node_modules|bower_components)/,
use: {
loader: "ts-loader"
}
use: ["ts-loader"]
}

@@ -29,0 +27,0 @@ ]

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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