Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mysticatea/eaw
The Node.js module to calculate the width of east Asian characters.
https://github.com/mysticatea/eaw
east-asian-characters eastasianwidth javascript node nodejs npm npm-module npm-package text unicode web
Last synced: 7 days ago
JSON representation
The Node.js module to calculate the width of east Asian characters.
- Host: GitHub
- URL: https://github.com/mysticatea/eaw
- Owner: mysticatea
- License: mit
- Created: 2016-11-21T07:54:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-26T08:09:49.000Z (almost 8 years ago)
- Last Synced: 2024-09-17T14:20:19.276Z (2 months ago)
- Topics: east-asian-characters, eastasianwidth, javascript, node, nodejs, npm, npm-module, npm-package, text, unicode, web
- Language: JavaScript
- Size: 43 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eaw
[![npm version](https://img.shields.io/npm/v/eaw.svg)](https://www.npmjs.com/package/eaw)
[![Downloads/month](https://img.shields.io/npm/dm/eaw.svg)](http://www.npmtrends.com/eaw)
[![Build Status](https://travis-ci.org/mysticatea/eaw.svg?branch=master)](https://travis-ci.org/mysticatea/eaw)
[![Coverage Status](https://codecov.io/gh/mysticatea/eaw/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/eaw)
[![Dependency Status](https://david-dm.org/mysticatea/eaw.svg)](https://david-dm.org/mysticatea/eaw)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] that Unicode Character Database provides.
- The generator script is [./scripts/generate.js].
- The generated script is [./lib/is-narrow-character.js].The generator script is used to **maintain** this module as following to latest Unicode.
## πΏ Installation
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.## π Usage
### CLI
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 ... It splits the given text by LF to make the
width of each line shorter than the given
number.
-t, --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,
δΈη
```### Node.js
This module provides Node.js module.
```js
const eaw = require("eaw")console.log(eaw.isNarrowCharacter("A")) // β true
console.log(eaw.isNarrowCharacter("γ")) // β false
console.log(eaw.getWidth("A")) // β 1
console.log(eaw.getWidth("γ")) // β 2
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)
```> eaw.isNarrowCharacter(character: string): boolean
It checks whether the given character is a narrow character or not.
This function checks the first code point if the argument has 2 or more characters.
> eaw.getWidth(characters: string, widthOfWideCharacters?: number = 2): number
> eaw.getWidth(characters: string[], widthOfWideCharacters?: number = 2): number[]
> eaw.getWidth(characters: Iterable<string>, widthOfWideCharacters?: number = 2): Iterable<number>It returns the total width of the given characters.
> eaw.split(characters: string, maxPerLine: number, widthOfWideCharacters?: number = 2): string[]
> eaw.split(characters: string[], maxPerLine: number, widthOfWideCharacters?: number = 2): string[]
> eaw.split(characters: Iterable<string>, maxPerLine: number, widthOfWideCharacters?: number = 2): Iterable<string>It splits the given characters to make the width of each line shorter than the given number.
> eaw.createWidthStream(widthOfWideCharacters?: number = 2): [stream.Transform]
It returns the transform stream to calculate the width of each line.
> eaw.createSplitStream(maxPerLine: number, widthOfWideCharacters?: number = 2): [stream.Transform]
It returns the transform stream to split the given characters to make the width of each line shorter than the given number.
## π° Changelog
See [GitHub Releases]
## πͺ Contributing
Welcom your contributing!
Please use GitHub's issues/PRs.
### Development tools
- `npm test` runs tests.
- `npm run build` generates the script from [EastAsianWidth.txt].
- `npm run clean` removes the coverage result of the last `npm test` command.
- `npm run coverage` opens the coverage of the last `npm test` command by browsers.
- `npm run lint` runs [ESLint].
- `npm run watch` runs tests for each file change.[EastAsianWidth.txt]: http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
[./scripts/generate.js]: ./scripts/generate.js
[./lib/is-narrow-character.js]: ./lib/is-narrow-character.js
[npm]: https://www.npmjs.com/
[browserify]: http://browserify.org/
[stream.Transform]: https://nodejs.org/api/stream.html#stream_class_stream_transform
[GitHub Releases]: https://github.com/mysticatea/eaw/releases
[ESLint]: http://eslint.org/