SimpleSlug v0.1.0 SimpleSlug View Source
A passive slugging module — simple, transliteration-free slugs.
Given Elixir handles UTF-8 without issue, and browsers handle UtF-8 without issue both in content and in URIs, why should you fight your users’ preferred input?
Transliteration is ridiculously difficult and expensive. The best we have are brute force libraries:
- http://cldr.unicode.org/index/cldr-spec/transliteration-guidelines
- http://userguide.icu-project.org/transforms/general
Here’s an example: what would a typical transliteration of 消防署 be? Chances are it would be transformed to xiāofángshǔ. That’s fine if you intended it to be Chinese, but totally incorrect if it was supposed to be Japanese (shōbōsho). Do all German speakers want ß to be cast to s or ss?
The gist of all of this is: take the path of least resistance and don’t try to force everything to conform to ASCII.
Link to this section Summary
Functions
Creates a slugified version of a string
Link to this section Functions
Creates a slugified version of a string.
Parameters
value
: The string that you want to use to create a slug.opts
: See Options section.
Options
joiner
: The value that will join the separated parts of the value. Default is"-"
.lowercase?
: Should the slug be cast to all lowercase? Default istrue
.truncate
: The maximum length of the slug. The value is not a guarantee of the length of the resulting slug — for example, if you specify truncating at the 6th character, but that character is thejoiner
, that value is removed — if it would otherwise returnhello-
it will returnhello
. Default isfalse
; use an integer to apply.
Examples
iex> SimpleSlug.slugify(“Hello World”) “hello-world”
iex> SimpleSlug.slugify(“Hello World”, joiner: “_”) “hello_world”
iex> SimpleSlug.slugify(“Hello World”, lowercase?: false) “Hello-World”
iex> SimpleSlug.slugify(“Hello World”, truncate: 5) “hello”
iex> SimpleSlug.slugify(“Hello World”, truncate: 6) “hello”
iex> SimpleSlug.slugify(“Straßen von Berlin”) “straßen-von-berlin”
iex> SimpleSlug.slugify(“東京キャブ乗り場2018年1月”) “東京キャブ乗り場2018年1月”