2.0.0 ā€¢ Published 2 months ago

yoctocolors v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgGray
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright

Prior art

Yes

Benchmark

$ ./benchmark.js
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
ā”‚ (index) ā”‚    library     ā”‚   ops/sec   ā”‚
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
ā”‚    0    ā”‚ 'yoctocolors'  ā”‚ '8,928,571' ā”‚
ā”‚    1    ā”‚  'nanocolors'  ā”‚ '8,000,000' ā”‚
ā”‚    2    ā”‚  'picocolors'  ā”‚ '7,751,938' ā”‚
ā”‚    3    ā”‚  'colorette'   ā”‚ '6,097,561' ā”‚
ā”‚    4    ā”‚ 'kleur/colors' ā”‚ '5,882,353' ā”‚
ā”‚    5    ā”‚    'chalk'     ā”‚ '5,263,158' ā”‚
ā”‚    6    ā”‚    'kleur'     ā”‚ '4,115,226' ā”‚
ā”‚    7    ā”‚ 'ansi-colors'  ā”‚ '1,288,660' ā”‚
ā”‚    8    ā”‚  'cli-color'   ā”‚  '377,786'  ā”‚
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

See benchmark.js.

FAQ

What is yocto?

It was the smallest official unit prefix in the metric system until 2022. Much smaller than nano.

Related

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