Package slug generates URL-friendly slugs from Unicode strings with support for multiple languages. It provides both simple functions and a more configurable object-oriented approach.
- Clean, URL-safe slug generation.
- Multi-language support through transliteration t13n.
- Customizable character replacement.
- Thread-safe operations.
- High performance.
- No external dependencies for core functionality.
go get -u github.com/goloop/slug
To use this module import it as: github.com/goloop/slug
package main
import (
"fmt"
"github.com/goloop/slug"
)
func main() {
// Simple usage
fmt.Println(slug.Make("Hello 世界"))
// Output: Hello-Shi-Jie
// With language-specific settings
s := slug.New()
fmt.Println(s.Lang("uk").Make("Привіт Світ"))
// Output: Pryvit-Svit
}
Use the Make
method to convert a string to slug.
package main
import (
"fmt"
"github.com/goloop/slug"
)
func main() {
// Simple generate slug from the string.
s := slug.Make("Hello 世界")
h := "https://example.com/"
fmt.Printf("%s%s\n", h, s)
// Output: https://example.com/Hello-Shi-Jie
}
Make(t string) string
- Generate a slug from a string.Lower(t string) string
- Generate a lowercase slug.Upper(t string) string
- Generate an uppercase slug.New() *Slug
- Create a new Slug instance for advanced configuration.
Lang(l string) *Slug
- Set language for transliteration.Make(t string) string
- Generate a slug.Lower(t string) string
- Generate a lowercase slug.Upper(t string) string
- Generate an uppercase slug.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.