Word wrapping with both greedy and balanced (Minimum raggedness) implementations.
npm install fair-linesInstall with npm
``sh`
$ npm install fair-lines --save
js
var wrap = require('fair-lines');var text = "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, they cannot foresee the pain and trouble that are bound to ensue."
var result = wrap.basic(text, { width: 35 });
`Results in:
`
On the other hand, we denounce with
righteous indignation and dislike
men who are so beguiled and
demoralized by the charms of
pleasure of the moment, so blinded
by desire, they cannot foresee the
pain and trouble that are bound to
ensue.
`$3
`js
var wrap = require('fair-lines');var text = "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, they cannot foresee the pain and trouble that are bound to ensue."
var result = wrap.balanced(text, { width: 35 });
`Results in:
`
On the other hand, we denounce
with righteous indignation and
dislike men who are so beguiled
and demoralized by the charms
of pleasure of the moment, so
blinded by desire, they cannot
foresee the pain and trouble
that are bound to ensue.
`
Options
$3
Type:
NumberDefault:
30The line wrapping length
Example:
`js
wrap.balanced(text, {width: 50});
`$3
Type:
NumberDefault:
0The indentation width at the beginning of each line.
Example:
`js
wrap.balanced(text, {indent: 10});
`$3
Type:
BooleanDefault:
falseWhether or not to respect new line breaks of the text in the output.
Example:
`js
wrap.balanced(text, {respectNL: true});
``Copyright © 2015 Moustafa Badawy
Released under the MIT license.