mingo
Version:
MongoDB query language for in-memory objects
23 lines (22 loc) • 513 B
JavaScript
import { computeValue } from "../../../core/_internal";
import { truthy } from "../../../util/_internal";
const $switch = (obj, expr, options) => {
let thenExpr = null;
expr.branches.some((b) => {
const condition = truthy(
computeValue(obj, b.case, null, options),
options.useStrictMode
);
if (condition) thenExpr = b.then;
return condition;
});
return computeValue(
obj,
thenExpr !== null ? thenExpr : expr.default,
null,
options
);
};
export {
$switch
};