Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

meaw

susisu1.3kMIT9.1.0TypeScript support: included

Utilities for Unicode East Asian Width

unicode, east, asian, width

readme

meaw

CI

Utilities for Unicode East Asian Width (EAW).

Installation

# npm
npm i --save meaw
# yarn
yarn add meaw
# pnpm
pnpm add meaw

Usage

getEAW()

Gets the EAW property of a character.

import { getEAW } from "meaw";

// Narrow
assert(getEAW("A") === "Na");
// Wide
assert(getEAW("あ") === "W");
assert(getEAW("安") === "W");
assert(getEAW("🍣") === "W");
// Fullwidth
assert(getEAW("A") === "F");
// Halfwidth
assert(getEAW("ア") === "H");
// Ambiguous
assert(getEAW("∀") === "A");
assert(getEAW("→") === "A");
assert(getEAW("Ω") === "A");
assert(getEAW("Я") === "A");
// Neutral
assert(getEAW("ℵ") === "N");

// character position (in code unit) can be specified
assert(getEAW("ℵAあAア∀", 2) === "W");

getEAWOfCodePoint()

Similar to getEAW(), but takes a code point (number) instead of a string.

import { getEAWOfCodePoint } from "meaw";

// 0x3042 is the code point of 'あ' (U+3042)
assert(getEAWOfCodePoint(0x3042) === "W");

computeWidth()

Deprecated. To calculate the visual width of a string, it is recommended to split the string into graphemes (using Intl.Segmenter or libraries like graphemer) and then calculate the widths of them.

Computes an approximate width of a string based on the EAW properties of the characters. By default, characters with property Wide (W) or Fullwidth (F) are treated as wide (= 2) and others are as narrow (= 1).

import { computeWidth } from "meaw";

assert(computeWidth("Aあ🍣Ω") === 6);
// character width for each EAW property can be customized
assert(computeWidth("Aあ🍣Ω", { "A": 2 }) === 7);

Development

Setup

git clone https://github.com/susisu/meaw.git
cd meaw
pnpm i

Scripts

Name Description
fetch fetch the latest version of the EAW definition file
generate generate source script from the EAW definition file
format run Prettier
lint run ESLint
typecheck run tsc --noEmit
test execute tests
build build scripts

License

MIT License

Author

Susisu (GitHub, Twitter)

changelog

v9.1.0 (2025-03-23)

  • Export getEAWOfCodePoint() (#15)

v9.0.0 (2024-09-21)

  • Update to Unicode 16.0.0

v8.0.1 (2023-09-29)

  • Update build tool

v8.0.0 (2023-09-23)

Breaking changes

  • Update to Unicode 15.1.0
  • Drop support for Node.js 14 and 16
  • Deprecate computeWidth()
    • To calculate the visual width of a string, it is more accurate and recommended to split the string into graphemes (using libraries like graphemer) and calculate the width for those graphemes.

v7.0.0 (2022-09-17)

Breaking changes

  • Update to Unicode 15.0.0

v6.0.0 (2021-09-18)

Breaking changes

  • Update to Unicode 14.0.0

v5.0.0 (2020-10-17)

Breaking changes

  • Update EAW version to Unicode 13.0.0
  • Change return type of getEAW() from EastAsianWidth to EastAsianWidth | undefined

Features

  • Rewrite in TypeScript
  • Reduce script size

v4.3.0 (2019-05-08)

  • Update Unicode EAW to 12.1.0

v4.2.0 (2019-04-28)

  • Add eawVersion, which is the version of the East Asian Width data file
  • Improve .d.ts

v4.1.0 (2019-03-07)

  • Provide type definitions for TypeScript

v4.0.0 (2019-03-07)

  • Upgrade Unicode East Asian Width to 12.0.0

v3.0.0 (2018-08-26)

  • Upgrade Unicode East Asian Width to 11.0.0

v2.0.0 (2017-11-10)

  • Upgrade Unicode East Asian Width to 10.0.0

v1.0.0 (2017-04-20)

  • First release