pencil-case 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ # pencil-case
2
+ An npm package for ANSI styling. Supports millions of colors and is open to customization.
3
+
4
+ ```js
5
+ console.log(black.redBg + "Roses are red," + regularBg + " " + blueBg + "violets are blue");
6
+ console.log("Oh, to be your " + green + "constant " + red + "companion");
7
+ ```
@@ -0,0 +1,2 @@
1
+ import { black, blackBg, blue, blueBg, cyan, cyanBg, green, greenBg, magenta, magentaBg, Pencil, red, redBg, regular, regularBg, white, whiteBg, yellow, yellowBg } from "./pencil.js";
2
+ export { black, blackBg, blue, blueBg, cyan, cyanBg, green, greenBg, magenta, magentaBg, Pencil, red, redBg, regular, regularBg, white, whiteBg, yellow, yellowBg };
@@ -0,0 +1,312 @@
1
+ class Pencil extends String {
2
+ _value;
3
+ /**
4
+ * Black foreground
5
+ *
6
+ * Raw value: ``
7
+ */
8
+ black;
9
+ /**
10
+ * Red foreground
11
+ *
12
+ * Raw value: ``
13
+ */
14
+ red;
15
+ /**
16
+ * Green foreground
17
+ *
18
+ * Raw value: ``
19
+ */
20
+ green;
21
+ /**
22
+ * Yellow foreground
23
+ *
24
+ * Raw value: ``
25
+ */
26
+ yellow;
27
+ /**
28
+ * Blue foreground
29
+ *
30
+ * Raw value: ``
31
+ */
32
+ blue;
33
+ /**
34
+ * Magenta/purple foreground
35
+ *
36
+ * Raw value: ``
37
+ */
38
+ magenta;
39
+ /**
40
+ * Cyan foreground
41
+ *
42
+ * Raw value: ``
43
+ */
44
+ cyan;
45
+ /**
46
+ * White foreground
47
+ *
48
+ * Raw value: ``
49
+ */
50
+ white;
51
+ /**
52
+ * Default foreground
53
+ *
54
+ * Raw value: ``
55
+ */
56
+ regular;
57
+ /**
58
+ * Black background
59
+ *
60
+ * Raw value: ``
61
+ */
62
+ blackBg;
63
+ /**
64
+ * Red background
65
+ *
66
+ * Raw value: ``
67
+ */
68
+ redBg;
69
+ /**
70
+ * Green background
71
+ *
72
+ * Raw value: ``
73
+ */
74
+ greenBg;
75
+ /**
76
+ * Yellow background
77
+ *
78
+ * Raw value: ``
79
+ */
80
+ yellowBg;
81
+ /**
82
+ * Blue background
83
+ *
84
+ * Raw value: ``
85
+ */
86
+ blueBg;
87
+ /**
88
+ * Magenta/purple background
89
+ *
90
+ * Raw value: ``
91
+ */
92
+ magentaBg;
93
+ /**
94
+ * Cyan background
95
+ *
96
+ * Raw value: ``
97
+ */
98
+ cyanBg;
99
+ /**
100
+ * White background
101
+ *
102
+ * Raw value: ``
103
+ */
104
+ whiteBg;
105
+ /**
106
+ * Default background
107
+ *
108
+ * Raw value: ``
109
+ */
110
+ regularBg;
111
+ /**
112
+ * Bold text
113
+ *
114
+ * Raw value: ``
115
+ *
116
+ * This property is also callable due to the `String` class having a `bold` method.
117
+ */
118
+ bold;
119
+ constructor(...args) {
120
+ const code = [3, 4].includes(args.length) ? `\x1b[${(args[4] ?? false) ? 4 : 3}8;2;${args[0]};${args[1]};${args[2]}m` : args[0];
121
+ super(code);
122
+ this._value = code;
123
+ Object.defineProperties(this, {
124
+ black: {
125
+ get: () => new Pencil(this._value + "\x1b[30m")
126
+ },
127
+ red: {
128
+ get: () => new Pencil(this._value + "\x1b[31m")
129
+ },
130
+ green: {
131
+ get: () => new Pencil(this._value + "\x1b[32m")
132
+ },
133
+ yellow: {
134
+ get: () => new Pencil(this._value + "\x1b[33m")
135
+ },
136
+ blue: {
137
+ get: () => new Pencil(this._value + "\x1b[34m")
138
+ },
139
+ magenta: {
140
+ get: () => new Pencil(this._value + "\x1b[35m")
141
+ },
142
+ cyan: {
143
+ get: () => new Pencil(this._value + "\x1b[36m")
144
+ },
145
+ white: {
146
+ get: () => new Pencil(this._value + "\x1b[37m")
147
+ },
148
+ regular: {
149
+ get: () => new Pencil(this._value + "\x1b[39m")
150
+ },
151
+ blackBg: {
152
+ get: () => new Pencil(this._value + "\x1b[40m")
153
+ },
154
+ redBg: {
155
+ get: () => new Pencil(this._value + "\x1b[41m")
156
+ },
157
+ greenBg: {
158
+ get: () => new Pencil(this._value + "\x1b[42m")
159
+ },
160
+ yellowBg: {
161
+ get: () => new Pencil(this._value + "\x1b[43m")
162
+ },
163
+ blueBg: {
164
+ get: () => new Pencil(this._value + "\x1b[44m")
165
+ },
166
+ magentaBg: {
167
+ get: () => new Pencil(this._value + "\x1b[45m")
168
+ },
169
+ cyanBg: {
170
+ get: () => new Pencil(this._value + "\x1b[46m")
171
+ },
172
+ whiteBg: {
173
+ get: () => new Pencil(this._value + "\x1b[47m")
174
+ },
175
+ regularBg: {
176
+ get: () => new Pencil(this._value + "\x1b[49m")
177
+ },
178
+ bold: {
179
+ get: () => {
180
+ const bold = this.toString().bold;
181
+ bold.toString = () => "\x1b[1m";
182
+ bold[Symbol.for("nodejs.util.inspect.custom")] = bold.toString;
183
+ return bold;
184
+ }
185
+ }
186
+ });
187
+ }
188
+ custom(...args) {
189
+ return [3, 4].includes(args.length) ? new Pencil(`${this._value}\x1b[${(args[4] ?? false) ? 4 : 3}8;2;${args[0]};${args[1]};${args[2]}m`) : args[0];
190
+ }
191
+ customBg(...args) {
192
+ return args.length === 3 ? new Pencil(`${this._value}\x1b[48;2;${args[0]};${args[1]};${args[2]}m`) : args[0];
193
+ }
194
+ [Symbol.for("nodejs.util.inspect.custom")]() {
195
+ return this.toString();
196
+ }
197
+ /**
198
+ * Returns the string representation of a Pencil.
199
+ */
200
+ toString() {
201
+ return this._value;
202
+ }
203
+ }
204
+ /**
205
+ * Black foreground
206
+ *
207
+ * Raw value: ``
208
+ */
209
+ const black = new Pencil("\x1b[30m");
210
+ /**
211
+ * Red foreground
212
+ *
213
+ * Raw value: ``
214
+ */
215
+ const red = new Pencil("\x1b[31m");
216
+ /**
217
+ * Green foreground
218
+ *
219
+ * Raw value: ``
220
+ */
221
+ const green = new Pencil("\x1b[32m");
222
+ /**
223
+ * Yellow foreground
224
+ *
225
+ * Raw value: ``
226
+ */
227
+ const yellow = new Pencil("\x1b[33m");
228
+ /**
229
+ * Blue foreground
230
+ *
231
+ * Raw value: ``
232
+ */
233
+ const blue = new Pencil("\x1b[34m");
234
+ /**
235
+ * Magenta/purple foreground
236
+ *
237
+ * Raw value: ``
238
+ */
239
+ const magenta = new Pencil("\x1b[35m");
240
+ /**
241
+ * Cyan foreground
242
+ *
243
+ * Raw value: ``
244
+ */
245
+ const cyan = new Pencil("\x1b[36m");
246
+ /**
247
+ * White foreground
248
+ *
249
+ * Raw value: ``
250
+ */
251
+ const white = new Pencil("\x1b[37m");
252
+ /**
253
+ * Default foreground
254
+ *
255
+ * Raw value: ``
256
+ */
257
+ const regular = new Pencil("\x1b[39m");
258
+ /**
259
+ * Black background
260
+ *
261
+ * Raw value: ``
262
+ */
263
+ const blackBg = new Pencil("\x1b[40m");
264
+ /**
265
+ * Red background
266
+ *
267
+ * Raw value: ``
268
+ */
269
+ const redBg = new Pencil("\x1b[41m");
270
+ /**
271
+ * Green background
272
+ *
273
+ * Raw value: ``
274
+ */
275
+ const greenBg = new Pencil("\x1b[42m");
276
+ /**
277
+ * Yellow background
278
+ *
279
+ * Raw value: ``
280
+ */
281
+ const yellowBg = new Pencil("\x1b[43m");
282
+ /**
283
+ * Blue background
284
+ *
285
+ * Raw value: ``
286
+ */
287
+ const blueBg = new Pencil("\x1b[44m");
288
+ /**
289
+ * Magenta/purple background
290
+ *
291
+ * Raw value: ``
292
+ */
293
+ const magentaBg = new Pencil("\x1b[45m");
294
+ /**
295
+ * Cyan background
296
+ *
297
+ * Raw value: ``
298
+ */
299
+ const cyanBg = new Pencil("\x1b[46m");
300
+ /**
301
+ * White background
302
+ *
303
+ * Raw value: ``
304
+ */
305
+ const whiteBg = new Pencil("\x1b[47m");
306
+ /**
307
+ * Default background
308
+ *
309
+ * Raw value: ``
310
+ */
311
+ const regularBg = new Pencil("\x1b[49m");
312
+ export { black, blackBg, blue, blueBg, cyan, cyanBg, green, greenBg, magenta, magentaBg, Pencil, red, redBg, regular, regularBg, white, whiteBg, yellow, yellowBg };
@@ -0,0 +1,2 @@
1
+ import { black, blackBg, blue, blueBg, cyan, cyanBg, green, greenBg, magenta, magentaBg, Pencil, red, redBg, regular, regularBg, white, whiteBg, yellow, yellowBg } from "./pencil.js";
2
+ export { black, blackBg, blue, blueBg, cyan, cyanBg, green, greenBg, magenta, magentaBg, Pencil, red, redBg, regular, regularBg, white, whiteBg, yellow, yellowBg };
@@ -0,0 +1,243 @@
1
+ type Numberish = number | `${number}`;
2
+ declare class Pencil extends String {
3
+ private _value;
4
+ /**
5
+ * Black foreground
6
+ *
7
+ * Raw value: ``
8
+ */
9
+ black: Pencil;
10
+ /**
11
+ * Red foreground
12
+ *
13
+ * Raw value: ``
14
+ */
15
+ red: Pencil;
16
+ /**
17
+ * Green foreground
18
+ *
19
+ * Raw value: ``
20
+ */
21
+ green: Pencil;
22
+ /**
23
+ * Yellow foreground
24
+ *
25
+ * Raw value: ``
26
+ */
27
+ yellow: Pencil;
28
+ /**
29
+ * Blue foreground
30
+ *
31
+ * Raw value: ``
32
+ */
33
+ blue: Pencil;
34
+ /**
35
+ * Magenta/purple foreground
36
+ *
37
+ * Raw value: ``
38
+ */
39
+ magenta: Pencil;
40
+ /**
41
+ * Cyan foreground
42
+ *
43
+ * Raw value: ``
44
+ */
45
+ cyan: Pencil;
46
+ /**
47
+ * White foreground
48
+ *
49
+ * Raw value: ``
50
+ */
51
+ white: Pencil;
52
+ /**
53
+ * Default foreground
54
+ *
55
+ * Raw value: ``
56
+ */
57
+ regular: Pencil;
58
+ /**
59
+ * Black background
60
+ *
61
+ * Raw value: ``
62
+ */
63
+ blackBg: Pencil;
64
+ /**
65
+ * Red background
66
+ *
67
+ * Raw value: ``
68
+ */
69
+ redBg: Pencil;
70
+ /**
71
+ * Green background
72
+ *
73
+ * Raw value: ``
74
+ */
75
+ greenBg: Pencil;
76
+ /**
77
+ * Yellow background
78
+ *
79
+ * Raw value: ``
80
+ */
81
+ yellowBg: Pencil;
82
+ /**
83
+ * Blue background
84
+ *
85
+ * Raw value: ``
86
+ */
87
+ blueBg: Pencil;
88
+ /**
89
+ * Magenta/purple background
90
+ *
91
+ * Raw value: ``
92
+ */
93
+ magentaBg: Pencil;
94
+ /**
95
+ * Cyan background
96
+ *
97
+ * Raw value: ``
98
+ */
99
+ cyanBg: Pencil;
100
+ /**
101
+ * White background
102
+ *
103
+ * Raw value: ``
104
+ */
105
+ whiteBg: Pencil;
106
+ /**
107
+ * Default background
108
+ *
109
+ * Raw value: ``
110
+ */
111
+ regularBg: Pencil;
112
+ /**
113
+ * Bold text
114
+ *
115
+ * Raw value: ``
116
+ *
117
+ * This property is also callable due to the `String` class having a `bold` method.
118
+ */
119
+ bold: Pencil & typeof String.prototype.bold;
120
+ constructor(
121
+ /**
122
+ * The value to return when `toString` is called.
123
+ */
124
+ code: string);
125
+ constructor(red: Numberish, green: Numberish, blue: Numberish, background?: boolean);
126
+ custom(pencil: Pencil): Pencil;
127
+ custom(red: Numberish, green: Numberish, blue: Numberish, background?: boolean): Pencil;
128
+ customBg(pencil: Pencil): Pencil;
129
+ customBg(red: Numberish, green: Numberish, blue: Numberish): Pencil;
130
+ /**
131
+ * Returns the string representation of a Pencil.
132
+ */
133
+ toString(): string;
134
+ }
135
+ /**
136
+ * Black foreground
137
+ *
138
+ * Raw value: ``
139
+ */
140
+ declare const black: Pencil;
141
+ /**
142
+ * Red foreground
143
+ *
144
+ * Raw value: ``
145
+ */
146
+ declare const red: Pencil;
147
+ /**
148
+ * Green foreground
149
+ *
150
+ * Raw value: ``
151
+ */
152
+ declare const green: Pencil;
153
+ /**
154
+ * Yellow foreground
155
+ *
156
+ * Raw value: ``
157
+ */
158
+ declare const yellow: Pencil;
159
+ /**
160
+ * Blue foreground
161
+ *
162
+ * Raw value: ``
163
+ */
164
+ declare const blue: Pencil;
165
+ /**
166
+ * Magenta/purple foreground
167
+ *
168
+ * Raw value: ``
169
+ */
170
+ declare const magenta: Pencil;
171
+ /**
172
+ * Cyan foreground
173
+ *
174
+ * Raw value: ``
175
+ */
176
+ declare const cyan: Pencil;
177
+ /**
178
+ * White foreground
179
+ *
180
+ * Raw value: ``
181
+ */
182
+ declare const white: Pencil;
183
+ /**
184
+ * Default foreground
185
+ *
186
+ * Raw value: ``
187
+ */
188
+ declare const regular: Pencil;
189
+ /**
190
+ * Black background
191
+ *
192
+ * Raw value: ``
193
+ */
194
+ declare const blackBg: Pencil;
195
+ /**
196
+ * Red background
197
+ *
198
+ * Raw value: ``
199
+ */
200
+ declare const redBg: Pencil;
201
+ /**
202
+ * Green background
203
+ *
204
+ * Raw value: ``
205
+ */
206
+ declare const greenBg: Pencil;
207
+ /**
208
+ * Yellow background
209
+ *
210
+ * Raw value: ``
211
+ */
212
+ declare const yellowBg: Pencil;
213
+ /**
214
+ * Blue background
215
+ *
216
+ * Raw value: ``
217
+ */
218
+ declare const blueBg: Pencil;
219
+ /**
220
+ * Magenta/purple background
221
+ *
222
+ * Raw value: ``
223
+ */
224
+ declare const magentaBg: Pencil;
225
+ /**
226
+ * Cyan background
227
+ *
228
+ * Raw value: ``
229
+ */
230
+ declare const cyanBg: Pencil;
231
+ /**
232
+ * White background
233
+ *
234
+ * Raw value: ``
235
+ */
236
+ declare const whiteBg: Pencil;
237
+ /**
238
+ * Default background
239
+ *
240
+ * Raw value: ``
241
+ */
242
+ declare const regularBg: Pencil;
243
+ export { black, blackBg, blue, blueBg, cyan, cyanBg, green, greenBg, magenta, magentaBg, Pencil, red, redBg, regular, regularBg, white, whiteBg, yellow, yellowBg };
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "pencil-case",
3
+ "description": "An npm package for ANSI styling",
4
+ "version": "0.1.0",
5
+ "main": "dist/src/index.js",
6
+ "types": "dist/types/src/index.d.ts",
7
+ "type": "module",
8
+ "devDependencies": {
9
+ "typescript": "^5.9.3"
10
+ }
11
+ }
package/src/index.ts ADDED
@@ -0,0 +1,55 @@
1
+ import {
2
+ black,
3
+ blackBg,
4
+ blinking,
5
+ blue,
6
+ blueBg,
7
+ bold,
8
+ cyan,
9
+ cyanBg,
10
+ dim,
11
+ green,
12
+ greenBg,
13
+ italic,
14
+ magenta,
15
+ magentaBg,
16
+ Pencil,
17
+ red,
18
+ redBg,
19
+ regular,
20
+ regularBg,
21
+ strikethrough,
22
+ underlined,
23
+ white,
24
+ whiteBg,
25
+ yellow,
26
+ yellowBg
27
+ } from "./pencil.js";
28
+
29
+ export {
30
+ black,
31
+ blackBg,
32
+ blinking,
33
+ blue,
34
+ blueBg,
35
+ bold,
36
+ cyan,
37
+ cyanBg,
38
+ dim,
39
+ green,
40
+ greenBg,
41
+ italic,
42
+ magenta,
43
+ magentaBg,
44
+ Pencil,
45
+ red,
46
+ redBg,
47
+ regular,
48
+ regularBg,
49
+ strikethrough,
50
+ underlined,
51
+ white,
52
+ whiteBg,
53
+ yellow,
54
+ yellowBg
55
+ };
package/src/pencil.ts ADDED
@@ -0,0 +1,453 @@
1
+ type Numberish = number | `${number}`;
2
+
3
+ class Pencil extends String {
4
+ private _value: string;
5
+ /**
6
+ * Black foreground
7
+ *
8
+ * Raw value: ``
9
+ */
10
+ black: Pencil;
11
+ /**
12
+ * Red foreground
13
+ *
14
+ * Raw value: ``
15
+ */
16
+ red: Pencil;
17
+ /**
18
+ * Green foreground
19
+ *
20
+ * Raw value: ``
21
+ */
22
+ green: Pencil;
23
+ /**
24
+ * Yellow foreground
25
+ *
26
+ * Raw value: ``
27
+ */
28
+ yellow: Pencil;
29
+ /**
30
+ * Blue foreground
31
+ *
32
+ * Raw value: ``
33
+ */
34
+ blue: Pencil;
35
+ /**
36
+ * Magenta/purple foreground
37
+ *
38
+ * Raw value: ``
39
+ */
40
+ magenta: Pencil;
41
+ /**
42
+ * Cyan foreground
43
+ *
44
+ * Raw value: ``
45
+ */
46
+ cyan: Pencil;
47
+ /**
48
+ * White foreground
49
+ *
50
+ * Raw value: ``
51
+ */
52
+ white: Pencil;
53
+ /**
54
+ * Default foreground
55
+ *
56
+ * Raw value: ``
57
+ */
58
+ regular: Pencil;
59
+ /**
60
+ * Black background
61
+ *
62
+ * Raw value: ``
63
+ */
64
+ blackBg: Pencil;
65
+ /**
66
+ * Red background
67
+ *
68
+ * Raw value: ``
69
+ */
70
+ redBg: Pencil;
71
+ /**
72
+ * Green background
73
+ *
74
+ * Raw value: ``
75
+ */
76
+ greenBg: Pencil;
77
+ /**
78
+ * Yellow background
79
+ *
80
+ * Raw value: ``
81
+ */
82
+ yellowBg: Pencil;
83
+ /**
84
+ * Blue background
85
+ *
86
+ * Raw value: ``
87
+ */
88
+ blueBg: Pencil;
89
+ /**
90
+ * Magenta/purple background
91
+ *
92
+ * Raw value: ``
93
+ */
94
+ magentaBg: Pencil;
95
+ /**
96
+ * Cyan background
97
+ *
98
+ * Raw value: ``
99
+ */
100
+ cyanBg: Pencil;
101
+ /**
102
+ * White background
103
+ *
104
+ * Raw value: ``
105
+ */
106
+ whiteBg: Pencil;
107
+ /**
108
+ * Default background
109
+ *
110
+ * Raw value: ``
111
+ */
112
+ regularBg: Pencil;
113
+ /**
114
+ * Bold text
115
+ *
116
+ * Raw value: ``
117
+ *
118
+ * This property is also callable due to the `String` class having a `bold` method.
119
+ */
120
+ bold: Pencil & typeof String.prototype.bold;
121
+ /**
122
+ * Dim text
123
+ *
124
+ * Raw value: ``
125
+ */
126
+ dim: Pencil;
127
+ /**
128
+ * Italic text
129
+ *
130
+ * Raw value: ``
131
+ */
132
+ italic: Pencil;
133
+ /**
134
+ * Underlined text
135
+ *
136
+ * Raw value: ``
137
+ */
138
+ underlined: Pencil;
139
+ /**
140
+ * Blinking text
141
+ *
142
+ * Raw value: ``
143
+ */
144
+ blinking: Pencil;
145
+ /**
146
+ * Strikethrough text
147
+ *
148
+ * Raw value: ``
149
+ */
150
+ strikethrough: Pencil;
151
+
152
+ public constructor(
153
+ /**
154
+ * The value to return when `toString` is called.
155
+ */
156
+ code: string
157
+ );
158
+ public constructor(
159
+ red: Numberish,
160
+ green: Numberish,
161
+ blue: Numberish,
162
+ background?: boolean
163
+ );
164
+ constructor(...args: any[]) {
165
+ const code = [3, 4].includes(args.length) ? `\x1b[${(args[4] ?? false) ? 4 : 3}8;2;${args[0]};${args[1]};${args[2]}m` : args[0];
166
+ super(code);
167
+ this._value = code;
168
+ Object.defineProperties(this, {
169
+ black: {
170
+ get: () => new Pencil(this._value + "\x1b[30m")
171
+ },
172
+ red: {
173
+ get: () => new Pencil(this._value + "\x1b[31m")
174
+ },
175
+ green: {
176
+ get: () => new Pencil(this._value + "\x1b[32m")
177
+ },
178
+ yellow: {
179
+ get: () => new Pencil(this._value + "\x1b[33m")
180
+ },
181
+ blue: {
182
+ get: () => new Pencil(this._value + "\x1b[34m")
183
+ },
184
+ magenta: {
185
+ get: () => new Pencil(this._value + "\x1b[35m")
186
+ },
187
+ cyan: {
188
+ get: () => new Pencil(this._value + "\x1b[36m")
189
+ },
190
+ white: {
191
+ get: () => new Pencil(this._value + "\x1b[37m")
192
+ },
193
+ regular: {
194
+ get: () => new Pencil(this._value + "\x1b[39m")
195
+ },
196
+ blackBg: {
197
+ get: () => new Pencil(this._value + "\x1b[40m")
198
+ },
199
+ redBg: {
200
+ get: () => new Pencil(this._value + "\x1b[41m")
201
+ },
202
+ greenBg: {
203
+ get: () => new Pencil(this._value + "\x1b[42m")
204
+ },
205
+ yellowBg: {
206
+ get: () => new Pencil(this._value + "\x1b[43m")
207
+ },
208
+ blueBg: {
209
+ get: () => new Pencil(this._value + "\x1b[44m")
210
+ },
211
+ magentaBg: {
212
+ get: () => new Pencil(this._value + "\x1b[45m")
213
+ },
214
+ cyanBg: {
215
+ get: () => new Pencil(this._value + "\x1b[46m")
216
+ },
217
+ whiteBg: {
218
+ get: () => new Pencil(this._value + "\x1b[47m")
219
+ },
220
+ regularBg: {
221
+ get: () => new Pencil(this._value + "\x1b[49m")
222
+ },
223
+ bold: {
224
+ get: () => {
225
+ const bold = this.toString().bold;
226
+ bold.toString = () => "\x1b[1m";
227
+ bold[Symbol.for("nodejs.util.inspect.custom")] = bold.toString;
228
+ return bold;
229
+ }
230
+ },
231
+ dim: {
232
+ get: () => new Pencil(this._value + "\x1b[2m")
233
+ },
234
+ italic: {
235
+ get: () => new Pencil(this._value + "\x1b[3m")
236
+ },
237
+ underlined: {
238
+ get: () => new Pencil(this._value + "\x1b[4m")
239
+ },
240
+ blinking: {
241
+ get: () => new Pencil(this._value + "\x1b[5m")
242
+ },
243
+ strikethrough: {
244
+ get: () => new Pencil(this._value + "\x1b[9m")
245
+ }
246
+ });
247
+ }
248
+
249
+ custom(pencil: Pencil): Pencil;
250
+ custom(
251
+ red: Numberish,
252
+ green: Numberish,
253
+ blue: Numberish,
254
+ background?: boolean
255
+ ): Pencil;
256
+ custom(...args: any[]): Pencil {
257
+ return [3, 4].includes(args.length) ? new Pencil(`${this._value}\x1b[${(args[4] ?? false) ? 4 : 3}8;2;${args[0]};${args[1]};${args[2]}m`) : args[0];
258
+ }
259
+
260
+ customBg(pencil: Pencil): Pencil;
261
+ customBg(
262
+ red: Numberish,
263
+ green: Numberish,
264
+ blue: Numberish
265
+ ): Pencil;
266
+ customBg(...args: any[]): Pencil {
267
+ return args.length === 3 ? new Pencil(`${this._value}\x1b[48;2;${args[0]};${args[1]};${args[2]}m`) : args[0];
268
+ }
269
+
270
+ [Symbol.for("nodejs.util.inspect.custom")]() {
271
+ return this.toString();
272
+ }
273
+
274
+ /**
275
+ * Returns the string representation of a Pencil.
276
+ */
277
+ override toString(): string {
278
+ return this._value;
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Black foreground
284
+ *
285
+ * Raw value: ``
286
+ */
287
+ const black = new Pencil("\x1b[30m");
288
+ /**
289
+ * Red foreground
290
+ *
291
+ * Raw value: ``
292
+ */
293
+ const red = new Pencil("\x1b[31m");
294
+ /**
295
+ * Green foreground
296
+ *
297
+ * Raw value: ``
298
+ */
299
+ const green = new Pencil("\x1b[32m");
300
+ /**
301
+ * Yellow foreground
302
+ *
303
+ * Raw value: ``
304
+ */
305
+ const yellow = new Pencil("\x1b[33m");
306
+ /**
307
+ * Blue foreground
308
+ *
309
+ * Raw value: ``
310
+ */
311
+ const blue = new Pencil("\x1b[34m");
312
+ /**
313
+ * Magenta/purple foreground
314
+ *
315
+ * Raw value: ``
316
+ */
317
+ const magenta = new Pencil("\x1b[35m");
318
+ /**
319
+ * Cyan foreground
320
+ *
321
+ * Raw value: ``
322
+ */
323
+ const cyan = new Pencil("\x1b[36m");
324
+ /**
325
+ * White foreground
326
+ *
327
+ * Raw value: ``
328
+ */
329
+ const white = new Pencil("\x1b[37m");
330
+ /**
331
+ * Default foreground
332
+ *
333
+ * Raw value: ``
334
+ */
335
+ const regular = new Pencil("\x1b[39m");
336
+ /**
337
+ * Black background
338
+ *
339
+ * Raw value: ``
340
+ */
341
+ const blackBg = new Pencil("\x1b[40m");
342
+ /**
343
+ * Red background
344
+ *
345
+ * Raw value: ``
346
+ */
347
+ const redBg = new Pencil("\x1b[41m");
348
+ /**
349
+ * Green background
350
+ *
351
+ * Raw value: ``
352
+ */
353
+ const greenBg = new Pencil("\x1b[42m");
354
+ /**
355
+ * Yellow background
356
+ *
357
+ * Raw value: ``
358
+ */
359
+ const yellowBg = new Pencil("\x1b[43m");
360
+ /**
361
+ * Blue background
362
+ *
363
+ * Raw value: ``
364
+ */
365
+ const blueBg = new Pencil("\x1b[44m");
366
+ /**
367
+ * Magenta/purple background
368
+ *
369
+ * Raw value: ``
370
+ */
371
+ const magentaBg = new Pencil("\x1b[45m");
372
+ /**
373
+ * Cyan background
374
+ *
375
+ * Raw value: ``
376
+ */
377
+ const cyanBg = new Pencil("\x1b[46m");
378
+ /**
379
+ * White background
380
+ *
381
+ * Raw value: ``
382
+ */
383
+ const whiteBg = new Pencil("\x1b[47m");
384
+ /**
385
+ * Default background
386
+ *
387
+ * Raw value: ``
388
+ */
389
+ const regularBg = new Pencil("\x1b[49m");
390
+ /**
391
+ * Bold text
392
+ *
393
+ * Raw value: ``
394
+ */
395
+ const bold = new Pencil("\x1b[1m");
396
+ /**
397
+ * Dim text
398
+ *
399
+ * Raw value: ``
400
+ */
401
+ const dim = new Pencil("\x1b[2m");
402
+ /**
403
+ * Italic text
404
+ *
405
+ * Raw value: ``
406
+ */
407
+ const italic = new Pencil("\x1b[3m");
408
+ /**
409
+ * Underlined text
410
+ *
411
+ * Raw value: ``
412
+ */
413
+ const underlined = new Pencil("\x1b[4m");
414
+ /**
415
+ * Blinking text
416
+ *
417
+ * Raw value: ``
418
+ */
419
+ const blinking = new Pencil("\x1b[5m");
420
+ /**
421
+ * Strikethrough text
422
+ *
423
+ * Raw value: ``
424
+ */
425
+ const strikethrough = new Pencil("\x1b[9m");
426
+
427
+ export {
428
+ black,
429
+ blackBg,
430
+ blinking,
431
+ blue,
432
+ blueBg,
433
+ bold,
434
+ cyan,
435
+ cyanBg,
436
+ dim,
437
+ green,
438
+ greenBg,
439
+ italic,
440
+ magenta,
441
+ magentaBg,
442
+ Pencil,
443
+ red,
444
+ redBg,
445
+ regular,
446
+ regularBg,
447
+ strikethrough,
448
+ underlined,
449
+ white,
450
+ whiteBg,
451
+ yellow,
452
+ yellowBg
453
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationDir": "dist/types",
5
+ "module": "nodenext",
6
+ "outDir": "dist",
7
+ "rootDir": "."
8
+ }
9
+ }