Skip to main content

Function: countGraphemes()

countGraphemes(text): number

Defined in: web/lib/bluesky/post-service.ts:241

Count graphemes in a string (for Bluesky's 300 character limit).

Parameters

text

string

Text to count

Returns

number

Number of grapheme clusters

Remarks

Bluesky uses grapheme clusters per UAX #29, not code points or bytes. This uses the same unicode-segmenter library that Bluesky uses internally via @atproto/lex-data, ensuring exact compatibility with Bluesky's counting.

Example

countGraphemes('Hello'); // 5
countGraphemes('👨‍👩‍👧‍👧'); // 1 (family emoji is one grapheme)
countGraphemes('café'); // 4 (e with accent is one grapheme)

See