summit-marker 1.0.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/LICENSE +47 -0
- package/README.md +389 -0
- package/package.json +46 -0
- package/src/colors.js +52 -0
- package/src/extended.js +28 -0
- package/src/index.js +97 -0
- package/src/messages.js +20 -0
- package/src/styles.js +26 -0
- package/src/types.d.ts +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
SUMMIT MARKER LICENSE NOTICE
|
|
2
|
+
|
|
3
|
+
This software package is UNLICENSED.
|
|
4
|
+
|
|
5
|
+
Copyright (c) Summit. All rights reserved.
|
|
6
|
+
|
|
7
|
+
This package and all associated source code, documentation,
|
|
8
|
+
examples, assets, and related materials are protected by
|
|
9
|
+
copyright and remain the exclusive property of the author.
|
|
10
|
+
|
|
11
|
+
No permission is granted to use, copy, modify, merge, publish,
|
|
12
|
+
distribute, sublicense, sell, or create derivative works based
|
|
13
|
+
on this software unless explicit written permission has been
|
|
14
|
+
provided by the copyright holder.
|
|
15
|
+
|
|
16
|
+
Installing or downloading this package does not grant any
|
|
17
|
+
ownership rights, intellectual property rights, redistribution
|
|
18
|
+
rights, or authorization to create modified versions of this
|
|
19
|
+
software.
|
|
20
|
+
|
|
21
|
+
You may use this package only in ways explicitly allowed by the
|
|
22
|
+
author. Any use outside of those permissions is prohibited.
|
|
23
|
+
|
|
24
|
+
Redistribution of this package, whether in original or modified
|
|
25
|
+
form, is not permitted without prior authorization.
|
|
26
|
+
|
|
27
|
+
Modification of the source code, removal of copyright notices,
|
|
28
|
+
rebranding, republishing under another package name, or claiming
|
|
29
|
+
this software as your own is not permitted.
|
|
30
|
+
|
|
31
|
+
The author reserves all rights to this software and may change,
|
|
32
|
+
update, restrict, or discontinue access to this package at any
|
|
33
|
+
time.
|
|
34
|
+
|
|
35
|
+
This software is provided without any express or implied
|
|
36
|
+
permission beyond what has been specifically granted by the
|
|
37
|
+
author. The author is not required to provide support,
|
|
38
|
+
maintenance, updates, or future versions of this software.
|
|
39
|
+
|
|
40
|
+
By installing or accessing this package, you acknowledge that
|
|
41
|
+
the software remains the property of Summit and that no license
|
|
42
|
+
or ownership rights are transferred to you.
|
|
43
|
+
|
|
44
|
+
For licensing requests, commercial use, redistribution requests,
|
|
45
|
+
or other permissions, contact the copyright holder directly.
|
|
46
|
+
|
|
47
|
+
All rights reserved.
|
package/README.md
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
# Marker
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
███╗ ███╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
|
5
|
+
████╗ ████║██╔══██╗██╔══██╗██║ ██╔╝██╔════╝██╔══██╗
|
|
6
|
+
██╔████╔██║███████║██████╔╝█████╔╝ █████╗ ██████╔╝
|
|
7
|
+
██║╚██╔╝██║██╔══██║██╔══██╗██╔═██╗ ██╔══╝ ██╔══██╗
|
|
8
|
+
██║ ╚═╝ ██║██║ ██║██║ ██║██║ ██╗███████╗██║ ██║
|
|
9
|
+
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
Marker Supports **16.7 Million True Colors** With RGB and Hex Support
|
|
20
|
+
|
|
21
|
+
A zero-dependency Chalk alternative for Node.js with terminal colors, chaining, RGB, hex colors, gradients, and styled messages.
|
|
22
|
+
|
|
23
|
+
Built by **Summit**.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import marker from "summit-marker";
|
|
31
|
+
|
|
32
|
+
console.log(marker.bold.green("✓ Marker is working"));
|
|
33
|
+
|
|
34
|
+
console.log(marker.gradient("SUMMIT"));
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Package Stats
|
|
40
|
+
|
|
41
|
+
- Dependencies: 0
|
|
42
|
+
- Runtime: Node.js
|
|
43
|
+
- Color support: True RGB
|
|
44
|
+
- Color range: 16,777,216 colors
|
|
45
|
+
|
|
46
|
+
## Supported
|
|
47
|
+
|
|
48
|
+
- Node.js ✅
|
|
49
|
+
- Linux terminals ✅
|
|
50
|
+
- macOS terminals ✅
|
|
51
|
+
- Windows terminals ✅
|
|
52
|
+
- Termux/Android Node.js ✅
|
|
53
|
+
|
|
54
|
+
## Changelog
|
|
55
|
+
|
|
56
|
+
### 1.0.0
|
|
57
|
+
|
|
58
|
+
- Initial release
|
|
59
|
+
- Added colors
|
|
60
|
+
- Added styles
|
|
61
|
+
- Added RGB/hex support
|
|
62
|
+
- Added gradients
|
|
63
|
+
- Added message helpers
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Marker vs Traditional ANSI
|
|
68
|
+
|
|
69
|
+
| Feature | Marker |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Colors | ✅ |
|
|
72
|
+
| RGB | ✅ |
|
|
73
|
+
| Hex | ✅ |
|
|
74
|
+
| Gradients | ✅ |
|
|
75
|
+
| Chaining | ✅ |
|
|
76
|
+
| Zero dependencies | ✅ |
|
|
77
|
+
| Manual ANSI codes | ❌ |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Why Marker?
|
|
82
|
+
|
|
83
|
+
Writing terminal colors manually with ANSI escape codes is difficult and hard to read.
|
|
84
|
+
|
|
85
|
+
Instead of:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
"\x1b[31mError\x1b[0m"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Marker lets developers write:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
marker.red("Error")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Marker provides a clean and modern API for creating beautiful command-line output.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Features
|
|
102
|
+
|
|
103
|
+
- 🎨 Basic terminal colors
|
|
104
|
+
- 🌈 Extended color palette
|
|
105
|
+
- 🔗 Chainable styles
|
|
106
|
+
- ✨ Bold, italic, underline, and more
|
|
107
|
+
- 🎯 RGB true-color support
|
|
108
|
+
- 🔢 Hex color support
|
|
109
|
+
- 🌈 Gradient text
|
|
110
|
+
- ✅ Success, error, warning, and info messages
|
|
111
|
+
- 🖥️ Automatic color detection
|
|
112
|
+
- 📦 Zero dependencies
|
|
113
|
+
- ⚡ Lightweight and fast
|
|
114
|
+
- 🟦 TypeScript support
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Installation
|
|
119
|
+
|
|
120
|
+
Install Marker with npm:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm install summit-marker
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Basic Usage
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
import marker from "summit-marker";
|
|
132
|
+
|
|
133
|
+
console.log(marker.red("Error"));
|
|
134
|
+
console.log(marker.green("Success"));
|
|
135
|
+
console.log(marker.blue("Information"));
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## TypeScript
|
|
141
|
+
|
|
142
|
+
Marker includes TypeScript declarations.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import marker from "summit-marker";
|
|
146
|
+
|
|
147
|
+
marker.bold.blue("Hello TypeScript");
|
|
148
|
+
|
|
149
|
+
marker.rgb(255, 0, 0)("Red");
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Colors
|
|
155
|
+
|
|
156
|
+
Marker includes many built-in colors:
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
marker.red("Red");
|
|
160
|
+
marker.green("Green");
|
|
161
|
+
marker.blue("Blue");
|
|
162
|
+
marker.orange("Orange");
|
|
163
|
+
marker.pink("Pink");
|
|
164
|
+
marker.brown("Brown");
|
|
165
|
+
marker.neon("Neon");
|
|
166
|
+
|
|
167
|
+
marker.gold("Gold");
|
|
168
|
+
marker.lime("Lime");
|
|
169
|
+
marker.teal("Teal");
|
|
170
|
+
marker.violet("Violet");
|
|
171
|
+
marker.magenta("Magenta");
|
|
172
|
+
marker.navy("Navy");
|
|
173
|
+
marker.skyBlue("Sky Blue");
|
|
174
|
+
marker.emerald("Emerald");
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Text Styles
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
marker.bold("Bold");
|
|
183
|
+
|
|
184
|
+
marker.italic("Italic");
|
|
185
|
+
|
|
186
|
+
marker.underline("Underline");
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Chaining
|
|
192
|
+
|
|
193
|
+
Combine colors and styles:
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
marker.bold.red("Critical Error");
|
|
197
|
+
|
|
198
|
+
marker.underline.blue("Documentation");
|
|
199
|
+
|
|
200
|
+
marker.neon.emerald("Success");
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## RGB Colors
|
|
206
|
+
|
|
207
|
+
Marker supports true 24-bit RGB colors.
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
marker.rgb(255, 120, 0)("Custom Orange");
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
RGB supports:
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
16,777,216 possible colors
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Hex Colors
|
|
222
|
+
|
|
223
|
+
Use any hex color:
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
marker.hex("#ff8800")("Custom Orange");
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Examples:
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
marker.hex("#ff0000")("Red");
|
|
233
|
+
|
|
234
|
+
marker.hex("#00ff00")("Green");
|
|
235
|
+
|
|
236
|
+
marker.hex("#0000ff")("Blue");
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Gradients
|
|
242
|
+
|
|
243
|
+
Create colorful gradient text:
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
marker.gradient("SUMMIT");
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Messages
|
|
252
|
+
|
|
253
|
+
Marker includes common terminal messages:
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
marker.success("Package installed");
|
|
257
|
+
|
|
258
|
+
marker.error("Build failed");
|
|
259
|
+
|
|
260
|
+
marker.warning("Deprecated feature");
|
|
261
|
+
|
|
262
|
+
marker.info("Searching...");
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Example output:
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
✔ Package installed
|
|
269
|
+
✖ Build failed
|
|
270
|
+
⚠ Deprecated feature
|
|
271
|
+
ℹ Searching...
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Color Detection
|
|
277
|
+
|
|
278
|
+
Marker automatically detects terminal color support.
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
console.log(marker.level);
|
|
282
|
+
|
|
283
|
+
console.log(marker.supportsColor);
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Levels:
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
0 - Disabled
|
|
290
|
+
1 - Basic colors
|
|
291
|
+
2 - 256 colors
|
|
292
|
+
3 - True RGB colors
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Disable colors:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
NO_COLOR=1 node app.js
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Force color support:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
FORCE_COLOR=3 node app.js
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Example
|
|
310
|
+
|
|
311
|
+
Run:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
node examples/BestColors.js
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Example:
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
=== Basic Colors ===
|
|
321
|
+
Red
|
|
322
|
+
Green
|
|
323
|
+
Blue
|
|
324
|
+
Orange
|
|
325
|
+
Pink
|
|
326
|
+
Brown
|
|
327
|
+
Neon
|
|
328
|
+
|
|
329
|
+
=== Styles ===
|
|
330
|
+
Bold
|
|
331
|
+
Italic
|
|
332
|
+
Underline
|
|
333
|
+
|
|
334
|
+
=== Chaining ===
|
|
335
|
+
Bold Red
|
|
336
|
+
Blue Underline
|
|
337
|
+
|
|
338
|
+
=== RGB ===
|
|
339
|
+
Custom RGB Orange
|
|
340
|
+
|
|
341
|
+
=== HEX ===
|
|
342
|
+
Custom Hex Purple
|
|
343
|
+
|
|
344
|
+
=== Gradient ===
|
|
345
|
+
SUMMIT
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Project Structure
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
summit-marker/
|
|
354
|
+
├── src/
|
|
355
|
+
│ ├── index.js
|
|
356
|
+
│ ├── colors.js
|
|
357
|
+
│ ├── styles.js
|
|
358
|
+
│ ├── messages.js
|
|
359
|
+
│ └── types.d.ts
|
|
360
|
+
├── examples/
|
|
361
|
+
│ └── BestColors.js
|
|
362
|
+
├── README.md
|
|
363
|
+
└── package.json
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Technology
|
|
369
|
+
|
|
370
|
+
Marker is built with:
|
|
371
|
+
|
|
372
|
+
- Node.js
|
|
373
|
+
- JavaScript ES Modules
|
|
374
|
+
- ANSI terminal formatting
|
|
375
|
+
- TypeScript declarations
|
|
376
|
+
|
|
377
|
+
No external dependencies are required.
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
UNLICENSED
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Built By
|
|
388
|
+
|
|
389
|
+
**Summit**
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "summit-marker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Marker a zero-dependency Chalk alternative for Node.js with terminal colors, chaining, RGB, hex colors, gradients, and styled messages.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"types": "src/types.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/types.d.ts",
|
|
11
|
+
"import": "./src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"chalk",
|
|
16
|
+
"chalk-alternative",
|
|
17
|
+
"chalk-replacement",
|
|
18
|
+
"terminal",
|
|
19
|
+
"terminal-colors",
|
|
20
|
+
"cli",
|
|
21
|
+
"cli-colors",
|
|
22
|
+
"ansi",
|
|
23
|
+
"ansi-colors",
|
|
24
|
+
"console-colors",
|
|
25
|
+
"nodejs",
|
|
26
|
+
"javascript",
|
|
27
|
+
"rgb",
|
|
28
|
+
"hex",
|
|
29
|
+
"gradient",
|
|
30
|
+
"terminal-formatting",
|
|
31
|
+
"developer-tools",
|
|
32
|
+
"summit"
|
|
33
|
+
],
|
|
34
|
+
"author": "Summit",
|
|
35
|
+
"license": "UNLICENSED",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "node test.js"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/colors.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const colors = {
|
|
2
|
+
red: "\x1b[31m",
|
|
3
|
+
green: "\x1b[32m",
|
|
4
|
+
yellow: "\x1b[33m",
|
|
5
|
+
blue: "\x1b[34m",
|
|
6
|
+
purple: "\x1b[35m",
|
|
7
|
+
cyan: "\x1b[36m",
|
|
8
|
+
white: "\x1b[37m",
|
|
9
|
+
grey: "\x1b[90m",
|
|
10
|
+
black: "\x1b[30m",
|
|
11
|
+
|
|
12
|
+
orange: "\x1b[38;5;208m",
|
|
13
|
+
pink: "\x1b[38;5;213m",
|
|
14
|
+
brown: "\x1b[38;5;94m",
|
|
15
|
+
neon: "\x1b[38;5;82m",
|
|
16
|
+
|
|
17
|
+
gold: "\x1b[38;5;220m",
|
|
18
|
+
lime: "\x1b[38;5;118m",
|
|
19
|
+
teal: "\x1b[38;5;30m",
|
|
20
|
+
violet: "\x1b[38;5;177m",
|
|
21
|
+
magenta: "\x1b[38;5;201m",
|
|
22
|
+
navy: "\x1b[38;5;17m",
|
|
23
|
+
skyBlue: "\x1b[38;5;117m",
|
|
24
|
+
emerald: "\x1b[38;5;48m"
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const styles = {
|
|
28
|
+
bold: "\x1b[1m",
|
|
29
|
+
dim: "\x1b[2m",
|
|
30
|
+
italic: "\x1b[3m",
|
|
31
|
+
underline: "\x1b[4m",
|
|
32
|
+
reverse: "\x1b[7m",
|
|
33
|
+
strike: "\x1b[9m"
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function rgb(r, g, b) {
|
|
37
|
+
return `\x1b[38;2;${r};${g};${b}m`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function hex(value) {
|
|
41
|
+
value = value.replace("#", "");
|
|
42
|
+
|
|
43
|
+
if (!/^[0-9a-fA-F]{6}$/.test(value)) {
|
|
44
|
+
throw new Error("Invalid hex color");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const r = parseInt(value.slice(0, 2), 16);
|
|
48
|
+
const g = parseInt(value.slice(2, 4), 16);
|
|
49
|
+
const b = parseInt(value.slice(4, 6), 16);
|
|
50
|
+
|
|
51
|
+
return rgb(r, g, b);
|
|
52
|
+
}
|
package/src/extended.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { apply } from "./styles.js";
|
|
2
|
+
|
|
3
|
+
const reset = "\x1b[0m";
|
|
4
|
+
|
|
5
|
+
const extendedColors = {
|
|
6
|
+
orange: "\x1b[38;5;208m",
|
|
7
|
+
pink: "\x1b[38;5;213m",
|
|
8
|
+
brown: "\x1b[38;5;94m",
|
|
9
|
+
neon: "\x1b[38;5;82m"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const extraColors = {};
|
|
13
|
+
|
|
14
|
+
for (const [name, code] of Object.entries(extendedColors)) {
|
|
15
|
+
extraColors[name] = (text) => apply(code, text);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function gradient(text, colors = [196, 201, 226]) {
|
|
19
|
+
let output = "";
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < text.length; i++) {
|
|
22
|
+
const color = colors[i % colors.length];
|
|
23
|
+
|
|
24
|
+
output += `\x1b[38;5;${color}m${text[i]}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return output + reset;
|
|
28
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { colors, styles, rgb, hex } from "./colors.js";
|
|
2
|
+
import { apply } from "./styles.js";
|
|
3
|
+
import { messages } from "./messages.js";
|
|
4
|
+
|
|
5
|
+
const marker = {};
|
|
6
|
+
|
|
7
|
+
function createChain(codes = []) {
|
|
8
|
+
const builder = (text) => {
|
|
9
|
+
if (marker.level === 0) {
|
|
10
|
+
return text;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return apply(codes, text);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
for (const [name, code] of Object.entries({
|
|
17
|
+
...colors,
|
|
18
|
+
...styles
|
|
19
|
+
})) {
|
|
20
|
+
Object.defineProperty(builder, name, {
|
|
21
|
+
get() {
|
|
22
|
+
return createChain([
|
|
23
|
+
...codes,
|
|
24
|
+
code
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return builder;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const [name, code] of Object.entries({
|
|
34
|
+
...colors,
|
|
35
|
+
...styles
|
|
36
|
+
})) {
|
|
37
|
+
Object.defineProperty(marker, name, {
|
|
38
|
+
get() {
|
|
39
|
+
return createChain([code]);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
marker.rgb = (r, g, b) => {
|
|
45
|
+
return createChain([rgb(r, g, b)]);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
marker.hex = (value) => {
|
|
49
|
+
return createChain([hex(value)]);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
marker.gradient = (text) => {
|
|
53
|
+
if (marker.level === 0) {
|
|
54
|
+
return text;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const palette = [
|
|
58
|
+
196,
|
|
59
|
+
201,
|
|
60
|
+
226
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
let output = "";
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < text.length; i++) {
|
|
66
|
+
output += `\x1b[38;5;${palette[i % palette.length]}m${text[i]}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return `${output}\x1b[0m`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
Object.assign(marker, messages);
|
|
73
|
+
|
|
74
|
+
function getColorLevel() {
|
|
75
|
+
if (process.env.NO_COLOR) {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (process.env.FORCE_COLOR) {
|
|
80
|
+
return Number(process.env.FORCE_COLOR);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!process.stdout.isTTY) {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (process.env.COLORTERM) {
|
|
88
|
+
return 3;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
marker.level = getColorLevel();
|
|
95
|
+
marker.supportsColor = marker.level > 0;
|
|
96
|
+
|
|
97
|
+
export default marker;
|
package/src/messages.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { colors } from "./colors.js";
|
|
2
|
+
import { apply } from "./styles.js";
|
|
3
|
+
|
|
4
|
+
export const messages = {
|
|
5
|
+
success(text) {
|
|
6
|
+
return apply(colors.green, `✔ ${text}`);
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
error(text) {
|
|
10
|
+
return apply(colors.red, `✖ ${text}`);
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
warning(text) {
|
|
14
|
+
return apply(colors.yellow, `⚠ ${text}`);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
info(text) {
|
|
18
|
+
return apply(colors.blue, `ℹ ${text}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
package/src/styles.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const reset = "\x1b[0m";
|
|
2
|
+
|
|
3
|
+
export function apply(codes, text) {
|
|
4
|
+
if (!Array.isArray(codes)) {
|
|
5
|
+
codes = [codes];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return `${codes.join("")}${text}${reset}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function strip(text) {
|
|
12
|
+
return text.replace(
|
|
13
|
+
/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g,
|
|
14
|
+
""
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createBuilder(codes = []) {
|
|
19
|
+
const builder = (text) => {
|
|
20
|
+
return apply(codes, text);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
builder._codes = codes;
|
|
24
|
+
|
|
25
|
+
return builder;
|
|
26
|
+
}
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type MarkerFunction = (text: string) => string;
|
|
2
|
+
|
|
3
|
+
declare const marker: {
|
|
4
|
+
red: MarkerFunction;
|
|
5
|
+
green: MarkerFunction;
|
|
6
|
+
yellow: MarkerFunction;
|
|
7
|
+
blue: MarkerFunction;
|
|
8
|
+
purple: MarkerFunction;
|
|
9
|
+
cyan: MarkerFunction;
|
|
10
|
+
white: MarkerFunction;
|
|
11
|
+
grey: MarkerFunction;
|
|
12
|
+
black: MarkerFunction;
|
|
13
|
+
|
|
14
|
+
orange: MarkerFunction;
|
|
15
|
+
pink: MarkerFunction;
|
|
16
|
+
brown: MarkerFunction;
|
|
17
|
+
neon: MarkerFunction;
|
|
18
|
+
|
|
19
|
+
bold: MarkerFunction;
|
|
20
|
+
italic: MarkerFunction;
|
|
21
|
+
underline: MarkerFunction;
|
|
22
|
+
dim: MarkerFunction;
|
|
23
|
+
|
|
24
|
+
success: MarkerFunction;
|
|
25
|
+
error: MarkerFunction;
|
|
26
|
+
warning: MarkerFunction;
|
|
27
|
+
info: MarkerFunction;
|
|
28
|
+
|
|
29
|
+
rgb(
|
|
30
|
+
r: number,
|
|
31
|
+
g: number,
|
|
32
|
+
b: number
|
|
33
|
+
): MarkerFunction;
|
|
34
|
+
|
|
35
|
+
hex(
|
|
36
|
+
value: string
|
|
37
|
+
): MarkerFunction;
|
|
38
|
+
|
|
39
|
+
gradient(
|
|
40
|
+
text: string
|
|
41
|
+
): string;
|
|
42
|
+
|
|
43
|
+
level: number;
|
|
44
|
+
supportsColor: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default marker;
|