wrap-ansi

  • Version 9.0.0
  • Published
  • 11.5 kB
  • 3 dependencies
  • MIT license

Install

npm i wrap-ansi
yarn add wrap-ansi
pnpm add wrap-ansi

Overview

Wordwrap a string with ANSI escape codes

Index

Functions

Type Aliases

Functions

function wrapAnsi

wrapAnsi: (string: string, columns: number, options?: Options) => string;
  • Wrap words to the specified column width.

    Parameter string

    A string with ANSI escape codes, like one styled by [chalk](https://github.com/chalk/chalk). Newline characters will be normalized to \n.

    Parameter columns

    The number of columns to wrap the text to.

    Example 1

    import chalk from 'chalk';
    import wrapAnsi from 'wrap-ansi';
    const input = 'The quick brown ' + chalk.red('fox jumped over ') +
    'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
    console.log(wrapAnsi(input, 20));

Type Aliases

type Options

type Options = {
/**
By default the wrap is soft, meaning long words may extend past the column width. Setting this to `true` will make it hard wrap at the column width.
@default false
*/
readonly hard?: boolean;
/**
By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary.
@default true
*/
readonly wordWrap?: boolean;
/**
Whitespace on all lines is removed by default. Set this option to `false` if you don't want to trim.
@default true
*/
readonly trim?: boolean;
};

    Package Files (1)

    Dependencies (3)

    Dev Dependencies (7)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/wrap-ansi.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/wrap-ansi)
    • HTML
      <a href="https://www.jsdocs.io/package/wrap-ansi"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>