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: Fix-function-and-Cookbook.md
+75-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
This page is a replication of the passage of the Fix Readme.md.
1
+
This page is a replication of the passage of the Fix Readme.md. Status: [Fix Release 1.0.0](https://github.com/metafacture/metafacture-fix/releases/tag/1.0.0)
2
2
3
3
## Functions and cookbook
4
4
@@ -66,6 +66,8 @@ Does nothing. It is used for benchmarking in Catmandu.
66
66
nothing()
67
67
```
68
68
69
+
[Example in Playground](https://metafacture.org/playground/?example=nothing)
70
+
69
71
##### `put_filemap`
70
72
71
73
Defines an external map for [lookup](#lookup) from a file or a URL. Maps with more than 2 columns are supported but are reduced to a defined key and a value column.
@@ -74,6 +76,8 @@ Defines an external map for [lookup](#lookup) from a file or a URL. Maps with mo
[Example in Playground](https://metafacture.org/playground/?example=set_array)
356
+
325
357
##### `set_field`
326
358
327
359
Creates (or replaces) a field with a defined value.
@@ -361,6 +393,8 @@ Deletes empty fields, arrays and objects.
361
393
vacuum()
362
394
```
363
395
396
+
[Example in Playground](https://metafacture.org/playground/?example=vacuum)
397
+
364
398
#### Field-level functions
365
399
366
400
##### `append`
@@ -371,6 +405,8 @@ Adds a string at the end of a field value.
371
405
append("<sourceField>", "<appendString>")
372
406
```
373
407
408
+
[Example in Playground](https://metafacture.org/playground/?example=append)
409
+
374
410
##### `capitalize`
375
411
376
412
Upcases the first character in a field value.
@@ -379,6 +415,8 @@ Upcases the first character in a field value.
379
415
capitalize("<sourceField>")
380
416
```
381
417
418
+
[Example in Playground](https://metafacture.org/playground/?example=capitalize)
419
+
382
420
##### `count`
383
421
384
422
Counts the number of elements in an array or a hash and replaces the field value with this number.
@@ -395,6 +433,8 @@ Downcases all characters in a field value.
395
433
downcase("<sourceField>")
396
434
```
397
435
436
+
[Example in Playground](https://metafacture.org/playground/?example=downcase)
437
+
398
438
##### `filter`
399
439
400
440
Only keeps field values that match the regular expression pattern. Works only with array of strings/repeated fields.
@@ -411,6 +451,8 @@ Flattens a nested array field.
411
451
flatten("<sourceField>")
412
452
```
413
453
454
+
[Example in Playground](https://metafacture.org/playground/?example=flatten)
455
+
414
456
##### `from_json`
415
457
416
458
Replaces the string with its JSON deserialization.
@@ -445,6 +487,8 @@ Options:
445
487
isbn("<sourceField>"[, to: "<isbnFormat>"][, verify_check_digit: "<boolean>"][, error_string: "<errorValue>"])
446
488
```
447
489
490
+
[Example in Playground](https://metafacture.org/playground/?example=isbn)
491
+
448
492
##### `join_field`
449
493
450
494
Joins an array of strings into a single string.
@@ -453,6 +497,8 @@ Joins an array of strings into a single string.
453
497
join_field("<sourceField>", "<separator>")
454
498
```
455
499
500
+
[Example in Playground](https://metafacture.org/playground/?example=join_field)
501
+
456
502
##### `lookup`
457
503
458
504
Looks up matching values in a map and replaces the field value with this match. [External files](#put_filemap), [internal maps](#put_map) as well as [RDF resources](#put_rdfmap) can be used.
@@ -520,6 +566,8 @@ Adds a string at the beginning of a field value.
520
566
prepend("<sourceField>", "<prependString>")
521
567
```
522
568
569
+
[Example in Playground](https://metafacture.org/playground/?example=prepend)
570
+
523
571
##### `replace_all`
524
572
525
573
Replaces a regular expression pattern in field values with a replacement string. Regexp capturing is possible; refer to capturing groups by number (`$<number>`) or name (`${<name>}`).
@@ -528,6 +576,8 @@ Replaces a regular expression pattern in field values with a replacement string.
[Example in Playground](https://metafacture.org/playground/?example=sort_field)
600
+
549
601
##### `split_field`
550
602
551
603
Splits a string into an array and replaces the field value with this array.
@@ -554,6 +606,8 @@ Splits a string into an array and replaces the field value with this array.
554
606
split_field("<sourceField>", "<separator>")
555
607
```
556
608
609
+
[Example in Playground](https://metafacture.org/playground/?example=split_field)
610
+
557
611
##### `substring`
558
612
559
613
Replaces a string with its substring as defined by the start position (offset) and length.
@@ -591,6 +645,8 @@ Deletes whitespace at the beginning and the end of a field value.
591
645
trim("<sourceField>")
592
646
```
593
647
648
+
[Example in Playground](https://metafacture.org/playground/?example=trim)
649
+
594
650
##### `uniq`
595
651
596
652
Deletes duplicate values in an array.
@@ -599,6 +655,9 @@ Deletes duplicate values in an array.
599
655
uniq("<sourceField>")
600
656
```
601
657
658
+
[Example in Playground](https://metafacture.org/playground/?example=uniq)
659
+
660
+
602
661
##### `upcase`
603
662
604
663
Upcases all characters in a field value.
@@ -607,6 +666,8 @@ Upcases all characters in a field value.
607
666
upcase("<sourceField>")
608
667
```
609
668
669
+
[Example in Playground](https://metafacture.org/playground/?example=upcase)
670
+
610
671
##### `uri_encode`
611
672
612
673
Encodes a field value as URI. Aka percent-encoding.
@@ -638,6 +699,8 @@ if <condition>
638
699
end
639
700
```
640
701
702
+
[Example in Playground](https://metafacture.org/playground/?example=reject)
703
+
641
704
### Binds
642
705
643
706
#### `do list`
@@ -650,6 +713,8 @@ do list(path: "<sourceField>")
650
713
end
651
714
```
652
715
716
+
[Example in Playground](https://metafacture.org/playground/?example=do_list)
717
+
653
718
Only the current element is accessible in this case (as the root element).
654
719
655
720
When specifying a variable name for the current element, the record remains accessible as the root element and the current element is accessible through the variable name:
@@ -660,6 +725,8 @@ do list(path: "<sourceField>", "var": "<variableName>")
660
725
end
661
726
```
662
727
728
+
[Example in Playground](https://metafacture.org/playground/?example=do_list_with_var)
729
+
663
730
#### `do list_as`
664
731
665
732
Iterates over each _named_ element of an array (like [`do list`](#do-list) with a variable name). If multiple arrays are given, iterates over the _corresponding_ elements from each array (i.e., all elements with the same array index, skipping elements whose arrays have already been exhausted).
@@ -693,6 +760,8 @@ do once()
693
760
end
694
761
```
695
762
763
+
[Example in Playground](https://metafacture.org/playground/?example=do_once)
764
+
696
765
In order to execute multiple blocks only once, tag them with unique identifiers:
[Example in Playground](https://metafacture.org/playground/?example=do_put_macro)
802
+
732
803
### Conditionals
733
804
734
805
Conditionals start with `if` in case of affirming the condition or `unless` rejecting the condition.
@@ -865,3 +936,6 @@ Executes the functions if/unless the field value does not match the regular expr
865
936
866
937
Executes the functions if/unless the string matches the regular expression pattern.
867
938
939
+
## Xtext
940
+
941
+
This repo has been originally set up with [Xtext](https://www.eclipse.org/Xtext/) 2.17.0 and Eclipse for Java 2019-03, following [https://www.eclipse.org/Xtext/documentation/104_jvmdomainmodel.html](https://www.eclipse.org/Xtext/documentation/104_jvmdomainmodel.html).
0 commit comments