Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jamiebuilds
Created November 18, 2021 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiebuilds/1d44f16a9dd266cbea07de1cb4ffc910 to your computer and use it in GitHub Desktop.
Save jamiebuilds/1d44f16a9dd266cbea07de1cb4ffc910 to your computer and use it in GitHub Desktop.
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