> Le 8 août 2019 à 04:37, fanerge <fane...@qq.com> 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: ```js 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? —Claude
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss