ANSI Encode
🔢 Convert ANSI escape sequences to regular strings.
Usage
const chalk = const ansiEscapeStr = chalk// '\u001b[32mHello, world!\u001b[39m' const result = // '\\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.