Proposal: `String.prototype.codePointCount`

Claude Pache claude.pache at
Thu Aug 8 08:45:35 UTC 2019

> Le 8 août 2019 à 04:37, fanerge <fanerge at> a écrit :
> I expect to be able to add an attribute to String.prototype that returns the number of codePoints of the string to reflect the actual number of characters instead of the code unit.

Note however that “the number of code points” is not the same thing as “the actual number of characters” for what a human usually perceives as “character”. For example:

Object.defineProperty(String.prototype, "codePointCount", {
    get() { return [...this].length }
"🇨🇦".codePointCount // 2
"n̈".codePointCount // 2
"é".codePointCount // 1
"é".normalize("NFD").codePointCount // 2

> I believe that most developers need such a method and property to get the number of codePoints in a string.

For what purposes do “most developers” need the number of code points?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list