The fastest Node.js library for formatting terminal text with ANSI colors~!. Use when: Super lightweight & performant; Supports nested & chained colors; Conditional color support. NOT for: production runtime logic; replacing static type checking.
The fastest Node.js library for formatting terminal text with ANSI colors~!. > Note: Both kleur and kleur/colors share the same detection logic.
npm install kleur
$ npm install --save kleur
import kleur from 'kleur';
// basic usage
kleur.red('red text');
// chained methods
kleur.blue().bold().underline('howdy partner');
// nested methods
kleur.bold(`${ white().bgRed('[ERROR]') } ${ kleur.red().italic('Something happened')}`);
const { bold, green } = require('kleur');
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'));
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'));
import kleur from 'kleur';
// manually disable
kleur.enabled = false;
// or use another library to detect support
kleur.enabled = require('color-support').level > 0;
console.log(kleur.red('I will only be colored red if the terminal supports colors'));
See the official documentation for configuration options and advanced settings.