Created
March 15, 2021 15:43
-
-
Save chaosmonster/7c4bb02864ec064c4e423139c4e36667 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple German normalize | |
function normalizeIt(str) { | |
const normalized = str.normalize('NFC') | |
.toLocaleUpperCase() | |
.trim() | |
.replace(/Ä/g, 'AE' ) | |
.replace(/Ö/g, 'OE' ) | |
.replace(/Ü/g, 'UE' ) | |
.replace(/ß/g, 'SS' ) | |
.replace(/ /g, '_' ) | |
.replace(/-/g, '_') | |
.replace(/__/g, '_' ); | |
return str === normalized ? normalized : normalizeIt(normalized); | |
} | |
console.log(normalizeIt('test')); | |
console.log(normalizeIt('test ')); | |
console.log(normalizeIt(' test ')); | |
console.log(normalizeIt(' test')); | |
console.log(normalizeIt('test foo')); | |
console.log(normalizeIt('test-foo')); | |
console.log(normalizeIt('test -foo')); | |
console.log(normalizeIt('test - foo')); | |
console.log(normalizeIt('ä')); | |
console.log(normalizeIt('Ä')); | |
console.log(normalizeIt('ö')); | |
console.log(normalizeIt('Ö')); | |
console.log(normalizeIt('ü')); | |
console.log(normalizeIt('Ü')); | |
console.log(normalizeIt('ß')); | |
console.log(normalizeIt('a sÜß ')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment