* Compare two values using the given operator. * Returns true if the comparison holds.
(left: any, operator: BinaryOperator, right: any)
| 2108 | * Returns true if the comparison holds. |
| 2109 | */ |
| 2110 | function compareValues(left: any, operator: BinaryOperator, right: any): boolean { |
| 2111 | switch (operator) { |
| 2112 | case "=": { |
| 2113 | if (left == null) { |
| 2114 | return right == null; |
| 2115 | } |
| 2116 | if (right == null) { |
| 2117 | return false; |
| 2118 | } |
| 2119 | if (typeof left === "object" && typeof right === "string") { |
| 2120 | return String(left) === right; |
| 2121 | } |
| 2122 | if (typeof left !== typeof right) { |
| 2123 | return false; |
| 2124 | } |
| 2125 | if (typeof right === "object") { |
| 2126 | return compare(left, right) === 0; |
| 2127 | } |
| 2128 | return left === right; |
| 2129 | } |
| 2130 | case "!=": { |
| 2131 | if (left == null) { |
| 2132 | return right !== null; |
| 2133 | } |
| 2134 | if (right == null) { |
| 2135 | return true; |
| 2136 | } |
| 2137 | if (typeof left === "object" && typeof right === "string") { |
| 2138 | return String(left) !== right; |
| 2139 | } |
| 2140 | if (typeof left !== typeof right) { |
| 2141 | return true; |
| 2142 | } |
| 2143 | if (typeof right === "object") { |
| 2144 | return compare(left, right) !== 0; |
| 2145 | } |
| 2146 | return left !== right; |
| 2147 | } |
| 2148 | case "<": |
| 2149 | return left < right; |
| 2150 | case "<=": |
| 2151 | return left <= right; |
| 2152 | case ">": |
| 2153 | return left > right; |
| 2154 | case ">=": |
| 2155 | return left >= right; |
| 2156 | default: |
| 2157 | // Handle string predicates, regex etc - not supported in expression conditions |
| 2158 | return false; |
| 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | function evaluateBinaryCondition( |
| 2163 | path: TraversalPath<any, any, any>, |
no test coverage detected