Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thetardigrade/golang-slug

Go package that generates slugs from text
https://github.com/thetardigrade/golang-slug

characters go golang headlines page-title slug titles titling url url-slug

Last synced: 7 days ago
JSON representation

Go package that generates slugs from text

Awesome Lists containing this project

README

        

# golang-slug

This Go package makes it easy to generate [slugs](https://en.wikipedia.org/wiki/Clean_URL#Slug) from human-readable text.

[![Go Reference](https://pkg.go.dev/badge/github.com/theTardigrade/golang-slug.svg)](https://pkg.go.dev/github.com/theTardigrade/golang-slug) [![Go Report Card](https://goreportcard.com/badge/github.com/theTardigrade/golang-slug)](https://goreportcard.com/report/github.com/theTardigrade/golang-slug)

## Example

```golang
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)
}
```

## Support

If you use this package, or find any value in it, please consider donating:

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S2EIRL0)