Skip to content

The smallest and fastest command-line coloring package on the internet

License

Notifications You must be signed in to change notification settings

silverwind/yoctocolors

 
 

Repository files navigation

yoctocolors 🌈

The smallest and fastest command-line coloring package on the internet

Check out Chalk if you want something more mature and comprehensive.

Highlights

  • Tiny
  • Fast
  • Tree-shakeable
  • No dependencies
  • Actively maintained

Install

npm install yoctocolors

Usage

import * as colors from 'yoctocolors';

console.log(colors.red('Yo!'));

This package supports basic color detection. Colors can be forcefully enabled by setting the FORCE_COLOR environment variable to 1 and can be forcefully disabled by setting NO_COLOR or NODE_DISABLE_COLORS to any value. More info.

Styles

Modifiers

  • reset - Reset the current style.
  • bold - Make the text bold.
  • dim - Make the text have lower opacity.
  • italic - Make the text italic. (Not widely supported)
  • underline - Put a horizontal line above the text. (Not widely supported)
  • overline - Put a horizontal line below the text. (Not widely supported)
  • inverse- Invert background and foreground colors.
  • hidden - Print the text but make it invisible.
  • strikethrough - Put a horizontal line through the center of the text. (Not widely supported)

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgGray

Prior art

Yes

Benchmark

$ ./benchmark.js
┌─────────┬────────────────┬─────────────┐
│ (index) │    library     │   ops/sec   │
├─────────┼────────────────┼─────────────┤
│    0    │ 'yoctocolors''8,771,930' │
│    1    │  'nanocolors''6,896,552' │
│    2    │  'colorette''6,172,840' │
│    3    │  'picocolors''6,060,606' │
│    4    │ 'kleur/colors''5,263,158' │
│    5    │    'chalk''4,484,305' │
│    6    │    'kleur''3,731,343' │
│    7    │ 'ansi-colors''1,283,697' │
│    8    │  'cli-color''393,236'  │
└─────────┴────────────────┴─────────────┘

See benchmark.js.

FAQ

What is yocto?

It's the smallest official unit prefix in the metric system. Much smaller than nano.

Related

  • yoctodelay - Delay a promise a given amount of time
  • chalk - Terminal string styling

About

The smallest and fastest command-line coloring package on the internet

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 97.7%
  • TypeScript 2.3%