Expose style names (#566)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
This commit is contained in:
parent
96f44c976b
commit
d7d75717b3
3 changed files with 26 additions and 0 deletions
16
readme.md
16
readme.md
|
|
@ -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.
|
`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
|
## Styles
|
||||||
|
|
||||||
### Modifiers
|
### Modifiers
|
||||||
|
|
|
||||||
5
source/index.d.ts
vendored
5
source/index.d.ts
vendored
|
|
@ -284,4 +284,9 @@ export {
|
||||||
// } from '#supports-color';
|
// } from '#supports-color';
|
||||||
} from './vendor/supports-color/index.js';
|
} 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;
|
export default chalk;
|
||||||
|
|
|
||||||
|
|
@ -209,4 +209,9 @@ export {
|
||||||
stderrColor as supportsColorStderr,
|
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;
|
export default chalk;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue