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
Copy file name to clipboardExpand all lines: docs/syntax.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,6 +112,8 @@ The unary `+` and `-` operators are an exception, and always have their normal p
112
112
113
113
Besides the "operator" functions, there are several pre-defined functions. You can provide your own, by binding variables to normal JavaScript functions. These are not evaluated by simplify.
114
114
115
+
### Numeric Functions
116
+
115
117
| Function | Description |
116
118
|:------------- |:----------- |
117
119
| random(n) | Get a random number in the range [0, n). If n is zero, or not provided, it defaults to 1. |
@@ -124,15 +126,27 @@ Besides the "operator" functions, there are several pre-defined functions. You c
124
126
| pow(x, y) | Equivalent to x^y. For consistency with JavaScript's Math object. |
125
127
| atan2(y, x) | Arc tangent of x/y. i.e. the angle between (0, 0) and (x, y) in radians. |
126
128
| roundTo(x, n) | Rounds x to n places after the decimal point. |
129
+
130
+
### Array Functions
131
+
132
+
| Function | Description |
133
+
|:------------- |:----------- |
127
134
| count(a) | Returns the number of items in an array. |
128
135
| map(f, a) | Array map: Pass each element of `a` the function `f`, and return an array of the results. |
129
136
| fold(f, y, a) | Array fold: Fold/reduce array `a` into a single value, `y` by setting `y = f(y, x, index)` for each element `x` of the array. |
130
137
| filter(f, a) | Array filter: Return an array containing only the values from `a` where `f(x, index)` is `true`. |
131
138
| indexOf(x, a) | Return the first index of string or array `a` matching the value `x`, or `-1` if not found. |
132
139
| join(sep, a) | Concatenate the elements of `a`, separated by `sep`. |
140
+
| naturalSort(arr) | Sorts an array of strings using natural sort order (alphanumeric-aware). For example, `["file10", "file2", "file1"]` becomes `["file1", "file2", "file10"]`. |
141
+
142
+
### Utility Functions
143
+
144
+
| Function | Description |
145
+
|:------------- |:----------- |
133
146
| if(c, a, b) | Function form of c ? a : b. Note: This always evaluates both `a` and `b`, regardless of whether `c` is `true` or not. Use `c ? a : b` instead if there are side effects, or if evaluating the branches could be expensive. |
147
+
| coalesce(a, b, ...) | Returns the first non-null and non-empty string value from the arguments. Numbers and booleans (including 0 and false) are considered valid values. |
134
148
135
-
## String Manipulation Functions
149
+
## String Functions
136
150
137
151
The parser includes comprehensive string manipulation capabilities.
138
152
@@ -166,19 +180,13 @@ The parser includes comprehensive string manipulation capabilities.
166
180
| right(str, n) | Returns the rightmost `n` characters from a string. |
167
181
| split(str, delim)| Splits a string by delimiter and returns an array. |
168
182
169
-
### String Manipulation
183
+
### String Replacement
170
184
171
185
| Function | Description |
172
186
|:--------------------------- |:----------- |
173
187
| replace(str, old, new) | Replaces all occurrences of `old` with `new` in `str`. |
174
188
| replaceFirst(str, old, new) | Replaces only the first occurrence of `old` with `new` in `str`. |
175
189
176
-
### String/Array Sorting
177
-
178
-
| Function | Description |
179
-
|:---------------- |:----------- |
180
-
| naturalSort(arr) | Sorts an array of strings using natural sort order (alphanumeric-aware). For example, `["file10", "file2", "file1"]` becomes `["file1", "file2", "file10"]`. |
181
-
182
190
### Type Conversion
183
191
184
192
| Function | Description |
@@ -203,12 +211,6 @@ The parser includes comprehensive string manipulation capabilities.
203
211
| base64Encode(str) | Base64-encodes a string with proper UTF-8 support. |
204
212
| base64Decode(str) | Base64-decodes a string with proper UTF-8 support. |
205
213
206
-
### Utility Functions
207
-
208
-
| Function | Description |
209
-
|:--------------------- |:----------- |
210
-
| coalesce(a, b, ...) | Returns the first non-null and non-empty string value from the arguments. Numbers and booleans (including 0 and false) are considered valid values. |
> **Note:** All string functions return `undefined` if any of their required arguments are `undefined`, allowing for safe chaining and conditional logic.
279
281
280
-
## Object Manipulation Functions
282
+
## Object Functions
281
283
282
284
The parser includes functions for working with objects.
0 commit comments