mingo
Version:
MongoDB query language for in-memory objects
28 lines (27 loc) • 729 B
JavaScript
import { computeValue } from "../../../core/_internal";
import { isNumber } from "../../../util";
import { errExpectNumber } from "../_internal";
function processOperator(obj, expr, options, fn, fixedPoints) {
const fp = {
undefined: null,
null: null,
NaN: NaN,
Infinity: new Error(),
"-Infinity": new Error(),
...fixedPoints
};
const foe = options.failOnError;
const op = fn.name;
const n = computeValue(obj, expr, null, options);
if (n in fp) {
const res = fp[n];
if (res instanceof Error)
return errExpectNumber(foe, `$${op} invalid input '${n}'`);
return res;
}
if (!isNumber(n)) return errExpectNumber(foe, `$${op}`);
return fn(n);
}
export {
processOperator
};