Skip to content

Word wrapping with both greedy and balanced (Minimum raggedness) implementations.

License

Notifications You must be signed in to change notification settings

nginz/fair-lines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fair-lines

Word wrapping with both greedy and balanced (Minimum raggedness) implementations.

Install with npm

$ npm install fair-lines --save

Usage

Greedy wrapping (basic)

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.

Minimum raggedness (balanced)

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

options.width

Type: Number

Default: 30

The line wrapping length

Example:

wrap.balanced(text, {width: 50});

options.indent

Type: Number

Default: 0

The indentation width at the beginning of each line.

Example:

wrap.balanced(text, {indent: 10});

options.respectNL

Type: Boolean

Default: false

Whether or not to respect new line breaks of the text in the output.

Example:

wrap.balanced(text, {respectNL: true});

License

Copyright © 2015 Moustafa Badawy Released under the MIT license.

About

Word wrapping with both greedy and balanced (Minimum raggedness) implementations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published