UNPKG

mingo

Version:

MongoDB query language for in-memory objects

24 lines (23 loc) 499 B
import { computeValue } from "../../../core"; import { truthy } from "../../../util"; 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 };