Javascript Snippets
String / Unicode Normalization
When doing a string comparison, if you are comparing Unicode characters, you may get incorrect results because of the fact that Unicode can be defined in UTF-8 or UTF-16.
To safely do this, you need to normalize the strings. Luckily, there is a JavaScript function on the string prototype for this.
const str = '\u0065\u0301'
console.log(str == '\u00e9') // => false
const normalized = str.normalize('NFC')
console.log(normalized == '\u00e9') // => true
console.log(normalized.length) // => 1