github
基本格式
chalk.[.<style>...](string)
chalk[樣式關(guān)鍵字_1][樣式關(guān)鍵字_2](輸出內(nèi)容)
例子
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="javascript" contenteditable="true" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">const chalk = reuquire("chalk")
const log = console.log
?
// 顏色字體
log( chalk.red("紅色") )
?
// 背景色
log( chalk.bgBlue("藍(lán)色背景") )
?
// 樣式字體
log( chalk.bold("加粗") )
?
// 多參數(shù)
log( chalk.blue("name", "age", "job") )
?
// ES6 多行文本
log(
// 多行文本將保留縮進(jìn)格式
chalk.blue(`
name: Rogan
age: ${25}
job: ${ 'IT' }
`)
)
?
?
// 其他顏色設(shè)置方式
log(chalk.keyword("orange")(' keyword ')) // 關(guān)鍵字
log(chalk.rgb(100, 100, 100)(' rgb ')) // rgb
log(chalk.hex('#ffffff')(' hex ')) // hex
?
?
?
// 樣式組合
log(` colors: ${chalk.blue('blue')}, ${chalk.red('red')} `) // 拼接
?
log(chalk.blue.bold("Title")) // 鏈?zhǔn)浇M合
?
log( chalk.bgYellow(` error: ${chalk.red(" chalk is undefined ")} `) ) // 嵌套
?
?
?
// 自定義組合
const error = chalk.bgRed;
const warning = chalk.yellow.bold;</pre>
樣式api
reset
- 樣式重置bold
- 加粗dim
- 淺高亮italic
- 斜體underline
- 下劃線inverse
- 反轉(zhuǎn)前景和背景色hidden
- 隱藏內(nèi)容strikethrough
- 刪除線visible
- 顯示chalk level > 0 的內(nèi)容
前景色關(guān)鍵字(非全支持)
black
red
green
yellow
blue
magenta
cyan
white
blackBright
(alias:gray
,grey
)redBright
greenBright
yellowBright
blueBright
magentaBright
cyanBright
whiteBright
背景色關(guān)鍵字(非全支持)
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
bgBlackBright
(alias:bgGray
,bgGrey
)bgRedBright
bgGreenBright
bgYellowBright
bgBlueBright
bgMagentaBright
bgCyanBright
bgWhiteBright
取色模式
rgb
- Example:chalk.rgb(255, 136, 0).bold('Orange!')
hex
- Example:chalk.hex('#FF8800').bold('Orange!')
keyword
(CSS keywords) - Example:chalk.keyword('orange').bold('Orange!')
hsl
- Example:chalk.hsl(32, 100, 50).bold('Orange!')
hsv
- Example:chalk.hsv(32, 100, 100).bold('Orange!')
hwb
- Example:chalk.hwb(32, 0, 50).bold('Orange!')
ansi16
ansi256