Slugify v1.3.1 Slug View Source

Transform strings from any language into slugs.

It works by transliterating Unicode characters into alphanumeric strings (e.g. into zi). All punctuation is stripped and whitespace between words are replaced by hyphens.

Link to this section Summary


Returns string as a slug or nil if it failed.

Link to this section Functions

Link to this function

slugify(string, opts \\ [])

View Source (since 1.0.0)


slugify(String.t(), Keyword.t()) :: String.t() | nil

Returns string as a slug or nil if it failed.


  • :separator - Replace whitespaces with this string. Leading, trailing or repeated whitespaces are trimmed. Defaults to -.
  • :lowercase - Set to false if you wish to retain capitalization. Defaults to true.
  • :truncate - Truncates slug at this character length, shortened to the nearest word.
  • :ignore - Pass in a string (or list of strings) of characters to ignore.


iex> Slug.slugify("Hello, World!")

iex> Slug.slugify("Madam, I'm Adam", separator: "")

iex> Slug.slugify("StUdLy CaPs", lowercase: false)

iex> Slug.slugify("Call me maybe", truncate: 10)

iex> Slug.slugify("你好,世界", ignore: ["你", "好"])