summit-marker 3.0.1 → 3.0.2
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 +39 -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.2",
|
|
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,8 @@
|
|
|
1
|
+
import spinner from "./spinner.js";
|
|
2
|
+
import table from "./table.js";
|
|
3
|
+
import logger from "./logger.js";
|
|
4
|
+
import { createThemes } from "./themes.js";
|
|
5
|
+
import { backgrounds, bgRgb } from "./backgrounds.js";
|
|
1
6
|
import { text } from "./text.js";
|
|
2
7
|
import box from "./box.js";
|
|
3
8
|
import { colors, styles, rgb, hex } from "./colors.js";
|
|
@@ -5,9 +10,17 @@ import { apply } from "./styles.js";
|
|
|
5
10
|
import { messages, symbols } from "./messages.js";
|
|
6
11
|
import { gradients } from "./gradients.js";
|
|
7
12
|
import { rgbGradient } from "./rgbGradient.js";
|
|
8
|
-
import { createThemes } from "./themes.js";
|
|
9
13
|
|
|
10
14
|
const marker = {};
|
|
15
|
+
marker.logger = logger;
|
|
16
|
+
marker.table = table;
|
|
17
|
+
marker.spinner = spinner;
|
|
18
|
+
|
|
19
|
+
const chainStyles = {
|
|
20
|
+
...colors,
|
|
21
|
+
...styles,
|
|
22
|
+
...backgrounds
|
|
23
|
+
};
|
|
11
24
|
|
|
12
25
|
function createChain(codes = []) {
|
|
13
26
|
const builder = (text) => {
|
|
@@ -18,10 +31,7 @@ function createChain(codes = []) {
|
|
|
18
31
|
return apply(codes, text);
|
|
19
32
|
};
|
|
20
33
|
|
|
21
|
-
for (const [name, code] of Object.entries({
|
|
22
|
-
...colors,
|
|
23
|
-
...styles
|
|
24
|
-
})) {
|
|
34
|
+
for (const [name, code] of Object.entries(chainStyles)) {
|
|
25
35
|
Object.defineProperty(builder, name, {
|
|
26
36
|
get() {
|
|
27
37
|
return createChain([
|
|
@@ -35,10 +45,7 @@ function createChain(codes = []) {
|
|
|
35
45
|
return builder;
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
for (const [name, code] of Object.entries({
|
|
39
|
-
...colors,
|
|
40
|
-
...styles
|
|
41
|
-
})) {
|
|
48
|
+
for (const [name, code] of Object.entries(chainStyles)) {
|
|
42
49
|
Object.defineProperty(marker, name, {
|
|
43
50
|
get() {
|
|
44
51
|
return createChain([code]);
|
|
@@ -46,18 +53,31 @@ for (const [name, code] of Object.entries({
|
|
|
46
53
|
});
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
|
|
57
|
+
// RGB foreground
|
|
49
58
|
marker.rgb = (r, g, b) => {
|
|
50
59
|
return createChain([
|
|
51
60
|
rgb(r, g, b)
|
|
52
61
|
]);
|
|
53
62
|
};
|
|
54
63
|
|
|
64
|
+
|
|
65
|
+
// HEX foreground
|
|
55
66
|
marker.hex = (value) => {
|
|
56
67
|
return createChain([
|
|
57
68
|
hex(value)
|
|
58
69
|
]);
|
|
59
70
|
};
|
|
60
71
|
|
|
72
|
+
|
|
73
|
+
// RGB background
|
|
74
|
+
marker.bgRgb = (r, g, b) => {
|
|
75
|
+
return createChain([
|
|
76
|
+
bgRgb(r, g, b)
|
|
77
|
+
]);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
|
|
61
81
|
// 256 color gradient
|
|
62
82
|
marker.gradient = (text) => {
|
|
63
83
|
if (marker.level === 0) {
|
|
@@ -80,27 +100,35 @@ marker.gradient = (text) => {
|
|
|
80
100
|
return `${output}\x1b[0m`;
|
|
81
101
|
};
|
|
82
102
|
|
|
103
|
+
|
|
83
104
|
// True RGB gradient
|
|
84
105
|
marker.rgbGradient = rgbGradient;
|
|
85
106
|
|
|
107
|
+
|
|
86
108
|
// Gradient presets
|
|
87
109
|
marker.gradients = gradients;
|
|
88
110
|
|
|
111
|
+
|
|
89
112
|
// Box formatting
|
|
90
113
|
marker.box = box;
|
|
91
114
|
|
|
115
|
+
|
|
92
116
|
// Messages
|
|
93
117
|
Object.assign(marker, messages);
|
|
94
118
|
|
|
119
|
+
|
|
95
120
|
// Symbols
|
|
96
121
|
marker.symbols = symbols;
|
|
97
122
|
|
|
123
|
+
|
|
98
124
|
// Text utilities
|
|
99
125
|
Object.assign(marker, text);
|
|
100
126
|
|
|
127
|
+
|
|
101
128
|
// Themes
|
|
102
129
|
marker.themes = createThemes(marker);
|
|
103
130
|
|
|
131
|
+
|
|
104
132
|
function getColorLevel() {
|
|
105
133
|
if (process.env.NO_COLOR) {
|
|
106
134
|
return 0;
|
|
@@ -121,8 +149,10 @@ function getColorLevel() {
|
|
|
121
149
|
return 1;
|
|
122
150
|
}
|
|
123
151
|
|
|
152
|
+
|
|
124
153
|
marker.level = getColorLevel();
|
|
125
154
|
|
|
126
155
|
marker.supportsColor = marker.level > 0;
|
|
127
156
|
|
|
157
|
+
|
|
128
158
|
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.
|