diff --git a/README.md b/README.md index a846be3..a7d895f 100644 --- a/README.md +++ b/README.md @@ -4,28 +4,21 @@ Textwrap for JavaScript/Node.js. Correctly handles wide characters (宽字符) and emojis (😃). Optionally break words when wrapping strings. Preserves ANSI escape codes. -## Why? +## Packages in this repo -JavaScript's `String.length` counts code units, not visual terminal width. -Wide characters (CJK) and many emoji occupy 2 columns but have length 1. -This package wraps text to a target **visual** width using `wcwidth`. +| Install | Package | What you get | +|---------|---------|----------------| +| `npm install smartwrap` | **smartwrap** (this package) | Core library only — **no CLI, no `yargs`** | +| `npm install -g smartwrap-cli` | [smartwrap-cli](./packages/smartwrap-cli) | `smartwrap` binary | -## Installation +Library users who only need wrapping no longer pull in CLI dependencies ([#19](https://github.com/tecfu/smartwrap/issues/19)). -```bash -npm install smartwrap -``` - -CLI (global): +## Installation (library) ```bash -npm install -g smartwrap +npm install smartwrap ``` -## Node module - -### Wide character wrapping - ```js const smartwrap = require('smartwrap') console.log(smartwrap('宽字符', { width: 2 })) @@ -34,24 +27,14 @@ console.log(smartwrap('宽字符', { width: 2 })) // 符 ``` -### Word wrapping (default) - ```js -console.log(smartwrap('break at word', { - width: 10, - breakword: false // default -})) +console.log(smartwrap('break at word', { width: 10 })) // break at // word ``` -### Force-break long words - ```js -console.log(smartwrap('break at word', { - width: 10, - breakword: true -})) +console.log(smartwrap('break at word', { width: 10, breakword: true })) // break at w // ord ``` @@ -72,41 +55,35 @@ console.log(smartwrap('break at word', { ## CLI ```bash +npm install -g smartwrap-cli echo "somestring you want to wrap" | smartwrap --width=3 --paddingLeft=1 +smartwrap --help ``` -``` - so - me - st - ri - ng - yo - u - wa - nt - to - wr - ap -``` - -Run `smartwrap --help` for all flags. - ## Breaking changes in 3.0.0 - **Node.js ≥ 12** required (native `Array.prototype.flat`). -- Removed unused `grapheme-splitter` and the `array.prototype.flat` polyfill (eliminates ~50 transitive dependencies). -- Updated `yargs` and other dependencies. -- CLI now correctly passes `breakword` and `errorChar`. -- Test runner switched from Grunt to plain Mocha. -- Minor code cleanups (fixed undeclared variable, modernized style). +- **CLI moved** to the separate package `smartwrap-cli`. + `npm install smartwrap` no longer installs `yargs` or the `smartwrap` binary. +- Removed unused `grapheme-splitter` and the `array.prototype.flat` polyfill. +- CLI options (`breakword`, `errorChar`, etc.) are forwarded correctly in `smartwrap-cli`. +- Test runner switched from Grunt to Mocha. -Existing wrapping behavior for supported inputs is intentionally preserved. +## Development -## Compatibility +```bash +npm install +npm test +``` + +To exercise the CLI locally against this checkout: -- Node.js ≥ 12 -- CommonJS +```bash +cd packages/smartwrap-cli +npm install +npm link ../.. # or: npm install file:../.. +# then: echo "宽字符" | node src/terminal-adapter.js -w 2 +``` ## License diff --git a/package.json b/package.json index 3916675..f0c16bd 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,10 @@ "engines": { "node": ">=12" }, - "bin": { - "smartwrap": "src/terminal-adapter.js" - }, "scripts": { "test": "mocha test/test.js", "test-display": "mocha test/test.js --require test/display-hook.js", - "lint": "eslint src/", - "lint-fix": "eslint src/ --fix" + "lint": "eslint src/ packages/smartwrap-cli/src/" }, "repository": { "type": "git", @@ -32,8 +28,7 @@ "dependencies": { "breakword": "^1.0.5", "strip-ansi": "^6.0.1", - "wcwidth": "^1.0.1", - "yargs": "^17.7.2" + "wcwidth": "^1.0.1" }, "devDependencies": { "chai": "^4.3.10", diff --git a/packages/smartwrap-cli/LICENSE b/packages/smartwrap-cli/LICENSE new file mode 100644 index 0000000..d13cc4b --- /dev/null +++ b/packages/smartwrap-cli/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/smartwrap-cli/README.md b/packages/smartwrap-cli/README.md new file mode 100644 index 0000000..921e691 --- /dev/null +++ b/packages/smartwrap-cli/README.md @@ -0,0 +1,22 @@ +# smartwrap-cli + +Command-line interface for [smartwrap](https://www.npmjs.com/package/smartwrap). + +## Install + +```bash +npm install -g smartwrap-cli +``` + +For library-only use (no CLI, no `yargs`), install [`smartwrap`](https://www.npmjs.com/package/smartwrap) instead. + +## Usage + +```bash +echo "somestring you want to wrap" | smartwrap --width=3 --paddingLeft=1 +smartwrap --help +``` + +## License + +MIT diff --git a/packages/smartwrap-cli/package.json b/packages/smartwrap-cli/package.json new file mode 100644 index 0000000..b230670 --- /dev/null +++ b/packages/smartwrap-cli/package.json @@ -0,0 +1,33 @@ +{ + "name": "smartwrap-cli", + "version": "3.0.0", + "description": "CLI for smartwrap — text wrapping with wide-character and emoji support", + "bin": { + "smartwrap": "src/terminal-adapter.js" + }, + "engines": { + "node": ">=12" + }, + "repository": { + "type": "git", + "url": "https://github.com/tecfu/smartwrap.git", + "directory": "packages/smartwrap-cli" + }, + "keywords": [ + "smartwrap", + "wordwrap", + "cli", + "terminal" + ], + "author": "tecfu", + "license": "MIT", + "dependencies": { + "smartwrap": "^3.0.0", + "yargs": "^17.7.2" + }, + "files": [ + "src/", + "LICENSE", + "README.md" + ] +} diff --git a/src/terminal-adapter.js b/packages/smartwrap-cli/src/terminal-adapter.js similarity index 97% rename from src/terminal-adapter.js rename to packages/smartwrap-cli/src/terminal-adapter.js index 2c6520d..17f3594 100755 --- a/src/terminal-adapter.js +++ b/packages/smartwrap-cli/src/terminal-adapter.js @@ -1,7 +1,7 @@ #!/usr/bin/env node 'use strict' -const smartwrap = require('./main.js') +const smartwrap = require('smartwrap') const yargs = require('yargs') yargs diff --git a/test/test.js b/test/test.js index 4e3c13b..93b220d 100644 --- a/test/test.js +++ b/test/test.js @@ -7,7 +7,7 @@ const chai = require('chai'); const expect = chai.expect; const assert = chai.assert; const should = chai.should(); -const smartwrap = require("../"); +const smartwrap = require(".."); const data = require("./data") let test = function(testResult,savedResult){