supports-color
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
has-flag | 4.0.0 | 2.15 kB | MIT | prod |
The "supports-color" is a module in Node.js, designed primarily to detect whether a terminal supports color. Its function enables programmers to write colorful and therefore, user-friendly and aesthetically pleasing console logs.
To use the "supports-color" module, you first need to install it via npm using the command npm install supports-color
. Once installed, you can import it into your JavaScript file and use it to check if the terminal supports colors, 256 colors, or even 16 million colors (true colors) for stdout and stderr.
Here's an example of how you can use "supports-color" in your code:
import supportsColor from 'supports-color';
if (supportsColor.stdout) {
console.log('Terminal stdout supports color');
}
if (supportsColor.stdout.has256) {
console.log('Terminal stdout supports 256 colors');
}
if (supportsColor.stderr.has16m) {
console.log('Terminal stderr supports 16 million colors (truecolor)');
}
You can also create custom instances for an arbitrary write stream. For instance:
import {createSupportsColor} from 'supports-color';
const stdoutSupportsColor = createSupportsColor(process.stdout);
if (stdoutSupportsColor) {
console.log('Terminal stdout supports color');
}
The complete documentation for the "supports-color" module can be found in the README file of the module's GitHub repository at the following URL: git+https://github.com/chalk/supports-color.git. The documentation provides complete details about installation, usage, API, and related information about "supports-color".