pretty-ansi

Convert ANSI escape sequences to human readable text

MIT 4 个版本
安装
npm install pretty-ansi
yarn add pretty-ansi
pnpm add pretty-ansi
bun add pretty-ansi
README

pretty-ansi

version license install-size 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 assert from "node:assert";
import test from "node:test";
import prettyAnsi from "pretty-ansi";

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

  assert.strictEqual(prettyAnsi(commandOutput), "<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.

License

MIT

版本列表
4.0.0 2026-03-30
3.0.0 2024-11-26
2.0.0 2024-02-20
1.0.0 2024-02-19