Installations
npm install supports-color
Score
99.4
Supply Chain
95.9
Quality
78.3
Maintenance
100
Vulnerability
100
License
Developer
chalk
Developer Guide
Module System
ESM
Min. Node Version
>=12
Typescript Support
Yes
Node Version
16.20.0
NPM Version
9.2.0
Statistics
349 Stars
192 Commits
85 Forks
14 Watching
2 Branches
35 Contributors
Updated on 26 Nov 2024
Bundle Size
2.18 kB
Minified
1.12 kB
Minified + Gzipped
Languages
JavaScript (97.08%)
TypeScript (2.92%)
Total Downloads
Cumulative downloads
Total Downloads
52,307,807,934
Last day
-8.7%
59,417,866
Compared to previous day
Last week
-2%
345,337,671
Compared to previous week
Last month
3.6%
1,470,204,788
Compared to previous month
Last year
17.2%
16,193,868,691
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
5
supports-color
Detect whether a terminal supports color
Install
1npm install supports-color
Usage
1import supportsColor from 'supports-color'; 2 3if (supportsColor.stdout) { 4 console.log('Terminal stdout supports color'); 5} 6 7if (supportsColor.stdout.has256) { 8 console.log('Terminal stdout supports 256 colors'); 9} 10 11if (supportsColor.stderr.has16m) { 12 console.log('Terminal stderr supports 16 million colors (truecolor)'); 13}
API
Returns an object
with a stdout
and stderr
property for testing either streams. Each property is an Object
, or false
if color is not supported.
The stdout
/stderr
objects specifies a level of support for color through a .level
property and a corresponding flag:
.level = 1
and.hasBasic = true
: Basic color support (16 colors).level = 2
and.has256 = true
: 256 color support.level = 3
and.has16m = true
: Truecolor support (16 million colors)
Custom instance
The package also exposes the named export createSupportColor
function that takes an arbitrary write stream (for example, process.stdout
) and an optional options object to (re-)evaluate color support for an arbitrary stream.
1import {createSupportsColor} from 'supports-color'; 2 3const stdoutSupportsColor = createSupportsColor(process.stdout); 4 5if (stdoutSupportsColor) { 6 console.log('Terminal stdout supports color'); 7} 8 9// `stdoutSupportsColor` is the same as `supportsColor.stdout`
The options object supports a single boolean property sniffFlags
. By default it is true
, which instructs the detection to sniff process.argv
for the multitude of --color
flags (see Info below). If false
, then process.argv
is not considered when determining color support.
Info
It obeys the --color
and --no-color
CLI flags.
For situations where using --color
is not possible, use the environment variable FORCE_COLOR=1
(level 1), FORCE_COLOR=2
(level 2), or FORCE_COLOR=3
(level 3) to forcefully enable color, or FORCE_COLOR=0
to forcefully disable. The use of FORCE_COLOR
overrides all other color support checks.
Explicit 256/Truecolor mode can be enabled using the --color=256
and --color=16m
flags, respectively.
Related
- supports-color-cli - CLI for this module
- chalk - Terminal string styling done right
- is-unicode-supported - Detect whether the terminal supports Unicode
- is-interactive - Check if stdout or stderr is interactive
Maintainers
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/chalk/supports-color/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/chalk/supports-color/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:21
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
4.4
/10
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 MoreOther packages similar to supports-color
@types/supports-color
TypeScript definitions for supports-color
support-color
Detect whether a terminal supports color
@chalkbox/supports-color
Detect whether a terminal supports color
@mnrendra/chalk-supports-color
Refactored supports-color code to support both CommonJS (CJS) and ES Modules (ESM) with mixed exports.