ahmedelgabri 8.0.5 → 8.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.
@@ -1,564 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
3
- // This module is browser compatible.
4
- // A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
5
- // on npm.
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || function (mod) {
23
- if (mod && mod.__esModule) return mod;
24
- var result = {};
25
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
- __setModuleDefault(result, mod);
27
- return result;
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.stripAnsiCode = exports.stripColor = exports.bgRgb24 = exports.rgb24 = exports.bgRgb8 = exports.rgb8 = exports.bgBrightWhite = exports.bgBrightCyan = exports.bgBrightMagenta = exports.bgBrightBlue = exports.bgBrightYellow = exports.bgBrightGreen = exports.bgBrightRed = exports.bgBrightBlack = exports.bgWhite = exports.bgCyan = exports.bgMagenta = exports.bgBlue = exports.bgYellow = exports.bgGreen = exports.bgRed = exports.bgBlack = exports.brightWhite = exports.brightCyan = exports.brightMagenta = exports.brightBlue = exports.brightYellow = exports.brightGreen = exports.brightRed = exports.brightBlack = exports.gray = exports.white = exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = exports.black = exports.strikethrough = exports.hidden = exports.inverse = exports.underline = exports.italic = exports.dim = exports.bold = exports.reset = exports.getColorEnabled = exports.setColorEnabled = void 0;
31
- /**
32
- * String formatters and utilities for dealing with ANSI color codes.
33
- *
34
- * This module is browser compatible.
35
- *
36
- * This module supports `NO_COLOR` environmental variable disabling any coloring
37
- * if `NO_COLOR` is set.
38
- *
39
- * @example
40
- * ```ts
41
- * import {
42
- * bgBlue,
43
- * bgRgb24,
44
- * bgRgb8,
45
- * bold,
46
- * italic,
47
- * red,
48
- * rgb24,
49
- * rgb8,
50
- * } from "@std/fmt/colors";
51
- *
52
- * console.log(bgBlue(italic(red(bold("Hello, World!")))));
53
- *
54
- * // also supports 8bit colors
55
- *
56
- * console.log(rgb8("Hello, World!", 42));
57
- *
58
- * console.log(bgRgb8("Hello, World!", 42));
59
- *
60
- * // and 24bit rgb
61
- *
62
- * console.log(rgb24("Hello, World!", {
63
- * r: 41,
64
- * g: 42,
65
- * b: 43,
66
- * }));
67
- *
68
- * console.log(bgRgb24("Hello, World!", {
69
- * r: 41,
70
- * g: 42,
71
- * b: 43,
72
- * }));
73
- * ```
74
- *
75
- * @module
76
- */
77
- // deno-lint-ignore no-explicit-any
78
- const dntShim = __importStar(require("../../../../../_dnt.shims.js"));
79
- const { Deno } = dntShim.dntGlobalThis;
80
- const noColor = typeof Deno?.noColor === "boolean"
81
- ? Deno.noColor
82
- : false;
83
- let enabled = !noColor;
84
- /**
85
- * Set changing text color to enabled or disabled
86
- * @param value
87
- */
88
- function setColorEnabled(value) {
89
- if (Deno?.noColor) {
90
- return;
91
- }
92
- enabled = value;
93
- }
94
- exports.setColorEnabled = setColorEnabled;
95
- /** Get whether text color change is enabled or disabled. */
96
- function getColorEnabled() {
97
- return enabled;
98
- }
99
- exports.getColorEnabled = getColorEnabled;
100
- /**
101
- * Builds color code
102
- * @param open
103
- * @param close
104
- */
105
- function code(open, close) {
106
- return {
107
- open: `\x1b[${open.join(";")}m`,
108
- close: `\x1b[${close}m`,
109
- regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
110
- };
111
- }
112
- /**
113
- * Applies color and background based on color code and its associated text
114
- * @param str text to apply color settings to
115
- * @param code color code to apply
116
- */
117
- function run(str, code) {
118
- return enabled
119
- ? `${code.open}${str.replace(code.regexp, code.open)}${code.close}`
120
- : str;
121
- }
122
- /**
123
- * Reset the text modified.
124
- * @param str text to reset
125
- */
126
- function reset(str) {
127
- return run(str, code([0], 0));
128
- }
129
- exports.reset = reset;
130
- /**
131
- * Make the text bold.
132
- * @param str text to make bold
133
- */
134
- function bold(str) {
135
- return run(str, code([1], 22));
136
- }
137
- exports.bold = bold;
138
- /**
139
- * The text emits only a small amount of light.
140
- * @param str text to dim
141
- *
142
- * Warning: Not all terminal emulators support `dim`.
143
- * For compatibility across all terminals, use {@linkcode gray} or {@linkcode brightBlack} instead.
144
- */
145
- function dim(str) {
146
- return run(str, code([2], 22));
147
- }
148
- exports.dim = dim;
149
- /**
150
- * Make the text italic.
151
- * @param str text to make italic
152
- */
153
- function italic(str) {
154
- return run(str, code([3], 23));
155
- }
156
- exports.italic = italic;
157
- /**
158
- * Make the text underline.
159
- * @param str text to underline
160
- */
161
- function underline(str) {
162
- return run(str, code([4], 24));
163
- }
164
- exports.underline = underline;
165
- /**
166
- * Invert background color and text color.
167
- * @param str text to invert its color
168
- */
169
- function inverse(str) {
170
- return run(str, code([7], 27));
171
- }
172
- exports.inverse = inverse;
173
- /**
174
- * Make the text hidden.
175
- * @param str text to hide
176
- */
177
- function hidden(str) {
178
- return run(str, code([8], 28));
179
- }
180
- exports.hidden = hidden;
181
- /**
182
- * Put horizontal line through the center of the text.
183
- * @param str text to strike through
184
- */
185
- function strikethrough(str) {
186
- return run(str, code([9], 29));
187
- }
188
- exports.strikethrough = strikethrough;
189
- /**
190
- * Set text color to black.
191
- * @param str text to make black
192
- */
193
- function black(str) {
194
- return run(str, code([30], 39));
195
- }
196
- exports.black = black;
197
- /**
198
- * Set text color to red.
199
- * @param str text to make red
200
- */
201
- function red(str) {
202
- return run(str, code([31], 39));
203
- }
204
- exports.red = red;
205
- /**
206
- * Set text color to green.
207
- * @param str text to make green
208
- */
209
- function green(str) {
210
- return run(str, code([32], 39));
211
- }
212
- exports.green = green;
213
- /**
214
- * Set text color to yellow.
215
- * @param str text to make yellow
216
- */
217
- function yellow(str) {
218
- return run(str, code([33], 39));
219
- }
220
- exports.yellow = yellow;
221
- /**
222
- * Set text color to blue.
223
- * @param str text to make blue
224
- */
225
- function blue(str) {
226
- return run(str, code([34], 39));
227
- }
228
- exports.blue = blue;
229
- /**
230
- * Set text color to magenta.
231
- * @param str text to make magenta
232
- */
233
- function magenta(str) {
234
- return run(str, code([35], 39));
235
- }
236
- exports.magenta = magenta;
237
- /**
238
- * Set text color to cyan.
239
- * @param str text to make cyan
240
- */
241
- function cyan(str) {
242
- return run(str, code([36], 39));
243
- }
244
- exports.cyan = cyan;
245
- /**
246
- * Set text color to white.
247
- * @param str text to make white
248
- */
249
- function white(str) {
250
- return run(str, code([37], 39));
251
- }
252
- exports.white = white;
253
- /**
254
- * Set text color to gray.
255
- * @param str text to make gray
256
- */
257
- function gray(str) {
258
- return brightBlack(str);
259
- }
260
- exports.gray = gray;
261
- /**
262
- * Set text color to bright black.
263
- * @param str text to make bright-black
264
- */
265
- function brightBlack(str) {
266
- return run(str, code([90], 39));
267
- }
268
- exports.brightBlack = brightBlack;
269
- /**
270
- * Set text color to bright red.
271
- * @param str text to make bright-red
272
- */
273
- function brightRed(str) {
274
- return run(str, code([91], 39));
275
- }
276
- exports.brightRed = brightRed;
277
- /**
278
- * Set text color to bright green.
279
- * @param str text to make bright-green
280
- */
281
- function brightGreen(str) {
282
- return run(str, code([92], 39));
283
- }
284
- exports.brightGreen = brightGreen;
285
- /**
286
- * Set text color to bright yellow.
287
- * @param str text to make bright-yellow
288
- */
289
- function brightYellow(str) {
290
- return run(str, code([93], 39));
291
- }
292
- exports.brightYellow = brightYellow;
293
- /**
294
- * Set text color to bright blue.
295
- * @param str text to make bright-blue
296
- */
297
- function brightBlue(str) {
298
- return run(str, code([94], 39));
299
- }
300
- exports.brightBlue = brightBlue;
301
- /**
302
- * Set text color to bright magenta.
303
- * @param str text to make bright-magenta
304
- */
305
- function brightMagenta(str) {
306
- return run(str, code([95], 39));
307
- }
308
- exports.brightMagenta = brightMagenta;
309
- /**
310
- * Set text color to bright cyan.
311
- * @param str text to make bright-cyan
312
- */
313
- function brightCyan(str) {
314
- return run(str, code([96], 39));
315
- }
316
- exports.brightCyan = brightCyan;
317
- /**
318
- * Set text color to bright white.
319
- * @param str text to make bright-white
320
- */
321
- function brightWhite(str) {
322
- return run(str, code([97], 39));
323
- }
324
- exports.brightWhite = brightWhite;
325
- /**
326
- * Set background color to black.
327
- * @param str text to make its background black
328
- */
329
- function bgBlack(str) {
330
- return run(str, code([40], 49));
331
- }
332
- exports.bgBlack = bgBlack;
333
- /**
334
- * Set background color to red.
335
- * @param str text to make its background red
336
- */
337
- function bgRed(str) {
338
- return run(str, code([41], 49));
339
- }
340
- exports.bgRed = bgRed;
341
- /**
342
- * Set background color to green.
343
- * @param str text to make its background green
344
- */
345
- function bgGreen(str) {
346
- return run(str, code([42], 49));
347
- }
348
- exports.bgGreen = bgGreen;
349
- /**
350
- * Set background color to yellow.
351
- * @param str text to make its background yellow
352
- */
353
- function bgYellow(str) {
354
- return run(str, code([43], 49));
355
- }
356
- exports.bgYellow = bgYellow;
357
- /**
358
- * Set background color to blue.
359
- * @param str text to make its background blue
360
- */
361
- function bgBlue(str) {
362
- return run(str, code([44], 49));
363
- }
364
- exports.bgBlue = bgBlue;
365
- /**
366
- * Set background color to magenta.
367
- * @param str text to make its background magenta
368
- */
369
- function bgMagenta(str) {
370
- return run(str, code([45], 49));
371
- }
372
- exports.bgMagenta = bgMagenta;
373
- /**
374
- * Set background color to cyan.
375
- * @param str text to make its background cyan
376
- */
377
- function bgCyan(str) {
378
- return run(str, code([46], 49));
379
- }
380
- exports.bgCyan = bgCyan;
381
- /**
382
- * Set background color to white.
383
- * @param str text to make its background white
384
- */
385
- function bgWhite(str) {
386
- return run(str, code([47], 49));
387
- }
388
- exports.bgWhite = bgWhite;
389
- /**
390
- * Set background color to bright black.
391
- * @param str text to make its background bright-black
392
- */
393
- function bgBrightBlack(str) {
394
- return run(str, code([100], 49));
395
- }
396
- exports.bgBrightBlack = bgBrightBlack;
397
- /**
398
- * Set background color to bright red.
399
- * @param str text to make its background bright-red
400
- */
401
- function bgBrightRed(str) {
402
- return run(str, code([101], 49));
403
- }
404
- exports.bgBrightRed = bgBrightRed;
405
- /**
406
- * Set background color to bright green.
407
- * @param str text to make its background bright-green
408
- */
409
- function bgBrightGreen(str) {
410
- return run(str, code([102], 49));
411
- }
412
- exports.bgBrightGreen = bgBrightGreen;
413
- /**
414
- * Set background color to bright yellow.
415
- * @param str text to make its background bright-yellow
416
- */
417
- function bgBrightYellow(str) {
418
- return run(str, code([103], 49));
419
- }
420
- exports.bgBrightYellow = bgBrightYellow;
421
- /**
422
- * Set background color to bright blue.
423
- * @param str text to make its background bright-blue
424
- */
425
- function bgBrightBlue(str) {
426
- return run(str, code([104], 49));
427
- }
428
- exports.bgBrightBlue = bgBrightBlue;
429
- /**
430
- * Set background color to bright magenta.
431
- * @param str text to make its background bright-magenta
432
- */
433
- function bgBrightMagenta(str) {
434
- return run(str, code([105], 49));
435
- }
436
- exports.bgBrightMagenta = bgBrightMagenta;
437
- /**
438
- * Set background color to bright cyan.
439
- * @param str text to make its background bright-cyan
440
- */
441
- function bgBrightCyan(str) {
442
- return run(str, code([106], 49));
443
- }
444
- exports.bgBrightCyan = bgBrightCyan;
445
- /**
446
- * Set background color to bright white.
447
- * @param str text to make its background bright-white
448
- */
449
- function bgBrightWhite(str) {
450
- return run(str, code([107], 49));
451
- }
452
- exports.bgBrightWhite = bgBrightWhite;
453
- /* Special Color Sequences */
454
- /**
455
- * Clam and truncate color codes
456
- * @param n
457
- * @param max number to truncate to
458
- * @param min number to truncate from
459
- */
460
- function clampAndTruncate(n, max = 255, min = 0) {
461
- return Math.trunc(Math.max(Math.min(n, max), min));
462
- }
463
- /**
464
- * Set text color using paletted 8bit colors.
465
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
466
- * @param str text color to apply paletted 8bit colors to
467
- * @param color code
468
- */
469
- function rgb8(str, color) {
470
- return run(str, code([38, 5, clampAndTruncate(color)], 39));
471
- }
472
- exports.rgb8 = rgb8;
473
- /**
474
- * Set background color using paletted 8bit colors.
475
- * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
476
- * @param str text color to apply paletted 8bit background colors to
477
- * @param color code
478
- */
479
- function bgRgb8(str, color) {
480
- return run(str, code([48, 5, clampAndTruncate(color)], 49));
481
- }
482
- exports.bgRgb8 = bgRgb8;
483
- /**
484
- * Set text color using 24bit rgb.
485
- * `color` can be a number in range `0x000000` to `0xffffff` or
486
- * an `Rgb`.
487
- *
488
- * To produce the color magenta:
489
- *
490
- * ```ts
491
- * import { rgb24 } from "@std/fmt/colors";
492
- *
493
- * rgb24("foo", 0xff00ff);
494
- * rgb24("foo", {r: 255, g: 0, b: 255});
495
- * ```
496
- * @param str text color to apply 24bit rgb to
497
- * @param color code
498
- */
499
- function rgb24(str, color) {
500
- if (typeof color === "number") {
501
- return run(str, code([38, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 39));
502
- }
503
- return run(str, code([
504
- 38,
505
- 2,
506
- clampAndTruncate(color.r),
507
- clampAndTruncate(color.g),
508
- clampAndTruncate(color.b),
509
- ], 39));
510
- }
511
- exports.rgb24 = rgb24;
512
- /**
513
- * Set background color using 24bit rgb.
514
- * `color` can be a number in range `0x000000` to `0xffffff` or
515
- * an `Rgb`.
516
- *
517
- * To produce the color magenta:
518
- *
519
- * ```ts
520
- * import { bgRgb24 } from "@std/fmt/colors";
521
- *
522
- * bgRgb24("foo", 0xff00ff);
523
- * bgRgb24("foo", {r: 255, g: 0, b: 255});
524
- * ```
525
- * @param str text color to apply 24bit rgb to
526
- * @param color code
527
- */
528
- function bgRgb24(str, color) {
529
- if (typeof color === "number") {
530
- return run(str, code([48, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 49));
531
- }
532
- return run(str, code([
533
- 48,
534
- 2,
535
- clampAndTruncate(color.r),
536
- clampAndTruncate(color.g),
537
- clampAndTruncate(color.b),
538
- ], 49));
539
- }
540
- exports.bgRgb24 = bgRgb24;
541
- // https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
542
- const ANSI_PATTERN = new RegExp([
543
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
544
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))",
545
- ].join("|"), "g");
546
- /**
547
- * Remove ANSI escape codes from the string.
548
- * @param string to remove ANSI escape codes from
549
- *
550
- * @deprecated (will be removed in 1.0.0) Use {@linkcode stripAnsiCode} instead.
551
- */
552
- function stripColor(string) {
553
- return stripAnsiCode(string);
554
- }
555
- exports.stripColor = stripColor;
556
- /**
557
- * Remove ANSI escape codes from the string.
558
- *
559
- * @param string to remove ANSI escape codes from
560
- */
561
- function stripAnsiCode(string) {
562
- return string.replace(ANSI_PATTERN, "");
563
- }
564
- exports.stripAnsiCode = stripAnsiCode;