🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@kabeep/palette

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kabeep/palette

The fastest Node.js library to set terminal text colours & styles with hex, rgb and tree-shaking.

Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Palette

🎨 The fastest Node.js library to set terminal text colours & styles with hex, rgb and tree-shaking.

NodeJS License NPM Codecov BundlePhobia CircleCI

English | 简体中文

📖 Introduction

While chalk offers a user-friendly, chainable API, I don’t fully agree with its defensive response with "a stubborn stance". Here’s why:

  • Its large package size: chalk@4 is 101KB and chalk@5 is still 43.2KB.
  • No tree-shaking support.
  • Lacks pipe/compose functional programming support.
  • In lightweight scenarios, static ANSI strings are much more cost-effective.

This led me to develop the @kabeep/palette package in just two hours, which, like chalk, supports ANSI 16 colors, 256 colors, and 16m true-colors.

Compared to other lightweight alternatives, it goes beyond basic ANSI keywords and also supports Hex Triplet, RGB Color Model, and CSS Keywords.

But this doesn’t mean it compromises on size or performance. On the contrary, it performs excellently in Benchmark Reports:

  • Its ESModule file is just 9.48KB, with CommonJS only 12.7KB.
  • In a wide range of benchmark samples, it outperforms chalk by more than 1.7x in speed.
  • It’s significantly faster than other popular packages on npm, like colorette, which only supports ANSI keywords, and offers more API features.
  • Fully supports tree-shaking, so CLI apps needing only basic styles like yellow or red can import it with no overhead.
  • Enjoy functional programming with ease.

See documentation.

📦 Installation

npm install @kabeep/palette --save
yarn add @kabeep/palette
pnpm add @kabeep/palette

⚙️ Usage

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'));

🌈 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)

Foreground Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright

Background Colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgGray
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright

Hex Triplet

  • hex - (three-digit) #fff, ...
  • hex - (six-digit) #ffffff, ...
  • hex - (without hashtag) fff, ffffff, ...

RGB Color Model

  • rgb - (255, 255, 255), ...

CSS Color Keywords

See the full list at W3C Wiki.

  • keyword - azure, gold, indigo, ...

💐 Credits

  • [forex-cli][forex-cli-url] - 💱 A Node.js Library to convert foreign exchange in terminal.

🤝 Contribution

Contributions via Pull Requests or Issues are welcome.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Keywords

color

FAQs

Package last updated on 20 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts