https://github.com/goloop/slug
Package slug generate slug from Unicode string.
https://github.com/goloop/slug
golang slug url-slug url-slug-t13n
Last synced: 6 months ago
JSON representation
Package slug generate slug from Unicode string.
- Host: GitHub
- URL: https://github.com/goloop/slug
- Owner: goloop
- License: mit
- Created: 2022-04-29T19:20:34.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-07T20:54:53.000Z (over 1 year ago)
- Last Synced: 2024-12-07T21:28:36.940Z (over 1 year ago)
- Topics: golang, slug, url-slug, url-slug-t13n
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/goloop/slug) [](https://github.com/goloop/slug/blob/master/LICENSE) [](https://godoc.org/github.com/goloop/slug) [](https://u24.gov.ua/)
# slug
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.
## Features
- Clean, URL-safe slug generation.
- Multi-language support through transliteration [t13n](https://github.com/goloop/t13n).
- Customizable character replacement.
- Thread-safe operations.
- High performance.
- No external dependencies for core functionality.
## Installation
```bash
go get -u github.com/goloop/slug
```
## Quick Start
To use this module import it as: `github.com/goloop/slug`
```go
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
}
```
### Conversion functions
#### Fast conversion.
Use the `Make` method to convert a string to slug.
```go
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
}
```
## API Reference
### Functions
- `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.
### Slug Methods
- `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.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.