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

mingo

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mingo - npm Package Compare versions

Comparing version 6.1.3 to 6.2.0

operators/accumulator/bottom.d.ts

4

aggregator.d.ts

@@ -12,4 +12,4 @@ import { Options } from "./core";

export declare class Aggregator {
readonly pipeline: Array<RawObject>;
readonly options?: Options;
private readonly pipeline;
private readonly options?;
constructor(pipeline: Array<RawObject>, options?: Options);

@@ -16,0 +16,0 @@ /**

@@ -42,3 +42,3 @@ "use strict";

var call = (0, core_1.getOperator)(core_1.OperatorType.PIPELINE, op);
(0, util_1.assert)(operatorKeys.length === 1 && !!call, "invalid aggregation operator " + op);
(0, util_1.assert)(operatorKeys.length === 1 && !!call, "invalid aggregation operator ".concat(op));
pipelineOperators.push(op);

@@ -45,0 +45,0 @@ iterator = call(iterator, operator[op], this.options);

# Changelog
## 6.2.0 / 2022-12-16
**New**
- Added array expression operators; `$maxN`, `$minN`, `$firstN`, `$lastN`, and `$sortArray`.
- Added accumulator operators; `$maxN`, `$minN`, `$first`, `$firstN`, `$last`, `$lastN`, `$top`, `$topN`, `$bottom`, and `$bottomN`.
- Added trignometry operators; `$cosh` and `$sinh`.
**Fixes**
- Correclt handle boundary values for trignometry functions.
- Nested arrays are projected correctly when excluded in results.
- Support MongoDB comparison sort order by data type.
## 6.1.3 / 2022-12-09
**Fixes**
- Use correct context for resolving paths. Closes [284](https://github.com/kofrasa/mingo/issues/284)

@@ -7,0 +22,0 @@ - Support user-defined global variables.

@@ -113,3 +113,3 @@ import { Iterator } from "./lazy";

/** Updates the internal mutable state. */
udpate(root?: AnyVal, local?: LocalData): ComputeOptions;
update(root?: AnyVal, local?: LocalData): ComputeOptions;
get root(): unknown;

@@ -116,0 +116,0 @@ get local(): LocalData;

@@ -66,3 +66,3 @@ "use strict";

this.options = options;
this.udpate(_root, _local);
this.update(_root, _local);
}

@@ -78,3 +78,3 @@ /**

return options instanceof ComputeOptions
? options.udpate(
? options.update(
// value can be '0' or 'false'

@@ -85,3 +85,3 @@ (0, util_1.isNil)(options.root) ? root : options.root, options.local || local)

/** Updates the internal mutable state. */
ComputeOptions.prototype.udpate = function (root, local) {
ComputeOptions.prototype.update = function (root, local) {
// NOTE: this is done for efficiency to avoid creating too many intermediate options objects.

@@ -219,5 +219,5 @@ this._root = root;

var _b = _a[_i], name_1 = _b[0], fn = _b[1];
(0, util_1.assert)(fn instanceof Function && (0, util_1.isOperator)(name_1), "'" + name_1 + "' is not a valid operator");
(0, util_1.assert)(fn instanceof Function && (0, util_1.isOperator)(name_1), "'".concat(name_1, "' is not a valid operator"));
var currentFn = getOperator(type, name_1);
(0, util_1.assert)(!currentFn || fn === currentFn, name_1 + " already exists for '" + type + "' operators. Cannot change operator function once registered.");
(0, util_1.assert)(!currentFn || fn === currentFn, "".concat(name_1, " already exists for '").concat(type, "' operators. Cannot change operator function once registered."));
}

@@ -283,3 +283,3 @@ // toss the operator salad :)

if ((0, util_1.isObject)(elem)) {
elem = redact(elem, expr, options.udpate(elem));
elem = redact(elem, expr, options.update(elem));
}

@@ -293,3 +293,3 @@ if (!(0, util_1.isNil)(elem)) {

else {
result = redact(current, expr, options.udpate(current));
result = redact(current, expr, options.update(current));
}

@@ -335,10 +335,10 @@ if ((0, util_1.isNil)(result)) {

// validate that we have an array
(0, util_1.assert)(obj instanceof Array, "'" + operator + "' target must be an array.");
(0, util_1.assert)(obj instanceof Array, "'".concat(operator, "' target must be an array."));
// for accumulators, we use the global options since the root is specific to each element within array.
return callAccumulator(obj, expr,
// reset the root object for accumulators.
copts.udpate(null, copts.local));
copts.update(null, copts.local));
}
// operator was not found
throw new Error("operator '" + operator + "' is not registered");
throw new Error("operator '".concat(operator, "' is not registered"));
}

@@ -372,3 +372,3 @@ // if expr is a string and begins with "$$", then we have a variable.

var prefix = arr[0].substr(2);
(0, util_1.assert)((0, util_1.has)(context, prefix), "Use of undefined variable: " + prefix);
(0, util_1.assert)((0, util_1.has)(context, prefix), "Use of undefined variable: ".concat(prefix));
expr = expr.slice(2);

@@ -375,0 +375,0 @@ }

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

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -18,0 +22,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -34,4 +34,3 @@ "use strict";

function isGenerator(o) {
var _a;
return (!!o && typeof o === "object" && ((_a = o) === null || _a === void 0 ? void 0 : _a.next) instanceof Function);
return (!!o && typeof o === "object" && (o === null || o === void 0 ? void 0 : o.next) instanceof Function);
}

@@ -147,3 +146,3 @@ function dropItem(array, i) {

else if (!(source instanceof Function)) {
throw new Error("Source is of type '" + typeof source + "'. Must be Array, Function, or Generator");
throw new Error("Source is of type '".concat(typeof source, "'. Must be Array, Function, or Generator"));
}

@@ -150,0 +149,0 @@ // create next function

@@ -67,3 +67,3 @@ "use strict";

var eq = util_1.isEqual.bind(null, b);
return a.some(eq) || (0, util_1.flatten)(a, options.depth).some(eq);
return a.some(eq) || (0, util_1.flatten)(a, options === null || options === void 0 ? void 0 : options.depth).some(eq);
}

@@ -70,0 +70,0 @@ return false;

@@ -30,3 +30,3 @@ "use strict";

var copts = core_1.ComputeOptions.init(options);
var initArgs = (0, core_1.computeValue)({}, expr.initArgs || [], null, copts.udpate(((_c = copts === null || copts === void 0 ? void 0 : copts.local) === null || _c === void 0 ? void 0 : _c.groupId) || {}));
var initArgs = (0, core_1.computeValue)({}, expr.initArgs || [], null, copts.update(((_c = copts === null || copts === void 0 ? void 0 : copts.local) === null || _c === void 0 ? void 0 : _c.groupId) || {}));
var state = (_a = expr.init).call.apply(_a, __spreadArray([null], initArgs, false));

@@ -36,3 +36,3 @@ for (var _i = 0, collection_1 = collection; _i < collection_1.length; _i++) {

// get arguments for document
var args = (0, core_1.computeValue)(doc, expr.accumulateArgs, null, copts.udpate(doc));
var args = (0, core_1.computeValue)(doc, expr.accumulateArgs, null, copts.update(doc));
// update the state with each documents value

@@ -39,0 +39,0 @@ state = (_b = expr.accumulate).call.apply(_b, __spreadArray([null], __spreadArray([state], args, true), false));

@@ -7,2 +7,4 @@ /**

export * from "./avg";
export * from "./bottom";
export * from "./bottomN";
export * from "./count";

@@ -12,6 +14,10 @@ export * from "./covariancePop";

export * from "./first";
export * from "./firstN";
export * from "./last";
export * from "./lastN";
export * from "./max";
export * from "./maxN";
export * from "./mergeObjects";
export * from "./min";
export * from "./minN";
export * from "./push";

@@ -21,1 +27,3 @@ export * from "./stdDevPop";

export * from "./sum";
export * from "./top";
export * from "./topN";

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

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -20,2 +24,4 @@ if (k2 === undefined) k2 = k;

__exportStar(require("./avg"), exports);
__exportStar(require("./bottom"), exports);
__exportStar(require("./bottomN"), exports);
__exportStar(require("./count"), exports);

@@ -25,6 +31,10 @@ __exportStar(require("./covariancePop"), exports);

__exportStar(require("./first"), exports);
__exportStar(require("./firstN"), exports);
__exportStar(require("./last"), exports);
__exportStar(require("./lastN"), exports);
__exportStar(require("./max"), exports);
__exportStar(require("./maxN"), exports);
__exportStar(require("./mergeObjects"), exports);
__exportStar(require("./min"), exports);
__exportStar(require("./minN"), exports);
__exportStar(require("./push"), exports);

@@ -34,1 +44,3 @@ __exportStar(require("./stdDevPop"), exports);

__exportStar(require("./sum"), exports);
__exportStar(require("./top"), exports);
__exportStar(require("./topN"), exports);

@@ -19,5 +19,5 @@ "use strict";

return collection.map(function (obj) {
return (0, core_1.computeValue)(obj, expr, null, copts.udpate(obj));
return (0, core_1.computeValue)(obj, expr, null, copts.update(obj));
});
}
exports.$push = $push;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
// Array Expression Operators: https://docs.mongodb.com/manual/reference/operator/aggregation/#array-expression-operators
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -28,8 +17,9 @@ exports.$filter = void 0;

(0, util_1.assert)((0, util_1.isArray)(input), "$filter 'input' expression must resolve to an array");
var copts = core_1.ComputeOptions.init(options, obj);
var k = expr.as || "this";
return input.filter(function (o) {
var _a;
return (0, core_1.computeValue)(obj, expr.cond, null, __assign(__assign({}, options), { variables: (_a = {}, _a[k] = o, _a) })) === true;
return (0, core_1.computeValue)(o, expr.cond, null, copts.update(copts.root, { variables: (_a = {}, _a[k] = o, _a) })) === true;
});
}
exports.$filter = $filter;

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

var util_1 = require("../../../util");
var accumulator_1 = require("../../accumulator");
/**

@@ -16,10 +17,11 @@ * Returns the first element in an array.

function $first(obj, expr, options) {
var copts = core_1.ComputeOptions.init(options);
if (obj instanceof Array)
return (0, accumulator_1.$first)(obj, expr, copts.update());
var arr = (0, core_1.computeValue)(obj, expr, null, options);
if (arr == null)
if ((0, util_1.isNil)(arr))
return null;
(0, util_1.assert)((0, util_1.isArray)(arr), "Must resolve to an array/null or missing");
if (arr.length > 0)
return arr[0];
return undefined;
return (0, accumulator_1.$first)(arr, "$$this", options);
}
exports.$first = $first;

@@ -6,2 +6,3 @@ export * from "./arrayElemAt";

export * from "./first";
export * from "./firstN";
export * from "./in";

@@ -11,3 +12,6 @@ export * from "./indexOfArray";

export * from "./last";
export * from "./lastN";
export * from "./map";
export * from "./maxN";
export * from "./minN";
export * from "./nin";

@@ -19,2 +23,3 @@ export * from "./range";

export * from "./slice";
export * from "./sortArray";
export * from "./zip";
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -18,2 +22,3 @@ if (k2 === undefined) k2 = k;

__exportStar(require("./first"), exports);
__exportStar(require("./firstN"), exports);
__exportStar(require("./in"), exports);

@@ -23,3 +28,6 @@ __exportStar(require("./indexOfArray"), exports);

__exportStar(require("./last"), exports);
__exportStar(require("./lastN"), exports);
__exportStar(require("./map"), exports);
__exportStar(require("./maxN"), exports);
__exportStar(require("./minN"), exports);
__exportStar(require("./nin"), exports);

@@ -31,2 +39,3 @@ __exportStar(require("./range"), exports);

__exportStar(require("./slice"), exports);
__exportStar(require("./sortArray"), exports);
__exportStar(require("./zip"), exports);

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

var util_1 = require("../../../util");
var accumulator_1 = require("../../accumulator");
/**

@@ -16,10 +17,11 @@ * Returns the last element in an array.

function $last(obj, expr, options) {
var copts = core_1.ComputeOptions.init(options);
if (obj instanceof Array)
return (0, accumulator_1.$last)(obj, expr, copts.update());
var arr = (0, core_1.computeValue)(obj, expr, null, options);
if (arr == null)
if ((0, util_1.isNil)(arr))
return null;
(0, util_1.assert)((0, util_1.isArray)(arr), "Must resolve to an array/null or missing");
if (arr.length > 0)
return arr[arr.length - 1];
return undefined;
return (0, accumulator_1.$last)(arr, "$$this", options);
}
exports.$last = $last;

@@ -21,3 +21,3 @@ "use strict";

var _a;
return (0, core_1.computeValue)(o, expr.in, null, copts.udpate(obj, {
return (0, core_1.computeValue)(o, expr.in, null, copts.update(obj, {
variables: (_a = {}, _a[k] = o, _a),

@@ -24,0 +24,0 @@ }));

@@ -22,3 +22,3 @@ "use strict";

return input.reduce(function (acc, n) {
return (0, core_1.computeValue)(n, inExpr, null, copts.udpate(obj, {
return (0, core_1.computeValue)(n, inExpr, null, copts.update(obj, {
variables: { value: acc },

@@ -25,0 +25,0 @@ }));

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -94,3 +94,3 @@ "use strict";

if (!m)
throw Error("invalid or location-based timezone '" + tzstr + "' not supported");
throw Error("invalid or location-based timezone '".concat(tzstr, "' not supported"));
var hr = parseInt(m[2]) || 0;

@@ -139,3 +139,3 @@ var min = parseInt(m[3]) || 0;

}
throw Error("cannot convert " + (expr === null || expr === void 0 ? void 0 : expr.toString()) + " to date");
throw Error("cannot convert ".concat(expr === null || expr === void 0 ? void 0 : expr.toString(), " to date"));
}

@@ -150,3 +150,3 @@ exports.computeDate = computeDate;

"^.-*?$".split("").forEach(function (c) {
s = s.replace(c, "\\" + c);
s = s.replace(c, "\\".concat(c));
});

@@ -153,0 +153,0 @@ return s;

@@ -78,3 +78,3 @@ "use strict";

// only one of in-date timeone or timezone argument but not both.
!(m && args.timezone), "$dateFromString: you cannot pass in a date/time string with time zone information ('" + (m && m[0]) + "') together with a timezone argument");
!(m && args.timezone), "$dateFromString: you cannot pass in a date/time string with time zone information ('".concat(m && m[0], "') together with a timezone argument"));
var minuteOffset = m

@@ -81,0 +81,0 @@ ? TZ_LETTER_OFFSETS[m[0]] * _internal_1.MINUTES_PER_HOUR

@@ -78,3 +78,3 @@ "use strict";

else {
(0, util_1.assert)(!!operatorFn, "unsupported date format specifier '" + formatSpecifier + "'");
(0, util_1.assert)(!!operatorFn, "unsupported date format specifier '".concat(formatSpecifier, "'"));
value = (0, _internal_1.padDigits)(operatorFn(obj, date, options), props.padding);

@@ -81,0 +81,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -8,2 +8,2 @@ import { ExpressionOperator } from "../../../core";

*/
export declare function createTrignometryOperator(f: Callback<number | null>, returnInfinity?: boolean): ExpressionOperator;
export declare function createTrignometryOperator(f: Callback<number | null>, fixedPoints?: Record<string, number | Error>): ExpressionOperator;

@@ -6,3 +6,9 @@ "use strict";

var core_1 = require("../../../core");
var util_1 = require("../../../util");
var FIXED_POINTS = {
undefined: null,
null: null,
NaN: NaN,
Infinity: new Error(),
"-Infinity": new Error(),
};
/**

@@ -13,11 +19,14 @@ * Returns an operator for a given trignometric function

*/
function createTrignometryOperator(f, returnInfinity) {
function createTrignometryOperator(f, fixedPoints) {
if (fixedPoints === void 0) { fixedPoints = FIXED_POINTS; }
var fp = Object.assign({}, FIXED_POINTS, fixedPoints);
var keySet = new Set(Object.keys(fp));
return function (obj, expr, options) {
var n = (0, core_1.computeValue)(obj, expr, null, options);
if (isNaN(n) || (0, util_1.isNil)(n))
return n;
if (n === Infinity || n === -Infinity) {
if (returnInfinity)
return n;
throw new Error("cannot apply $" + f.name + " to -inf, value must in (-inf,inf)");
if (keySet.has("".concat(n))) {
var res = fp["".concat(n)];
if (res instanceof Error) {
throw new Error("cannot apply $".concat(f.name, " to -inf, value must in (-inf,inf)"));
}
return res;
}

@@ -24,0 +33,0 @@ return f(n);

@@ -7,2 +7,5 @@ "use strict";

/** Returns the inverse cosine (arc cosine) of a value in radians. */
exports.$acos = (0, _internal_1.createTrignometryOperator)(Math.acos);
exports.$acos = (0, _internal_1.createTrignometryOperator)(Math.acos, {
Infinity: Infinity,
0: new Error(),
});

@@ -7,2 +7,5 @@ "use strict";

/** Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. */
exports.$acosh = (0, _internal_1.createTrignometryOperator)(Math.acosh);
exports.$acosh = (0, _internal_1.createTrignometryOperator)(Math.acosh, {
Infinity: Infinity,
0: new Error(),
});

@@ -7,2 +7,5 @@ "use strict";

/** Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. */
exports.$asinh = (0, _internal_1.createTrignometryOperator)(Math.asinh);
exports.$asinh = (0, _internal_1.createTrignometryOperator)(Math.asinh, {
Infinity: Infinity,
"-Infinity": -Infinity,
});

@@ -7,2 +7,5 @@ "use strict";

/** Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. */
exports.$atanh = (0, _internal_1.createTrignometryOperator)(Math.atanh);
exports.$atanh = (0, _internal_1.createTrignometryOperator)(Math.atanh, {
1: Infinity,
"-1": -Infinity,
});

@@ -8,2 +8,5 @@ "use strict";

/** Converts a value from degrees to radians. */
exports.$degreesToRadians = (0, _internal_1.createTrignometryOperator)(function (n) { return n * RADIANS_FACTOR; }, true /*returnInfinity*/);
exports.$degreesToRadians = (0, _internal_1.createTrignometryOperator)(function (n) { return n * RADIANS_FACTOR; }, {
Infinity: Infinity,
"-Infinity": Infinity,
});

@@ -9,5 +9,7 @@ export * from "./acos";

export * from "./cos";
export * from "./cosh";
export * from "./degreesToRadians";
export * from "./radiansToDegrees";
export * from "./sin";
export * from "./sinh";
export * from "./tan";
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -21,5 +25,7 @@ if (k2 === undefined) k2 = k;

__exportStar(require("./cos"), exports);
__exportStar(require("./cosh"), exports);
__exportStar(require("./degreesToRadians"), exports);
__exportStar(require("./radiansToDegrees"), exports);
__exportStar(require("./sin"), exports);
__exportStar(require("./sinh"), exports);
__exportStar(require("./tan"), exports);

@@ -8,2 +8,5 @@ "use strict";

/** Converts a value from radians to degrees. */
exports.$radiansToDegrees = (0, _internal_1.createTrignometryOperator)(function (n) { return n * DEGREES_FACTOR; }, true /*returnInfinity*/);
exports.$radiansToDegrees = (0, _internal_1.createTrignometryOperator)(function (n) { return n * DEGREES_FACTOR; }, {
Infinity: Infinity,
"-Infinity": -Infinity,
});

@@ -47,4 +47,4 @@ "use strict";

}
throw new TypeConvertError("cannot convert '" + val + "' to " + typename);
throw new TypeConvertError("cannot convert '".concat(val, "' to ").concat(typename));
}
exports.toInteger = toInteger;

@@ -58,4 +58,4 @@ "use strict";

return args.onError;
throw new _internal_1.TypeConvertError("could not convert to type " + args.to + ".");
throw new _internal_1.TypeConvertError("could not convert to type ".concat(args.to, "."));
}
exports.$convert = $convert;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -26,4 +26,4 @@ "use strict";

return d;
throw new _internal_1.TypeConvertError("cannot convert '" + val + "' to date");
throw new _internal_1.TypeConvertError("cannot convert '".concat(val, "' to date"));
}
exports.$toDate = $toDate;

@@ -29,4 +29,4 @@ "use strict";

return n;
throw new _internal_1.TypeConvertError("cannot convert '" + val + "' to double/decimal");
throw new _internal_1.TypeConvertError("cannot convert '".concat(val, "' to double/decimal"));
}
exports.$toDouble = $toDouble;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -5,13 +5,2 @@ "use strict";

*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -35,4 +24,4 @@ exports.$let = void 0;

}
return (0, core_1.computeValue)(obj, expr.in, null, __assign({ variables: variables }, options));
return (0, core_1.computeValue)(obj, expr.in, null, core_1.ComputeOptions.init(options, obj, { variables: variables }));
}
exports.$let = $let;

@@ -20,3 +20,3 @@ "use strict";

var bucketCount = expr.buckets;
(0, util_1.assert)(bucketCount > 0, "The $bucketAuto 'buckets' field must be greater than 0, but found: " + bucketCount);
(0, util_1.assert)(bucketCount > 0, "The $bucketAuto 'buckets' field must be greater than 0, but found: ".concat(bucketCount));
var ID_KEY = "_id";

@@ -23,0 +23,0 @@ return collection.transform(function (coll) {

@@ -49,3 +49,3 @@ "use strict";

var _b = _a[_i], key = _b[0], val = _b[1];
obj[key] = (0, core_1.computeValue)(partitions.groups[i], val, key, copts.udpate(null, { groupId: groupId }));
obj[key] = (0, core_1.computeValue)(partitions.groups[i], val, key, copts.update(null, { groupId: groupId }));
}

@@ -52,0 +52,0 @@ return { value: obj, done: false };

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

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -10,0 +14,0 @@ if (k2 === undefined) k2 = k;

@@ -61,5 +61,5 @@ "use strict";

// 'root' is the item from the iteration.
copts.udpate(o));
copts.update(o));
if ((0, util_1.isArray)(expr.whenMatched)) {
var aggregator = new aggregator_1.Aggregator(expr.whenMatched, __assign(__assign({}, options), { variables: variables }));
var aggregator = new aggregator_1.Aggregator(expr.whenMatched, __assign(__assign({}, copts.options), { variables: variables }));
output[i] = aggregator.run([target])[0];

@@ -80,3 +80,3 @@ }

// 'root' is the item from the iteration.
copts.udpate(o, { variables: variables }));
copts.update(o, { variables: variables }));
break;

@@ -83,0 +83,0 @@ }

@@ -37,3 +37,3 @@ "use strict";

return collection.map(function (obj) {
return processObject(obj, expr, copts.udpate(obj), expressionKeys, idOnlyExcluded);
return processObject(obj, expr, copts.update(obj), expressionKeys, idOnlyExcluded);
});

@@ -40,0 +40,0 @@ }

@@ -13,5 +13,5 @@ "use strict";

return collection.map(function (obj) {
return (0, core_1.redact)(obj, expr, copts.udpate(obj));
return (0, core_1.redact)(obj, expr, copts.update(obj));
});
}
exports.$redact = $redact;

@@ -27,3 +27,3 @@ "use strict";

(0, util_1.assert)(!!(0, core_1.getOperator)(core_1.OperatorType.WINDOW, op) ||
!!(0, core_1.getOperator)(core_1.OperatorType.ACCUMULATOR, op), op + " is not a valid window operator");
!!(0, core_1.getOperator)(core_1.OperatorType.ACCUMULATOR, op), "".concat(op, " is not a valid window operator"));
(0, util_1.assert)(keys.length > 0 &&

@@ -30,0 +30,0 @@ keys.length <= 2 &&

@@ -16,3 +16,3 @@ "use strict";

return collection;
var cmp = util_1.compare;
var cmp = util_1.DEFAULT_COMPARATOR;
// check for collation spec on the options

@@ -95,3 +95,3 @@ var collationSpec = options.collation;

if (!(0, util_1.isString)(a) || !(0, util_1.isString)(b))
return (0, util_1.compare)(a, b);
return (0, util_1.DEFAULT_COMPARATOR)(a, b);
// only for strings

@@ -98,0 +98,0 @@ var i = collator.compare(a, b);

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

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -8,0 +12,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -21,3 +21,3 @@ "use strict";

var operator = Object.keys(outputExpr).find(util_1.isOperator);
(0, util_1.assert)(!outputExpr.window, "$" + operator + " does not support 'window' option in $setWindowFields");
(0, util_1.assert)(!outputExpr.window, "$".concat(operator, " does not support 'window' option in $setWindowFields"));
var key = (0, util_1.hashCode)(collection[0]);

@@ -24,0 +24,0 @@ var sortKey = "$" + Object.keys(expr.parentExpr.sortBy)[0];

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

{
"name": "mingo",
"version": "6.1.3",
"version": "6.2.0",
"description": "MongoDB query language for in-memory objects",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -35,3 +35,3 @@ "use strict";

// normalize expression
(0, util_1.assert)(!(0, util_1.isOperator)(field), "unknown top level operator: " + field);
(0, util_1.assert)(!(0, util_1.isOperator)(field), "unknown top level operator: ".concat(field));
for (var _c = 0, _d = Object.entries((0, util_1.normalize)(expr)); _c < _d.length; _c++) {

@@ -49,3 +49,3 @@ var _e = _d[_c], operator = _e[0], val = _e[1];

var call = (0, core_1.getOperator)(core_1.OperatorType.QUERY, operator);
(0, util_1.assert)(!!call, "unknown operator " + operator);
(0, util_1.assert)(!!call, "unknown operator ".concat(operator));
var fn = call(field, value, this.options);

@@ -52,0 +52,0 @@ this.compiled.push(fn);

@@ -258,2 +258,4 @@ # mingo

readonly jsonSchemaValidator?: JsonSchemaValidator;
/** Global variables. */
readonly variables?: Readonly<RawObject>;
}

@@ -260,0 +262,0 @@ ```

@@ -11,5 +11,4 @@ export declare type AnyVal = unknown;

}
export declare type ComparatorResult = -1 | 0 | 1;
export interface Comparator<T> {
(left: T, right: T): ComparatorResult;
(left: T, right: T): number;
}

@@ -16,0 +15,0 @@ /**

/**
* Utility constants and functions
*/
import { AnyVal, ArrayOrObject, Callback, Comparator, ComparatorResult, HashFunction, RawArray, RawObject } from "./types";
import { AnyVal, ArrayOrObject, Callback, Comparator, HashFunction, RawArray, RawObject } from "./types";
export declare const MAX_INT = 2147483647;

@@ -15,2 +15,10 @@ export declare const MIN_INT = -2147483648;

}
/**
* Compare function which adheres to MongoDB comparison order.
*
* @param a The first value
* @param b The second value
* @returns {Number}
*/
export declare const DEFAULT_COMPARATOR: (a: AnyVal, b: AnyVal) => number;
export declare function assert(condition: boolean, message: string): void;

@@ -40,2 +48,3 @@ /**

export declare function isEmpty(x: AnyVal): boolean;
export declare function isMissing(m: AnyVal): boolean;
export declare function ensureArray(x: AnyVal): RawArray;

@@ -111,8 +120,2 @@ export declare function has(obj: RawObject, prop: string): boolean;

/**
* Default compare function
* @param {*} a
* @param {*} b
*/
export declare function compare(a: AnyVal, b: AnyVal): ComparatorResult;
/**
* Returns a (stably) sorted copy of list, ranked in ascending order by the results of running each value through iteratee

@@ -176,2 +179,6 @@ *

export declare function filterMissing(obj: ArrayOrObject): void;
interface WalkOptions {
buildGraph?: boolean;
descendArray?: boolean;
}
/**

@@ -193,5 +200,3 @@ * Set the value of the given object field

*/
export declare function removeValue(obj: ArrayOrObject, selector: string, options?: {
descendArray: boolean;
}): void;
export declare function removeValue(obj: ArrayOrObject, selector: string, options?: Pick<WalkOptions, "descendArray">): void;
/**

@@ -198,0 +203,0 @@ * Check whether the given name passes for an operator. We assume AnyVal field name starting with '$' is an operator.

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.normalize = exports.isOperator = exports.removeValue = exports.setValue = exports.filterMissing = exports.resolveGraph = exports.resolve = exports.memoize = exports.into = exports.groupBy = exports.sortBy = exports.compare = exports.hashCode = exports.stringify = exports.unique = exports.isEqual = exports.flatten = exports.intersection = exports.merge = exports.objectMap = exports.has = exports.ensureArray = exports.isEmpty = exports.truthy = exports.notInArray = exports.inArray = exports.isNil = exports.isFunction = exports.isRegExp = exports.isDate = exports.isObjectLike = exports.isObject = exports.isArray = exports.isNumber = exports.isString = exports.isBoolean = exports.getType = exports.cloneDeep = exports.assert = exports.MIN_LONG = exports.MAX_LONG = exports.MIN_INT = exports.MAX_INT = void 0;
exports.normalize = exports.isOperator = exports.removeValue = exports.setValue = exports.filterMissing = exports.resolveGraph = exports.resolve = exports.memoize = exports.into = exports.groupBy = exports.sortBy = exports.hashCode = exports.stringify = exports.unique = exports.isEqual = exports.flatten = exports.intersection = exports.merge = exports.objectMap = exports.has = exports.ensureArray = exports.isMissing = exports.isEmpty = exports.truthy = exports.notInArray = exports.inArray = exports.isNil = exports.isFunction = exports.isRegExp = exports.isDate = exports.isObjectLike = exports.isObject = exports.isArray = exports.isNumber = exports.isString = exports.isBoolean = exports.getType = exports.cloneDeep = exports.assert = exports.DEFAULT_COMPARATOR = exports.MIN_LONG = exports.MAX_LONG = exports.MIN_INT = exports.MAX_INT = void 0;
exports.MAX_INT = 2147483647;

@@ -24,3 +24,3 @@ exports.MIN_INT = -2147483648;

// special value to identify missing items. treated differently from undefined
var MISSING = Object.freeze({});
var MISSING = Symbol("missing");
/**

@@ -50,2 +50,38 @@ * Uses the simple hash method as described in Effective Java.

]);
/** MongoDB sort comparison order. https://www.mongodb.com/docs/manual/reference/bson-type-comparison-order */
var SORT_ORDER_BY_TYPE = {
null: 0,
undefined: 0,
number: 1,
string: 2,
object: 3,
array: 4,
boolean: 5,
date: 6,
regexp: 7,
function: 8,
};
/**
* Compare function which adheres to MongoDB comparison order.
*
* @param a The first value
* @param b The second value
* @returns {Number}
*/
var DEFAULT_COMPARATOR = function (a, b) {
if (a === MISSING)
a = undefined;
if (b === MISSING)
b = undefined;
var u = SORT_ORDER_BY_TYPE[getType(a).toLowerCase()];
var v = SORT_ORDER_BY_TYPE[getType(b).toLowerCase()];
if (u !== v)
return u - v;
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
};
exports.DEFAULT_COMPARATOR = DEFAULT_COMPARATOR;
var OBJECT_PROTOTYPE = Object.getPrototypeOf({});

@@ -140,2 +176,6 @@ var OBJECT_TAG = "[object Object]";

exports.isEmpty = isEmpty;
function isMissing(m) {
return m === MISSING;
}
exports.isMissing = isMissing;
// ensure a value is an array or wrapped within one

@@ -177,5 +217,5 @@ function ensureArray(x) {

// take care of missing inputs
if (target === MISSING)
if (isMissing(target))
return obj;
if (obj === MISSING)
if (isMissing(obj))
return target;

@@ -511,7 +551,7 @@ var inputs = [target, obj];

// default case
var prefix = type === "object" ? "" : "" + getType(value);
var prefix = type === "object" ? "" : "".concat(getType(value));
var objKeys = Object.keys(value);
objKeys.sort();
return (prefix + "{" +
objKeys.map(function (k) { return stringify(k) + ":" + stringify(value[k]); }).join(",") +
return ("".concat(prefix, "{") +
objKeys.map(function (k) { return "".concat(stringify(k), ":").concat(stringify(value[k])); }).join(",") +
"}");

@@ -536,15 +576,2 @@ }

/**
* Default compare function
* @param {*} a
* @param {*} b
*/
function compare(a, b) {
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
}
exports.compare = compare;
/**
* Returns a (stably) sorted copy of list, ranked in ascending order by the results of running each value through iteratee

@@ -560,6 +587,5 @@ *

function sortBy(collection, keyFn, comparator) {
var sorted = new Array();
var result = new Array();
var hash = {};
comparator = comparator || compare;
if (comparator === void 0) { comparator = exports.DEFAULT_COMPARATOR; }
var sorted = [];
var result = [];
if (isEmpty(collection))

@@ -570,3 +596,2 @@ return collection;

var key = keyFn(obj, i);
// objects with nil keys will go in first
if (isNil(key)) {

@@ -576,19 +601,8 @@ result.push(obj);

else {
// null suffix to differentiate string keys from native object properties
if (isString(key))
key += "\0";
if (hash[key]) {
hash[key].push(obj);
}
else {
hash[key] = [obj];
sorted.push(key);
}
sorted.push([key, obj]);
}
}
// use native array sorting but enforce stableness
sorted.sort(comparator);
for (var i = 0; i < sorted.length; i++) {
into(result, hash[sorted[i]]);
}
sorted.sort(function (a, b) { return comparator(a[0], b[0]); });
result.push.apply(result, sorted.map(function (o) { return o[1]; }));
return result;

@@ -864,6 +878,22 @@ }

// force the rest of the graph while traversing
if ((options === null || options === void 0 ? void 0 : options.buildGraph) === true && isNil(obj[key])) {
if ((options === null || options === void 0 ? void 0 : options.buildGraph) && isNil(obj[key])) {
obj[key] = {};
}
walk(obj[key], next, fn, options);
// get the next item
var item = obj[key];
// we peek to see if next key is an array index.
var isNextArrayIndex = !!(names.length > 1 && names[1].match(/^\d+$/));
// if we have an array value but the next key is not an index and the 'descendArray' option is set,
// we walk each item in the array separately. This allows for handling traversing keys for objects
// nested within an array.
//
// Eg: Given { array: [ {k:1}, {k:2}, {k:3} ] }
// - individual objecs can be traversed with "array.k"
// - a specific object can be traversed with "array.1"
if (item instanceof Array && (options === null || options === void 0 ? void 0 : options.descendArray) && !isNextArrayIndex) {
item.forEach(function (e) { return walk(e, next, fn, options); });
}
else {
walk(item, next, fn, options);
}
}

@@ -910,3 +940,3 @@ }

}
});
}, options);
}

@@ -913,0 +943,0 @@ exports.removeValue = removeValue;

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