/mangler

A collection of utilities to validate and transform strings for Elixir

Primary LanguageElixir

Mangler

A collection of utilities to validate and transform strings with diacritics, unicode and ascii.

Substitute diacritics in the given string with their ASCII equivalents. This function works by performing NFD normalization on the graphemes in the string. It then removes any non-words from the string. Due to this, an allowlist must be provided to keep any non-word characters intact.

Also provides utility functions to validate if a string contains ASCII or Unicode characters

Installation

def deps do
  [
    {:mangler, "~> 0.2.0"}
  ]
end

Usage

Transform

iex> Mangler.Transform.substitute_diacritics("Röçkêt Îñśíghtš")
"RocketInsights"

to preserve spaces or any other specific character use the allow opt

iex> Mangler.Transform.substitute_diacritics("Röçkêt Îñśíghtš", allow: [" "])
"Rocket Insights"

Validate unicode letters

iex> Mangler.Validate.unicode_letters?("a")
true

iex> Mangler.Validate.unicode_letters?("🚀")
false

iex> Mangler.Validate.unicode_letters?("ö")
true

Validate ascii letters

iex> Mangler.Validate.ascii_printable?("a")
true

iex> Mangler.Validate.ascii_printable?("🚀")
false

iex> Mangler.Validate.ascii_printable?("ö")
false

Authors

Rocket Insights