1.6.0 • Published 1 year ago

@colors/colors v1.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@colors/colors ("colors.js")

Build Status version

Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback.

get color and style in your node.js console

Demo

Installation

npm install @colors/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/colors now ships with two types of usages!

The super nifty way

var colors = require('@colors/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/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');
colors.enable();
colors.disable();

Console.log string substitution

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

Custom themes

Using standard API

var colors = require('@colors/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/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');

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.

winstonlogformkarmatest-new-r-sdktest-t-r-s@schwabyio/xrunner@unloc-dev/raydium-sdk@unloc-dev/unloc-sdk@everything-registry/sub-chunk-189magicmirror-rebuildtailwindcss-classnameswinston-no-fswinston-logger-nodewinston61299winstonnewwa-spwnwrangler-secretspatial-clisdg-clirsc-loggervitaqai-apifastproxyhttpharpmad-logsmpj-cligrumpy-aiikea-availability-checkergraphql-auto-querygo-git-itnodelight-jsprom_tcrprompt_ngochienpromptprm-winstonprisma-accelerate-localpush-all-in-oneperiodo-clinode-ssh-manager-clineoxr-botrailflow-zephyrraydium-sdk-mjsrumrunrooseveltroosevelt-loggersla-tstitano@altronix/device@appium/support@appium/test-support@appium/base-driver@appium/doctor@andersonsmed/create-js-lib@aibulat/sendeml@aibulat/watch-dir-count@aibulat/fs@badisi/latest-version@badisi/wdio-harness@badisi/xbw@begin/deploy@begin/cli@cliffhanger-js/cliffhanger@diegab/cliffhanger@diegab/swiftwebpack-browser-extension-common-errorswebpack-mkcert-pluginwebpack-run-chrome-extensionwebpack-run-edge-extensionwebpack-run-firefox-addonverdure-utils-pm2-tools@ectomigo/ectomigo@greysmpich/markdown-links@hug/ngx-schematics-utilities@finviet-jsrpt/jsrpt-core@gpt-tag/openai@infinitebrahmanuniverse/nolb-_col@liquidapps/zeus-cmd@livepreso/content-upgrade@livepreso/create-deck@livepreso/create-livepreso-deck@loxo/cli@loxo/core@loxo/studio@libv/cli@libv/core@libv/studio@nguyenbavinh-decathlon/cypress-parallel@mrblock7777/aws-s3-purge@extension-create/cli@extension-create/create@extension-create/develop@enhance/cli@enhance/enhance-plugin-performance-budget@fabric-foundation/sdk@makerx/node-winston@jsreport/jsreport-core@schwabyio/xrun@rf-logger/logger@rhobweb/console-logger@team_seki/winston-logger@orbit-online/logform
1.6.0

1 year ago

1.5.0

3 years ago

1.4.0

3 years ago