summit-marker 3.0.1 → 3.0.3
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 +250 -427
- package/package.json +2 -2
- package/src/backgrounds.js +16 -0
- package/src/errors.js +34 -0
- package/src/index.js +46 -9
- package/src/logger.js +65 -0
- package/src/spinner.js +83 -0
- package/src/table.js +57 -0
- package/LICENSE +0 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "summit-marker",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Marker a zero-dependency Chalk alternative for Node.js with terminal colors, chaining, RGB, hex colors, gradients, and styled messages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"summit"
|
|
33
33
|
],
|
|
34
34
|
"author": "Summit",
|
|
35
|
-
"license": "
|
|
35
|
+
"license": "EULA",
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "node test.js"
|
|
38
38
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const backgrounds = {
|
|
2
|
+
bgBlack: "\x1b[40m",
|
|
3
|
+
bgRed: "\x1b[41m",
|
|
4
|
+
bgGreen: "\x1b[42m",
|
|
5
|
+
bgYellow: "\x1b[43m",
|
|
6
|
+
bgBlue: "\x1b[44m",
|
|
7
|
+
bgPurple: "\x1b[45m",
|
|
8
|
+
bgCyan: "\x1b[46m",
|
|
9
|
+
bgWhite: "\x1b[47m",
|
|
10
|
+
|
|
11
|
+
bgGray: "\x1b[100m"
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function bgRgb(r, g, b) {
|
|
15
|
+
return `\x1b[48;2;${r};${g};${b}m`;
|
|
16
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export default function error(options = {}) {
|
|
2
|
+
const {
|
|
3
|
+
title = "Error",
|
|
4
|
+
message = "",
|
|
5
|
+
code = null,
|
|
6
|
+
details = null
|
|
7
|
+
} = options;
|
|
8
|
+
|
|
9
|
+
let output = [];
|
|
10
|
+
|
|
11
|
+
output.push(
|
|
12
|
+
`✖ ${title}`
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
if (message) {
|
|
16
|
+
output.push(
|
|
17
|
+
`\n${message}`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (code) {
|
|
22
|
+
output.push(
|
|
23
|
+
`\nCode: ${code}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (details) {
|
|
28
|
+
output.push(
|
|
29
|
+
`\nDetails:\n${details}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return output.join("");
|
|
34
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { progress } from "./progress.js";
|
|
2
|
+
import error from "./errors.js";
|
|
3
|
+
import * as extended from "./extended.js";
|
|
4
|
+
import spinner from "./spinner.js";
|
|
5
|
+
import table from "./table.js";
|
|
6
|
+
import logger from "./logger.js";
|
|
7
|
+
import { createThemes } from "./themes.js";
|
|
8
|
+
import { backgrounds, bgRgb } from "./backgrounds.js";
|
|
1
9
|
import { text } from "./text.js";
|
|
2
10
|
import box from "./box.js";
|
|
3
11
|
import { colors, styles, rgb, hex } from "./colors.js";
|
|
@@ -5,9 +13,21 @@ import { apply } from "./styles.js";
|
|
|
5
13
|
import { messages, symbols } from "./messages.js";
|
|
6
14
|
import { gradients } from "./gradients.js";
|
|
7
15
|
import { rgbGradient } from "./rgbGradient.js";
|
|
8
|
-
import { createThemes } from "./themes.js";
|
|
9
16
|
|
|
10
17
|
const marker = {};
|
|
18
|
+
marker.logger = logger;
|
|
19
|
+
marker.table = table;
|
|
20
|
+
marker.spinner = spinner;
|
|
21
|
+
marker.progress = progress;
|
|
22
|
+
|
|
23
|
+
marker.error = error;
|
|
24
|
+
Object.assign(marker, extended);
|
|
25
|
+
|
|
26
|
+
const chainStyles = {
|
|
27
|
+
...colors,
|
|
28
|
+
...styles,
|
|
29
|
+
...backgrounds
|
|
30
|
+
};
|
|
11
31
|
|
|
12
32
|
function createChain(codes = []) {
|
|
13
33
|
const builder = (text) => {
|
|
@@ -18,10 +38,7 @@ function createChain(codes = []) {
|
|
|
18
38
|
return apply(codes, text);
|
|
19
39
|
};
|
|
20
40
|
|
|
21
|
-
for (const [name, code] of Object.entries({
|
|
22
|
-
...colors,
|
|
23
|
-
...styles
|
|
24
|
-
})) {
|
|
41
|
+
for (const [name, code] of Object.entries(chainStyles)) {
|
|
25
42
|
Object.defineProperty(builder, name, {
|
|
26
43
|
get() {
|
|
27
44
|
return createChain([
|
|
@@ -35,10 +52,7 @@ function createChain(codes = []) {
|
|
|
35
52
|
return builder;
|
|
36
53
|
}
|
|
37
54
|
|
|
38
|
-
for (const [name, code] of Object.entries({
|
|
39
|
-
...colors,
|
|
40
|
-
...styles
|
|
41
|
-
})) {
|
|
55
|
+
for (const [name, code] of Object.entries(chainStyles)) {
|
|
42
56
|
Object.defineProperty(marker, name, {
|
|
43
57
|
get() {
|
|
44
58
|
return createChain([code]);
|
|
@@ -46,18 +60,31 @@ for (const [name, code] of Object.entries({
|
|
|
46
60
|
});
|
|
47
61
|
}
|
|
48
62
|
|
|
63
|
+
|
|
64
|
+
// RGB foreground
|
|
49
65
|
marker.rgb = (r, g, b) => {
|
|
50
66
|
return createChain([
|
|
51
67
|
rgb(r, g, b)
|
|
52
68
|
]);
|
|
53
69
|
};
|
|
54
70
|
|
|
71
|
+
|
|
72
|
+
// HEX foreground
|
|
55
73
|
marker.hex = (value) => {
|
|
56
74
|
return createChain([
|
|
57
75
|
hex(value)
|
|
58
76
|
]);
|
|
59
77
|
};
|
|
60
78
|
|
|
79
|
+
|
|
80
|
+
// RGB background
|
|
81
|
+
marker.bgRgb = (r, g, b) => {
|
|
82
|
+
return createChain([
|
|
83
|
+
bgRgb(r, g, b)
|
|
84
|
+
]);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
|
|
61
88
|
// 256 color gradient
|
|
62
89
|
marker.gradient = (text) => {
|
|
63
90
|
if (marker.level === 0) {
|
|
@@ -80,27 +107,35 @@ marker.gradient = (text) => {
|
|
|
80
107
|
return `${output}\x1b[0m`;
|
|
81
108
|
};
|
|
82
109
|
|
|
110
|
+
|
|
83
111
|
// True RGB gradient
|
|
84
112
|
marker.rgbGradient = rgbGradient;
|
|
85
113
|
|
|
114
|
+
|
|
86
115
|
// Gradient presets
|
|
87
116
|
marker.gradients = gradients;
|
|
88
117
|
|
|
118
|
+
|
|
89
119
|
// Box formatting
|
|
90
120
|
marker.box = box;
|
|
91
121
|
|
|
122
|
+
|
|
92
123
|
// Messages
|
|
93
124
|
Object.assign(marker, messages);
|
|
94
125
|
|
|
126
|
+
|
|
95
127
|
// Symbols
|
|
96
128
|
marker.symbols = symbols;
|
|
97
129
|
|
|
130
|
+
|
|
98
131
|
// Text utilities
|
|
99
132
|
Object.assign(marker, text);
|
|
100
133
|
|
|
134
|
+
|
|
101
135
|
// Themes
|
|
102
136
|
marker.themes = createThemes(marker);
|
|
103
137
|
|
|
138
|
+
|
|
104
139
|
function getColorLevel() {
|
|
105
140
|
if (process.env.NO_COLOR) {
|
|
106
141
|
return 0;
|
|
@@ -121,8 +156,10 @@ function getColorLevel() {
|
|
|
121
156
|
return 1;
|
|
122
157
|
}
|
|
123
158
|
|
|
159
|
+
|
|
124
160
|
marker.level = getColorLevel();
|
|
125
161
|
|
|
126
162
|
marker.supportsColor = marker.level > 0;
|
|
127
163
|
|
|
164
|
+
|
|
128
165
|
export default marker;
|
package/src/logger.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { symbols } from "./messages.js";
|
|
2
|
+
|
|
3
|
+
function timestamp() {
|
|
4
|
+
return new Date().toLocaleTimeString();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function format(level, message, symbol) {
|
|
8
|
+
return `${symbol} [${timestamp()}] ${level}: ${message}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const logger = {
|
|
12
|
+
info(message) {
|
|
13
|
+
console.log(
|
|
14
|
+
format(
|
|
15
|
+
"INFO",
|
|
16
|
+
message,
|
|
17
|
+
symbols.info || "ℹ"
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
success(message) {
|
|
23
|
+
console.log(
|
|
24
|
+
format(
|
|
25
|
+
"SUCCESS",
|
|
26
|
+
message,
|
|
27
|
+
symbols.success || "✔"
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
warn(message) {
|
|
33
|
+
console.log(
|
|
34
|
+
format(
|
|
35
|
+
"WARN",
|
|
36
|
+
message,
|
|
37
|
+
symbols.warning || "⚠"
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
error(message) {
|
|
43
|
+
console.log(
|
|
44
|
+
format(
|
|
45
|
+
"ERROR",
|
|
46
|
+
message,
|
|
47
|
+
symbols.error || "✖"
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
debug(message) {
|
|
53
|
+
if (process.env.MARKER_DEBUG) {
|
|
54
|
+
console.log(
|
|
55
|
+
format(
|
|
56
|
+
"DEBUG",
|
|
57
|
+
message,
|
|
58
|
+
"🐛"
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default logger;
|
package/src/spinner.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const frames = [
|
|
2
|
+
"⠋",
|
|
3
|
+
"⠙",
|
|
4
|
+
"⠹",
|
|
5
|
+
"⠸",
|
|
6
|
+
"⠼",
|
|
7
|
+
"⠴",
|
|
8
|
+
"⠦",
|
|
9
|
+
"⠧",
|
|
10
|
+
"⠇",
|
|
11
|
+
"⠏"
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export default function spinner(message = "Loading") {
|
|
15
|
+
let interval = null;
|
|
16
|
+
let index = 0;
|
|
17
|
+
let active = false;
|
|
18
|
+
|
|
19
|
+
function render(frame) {
|
|
20
|
+
process.stdout.write(
|
|
21
|
+
`\r${frame} ${message}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
|
|
27
|
+
start() {
|
|
28
|
+
if (active) return;
|
|
29
|
+
|
|
30
|
+
active = true;
|
|
31
|
+
|
|
32
|
+
interval = setInterval(() => {
|
|
33
|
+
render(frames[index]);
|
|
34
|
+
|
|
35
|
+
index++;
|
|
36
|
+
|
|
37
|
+
if (index >= frames.length) {
|
|
38
|
+
index = 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}, 80);
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
stop(finalMessage = message) {
|
|
46
|
+
if (!active) return;
|
|
47
|
+
|
|
48
|
+
clearInterval(interval);
|
|
49
|
+
interval = null;
|
|
50
|
+
active = false;
|
|
51
|
+
|
|
52
|
+
process.stdout.write(
|
|
53
|
+
`\r ${finalMessage}\n`
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
success(finalMessage = "Done") {
|
|
59
|
+
if (interval) {
|
|
60
|
+
clearInterval(interval);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
active = false;
|
|
64
|
+
|
|
65
|
+
process.stdout.write(
|
|
66
|
+
`\r✔ ${finalMessage}\n`
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
error(finalMessage = "Failed") {
|
|
72
|
+
if (interval) {
|
|
73
|
+
clearInterval(interval);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
active = false;
|
|
77
|
+
|
|
78
|
+
process.stdout.write(
|
|
79
|
+
`\r✖ ${finalMessage}\n`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
package/src/table.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function getColumnWidths(rows) {
|
|
2
|
+
const widths = [];
|
|
3
|
+
|
|
4
|
+
for (const row of rows) {
|
|
5
|
+
row.forEach((cell, index) => {
|
|
6
|
+
const length = String(cell).length;
|
|
7
|
+
|
|
8
|
+
if (!widths[index] || length > widths[index]) {
|
|
9
|
+
widths[index] = length;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return widths;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function border(widths) {
|
|
18
|
+
return (
|
|
19
|
+
"+" +
|
|
20
|
+
widths
|
|
21
|
+
.map(width => "-".repeat(width + 2))
|
|
22
|
+
.join("+") +
|
|
23
|
+
"+"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function createRow(row, widths) {
|
|
28
|
+
return (
|
|
29
|
+
"|" +
|
|
30
|
+
row
|
|
31
|
+
.map(
|
|
32
|
+
(cell, index) =>
|
|
33
|
+
` ${String(cell).padEnd(widths[index])} `
|
|
34
|
+
)
|
|
35
|
+
.join("|") +
|
|
36
|
+
"|"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function table(rows = []) {
|
|
41
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const widths = getColumnWidths(rows);
|
|
46
|
+
|
|
47
|
+
const lines = [];
|
|
48
|
+
|
|
49
|
+
lines.push(border(widths));
|
|
50
|
+
|
|
51
|
+
for (const row of rows) {
|
|
52
|
+
lines.push(createRow(row, widths));
|
|
53
|
+
lines.push(border(widths));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return lines.join("\n");
|
|
57
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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.
|