mingo
Version:
MongoDB query language for in-memory objects
18 lines (17 loc) • 683 B
JavaScript
import { computeValue } 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 = computeValue(obj, expr, null, options);
const foe = options.failOnError;
if (args.every(isNil)) return 0;
if (!args.every(isString))
return errExpectArray(foe, `$strcasecmp arguments`, { type: "string" });
const [a, b] = args.map((s) => s.toLowerCase());
return simpleCmp(a, b);
};
export {
$strcasecmp
};