Gathering detailed insights and metrics for ansi-styles
Gathering detailed insights and metrics for ansi-styles
Gathering detailed insights and metrics for ansi-styles
Gathering detailed insights and metrics for ansi-styles
ANSI escape codes for styling strings in the terminal
npm install ansi-styles
99.5
Supply Chain
99.5
Quality
78.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
423 Stars
113 Commits
73 Forks
13 Watching
2 Branches
18 Contributors
Updated on 16 Nov 2024
Minified
Minified + Gzipped
JavaScript (65.09%)
TypeScript (34.91%)
Cumulative downloads
Total Downloads
Last day
-8.4%
66,067,588
Compared to previous day
Last week
-2%
379,200,210
Compared to previous week
Last month
1.9%
1,638,608,067
Compared to previous month
Last year
29.5%
17,896,364,758
Compared to previous year
4
ANSI escape codes for styling strings in the terminal
You probably want the higher-level chalk module for styling your strings.
1npm install ansi-styles
1import styles from 'ansi-styles'; 2 3console.log(`${styles.green.open}Hello world!${styles.green.close}`); 4 5 6// Color conversion between 256/truecolor 7// NOTE: When converting from truecolor to 256 colors, the original color 8// may be degraded to fit the new color palette. This means terminals 9// that do not support 16 million colors will best-match the 10// original color. 11console.log(`${styles.color.ansi(styles.rgbToAnsi(199, 20, 250))}Hello World${styles.color.close}`) 12console.log(`${styles.color.ansi256(styles.rgbToAnsi256(199, 20, 250))}Hello World${styles.color.close}`) 13console.log(`${styles.color.ansi16m(...styles.hexToRgb('#abcdef'))}Hello World${styles.color.close}`)
open
and close
Each style has an open
and close
property.
modifierNames
, foregroundColorNames
, backgroundColorNames
, and colorNames
All supported style strings are exposed as an array of strings for convenience. colorNames
is the combination of foregroundColorNames
and backgroundColorNames
.
This can be useful if you need to validate input:
1import {modifierNames, foregroundColorNames} from 'ansi-styles'; 2 3console.log(modifierNames.includes('bold')); 4//=> true 5 6console.log(foregroundColorNames.includes('pink')); 7//=> false
reset
bold
dim
italic
(Not widely supported)underline
overline
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.inverse
hidden
strikethrough
(Not widely supported)black
red
green
yellow
blue
magenta
cyan
white
blackBright
(alias: gray
, grey
)redBright
greenBright
yellowBright
blueBright
magentaBright
cyanBright
whiteBright
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
bgBlackBright
(alias: bgGray
, bgGrey
)bgRedBright
bgGreenBright
bgYellowBright
bgBlueBright
bgMagentaBright
bgCyanBright
bgWhiteBright
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
styles.modifier
styles.color
styles.bgColor
1import styles from 'ansi-styles'; 2 3console.log(styles.color.green.open);
Raw escape codes (i.e. without the CSI escape prefix \u001B[
and render mode postfix m
) are available under styles.codes
, which returns a Map
with the open codes as keys and close codes as values.
1import styles from 'ansi-styles'; 2 3console.log(styles.codes.get(36)); 4//=> 39
ansi-styles
allows converting between various color formats and ANSI escapes, with support for 16, 256 and 16 million colors.
The following color spaces are supported:
rgb
hex
ansi256
ansi
To use these, call the associated conversion function with the intended output, for example:
1import styles from 'ansi-styles'; 2 3styles.color.ansi(styles.rgbToAnsi(100, 200, 15)); // RGB to 16 color ansi foreground code 4styles.bgColor.ansi(styles.hexToAnsi('#C0FFEE')); // HEX to 16 color ansi foreground code 5 6styles.color.ansi256(styles.rgbToAnsi256(100, 200, 15)); // RGB to 256 color ansi foreground code 7styles.bgColor.ansi256(styles.hexToAnsi256('#C0FFEE')); // HEX to 256 color ansi foreground code 8 9styles.color.ansi16m(100, 200, 15); // RGB to 16 million color foreground code 10styles.bgColor.ansi16m(...styles.hexToRgb('#C0FFEE')); // Hex (RGB) to 16 million color foreground code
Available as part of the Tidelift Subscription.
The maintainers of ansi-styles
and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
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 2024-11-25
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 More