The Node.js module to calculate the width of east Asian characters. (based on Unicode 9.0.0)
The script of this module is generated with EastAsianWidth.txt Unicode Character Database provides. The generator script is ./scripts/generate.js.
This module can be installed by npm.
$ npm install --save eaw
- It requires Node.js
>=4.0.0. - It can be used in browsers by browserify-like tools.
This module provides a CLI command: eaw
The command calculates the width of east Asian characters for each line.
Usage: eaw [OPTIONS]
It calculates the width of given east Asian characters.
It reads the characters from stdin or `--text` option.
OPTIONS:
-s, --split <NUMBER> ... It splits the given text by LF to make the
width of each line shorter than the given
number.
-t, --text <TEXT> ...... The characters that eaw processes instead of
stdin.
Example:
$ eaw --text "hello, 世界"
11
$ cat hello.txt | eaw
11
$ cat hello.txt | eaw --split 4
hell
o,
世界
This module provides Node.js module.
const eaw = require("eaw")
console.log(eaw.getWidth("hello, 世界")) // → 11
console.log(eaw.getWidth(["hello, 世界", "🌟❤"])) // → [11, 4]
console.log(eaw.split("hello, 世界", 4)) // → ["hell", "o, ", "世界"]
console.log(eaw.split(["hello, 世界", "🌟❤👍"], 4)) // → ["hell", "o, ", "世界", "🌟❤", "👍"]
process.stdin
.pipe(eaw.createWidthStream())
.pipe(process.stdout)
process.stdin
.pipe(eaw.createSplitStream(4))
.pipe(process.stdout)It returns the total width of the given characters.
It returns the total width of each given characters.
It splits the given characters to make the width of each line shorter than the given number.
It splits the given characters to make the width of each line shorter than the given number.
eaw.createWidthStream(): stream.Transform
It returns the transform stream to calculate the width of each line.
eaw.createSplitStream(maxPerLine: number): stream.Transform
It returns the transform stream to split the given characters to make the width of each line shorter than the given number.
See GitHub Releases
Welcom your contributing!
Please use GitHub's issues/PRs.
npm testruns tests.npm run buildgenerates the script from EastAsianWidth.txt.npm run cleanremoves the coverage result of the lastnpm testcommand.npm run coverageopens the coverage of the lastnpm testcommand by browsers.npm run lintruns ESLint.npm run watchruns tests for each file change.