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 🙏

© 2025 – Pkg Stats / Ryan Hefner

short-ansi

v1.0.2

Published

A package to make styling terminal output easier and simpler

Downloads

17

Readme

short-ansi

This package allows you to easily mix and match ANSI terminal color/formatting to make it easier to style your output logs.

To use short-ansi, start by creating a session:

let a = require('short-ansi')();

From there you can immediately generate formatting codes by accessing properties of your short-ansi session:

console.log(a.ut + "This text is underlined and bold" + a.e + " and this is not");

The name of the property you access gets parsed by the session (a JavaScript proxy) to create the formatting codes dynamically, and each character of that name represents a command or parameter.

There is also another, nicer way to use short-ansi, using JavaScript template strings. A short-ansi session, along with being a proxy, is also a function that can parse template strings and format them automatically:

console.log(a`\{ut This text is underlined and bold\} and this is not`);

Notice how our session a is prepended to the template string. This tells JavaScript to use our session as a parser for the template string.

When short-ansi parses your template strings, it looks for matching escaped brackets and applies styles within them. Normally, escaped brackets would just be converted into normal brackets, but short-ansi actually parses the raw text inside the string. The first non-space characters inside a set of brackets determine the formatting to apply to the text inside the brackets (ut in this example), which is then followed by a space and the text you want to format. Then after the closing bracket of the set, the formatting of the string is returned to its previous state. This means that you can actually nest formatting inside template strings:

console.log(a`\{u This text is underlined \{t and this is also bold\} and this is just underlined again\}`);
console.log(a`\{rt This is red and bold \{e this is normal\} and this is red and bold again\}`);

Because we are using template strings, we can still use string interpolation too:

let someText = "This will be printed in red";
console.log(a`Value of 'someText': \{r ${someText}\}`);

short-ansi has one last feature: presets. You can define and use a preset just like so:

a.p1 = a.utr;
console.log(a`\{p1 This is underlined, bold, and red\}`);

Presets are numbered and prefixed with a p, and are unique to each session.

Format

If you have any confusion about what the color commands do, Wikipedia has some good documentation.

| Command | Type | Description | Parameters | | --------------- | --------------- | ------------------------------- | ----------------------------------- | | , | no-op | used for readability | (none) | | e | reset | reset all formatting (end) | (none) | | u | style | underline | (none) | | t | style | bold (thick) | (none) | | s | style | faint (slim) | (none) | | i | style | italic | (none) | | f[n] | style | font | f: font number | | d | basic color | black (dark) | (none) | | r | basic color | red | (none) | | g | basic color | green | (none) | | y | basic color | yellow | (none) | | b | basic color | blue | (none) | | m | basic color | magenta | (none) | | c | basic color | cyan | (none) | | w | basic color | white | (none) | | q[n] | color | 8-bit color cube (qube) | n: color cube number | | a[r]_[g]_[b] | color | 24-bit rgb (all colors) | r: red, g: green, b: blue | | l[c] | color modifier | brighten (lighten) | c: basic color | | h[c] | color modifier | background (highlight) | c: any color or brightened color | | n[c] | modifier | not | c: any of utsidrgybmcwqah | | p[n] | preset | preset | n: preset number |

Note: the "not" (n) command takes a single character without any extra parameters. For example, nq30 is not valid because q is used as a raw parameter instead of as a command, and 30 isn't a known command. Conversely, q30 is valid, because 30 is used as q's parameter. Also, when paired with a style, the "not" command will reset that style specifically, but when paired with h or any color command, it will reset the background color or foreground color, respectively.