
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
The has-color npm package is a utility that checks if the terminal supports color. It is useful for developers who want to conditionally enable or disable color output in their command-line applications based on the terminal's capabilities.
Check if terminal supports color
This feature allows you to check if the terminal supports color. The code sample demonstrates how to require the has-color package and log whether the terminal supports color.
const hasColor = require('has-color');
console.log(hasColor); // true or false
Check if specific stream supports color
This feature allows you to check if a specific stream, such as process.stdout, supports color. The code sample shows how to pass the stream to the has-color function and log the result.
const hasColor = require('has-color');
console.log(hasColor(process.stdout)); // true or false
The supports-color package is similar to has-color but provides more detailed information about the terminal's color capabilities. It can detect the level of color support (basic, 256, or truecolor) and is more feature-rich compared to has-color.
Chalk is a popular package for styling terminal strings. While its primary purpose is to add color and style to terminal output, it also includes functionality to detect if the terminal supports color, making it a more comprehensive solution compared to has-color.
Ansi-colors is another package for styling terminal output with ANSI colors. It includes utilities to check for color support and provides a wide range of styling options, making it a more versatile option compared to has-color.
Detect whether a terminal supports color.
Used in the terminal color module chalk.
$ npm install --save has-color
var hasColor = require('has-color');
if (hasColor) {
console.log('Terminal supports color.');
}
It obeys the --color
and --no-color
CLI flags.
FAQs
Detect whether a terminal supports color
The npm package has-color receives a total of 641,241 weekly downloads. As such, has-color popularity was classified as popular.
We found that has-color demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.