diff --git a/index.d.ts b/index.d.ts index c42757a..6f24e08 100644 --- a/index.d.ts +++ b/index.d.ts @@ -401,6 +401,8 @@ This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`. declare const chalk: ChalkInstance & ChalkFunction; export const supportsColor: ColorSupport | false; + export const chalkStderr: typeof chalk & {supportsColor: typeof supportsColor}; +export const supportsColorStderr: typeof supportsColor; export default chalk; diff --git a/index.test-d.ts b/index.test-d.ts index 9b6c1eb..3e7e2d6 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType, expectAssignable, expectError} from 'tsd'; -import chalk, {Chalk, ChalkInstance, Color, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor} from './index.js'; +import chalk, {Chalk, ChalkInstance, Color, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js'; // - Helpers - type colorReturn = ChalkInstance & {supportsColor?: never}; @@ -14,15 +14,15 @@ if (supportsColor) { // - stderr - expectAssignable(chalkStderr); -expectType(chalkStderr.supportsColor); -if (chalkStderr.supportsColor) { - expectType(chalkStderr.supportsColor.hasBasic); - expectType(chalkStderr.supportsColor.has256); - expectType(chalkStderr.supportsColor.has16m); +expectType(supportsColorStderr); +if (supportsColorStderr) { + expectType(supportsColorStderr.hasBasic); + expectType(supportsColorStderr.has256); + expectType(supportsColorStderr.has16m); } -// -- `stderr` is not a member of the Chalk interface -- -expectError(chalk.reset.stderr); +// -- `supportsColorStderr` is not a member of the Chalk interface -- +expectError(chalk.reset.supportsColorStderr); // -- `supportsColor` is not a member of the Chalk interface -- expectError(chalk.reset.supportsColor); diff --git a/readme.md b/readme.md index 575dd7b..45e4be7 100644 --- a/readme.md +++ b/readme.md @@ -191,9 +191,9 @@ Can be overridden by the user with the flags `--color` and `--no-color`. For sit Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively. -### chalkStderr and chalkStderr.supportsColor +### chalkStderr and supportsColorStderr -`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `chalkStderr.supportsColor` 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. ## Styles diff --git a/source/index.js b/source/index.js index 32c3725..0f159d4 100644 --- a/source/index.js +++ b/source/index.js @@ -213,10 +213,10 @@ Object.defineProperties(createChalk.prototype, styles); const chalk = createChalk(); export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0}); -chalkStderr.supportsColor = stderrColor; export { - stdoutColor as supportsColor + stdoutColor as supportsColor, + stderrColor as supportsColorStderr }; export default chalk;