deno.land / x / nanocolors@0.1.12 / mod.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
export type Color = (text: string | number) => string;
export interface Colors { isColorSupported: boolean; reset: Color; bold: Color; dim: Color; italic: Color; underline: Color; inverse: Color; hidden: Color; strikethrough: Color; black: Color; red: Color; green: Color; yellow: Color; blue: Color; magenta: Color; cyan: Color; white: Color; gray: Color; bgBlack: Color; bgRed: Color; bgGreen: Color; bgYellow: Color; bgBlue: Color; bgMagenta: Color; bgCyan: Color; bgWhite: Color;}
export let isColorSupported = !Deno.noColor;
let nope: Color = (s) => String(s);
function hasClosed(s: string | number, close: string): s is string { return !!~("" + s).indexOf(close, 4);}
function color(open: string, close: string, closeRegex: RegExp): Color { return (s) => { if (s === "") { return s; } else { return ( open + (hasClosed(s, close) ? s.replace(closeRegex, open) : s) + close ); } };}
let close39 = "\x1b[39m";let close49 = "\x1b[49m";let regexp39 = /\x1b\[39m/g;let regexp49 = /\x1b\[49m/g;
export function createColors(enabled = isColorSupported): Colors { if (enabled) { return { isColorSupported: true, reset: (s) => `\x1b[0m${s}\x1b[0m`, bold: color("\x1b[1m", "\x1b[22m", /\x1b\[22m/g), dim: color("\x1b[2m", "\x1b[22m", /\x1b\[22m/g), italic: color("\x1b[3m", "\x1b[23m", /\x1b\[23m/g), underline: color("\x1b[4m", "\x1b[24m", /\x1b\[24m/g), inverse: color("\x1b[7m", "\x1b[27m", /\x1b\[27m/g), hidden: color("\x1b[8m", "\x1b[28m", /\x1b\[28m/g), strikethrough: color("\x1b[9m", "\x1b[29m", /\x1b\[29m/g), black: color("\x1b[30m", close39, regexp39), red: color("\x1b[31m", close39, regexp39), green: color("\x1b[32m", close39, regexp39), yellow: color("\x1b[33m", close39, regexp39), blue: color("\x1b[34m", close39, regexp39), magenta: color("\x1b[35m", close39, regexp39), cyan: color("\x1b[36m", close39, regexp39), white: color("\x1b[37m", close39, regexp39), gray: color("\x1b[90m", close39, regexp39), bgBlack: color("\x1b[40m", close49, regexp49), bgRed: color("\x1b[41m", close49, regexp49), bgGreen: color("\x1b[42m", close49, regexp49), bgYellow: color("\x1b[43m", close49, regexp49), bgBlue: color("\x1b[44m", close49, regexp49), bgMagenta: color("\x1b[45m", close49, regexp49), bgCyan: color("\x1b[46m", close49, regexp49), bgWhite: color("\x1b[47m", close49, regexp49), }; } else { return { isColorSupported: false, reset: nope, bold: nope, dim: nope, italic: nope, underline: nope, inverse: nope, hidden: nope, strikethrough: nope, black: nope, red: nope, green: nope, yellow: nope, blue: nope, magenta: nope, cyan: nope, white: nope, gray: nope, bgBlack: nope, bgRed: nope, bgGreen: nope, bgYellow: nope, bgBlue: nope, bgMagenta: nope, bgCyan: nope, bgWhite: nope, }; }}
export let { reset, bold, dim, italic, underline, inverse, hidden, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite,} = createColors(isColorSupported);
nanocolors

Version Info

Tagged at
2 years ago