chalk-ts 1.0.0 โ 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +462 -151
- package/dist/ansi.d.ts +54 -43
- package/dist/ansi.d.ts.map +1 -1
- package/dist/chalk.d.ts +135 -83
- package/dist/chalk.d.ts.map +1 -1
- package/dist/effects.d.ts +0 -1
- package/dist/effects.d.ts.map +1 -1
- package/dist/gradient.d.ts +11 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +441 -211
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +444 -210
- package/dist/index.js.map +1 -1
- package/dist/theme.d.ts +25 -0
- package/dist/theme.d.ts.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,27 +9,42 @@
|
|
|
9
9
|
[](https://badge.fury.io/js/chalk-ts)
|
|
10
10
|
[](https://opensource.org/licenses/MIT)
|
|
11
11
|
[](https://www.typescriptlang.org/)
|
|
12
|
-
[](https://github.com/noorjsdivs/chalk-ts)
|
|
13
13
|
[](https://www.youtube.com/@reactjsBD)
|
|
14
14
|
[](https://buymeacoffee.com/reactbd)
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
18
|
> ๐ **Modern terminal string styling library built with TypeScript**
|
|
19
|
-
> A powerful, feature-rich alternative to chalk with enhanced capabilities,
|
|
19
|
+
> A powerful, feature-rich alternative to chalk with enhanced capabilities, TrueColor support, visual effects, and modern development experience.
|
|
20
20
|
|
|
21
21
|
## โจ Features
|
|
22
22
|
|
|
23
|
-
- ๐จ **Rich Color Support**: 20+ built-in colors, RGB
|
|
24
|
-
- ๐ญ **Advanced Effects**:
|
|
23
|
+
- ๐จ **Rich Color Support**: 20+ built-in colors, TrueColor (RGB/HEX/HSL)
|
|
24
|
+
- ๐ญ **Advanced Effects**: Gradients, rainbow, pulse, neon, shadow, zebra stripes
|
|
25
25
|
- ๐ ๏ธ **Built-in Utilities**: Tables, progress bars, boxes, spinners
|
|
26
|
+
- ๐ฏ **Semantic Theming**: Create reusable theme configurations
|
|
26
27
|
- ๐ **TypeScript First**: Full type safety with excellent IntelliSense
|
|
27
|
-
- ๐ฆ **Zero Dependencies**: No external packages, minimal bundle size
|
|
28
|
+
- ๐ฆ **Zero Dependencies**: No external packages, minimal bundle size (~15KB)
|
|
28
29
|
- ๐ณ **Tree Shakeable**: Import only what you need
|
|
29
30
|
- โก **High Performance**: Optimized for speed and efficiency
|
|
30
31
|
- ๐ง **Easy Migration**: Drop-in replacement for most chalk usage
|
|
32
|
+
- ๐ **Web Demo**: Interactive browser-based demo with live examples
|
|
31
33
|
- ๐ **Comprehensive Docs**: Extensive documentation and examples
|
|
32
|
-
- ๐งช **Well Tested**:
|
|
34
|
+
- ๐งช **Well Tested**: 98%+ test coverage with 98 passing tests
|
|
35
|
+
|
|
36
|
+
## ๐ Interactive Demo
|
|
37
|
+
|
|
38
|
+
Try out all features in your browser: **[Live Web Demo](https://www.reactbd.com/npm-packages/chalk-ts-typescript)**
|
|
39
|
+
|
|
40
|
+
The demo includes:
|
|
41
|
+
|
|
42
|
+
- โ
All 20+ colors and backgrounds
|
|
43
|
+
- โ
TrueColor (RGB/HEX/HSL) examples
|
|
44
|
+
- โ
Visual effects (gradients, rainbow, neon, etc.)
|
|
45
|
+
- โ
Utilities (boxes, tables, progress bars)
|
|
46
|
+
- โ
Code snippets with copy functionality
|
|
47
|
+
- โ
Live terminal output rendering
|
|
33
48
|
|
|
34
49
|
## ๐ฆ Installation
|
|
35
50
|
|
|
@@ -45,29 +60,44 @@ yarn add chalk-ts
|
|
|
45
60
|
pnpm add chalk-ts
|
|
46
61
|
```
|
|
47
62
|
|
|
63
|
+
```bash
|
|
64
|
+
bun add chalk-ts
|
|
65
|
+
```
|
|
66
|
+
|
|
48
67
|
## ๐ Quick Start
|
|
49
68
|
|
|
50
69
|
```typescript
|
|
51
|
-
import
|
|
70
|
+
import chalk from "chalk-ts";
|
|
52
71
|
|
|
53
72
|
// Basic colors
|
|
54
|
-
console.log(
|
|
55
|
-
console.log(
|
|
73
|
+
console.log(chalk.red("Hello World!"));
|
|
74
|
+
console.log(chalk.green.bold("Success message"));
|
|
56
75
|
|
|
57
|
-
//
|
|
58
|
-
console.log(
|
|
59
|
-
console.log(
|
|
60
|
-
console.log(
|
|
76
|
+
// TrueColor support
|
|
77
|
+
console.log(chalk.rgb(255, 136, 0)("Custom RGB color"));
|
|
78
|
+
console.log(chalk.hex("#ff8800")("HEX color"));
|
|
79
|
+
console.log(chalk.hsl(30, 100, 50)("HSL color"));
|
|
61
80
|
|
|
62
81
|
// Method chaining
|
|
63
|
-
console.log(
|
|
82
|
+
console.log(chalk.bold.red.bgYellow("Styled text"));
|
|
64
83
|
|
|
65
84
|
// Advanced effects
|
|
66
|
-
import { gradient, rainbow, box } from "chalk-ts";
|
|
85
|
+
import { gradient, rainbow, box, createTheme } from "chalk-ts";
|
|
67
86
|
|
|
68
|
-
console.log(gradient("Gradient text!", "#ff0000", "#0000ff"));
|
|
87
|
+
console.log(gradient("Gradient text!", ["#ff0000", "#00ff00", "#0000ff"]));
|
|
69
88
|
console.log(rainbow("Rainbow colors!"));
|
|
70
89
|
console.log(box("Boxed text"));
|
|
90
|
+
|
|
91
|
+
// Semantic theming
|
|
92
|
+
const theme = createTheme({
|
|
93
|
+
info: chalk.blue.bold,
|
|
94
|
+
success: chalk.green,
|
|
95
|
+
error: chalk.red.bold,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log(theme.info("Info message"));
|
|
99
|
+
console.log(theme.success("Success!"));
|
|
100
|
+
console.log(theme.error("Error occurred"));
|
|
71
101
|
```
|
|
72
102
|
|
|
73
103
|
## ๐จ Basic Styling
|
|
@@ -75,38 +105,41 @@ console.log(box("Boxed text"));
|
|
|
75
105
|
### Text Styles
|
|
76
106
|
|
|
77
107
|
```typescript
|
|
78
|
-
import
|
|
79
|
-
|
|
80
|
-
console.log(
|
|
81
|
-
console.log(
|
|
82
|
-
console.log(
|
|
83
|
-
console.log(
|
|
84
|
-
console.log(
|
|
85
|
-
console.log(
|
|
108
|
+
import chalk from "chalk-ts";
|
|
109
|
+
|
|
110
|
+
console.log(chalk.bold("Bold text"));
|
|
111
|
+
console.log(chalk.italic("Italic text"));
|
|
112
|
+
console.log(chalk.underline("Underlined text"));
|
|
113
|
+
console.log(chalk.strikethrough("Strikethrough text"));
|
|
114
|
+
console.log(chalk.dim("Dimmed text"));
|
|
115
|
+
console.log(chalk.inverse("Inverted text"));
|
|
86
116
|
```
|
|
87
117
|
|
|
88
118
|
### Basic Colors
|
|
89
119
|
|
|
90
120
|
```typescript
|
|
91
121
|
// Foreground colors
|
|
92
|
-
console.log(
|
|
93
|
-
console.log(
|
|
94
|
-
console.log(
|
|
95
|
-
console.log(
|
|
96
|
-
console.log(
|
|
97
|
-
console.log(
|
|
98
|
-
console.log(
|
|
99
|
-
console.log(
|
|
122
|
+
console.log(chalk.black("Black text"));
|
|
123
|
+
console.log(chalk.red("Red text"));
|
|
124
|
+
console.log(chalk.green("Green text"));
|
|
125
|
+
console.log(chalk.yellow("Yellow text"));
|
|
126
|
+
console.log(chalk.blue("Blue text"));
|
|
127
|
+
console.log(chalk.magenta("Magenta text"));
|
|
128
|
+
console.log(chalk.cyan("Cyan text"));
|
|
129
|
+
console.log(chalk.white("White text"));
|
|
130
|
+
console.log(chalk.gray("Gray text"));
|
|
100
131
|
|
|
101
132
|
// Background colors
|
|
102
|
-
console.log(
|
|
103
|
-
console.log(
|
|
104
|
-
console.log(
|
|
133
|
+
console.log(chalk.bgRed("Red background"));
|
|
134
|
+
console.log(chalk.bgGreen("Green background"));
|
|
135
|
+
console.log(chalk.bgBlue("Blue background"));
|
|
136
|
+
console.log(chalk.bgYellow("Yellow background"));
|
|
105
137
|
|
|
106
138
|
// Bright colors
|
|
107
|
-
console.log(
|
|
108
|
-
console.log(
|
|
109
|
-
console.log(
|
|
139
|
+
console.log(chalk.redBright("Bright red"));
|
|
140
|
+
console.log(chalk.greenBright("Bright green"));
|
|
141
|
+
console.log(chalk.blueBright("Bright blue"));
|
|
142
|
+
console.log(chalk.yellowBright("Bright yellow"));
|
|
110
143
|
```
|
|
111
144
|
|
|
112
145
|
### Extended Color Palette
|
|
@@ -114,61 +147,81 @@ console.log(chalkTs.blueBright("Bright blue"));
|
|
|
114
147
|
chalk-ts includes 20+ built-in colors beyond the standard ANSI colors:
|
|
115
148
|
|
|
116
149
|
```typescript
|
|
117
|
-
console.log(
|
|
118
|
-
console.log(
|
|
119
|
-
console.log(
|
|
120
|
-
console.log(
|
|
121
|
-
console.log(
|
|
122
|
-
console.log(
|
|
123
|
-
console.log(
|
|
124
|
-
console.log(
|
|
125
|
-
console.log(
|
|
126
|
-
console.log(
|
|
150
|
+
console.log(chalk.orange("Orange text"));
|
|
151
|
+
console.log(chalk.purple("Purple text"));
|
|
152
|
+
console.log(chalk.pink("Pink text"));
|
|
153
|
+
console.log(chalk.brown("Brown text"));
|
|
154
|
+
console.log(chalk.lime("Lime text"));
|
|
155
|
+
console.log(chalk.indigo("Indigo text"));
|
|
156
|
+
console.log(chalk.violet("Violet text"));
|
|
157
|
+
console.log(chalk.turquoise("Turquoise text"));
|
|
158
|
+
console.log(chalk.gold("Gold text"));
|
|
159
|
+
console.log(chalk.silver("Silver text"));
|
|
160
|
+
console.log(chalk.crimson("Crimson text"));
|
|
161
|
+
console.log(chalk.navy("Navy text"));
|
|
162
|
+
console.log(chalk.teal("Teal text"));
|
|
163
|
+
console.log(chalk.olive("Olive text"));
|
|
164
|
+
console.log(chalk.maroon("Maroon text"));
|
|
127
165
|
```
|
|
128
166
|
|
|
129
|
-
## ๐
|
|
167
|
+
## ๐ TrueColor Support
|
|
130
168
|
|
|
131
|
-
### RGB Colors
|
|
169
|
+
### RGB Colors (24-bit)
|
|
132
170
|
|
|
133
171
|
```typescript
|
|
134
172
|
// Foreground RGB
|
|
135
|
-
console.log(
|
|
173
|
+
console.log(chalk.rgb(255, 136, 0)("Custom Orange"));
|
|
174
|
+
console.log(chalk.rgb(100, 200, 255)("Sky Blue"));
|
|
136
175
|
|
|
137
176
|
// Background RGB
|
|
138
|
-
console.log(
|
|
177
|
+
console.log(chalk.bgRgb(255, 136, 0)("Orange background"));
|
|
178
|
+
console.log(chalk.bgRgb(100, 200, 255)("Sky blue background"));
|
|
139
179
|
```
|
|
140
180
|
|
|
141
181
|
### HEX Colors
|
|
142
182
|
|
|
143
183
|
```typescript
|
|
144
184
|
// Foreground HEX
|
|
145
|
-
console.log(
|
|
185
|
+
console.log(chalk.hex("#ff8800")("Orange HEX"));
|
|
186
|
+
console.log(chalk.hex("#64c8ff")("Sky Blue HEX"));
|
|
146
187
|
|
|
147
188
|
// Background HEX
|
|
148
|
-
console.log(
|
|
189
|
+
console.log(chalk.bgHex("#ff8800")("Orange background"));
|
|
190
|
+
console.log(chalk.bgHex("#64c8ff")("Sky blue background"));
|
|
149
191
|
```
|
|
150
192
|
|
|
151
193
|
### HSL Colors
|
|
152
194
|
|
|
153
195
|
```typescript
|
|
154
|
-
// Foreground HSL
|
|
155
|
-
console.log(
|
|
196
|
+
// Foreground HSL (Hue, Saturation, Lightness)
|
|
197
|
+
console.log(chalk.hsl(30, 100, 50)("Orange HSL"));
|
|
198
|
+
console.log(chalk.hsl(200, 100, 70)("Sky Blue HSL"));
|
|
156
199
|
|
|
157
200
|
// Background HSL
|
|
158
|
-
console.log(
|
|
201
|
+
console.log(chalk.bgHsl(30, 100, 50)("Orange background"));
|
|
202
|
+
console.log(chalk.bgHsl(200, 100, 70)("Sky blue background"));
|
|
159
203
|
```
|
|
160
204
|
|
|
161
|
-
## ๐ญ
|
|
205
|
+
## ๐ญ Visual Effects
|
|
162
206
|
|
|
163
207
|
### Gradient
|
|
164
208
|
|
|
165
|
-
Create beautiful gradient effects
|
|
209
|
+
Create beautiful gradient effects with multiple color stops:
|
|
166
210
|
|
|
167
211
|
```typescript
|
|
168
212
|
import { gradient } from "chalk-ts";
|
|
169
213
|
|
|
170
|
-
|
|
171
|
-
console.log(gradient("
|
|
214
|
+
// Two-color gradient
|
|
215
|
+
console.log(gradient("Gradient Text!", ["#ff0000", "#0000ff"]));
|
|
216
|
+
|
|
217
|
+
// Multi-color gradient
|
|
218
|
+
console.log(gradient("Rainbow Gradient!", ["#ff0000", "#00ff00", "#0000ff"]));
|
|
219
|
+
|
|
220
|
+
// Fire effect
|
|
221
|
+
console.log(gradient("Fire Effect", ["#ff4500", "#ffd700"]));
|
|
222
|
+
|
|
223
|
+
// Ocean effect
|
|
224
|
+
console.log(gradient("Ocean Waves", ["#006994", "#00d4ff", "#7fffd4"]));
|
|
172
225
|
```
|
|
173
226
|
|
|
174
227
|
### Rainbow
|
|
@@ -201,7 +254,7 @@ Alternate between two colors:
|
|
|
201
254
|
import { zebra } from "chalk-ts";
|
|
202
255
|
|
|
203
256
|
console.log(zebra("Zebra effect", "red", "blue"));
|
|
204
|
-
console.log(zebra("Alternating!", "green", "yellow"));
|
|
257
|
+
console.log(zebra("Alternating colors!", "green", "yellow"));
|
|
205
258
|
```
|
|
206
259
|
|
|
207
260
|
### Neon Effect
|
|
@@ -213,6 +266,7 @@ import { neon } from "chalk-ts";
|
|
|
213
266
|
|
|
214
267
|
console.log(neon("Neon text!", "cyan"));
|
|
215
268
|
console.log(neon("Glowing!", "magenta"));
|
|
269
|
+
console.log(neon("Electric!", "blue"));
|
|
216
270
|
```
|
|
217
271
|
|
|
218
272
|
### Shadow Effect
|
|
@@ -223,13 +277,14 @@ Add shadow to text:
|
|
|
223
277
|
import { shadow } from "chalk-ts";
|
|
224
278
|
|
|
225
279
|
console.log(shadow("Text with shadow", "cyan", "gray"));
|
|
280
|
+
console.log(shadow("Depth effect", "yellow", "black"));
|
|
226
281
|
```
|
|
227
282
|
|
|
228
283
|
## ๐ ๏ธ Built-in Utilities
|
|
229
284
|
|
|
230
285
|
### Boxes
|
|
231
286
|
|
|
232
|
-
Create beautiful boxes around text:
|
|
287
|
+
Create beautiful boxes around text with various styles:
|
|
233
288
|
|
|
234
289
|
```typescript
|
|
235
290
|
import { box } from "chalk-ts";
|
|
@@ -243,52 +298,88 @@ console.log(
|
|
|
243
298
|
padding: 2,
|
|
244
299
|
color: "cyan",
|
|
245
300
|
style: "double",
|
|
246
|
-
})
|
|
301
|
+
}),
|
|
247
302
|
);
|
|
248
303
|
|
|
249
|
-
// Different styles
|
|
250
|
-
console.log(box("
|
|
304
|
+
// Different styles
|
|
305
|
+
console.log(box("Single Border", { style: "single" }));
|
|
306
|
+
console.log(box("Double Border", { style: "double" }));
|
|
307
|
+
console.log(box("Rounded Corners", { style: "rounded" }));
|
|
308
|
+
console.log(box("Thick Border", { style: "thick" }));
|
|
309
|
+
|
|
310
|
+
// Multi-line content
|
|
311
|
+
console.log(
|
|
312
|
+
box("Line 1\nLine 2\nLine 3", {
|
|
313
|
+
padding: 1,
|
|
314
|
+
color: "green",
|
|
315
|
+
}),
|
|
316
|
+
);
|
|
251
317
|
```
|
|
252
318
|
|
|
253
319
|
### Progress Bars
|
|
254
320
|
|
|
255
|
-
Create progress indicators:
|
|
321
|
+
Create customizable progress indicators:
|
|
256
322
|
|
|
257
323
|
```typescript
|
|
258
324
|
import { progressBar } from "chalk-ts";
|
|
259
325
|
|
|
326
|
+
// Simple progress bar
|
|
260
327
|
console.log(progressBar(75, 100)); // 75% progress
|
|
328
|
+
|
|
329
|
+
// Customized progress bar
|
|
261
330
|
console.log(
|
|
262
331
|
progressBar(50, 100, {
|
|
263
332
|
width: 30,
|
|
264
333
|
complete: "โ ",
|
|
265
334
|
incomplete: "โก",
|
|
266
335
|
color: "green",
|
|
267
|
-
})
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
// Different styles
|
|
340
|
+
console.log(
|
|
341
|
+
progressBar(80, 100, {
|
|
342
|
+
complete: "โ",
|
|
343
|
+
incomplete: "โ",
|
|
344
|
+
color: "cyan",
|
|
345
|
+
}),
|
|
268
346
|
);
|
|
269
347
|
```
|
|
270
348
|
|
|
271
349
|
### Tables
|
|
272
350
|
|
|
273
|
-
Create formatted tables:
|
|
351
|
+
Create formatted tables with headers and custom styling:
|
|
274
352
|
|
|
275
353
|
```typescript
|
|
276
354
|
import { table } from "chalk-ts";
|
|
277
355
|
|
|
278
356
|
const data = [
|
|
279
|
-
["John", "
|
|
280
|
-
["Jane", "
|
|
281
|
-
["Bob", "
|
|
357
|
+
["John Doe", "28", "Developer"],
|
|
358
|
+
["Jane Smith", "34", "Designer"],
|
|
359
|
+
["Bob Johnson", "45", "Manager"],
|
|
282
360
|
];
|
|
283
361
|
|
|
284
362
|
const headers = ["Name", "Age", "Role"];
|
|
285
363
|
|
|
364
|
+
// Table with headers
|
|
286
365
|
console.log(
|
|
287
366
|
table(data, {
|
|
288
367
|
headers,
|
|
289
368
|
headerColor: "cyan",
|
|
290
369
|
borderColor: "gray",
|
|
291
|
-
})
|
|
370
|
+
}),
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
// Table without headers
|
|
374
|
+
console.log(table(data));
|
|
375
|
+
|
|
376
|
+
// Custom styling
|
|
377
|
+
console.log(
|
|
378
|
+
table(data, {
|
|
379
|
+
headers,
|
|
380
|
+
headerColor: "yellow",
|
|
381
|
+
borderColor: "blue",
|
|
382
|
+
}),
|
|
292
383
|
);
|
|
293
384
|
```
|
|
294
385
|
|
|
@@ -301,8 +392,53 @@ import { spinner } from "chalk-ts";
|
|
|
301
392
|
|
|
302
393
|
// Display different frames
|
|
303
394
|
for (let i = 0; i < 10; i++) {
|
|
304
|
-
console.
|
|
395
|
+
console.clear();
|
|
396
|
+
console.log(spinner(i, "cyan") + " Loading...");
|
|
397
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
305
398
|
}
|
|
399
|
+
|
|
400
|
+
// Different colors
|
|
401
|
+
console.log(spinner(0, "green") + " Processing...");
|
|
402
|
+
console.log(spinner(1, "yellow") + " Working...");
|
|
403
|
+
console.log(spinner(2, "magenta") + " Please wait...");
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## ๐ฏ Semantic Theming
|
|
407
|
+
|
|
408
|
+
Create reusable theme configurations for consistent styling:
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
import { createTheme } from "chalk-ts";
|
|
412
|
+
import chalk from "chalk-ts";
|
|
413
|
+
|
|
414
|
+
// Define your theme
|
|
415
|
+
const theme = createTheme({
|
|
416
|
+
info: chalk.blue.bold,
|
|
417
|
+
success: chalk.green,
|
|
418
|
+
warning: chalk.yellow.bold,
|
|
419
|
+
error: chalk.red.bold.bgWhite,
|
|
420
|
+
debug: chalk.gray.dim,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// Use the theme
|
|
424
|
+
console.log(theme.info("Application started"));
|
|
425
|
+
console.log(theme.success("โ Task completed successfully"));
|
|
426
|
+
console.log(theme.warning("โ Warning: Low memory"));
|
|
427
|
+
console.log(theme.error("โ Error: Connection failed"));
|
|
428
|
+
console.log(theme.debug("Debug: Variable value = 42"));
|
|
429
|
+
|
|
430
|
+
// Themes can use any chalk styling
|
|
431
|
+
const fancyTheme = createTheme({
|
|
432
|
+
header: chalk.bold.underline.cyan,
|
|
433
|
+
subheader: chalk.italic.blue,
|
|
434
|
+
highlight: chalk.bgYellow.black.bold,
|
|
435
|
+
muted: chalk.dim.gray,
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
console.log(fancyTheme.header("Main Title"));
|
|
439
|
+
console.log(fancyTheme.subheader("Subtitle"));
|
|
440
|
+
console.log(fancyTheme.highlight("Important!"));
|
|
441
|
+
console.log(fancyTheme.muted("Less important"));
|
|
306
442
|
```
|
|
307
443
|
|
|
308
444
|
## ๐ Method Chaining
|
|
@@ -311,24 +447,29 @@ chalk-ts supports full method chaining for complex styling:
|
|
|
311
447
|
|
|
312
448
|
```typescript
|
|
313
449
|
// Combine multiple styles
|
|
314
|
-
console.log(
|
|
450
|
+
console.log(chalk.bold.red.bgYellow("Complex styling"));
|
|
315
451
|
|
|
316
|
-
// Chain with
|
|
317
|
-
console.log(
|
|
452
|
+
// Chain with TrueColor
|
|
453
|
+
console.log(chalk.bold.rgb(255, 100, 0).bgHex("#000000")("Custom chain"));
|
|
318
454
|
|
|
319
455
|
// Multiple text effects
|
|
320
|
-
console.log(
|
|
456
|
+
console.log(chalk.bold.italic.underline.red("All effects"));
|
|
457
|
+
|
|
458
|
+
// Nested styling
|
|
459
|
+
console.log(
|
|
460
|
+
chalk.blue("Blue text with " + chalk.red.bold("red bold") + " inside"),
|
|
461
|
+
);
|
|
321
462
|
```
|
|
322
463
|
|
|
323
|
-
## ๐ง
|
|
464
|
+
## ๐ง Utility Methods
|
|
324
465
|
|
|
325
466
|
### Strip ANSI Codes
|
|
326
467
|
|
|
327
468
|
Remove styling from text:
|
|
328
469
|
|
|
329
470
|
```typescript
|
|
330
|
-
const styled =
|
|
331
|
-
const plain =
|
|
471
|
+
const styled = chalk.red.bold("Styled text");
|
|
472
|
+
const plain = chalk.strip(styled);
|
|
332
473
|
console.log(plain); // 'Styled text'
|
|
333
474
|
```
|
|
334
475
|
|
|
@@ -337,56 +478,75 @@ console.log(plain); // 'Styled text'
|
|
|
337
478
|
Get the actual text length without ANSI codes:
|
|
338
479
|
|
|
339
480
|
```typescript
|
|
340
|
-
const styled =
|
|
341
|
-
console.log(styled.length); // Includes ANSI codes
|
|
342
|
-
console.log(
|
|
481
|
+
const styled = chalk.red.bold("Hello");
|
|
482
|
+
console.log(styled.length); // Includes ANSI codes (e.g., 23)
|
|
483
|
+
console.log(chalk.length(styled)); // 5 (actual text length)
|
|
343
484
|
```
|
|
344
485
|
|
|
345
486
|
### Template Literals
|
|
346
487
|
|
|
347
|
-
Support for template strings:
|
|
488
|
+
Support for template strings with embedded styling:
|
|
348
489
|
|
|
349
490
|
```typescript
|
|
350
491
|
const name = "World";
|
|
351
|
-
|
|
492
|
+
const greeting = chalk.template`Hello {red.bold ${name}}!`;
|
|
493
|
+
console.log(greeting);
|
|
494
|
+
|
|
495
|
+
// More complex templates
|
|
496
|
+
const status = "success";
|
|
497
|
+
const message = chalk.template`Status: {green.bold ${status}} - All systems operational`;
|
|
498
|
+
console.log(message);
|
|
352
499
|
```
|
|
353
500
|
|
|
354
|
-
|
|
501
|
+
## ๐ฎ Color Level Control
|
|
355
502
|
|
|
356
|
-
Control color output:
|
|
503
|
+
Control color output levels for different environments:
|
|
357
504
|
|
|
358
505
|
```typescript
|
|
359
506
|
import { ChalkTS } from "chalk-ts";
|
|
360
507
|
|
|
361
|
-
//
|
|
362
|
-
const noColors = new ChalkTS(
|
|
508
|
+
// Level 0: No colors
|
|
509
|
+
const noColors = new ChalkTS({ level: 0 });
|
|
363
510
|
console.log(noColors.red("Plain text"));
|
|
364
511
|
|
|
365
|
-
//
|
|
366
|
-
const
|
|
367
|
-
console.log(
|
|
512
|
+
// Level 1: Basic 16 colors
|
|
513
|
+
const basicColors = new ChalkTS({ level: 1 });
|
|
514
|
+
console.log(basicColors.red("Basic red"));
|
|
515
|
+
|
|
516
|
+
// Level 2: 256 colors
|
|
517
|
+
const extendedColors = new ChalkTS({ level: 2 });
|
|
518
|
+
console.log(extendedColors.rgb(255, 100, 0)("Downsampled to 256"));
|
|
519
|
+
|
|
520
|
+
// Level 3: TrueColor (16 million colors)
|
|
521
|
+
const trueColor = new ChalkTS({ level: 3 });
|
|
522
|
+
console.log(trueColor.rgb(255, 100, 0)("Full RGB"));
|
|
523
|
+
|
|
524
|
+
// Auto-detect (default)
|
|
525
|
+
import chalk from "chalk-ts";
|
|
526
|
+
console.log(chalk.red("Auto-detected color level"));
|
|
368
527
|
```
|
|
369
528
|
|
|
370
|
-
## ๐ Performance Comparison
|
|
529
|
+
## ๐ Performance & Comparison
|
|
371
530
|
|
|
372
531
|
chalk-ts is designed for performance while providing more features:
|
|
373
532
|
|
|
374
|
-
| Library | Bundle Size |
|
|
375
|
-
| --------- | ----------- |
|
|
376
|
-
| chalk-ts | ~15KB |
|
|
377
|
-
| Chalk | ~17KB |
|
|
378
|
-
| Colorette | ~8KB |
|
|
533
|
+
| Library | Bundle Size | Colors | Effects | Utilities | TypeScript | Tests |
|
|
534
|
+
| --------- | ----------- | ------ | ------- | --------- | ---------- | ----- |
|
|
535
|
+
| chalk-ts | ~15KB | 20+ | 6+ | 4+ | โญโญโญโญโญ | 98 |
|
|
536
|
+
| Chalk | ~17KB | 8 | 0 | 0 | โญโญโญโญ | - |
|
|
537
|
+
| Colorette | ~8KB | 8 | 0 | 0 | โญโญโญ | - |
|
|
379
538
|
|
|
380
539
|
### Why Choose chalk-ts?
|
|
381
540
|
|
|
382
|
-
1. **๐จ More Colors**: 20+ built-in colors
|
|
383
|
-
2. **๐ญ
|
|
384
|
-
3. **๐ ๏ธ
|
|
385
|
-
4.
|
|
386
|
-
5.
|
|
387
|
-
6.
|
|
388
|
-
7.
|
|
389
|
-
8.
|
|
541
|
+
1. **๐จ More Colors**: 20+ built-in colors + TrueColor support
|
|
542
|
+
2. **๐ญ Visual Effects**: Gradients, rainbow, pulse, neon, shadow, zebra
|
|
543
|
+
3. **๐ ๏ธ Built-in Utilities**: Tables, progress bars, boxes, spinners
|
|
544
|
+
4. **๐ฏ Theming**: Semantic theme system for consistent styling
|
|
545
|
+
5. **๐ Better Types**: Full TypeScript support with strict typing
|
|
546
|
+
6. **๐ฆ Modern Build**: ES modules, tree-shaking, zero dependencies
|
|
547
|
+
7. **๐งช Well Tested**: 98%+ coverage with 98 passing tests
|
|
548
|
+
8. **๐ Great Docs**: Comprehensive documentation + interactive demo
|
|
549
|
+
9. **๐ง Easy Migration**: Drop-in replacement for chalk
|
|
390
550
|
|
|
391
551
|
## ๐ Migration from Chalk
|
|
392
552
|
|
|
@@ -397,64 +557,187 @@ chalk-ts is designed as a drop-in replacement for chalk:
|
|
|
397
557
|
import chalk from "chalk";
|
|
398
558
|
console.log(chalk.red.bold("Hello"));
|
|
399
559
|
|
|
400
|
-
// After (chalk-ts)
|
|
401
|
-
import
|
|
402
|
-
console.log(
|
|
560
|
+
// After (chalk-ts) - same API!
|
|
561
|
+
import chalk from "chalk-ts";
|
|
562
|
+
console.log(chalk.red.bold("Hello"));
|
|
563
|
+
|
|
564
|
+
// Plus new features!
|
|
565
|
+
import { gradient, createTheme } from "chalk-ts";
|
|
566
|
+
console.log(gradient("Gradient!", ["#ff0000", "#0000ff"]));
|
|
403
567
|
```
|
|
404
568
|
|
|
405
|
-
Most chalk code will work without changes, but you'll get
|
|
569
|
+
Most chalk code will work without changes, but you'll get:
|
|
570
|
+
|
|
571
|
+
- โ
20+ additional colors
|
|
572
|
+
- โ
TrueColor (RGB/HEX/HSL) support
|
|
573
|
+
- โ
Visual effects (gradients, rainbow, etc.)
|
|
574
|
+
- โ
Built-in utilities (tables, boxes, etc.)
|
|
575
|
+
- โ
Semantic theming
|
|
576
|
+
- โ
Better TypeScript support
|
|
406
577
|
|
|
407
|
-
## ๐ API Reference
|
|
578
|
+
## ๐ Complete API Reference
|
|
408
579
|
|
|
409
580
|
### Basic Colors
|
|
410
581
|
|
|
411
|
-
|
|
412
|
-
|
|
582
|
+
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`
|
|
583
|
+
|
|
584
|
+
### Bright Colors
|
|
585
|
+
|
|
586
|
+
`redBright`, `greenBright`, `yellowBright`, `blueBright`, `magentaBright`, `cyanBright`, `whiteBright`
|
|
413
587
|
|
|
414
588
|
### Background Colors
|
|
415
589
|
|
|
416
|
-
|
|
417
|
-
|
|
590
|
+
`bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`, `bgGray`
|
|
591
|
+
|
|
592
|
+
### Bright Backgrounds
|
|
418
593
|
|
|
419
|
-
|
|
594
|
+
`bgRedBright`, `bgGreenBright`, `bgYellowBright`, `bgBlueBright`, `bgMagentaBright`, `bgCyanBright`, `bgWhiteBright`
|
|
420
595
|
|
|
421
|
-
|
|
596
|
+
### Extended Colors (20+)
|
|
597
|
+
|
|
598
|
+
`orange`, `purple`, `pink`, `brown`, `lime`, `indigo`, `violet`, `turquoise`, `gold`, `silver`, `crimson`, `navy`, `teal`, `olive`, `maroon`
|
|
422
599
|
|
|
423
600
|
### Text Styles
|
|
424
601
|
|
|
425
|
-
|
|
602
|
+
`bold`, `dim`, `italic`, `underline`, `blink`, `inverse`, `hidden`, `strikethrough`
|
|
426
603
|
|
|
427
|
-
###
|
|
604
|
+
### TrueColor Methods
|
|
428
605
|
|
|
429
|
-
- `rgb(r, g, b)
|
|
430
|
-
- `
|
|
431
|
-
- `
|
|
606
|
+
- `rgb(r, g, b)` - Foreground RGB color
|
|
607
|
+
- `bgRgb(r, g, b)` - Background RGB color
|
|
608
|
+
- `hex(color)` - Foreground HEX color
|
|
609
|
+
- `bgHex(color)` - Background HEX color
|
|
610
|
+
- `hsl(h, s, l)` - Foreground HSL color
|
|
611
|
+
- `bgHsl(h, s, l)` - Background HSL color
|
|
432
612
|
|
|
433
|
-
###
|
|
613
|
+
### Utility Methods
|
|
434
614
|
|
|
435
|
-
- `strip(text)` - Remove ANSI codes
|
|
615
|
+
- `strip(text)` - Remove ANSI codes from text
|
|
436
616
|
- `length(text)` - Get text length without ANSI codes
|
|
437
617
|
- `template` - Template literal support
|
|
438
618
|
|
|
439
|
-
### Effects
|
|
619
|
+
### Visual Effects
|
|
440
620
|
|
|
441
|
-
- `gradient(text,
|
|
442
|
-
- `rainbow(text)`
|
|
443
|
-
- `pulse(text, color?)`
|
|
444
|
-
- `zebra(text, color1?, color2?)`
|
|
445
|
-
- `neon(text, color?)`
|
|
446
|
-
- `shadow(text, color?, shadowColor?)`
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
- `
|
|
621
|
+
- `gradient(text, colors[])` - Multi-color gradient
|
|
622
|
+
- `rainbow(text)` - Rainbow effect
|
|
623
|
+
- `pulse(text, color?)` - Pulsing effect
|
|
624
|
+
- `zebra(text, color1?, color2?)` - Alternating colors
|
|
625
|
+
- `neon(text, color?)` - Neon glow effect
|
|
626
|
+
- `shadow(text, color?, shadowColor?)` - Shadow effect
|
|
627
|
+
|
|
628
|
+
### Utilities
|
|
629
|
+
|
|
630
|
+
- `box(text, options?)` - Create bordered box
|
|
631
|
+
- `progressBar(current, total, options?)` - Progress indicator
|
|
632
|
+
- `spinner(frame, color?)` - Loading spinner
|
|
633
|
+
- `table(data, options?)` - Formatted table
|
|
634
|
+
|
|
635
|
+
### Theming
|
|
636
|
+
|
|
637
|
+
- `createTheme(config)` - Create semantic theme
|
|
451
638
|
|
|
452
639
|
## ๐ Examples
|
|
453
640
|
|
|
454
|
-
|
|
641
|
+
### CLI Application
|
|
642
|
+
|
|
643
|
+
```typescript
|
|
644
|
+
import chalk from "chalk-ts";
|
|
645
|
+
import { box, progressBar, createTheme } from "chalk-ts";
|
|
646
|
+
|
|
647
|
+
const theme = createTheme({
|
|
648
|
+
info: chalk.blue.bold,
|
|
649
|
+
success: chalk.green.bold,
|
|
650
|
+
error: chalk.red.bold,
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
console.log(
|
|
654
|
+
box("My CLI App v1.0.0", {
|
|
655
|
+
padding: 1,
|
|
656
|
+
color: "cyan",
|
|
657
|
+
style: "rounded",
|
|
658
|
+
}),
|
|
659
|
+
);
|
|
660
|
+
|
|
661
|
+
console.log(theme.info("Starting installation..."));
|
|
662
|
+
console.log(progressBar(50, 100, { color: "cyan" }));
|
|
663
|
+
console.log(theme.success("โ Installation complete!"));
|
|
664
|
+
```
|
|
455
665
|
|
|
456
|
-
|
|
457
|
-
|
|
666
|
+
### Log System
|
|
667
|
+
|
|
668
|
+
```typescript
|
|
669
|
+
import chalk from "chalk-ts";
|
|
670
|
+
import { createTheme } from "chalk-ts";
|
|
671
|
+
|
|
672
|
+
const logTheme = createTheme({
|
|
673
|
+
debug: chalk.gray.dim,
|
|
674
|
+
info: chalk.blue,
|
|
675
|
+
warn: chalk.yellow.bold,
|
|
676
|
+
error: chalk.red.bold.bgWhite,
|
|
677
|
+
success: chalk.green.bold,
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
class Logger {
|
|
681
|
+
debug(msg: string) {
|
|
682
|
+
console.log(logTheme.debug(`[DEBUG] ${msg}`));
|
|
683
|
+
}
|
|
684
|
+
info(msg: string) {
|
|
685
|
+
console.log(logTheme.info(`[INFO] ${msg}`));
|
|
686
|
+
}
|
|
687
|
+
warn(msg: string) {
|
|
688
|
+
console.log(logTheme.warn(`[WARN] ${msg}`));
|
|
689
|
+
}
|
|
690
|
+
error(msg: string) {
|
|
691
|
+
console.log(logTheme.error(`[ERROR] ${msg}`));
|
|
692
|
+
}
|
|
693
|
+
success(msg: string) {
|
|
694
|
+
console.log(logTheme.success(`[SUCCESS] ${msg}`));
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const logger = new Logger();
|
|
699
|
+
logger.info("Application started");
|
|
700
|
+
logger.success("Connected to database");
|
|
701
|
+
logger.warn("High memory usage detected");
|
|
702
|
+
logger.error("Failed to load configuration");
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
### Data Visualization
|
|
706
|
+
|
|
707
|
+
```typescript
|
|
708
|
+
import { table, progressBar, gradient } from "chalk-ts";
|
|
709
|
+
|
|
710
|
+
// Sales report
|
|
711
|
+
const salesData = [
|
|
712
|
+
["Product A", "$1,234", "โ 15%"],
|
|
713
|
+
["Product B", "$2,456", "โ 23%"],
|
|
714
|
+
["Product C", "$987", "โ 5%"],
|
|
715
|
+
];
|
|
716
|
+
|
|
717
|
+
console.log(gradient("SALES REPORT", ["#00d4ff", "#7fffd4"]));
|
|
718
|
+
console.log(
|
|
719
|
+
table(salesData, {
|
|
720
|
+
headers: ["Product", "Revenue", "Change"],
|
|
721
|
+
headerColor: "cyan",
|
|
722
|
+
borderColor: "gray",
|
|
723
|
+
}),
|
|
724
|
+
);
|
|
725
|
+
|
|
726
|
+
console.log("\nQuarterly Progress:");
|
|
727
|
+
console.log(
|
|
728
|
+
progressBar(75, 100, {
|
|
729
|
+
width: 40,
|
|
730
|
+
color: "green",
|
|
731
|
+
complete: "โ",
|
|
732
|
+
incomplete: "โ",
|
|
733
|
+
}),
|
|
734
|
+
);
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
Check out more examples:
|
|
738
|
+
|
|
739
|
+
- [Complete Demo](./examples/demo.ts) - All features showcase
|
|
740
|
+
- [Web Demo](https://www.reactbd.com/npm-packages/chalk-ts-typescript) - Interactive browser demo
|
|
458
741
|
|
|
459
742
|
## ๐งช Testing
|
|
460
743
|
|
|
@@ -470,33 +753,61 @@ Run tests with coverage:
|
|
|
470
753
|
npm run test:coverage
|
|
471
754
|
```
|
|
472
755
|
|
|
756
|
+
Run demo:
|
|
757
|
+
|
|
758
|
+
```bash
|
|
759
|
+
npm run demo
|
|
760
|
+
```
|
|
761
|
+
|
|
473
762
|
## ๐ค Contributing
|
|
474
763
|
|
|
475
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
764
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
476
765
|
|
|
477
766
|
1. Fork the repository
|
|
478
|
-
2. Create your feature branch (`git checkout -b feature/
|
|
479
|
-
3. Commit your changes (`git commit -m 'Add some
|
|
480
|
-
4. Push to the branch (`git push origin feature/
|
|
767
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
768
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
769
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
481
770
|
5. Open a Pull Request
|
|
482
771
|
|
|
483
|
-
##
|
|
772
|
+
## ๐ License
|
|
484
773
|
|
|
485
|
-
|
|
774
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
486
775
|
|
|
487
776
|
## ๐ Acknowledgments
|
|
488
777
|
|
|
489
|
-
|
|
778
|
+
Inspired by:
|
|
779
|
+
|
|
780
|
+
- [chalk](https://github.com/chalk/chalk) - The original terminal styling library
|
|
490
781
|
- Thanks to all contributors and the open source community
|
|
491
782
|
|
|
492
783
|
## ๐ Support
|
|
493
784
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
-
|
|
785
|
+
If you have any questions or need help, please:
|
|
786
|
+
|
|
787
|
+
- ๐ **Homepage**: [reactbd.com/npm-packages/chalk-ts-typescript](https://www.reactbd.com/npm-packages/chalk-ts-typescript)
|
|
788
|
+
- ๐ฆ **NPM**: [npmjs.com/package/chalk-ts](https://www.npmjs.com/package/chalk-ts)
|
|
789
|
+
- ๐ป **GitHub**: [github.com/noorjsdivs/chalk-ts](https://github.com/noorjsdivs/chalk-ts)
|
|
790
|
+
- ๐ **Issues**: [GitHub Issues](https://github.com/noorjsdivs/chalk-ts/issues)
|
|
791
|
+
- ๐ฌ **Discussions**: [GitHub Discussions](https://github.com/noorjsdivs/chalk-ts/discussions)
|
|
792
|
+
- ๐ง **Email**: [dev.reactbd@gmail.com](mailto:dev.reactbd@gmail.com)
|
|
793
|
+
- ๐ฅ **YouTube**: [@reactjsBD](https://www.youtube.com/@reactjsBD)
|
|
794
|
+
|
|
795
|
+
## ๐ Show Your Support
|
|
796
|
+
|
|
797
|
+
If this library helped you, please give it a โญ๏ธ on GitHub!
|
|
798
|
+
|
|
799
|
+
You can also support the development of this project by buying me a coffee:
|
|
800
|
+
|
|
801
|
+
<a href="https://buymeacoffee.com/reactbd" target="_blank">
|
|
802
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" >
|
|
803
|
+
</a>
|
|
497
804
|
|
|
498
805
|
---
|
|
499
806
|
|
|
500
|
-
|
|
807
|
+
<div align="center">
|
|
808
|
+
|
|
809
|
+
[Made with โค๏ธ by Noor Mohammad](https://reactbd.com)
|
|
810
|
+
|
|
811
|
+
โญ **Star this repo if you find it useful!**
|
|
501
812
|
|
|
502
|
-
|
|
813
|
+
</div>
|