Utilities for Unicode East Asian Width
npm install meaw
Utilities for Unicode East Asian Width (EAW).
`` shell`npm
npm i --save meawyarn
yarn add meawpnpm
pnpm add meaw
Gets the EAW property of a character.
` javascript
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");
`
Similar to getEAW(), but takes a code point (number) instead of a string.
`javascript
import { getEAWOfCodePoint } from "meaw";
// 0x3042 is the code point of 'あ' (U+3042)
assert(getEAWOfCodePoint(0x3042) === "W");
`
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).
` javascript
import { computeWidth } from "meaw";
assert(computeWidth("Aあ🍣Ω") === 6);
// character width for each EAW property can be customized
assert(computeWidth("Aあ🍣Ω", { "A": 2 }) === 7);
`
` shell`
git clone https://github.com/susisu/meaw.git
cd meaw
pnpm i
| 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 |
|