What is @types/supports-color?
@types/supports-color is a TypeScript type definition package for the 'supports-color' npm package. The 'supports-color' package is used to detect whether the terminal supports color output, which is useful for creating command-line applications that can adapt their output based on the terminal's capabilities.
What are @types/supports-color's main functionalities?
Check if terminal supports color
This feature allows you to check if the terminal supports color output. The 'supportsColor.stdout' property returns a boolean indicating whether the terminal supports color.
const supportsColor = require('supports-color');
if (supportsColor.stdout) {
console.log('Terminal supports color');
} else {
console.log('Terminal does not support color');
}
Check color level support
This feature allows you to check the level of color support in the terminal. The 'supportsColor.stdout.level' property returns a number indicating the level of color support (0 for no color, 1 for basic color, 2 for 256 colors, and 3 for truecolor).
const supportsColor = require('supports-color');
if (supportsColor.stdout) {
console.log(`Color level: ${supportsColor.stdout.level}`);
} else {
console.log('Terminal does not support color');
}
Other packages similar to @types/supports-color
chalk
Chalk is a popular library for styling terminal strings. It provides a rich API for applying colors and styles to text, and it automatically detects if the terminal supports color. Compared to 'supports-color', Chalk offers more functionality for styling text but also includes color support detection.
colorette
Colorette is a lightweight and fast library for styling terminal output with ANSI colors. It also includes color support detection similar to 'supports-color'. Colorette is known for its minimalistic approach and performance.
kleur
Kleur is another lightweight library for terminal string styling with ANSI colors. It provides a simple API for applying colors and styles and includes color support detection. Kleur is designed to be fast and easy to use.
Installation
npm install --save @types/supports-color
Summary
This package contains type definitions for supports-color (https://github.com/chalk/supports-color).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/supports-color.
export namespace supportsColor {
interface Level {
level: number;
hasBasic: boolean;
has256: boolean;
has16m: boolean;
}
interface Options {
sniffFlags?: boolean | undefined;
isTTY?: boolean | undefined;
}
type SupportsColor = false | Level;
}
export function supportsColor(
stream: {
isTTY?: boolean | undefined;
},
options?: supportsColor.Options,
): supportsColor.SupportsColor;
export const stdout: supportsColor.SupportsColor;
export const stderr: supportsColor.SupportsColor;
Additional Details
- Last updated: Tue, 07 Nov 2023 15:11:36 GMT
- Dependencies: none
Credits
These definitions were written by Melvin Groenhoff, Matt Traynham, and Piotr Błażejewicz.