Gathering detailed insights and metrics for kleur
Gathering detailed insights and metrics for kleur
Gathering detailed insights and metrics for kleur
Gathering detailed insights and metrics for kleur
The fastest Node.js library for formatting terminal text with ANSI colors~!
npm install kleur
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.8
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (88.88%)
Shell (11.12%)
Total Downloads
5,397,414,836
Last Day
2,130,299
Last Week
36,541,639
Last Month
158,167,546
Last Year
1,581,514,147
MIT License
1,659 Stars
125 Commits
47 Forks
8 Watchers
2 Branches
16 Contributors
Updated on Jul 02, 2025
Minified
Minified + Gzipped
Latest Version
4.1.5
Package Id
kleur@4.1.5
Unpacked Size
19.78 kB
Size
6.01 kB
File Count
9
NPM Version
8.11.0
Node Version
18.3.0
Cumulative downloads
Total Downloads
Last Day
-10.4%
2,130,299
Compared to previous day
Last Week
-8.7%
36,541,639
Compared to previous week
Last Month
4.8%
158,167,546
Compared to previous month
Last Year
21.6%
1,581,514,147
Compared to previous year
String.prototype
modificationsAs of v3.0
the Chalk-style syntax (magical getter) is no longer used.
Please visit History for migration paths supporting that syntax.
$ npm install --save kleur
1import kleur from 'kleur'; 2 3// basic usage 4kleur.red('red text'); 5 6// chained methods 7kleur.blue().bold().underline('howdy partner'); 8 9// nested methods 10kleur.bold(`${ white().bgRed('[ERROR]') } ${ kleur.red().italic('Something happened')}`);
1const { bold, green } = require('kleur'); 2 3console.log(bold().red('this is a bold red message')); 4console.log(bold().italic('this is a bold italicized message')); 5console.log(bold().yellow().bgRed().italic('this is a bold yellow italicized message')); 6console.log(green().bold().underline('this is a bold green underlined message'));
1const { yellow, red, cyan } = require('kleur'); 2 3console.log(yellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`)); 4console.log(yellow('foo ' + red().bold('red') + ' bar ' + cyan('cyan') + ' baz'));
Toggle color support as needed; kleur
includes simple auto-detection which may not cover all cases.
Note: Both
kleur
andkleur/colors
share the same detection logic.
1import kleur from 'kleur'; 2 3// manually disable 4kleur.enabled = false; 5 6// or use another library to detect support 7kleur.enabled = require('color-support').level > 0; 8 9console.log(kleur.red('I will only be colored red if the terminal supports colors'));
Important:
Colors will be disabled automatically in non TTY contexts. For example, spawning another process or piping output into another process will disable colorization automatically. To force colors in your piped output, you may do so with theFORCE_COLOR=1
environment variable:
1$ node app.js #=> COLORS 2$ node app.js > log.txt #=> NO COLORS 3$ FORCE_COLOR=1 node app.js > log.txt #=> COLORS 4$ FORCE_COLOR=0 node app.js > log.txt #=> NO COLORS
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
Backgrounds:
bgBlack — bgRed — bgGreen — bgYellow — bgBlue — bgMagenta — bgCyan — bgWhite
Modifiers:
reset — bold — dim — italic* — underline — inverse — hidden — strikethrough*
* Not widely supported
When you only need a few colors, it doesn't make sense to import all of kleur
because, as small as it is, kleur
is not treeshakeable, and so most of its code will be doing nothing. In order to fix this, you can import from the kleur/colors
submodule which fully supports tree-shaking.
The caveat with this approach is that color functions are not chainable~!
Each function receives and colorizes its input. You may combine colors, backgrounds, and modifiers by nesting function calls within other functions.
1// or: import * as kleur from 'kleur/colors'; 2import { red, underline, bgWhite } from 'kleur/colors'; 3 4red('red text'); 5//~> kleur.red('red text'); 6 7underline(red('red underlined text')); 8//~> kleur.underline().red('red underlined text'); 9 10bgWhite(underline(red('red underlined text w/ white background'))); 11//~> kleur.bgWhite().underline().red('red underlined text w/ white background');
Note: All the same colors, backgrounds, and modifiers are available.
Conditional Support
The kleur/colors
submodule also allows you to toggle color support, as needed.
It includes the same initial assumptions as kleur
, in an attempt to have colors enabled by default.
Unlike kleur
, this setting exists as kleur.$.enabled
instead of kleur.enabled
:
1import * as kleur from 'kleur/colors'; 2// or: import { $, red } from 'kleur/colors'; 3 4// manually disabled 5kleur.$.enabled = false; 6 7// or use another library to detect support 8kleur.$.enabled = require('color-support').level > 0; 9 10console.log(red('I will only be colored red if the terminal supports colors'));
Using Node v10.13.0
chalk :: 5.303ms
kleur :: 0.488ms
kleur/colors :: 0.369ms
ansi-colors :: 1.504ms
# All Colors
ansi-colors x 177,625 ops/sec ±1.47% (92 runs sampled)
chalk x 611,907 ops/sec ±0.20% (92 runs sampled)
kleur x 742,509 ops/sec ±1.47% (93 runs sampled)
kleur/colors x 881,742 ops/sec ±0.19% (98 runs sampled)
# Stacked colors
ansi-colors x 23,331 ops/sec ±1.81% (94 runs sampled)
chalk x 337,178 ops/sec ±0.20% (98 runs sampled)
kleur x 78,299 ops/sec ±1.01% (97 runs sampled)
kleur/colors x 104,431 ops/sec ±0.22% (97 runs sampled)
# Nested colors
ansi-colors x 67,181 ops/sec ±1.15% (92 runs sampled)
chalk x 116,361 ops/sec ±0.63% (94 runs sampled)
kleur x 139,514 ops/sec ±0.76% (95 runs sampled)
kleur/colors x 145,716 ops/sec ±0.97% (97 runs sampled)
This project originally forked ansi-colors
.
Beginning with kleur@3.0
, the Chalk-style syntax (magical getter) has been replaced with function calls per key:
1// Old: 2c.red.bold.underline('old'); 3 4// New: 5c.red().bold().underline('new');
As I work more with Rust, the newer syntax feels so much better & more natural!
If you prefer the old syntax, you may migrate to ansi-colors
or newer chalk
releases.
Versions below kleur@3.0
have been officially deprecated.
MIT © Luke Edwards
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Moreansi-colors
Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).
@poppinss/colors
A wrapper on top of kleur with ability to write test against the color functions
@kristoferbaxter/kleur
The fastest Node.js library for formatting terminal text with ANSI colors~!
kleur-template
🌈 Add color to your strings with templating