Count Unicode characters more accurately

This treats emoji like 🦊 as one instead of two characters. Still not perfect, but hopefully close enough.

https://dev.to/coolgoose/quick-and-easy-way-of-counting-utf-8-characters-in-javascript-23ce
This commit is contained in:
Kianga 2023-01-16 21:45:33 +01:00
parent 184e579d78
commit 00993cff25
Signed by: kianga
SSH Key Fingerprint: SHA256:FsfHSVtt4BSm5AV+MG3KYJplFo8Q8+TWvSeud7Um4Oo
1 changed files with 1 additions and 1 deletions

View File

@ -17,7 +17,7 @@ function update(statusBar, textArea) {
qualifier = "in selection";
}
let charCount = text.trim().length;
let charCount = [...text.trim()].length;
let wordCount = countWords(text);
statusBar.innerText = `${charCount} characters ${wordCount} words ${qualifier}`;