You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: Implement ternary operator
This commit introduces the ternary operator (? :) to the expression language.
The following changes were made:
- Added TernaryNode to AST.type.ts
- Added TOK_QUESTION to Lexer.ts and Lexer.type.ts
- Updated Parser.ts to handle the ternary operator
- Updated TreeInterpreter.ts to evaluate ternary expressions
- Updated compliance tests (points to `feature/ternary-operator` branch for now)
<!-- ps-id: 23d6602d-719c-495d-8421-97a050351f6f -->
* fixed operator precedence
---------
Co-authored-by: Springcomp <springcomp@users.noreply.github.com>
One of the best things about JMESPath is that it is
171
153
implemented in many different programming languages including
172
-
python, ruby, php, lua, etc. To see a complete list of libraries,
154
+
python, ruby, php, lua, etc. To see a complete list of libraries,
173
155
check out the [JMESPath libraries page](http://jmespath.site/main#libraries).
174
156
175
157
And finally, the full JMESPath specification can be found
176
158
on the [JMESPath site](https://jmespath.site/main/#specification).
159
+
160
+
## Experimental Features
161
+
162
+
### Ternary Operations (`?:`)
163
+
164
+
**Supported Version:** 1.1.6
165
+
166
+
Experimental support for [ternary operations](https://github.com/jmespath-community/jmespath.spec/discussions/179) has been added, allowing for conditional logic within your JMESPath expressions. The syntax is `condition ? value_if_true : value_if_false`.
167
+
168
+
- **Condition:** The expression before the `?`. JMESPath determines truthiness based on the evaluated value:
169
+
- `true` is truthy.
170
+
- Any non-empty object, array, or string is truthy.
171
+
- Any non-zero number is truthy.
172
+
- `false`, `null`, empty objects `{}`, empty arrays `[]`, and empty strings `''` are falsy.
173
+
- **Value if true:** The expression between the `?` and `:`. This is evaluated and returned if the condition is truthy.
174
+
- **Value if false:** The expression after the `:`. This is evaluated and returned if the condition is falsy.
175
+
176
+
**Examples:**
177
+
178
+
Basic usage:
179
+
180
+
```javascript
181
+
search({ is_active:true, user:"Alice" }, "is_active ? user : 'Guest'");
182
+
// OUTPUTS: "Alice"
183
+
184
+
search({ is_active:false, user:"Bob" }, "is_active ? user : 'Guest'");
0 commit comments