hjw 6c42b6a025 first commit 1 week ago
..
index.d.ts 6c42b6a025 first commit 1 week ago
index.js 6c42b6a025 first commit 1 week ago
license 6c42b6a025 first commit 1 week ago
package.json 6c42b6a025 first commit 1 week ago
readme.md 6c42b6a025 first commit 1 week ago

readme.md

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
  • Handles nested colors
  • Tree-shakeable
  • No dependencies
  • Actively maintained

Install

npm install yoctocolors

Usage

import colors from 'yoctocolors';

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

console.log(colors.blue(`Welcome to the ${colors.green('yoctocolors')} package!`));

You can also import colors as named imports:

import {red, blue, green} from 'yoctocolors';

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

console.log(blue(`Welcome to the ${green('yoctocolors')} package!`));

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,000,000' โ”‚
โ”‚ 1       โ”‚ 'colorette'    โ”‚ '8,000,000' โ”‚
โ”‚ 2       โ”‚ 'picocolors'   โ”‚ '8,000,000' โ”‚
โ”‚ 3       โ”‚ 'nanocolors'   โ”‚ '5,988,024' โ”‚
โ”‚ 4       โ”‚ 'chalk'        โ”‚ '4,807,692' โ”‚
โ”‚ 5       โ”‚ 'kleur/colors' โ”‚ '4,807,692' โ”‚
โ”‚ 6       โ”‚ 'kleur'        โ”‚ '4,784,689' โ”‚
โ”‚ 7       โ”‚ 'ansi-colors'  โ”‚ '2,178,649' โ”‚
โ”‚ 8       โ”‚ 'cli-color'    โ”‚ '585,138'   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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