Socket
Socket
Sign inDemoInstall

ansi-encode

Package Overview
Dependencies
56
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ansi-encode

Convert ANSI escape sequences to regular strings.


Version published
Maintainers
1
Install size
4.86 MB
Created

Readme

Source

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.

Keywords

FAQs

Last updated on 15 Mar 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc