nip54: normalize identifier.

This commit is contained in:
fiatjaf
2024-03-13 12:53:33 -03:00
parent 7284ebcf13
commit cff9af9aca

17
nip54/nip54.go Normal file
View File

@@ -0,0 +1,17 @@
package nip54
import (
"regexp"
"strings"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
var nonLetter = regexp.MustCompile(`\W`)
func NormalizeIdentifier(name string) string {
res, _, _ := transform.Bytes(norm.NFKC, []byte(name))
str := nonLetter.ReplaceAllString(string(res), "-")
return strings.ToLower(str)
}