|
53 | 53 | </tr>
|
54 | 54 | </table>
|
55 | 55 |
|
56 |
| - |
57 | 56 | ## Operators
|
58 | 57 |
|
59 | 58 | <table>
|
@@ -126,8 +125,8 @@ foo matches "^[A-Z].*"
|
126 | 125 | ### Membership Operator
|
127 | 126 |
|
128 | 127 | Fields of structs and items of maps can be accessed with `.` operator
|
129 |
| -or `[]` operator. Elements of arrays and slices can be accessed with |
130 |
| -`[]` operator. Negative indices are supported with `-1` being |
| 128 | +or `[]` operator. Elements of arrays and slices can be accessed with |
| 129 | +`[]` operator. Negative indices are supported with `-1` being |
131 | 130 | the last element.
|
132 | 131 |
|
133 | 132 | The `in` operator can be used to check if an item is in an array or a map.
|
@@ -169,7 +168,6 @@ array[3:] == [4, 5]
|
169 | 168 | array[:] == array
|
170 | 169 | ```
|
171 | 170 |
|
172 |
| - |
173 | 171 | ## Built-in Functions
|
174 | 172 |
|
175 | 173 | ### all(array, predicate)
|
@@ -238,122 +236,262 @@ int("123") == 123
|
238 | 236 |
|
239 | 237 | Returns the float value of a number or a string.
|
240 | 238 |
|
241 |
| -### string() |
| 239 | +### string(v) |
242 | 240 |
|
243 |
| -todo |
| 241 | +Converts the given value `v` into a string representation. |
244 | 242 |
|
245 |
| -### trim() |
| 243 | +```expr |
| 244 | +string(123) == "123" |
| 245 | +``` |
246 | 246 |
|
247 |
| -todo |
| 247 | +### trim(v[, chars]) |
248 | 248 |
|
249 |
| -### trimPrefix() |
| 249 | +Removes white spaces from both ends of a string `v`. |
| 250 | +If the optional `chars` argument is given, it is a string specifying the set of characters to be removed. |
250 | 251 |
|
251 |
| -todo |
| 252 | +```expr |
| 253 | +trim(" Hello ") == "Hello" |
| 254 | +trim("__Hello__", "_") == "Hello" |
| 255 | +``` |
252 | 256 |
|
253 |
| -### trimSuffix() |
| 257 | +### trimPrefix(v, prefix) |
254 | 258 |
|
255 |
| -todo |
| 259 | +Removes the specified prefix from the string `v` if it starts with that prefix. |
256 | 260 |
|
257 |
| -### upper() |
| 261 | +```expr |
| 262 | +trimPrefix("HelloWorld", "Hello") == "World" |
| 263 | +``` |
258 | 264 |
|
259 |
| -todo |
| 265 | +### trimSuffix(v, suffix) |
260 | 266 |
|
261 |
| -### lower() |
| 267 | +Removes the specified suffix from the string `v` if it ends with that suffix. |
262 | 268 |
|
263 |
| -todo |
| 269 | +```expr |
| 270 | +trimSuffix("HelloWorld", "World") == "Hello" |
| 271 | +``` |
264 | 272 |
|
265 |
| -### split() |
| 273 | +### upper(v) |
266 | 274 |
|
267 |
| -todo |
| 275 | +Converts all the characters in string `v` to uppercase. |
268 | 276 |
|
269 |
| -### splitN() |
| 277 | +```expr |
| 278 | +upper("hello") == "HELLO" |
| 279 | +``` |
270 | 280 |
|
271 |
| -todo |
| 281 | +### lower(v) |
272 | 282 |
|
273 |
| -### splitAfter() |
| 283 | +Converts all the characters in string `v` to lowercase. |
274 | 284 |
|
275 |
| -todo |
| 285 | +```expr |
| 286 | +lower("HELLO") == "hello" |
| 287 | +``` |
276 | 288 |
|
277 |
| -### splitAfterN() |
| 289 | +### split(v, delimiter) |
278 | 290 |
|
279 |
| -todo |
| 291 | +Splits the string `v` at each instance of the delimiter and returns an array of substrings. |
280 | 292 |
|
281 |
| -### replace() |
| 293 | +```expr |
| 294 | +split("apple,orange,grape", ",") == ["apple", "orange", "grape"] |
| 295 | +``` |
282 | 296 |
|
283 |
| -todo |
| 297 | +### splitN(v, delimiter, n) |
284 | 298 |
|
285 |
| -### repeat() |
| 299 | +Splits the string `v` at each instance of the delimiter but limits the result to `n` substrings. |
286 | 300 |
|
287 |
| -todo |
| 301 | +```expr |
| 302 | +splitN("apple,orange,grape", ",", 2) == ["apple", "orange,grape"] |
| 303 | +``` |
288 | 304 |
|
289 |
| -### join() |
| 305 | +### splitAfter(v, delimiter) |
290 | 306 |
|
291 |
| -todo |
| 307 | +Splits the string `v` after each instance of the delimiter. |
292 | 308 |
|
293 |
| -### indexOf() |
| 309 | +```expr |
| 310 | +splitAfter("apple,orange,grape", ",") == ["apple,", "orange,", "grape"] |
| 311 | +``` |
294 | 312 |
|
295 |
| -todo |
| 313 | +### splitAfterN(v, delimiter, n) |
296 | 314 |
|
297 |
| -### lastIndexOf() |
| 315 | +Splits the string `v` after each instance of the delimiter but limits the result to `n` substrings. |
298 | 316 |
|
299 |
| -todo |
| 317 | +```expr |
| 318 | +splitAfterN("apple,orange,grape", ",", 2) == ["apple,", "orange,grape"] |
| 319 | +``` |
300 | 320 |
|
301 |
| -### hasPrefix() |
| 321 | +### replace(v, old, new) |
302 | 322 |
|
303 |
| -todo |
| 323 | +Replaces all occurrences of `old` in string `v` with `new`. |
304 | 324 |
|
305 |
| -### hasSuffix() |
| 325 | +```expr |
| 326 | +replace("Hello World", "World", "Universe") == "Hello Universe" |
| 327 | +``` |
306 | 328 |
|
307 |
| -todo |
| 329 | +### repeat(v, n) |
308 | 330 |
|
309 |
| -### max() |
| 331 | +Repeats the string `v` `n` times. |
310 | 332 |
|
311 |
| -todo |
| 333 | +```expr |
| 334 | +repeat("Hi", 3) == "HiHiHi" |
| 335 | +``` |
| 336 | + |
| 337 | +### join(v, delimiter) |
| 338 | + |
| 339 | +Joins an array of strings `v` into a single string with the given delimiter. |
| 340 | + |
| 341 | +```expr |
| 342 | +join(["apple", "orange", "grape"], ",") == "apple,orange,grape" |
| 343 | +``` |
312 | 344 |
|
313 |
| -### min() |
| 345 | +### indexOf(v, substring) |
314 | 346 |
|
315 |
| -todo |
| 347 | +Returns the index of the first occurrence of the substring in string `v` or -1 if not found. |
316 | 348 |
|
317 |
| -### toJSON() |
| 349 | +```expr |
| 350 | +indexOf("apple pie", "pie") == 6 |
| 351 | +``` |
318 | 352 |
|
319 |
| -todo |
| 353 | +### lastIndexOf(v, substring) |
320 | 354 |
|
321 |
| -### fromJSON() |
| 355 | +Returns the index of the last occurrence of the substring in string `v` or -1 if not found. |
322 | 356 |
|
323 |
| -todo |
| 357 | +```expr |
| 358 | +lastIndexOf("apple pie apple", "apple") == 10 |
| 359 | +``` |
324 | 360 |
|
325 |
| -### toBase64() |
| 361 | +### hasPrefix(v, prefix) |
326 | 362 |
|
327 |
| -todo |
| 363 | +Returns `true` if string `v` starts with the given prefix. |
328 | 364 |
|
329 |
| -### fromBase64() |
| 365 | +```expr |
| 366 | +hasPrefix("HelloWorld", "Hello") == true |
| 367 | +``` |
| 368 | + |
| 369 | +### hasSuffix(v, suffix) |
| 370 | + |
| 371 | +Returns `true` if string `v` ends with the given suffix. |
| 372 | + |
| 373 | +```expr |
| 374 | +hasSuffix("HelloWorld", "World") == true |
| 375 | +``` |
| 376 | + |
| 377 | +### max(v1, v2) |
| 378 | + |
| 379 | +Returns the maximum of the two values `v1` and `v2`. |
| 380 | + |
| 381 | +```expr |
| 382 | +max(5, 7) == 7 |
| 383 | +``` |
330 | 384 |
|
331 |
| -todo |
| 385 | +### min(v1, v2) |
| 386 | + |
| 387 | +Returns the minimum of the two values `v1` and `v2`. |
| 388 | + |
| 389 | +```expr |
| 390 | +min(5, 7) == 5 |
| 391 | +``` |
| 392 | + |
| 393 | +### toJSON(v) |
| 394 | + |
| 395 | +Converts the given value `v` to its JSON string representation. |
| 396 | + |
| 397 | +```expr |
| 398 | +toJSON({"name": "John", "age": 30}) |
| 399 | +``` |
| 400 | + |
| 401 | +### fromJSON(v) |
| 402 | + |
| 403 | +Parses the given JSON string `v` and returns the corresponding value. |
| 404 | + |
| 405 | +```expr |
| 406 | +fromJSON('{"name": "John", "age": 30}') |
| 407 | +``` |
| 408 | + |
| 409 | +### toBase64(v) |
| 410 | + |
| 411 | +Encodes the string `v` into Base64 format. |
| 412 | + |
| 413 | +```expr |
| 414 | +toBase64("Hello World") == "SGVsbG8gV29ybGQ=" |
| 415 | +``` |
| 416 | + |
| 417 | +### fromBase64(v) |
| 418 | + |
| 419 | +Decodes the Base64 encoded string `v` back to its original form. |
| 420 | + |
| 421 | +```expr |
| 422 | +fromBase64("SGVsbG8gV29ybGQ=") == "Hello World" |
| 423 | +``` |
332 | 424 |
|
333 | 425 | ### now()
|
334 | 426 |
|
335 |
| -todo |
| 427 | +Returns the current date and time. |
| 428 | + |
| 429 | +```expr |
| 430 | +createdAt > now() - duration(1h) |
| 431 | +``` |
| 432 | + |
| 433 | +### duration(v) |
| 434 | + |
| 435 | +Returns [time.Duration](https://pkg.go.dev/time#Duration) value of the given string `v`. |
336 | 436 |
|
337 |
| -### duration() |
| 437 | +Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". |
338 | 438 |
|
339 |
| -todo |
| 439 | +```expr |
| 440 | +duration("1h").Seconds() == 3600 |
| 441 | +``` |
| 442 | + |
| 443 | +### date(v[, format, timezone]) |
340 | 444 |
|
341 |
| -### date() |
| 445 | +Converts the given value `v` into a date representation. |
342 | 446 |
|
343 |
| -todo |
| 447 | +If the optional `format` argument is given, it is a string specifying the format of the date. |
| 448 | +The format string uses the same formatting rules as the standard |
| 449 | +Go [time package](https://pkg.go.dev/time#pkg-constants). |
344 | 450 |
|
345 |
| -### first() |
| 451 | +If the optional `timezone` argument is given, it is a string specifying the timezone of the date. |
346 | 452 |
|
347 |
| -todo |
| 453 | +If the `format` argument is not given, the `v` argument must be in one of the following formats: |
348 | 454 |
|
349 |
| -### last() |
| 455 | +- 2006-01-02 |
| 456 | +- 15:04:05 |
| 457 | +- 2006-01-02 15:04:05 |
| 458 | +- RFC3339 |
| 459 | +- RFC822, |
| 460 | +- RFC850, |
| 461 | +- RFC1123, |
350 | 462 |
|
351 |
| -todo |
| 463 | +```expr |
| 464 | +date("2023-08-14") |
| 465 | +date("15:04:05") |
| 466 | +date("2023-08-14T00:00:00Z") |
| 467 | +date("2023-08-14 00:00:00", "2006-01-02 15:04:05", "Europe/Zurich") |
| 468 | +``` |
352 | 469 |
|
353 |
| -### get() |
| 470 | +### first(v) |
354 | 471 |
|
355 |
| -todo |
| 472 | +Returns the first element from an array `v`. If the array is empty, returns `nil`. |
356 | 473 |
|
| 474 | +```expr |
| 475 | +first([1, 2, 3]) == 1 |
| 476 | +``` |
| 477 | + |
| 478 | +### last(v) |
| 479 | + |
| 480 | +Returns the last element from an array `v`. If the array is empty, returns `nil`. |
| 481 | + |
| 482 | +```expr |
| 483 | +last([1, 2, 3]) == 3 |
| 484 | +``` |
| 485 | + |
| 486 | +### get(v, index) |
| 487 | + |
| 488 | +Retrieves the element at the specified index from an array or map `v`. If the index is out of range, returns `nil`. |
| 489 | +Or the key does not exist, returns `nil`. |
| 490 | + |
| 491 | +```expr |
| 492 | +get([1, 2, 3], 1) == 2 |
| 493 | +get({"name": "John", "age": 30}, "name") == "John" |
| 494 | +``` |
357 | 495 |
|
358 | 496 | ## Predicate
|
359 | 497 |
|
|
0 commit comments