ansi-wordwrap
Word wraps text while ignoring ANSI codes
Last updated 8 years ago by dinchak .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install ansi-wordwrap 
SYNC missed versions from official npm registry.

ansi-wordwrap

Have you ever needed to word wrap text that had ANSI color codes in it? Did you want to ignore the ANSI color codes? If you answered "heck yeah" to any of those questions then you've come to the right web site.

Installation

npm install ansi-wordwrap

Examples

const wrap = require('ansi-wordwrap')

// use default options
wrap(someLongString)

// specify options
wrap(someLongString, {width: 80, patterns: [/@[A-Z]+@/g]})

Options

The optional second argument is an options object.

width

The width to wrap each line to, defaults to 80.

ignoreAnsi

When set to false this will disable the default pattern for matching ANSI codes, which is /\u001b.*?m/g Defaults to true. Useful if I've done a terrible job of defining this regex.

patterns

An array of regexes representing the patterns that should be ignored. For example, to ignore tokens of the form @TOKEN@, you could do:

wrap(str, {patterns: [/@[A-Z]+@/g]})

Current Tags

  • 1.0.2                                ...           latest (8 years ago)

3 Versions

  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 10
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 0
Last Month 5
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE