npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

console-palette

v1.0.1

Published

A light weight versatile Node.js library for customizing the style and color of the console output.

Downloads

133

Readme

Console Palette

Console Palette is a lightweight Node.js library that simplifies working with ANSI color codes in terminal output. Customize your terminal text with colors, backgrounds, and styles using easy-to-use utility functions.

Features

  • Predefined ANSI color and style methods for foreground and background. These can be passed as a string in the custom method — See section Available ANSI Codes below.
  • Custom color conversion from HEX and RGB values to ANSI.
  • Chaining and combining styles for complex output customization.

Installation

npm install console-palette

Usage

Import the library

const cp = require('./console-palette.js'); // for Common JS
// or
import cp from './console-palette.js'; // for ES6

Basic Provided Color Usage

console.log(cp.red('This text is red!'));
console.log(cp.bgBlue('This text has a blue background!'));
console.log(cp.brightYellow('This is bright yellow!'));

Applying Styles

let bold = cp.bold('Bold Text');
let italic = cp.italic('Italic and');
let underlined = cp.underline('Underlined Text');
console.log(bold + " " + italic + " " + underlined);

// **Bold** *Italic* and Underlined Text

Using the custom method for colors and style

You can also use custom HEX or RGB colors for more flexibility.

Provided color strings (see list below)

console.log(cp.custom('hello world', { color: 'brightYellow' }));

HEX color codes

console.log(cp.custom('Custom HEX color', { color: '#FF5733' }));

RGB string or object inputs

console.log(cp.custom('This text should be red', { color: { r: 255, g: 0, b: 0 } }));
console.log(cp.custom('This text should be red', { color: 'rgb(255, 0, 0)' }));

Custom Background Colors

console.log(cp.custom('Custom Background Color using hex', { background: '#34c3ff' }));
console.log(cp.custom('Custom Background Color RGB', { background: 'rgb(255, 0, 0)' }));
console.log(cp.custom('Custom Background with provided colors', { background: 'pink' }));

Custom styles

Separate multiple styles with the custom method by commas.

console.log(cp.custom('Hello World', {
    style: 'bold,underline,invert'
}));

Combining Styles, Colors, and Backgrounds

You can combine styles, foreground colors, and backgrounds for advanced formatting:

console.log(cp.custom('Styled Text', {
    color: 'green',
    background: 'pink',
    style: 'bold,underline'
}));

Chain Styles and Colors

You can combine multiple styles, colors, and backgrounds by nesting them or chaining directly through the custom function.

Chaining with Predefined Colors and Styles

console.log(cp.red(cp.bold('This text is bold and red!')));
console.log(cp.bgBlue(cp.underline(cp.white('This text is underlined and has a blue background!'))));

Utility Functions

  • hexToAnsi(hex): Converts HEX color to ANSI code for foreground.
  • rgbToAnsi(rgb): Converts an RGB object to ANSI code for foreground.
  • rgbStringToAnsi(rgbString): Converts an RGB string to ANSI code for foreground.
  • hexToAnsiBackground(hex): Converts HEX color to ANSI background.
  • rgbToAnsiBackground(rgb): Converts RGB object to ANSI background.
  • rgbStringToAnsiBackground(rgbString): Converts RGB string to ANSI background.

Available ANSI Codes

  • Foreground Colors: black, red, green, yellow, blue, magenta, cyan, white, and bright variants (brightRed, brightGreen, etc.).
  • Background Colors: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, and bright variants.
  • Styles: bold, underline, italic, strikethrough, inverse.