ansi-encode v1.0.1
ANSI Encode
🔢 Convert ANSI escape sequences to regular strings.
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-encodeAbout
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.