current position:Home>Charm - artifact to beautify node output

Charm - artifact to beautify node output

2021-08-27 04:47:27 MrXu_

This is a beautification console.log Output package . It is very convenient to output all kinds of beautiful faces log. Then the next issue is :inquirer - Command line interactive artifact

If you don't like reading words, you can watch B Station video version CHALK - beautify node Output artifact

Basic usage

const chalk = require('chalk');

//  Output  log  To blue 
console.log(chalk.blue('Hello world!'));
 Copy code 

thickness 、 Delete line, etc

The output can have the same font color as the document 、 The background color 、 thickness 、 Underline

log(chalk.blue(' Blue '));

log(chalk.bold(' In bold '));

log(chalk.bgRed(' The background turns red '));

log(chalk.underline(' Underline '));

log(chalk.italic(' Italics '));
 Copy code 

call chaining

But there is often a word that is blue + bold + Underline this situation ,chalk It also provides a simple way to use : call chaining

log(chalk.blue.bold.bgRed.underline(` Blue bold , Red background , Underlined `))
 Copy code 

A line of multiple styles

Then go on to the next line. The output may need to be bold in some places , Some don't

//  The way 1, You can nest more than one 
log(' I am a ' + chalk.blue(' Blue ') + chalk.bold(' In bold ') + ' A line of text ')
log(chalk` I am a ${chalk.blue(' Blue ')}${chalk.bold(' In bold ')} A line of text ,chalk.red.bold(' Blue bold ')`)

//  The way 2,  Ways to recommend 
log(chalk` I am a {blue  Blue }{bold  In bold } A line of text ,{red.bold ${' Red '} In bold },{green.bold  I also support multiple attributes }`)
 Copy code 

Basic colors | rgb | hex | hsl

  1. The basic colors supported by itself are 7 Kind of :

black (black) | red (red)) | green (green) | yellow (yellow)) | blue (blue) | magenta (magenta) | Turquoise (cyan) | white (white),

  1. Add... To the basic color Bright There will be 7 A bright color , among blackBright There is an alias for gray、grey
  2. The background is the same as above :bgRed,bgRedBright

If you use red,blue, When you are familiar with setting colors, you can only use ten kinds at most , I want more :

log(chalk.rgb(123, 45, 67).bold(' My color is rgb(123, 45, 67)  typeface '))
log(chalk.bold.hex('#DEADED')(' My color is #DEADED typeface '))
log(chalk.hsl(215, 100, 60)(' My color is  hsl("215 100% 60%")  typeface '))
log(chalk.keyword('orange')(' orange '))//  Can receive some color keywords , I don't know how the key words come from ...

log(chalk.bgRgb(123, 45, 67).bold(' My background color is rgb(123, 45, 67)  typeface '))
log(chalk.bold.bgHex('#DEADED')(' My background color is #DEADED typeface '))
log(chalk.bgHsl(215, 100, 60)(' My background color is  hsl("215 100% 60%")  typeface '))
log(chalk.bgKeyword('orange')(' Orange background '))//  Can receive some color keywords , I don't know how the key words come from ...
 Copy code 

other

He also has many wonderful attributes :

//  What's the use of not understanding 
log(chalk.dim(' The forest , I didn't find any special circumstances '))

//  Invert the background color and font color 
log(chalk.inverse(' The default background color is black , The words are white . After using it, it becomes a white background , Black word '))

//  Clearly printed the text , But hidden and invisible 
log(chalk.hidden(' Can't see me, can't see me '))
 Copy code 

copyright notice
author[MrXu_],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210827044724089h.html

Random recommended