Skip to content

Commit c9042c3

Browse files
authored
Reorganize docs/syntax.md functions into categorized sections (#30)
* Rearrange functions in docs/syntax.md into categorized sections
1 parent 5cd7549 commit c9042c3

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

docs/syntax.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ The unary `+` and `-` operators are an exception, and always have their normal p
112112

113113
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.
114114

115+
### Numeric Functions
116+
115117
| Function | Description |
116118
|:------------- |:----------- |
117119
| 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
124126
| pow(x, y) | Equivalent to x^y. For consistency with JavaScript's Math object. |
125127
| atan2(y, x) | Arc tangent of x/y. i.e. the angle between (0, 0) and (x, y) in radians. |
126128
| roundTo(x, n) | Rounds x to n places after the decimal point. |
129+
130+
### Array Functions
131+
132+
| Function | Description |
133+
|:------------- |:----------- |
127134
| count(a) | Returns the number of items in an array. |
128135
| map(f, a) | Array map: Pass each element of `a` the function `f`, and return an array of the results. |
129136
| 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. |
130137
| filter(f, a) | Array filter: Return an array containing only the values from `a` where `f(x, index)` is `true`. |
131138
| indexOf(x, a) | Return the first index of string or array `a` matching the value `x`, or `-1` if not found. |
132139
| 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+
|:------------- |:----------- |
133146
| 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. |
134148

135-
## String Manipulation Functions
149+
## String Functions
136150

137151
The parser includes comprehensive string manipulation capabilities.
138152

@@ -166,19 +180,13 @@ The parser includes comprehensive string manipulation capabilities.
166180
| right(str, n) | Returns the rightmost `n` characters from a string. |
167181
| split(str, delim)| Splits a string by delimiter and returns an array. |
168182

169-
### String Manipulation
183+
### String Replacement
170184

171185
| Function | Description |
172186
|:--------------------------- |:----------- |
173187
| replace(str, old, new) | Replaces all occurrences of `old` with `new` in `str`. |
174188
| replaceFirst(str, old, new) | Replaces only the first occurrence of `old` with `new` in `str`. |
175189

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-
182190
### Type Conversion
183191

184192
| Function | Description |
@@ -203,12 +211,6 @@ The parser includes comprehensive string manipulation capabilities.
203211
| base64Encode(str) | Base64-encodes a string with proper UTF-8 support. |
204212
| base64Decode(str) | Base64-decodes a string with proper UTF-8 support. |
205213

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. |
211-
212214
### String Function Examples
213215

214216
```js
@@ -277,7 +279,7 @@ parser.evaluate('toUpper(trim(left(" hello world ", 10)))'); // "HELLO WOR"
277279

278280
> **Note:** All string functions return `undefined` if any of their required arguments are `undefined`, allowing for safe chaining and conditional logic.
279281
280-
## Object Manipulation Functions
282+
## Object Functions
281283

282284
The parser includes functions for working with objects.
283285

0 commit comments

Comments
 (0)