unicode-programming/count-characters/javascript.md at master · patch/unicode-programming

Skip to content

Navigation Menu

Sign in

Appearance settings

Latest commit

File metadata and controls

17 lines (11 loc) · 422 Bytes

Count characters of a string in JavaScript

Code points

The Punycode.js library can be used to count code points.

var puny = require('punycode');

count = puny.ucs2.decode(str).length;

Grapheme clusters

The core language does not provide a way to count grapheme clusters. If you know of a library with this functionality, please contribute it here.