RadLikeWhoa / Countable

Add live paragraph-, word- and character-counting to an HTML element.
https://sacha.me/Countable
MIT License
1.64k stars 134 forks source link

Count symbols/code points more accurately #9

Closed mathiasbynens closed 11 years ago

mathiasbynens commented 11 years ago

See http://pastebin.com/raw.php?i=bZ7dbreC for some example characters that get miscounted. (GitHub won’t let me post them here.)

Perhaps this can help: http://mathiasbynens.be/notes/javascript-encoding It explains the problem in more detail and also offers a solution. You could use Punycode.js to make it really easy.

RadLikeWhoa commented 11 years ago

Thanks for the suggestion, but I'd rather keep Countable as lightweight as possible. I see the problem and your explanation cleared up a lot, but to me the issue seems not that bad, actually. I checked with some other tools (e.g. Google Docs) and most counted symbols as two characters as well.

mathiasbynens commented 11 years ago

I checked with some other tools (e.g. Google Docs) and most counted symbols as two characters as well.

Just because other software exhibits the same bug doesn’t mean that it’s not an issue.

Thanks for the suggestion, but I'd rather keep Countable as lightweight as possible.

This is not an argument either. Fixing it (even without a third-party library) would just take a few lines of code.


From the README:

Countable is a JavaScript function to add live paragraph-, word- and character-counting to an HTML element.

It just seems weird to me that a single-purpose JavaScript library fails at the only task it’s supposed to perform — especially when it can so easily be fixed.

mathiasbynens commented 11 years ago

Awesome!