@kytta/colours
v1.0.0
Published
The second-fastest command-line colouring package on the internet
Maintainers
Readme
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/coloursUsage
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
blackredgreenyellowbluemagentacyanwhiteblackBright(alias:gray,grey)redBrightgreenBrightyellowBrightblueBrightmagentaBrightcyanBrightwhiteBright
Background colors
bgBlackbgRedbgGreenbgYellowbgBluebgMagentabgCyanbgWhitebgBlackBright(alias:bgGray,bgGrey)bgRedBrightbgGreenBrightbgYellowBrightbgBlueBrightbgMagentaBrightbgCyanBrightbgWhiteBright
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:
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
