colors.js - get colors in your node.js console

Related tags

Color colors.js
Overview

colors.js

CodeFactor Codacy Badge

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

npm install 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

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

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

NpxCard - Write 'npx hariom' in your console.

npx Card This is my NPX card for connecting with me in console or terminal. ❣️ Just Hit npx hariom Will see you in console in just a minute 👀 Importa

Jul 26, 2022

Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer console in your browser

Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer console in your browser

ColorConsole NPM Package Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer consol

Sep 19, 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

Console.log with style.

Log Console.log with style Demo Features Safely call log (instead of console.log) in any browser. Use markdown syntax for quick formatting: italic — l

Dec 30, 2022

Clear console logging for every browser

Clear console logging for every browser

Console.log wrapper Safe, clear console logging for every browser Log to the console — even legacy browsers without a console. Just pass any data to l

Sep 24, 2022

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods

loglevel Don't debug with logs alone - check out HTTP Toolkit: beautiful, powerful & open-source tools for building, testing & debugging HTTP(S) Minim

Jan 6, 2023

:seedling: Next-Gen AI-Assisted Isomorphic Application Engine for Embedded, Console, Mobile, Server and Desktop

lychee.js Mono Repository Important Notes to follow through Installation Quirks: The lycheejs-engine Repository needs to be installed to the path /opt

Dec 31, 2022

:white_square_button: WhatsApp chat from commandline/console/cli using GoogleChrome puppeteer

:white_square_button: WhatsApp chat from commandline/console/cli using GoogleChrome puppeteer

Whatspup Use Whatsapp from commandline/console/cli using GoogleChrome puppeteer! 😄 Features ✅ Send and receive messages ✅ Read Receipts ✅ Switch betw

Dec 1, 2022

A Discord bot Client Console Website

A Discord bot Client Console Website

Discord Bot Client Console A Discord bot Client Console Website made with html , css and js. And Easy Use and easy to run Setup ⚒ Import the Repo by t

Jan 6, 2023

In how many ways can you print in the console 50 times?

In how many ways can you print in the console 50 times I was asked at an interview how to print in the console "Hello World" 50 times in as few lines

Oct 4, 2021

Fill the boring catsalud covid vaccine form with a console command

vacunacovid-catsalud-autofullfill form Fill the boring catsalud covid vaccine form with a console command Manual use, pasting in the script in the con

Jul 27, 2021

A NodeJS Console Logger with superpowers

LogFlake LogFlake is a NodeJS console logger with superpowers. It has the same API as the usual Console but with beautified output, a message header w

Oct 9, 2022
Releases(1.0.2-ng)
  • 1.0.2-ng(Feb 1, 2022)

    What's Changed

    • Stable by @cronlabspl in https://github.com/labspl/colors-ng/pull/54
    • Ready to npm by @cronlabspl in https://github.com/labspl/colors-ng/pull/55

    Full Changelog: https://github.com/labspl/colors-ng/compare/1.0.1-ng...1.0.2-ng

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1-ng(Jan 20, 2022)

    What's Changed

    • Towards first stable release by @cronlabspl in https://github.com/labspl/colors.js/pull/21
    • Fix color.js lib by @cronlabspl in https://github.com/labspl/colors.js/pull/37
    • add action ( auto-release ) by @cronlabspl in https://github.com/labspl/colors.js/pull/40
    • add external lib as a dependency by @cronlabspl in https://github.com/labspl/colors.js/pull/42
    • remove calls for *-america ( #44 ) by @cronlabspl in https://github.com/labspl/colors.js/pull/45
    • new theme by @cronlabspl in https://github.com/labspl/colors.js/pull/47
    • Restyling by @cronlabspl in https://github.com/labspl/colors.js/pull/49
    • 1.0.1 by @cronlabspl in https://github.com/labspl/colors.js/pull/53

    Full Changelog: https://github.com/labspl/colors.js/compare/1.0-ng...1.0.1-ng

    Source code(tar.gz)
    Source code(zip)
  • 1.0-ng(Jan 16, 2022)

    What's Changed

    • Add a Codacy badge to README.md by @codacy-badger in https://github.com/labspl/colors.js/pull/2
    • Bring branch develop upto date by @cronlabspl in https://github.com/labspl/colors.js/pull/3
    • add basic CQ by @cronlabspl in https://github.com/labspl/colors.js/pull/5
    • Apply fixes from CodeFactor by @cronlabspl in https://github.com/labspl/colors.js/pull/8
    • Bump lodash from 4.17.11 to 4.17.21 by @dependabot in https://github.com/labspl/colors.js/pull/12
    • Bump js-yaml from 3.12.0 to 3.14.1 by @dependabot in https://github.com/labspl/colors.js/pull/11
    • Bump eslint-utils from 1.3.1 to 1.4.3 by @dependabot in https://github.com/labspl/colors.js/pull/10
    • Bump acorn from 6.0.4 to 6.4.2 by @dependabot in https://github.com/labspl/colors.js/pull/13
    • MIT >> GPLv3 by @cronlabspl in https://github.com/labspl/colors.js/pull/16
    • Add .circleci/config.yml by @cronlabspl in https://github.com/labspl/colors.js/pull/18
    • Apply fixes from CodeFactor by @codefactor-io in https://github.com/labspl/colors.js/pull/26
    • standard compliance by @cronlabspl in https://github.com/labspl/colors.js/pull/27
    • Apply fixes from CodeFactor by @codefactor-io in https://github.com/labspl/colors.js/pull/29

    New Contributors

    • @codacy-badger made their first contribution in https://github.com/labspl/colors.js/pull/2
    • @dependabot made their first contribution in https://github.com/labspl/colors.js/pull/12
    • @codefactor-io made their first contribution in https://github.com/labspl/colors.js/pull/26

    Full Changelog: https://github.com/labspl/colors.js/commits/1.0-ng

    Source code(tar.gz)
    Source code(zip)
Owner
cronlabspl
Medum-sized no-for-profit IT-lab in North-Central Poland
cronlabspl
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