UNPKG

mingo

Version:

MongoDB query language for in-memory objects

23 lines (22 loc) 752 B
import { evalExpr } from "../../../core/_internal"; import { isArray, isNil, isString } from "../../../util"; import { assert, simpleCmp } from "../../../util/_internal"; import { errExpectArray } from "../_internal"; const $strcasecmp = (obj, expr, options) => { assert(isArray(expr) && expr.length === 2, `$strcasecmp expects array(2)`); const args = evalExpr(obj, expr, options); const foe = options.failOnError; let t_nil = true; let t_str = true; for (const v of args) { t_nil &&= isNil(v); t_str &&= isString(v); } if (t_nil) return 0; if (!t_str) return errExpectArray(foe, `$strcasecmp arguments`, { type: "string" }); return simpleCmp(args[0].toLowerCase(), args[1].toLowerCase()); }; export { $strcasecmp };