Skip to content

Commit

Permalink
Expose style names (#566)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
LitoMore and sindresorhus committed Oct 5, 2022
1 parent 96f44c9 commit d7d7571
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions readme.md
Expand Up @@ -210,6 +210,22 @@ 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.

### modifiers, foregroundColors, backgroundColors, and colors

All supported style strings are exposed as an array of strings for convenience. `colors` is the combination of `foregroundColors` and `backgroundColors`.

This can be useful if you wrap Chalk and need to validate input:

```js
import {modifiers, foregroundColors} from 'chalk';

console.log(modifiers.includes('bold'));
//=> true

console.log(foregroundColors.includes('pink'));
//=> false
```

## Styles

### Modifiers
Expand Down
5 changes: 5 additions & 0 deletions source/index.d.ts
Expand Up @@ -284,4 +284,9 @@ export {
// } from '#supports-color';
} from './vendor/supports-color/index.js';

export const modifiers: readonly Modifiers[];
export const foregroundColors: readonly ForegroundColor[];
export const backgroundColors: readonly BackgroundColor[];
export const colors: readonly Color[];

export default chalk;
5 changes: 5 additions & 0 deletions source/index.js
Expand Up @@ -209,4 +209,9 @@ export {
stderrColor as supportsColorStderr,
};

export const modifiers = Object.keys(ansiStyles.modifier);
export const foregroundColors = Object.keys(ansiStyles.color);
export const backgroundColors = Object.keys(ansiStyles.bgColor);
export const colors = [...foregroundColors, ...backgroundColors];

export default chalk;

0 comments on commit d7d7571

Please sign in to comment.