Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
/ colours Public archive
forked from sindresorhus/yoctocolors

The second-smallest and second-fastest command-line colouring package on the internet

License

Notifications You must be signed in to change notification settings

kytta/colours

 
 

Repository files navigation

colours

The fastest command-line colouring package on the internet

Check out the alternatives for more packages like this.

Highlights

  • Tiny
  • Fast
  • Tree-shakeable
  • No dependencies
  • Actively maintained
  • Supports NO_COLOR & FORCE_COLOR
  • Supports bright colours
  • Can be composed (WIP)
  • Works in browsers
  • Works on CommonJS

Install

pnpm add @kytta/colours

Usage

import * as colours from "@kytta/colours";

console.log(colours.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 below the text. (Not widely supported)
  • overline - Put a horizontal line above the text. (Not widely supported)
  • inverse- Invert background and foreground colors.
  • hidden - Print the text but make it invisible.
  • strikethrough - Puts a horizontal line through the center of the text. (Not widely supported)

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • blackBright (alias: gray, grey)
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgBlackBright (alias: bgGray, bgGrey)
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright

Prior art

Yes:

  • yoctocolors by Sindre Sorhus. This is a fork of it.
  • picocolors by Alexey Raspopov. As small as it can get.
  • nanocolors by Andrey Sitnik. A fork of colorette with hacks from kleur/colors.
  • colorette by Jorge Bucaran. The OG lightweight command-line colouring library.
  • kleur by Luke Edwards. Supports nesting and chaining
  • chalk by Sindre Sorhus. The most advanced of the bunch. Supports all RGB colours with graceful degradation, and more.
  • ansi-colors by Brian Woodward. A (then) faster drop-in replacement for Chalk without the bugs of other libraries.
  • cli-color by Mariusz Nowak. Supports 256 colours with some nice features added on top.

What should I use?

Probably chalk. But maybe not! See this graph for help:

A flowchart diagram illustrating your intended choice process. Choose this package, if you value speed and package size, if you don't need that many features, or if you want browser interoperability. If you need support for CommonJS and/or Node 10, and if you are willing to sacrifice functionality, choose this package also. Otherwise, choose Chalk v4 or v5, depending on the support for CommonJS.

Benchmark

This is outdated.

$ ./benchmark/index.js
┌─────────┬──────────────────┬──────────────┐
│ (index) │     Library      │   ops/sec    │
├─────────┼──────────────────┼──────────────┤
│    0    │ '@kytta/colours''27.725.838' │
│    1    │  'yoctocolors''26.188.058' │
│    2    │   'nanocolors''17.240.092' │
│    3    │   'picocolors''16.857.757' │
│    4    │   'colorette''16.798.142' │
│    5    │  'kleur/colors''16.535.599' │
│    6    │     'kleur''10.393.367' │
│    7    │    'chalk@5''10.101.294' │
│    8    │    'chalk@4''9.207.347'  │
│    9    │  'ansi-colors''3.825.073'  │
│   10    │   'cli-color''806.073'   │
└─────────┴──────────────────┴──────────────┘

See benchmark/index.js.

License

© 2023 Nikita Karamov
Licensed under the MIT License.

Based on yoctocolors.
© Sindre Sorhus
Licensed under the MIT License.


This project is hosted on GitHub: https://github.com/kytta/colours.git

About

The second-smallest and second-fastest command-line colouring package on the internet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 88.4%
  • TypeScript 11.6%