Installations
npm install @visulima/is-ansi-color-supported
Developer Guide
Typescript
Yes
Module System
ESM, UMD
Min. Node Version
>=18.* <=23.*
Node Version
18.20.5
NPM Version
9.6.7
Releases
@visulima/cerebro@1.1.38
Published on 29 Jan 2025
@visulima/api-platform@3.0.37
Published on 29 Jan 2025
@visulima/jsdoc-open-api@2.0.75
Published on 29 Jan 2025
@visulima/find-cache-dir@1.0.26
Published on 29 Jan 2025
@visulima/tsconfig@1.1.13
Published on 29 Jan 2025
@visulima/package@3.5.1
Published on 29 Jan 2025
Contributors
Languages
TypeScript (91.98%)
JavaScript (5.76%)
MDX (1.63%)
Handlebars (0.38%)
CSS (0.13%)
Shell (0.12%)
Developer
Download Statistics
Total Downloads
27,741
Last Day
374
Last Week
1,133
Last Month
5,586
Last Year
27,673
GitHub Statistics
13 Stars
2,429 Commits
3 Forks
2 Watching
18 Branches
2 Contributors
Bundle Size
842.00 B
Minified
434.00 B
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
2.2.10
Package Id
@visulima/is-ansi-color-supported@2.2.10
Unpacked Size
42.46 kB
Size
11.87 kB
File Count
17
NPM Version
9.6.7
Node Version
18.20.5
Publised On
12 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
27,741
Last day
379.5%
374
Compared to previous day
Last week
-12.5%
1,133
Compared to previous week
Last month
75.7%
5,586
Compared to previous month
Last year
40,595.6%
27,673
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
28
Visulima is-ansi-color-supported
Detect whether a terminal (stdout/stderr), browser or edge supports (next.js) ansi colors.
Daniel Bannert's open source work is supported by the community on GitHub Sponsors
Install
1npm install @visulima/is-ansi-color-supported
1yarn add @visulima/is-ansi-color-supported
1pnpm add @visulima/is-ansi-color-supported
Usage
1import { isStdoutColorSupported, isStderrColorSupported } from "@visulima/is-ansi-color-supported"; 2 3/** 4 * Levels: 5 * - `0` - All colors disabled. 6 * - `1` - Basic 16 colors support. 7 * - `2` - ANSI 256 colors support. 8 * - `3` - Truecolor 16 million colors support. 9 */ 10console.log(isStdoutColorSupported()); // 3 11 12console.log(isStderrColorSupported()); // 3
Color support
Ansis automatically detects the supported color space:
- TrueColor
- ANSI 256 colors
- ANSI 16 colors
- black & white (no color)
There is no standard way to detect which color space is supported.
The most common way to detect color support is to check the TERM
and COLORTERM
environment variables.
CI systems can be detected by checking for the existence of the CI
and other specifically environment variables.
Combine that with the knowledge about which operating system the program is running on, and we have a decent enough way to detect colors.
Terminal | ANSI 16 colors | ANSI 256 colors | True Color | env. TERM | env. COLORTERM | Specifically ENV variables |
---|---|---|---|---|---|---|
Azure CI | ✅ | ❌ | ❌ | dumb | TF_BUILD AGENT_NAME | |
GitHub CI | ✅ | ✅ | ✅ | dumb | CI GITHUB_ACTIONS | |
GitTea CI | ✅ | ✅ | ✅ | dumb | CI GITEA_ACTIONS | |
GitLab CI | ✅ | ❌ | ❌ | dumb | CI GITLAB_CI | |
Travis CI | ✅ | ❌ | ❌ | dumb | TRAVIS | |
PM2 not isTTY | ✅1 | ✅1 | ✅1 | dumb | PM2_HOME pm_id | |
JetBrains TeamCity >=2020.1.1 | ✅ | ✅ | ❌ | TEAMCITY_VERSION | ||
JetBrains IDEA | ✅ | ✅ | ✅ | xterm-256color | TERMINAL_EMULATOR='JetBrains-JediTerm' | |
VS Code | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
Windows Terminal | ✅ | ✅ | ✅2 | |||
Windows PowerShell | ✅ | ✅ | ✅2 | |||
macOS Terminal | ✅ | ✅ | ❌ | xterm-256color | ||
iTerm | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
Terminal emulator Kitty | ✅ | ✅ | ✅ | xterm-kitty |
See also:
Environment variables
To force disable or enable colored output use environment variables NO_COLOR
and FORCE_COLOR
.
The NO_COLOR
variable should be presents with any not empty value.
The value is not important, e.g., NO_COLOR=1
NO_COLOR=true
disable colors.
See standard description by NO_COLOR.
The FORCE_COLOR
variable should be presents with one of values:
FORCE_COLOR=0
force disable colors
FORCE_COLOR=1
force enable colors
CLI arguments
Use arguments --no-color
or --color=false
to disable colors and --color
to enable ones.
For example, an executable script colors.js:
1#!/usr/bin/env node 2import { isStdoutColorSupported } from "@visulima/is-ansi-color-supported"; 3 4console.log(isStdoutColorSupported());
Execute the script in a terminal:
$ ./colors.js # colored output in terminal
$ ./colors.js --no-color # non colored output in terminal
$ ./colors.js --color=false # non colored output in terminal
$ ./colors.js > log.txt # output in file without ANSI codes
$ ./colors.js --color > log.txt # output in file with ANSI codes
$ ./colors.js --color=true > log.txt # output in file with ANSI codes
Warning
The command line arguments have a higher priority than environment variable.
Info
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 - Detect whether a terminal supports color
- supports-color-cli - CLI for this module
Supported Node.js Versions
Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.
Contributing
If you would like to help take a look at the list of issues and check our Contributing guild.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Credits
License
The visulima is-ansi-color-supported is open-sourced software licensed under the MIT
Footnotes
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
2 out of 2 merged PRs checked by a CI test -- score normalized to 10
Reason
project has 6 contributing companies or organizations
Details
- Info: narrowspark contributor org/company found, anolilab contributor org/company found, growcss contributor org/company found, MarkdownDoc contributor org/company found, sass-projects contributor org/company found, faker-js contributor org/company found,
Reason
no dangerous workflow patterns detected
Reason
update tool detected
Details
- Info: detected update tool: RenovateBot: .github/renovate.json5:1
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
30 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (2) are checked with a SAST tool
Reason
dependency not pinned by hash detected -- score normalized to 8
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/lint.yml:135
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/lint.yml:186
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/lint.yml:237
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/lint.yml:84
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/lock-file-maintenance.yml:39
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/preview-release.yaml:50
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/semantic-release.yml:59
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/semantic-release.yml:78
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:96
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:164
- Warn: downloadThenRun not pinned by hash: .github/workflows/lint.yml:305
- Info: 25 out of 25 GitHub-owned GitHubAction dependencies pinned
- Info: 44 out of 54 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 downloadThenRun dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql.yml:33
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql.yml:34
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/lock-file-maintenance.yml:20
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/preview-release.yaml:22
- Warn: jobLevel 'checks' permission set to 'write': .github/workflows/preview-release.yaml:24
- Info: jobLevel 'pull-requests' permission set to 'read': .github/workflows/require-allow-edits.yml:11
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/scorecards.yml:31
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/scorecards.yml:32
- Warn: jobLevel 'statuses' permission set to 'write': .github/workflows/semantic-pull-request.yml:21
- Warn: no topLevel permission defined: .github/workflows/allo-allo.yaml:1
- Warn: no topLevel permission defined: .github/workflows/cache-clear.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/codeql.yml:24
- Info: topLevel 'contents' permission set to 'read': .github/workflows/comment-issue.yml:9
- Info: topLevel 'contents' permission set to 'read': .github/workflows/dependency-review.yml:17
- Info: topLevel 'contents' permission set to 'read': .github/workflows/lint.yml:16
- Info: topLevel 'contents' permission set to 'read': .github/workflows/lock-file-maintenance.yml:12
- Warn: no topLevel permission defined: .github/workflows/lock-issues.yaml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/preview-release.yaml:8
- Info: topLevel 'contents' permission set to 'read': .github/workflows/require-allow-edits.yml:6
- Info: topLevel permissions set to 'read-all': .github/workflows/scorecards.yml:20
- Info: topLevel 'contents' permission set to 'read': .github/workflows/semantic-pull-request.yml:15
- Info: topLevel 'contents' permission set to 'read': .github/workflows/semantic-release.yml:17
- Warn: no topLevel permission defined: .github/workflows/stale-issues.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/test.yml:16
Score
6.3
/10
Last Scanned on 2025-02-04T07:27:14Z
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