npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ansi2html-extended

v0.0.4

Published

Convert colored console output (ANSI shell escape codes) to HTML.

Downloads

14

Readme

ansi2html-extended

Build Status

Get it on npm

This module, written in JavaScript, is an extended fork of https://github.com/mmalecki/ansispan. It converts an input string with ANSI escape codes (for colored console output etc.) into its HTML equivalent. It can be used either as a nodejs module, or as a command-line utility.

Unlike original module, this module wraps text with <span>s with defined CSS classes, instead of hardcoded inline CSS strings.

Apart from that, it allows to:

  • output either standalone HTML file, or just an HTML chunk
  • pre-process the text by escaping HTML special characters

Tested on Windows (Git Bash / MINGW).

It requires nodejs and npm. If you don't have node, grab it at nodejs.org. Node installer bundles npm (node package manager).

Tested on nodejs 0.10.

API

a2h.fromStream(cfg, inputStream, outputStream)

Read text from inputStream and write HTML to outputStream.

a2h.fromStream(cfg)

Read text from stdin and write HTML to stdout.

a2h.fromString(string)
a2h.fromString(cfg, string)

Read input text String string and return HTML as String

Configuration

cfg.standalone Boolean (default: true when input is stream, false when input is string)

If true, output will be a valid HTML file, and it will contain color palette in the <head>, as a style tag. Otherwise, only a HTML chunk will be generated.

cfg.wrapped Boolean (defaults to value of cfg.standalone)

Whether to wrap the passed string in <span class="ansi_console_snippet"></span>.

cfg.escapeHtml Boolean (default: true)

Whether HTML entities in input string should be escaped (& -> &amp; etc.).

cfg.palette Object (optional)

This allows you to override the default colors.

By default, it is assumed that console is white text on black background, and HTML named colors are used for escape codes, i.e. ANSI 34 and 44 will use HTML blue color.

You can override each of the colors by passing any of the following keys: black, white, red, green, blue, yellow, purple, cyan.

You can also override each of them separately for foreground and background using fg_black, bg_black and so on.

You can override default colors of the console by either overriding black and white, or directly via bg and fg.

Example:

    palette: {
        bg: '#222222',
        fg: '#eeeeee',
        fg_red:'#ff0000',
        bg_red:'#dd0000',
        green: '#00cc3e'
    }

Usage as a nodejs module

$ npm install --save-dev ansi2html-extended
var a2h = require('ansi2html-extended');
var cfg = {
    standalone: true,
    palette: {
        black: '#222222',
        white: '#eeeeee'
    }
}

// read text from stdin and output HTML to stdout
a2h.fromStream(cfg);

// you can also just pass a string and get a string returned
a2h.fromString("commit d0fb3a8a5487559e8a2d76735f04b5a02b242838")
// returns `<span class="ansi_fg_yellow">commit d0fb3a8a5487559e8a2d76735f04b5a02b242838</span>`

// you can pass cfg as a first parameter too
a2h.fromString({
  wrapped: true
}, "commit d0fb3a8a5487559e8a2d76735f04b5a02b242838")
// returns `<span class="ansi_console_snippet"><span class="ansi_fg_yellow">commit d0fb3a8a5487559e8a2d76735f04b5a02b242838</span></span>`

Usage from command line

# this will create two symlinks in PATH: `ansi2html` and `a2h`
$ npm install -g ansi2html-extended

# Ask git for colored summary of last commit, and pipe it to a2h
# This prints to stdout by default
# Note we explicitly ask for --color; git disables colors when piping
$ git show --stat --color | a2h

# It will be more interesting when we save it to a file...
$ git show --stat --color | a2h > examples/git-show-stat.html
$ firefox examples/git-show-stat.html

See the live rendered examples/git-show-stat.html

The following options are used when a2h is invoked from command line:

{
    standalone: true,
    escapeHtml: true,
    palette: {
        black: '#222222',
        white: '#eeeeee',
        red:   '#dd0000',
        green: '#00cc3e',
        blue:  '#0099ff',
        yellow:'#eeee00',
        purple:'#bb00bb',
        cyan:  '#eeeeee'
    }
}

License

MIT � Jakub Gieryluk