transformers

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

common.go - Common transformation functions

date.go - Date/time transformation functions

number.go - Number transformation functions

phone.go - Phone number normalization for multiple countries

string.go - String transformation functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(transformers ...builders.Transformer) builders.Transformer

Chain allows chaining multiple transformers.

func Clamp

func Clamp(min, max float64) builders.Transformer

Clamp restricts a number to a range.

func Conditional

func Conditional(condition func(interface{}) bool, transformer builders.Transformer) builders.Transformer

Conditional applies a transformer only if a condition is met.

func DateFormat

func DateFormat(fromFormat, toFormat string) builders.Transformer

DateFormat converts between date formats.

func Default

func Default(defaultValue interface{}) builders.Transformer

Default returns a default value if the input is nil or empty.

func EndOfDay

func EndOfDay() builders.Transformer

EndOfDay sets time to 23:59:59.

func FormatPhone

func FormatPhone(country string) builders.Transformer

FormatPhone formats a normalized phone for display.

func FromPercentage

func FromPercentage() builders.Transformer

FromPercentage converts percentage to decimal (15 -> 0.15).

func Lowercase

func Lowercase() builders.Transformer

Lowercase converts string to lowercase.

func NormalizePhone

func NormalizePhone(defaultCountry string) builders.Transformer

NormalizePhone creates a transformer for phone normalization.

func NormalizePhoneWithCountry

func NormalizePhoneWithCountry(country string) builders.Transformer

NormalizePhoneWithCountry normalizes with explicit country.

func NormalizeWhitespace

func NormalizeWhitespace() builders.Transformer

NormalizeWhitespace converts multiple whitespace to single space.

func PadLeft

func PadLeft(minLength int, padChar rune) builders.Transformer

PadLeft pads string on the left to reach minLength.

func ParseDate

func ParseDate(format string) builders.Transformer

ParseDate parses a date string with the given format.

func Percentage

func Percentage() builders.Transformer

Percentage converts a decimal to percentage (0.15 -> 15).

func RemoveCurrencySymbols

func RemoveCurrencySymbols() builders.Transformer

RemoveCurrencySymbols removes common currency symbols.

func RemoveNonAlphanumeric

func RemoveNonAlphanumeric() builders.Transformer

RemoveNonAlphanumeric removes all non-alphanumeric characters.

func RemoveSpaces

func RemoveSpaces() builders.Transformer

RemoveSpaces removes all spaces from string.

func Replace

func Replace(old, new string) builders.Transformer

Replace replaces all occurrences of old with new.

func Round

func Round(decimals int) builders.Transformer

Round rounds a number to specified decimal places.

func StartOfDay

func StartOfDay() builders.Transformer

StartOfDay sets time to 00:00:00.

func TitleCase

func TitleCase() builders.Transformer

TitleCase converts string to title case.

func ToBoolean

func ToBoolean() builders.Transformer

ToBoolean converts value to boolean.

func ToFloat64

func ToFloat64() builders.Transformer

ToFloat64 converts value to float64.

func ToISO8601

func ToISO8601() builders.Transformer

ToISO8601 converts a time to ISO8601 string format.

func ToInt

func ToInt() builders.Transformer

ToInt converts value to int.

func ToString

func ToString() builders.Transformer

ToString converts value to string.

func ToTimezone

func ToTimezone(location string) builders.Transformer

ToTimezone converts time to specified timezone.

func Trim

func Trim() builders.Transformer

Trim removes leading and trailing whitespace.

func Truncate

func Truncate(maxLength int) builders.Transformer

Truncate truncates string to max length.

func Uppercase

func Uppercase() builders.Transformer

Uppercase converts string to uppercase.

Types

type PhoneFormat

type PhoneFormat struct {
	CountryCode   string
	CountryPrefix string
	Formats       []string // Possible input formats (regex)
	NormalizedLen int      // Expected length after normalization (excluding country code)
	OutputFormat  string   // How to format the normalized number
}

PhoneFormat defines the format for a country's phone numbers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL