style-logs 0.0.1
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/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +99 -0
- package/dist/index.mjs +72 -0
- package/package.json +52 -0
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
log: () => log
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/console.ts
|
|
28
|
+
var import_common_tags = require("common-tags");
|
|
29
|
+
var style = {
|
|
30
|
+
reset: "\x1B[0m",
|
|
31
|
+
styles: {
|
|
32
|
+
bold: "\x1B[1m",
|
|
33
|
+
dim: "\x1B[2m",
|
|
34
|
+
underline: "\x1B[4m",
|
|
35
|
+
inverse: "\x1B[7m",
|
|
36
|
+
hidden: "\x1B[8m"
|
|
37
|
+
},
|
|
38
|
+
fg: {
|
|
39
|
+
black: "\x1B[30m",
|
|
40
|
+
red: "\x1B[31m",
|
|
41
|
+
green: "\x1B[32m",
|
|
42
|
+
yellow: "\x1B[33m",
|
|
43
|
+
blue: "\x1B[34m",
|
|
44
|
+
magenta: "\x1B[35m",
|
|
45
|
+
cyan: "\x1B[36m",
|
|
46
|
+
white: "\x1B[37m",
|
|
47
|
+
crimson: "\x1B[38m",
|
|
48
|
+
orange: "\x1B[38;5;208m",
|
|
49
|
+
teal: "\x1B[38;5;6m"
|
|
50
|
+
},
|
|
51
|
+
bg: {
|
|
52
|
+
black: "\x1B[40m",
|
|
53
|
+
red: "\x1B[41m",
|
|
54
|
+
green: "\x1B[42m",
|
|
55
|
+
yellow: "\x1B[43m",
|
|
56
|
+
blue: "\x1B[44m",
|
|
57
|
+
magenta: "\x1B[45m",
|
|
58
|
+
cyan: "\x1B[46m",
|
|
59
|
+
white: "\x1B[47m",
|
|
60
|
+
crimson: "\x1B[48m",
|
|
61
|
+
orange: "\x1B[48;5;208m",
|
|
62
|
+
teal: "\x1B[48;5;6m"
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var log = (text) => {
|
|
66
|
+
const regex = /<text\s*(.*?)>(.*?)<\/text>/gs;
|
|
67
|
+
let result = "";
|
|
68
|
+
const lines = (0, import_common_tags.stripIndents)(text).split("\n");
|
|
69
|
+
lines.forEach((line) => {
|
|
70
|
+
let processedLine = line;
|
|
71
|
+
let match;
|
|
72
|
+
while ((match = regex.exec(line)) !== null) {
|
|
73
|
+
const attributes = match[1].trim();
|
|
74
|
+
const content = match[2];
|
|
75
|
+
let colorCode = style.reset;
|
|
76
|
+
if (attributes) {
|
|
77
|
+
const attributeRegex = /(f|b|s)-(\w+)/g;
|
|
78
|
+
let attrMatch;
|
|
79
|
+
while ((attrMatch = attributeRegex.exec(attributes)) !== null) {
|
|
80
|
+
const [, type, styleName] = attrMatch;
|
|
81
|
+
if (type === "f" && style.fg[styleName]) {
|
|
82
|
+
colorCode += style.fg[styleName];
|
|
83
|
+
} else if (type === "b" && style.bg[styleName]) {
|
|
84
|
+
colorCode += style.bg[styleName];
|
|
85
|
+
} else if (type === "s" && style.styles[styleName]) {
|
|
86
|
+
colorCode += style.styles[styleName];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
processedLine = processedLine.replace(match[0], `${colorCode}${content}${style.reset}`);
|
|
91
|
+
}
|
|
92
|
+
result += processedLine + "\n";
|
|
93
|
+
});
|
|
94
|
+
console.log(result.trim());
|
|
95
|
+
};
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
log
|
|
99
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/console.ts
|
|
2
|
+
import { stripIndents } from "common-tags";
|
|
3
|
+
var style = {
|
|
4
|
+
reset: "\x1B[0m",
|
|
5
|
+
styles: {
|
|
6
|
+
bold: "\x1B[1m",
|
|
7
|
+
dim: "\x1B[2m",
|
|
8
|
+
underline: "\x1B[4m",
|
|
9
|
+
inverse: "\x1B[7m",
|
|
10
|
+
hidden: "\x1B[8m"
|
|
11
|
+
},
|
|
12
|
+
fg: {
|
|
13
|
+
black: "\x1B[30m",
|
|
14
|
+
red: "\x1B[31m",
|
|
15
|
+
green: "\x1B[32m",
|
|
16
|
+
yellow: "\x1B[33m",
|
|
17
|
+
blue: "\x1B[34m",
|
|
18
|
+
magenta: "\x1B[35m",
|
|
19
|
+
cyan: "\x1B[36m",
|
|
20
|
+
white: "\x1B[37m",
|
|
21
|
+
crimson: "\x1B[38m",
|
|
22
|
+
orange: "\x1B[38;5;208m",
|
|
23
|
+
teal: "\x1B[38;5;6m"
|
|
24
|
+
},
|
|
25
|
+
bg: {
|
|
26
|
+
black: "\x1B[40m",
|
|
27
|
+
red: "\x1B[41m",
|
|
28
|
+
green: "\x1B[42m",
|
|
29
|
+
yellow: "\x1B[43m",
|
|
30
|
+
blue: "\x1B[44m",
|
|
31
|
+
magenta: "\x1B[45m",
|
|
32
|
+
cyan: "\x1B[46m",
|
|
33
|
+
white: "\x1B[47m",
|
|
34
|
+
crimson: "\x1B[48m",
|
|
35
|
+
orange: "\x1B[48;5;208m",
|
|
36
|
+
teal: "\x1B[48;5;6m"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var log = (text) => {
|
|
40
|
+
const regex = /<text\s*(.*?)>(.*?)<\/text>/gs;
|
|
41
|
+
let result = "";
|
|
42
|
+
const lines = stripIndents(text).split("\n");
|
|
43
|
+
lines.forEach((line) => {
|
|
44
|
+
let processedLine = line;
|
|
45
|
+
let match;
|
|
46
|
+
while ((match = regex.exec(line)) !== null) {
|
|
47
|
+
const attributes = match[1].trim();
|
|
48
|
+
const content = match[2];
|
|
49
|
+
let colorCode = style.reset;
|
|
50
|
+
if (attributes) {
|
|
51
|
+
const attributeRegex = /(f|b|s)-(\w+)/g;
|
|
52
|
+
let attrMatch;
|
|
53
|
+
while ((attrMatch = attributeRegex.exec(attributes)) !== null) {
|
|
54
|
+
const [, type, styleName] = attrMatch;
|
|
55
|
+
if (type === "f" && style.fg[styleName]) {
|
|
56
|
+
colorCode += style.fg[styleName];
|
|
57
|
+
} else if (type === "b" && style.bg[styleName]) {
|
|
58
|
+
colorCode += style.bg[styleName];
|
|
59
|
+
} else if (type === "s" && style.styles[styleName]) {
|
|
60
|
+
colorCode += style.styles[styleName];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
processedLine = processedLine.replace(match[0], `${colorCode}${content}${style.reset}`);
|
|
65
|
+
}
|
|
66
|
+
result += processedLine + "\n";
|
|
67
|
+
});
|
|
68
|
+
console.log(result.trim());
|
|
69
|
+
};
|
|
70
|
+
export {
|
|
71
|
+
log
|
|
72
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "style-logs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Design your console/terminal in HTML style.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"fonts"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"build:watch": "tsup --watch",
|
|
22
|
+
"deploy": "npm publish",
|
|
23
|
+
"deploy:beta": "npm publish --tag beta",
|
|
24
|
+
"test:m": "cd tests && node index.mjs",
|
|
25
|
+
"test:c": "cd tests && node index.js"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"style-logs",
|
|
29
|
+
"stylelogs",
|
|
30
|
+
"console",
|
|
31
|
+
"style console"
|
|
32
|
+
],
|
|
33
|
+
"author": "flameface",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/common-tags": "^1.8.4",
|
|
37
|
+
"@types/node": "^20.12.7",
|
|
38
|
+
"tsup": "^8.0.2",
|
|
39
|
+
"typescript": "^5.4.5"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"chalk": "^5.3.0",
|
|
43
|
+
"common-tags": "^1.8.2"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/unburn/style-logs.git"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/unburn/style-logs/issues"
|
|
51
|
+
}
|
|
52
|
+
}
|