smartwrap
Textwrap for javascript/nodejs. Correctly handles wide characters (宽字符) and emojis (😃). Wraps strings with option to break on words.
Last updated 5 years ago by tecfu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install smartwrap 
SYNC missed versions from official npm registry.

smartwrap

Build Status Dependency Status NPM version

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:

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

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

String Wrapping

let exampleText2 = "break at word"

console.log(smartwrap(exampleText2,{
  width: 10,
  breakword: false //default
}))
  • Output:
break at
word

Breaking Words When Wrapping Strings

console.log(smartwrap(exampleText2,{
  width: 10,
  breakword: true
}))
  • Output:
break at w
ord

Options

--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

Current Tags

  • 2.0.2                                ...           latest (5 years ago)

24 Versions

  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0 [deprecated]           ...           6 years ago
  • 1.2.5 [deprecated]           ...           6 years ago
  • 1.2.4 [deprecated]           ...           6 years ago
  • 1.2.3 [deprecated]           ...           6 years ago
  • 1.2.2 [deprecated]           ...           6 years ago
  • 1.2.1 [deprecated]           ...           6 years ago
  • 1.2.0 [deprecated]           ...           6 years ago
  • 1.1.2 [deprecated]           ...           6 years ago
  • 1.1.1 [deprecated]           ...           6 years ago
  • 1.1.0 [deprecated]           ...           7 years ago
  • 1.0.12 [deprecated]           ...           7 years ago
  • 1.0.11 [deprecated]           ...           7 years ago
  • 1.0.10 [deprecated]           ...           7 years ago
  • 1.0.9 [deprecated]           ...           9 years ago
  • 1.0.8 [deprecated]           ...           9 years ago
  • 1.0.7 [deprecated]           ...           9 years ago
  • 1.0.6 [deprecated]           ...           9 years ago
  • 1.0.5 [deprecated]           ...           9 years ago
  • 1.0.3 [deprecated]           ...           9 years ago
  • 1.0.2 [deprecated]           ...           9 years ago
  • 1.0.1 [deprecated]           ...           9 years ago
  • 1.0.0 [deprecated]           ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 5
Last Month 5
Dependencies (6)
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |