Ivandt logo

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_underscores is 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:

PropertyTypeRequiredDefaultDescription
options.allow_display_namebooleanNofalsePreserve "Display Name <email>" format
options.allow_underscoresbooleanNofalseKeep underscores instead of converting to dots
options.require_tldbooleanNotrueAdd TLD (.com, .net, .org) if missing
options.blacklisted_charsstringNo-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>" with allow_display_name: false

  • Output: "john@example.com"

  • Input: "John Doe <john@example.com>" with allow_display_name: true

  • Output: "John Doe <john@example.com>"

Underscore handling:

  • Input: "first_last@company.com" with allow_underscores: false

  • Output: "first.last@company.com"

  • Input: "first_last@company.com" with allow_underscores: true

  • Output: "first_last@company.com"

TLD completion:

  • Input: "user@icloud" with require_tld: true

  • Output: "user@icloud.com"

  • Input: "user@localhost" with require_tld: false

  • Output: "user@localhost"

Blacklisted characters:

  • Input: "user#name@example.com" with blacklisted_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:

PropertyTypeRequiredDefaultDescription
countriesCountryCode[]Yes-List of country codes to validate against. Phone number must be valid for at least one of these countries
withInternationalCodebooleanNofalseWhether to format with international dialing code
{
  key: 'phone',
  label: 'Phone',
  type: 'text',
  transformers: [
    {
      action: 'formatPhoneNumbers',
      payload: {
        countries: ['US', 'CA'],
        withInternationalCode: true
      }
    }
  ]
}

Examples:

  • Input: "4139009670" with countries: ['US'], withInternationalCode: true

  • Output: "+1 413 900 9670"

  • Input: "4139009670" with countries: ['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:

PropertyTypeRequiredDefaultDescription
enforceHttpsbooleanNofalseWhether to force all URLs to use HTTPS protocol
removeQueryParamsbooleanNofalseWhether 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" with removeQueryParams: 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:

PropertyTypeRequiredDescription
direction'codeToName' | 'nameToCode'YesDirection 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"