Skip to content

Commit

Permalink
Export createSupportsColor function from supports-color
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jun 14, 2023
1 parent a370f46 commit 2f13b14
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions readme.md
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions source/index.d.ts
Expand Up @@ -251,6 +251,7 @@ export {
ColorInfo,
ColorSupport,
ColorSupportLevel,
createSupportsColor
// } from '#supports-color';
} from './vendor/supports-color/index.js';

Expand Down
3 changes: 2 additions & 1 deletion source/index.js
Expand Up @@ -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');
Expand Down Expand Up @@ -218,6 +218,7 @@ export {
} from './vendor/ansi-styles/index.js';

export {
createSupportsColor,
stdoutColor as supportsColor,
stderrColor as supportsColorStderr,
};
Expand Down
4 changes: 3 additions & 1 deletion 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';
Expand All @@ -24,6 +24,8 @@ if (supportsColorStderr) {
expectType<boolean>(supportsColorStderr.has16m);
}

expectType<ColorInfo>(createSupportsColor());

// -- `supportsColorStderr` is not a member of the Chalk interface --
expectError(chalk.reset.supportsColorStderr);

Expand Down

0 comments on commit 2f13b14

Please sign in to comment.