Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export createSupportsColor function from supports-color #600

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"log-update": "^5.0.0",
"matcha": "^0.7.0",
"tsd": "^0.19.0",
"xo": "^0.53.0",
"xo": "^0.54.2",
"yoctodelay": "^2.0.0"
},
"xo": {
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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