JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3171105
  • Score
    100M100P100Q197565F
  • License MIT

Word-wrapping for javascript.

Package Exports

  • wordwrapjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wordwrapjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

view on npm npm module downloads Build Status Dependency Status js-standard-style

wordwrapjs

Word wrapping, with a few features.

  • multilingual - wraps any language using whitespace word separation.
  • force-break option
  • ignore pattern option (e.g. ansi escape sequences)
  • wraps hypenated words

Example
Wrap some sick bars in a 20 character column.

> wrap = require("wordwrapjs")

> bars = "I'm rapping. I'm rapping. I'm rap rap rapping. I'm rap rap rap rap rappity rapping."
> result = wrap(bars, { width: 20 })

result now looks like this:

I'm rapping. I'm
rapping. I'm rap rap
rapping. I'm rap rap
rap rap rappity
rapping.

By default, long words will not break. Unless you insist.

> url = "https://github.com/75lb/wordwrapjs"

> wrap.lines(url, { width: 18 })
[ 'https://github.com/75lb/wordwrapjs' ]

> wrap.lines(url, { width: 18, break: true })
[ 'https://github.com', '/75lb/wordwrapjs' ]

wrap(text, [options]) ⇒ string

Kind: Exported function

Param Type Default Description
text string the input text to wrap
[options] object optional config
[options.width] number 30 the max column width in characters
[options.ignore] RegExp | Array.<RegExp> one or more patterns to be ignored when sizing the newly wrapped lines. For example ignore: /\u001b.*?m/g will ignore unprintable ansi escape sequences.
[options.break] boolean if true, words exceeding the specified width will be forcefully broken
[options.eol] string "os.EOL" the desired new line character to use, defaults to os.EOL.

wrap.lines(text, [options]) ⇒ Array

returns the wrapped output as an array of lines, rather than a single string

Kind: static method of wrap

Param Type Description
text string the input text to wrap
[options] object same options as wrap

Example

> bars = "I'm rapping. I'm rapping. I'm rap rap rapping. I'm rap rap rap rap rappity rapping."
> wrap.lines(bars)
[ "I'm rapping. I'm rapping. I'm",
  "rap rap rapping. I'm rap rap",
  "rap rap rappity rapping." ]

wrap.isWrappable(text) ⇒ boolean

Returns true if the input text is wrappable

Kind: static method of wrap

Param Type Description
text string input text

wrap.getWords(text) ⇒ Array.<string>

Splits the input text returning an array of words

Kind: static method of wrap

Param Type Description
text string input text

© 2015 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.