Thank you for your reply,I know that there are ways to get the right results, 
but I still think that there should be such a method on the prototype chain of 
String, rather than by other means (mostly by converting to an array to find 
the length). I hope that members of ECMA can consider it.




Javascript itself supports such a method is definitely better than the 
developer alone.

 

There are many such requirements in a real development scenario, such as how 
many characters are allowed to be entered by the user, which is something we 
should consider not in Unicode for Basic Multilingual Plane. Unify the 
awareness of users and developers.

```

eg.

let str = '𠮷𠮷𠮷𠮷';

[...str].length; // 4

or

Array.from(str).length // 4
 
```














------------------ 原始邮件 ------------------
发件人: "Claude Pache"<claude.pa...@gmail.com>;
发送时间: 2019年8月8日(星期四) 下午4:45
收件人: "fanerge"<fane...@qq.com>;
抄送: "es-discuss"<es-discuss@mozilla.org>;
主题: Re: Proposal: `String.prototype.codePointCount`



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

Reply via email to