Skip to content

Commit

Permalink
Implement != operator for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Oct 4, 2023
1 parent b3bffd5 commit 6dc62f8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions plug-api/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit 6dc62f8

Please sign in to comment.