chalk
offers a user-friendly, chainable API. In spite of the excellent work done by @sindresorhus to reduce the size of the packaging as much as possible. But my view is that the key issue is not "Why not switch to a smaller coloring package?". Hereโs why:
- No tree-shaking support, and no FP such as pipe/compose.
- You will still need to create the full
chalk
using the factory function if you only need to colour the red failure and green success messages.- In lightweight scenarios, static ANSI strings are much more cost-effective.
So I created this package.
It supports ANSI 16 colours, 256 colours and 16 million true colours like chalk
.
Compared to other lightweight alternatives, it goes beyond basic ANSI keywords and also supports
Hex Triplet, RGB Color Model, and CSS Keywords.
But this does not mean it compromises on size or performance.
On the contrary, it performs excellently in Benchmark Reports.
Of course, all the coloring packages are more than fast enough,
I am just saying @kabeep/palette
is a good choice for people who value size and performance.
See documentation.
npm install @kabeep/palette --save
yarn add @kabeep/palette
pnpm add @kabeep/palette
CommonJS
const pipe = require('lodash.flow');
const { bgRgb, hex, keyword, yellowBright } = require('@kabeep/palette');
const padding = (text: string) => ` ${text} `;
const palette = pipe(keyword('gold'), padding, bgRgb(255, 0, 0));
console.log(palette('Error'), yellowBright('Warning'), hex('#ff0000')('Message'));
ESModule
import pipe from 'lodash.flow';
import { bgRgb, hex, keyword, yellowBright } from '@kabeep/palette';
const padding = (text: string) => ` ${text} `;
const palette = pipe(keyword('gold'), padding, bgRgb(255, 0, 0));
console.log(palette('Error'), yellowBright('Warning'), hex('#ff0000')('Message'));
- 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)
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- gray
- redBright
- greenBright
- yellowBright
- blueBright
- magentaBright
- cyanBright
- whiteBright
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgMagenta
- bgCyan
- bgWhite
- bgGray
- bgRedBright
- bgGreenBright
- bgYellowBright
- bgBlueBright
- bgMagentaBright
- bgCyanBright
- bgWhiteBright
- hex - (three-digit) #fff, ...
- hex - (six-digit) #ffffff, ...
- hex - (without hashtag) fff, ffffff, ...
- rgb - (255, 255, 255), ...
See the full list at W3C Wiki.
- keyword - azure, gold, indigo, ...
- ansi-styles - Implement hexToRgb function.
- chalk-pipe - Collating cssKeywords data.
- yoctocolors - Implement format function & style description.
Contributions via Pull Requests or Issues are welcome.
This project is licensed under the MIT License. See the LICENSE file for details.