Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/thetardigrade/golang-slug
- Owner: theTardigrade
- License: gpl-3.0
- Created: 2019-07-16T19:20:22.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-02-16T09:49:32.000Z (over 1 year ago)
- Last Synced: 2024-06-21T14:40:29.773Z (5 months ago)
- Topics: characters, go, golang, headlines, page-title, slug, titles, titling, url, url-slug
- Language: Go
- Homepage:
- Size: 43.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
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 mainimport (
"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)