pretty-ansi
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

pretty-ansi

version license packagephobia coverage

Convert ANSI escape sequences to human readable text.


This utility converts ANSI escape sequences to human readable text. It supports color, style and cursor control escapes and works with vanilla sequences as well as the output from libraries like chalk, colors, ansi-escapes, ansi-styles or terminal-kit.

Install

npm add -D pretty-ansi

Usage

For example, it can be useful to test the output of a command line tool:

import { expect } from "chai";
import { test } from "mocha";

import prettyAnsi from "pretty-ansi";

test("command output", () => {
  const commandOutput = "\u001b[3;32mSuccess!\u001b[0m";

  expect(prettyAnsi(commandOutput)).to.equal("<italic, green>Success!</>");
});

Notes

Currently only 16 colors are all supported.

Keep in mind that the escape sequences are not validated. Unrecognized sequence will print as <ESC>[a1b2c3, or as <?> in case this is a color or style sequence.

Related

License

MIT

Package Sidebar

Install

npm i pretty-ansi

Weekly Downloads

8,903

Version

2.0.0

License

MIT

Unpacked Size

8.89 kB

Total Files

7

Last publish

Collaborators

  • mrazauskas