Created
November 18, 2021 22:22
-
-
Save jamiebuilds/1d44f16a9dd266cbea07de1cb4ffc910 to your computer and use it in GitHub Desktop.
This file contains 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
function capitalize(locale, string) { | |
let segmenter = new Intl.Segmenter(locale, { granularity: "grapheme" }) | |
let result = "" | |
for (let item of segmenter.segment(string)) { | |
if (item.index === 0) { | |
result += item.segment.toLocaleUpperCase(locale) | |
} else { | |
result += item.segment | |
} | |
} | |
return result | |
} | |
console.log(capitalize("en-US", "ééé")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment