This Go package makes it easy to generate slugs from human-readable text.
package main
import (
"fmt"
slug "github.com/theTardigrade/golang-slug"
)
func main() {
defaultOptions := slug.NewOptionsWithDefaults()
result, err := slug.GetWithOptions("!=this is the text's slug=!", &slug.Options{
WholeWords: false,
MaxLen: 20,
Replacement: "_",
RunesToRemove: defaultOptions.RunesToRemove,
})
if err != nil {
panic(err)
}
// prints "this_is_the_texts_sl"
fmt.Println(result)
result, err = slug.GetRandomWithOptions(&slug.Options{
MaxLen: 20,
})
if err != nil {
panic(err)
}
// prints slug made up of twenty randomly selected
// uppercase letters, lowercase letters and digits
fmt.Println(result)
}
If you use this package, or find any value in it, please consider donating: