As of v3.0 the Chalk-style syntax (magical getter) is no longer used.
If you need or require that syntax, consider using ansi-colors, which maintains chalk parity.
console.log(bold().red('this is a bold red message'));console.log(bold().italic('this is a bold italicized message'));console.log(bold().yellow().bgRed().italic('this is a bold yellow italicized message'));console.log(green().bold().underline('this is a bold green underlined message'));
Nested Methods
const { yellow,red,cyan } =require('kleur');console.log(yellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`));console.log(yellow('foo '+red().bold('red') +' bar '+cyan('cyan') +' baz'));
Conditional Support
Toggle color support as needed; kleur includes simple auto-detection which may not cover all cases.
constkleur=require('kleur');// manually disablekleur.enabled =false;// or use another library to detect supportkleur.enabled =require('color-support').level;console.log(kleur.red('I will only be colored red if the terminal supports colors'));
API
Any kleur method returns a String when invoked with input; otherwise chaining is expected.
It's up to the developer to pass the output to destinations like console.log, process.stdout.write, etc.
The methods below are grouped by type for legibility purposes only. They each can be chained or nested with one another.
Colors:
black — red — green — yellow — blue — magenta — cyan — white — gray — grey