Skip to content

@jsvision/core / charWidth

Function: charWidth()

charWidth(codepoint, widthMode): 0 | 1 | 2

Defined in: render/width.ts:161

Display width of a Unicode code point.

Parameters

codepoint

number

The code point (e.g. from String.prototype.codePointAt).

widthMode

WidthMode

From the terminal's unicode.widthMode; 'ambiguous-wide' widens East-Asian Ambiguous characters to 2.

Returns

0 | 1 | 2

0 (C0/C1 control, combining, or zero-width), 2 (East-Asian Wide / Fullwidth / wide emoji, or Ambiguous under 'ambiguous-wide'), else 1.

Example

ts
import { charWidth } from '@jsvision/core';

charWidth('A'.codePointAt(0)!, 'wcwidth'); // 1 — normal Latin letter
charWidth('漢'.codePointAt(0)!, 'wcwidth'); // 2 — wide CJK ideograph
charWidth(0x0301, 'wcwidth');               // 0 — combining acute accent