一肌脱ぐか。

Twitter時代の文字の数え方 | 配電盤
正確には、「Unicode 3.1時代の文字の数え方」なのでしょうが、Unicodeの最新バージョンが6.0の今、それではぱっとしないので

SYNOPSIS

log('𠮷野家'.length                        );  /* 4 // unfortunately */
log('𠮷野家'.codePointsOf()                );  /* 3 // naturally */
log('𠮷野家'.codepoints                    );  /* 3 // naturally */
log(String.fromCodePoint(0x20BB7)         );  /* '𠮷' */
log('𠮷野家'.codePointAt(0).toString(16)   );  /* 0x20BB7 */
log('𠮷野家'.uCharAt(0)                    );  /* '𠮷' */
log('𠮷野家'.toArrayOfUChars()             );  /* ['𠮷','野','家'] */
log('𠮷野家'.replace(RegExp.RE_UCHARS, '!'));  /* '!!!' */

古いブラウザーでも動くはず。String.prototype.codepointsのみ、getterなのでES5が必要ですが、ES5非互換の環境では代わりに String.prototype.codePointsOf()が使えます。

Demo

3 codepoints

Source:


ところで String.fromCodePointString.prototype.codePointAt ってES6 Proposalからは消えちゃったのでしょうか? ECMAScript compatibility tableの方にはまだあるのですが…

Enjoy!

Dan the JavaScript Shimmer