get colors in your node.js console

Related tags

Color colors
Overview

colors.js

Build Status version

This is a fork of Marak Squires' original colors.js project

Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback, and check the develop branch for the latest bleeding-edge updates.

get color and style in your node.js console

Demo

Installation

Using npm:

npm i @jshor/colors

Using yarn:

yarn add @jshor/colors

colors and styles!

text colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • grey

bright text colors

  • brightRed
  • brightGreen
  • brightYellow
  • brightBlue
  • brightMagenta
  • brightCyan
  • brightWhite

background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgGray
  • bgGrey

bright background colors

  • bgBrightRed
  • bgBrightGreen
  • bgBrightYellow
  • bgBrightBlue
  • bgBrightMagenta
  • bgBrightCyan
  • bgBrightWhite

styles

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

extras

  • rainbow
  • zebra
  • america
  • trap
  • random

Usage

By popular demand, colors now ships with two types of usages!

The super nifty way

var colors = require('colors');

console.log('hello'.green); // outputs green text
console.log('i like cake and pies'.underline.red); // outputs red underlined text
console.log('inverse the color'.inverse); // inverses the color
console.log('OMG Rainbows!'.rainbow); // rainbow
console.log('Run the trap'.trap); // Drops the bass

or a slightly less nifty way which doesn't extend String.prototype

var colors = require('colors/safe');

console.log(colors.green('hello')); // outputs green text
console.log(colors.red.underline('i like cake and pies')); // outputs red underlined text
console.log(colors.inverse('inverse the color')); // inverses the color
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
console.log(colors.trap('Run the trap')); // Drops the bass

I prefer the first way. Some people seem to be afraid of extending String.prototype and prefer the second way.

If you are writing good code you will never have an issue with the first approach. If you really don't want to touch String.prototype, the second usage will not touch String native object.

Enabling/Disabling Colors

The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:

node myapp.js --no-color
node myapp.js --color=false

node myapp.js --color
node myapp.js --color=true
node myapp.js --color=always

FORCE_COLOR=1 node myapp.js

Or in code:

var colors = require('colors');
colors.enable();
colors.disable();

Console.log string substitution

var name = 'Marak';
console.log(colors.green('Hello %s'), name);
// outputs -> 'Hello Marak'

Custom themes

Using standard API

var colors = require('colors');

colors.setTheme({
  silly: 'rainbow',
  input: 'grey',
  verbose: 'cyan',
  prompt: 'grey',
  info: 'green',
  data: 'grey',
  help: 'cyan',
  warn: 'yellow',
  debug: 'blue',
  error: 'red'
});

// outputs red text
console.log("this is an error".error);

// outputs yellow text
console.log("this is a warning".warn);

Using string safe API

var colors = require('colors/safe');

// set single property
var error = colors.red;
error('this is red');

// set theme
colors.setTheme({
  silly: 'rainbow',
  input: 'grey',
  verbose: 'cyan',
  prompt: 'grey',
  info: 'green',
  data: 'grey',
  help: 'cyan',
  warn: 'yellow',
  debug: 'blue',
  error: 'red'
});

// outputs red text
console.log(colors.error("this is an error"));

// outputs yellow text
console.log(colors.warn("this is a warning"));

Combining Colors

var colors = require('colors');

colors.setTheme({
  custom: ['red', 'underline']
});

console.log('test'.custom);

Protip: There is a secret undocumented style in colors. If you find the style you can summon him.

You might also like...

get colors in your node.js console

colors.js This is a fork of Marak Squires' original colors.js project Please check out the roadmap for upcoming features and releases. Please open Iss

Jan 11, 2022

Get colors in your node.js console

Get colors in your node.js console

@colors/colors ("colors.js") Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback. get color and st

Dec 30, 2022

chakra-radix-colors provides radix-ui color palettes, automatic dark mode, and acessible colors to chakra-ui applications

chakra-radix-colors chakra-radix-colors provides radix-ui color palettes, automatic dark mode, and acessible colors to chakra-ui applications. About C

Dec 30, 2022

A PhotoShot Plugin to get material you colors easily.

material-you 可以快速获取符合 material-you 配色的 PhotoShop 插件。 参考自 Material Theme Builder 安装 初次安装 从 release 中下载压缩包并解压。打开 Photoshop ,运行 文件-脚本-浏览 ,选择安装包中的 安装脚本.js

Jun 17, 2022

Node Terminal Colors. Fast!

Tcol npm package to add colors to your terminal Installation # npm npm install tcol # pnpm pnpm install tcol Usage import { c } from "tcol"; console.

May 13, 2022

Personalize your GitHub experience by theming the site's accent colors.

Personalize your GitHub experience by theming the site's accent colors.

· Gitccentify · Personalize your GitHub experience by theming it to your own style! Disclaimer This project is not affiliated, associated, authorized,

Nov 30, 2022

A simple library to draw option menu or other popup inputs and layout on Node.js console.

A simple library to draw option menu or other popup inputs and layout on Node.js console.

console-gui-tools A simple library to draw option menu or other popup inputs and layout on Node.js console. console-gui-tools A simple Node.js library

Dec 24, 2022

A tiny script for generating attractive colors

A tiny script for generating attractive colors

Random Color A tiny script for generating attractive random colors. See the demo for an explanation and some samples. randomColor has been ported to C

Dec 24, 2022

Smarter defaults for colors on the web.

colors.css 3.0.0 Better default colors for the web. A collection of skin classes for faster prototyping and nicer looking sites. Stats 903 85 85 bytes

Jan 9, 2023

JavaScript Library for creating random pleasing colors and color schemes

#PleaseJS www.checkman.io/please Please.js is a polite companion that wants to help you make your projects beautiful. It uses HSV color space to creat

Dec 22, 2022

Extract prominent colors from an image. JS port of Android's Palette.

Extract prominent colors from an image. JS port of Android's Palette.

Vibrant.js Extract prominent colors from an image. Vibrant.js is a javascript port of the awesome Palette class in the Android support library. ⚠️ THI

Dec 25, 2022

⚗️ Zeplin extension that generates Swift snippets from colors, fonts, and layers

⚗️ Zeplin extension that generates Swift snippets from colors, fonts, and layers

Zeplin extension that generates Swift snippets from colors, fonts and layers. Features 🖍 Color pallette for iOS Example import UIKit extension UICol

May 29, 2022

Generate colors based on a desired contrast ratio

Generate colors based on a desired contrast ratio

Generate colors based on a desired contrast ratio

Jan 3, 2023

🎨 A simple library for extracting dominant colors from images.

🎨 A simple library for extracting dominant colors from images.

A dead simple, zero-dependency, promise-based javascript library for extracting the dominant color(s) from an image (in the browser). 👉 Version 2 was

Jan 4, 2023

👨🏼‍🎨 It is a virtual blackboard, where you can make 🖌 drawings through 🖱 the mouse. You have the option to choose 🎨 colors and line thickness.

👨🏼‍🎨 It is a virtual blackboard, where you can make 🖌 drawings through 🖱 the mouse. You have the option to choose 🎨 colors and line thickness.

👨🏼‍🎨 Lets Draw 🎨 ÍNDICE 1. Lets-Draw 2. Realization of the Project 3. Technologies used 4. Authors 1. Lets-Draw 👨🏼‍🎨 It is a virtual blackboard

Mar 7, 2022

A pleasing darker theme made mostly with complementary purple and blue colors, occasionally with a touch of pink or red.

A pleasing darker theme made mostly with complementary purple and blue colors, occasionally with a touch of pink or red.

Nebula Float away in space with a beautiful blurple oriented color theme. DISCLAIMER: ⚠️ This theme is not as high contrast as other themes. A pleasin

Nov 23, 2022

fix out-of-memory actions at colors@^1.4.1

What's it for? colors@^1.4.1 has action of out-of-memory: https://github.com/Marak/colors.js/commit/5d2d242f656103ac38086d6b26433a09f1c38c75. https://

Jan 11, 2022

Construct ANSI colors strings from object descriptors.

ansi-construct Construct ANSI colors strings from object descriptors. Usage import { ansi } from 'ansi-construct' const item = ansi({ text: 'foo', co

Sep 8, 2022
Owner
Josh
Josh
Get colors in your node.js console

@colors/colors ("colors.js") Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback. get color and st

David Hyde 89 Dec 30, 2022
Node Terminal Colors. Fast!

Tcol npm package to add colors to your terminal Installation # npm npm install tcol # pnpm pnpm install tcol Usage import { c } from "tcol"; console.

Posandu 4 May 13, 2022
A tiny script for generating attractive colors

Random Color A tiny script for generating attractive random colors. See the demo for an explanation and some samples. randomColor has been ported to C

David Merfield 5.9k Dec 24, 2022
Smarter defaults for colors on the web.

colors.css 3.0.0 Better default colors for the web. A collection of skin classes for faster prototyping and nicer looking sites. Stats 903 85 85 bytes

murmurs 9.2k Jan 9, 2023
JavaScript Library for creating random pleasing colors and color schemes

#PleaseJS www.checkman.io/please Please.js is a polite companion that wants to help you make your projects beautiful. It uses HSV color space to creat

Jordan Checkman 2.3k Dec 22, 2022
Extract prominent colors from an image. JS port of Android's Palette.

Vibrant.js Extract prominent colors from an image. Vibrant.js is a javascript port of the awesome Palette class in the Android support library. ⚠️ THI

Jari Zwarts 4.6k Dec 25, 2022
Generate colors based on a desired contrast ratio

Generate colors based on a desired contrast ratio

Adobe, Inc. 1.4k Jan 3, 2023
A simple Discord bot that will listen for HEX, RGB(a), and HSL(a) colors in a message, and provide a small image of that color.

Pigment For the teams of designers and developers out there - Pigment will listen for messages containing a HEX, RGB(a), or HSL(a) color, and provide

Conrad Crawford 17 Dec 8, 2022
Colormath.js - a color conversion and color manipulation library written in typescript for Node.js, Deno and Browser

Colormath.js - a color conversion and color manipulation library written in typescript for Node.js, Deno and Browser

TheSudarsanDev 8 Feb 8, 2022
Create your own complete Web color system fast and easy!

Simpler Color Create your own complete Web color system fast and easy, from as little as one base color! Color is at the heart of every UI design syst

Arnel Enero 278 Dec 20, 2022