Add StringTitle

This commit is contained in:
George Suntres
2026-03-30 18:29:58 -04:00
parent 65eec3c3b1
commit d829099a45
9 changed files with 73 additions and 0 deletions

View File

@@ -3,10 +3,19 @@ package commons
import (
"regexp"
"strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
var caserTitle cases.Caser = cases.Title(language.English)
var whitespace = regexp.MustCompile(`\s+`)
func StringTitle(s string) string {
return caserTitle.String(s)
}
// StringNormalize will replace arbitrary lengths of consecutive white space with a single one.
func StringNormalize(s string) string {
s = whitespace.ReplaceAllString(s, " ")