Word wrapping with both greedy and balanced (Minimum raggedness) implementations.
Install with npm
$ npm install fair-lines --save
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.
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.
Type: Number
Default: 30
The line wrapping length
Example:
wrap.balanced(text, {width: 50});
Type: Number
Default: 0
The indentation width at the beginning of each line.
Example:
wrap.balanced(text, {indent: 10});
Type: Boolean
Default: false
Whether or not to respect new line breaks of the text in the output.
Example:
wrap.balanced(text, {respectNL: true});
Copyright © 2015 Moustafa Badawy Released under the MIT license.