ansi-encode

1.0.1 • Public • Published

ANSI Encode

🔢 Convert ANSI escape sequences to regular strings.

Build Status Coverage Status Npm Version XO code style

Usage

const chalk = require('chalk')
 
const ansiEscapeStr = chalk.green('Hello, world!')
// '\u001b[32mHello, world!\u001b[39m'
 
const result = ansiEncode(ansiEscapeStr)
// '\\u001b[32mHello, world!\\u001b[39m'

Installation

yarn add ansi-encode

About

This simple Node module takes a JavaScript string containing ANSI escape sequences and converts them into regular JavaScript strings. It is a bit like using escape(string), where escape() turns individual characters into their respective codes; wheresansiEncode() converts ANSI escape sequences back into plain strings.

This ansi-encode exists because I ran into problems creating tests color terminal output in other Node modules. When a test failed in Mocha, I was able to see the ANSI escape codes and copy the correct string into the test. When I started using [AVA - The Futuristic Test Runner] for testing code, I discovered the escape sequences were not printed. This gave me no way to test color console output.

Package Sidebar

Install

npm i ansi-encode

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

169 kB

Total Files

8

Last publish

Collaborators

  • f1lt3r