UNPKG

3 kBMarkdownView Raw
1# chalk-pipe
2
3[![](https://github.com/LitoMore/chalk-pipe/workflows/Node/badge.svg)](https://github.com/LitoMore/chalk-pipe/actions)
4[![](https://img.shields.io/npm/v/chalk-pipe.svg)](https://www.npmjs.com/package/chalk-pipe)
5[![](https://img.shields.io/npm/l/chalk-pipe.svg)](https://github.com/LitoMore/chalk-pipe/blob/main/LICENSE)
6[![](https://shields.io/badge/code_style-5ed9c7?logo=xo&labelColor=gray)](https://github.com/xojs/xo)
7
8Create chalk style schemes with simpler style strings
9
10![](https://raw.githubusercontent.com/LitoMore/chalk-pipe/main/screenshot.png)
11
12## Install
13
14```sh
15npm install chalk-pipe
16```
17
18## Usage
19
20```js
21import chalkPipe from 'chalk-pipe';
22
23console.log(chalkPipe('blue.bold')('Hello world!'));
24```
25
26Use dot `.` to separeate multiple styles:
27
28```js
29const link = chalkPipe('blue.underline');
30const error = chalkPipe('bgRed.#cccccc');
31const warning = chalkPipe('orange.bold');
32
33console.log(link('Link!'));
34console.log(error('Error!'));
35console.log(warning('Warning!'));
36```
37
38`chalkPipe` is also `chalk`:
39
40```js
41const blue = chalkPipe('blue');
42const link = blue.underline;
43
44console.log(link('Link!'));
45```
46
47### Use custom chalk
48
49```js
50import chalkPipe, {chalk, Chalk} from 'chalk-pipe';
51
52const customChalk = new Chalk({level: 1});
53
54console.log(chalkPipe('underline', chalk.blue)('Link!'));
55console.log(chalkPipe('underline', customChalk.blue)('Link!'));
56```
57
58## Built-in Chalk
59
60All Chalk exported functions, variables, and declarations are exposed for convenience.
61
62This can be useful if you want to use `chalk` directly.
63
64```js
65import {chalk, Chalk} from 'chalk-pipe';
66
67const customChalk = new Chalk({level: 0});
68
69console.log(chalk.blue('Hello'))
70console.log(customChalk.green('World'));
71```
72
73## API
74
75### chalkPipe(styles)(text)
76
77Example:
78
79 ```js
80 chalkPipe('blue.underline')('Link!');
81 ```
82
83### chalkPipe(styles, chalk)(text)
84
85Example:
86
87```js
88import {Chalk} from 'chalk-pipe';
89
90const chalk = new Chalk({level: 1});
91
92chalkPipe('underline', chalk.blue)('Link!');
93```
94
95### keywordNames
96
97All supported keyword names are exposed as array of strings for convenience.
98
99```js
100import {keywordNames} from 'chalk-pipe';
101
102console.log(keywordNames.includes('pink'));
103//=> true
104```
105
106## Supported styles
107
108- [Modifiers](https://github.com/chalk/chalk#modifiers)
109- [Colors](https://github.com/chalk/chalk#colors)
110- [Background colors](https://github.com/chalk/chalk#background-colors)
111- [Hex triplet](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet)
112- [CSS keywords](https://www.w3.org/wiki/CSS/Properties/color/keywords)
113
114## Related
115
116- [chalk-pipe-cli](https://github.com/LitoMore/chalk-pipe-cli) - CLI for this module
117- [ink-color-pipe](https://github.com/LitoMore/ink-color-pipe) - Ink component for this module
118- [inquirer-chalk-pipe](https://github.com/LitoMore/inquirer-chalk-pipe) - A inquirer plugin for input chalk-pipe style strings
119- [chalk](https://github.com/chalk/chalk) - Output colored text to terminal
120
121## License
122
123MIT © [LitoMore](https://github.com/LitoMore)