1.4.0 • Published 5 years ago

colors v1.4.0

Weekly downloads
22,895,699
License
MIT
Repository
github
Last release
5 years ago

colors.js

Build Status version dependencies devDependencies

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

background colors

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

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.

Disabling Colors

To disable colors you can pass the following arguments in the command line to your application:

node myapp.js --no-color

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.

cli-tablejasmine-spec-reporter@webcoda/generator-boilerplatev-webpack@webappm/pwa-icons2023_march_madness_championship_mens_hd_live_streamwatch_miami-open-2023-live-streaming_coveragewatch_miami_open_2023_live_streamingwatchlive-miami-open-2023-live-broadcast-on-tv-02-apr@adr-express-ts/cliwatch-2023-march-madness-championship-mens-hd-live-streamwatch-uconn-vs-san-diego-state-2023-hd-live-freewordlesystemwatch-miami-open-livefxh-x2j@siourdas-vasilis/deploytos3emd-cli@allview-cli/core@bsolution/bsolution-dev-utils@bsolution/cli@azurerodrigo/react-native-monorepo-icon-splash@liongard/roarcli@shzware-framework/api@strive-cli/cli@snapps/core@mxw/devkit@nerwin/common@jbroutier/csv-validator@jdic/comminder@knzn/cli@knzn/command@vc-cli-dev/core@vic-cli-test/core@stoked-cenv/cenv-ui@zml-lerna-test/command@zml-lerna-test/corealienvaultotxacm-sftp-deploy-plguinbe-test-clibestpay-buildbestdeal.api.unit.test.clibinanceapibotbitev.io@btffamily/checkaam@btffamily/conpmon@btffamily/cordless@btffamily/fuel@btffamily/realhomes@btffamily/station@btffamily/tmaapp@btffamily/tmat@btffamily/union@btffamily/xpcommon@compusoluciones/autistic@cli-zx-test/core@diegoolavarria/orion-js-cli@dong-cli/command@dong-cli/core@def-builder/core@hazymoon-cli-dev/corecreate-sb-mfecypress-runnerd0r-os-moduled0r-rand-colorcreate-discordbot-appcolorized-logsdocker-stack-clidiscord-corda@ckenx/cli@lpecom/commonxams-nodejs@saasxx/ext-scripts@sooha/cli@harvestr-api/cli@haoyongsong/palife-act-cli@izidan/express-italvarocabreradam-custom-lograinbow-logcz-ppmoney-changelogbrowser-console-loggerdaily-scriptshostnamesjuniorfigletcra-template-mern-cra-template@qwenny/corewebprojectmobiweb-cookiecutter@andresmorelos/dev-cliprettier-stageddora-mockmike-clipaychat-backendplexustoolsuni-toolkit@kafelix496/promptps5-availability@arthureic/better-loggermm-soa-cligreet_agist-manage@cyber-start/create-cyber-docs
1.4.2

3 years ago

1.4.1

3 years ago

1.4.44-liberty-2

3 years ago

1.4.0

5 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.2.0-rc0

7 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.6.2

11 years ago

0.6.1

11 years ago

0.6.0-1

13 years ago

0.6.0

13 years ago

0.5.1

13 years ago

0.5.0

14 years ago

0.3.0

14 years ago