prantlf / yoctocolors

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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,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

About

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

License:MIT License


Languages

Language:JavaScript 97.7%Language:TypeScript 2.3%