xycolors
v0.1.2
Published
A tiny and fast package for adding colors to your terminal output.
Maintainers
Readme
xycolors 🌈
A tiny and fast package for adding colors to your terminal output.
Based on yoctocolors
Highlights
- Tiny
- Fast
- Handles nested colors
- Tree-shakeable
- No dependencies
- Actively maintained
Install
npm install xycolorsUsage
import * as c from 'xycolors'
console.log(c.red('Yo!'))
console.log(c.blue(`Welcome to the ${colors.magenta('xycolors')} 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
blackredgreenyellowbluemagentacyanwhitegrayredBrightgreenBrightyellowBrightblueBrightmagentaBrightcyanBrightwhiteBrightblackStylizeblackSecondaryStylizeredStylizeredSecondaryStylizegreenStylizegreenSecondaryStylizeyellowStylizeyellowSecondaryStylizeblueStylizeblueSecondaryStylizemagentaStylizemagentaSecondaryStylizepinkStylizepinkSecondaryStylizecyanStylizecyanSecondaryStylizewhiteStylizewhiteSecondaryStylizegrayStylizegraySecondaryStylize
Background colors
bgBlackbgRedbgGreenbgYellowbgBluebgMagentabgCyanbgWhitebgGraybgRedBrightbgGreenBrightbgYellowBrightbgBlueBrightbgMagentaBrightbgCyanBrightbgWhiteBright
TrueColor
You can use the hex or rgb format.
Foreground function: hex() rgb()
Background function: bgHex() bgRgb()
import { bgHex, bgRgb, hex, rgb } from 'xycolors'
// foreground color
hex('#E0115F')('Ruby')
hex('#96C')('Amethyst')
rgb(224, 17, 95)('Ruby')
// background color
bgHex('#E0115F')('Ruby')
bgHex('#96C')('Amethyst')
bgRgb(224, 17, 95)('Ruby')Benchmark
$ ./benchmark.js
┌─────────┬────────────────┬─────────────┐
│ (index) │ library │ ops/sec │
├─────────┼────────────────┼─────────────┤
│ 0 │ 'xycolors' │ '8,000,000' │
│ 1 │ 'picocolors' │ '8,000,000' │
│ 2 │ 'colorette' │ '6,024,096' │
│ 3 │ 'kleur/colors' │ '4,807,692' │
│ 4 │ 'nanocolors' │ '4,807,692' │
│ 5 │ 'chalk' │ '4,000,000' │
│ 6 │ 'kleur' │ '4,000,000' │
│ 7 │ 'ansi-colors' │ '1,848,429' │
│ 8 │ 'cli-color' │ '585,480' │
└─────────┴────────────────┴─────────────┘See benchmark.js.
