Options
#struct OptionsEverything that decides how a slug is made. Start from DefaultOptions or a preset and change single fields.
| Name | Type | Description |
|---|---|---|
separator | str = "-" | Text put between words, a hyphen by default. May be longer than one character or empty. |
lowercase | bool = true | Fold letters to lowercase. On by default. |
max_length | int = 0 | Largest length in characters, cut between words. 0 means no limit. |
lang | str = "" | Language code that picks between conventions (de, da, no, uk, bg, sr, fa, ar, ru and so on). Empty means detect it from the script. Region suffixes such as pt-BR are ignored. |
keep_unicode | bool = false | Keep the letters of every script instead of transliterating them. |
keep_han | bool = true | Keep Han characters, which have no table. On by default; when off they are dropped. |
stop_words | Vector<str> | Words left out of the slug. Use AddStopWords to fill it. |
replacements | Vector<str> | Pairs of pattern and value applied to the title first. Use AddReplacement to fill it. |
trim | bool = true | Remove separators, and allowed punctuation, from both ends. On by default. |
collapse | bool = true | Merge a run of separators into one. On by default; when off every character that is not kept gives its own separator. |
allow | str = "" | ASCII punctuation that stays in the slug, such as ._~ . A separator is not put next to an allowed character. |
symbols | bool = true | Spell & @ % + $ and currency signs as words. On by default; when off they are only separators. |
identifier | bool = false | Make the result usable as a name in code: when it starts with a digit an underscore is put in front. |
fallback | str = "" | Returned when the slug would be empty. |
import encoding.slug
func main:
mut opts := slug.Options {}
opts = slug.DefaultOptions()
opts.separator = "_"
opts.max_length = 20
opts.lang = "de"
slug.AddStopWords(opts, "the of")
slug.AddReplacement(opts, "&", " und ")
println slug.MakeWith("The Best of Müller & Söhne in Köln", opts)
slug.FreeOptions(opts)
println slug.MakeWith("Report (final).pdf", slug.Filename())
println slug.MakeWith("9 lives", slug.Identifier())
println slug.MakeWith("Привет мир", slug.Unicode())
println slug.MakeWith("a b c", slug.URL())
endbest_mueller_und Report_final.pdf _9_lives привет-мир a-b-c