当前位置: 首页 > Web前端 > HTML5

【每天一包0030】粉笔

时间:2023-04-06 00:10:42 HTML5

【github地址:https://github.com/ABCDdouyae...】chalk美化了终端的字符串样式,可以简单使用如下constchalk=require('chalk');constlog=console.log;//使用log(chalk.blue('Hello')+'world'+chalk.red('!'))组合样式字符串和普通字符串;//使用链式方法调用多个APIlog(chalk.blue.bgRed.bold('Helloworld!'));//传入多个参数log(chalk.blue('Hello','World!','Foo','bar','biz','baz'));//APIapplicationlog(chalk.red('Hello',chalk.underline.bgBlue('world')+'!'));log(chalk.green('我是绿线'+chalk.blue.underline.bold('withabluesubstring')+'又变绿了!'));//支持反引号解析字符串log(`CPU:${chalk.red('90%')}RAM:${chalk.green('40%')}DISK:${chalk.yellow('70%')}`);letcpu={totalPercent:67};letram={used:40,total:100};letdisk={使用:130,总数:512}log(chalk`CPU:{red${cpu.totalPercent}%}RAM:{green${ram.used/ram.total*100}%}DISK:{rgb(255,131,0)${disk.used/disk.total*100}%}`);//支持多种颜色写法log(chalk.keyword('orange')('Yayfororangecoloredtext!'));log(粉笔.rgb(123,45,67).underline('带下划线的红色'));log(chalk.hex('#DEADED').bold('大胆的灰色!'));您可以定义自己的主题constchalk=require('chalk');constlog=console.log;consterror=chalk.bold.red;constwarning=chalk.keyword('orange');log(error('Error!'));log(warning('Warning!'));使用console.log字符串替换constchalk=require('chalk');constlog=console.log;constname='Sindre';console.log(chalk.green('Hello%s'),name);APIchalk.enable:是否开启chalkconstlog=console.log;constctx1=newchalk.constructor({enabled:true});log(ctx1.red('HelloWorld'));constctx2=newchalk.constructor({enabled:false});log(ctx2.red('HelloWorld'));chalk.level:设置chalk支持的颜色constctx=newchalk.constructor({level:0});1.所有颜色disabled2.Basiccolorsupport(16色)3.256色支持4.Truecolor支持(1600万色)chalk.supportsColor:检测终端支持的颜色值格式,直接调用包supports-color(chalk.supportsColor)的stdoutlog//{level:2,hasBasic:true,has256:true,has16m:false}支持的样式和颜色样式resetbolddimitalic(Notwidelysupported)underlineinversehiddenstrikethrough(Notwidelysupported)visible(Textisemittedonlyifenabled)颜色blackredgreenyellowblue(OnWindowsthebrightversionisusedsincenormalblueisillegible)magentacyanwhitegray("brightblack")redBrightgreenBrightyellowBrightblueBrightmagentaBrightcyanBrightwhiteBright背景色bgBlackbgRedbgGreenbgYellowbgBluebgMagentabgCyanbgWhitebgBlackBrightbgRedBrightbgGreenBrightbgYellowBrightbgBlueBrightbgMagentaBrightbgCyanBrightbgWhiteBright颜色格式rgb-示例:chalk.rgb(255,136,0).bold('Orange!')hex-示例:chalk.hex('#FF8800').bold('Orange!')keyword(CSS关键字)-示例:chalk.keyword('orange').bold('Orange!')hsl-示例:chalk.hsl(32,100,50).bold('Orange!')hsv-示例:chalk.hsv(32,100,100).bold('Orange!')hwb-示例:chalk.hwb(32,0,50).bold('Orange!')ansi16ansi256