From 2f13b14e1c8efde7891f78b12c53bc3ddc413540 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 13 Jun 2023 23:59:58 -0700 Subject: [PATCH] Export `createSupportsColor` function from `supports-color` --- readme.md | 4 ++++ source/index.d.ts | 1 + source/index.js | 3 ++- source/index.test-d.ts | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 93511c01..a660ed38 100644 --- a/readme.md +++ b/readme.md @@ -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. +### 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 All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`. diff --git a/source/index.d.ts b/source/index.d.ts index b0cd2aee..fea80a83 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -251,6 +251,7 @@ export { ColorInfo, ColorSupport, ColorSupportLevel, + createSupportsColor // } from '#supports-color'; } from './vendor/supports-color/index.js'; diff --git a/source/index.js b/source/index.js index 8bc993da..38d921ed 100644 --- a/source/index.js +++ b/source/index.js @@ -5,7 +5,7 @@ import { // eslint-disable-line import/order stringEncaseCRLFWithFirstIndex, } from './utilities.js'; -const {stdout: stdoutColor, stderr: stderrColor} = supportsColor; +const {stdout: stdoutColor, stderr: stderrColor, createSupportsColor} = supportsColor; const GENERATOR = Symbol('GENERATOR'); const STYLER = Symbol('STYLER'); @@ -218,6 +218,7 @@ export { } from './vendor/ansi-styles/index.js'; export { + createSupportsColor, stdoutColor as supportsColor, stderrColor as supportsColorStderr, }; diff --git a/source/index.test-d.ts b/source/index.test-d.ts index e729675e..b32fd558 100644 --- a/source/index.test-d.ts +++ b/source/index.test-d.ts @@ -1,6 +1,6 @@ import {expectType, expectAssignable, expectError, expectDeprecated} from 'tsd'; import chalk, { - Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr, + Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr, createSupportsColor, ModifierName, ForegroundColorName, BackgroundColorName, ColorName, Modifiers, } from './index.js'; @@ -24,6 +24,8 @@ if (supportsColorStderr) { expectType(supportsColorStderr.has16m); } +expectType(createSupportsColor()); + // -- `supportsColorStderr` is not a member of the Chalk interface -- expectError(chalk.reset.supportsColorStderr);