UNPKG

mingo

Version:

MongoDB query language for in-memory objects

17 lines (16 loc) 555 B
import { computeValue } from "../../../core/_internal"; import { assert, isObject, truthy } from "../../../util/_internal"; const $switch = (obj, expr, options) => { assert(isObject(expr), "$switch received invalid arguments"); for (const { case: caseExpr, then } of expr.branches) { const condition = truthy( computeValue(obj, caseExpr, null, options), options.useStrictMode ); if (condition) return computeValue(obj, then, null, options); } return computeValue(obj, expr.default, null, options); }; export { $switch };