Skip to content

Commit

Permalink
slug string handle more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed May 14, 2024
1 parent a765f61 commit 30f500a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions slug_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"golang.org/x/text/unicode/norm"
)

// SlugString converts names into url or ID friendly human readable names, aiming for alphanumeric and dashes.
// Replaces _ with -, which may be undesired depending on your use case.
func SlugString(term string) string {
lowerCase := cases.Lower(language.English, cases.NoLower)
lowerTerm := lowerCase.String(term)
Expand All @@ -20,5 +22,8 @@ func SlugString(term string) string {
cleaned = strings.ReplaceAll(cleaned, " ", "-")
cleaned = strings.ReplaceAll(cleaned, "_", "-")

cleaned = strings.ReplaceAll(cleaned, "/", "-")
cleaned = strings.ReplaceAll(cleaned, ".", "-")

return cleaned
}

0 comments on commit 30f500a

Please sign in to comment.