Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.17 KB

learn-colors-npm.md

File metadata and controls

51 lines (39 loc) · 1.17 KB

Learn Colors

Get colors on screen on nodejs

Drawbacks of colors?

  • Typescript support is not provided by library owners.
  • Chalkjs is much more widely used so do use that! My guide to chalkjs: Click here
require('colors')

const str = 'Hello this is Sahil!'
const object = JSON.stringify({a: 10, b: 20}, null, 2)

console.log(str.red)
console.log(str.red.bold)
console.log(str.bold.red) // Order doesn't matter.
console.log(str.bold.red.bgRed) // Order doesn't matter.
console.log(str.blue.italic.bold.bgYellow)
console.log(object.black.magenta.bgWhite)
console.log(object.white.bgYellow)

BUT, you should create some theme:

// FILE: colorConfig.js
const colors = require('colors')

colors.setTheme({
	info: 'bgGreen',
	help: 'cyan',
	warn: 'yellow',
	success: 'bgBlue',
	error: 'red',
	m: 'magenta', // myString.m.b Fox chaining.: for chaining.
	b: 'bold',
	bm: ['bold', 'magenta'],
	by: ['bold', 'yellow'],
})

// Usage: Simply put below line in your server file:
// require('./colorsConfig')


myString.m.b // works good!
myString.mb // works good!