Product
Introducing Socket Optimize
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.
@visulima/is-ansi-color-supported
Advanced tools
Detect whether a terminal or browser supports ansi colors.
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
npm install @visulima/is-ansi-color-supported
yarn add @visulima/is-ansi-color-supported
pnpm add @visulima/is-ansi-color-supported
import { isStdoutColorSupported, isStderrColorSupported } from "@visulima/is-ansi-color-supported";
/**
* Levels:
* - `0` - All colors disabled.
* - `1` - Basic 16 colors support.
* - `2` - ANSI 256 colors support.
* - `3` - Truecolor 16 million colors support.
*/
console.log(isStdoutColorSupported()); // 3
console.log(isStderrColorSupported()); // 3
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
Use arguments --no-color
or --color=false
to disable colors and --color
to enable ones.
For example, an executable script colors.js:
#!/usr/bin/env node
import { isStdoutColorSupported } from "@visulima/is-ansi-color-supported";
console.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.
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.
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.
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.
The visulima is-ansi-color-supported is open-sourced software licensed under the MIT
FAQs
Detect whether a terminal or browser supports ansi colors.
The npm package @visulima/is-ansi-color-supported receives a total of 0 weekly downloads. As such, @visulima/is-ansi-color-supported popularity was classified as not popular.
We found that @visulima/is-ansi-color-supported demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.