This commit is contained in:
23
internal/utils/normalize_name.go
Normal file
23
internal/utils/normalize_name.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func NormalizeName(name string) string {
|
||||
// Remove extra whitespace
|
||||
name = strings.TrimSpace(name)
|
||||
name = regexp.MustCompile(`\s+`).ReplaceAllString(name, " ")
|
||||
|
||||
// Remove common punctuation but keep hyphens
|
||||
name = strings.Map(func(r rune) rune {
|
||||
if unicode.IsLetter(r) || unicode.IsSpace(r) || r == '-' {
|
||||
return unicode.ToLower(r)
|
||||
}
|
||||
return -1
|
||||
}, name)
|
||||
|
||||
return name
|
||||
}
|
||||
Reference in New Issue
Block a user