glugify/transformations
Types
A transformation function that processes text and may fail with an error.
Transformations can be composed together to create complex processing pipelines while preserving type safety and error handling.
Examples
let my_transform: Transformation = fn(text) {
text |> string.uppercase |> Ok
}
pub type Transformation =
fn(String) -> Result(String, errors.SlugifyError)
Values
pub fn compose(
transformations: List(
fn(String) -> Result(String, errors.SlugifyError),
),
) -> fn(String) -> Result(String, errors.SlugifyError)
Composes multiple transformations into a single transformation.
Transformations are applied in order from left to right. If any transformation fails, the entire composition fails.
Examples
let pipeline = compose([
normalize_unicode(),
transliterate_to_ascii()
])
pipeline("café")
// -> Ok("cafe")
pub fn normalize_unicode(
,
) -> fn(String) -> Result(String, errors.SlugifyError)
Creates a transformation that normalizes Unicode text.
Currently this is a no-op transformation that passes text through unchanged. In the future, this could implement Unicode normalization forms (NFC, NFD, etc.).
Examples
let normalizer = normalize_unicode()
normalizer("text")
// -> Ok("text")
pub fn transliterate_to_ascii(
,
) -> fn(String) -> Result(String, errors.SlugifyError)
Creates a transformation that transliterates Unicode to ASCII.
This transformation converts accented characters and symbols to their ASCII equivalents. Characters that cannot be transliterated will cause an error.
Examples
let transliterator = transliterate_to_ascii()
transliterator("café")
// -> Ok("cafe")