Documentation
¶
Overview ¶
Package slugify implements Make Pretty Slug
slugifier := (&slugify.Slugifier{}).ToLower(false).InvalidChar("-").WordSeparator("-") s := "北京kožušček,abc" fmt.Println(slugifier.Slugify(s)) // Output: bei-jing-kozuscek-abc
Index ¶
- func Version() string
- type Slugifier
- func (s *Slugifier) AllowedSet(allowedSet string) *Slugifier
- func (s *Slugifier) InvalidChar(invalidCharReplacement string) *Slugifier
- func (s *Slugifier) Slugify(txt string) string
- func (s *Slugifier) ToLower(toLower bool) *Slugifier
- func (s *Slugifier) WordSeparator(wordSeparator string) *Slugifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Slugifier ¶
type Slugifier struct {
// contains filtered or unexported fields
}
func NewSlugifier ¶
func NewSlugifier() Slugifier
NewSlugifier creates a new slugifier. Defaults to lowercasing and using a dash ("-") as the word separator and as the invalid character replacement.
func (*Slugifier) AllowedSet ¶
AllowedSet sets the allowed set of characters. Defaults to "a-zA-Z0-9". The allowed set is used to replace characters that are not in the allowed set with the invalid character replacement. It must be a valid regex set (typically in [] brackets), any characters that need escaping must be properly escaped. The word separator is automatically added to the allowed set.
func (*Slugifier) InvalidChar ¶
InvalidChar sets the character to use to replace invalid characters (anything not a-z, A-Z, 0-9, the word separator, or the InvalidChar). Defaults to a dash ("-"). Leading and trailing InvalidCharReplacements are trimmed. Multiple successive InvalidCharReplacements are NOT replaced with a single InvalidChar. Returns the slugifier for easy chaining.
func (*Slugifier) Slugify ¶
Slugify implements making a pretty slug from the given text. e.g. Slugify("kožušček hello world") => "kozuscek-hello-world"
func (*Slugifier) ToLower ¶
ToLower sets the flag indicating if the slugified result should be lowercased. Returns the slugifier for easy chaining.
func (*Slugifier) WordSeparator ¶
WordSeparator sets the word separator character to use. Defaults to a dash ("-"). The word separator is used to replace whitespace. Leading and trailing word separators are trimmed. Multiple successive word separators are replaced with a single word separator. Returns the slugifier for easy chaining.