npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eaw

v0.1.5

Published

The Node.js module to calculate the width of east Asian characters.

Downloads

218

Readme

eaw

npm version Downloads/month Build Status Coverage Status Dependency Status

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 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 <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,
    世界

Node.js

This module provides Node.js module.

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.