Skip to content

Commit 63a0a24

Browse files
authored
Create 使用 Intl.Segmenter 返回更准确的字符长度.js
1 parent 4068810 commit 63a0a24

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const s = new Intl.Segmenter('en')
2+
3+
['1','1️⃣','t', '@','😴', '🚗','👨‍👩‍👧‍👦'].forEach((v) => console.log([...s.segment(v)].length));
4+
5+
['1','1️⃣','t', '@','😴', '🚗','👨‍👩‍👧‍👦'].forEach((v) => console.log(v.length))

0 commit comments

Comments
 (0)