Slug
Overview
Converts arbitrary text into a URL-safe slug — strips punctuation, lowercases, and replaces spaces with hyphens.
If you are coming from Node.js, the closest pattern is slugify(s).
Signature
go
func Slug(s string) stringCompare: Node.js · Standard Go · gox
js
slugify('Hello World');go
s := strings.ToLower(strings.ReplaceAll(strings.TrimSpace(title), " ", "-"))go
import "github.com/sahilkhaire/gox/str"
slug := str.Slug("Hello World!")Example
go
import "github.com/sahilkhaire/gox/str"
slug := str.Slug("Hello World!")Tips
Use before writing user-generated titles to URL paths.
Standard library alternative
Use the standard library directly:
go
s := strings.ToLower(strings.ReplaceAll(strings.TrimSpace(title), " ", "-"))