# smartwrap

> Textwrap for javascript/nodejs. Correctly handles wide characters (宽字符) and emojis (😃). Wraps strings with option to break on words.

Latest version **2.0.2** (published 2021-05-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install smartwrap
pnpm add smartwrap
yarn add smartwrap
bun add smartwrap
```

Provides the command `smartwrap`.

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2021-05-15 |
| First published | 2017-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 6 |
| Unpacked size | 34.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | tecfu |
| Maintainers | tecfu |
| Keywords | wordwrap |

## Links

- npm: https://www.npmjs.com/package/smartwrap
- Repository: https://github.com/tecfu/smartwrap
- Homepage: https://github.com/tecfu/smartwrap#readme
- Issues: https://github.com/tecfu/smartwrap/issues
- npm.io page: https://npm.io/package/smartwrap

## Dependencies (6)

- [yargs](https://npm.io/package/yargs.md) ^15.1.0
- [wcwidth](https://npm.io/package/wcwidth.md) ^1.0.1
- [breakword](https://npm.io/package/breakword.md) ^1.0.5
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^6.0.0
- [grapheme-splitter](https://npm.io/package/grapheme-splitter.md) ^1.0.4
- [array.prototype.flat](https://npm.io/package/array.prototype.flat.md) ^1.2.3

## Recent versions

- 2.0.2 (latest) — 2021-05-15
- 2.0.1 — 2020-03-09
- 2.0.0 — 2020-02-29
- 1.2.5 — 2020-02-25
- 1.2.4 — 2020-02-25
- 1.2.3 — 2020-02-14
- 1.2.2 — 2020-02-13
- 1.2.1 — 2020-01-09
- 1.2.0 — 2019-11-12
- 1.1.2 — 2019-11-03
- 1.1.1 — 2019-11-03
- 1.1.0 — 2019-08-28
- 1.0.12 — 2019-08-13
- 1.0.11 — 2019-01-13
- 1.0.10 — 2018-12-21
- … 9 more at https://npm.io/package/smartwrap/versions

## README

# smartwrap

[![Build Status](https://travis-ci.org/tecfu/smartwrap.svg?branch=master)](https://travis-ci.org/tecfu/smartwrap) [![Dependency Status](https://david-dm.org/tecfu/smartwrap.png)](https://david-dm.org/tecfu/smartwrap) [![NPM version](https://badge.fury.io/js/smartwrap.svg)](http://badge.fury.io/js/smartwrap)

Textwrap for javascript/nodejs. Correctly handles wide characters (宽字符) and emojis (😃). Optionally break words when wrapping strings.
## Why? 

I needed a javascript package to correctly wrap wide characters - which have a "length" property value of 1 but occupy 2 or more spaces in the terminal.

## Example Usages:

### Terminal:
```sh
npm i -g smartwrap
echo somestring you want to wrap | smartwrap --width=3 --paddingLeft=1
```

#### Output:
```
 so
 me
 st
 ri
 ng
 yo
 u
 wa
 nt
 to
 wr
 ap
```

## Node module:

### Wide Character Wrapping

```js
var Smartwrap = require('smartwrap');
var exampleText1 = '宽字符';
console.log(Smartwrap(exampleText1,{
  width: 2
}));
```

- Output:
```
宽
字
符
```

### String Wrapping

```js
let exampleText2 = "break at word"

console.log(smartwrap(exampleText2,{
  width: 10,
  breakword: false //default
}))
```

- Output:

```
break at
word
```

### Breaking Words When Wrapping Strings

```js
console.log(smartwrap(exampleText2,{
  width: 10,
  breakword: true
}))
```

- Output:

```
break at w
ord
```

## Options

```sh
--breakword       Choose whether or not to break words when wrapping a string
                                                                 [default: false]
--errorChar       Placeholder for wide characters when minWidth < 2
                                                                 [default: �]
--minWidth        Never change this unless you are certin you are not using
                  wide characters and you want a column 1 space wide. Then
                  change to 1.                   [choices: 1, 2] [default: 2]
--paddingLeft     Set the left padding of the output             [default: 0]
--paddingRight    Set the right padding of the output            [default: 0]
--splitAt         Characters at which to split input    [default: [" ","\t"]]
--trim            Trim the whitespace from end of input       [default: true]
--width, -w       Set the line width of the output (in spaces)
                                                     [required] [default: 10]
```

## Compatibility 

node 6.0 <

## License

[MIT](https://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/smartwrap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
