Format transformers
Transformers for formatting specific data types
formatBooleans
Converts various boolean representations to true/false. Recognizes common boolean values (case-insensitive). Empty values become false. Unrecognized values are left unchanged.
Recognized values:
- Truthy: "true", "yes", "1", "✓", "✔", "on", "y", "t"
- Falsy: "false", "no", "0", "✗", "✘", "off", "n", "f"
Payload: None required
{
key: 'is_active',
label: 'Is active',
type: 'checkbox',
transformers: [
{
action: 'formatBooleans'
}
]
}Examples:
- Input:
"yes"→ Output:true - Input:
"no"→ Output:false - Input:
"1"→ Output:true - Input:
"0"→ Output:false - Input:
"✓"→ Output:true - Input:
""→ Output:false
formatEmails
Cleans and normalizes email addresses. Invalid emails are left unchanged.
Transformations applied:
- Removes "mailto:" prefix
- Lowercases the email
- Removes spaces and extra dots
- Converts underscores to dots (unless
allow_underscoresis true) - Removes blacklisted characters
- Attempts to fix missing @ symbols
- Auto-completes missing TLDs (.com, .net, .org)
- Extracts or preserves display name based on options
Payload:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
options.allow_display_name | boolean | No | false | Preserve "Display Name <email>" format |
options.allow_underscores | boolean | No | false | Keep underscores instead of converting to dots |
options.require_tld | boolean | No | true | Add TLD (.com, .net, .org) if missing |
options.blacklisted_chars | string | No | - | Characters to remove during cleanup |
Note: When used with validators, the transformer respects additional validation options but only the above options affect the transformation behavior.
{
key: 'email',
label: 'Email',
type: 'text',
transformers: [
{
action: 'formatEmails',
payload: {
options: {
allow_display_name: false,
allow_underscores: false,
require_tld: true
}
}
}
]
}Examples:
Basic cleanup:
- Input:
" JOHN@EXAMPLE.COM " - Output:
"john@example.com"
Display name handling:
-
Input:
"John Doe <john@example.com>"withallow_display_name: false -
Output:
"john@example.com" -
Input:
"John Doe <john@example.com>"withallow_display_name: true -
Output:
"John Doe <john@example.com>"
Underscore handling:
-
Input:
"first_last@company.com"withallow_underscores: false -
Output:
"first.last@company.com" -
Input:
"first_last@company.com"withallow_underscores: true -
Output:
"first_last@company.com"
TLD completion:
-
Input:
"user@icloud"withrequire_tld: true -
Output:
"user@icloud.com" -
Input:
"user@localhost"withrequire_tld: false -
Output:
"user@localhost"
Blacklisted characters:
- Input:
"user#name@example.com"withblacklisted_chars: '#' - Output:
"username@example.com"
formatPhoneNumbers
Formats and validates phone numbers using libphonenumber-js. Invalid numbers are left unchanged.
Transformations applied:
- Cleans non-digit characters
- Validates against specified countries
- Formats as international (+61 413 900 967) or national (0413 900 967)
Payload:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
countries | CountryCode[] | Yes | - | List of country codes to validate against. Phone number must be valid for at least one of these countries |
withInternationalCode | boolean | No | false | Whether to format with international dialing code |
{
key: 'phone',
label: 'Phone',
type: 'text',
transformers: [
{
action: 'formatPhoneNumbers',
payload: {
countries: ['US', 'CA'],
withInternationalCode: true
}
}
]
}Examples:
-
Input:
"4139009670"withcountries: ['US'],withInternationalCode: true -
Output:
"+1 413 900 9670" -
Input:
"4139009670"withcountries: ['US'],withInternationalCode: false -
Output:
"(413) 900-9670"
normalizeUrls
Normalizes and standardizes URL formats. Unparseable strings are left unchanged.
Transformations applied:
- Adds protocol if missing (defaults to http://)
- Lowercases hostname
- Optionally enforces HTTPS
- Optionally removes or sorts query parameters
Payload:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
enforceHttps | boolean | No | false | Whether to force all URLs to use HTTPS protocol |
removeQueryParams | boolean | No | false | Whether to remove all query parameters. When false, query parameters are sorted alphabetically |
{
key: 'website',
label: 'Website',
type: 'text',
transformers: [
{
action: 'normalizeUrls',
payload: {
enforceHttps: true,
removeQueryParams: false
}
}
]
}Examples:
-
Input:
"example.com/path?b=2&a=1" -
Output:
"https://example.com/path?a=1&b=2" -
Input:
"HTTP://EXAMPLE.COM" -
Output:
"https://example.com" -
Input:
"example.com/path?foo=bar"withremoveQueryParams: true -
Output:
"https://example.com/path"
mapCountryNames
Converts between country codes and country names using the country-list library. Unrecognized values are left unchanged.
Payload:
| Property | Type | Required | Description |
|---|---|---|---|
direction | 'codeToName' | 'nameToCode' | Yes | Direction of conversion |
{
key: 'country',
label: 'Country',
type: 'text',
transformers: [
{
action: 'mapCountryNames',
payload: {
direction: 'codeToName'
}
}
]
}Examples (codeToName):
- Input:
"US"→ Output:"United States" - Input:
"FR"→ Output:"France" - Input:
"GB"→ Output:"United Kingdom"
Examples (nameToCode):
- Input:
"United States"→ Output:"US" - Input:
"France"→ Output:"FR" - Input:
"United Kingdom"→ Output:"GB"