Export createSupportsColor function from supports-color

This commit is contained in:
Luke Karrys 2023-06-13 23:59:58 -07:00
parent a370f468a4
commit d0927f56a0
No known key found for this signature in database
4 changed files with 10 additions and 2 deletions

View file

@ -198,6 +198,10 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience. `chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.
### createSupportsColor
Create a [`supportsColor()`](https://github.com/chalk/supports-color) function based on a given stream. Used internally and handled for you, but exposed for convenience.
### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames ### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`. All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.

1
source/index.d.ts vendored
View file

@ -251,6 +251,7 @@ export {
ColorInfo, ColorInfo,
ColorSupport, ColorSupport,
ColorSupportLevel, ColorSupportLevel,
createSupportsColor,
// } from '#supports-color'; // } from '#supports-color';
} from './vendor/supports-color/index.js'; } from './vendor/supports-color/index.js';

View file

@ -5,7 +5,7 @@ import { // eslint-disable-line import/order
stringEncaseCRLFWithFirstIndex, stringEncaseCRLFWithFirstIndex,
} from './utilities.js'; } from './utilities.js';
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor; const {stdout: stdoutColor, stderr: stderrColor, createSupportsColor} = supportsColor;
const GENERATOR = Symbol('GENERATOR'); const GENERATOR = Symbol('GENERATOR');
const STYLER = Symbol('STYLER'); const STYLER = Symbol('STYLER');
@ -218,6 +218,7 @@ export {
} from './vendor/ansi-styles/index.js'; } from './vendor/ansi-styles/index.js';
export { export {
createSupportsColor,
stdoutColor as supportsColor, stdoutColor as supportsColor,
stderrColor as supportsColorStderr, stderrColor as supportsColorStderr,
}; };

View file

@ -1,6 +1,6 @@
import {expectType, expectAssignable, expectError, expectDeprecated} from 'tsd'; import {expectType, expectAssignable, expectError, expectDeprecated} from 'tsd';
import chalk, { import chalk, {
Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr, Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr, createSupportsColor,
ModifierName, ForegroundColorName, BackgroundColorName, ColorName, ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
Modifiers, Modifiers,
} from './index.js'; } from './index.js';
@ -24,6 +24,8 @@ if (supportsColorStderr) {
expectType<boolean>(supportsColorStderr.has16m); expectType<boolean>(supportsColorStderr.has16m);
} }
expectType<ColorInfo>(createSupportsColor());
// -- `supportsColorStderr` is not a member of the Chalk interface -- // -- `supportsColorStderr` is not a member of the Chalk interface --
expectError(chalk.reset.supportsColorStderr); expectError(chalk.reset.supportsColorStderr);