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

ansidec

v0.3.4

Published

Limited Unix ANSI escape sequences transformer for use in Browsers

Downloads

2,990

Readme

   ▄████████ ███▄▄▄▄      ▄████████  ▄█  ████████▄     ▄████████  ▄████████
  ███    ███ ███▀▀▀██▄   ███    ███ ███  ███   ▀███   ███    ███ ███    ███
  ███    ███ ███   ███   ███    █▀  ███▌ ███    ███   ███    █▀  ███    █▀
  ███    ███ ███   ███   ███        ███▌ ███    ███  ▄███▄▄▄     ███
▀███████████ ███   ███ ▀███████████ ███▌ ███    ███ ▀▀███▀▀▀     ███
  ███    ███ ███   ███          ███ ███  ███    ███   ███    █▄  ███    █▄
  ███    ███ ███   ███    ▄█    ███ ███  ███   ▄███   ███    ███ ███    ███
  ███    █▀   ▀█   █▀   ▄████████▀  █▀   ████████▀    ██████████ ████████▀

npm travis Coverage Status MIT badge

ANSIDec is a library for handling limited number of ANSI escape sequences for use in Browsers. The primary goal of the library is to allow of displaying ANSI and ASCII art in Browsers by transforming Unix encoding to html. But it can also be used from Node.js.

Demo

https://jcubic.github.io/ansidec/

Installation

Npm installation for use with webpack:

npm install ansidec

Besides npm you can also download that file locally or use unpkg.com:

<script src="https://unpkg.com/ansidec"></script>

Usage

// if you're using webpack or node.js you can use npm
var ansi = require('ansidec');

var format = ansi.format(function(styles, color, background, text) {
  var style = [];
  if (color) {
    style.push('color:' + color);
  }
  if (background) {
    style.push('background:' + background);
  }
  if (styles.bold) {
    style.push('font-weight:bold');
  }
  if (styles.italic) {
    style.push('font-style:italic');
  }
  if (styles.underline) {
    styles.push('text-decoration:underline');
  }
  return '<span style="' + style.join(';') + '">' + text + '</span>';
});

document.querySelector('pre').innerHTML = format(text);

format function can be executed with text as second argument, then it will return string. If it don't get string as second argument it will return function. So it's like it was curried.

If you want just to output html you can use helper:

var ansi = require('ansidec');
var output = document.querySelector('pre');
output.innerHTML = ansi.html(text)

and use format only if you need different html or any different output text.

ANSI art

If you want to render ANSI art with this library you will need to covert the text from ANSI art file to UTF-8 to do that you can use iconv-lite library or iconv on a Back-End see how to do that in examples directory.

Some ANSI art are 80 characters wide but some have meta data called SAUCE. You can read those data using ansi.meta function:

var sauce = ansi.meta(text);
if (sauce) {
  var chars = sauce.tInfo[0];
  // note that ch unit don't work properly in IE
  output.style.width = chars + 'ch';
}

meta object have those properties (description in SAUCE specification linked above).

{
  id: 'SAUCE',
  version: string,
  title: string,
  author: string,
  group: string,
  date: string,
  fileSize: number,
  tInfo: number[],
  comments: string,
  tflags: string,
  zstring: string
}

Changelog

  • 0.3.4 - fix GitHub url in README for npm
  • 0.3.3 - parse zstring from SAUCE + fixes to match unit tests
  • 0.3.2 - proper parsing of SAUCE comments
  • 0.3.1 - alternative SAUCE extraction
  • 0.3.0 - parsing SAUCE meta
  • 0.2.1 - bump up version for npm
  • 0.2.0 - fix 8 bit colors (Denis Ritchie)
  • 0.1.0 - first version

License

Released under MIT license

Copyright (c) 2018-2020 Jakub T. Jankiewicz