nip54 normalizeIdentifier function

This commit is contained in:
Baris Aydek
2025-02-25 19:28:28 +03:00
committed by fiatjaf_
parent e7e8db1dbd
commit 3c4019a154
5 changed files with 68 additions and 0 deletions

19
nip54.ts Normal file
View File

@@ -0,0 +1,19 @@
export function normalizeIdentifier(name: string): string {
// Trim and lowercase
name = name.trim().toLowerCase()
// Normalize Unicode to NFKC form
name = name.normalize('NFKC')
// Convert to array of characters and map each one
return Array.from(name)
.map(char => {
// Check if character is letter or number using Unicode ranges
if (/\p{Letter}/u.test(char) || /\p{Number}/u.test(char)) {
return char
}
return '-'
})
.join('')
}