View Source Aja.String (Aja v0.6.5)

Some extra helper functions for working with strings, that are not in the core String module.

Summary

Functions

Transforms the text as a slug. Removes whitespace, special characters and converts the rest to lowercase.

Types

@type mode() :: :default | :ascii | :greek

Functions

Link to this function

slugify(string, mode \\ :default)

View Source
@spec slugify(String.t(), mode()) :: String.t()

Transforms the text as a slug. Removes whitespace, special characters and converts the rest to lowercase.

This is typically useful to generate URLs based on content, e.g. the title of an article.

Like String.downcase/2, slugify/2 also can handle the following modes: :default (keeps unicode), :ascii or :greek.

Examples

iex> Aja.String.slugify("> \"It Was Me, Dio!!!\"\n")
"it-was-me-dio"
iex> Aja.String.slugify("Joseph Joestar a.k.a ジョジョ")
"joseph-joestar-aka-ジョジョ"
iex> Aja.String.slugify(<<220>>)
** (ArgumentError) Invalid string <<220>>

:ascii converts to ascii when possible or strips characters:

iex> Aja.String.slugify("OLÁ!\n", :ascii)
"ola"
iex> Aja.String.slugify("DIOの世界 -さらば友よ- ", :ascii)
"dio"

:greek handles the context sensitive sigma in Greek:

iex> Aja.String.slugify("\tΣΣ?")
"σσ"
iex> Aja.String.slugify("\tΣΣ?", :greek)
"σς"