Socket
Socket
Sign inDemoInstall

anser

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anser

A low level parser for ANSI sequences.


Version published
Weekly downloads
2.5M
increased by1.6%
Maintainers
1
Weekly downloads
 
Created

What is anser?

The 'anser' npm package is a library that allows you to convert ANSI escape codes into HTML. This is particularly useful for rendering terminal output in web applications, where you want to preserve the color and style formatting.

What are anser's main functionalities?

Convert ANSI to HTML

This feature allows you to convert a string containing ANSI escape codes into an HTML string with equivalent styling. The example converts a red-colored 'Hello, World!' from ANSI to HTML.

const anser = require('anser');
const ansiString = '\u001b[31mHello, World!\u001b[0m';
const htmlString = anser.toHtml(ansiString);
console.log(htmlString); // Outputs: <span style="color:#E34C26;">Hello, World!</span>

Strip ANSI codes

This feature allows you to strip ANSI escape codes from a string, leaving just the plain text. The example removes the red color formatting from 'Hello, World!'.

const anser = require('anser');
const ansiString = '\u001b[31mHello, World!\u001b[0m';
const plainString = anser.ansiToText(ansiString);
console.log(plainString); // Outputs: Hello, World!

Escape for HTML

This feature escapes HTML special characters in a string containing ANSI escape codes. The example converts '<' and '>' to their HTML entities.

const anser = require('anser');
const ansiString = '\u001b[31mHello, <World>!\u001b[0m';
const escapedHtmlString = anser.escapeForHtml(ansiString);
console.log(escapedHtmlString); // Outputs: \u001b[31mHello, &lt;World&gt;!\u001b[0m

Other packages similar to anser

Keywords

FAQs

Package last updated on 11 Nov 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc