Utility for Unicode East Asian Width 🐈
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts
src
.babelrc
.esdoc.json
.eslintrc.json
.gitignore
CHANGELOG.md
LICENSE
README.md
package.json
rollup.config.js
yarn.lock

README.md

meaw

Utilities for Unicode East Asian Width (EAW).

Installation

npm i meaw
# or
yarn add meaw

Usage

More detailed documentation is available here.

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("") === "F");
// Halfwidth
assert(getEAW("") === "H");
// Ambiguous
assert(getEAW("") === "A");
assert(getEAW("") === "A");
assert(getEAW("Ω") === "A");
assert(getEAW("Я") === "A");
// Neutral
assert(getEAW("") === "N");

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

computeWidth()

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

import { computeWidth } from "meaw";

assert(computeWidth("Aあ🍣Ω") === 6);
// custom widths can be specified by an object
assert(computeWidth("Aあ🍣Ω", { "A": 2 }) === 7);

Development

Setup

git clone https://github.com/susisu/meaw.git
cd meaw
npm install

Scripts

Name Description
fetch fetch the latest version of the EAW definition file
generate generate source script from the EAW definition file
lint run lint tool
test run tests
cover compute test coverage
build build script
doc build documentation
clean remove built script and documentation
prepare prepare for publishing (executed automatically before publishing)

License

MIT License

Author

Susisu (GitHub, Twitter)