{"id":19504029,"url":"https://github.com/mysticatea/eaw","last_synced_at":"2025-04-26T00:33:25.622Z","repository":{"id":57218989,"uuid":"74339482","full_name":"mysticatea/eaw","owner":"mysticatea","description":"The Node.js module to calculate the width of east Asian characters.","archived":false,"fork":false,"pushed_at":"2016-11-26T08:09:49.000Z","size":44,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T03:18:12.053Z","etag":null,"topics":["east-asian-characters","eastasianwidth","javascript","node","nodejs","npm","npm-module","npm-package","text","unicode","web"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mysticatea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-21T07:54:22.000Z","updated_at":"2018-09-25T02:30:57.000Z","dependencies_parsed_at":"2022-08-29T02:11:48.785Z","dependency_job_id":null,"html_url":"https://github.com/mysticatea/eaw","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feaw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feaw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feaw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feaw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mysticatea","download_url":"https://codeload.github.com/mysticatea/eaw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250917284,"owners_count":21507561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["east-asian-characters","eastasianwidth","javascript","node","nodejs","npm","npm-module","npm-package","text","unicode","web"],"created_at":"2024-11-10T22:24:01.554Z","updated_at":"2025-04-26T00:33:25.368Z","avatar_url":"https://github.com/mysticatea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eaw\n\n[![npm version](https://img.shields.io/npm/v/eaw.svg)](https://www.npmjs.com/package/eaw)\n[![Downloads/month](https://img.shields.io/npm/dm/eaw.svg)](http://www.npmtrends.com/eaw)\n[![Build Status](https://travis-ci.org/mysticatea/eaw.svg?branch=master)](https://travis-ci.org/mysticatea/eaw)\n[![Coverage Status](https://codecov.io/gh/mysticatea/eaw/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/eaw)\n[![Dependency Status](https://david-dm.org/mysticatea/eaw.svg)](https://david-dm.org/mysticatea/eaw)\n\nThe Node.js module to calculate the width of east Asian characters. (based on Unicode 9.0.0)\n\nThe script of this module is generated with [EastAsianWidth.txt] that Unicode Character Database provides.\n\n- The generator script is [./scripts/generate.js].\n- The generated script is [./lib/is-narrow-character.js].\n\nThe generator script is used to **maintain** this module as following to latest Unicode.\n\n## 💿 Installation\n\nThis module can be installed by [npm].\n\n    $ npm install --save eaw\n\n- It requires Node.js `\u003e=4.0.0`.\n- It can be used in browsers by [browserify]-like tools.\n\n## 📖 Usage\n\n### CLI\n\nThis module provides a CLI command: `eaw`\n\nThe command calculates the width of east Asian characters for each line.\n\n```\nUsage: eaw [OPTIONS]\n\n    It calculates the width of given east Asian characters.\n    It reads the characters from stdin or `--text` option.\n\n    OPTIONS:\n        -s, --split \u003cNUMBER\u003e ... It splits the given text by LF to make the\n                                 width of each line shorter than the given\n                                 number.\n        -t, --text \u003cTEXT\u003e ...... The characters that eaw processes instead of\n                                 stdin.\n\nExample:\n    $ eaw --text \"hello, 世界\"\n    11\n    $ cat hello.txt | eaw\n    11\n    $ cat hello.txt | eaw --split 4\n    hell\n    o,\n    世界\n```\n\n### Node.js\n\nThis module provides Node.js module.\n\n```js\nconst eaw = require(\"eaw\")\n\nconsole.log(eaw.isNarrowCharacter(\"A\"))              // → true\nconsole.log(eaw.isNarrowCharacter(\"あ\"))             // → false\nconsole.log(eaw.getWidth(\"A\"))                       // → 1\nconsole.log(eaw.getWidth(\"あ\"))                      // → 2\nconsole.log(eaw.getWidth(\"hello, 世界\"))             // → 11\nconsole.log(eaw.getWidth([\"hello, 世界\", \"🌟❤\"]))   // → [11, 4]\nconsole.log(eaw.split(\"hello, 世界\", 4))             // → [\"hell\", \"o, \", \"世界\"]\nconsole.log(eaw.split([\"hello, 世界\", \"🌟❤👍\"], 4)) // → [\"hell\", \"o, \", \"世界\", \"🌟❤\", \"👍\"]\n\nprocess.stdin\n    .pipe(eaw.createWidthStream())\n    .pipe(process.stdout)\n\nprocess.stdin\n    .pipe(eaw.createSplitStream(4))\n    .pipe(process.stdout)\n```\n\n\u003e eaw.isNarrowCharacter(character: string): boolean\n\nIt checks whether the given character is a narrow character or not.\n\nThis function checks the first code point if the argument has 2 or more characters.\n\n\u003e eaw.getWidth(characters: string, widthOfWideCharacters?: number = 2): number\u003cbr\u003e\n\u003e eaw.getWidth(characters: string[], widthOfWideCharacters?: number = 2): number[]\u003cbr\u003e\n\u003e eaw.getWidth(characters: Iterable\u0026lt;string\u003e, widthOfWideCharacters?: number = 2): Iterable\u0026lt;number\u003e\n\nIt returns the total width of the given characters.\n\n\u003e eaw.split(characters: string, maxPerLine: number, widthOfWideCharacters?: number = 2): string[]\u003cbr\u003e\n\u003e eaw.split(characters: string[], maxPerLine: number, widthOfWideCharacters?: number = 2): string[]\u003cbr\u003e\n\u003e eaw.split(characters: Iterable\u0026lt;string\u003e, maxPerLine: number, widthOfWideCharacters?: number = 2): Iterable\u0026lt;string\u003e\n\nIt splits the given characters to make the width of each line shorter than the given number.\n\n\u003e eaw.createWidthStream(widthOfWideCharacters?: number = 2): [stream.Transform]\n\nIt returns the transform stream to calculate the width of each line.\n\n\u003e eaw.createSplitStream(maxPerLine: number, widthOfWideCharacters?: number = 2): [stream.Transform]\n\nIt returns the transform stream to split the given characters to make the width of each line shorter than the given number.\n\n## 📰 Changelog\n\nSee [GitHub Releases]\n\n## 💪 Contributing\n\nWelcom your contributing!\n\nPlease use GitHub's issues/PRs.\n\n### Development tools\n\n- `npm test` runs tests.\n- `npm run build` generates the script from [EastAsianWidth.txt].\n- `npm run clean` removes the coverage result of the last `npm test` command.\n- `npm run coverage` opens the coverage of the last `npm test` command by browsers.\n- `npm run lint` runs [ESLint].\n- `npm run watch` runs tests for each file change.\n\n[EastAsianWidth.txt]: http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt\n[./scripts/generate.js]: ./scripts/generate.js\n[./lib/is-narrow-character.js]: ./lib/is-narrow-character.js\n[npm]: https://www.npmjs.com/\n[browserify]: http://browserify.org/\n[stream.Transform]: https://nodejs.org/api/stream.html#stream_class_stream_transform\n[GitHub Releases]: https://github.com/mysticatea/eaw/releases\n[ESLint]: http://eslint.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysticatea%2Feaw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmysticatea%2Feaw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysticatea%2Feaw/lists"}