Core Concepts
More often than not, the data provided by your end-users won't be in perfect shape. Extra trailing spaces, incorrectly formatted phone numbers, and other frequent irregularities that take time and effort to resolve.
importOK transformers are designed specifically to resolve this, by allowing you to apply common fixes. The transformation happens right after the file is uploaded and before the validation.
Let's see how we can extend our previous example, to make sure that all values have no leading or trailing spaces. For that purpose, we will be using the trim
transformer.
1[ 2 { 3 "label": "First name", 4 "transformers": "trim" 5 }, 6 { 7 "label": "Last name", 8 "transformers": "trim" 9 },10 {11 "label": "Phone",12 "transformers": "trim"13 },14 {15 "label": "Email",16 "transformers": "trim"17 },18 {19 "label": "Country",20 "transformers": "trim"21 }22]
Let's see how we can more transformers. We are looking to capitalize the first and last name, make sure that emails are always in lower case and that the country code is always in upper case. You can chain multiple transformers using pipe syntax.
1[ 2 { 3 "label": "First name", 4 "transformers": "trim|capitalize" 5 }, 6 { 7 "label": "Last name", 8 "transformers": "trim|capitalize" 9 },10 {11 "label": "Phone",12 "transformers": "trim"13 },14 {15 "label": "Email",16 "transformers": "trim|lowercase"17 },18 {19 "label": "Country",20 "transformers": "trim|uppercase"21 }22]
Transformer | Description |
---|---|
as:*provider* |
Uses the specified data provider to convert a value to the right label, or even finding the right value if a label was provided. |
capitalize |
Capitalizes the first letter of the string. |
date |
Converts a date from Excel format or Unix timestamp into YYYY-MM-DD . |
integer |
Converts the string to a numeric string, by removing any non digits. In case the string contains no digits, it remains unchanged. |
lowercase |
Converts the string to lowercase letters. |
number |
Converts the string to a numeric string (with floating-point), by removing any non digits. In case the string contains no digits, it remains unchanged. |
replace:*a*,*b* |
Replaces all matches of a with b |
trim |
Removes trailing and leading spaces from the string. |
uppercase |
Converts the string to uppercase letters. |
On top of the built-in transformers, you can always build your own transformers so that you can auto heal and format data based on your requirements.