style-logs 0.0.1 → 0.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/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- declare const log: (text: string) => void;
1
+ declare function style(text: string): string;
2
2
 
3
- export { log };
3
+ export { style };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const log: (text: string) => void;
1
+ declare function style(text: string): string;
2
2
 
3
- export { log };
3
+ export { style };
package/dist/index.js CHANGED
@@ -20,20 +20,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- log: () => log
23
+ style: () => style
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // src/console.ts
28
28
  var import_common_tags = require("common-tags");
29
- var style = {
29
+ var logs = {
30
30
  reset: "\x1B[0m",
31
31
  styles: {
32
32
  bold: "\x1B[1m",
33
- dim: "\x1B[2m",
34
33
  underline: "\x1B[4m",
35
- inverse: "\x1B[7m",
36
- hidden: "\x1B[8m"
34
+ inverse: "\x1B[7m"
37
35
  },
38
36
  fg: {
39
37
  black: "\x1B[30m",
@@ -62,7 +60,7 @@ var style = {
62
60
  teal: "\x1B[48;5;6m"
63
61
  }
64
62
  };
65
- var log = (text) => {
63
+ function style(text) {
66
64
  const regex = /<text\s*(.*?)>(.*?)<\/text>/gs;
67
65
  let result = "";
68
66
  const lines = (0, import_common_tags.stripIndents)(text).split("\n");
@@ -72,28 +70,28 @@ var log = (text) => {
72
70
  while ((match = regex.exec(line)) !== null) {
73
71
  const attributes = match[1].trim();
74
72
  const content = match[2];
75
- let colorCode = style.reset;
73
+ let colorCode = logs.reset;
76
74
  if (attributes) {
77
75
  const attributeRegex = /(f|b|s)-(\w+)/g;
78
76
  let attrMatch;
79
77
  while ((attrMatch = attributeRegex.exec(attributes)) !== null) {
80
78
  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];
79
+ if (type === "f" && logs.fg[styleName]) {
80
+ colorCode += logs.fg[styleName];
81
+ } else if (type === "b" && logs.bg[styleName]) {
82
+ colorCode += logs.bg[styleName];
83
+ } else if (type === "s" && logs.styles[styleName]) {
84
+ colorCode += logs.styles[styleName];
87
85
  }
88
86
  }
89
87
  }
90
- processedLine = processedLine.replace(match[0], `${colorCode}${content}${style.reset}`);
88
+ processedLine = processedLine.replace(match[0], `${colorCode}${content}${logs.reset}`);
91
89
  }
92
90
  result += processedLine + "\n";
93
91
  });
94
- console.log(result.trim());
95
- };
92
+ return result.trim();
93
+ }
96
94
  // Annotate the CommonJS export names for ESM import in node:
97
95
  0 && (module.exports = {
98
- log
96
+ style
99
97
  });
package/dist/index.mjs CHANGED
@@ -1,13 +1,11 @@
1
1
  // src/console.ts
2
2
  import { stripIndents } from "common-tags";
3
- var style = {
3
+ var logs = {
4
4
  reset: "\x1B[0m",
5
5
  styles: {
6
6
  bold: "\x1B[1m",
7
- dim: "\x1B[2m",
8
7
  underline: "\x1B[4m",
9
- inverse: "\x1B[7m",
10
- hidden: "\x1B[8m"
8
+ inverse: "\x1B[7m"
11
9
  },
12
10
  fg: {
13
11
  black: "\x1B[30m",
@@ -36,7 +34,7 @@ var style = {
36
34
  teal: "\x1B[48;5;6m"
37
35
  }
38
36
  };
39
- var log = (text) => {
37
+ function style(text) {
40
38
  const regex = /<text\s*(.*?)>(.*?)<\/text>/gs;
41
39
  let result = "";
42
40
  const lines = stripIndents(text).split("\n");
@@ -46,27 +44,27 @@ var log = (text) => {
46
44
  while ((match = regex.exec(line)) !== null) {
47
45
  const attributes = match[1].trim();
48
46
  const content = match[2];
49
- let colorCode = style.reset;
47
+ let colorCode = logs.reset;
50
48
  if (attributes) {
51
49
  const attributeRegex = /(f|b|s)-(\w+)/g;
52
50
  let attrMatch;
53
51
  while ((attrMatch = attributeRegex.exec(attributes)) !== null) {
54
52
  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];
53
+ if (type === "f" && logs.fg[styleName]) {
54
+ colorCode += logs.fg[styleName];
55
+ } else if (type === "b" && logs.bg[styleName]) {
56
+ colorCode += logs.bg[styleName];
57
+ } else if (type === "s" && logs.styles[styleName]) {
58
+ colorCode += logs.styles[styleName];
61
59
  }
62
60
  }
63
61
  }
64
- processedLine = processedLine.replace(match[0], `${colorCode}${content}${style.reset}`);
62
+ processedLine = processedLine.replace(match[0], `${colorCode}${content}${logs.reset}`);
65
63
  }
66
64
  result += processedLine + "\n";
67
65
  });
68
- console.log(result.trim());
69
- };
66
+ return result.trim();
67
+ }
70
68
  export {
71
- log
69
+ style
72
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "style-logs",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Design your console/terminal in HTML style.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -39,7 +39,6 @@
39
39
  "typescript": "^5.4.5"
40
40
  },
41
41
  "dependencies": {
42
- "chalk": "^5.3.0",
43
42
  "common-tags": "^1.8.2"
44
43
  },
45
44
  "repository": {
@@ -49,4 +48,4 @@
49
48
  "bugs": {
50
49
  "url": "https://github.com/unburn/style-logs/issues"
51
50
  }
52
- }
51
+ }