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:
parent
184e579d78
commit
00993cff25
|
@ -17,7 +17,7 @@ function update(statusBar, textArea) {
|
||||||
qualifier = "in selection";
|
qualifier = "in selection";
|
||||||
}
|
}
|
||||||
|
|
||||||
let charCount = text.trim().length;
|
let charCount = [...text.trim()].length;
|
||||||
let wordCount = countWords(text);
|
let wordCount = countWords(text);
|
||||||
statusBar.innerText = `${charCount} characters ${wordCount} words ${qualifier}`;
|
statusBar.innerText = `${charCount} characters ${wordCount} words ${qualifier}`;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue