East Asian Width categorizes Unicode characters based on their occupied space in East Asian typography, which helps in text layout and alignment, particularly in languages like Japanese, Chinese, and Korean.
Unlike other similar packages, this package uses the latest Unicode data (which changes each year).
Install
npm install get-east-asian-width
Usage
import {eastAsianWidth, eastAsianWidthType} from 'get-east-asian-width';const codePoint = '字'.codePointAt(0);console.log(eastAsianWidth(codePoint));//=> 2console.log(eastAsianWidthType(codePoint));//=> 'wide'
Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). If the context cannot be established reliably, they should be treated as narrow characters by default.