feat: add gradient and theme features with corresponding tests and documentation
This commit is contained in:
parent
aa06bb5ac3
commit
c017dd5b04
8 changed files with 505 additions and 13 deletions
36
source/index.d.ts
vendored
Normal file → Executable file
36
source/index.d.ts
vendored
Normal file → Executable file
|
|
@ -121,6 +121,21 @@ export interface ChalkInstance {
|
|||
*/
|
||||
bgAnsi256: (index: number) => this;
|
||||
|
||||
/**
|
||||
Create a gradient between colors and apply it to the text.
|
||||
|
||||
@param colors - Array of colors (hex strings or RGB arrays) to gradient between.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.gradient('#ff0000', '#0000ff')('Gradient text');
|
||||
chalk.gradient([255, 0, 0], [0, 0, 255])('RGB gradient');
|
||||
```
|
||||
*/
|
||||
gradient: (...colors: Array<string | [number, number, number]>) => this;
|
||||
|
||||
/**
|
||||
Modifier: Reset the current style.
|
||||
*/
|
||||
|
|
@ -228,6 +243,27 @@ export interface ChalkInstance {
|
|||
readonly bgMagentaBright: this;
|
||||
readonly bgCyanBright: this;
|
||||
readonly bgWhiteBright: this;
|
||||
|
||||
/**
|
||||
Create a themed Chalk instance with custom styles.
|
||||
|
||||
@param theme - An object where keys are style names and values are Chalk instances.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
const themedChalk = chalk.theme({
|
||||
error: chalk.red.bold,
|
||||
success: chalk.green,
|
||||
warning: chalk.yellow,
|
||||
});
|
||||
|
||||
console.log(themedChalk.error('This is an error'));
|
||||
console.log(themedChalk.success('This is a success'));
|
||||
```
|
||||
*/
|
||||
theme<T extends Record<string, this>>(theme: T): this & T;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue