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

ansi-colors-es6

v5.0.0

Published

ES6+ module to easily add ANSI colors to your browser console and node terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).

Downloads

325

Readme

ansi-colors-es6 NPM version NPM monthly downloads NPM total downloads

Easily add ANSI colors to your node terminal or browser console. A faster drop-in replacement for chalk, colors, kleur and turbocolor (without the dependencies and rendering bugs). And a lighter ES6 implementation of ansi-colors that works everywhere ES6+ works without the need for transpiling, unless you want to.

Install

Install with npm:

$ npm install --save ansi-colors-es6

image

node terminal color examples

Why use this?

ansi-colors-es6 is the fastest Node.js library for terminal and browser console styling. A more performant drop-in replacement for chalk, colors and ansi-colors with no dependencies.

Chrome

chrome terminal color examples

Edge

edge terminal color examples

Usage

//use relative paths to allow code sharing with browsers
//this way the same exact files will work in all locations
import ansi from './node_modules/ansi-colors-es6/index.js';

console.log(ansi.red('This is a red string!'));
console.log(ansi.green('This is a red string!'));
console.log(ansi.cyan('This is a cyan string!'));
console.log(ansi.yellow('This is a yellow string!'));

image

Chained colors

//use relative paths to allow code sharing with browsers
//this way the same exact files will work in all locations
import ansi from './node_modules/ansi-colors-es6/index.js';

console.log(ansi.bold.red('this is a bold red message'));
console.log(ansi.bold.yellow.italic('this is a bold yellow italicized message'));
console.log(ansi.green.bold.underline('this is a bold green underlined message'));

image

Nested colors

//use relative paths to allow code sharing with browsers
//this way the same exact files will work in all locations
import ansi from './node_modules/ansi-colors-es6/index.js';

console.log(ansi.yellow(`foo ${ansi.red.bold('red')} bar ${ansi.cyan('cyan')} baz`));

image

Toggle color support

Easily enable/disable colors.

//use relative paths to allow code sharing with browsers
//this way the same exact files will work in all locations
import ansi from './node_modules/ansi-colors-es6/index.js';

// disable colors manually
ansi.enabled = false;

// or use a library to automatically detect support
ansi.enabled = require('color-support').hasBasic;

console.log(ansi.red('I will only be colored red if the terminal supports colors'));

Strip ANSI codes

Use the .unstyle method to strip ANSI codes from a string.

console.log(ansi.unstyle(ansi.blue.bold('foo bar baz')));
//=> 'foo bar baz'

Available styles

Note that bright and bright-background colors are not always supported.

| Colors | Background Colors | Bright Colors | Bright Background Colors | | ------- | ----------------- | ------------- | ------------------------ | | black | bgBlack | blackBright | bgBlackBright | | red | bgRed | redBright | bgRedBright | | green | bgGreen | greenBright | bgGreenBright | | yellow | bgYellow | yellowBright | bgYellowBright | | blue | bgBlue | blueBright | bgBlueBright | | magenta | bgMagenta | magentaBright | bgMagentaBright | | cyan | bgCyan | cyanBright | bgCyanBright | | white | bgWhite | whiteBright | bgWhiteBright | | gray | | | | | grey | | | |

(gray is the U.S. spelling, grey is more commonly used in the Canada and U.K.)

Style modifiers

  • dim

  • bold

  • hidden

  • italic

  • underline

  • inverse

  • ~~strikethrough~~

  • reset

Aliases

Create custom aliases for styles.

//use relative paths to allow code sharing with browsers
//this way the same exact files will work in all locations
import ansi from './node_modules/ansi-colors-es6/index.js';

ansi.alias('primary', ansi.yellow);
ansi.alias('secondary', ansi.bold);

console.log(ansi.primary.secondary('Foo'));

Themes

A theme is an object of custom aliases.

//use relative paths to allow code sharing with browsers
//this way the same exact files will work in all locations
import ansi from './node_modules/ansi-colors-es6/index.js';

ansi.theme({
  danger: ansi.red,
  dark: ansi.dim.gray,
  disabled: ansi.gray,
  em: ansi.italic,
  heading: ansi.bold.underline,
  info: ansi.cyan,
  muted: ansi.dim,
  primary: ansi.blue,
  strong: ansi.bold,
  success: ansi.green,
  underline: ansi.underline,
  warning: ansi.yellow
});

// Now, we can use our custom styles alongside the built-in styles!
console.log(ansi.danger.strong.em('Error!'));
console.log(ansi.warning('Heads up!'));
console.log(ansi.info('Did you know...'));
console.log(ansi.success.bold('It worked!'));

Contributors

| Commits | Contributor |
| --- | --- |
| 48 | jonschlinkert |
| 42 | doowb |
| 9 | RIAEvangelist | | 6 | lukeed | | 2 | Silic0nS0ldier |
| 1 | dwieeb |
| 1 | jorgebucaran |
| 1 | madhavarshney |
| 1 | chapterjason |