1
0

Implement != operator for arrays

This commit is contained in:
Zef Hemel 2023-10-04 09:29:46 +02:00
parent b3bffd5f9a
commit 6dc62f8d14

View File

@ -80,19 +80,23 @@ export function evalQueryExpression(
case "=": {
if (Array.isArray(val1) && !Array.isArray(val2)) {
// Record property is an array, and value is a scalar: find the value in the array
if (val1.includes(val2)) {
return true;
}
return val1.includes(val2);
} else if (Array.isArray(val1) && Array.isArray(val2)) {
// Record property is an array, and value is an array: find the value in the array
if (val1.some((v) => val2.includes(v))) {
return true;
}
return val1.some((v) => val2.includes(v));
}
return val1 == val2;
}
case "!=":
return val1 != val2;
case "!=": {
if (Array.isArray(val1) && !Array.isArray(val2)) {
// Record property is an array, and value is a scalar: find the value in the array
return !val1.includes(val2);
} else if (Array.isArray(val1) && Array.isArray(val2)) {
// Record property is an array, and value is an array: find the value in the array
return !val1.some((v) => val2.includes(v));
}
return val1 !== val2;
}
case "=~": {
if (!Array.isArray(val2)) {
throw new Error(`Invalid regexp: ${val2}`);