cstyler 1.0.1 → 2.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.
@@ -0,0 +1,31 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [18.x, 20.x, 22.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v4
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ cache: 'npm'
29
+ - run: npm ci
30
+ - run: npm run build --if-present
31
+ - run: npm test
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # cstyler
1
+ # CSTYLER
2
2
  Hello World!
3
3
 
4
- You can style with color and style on the console text with this package
4
+ Style your console log with your cstyler package by kormoi.com
5
5
 
6
6
  This cstyler kit is fully free to use. You can colorize your console log useing this kit. You can use dot notation to add more style like 'bold, underline, italic, dark(for color), bg for background'. You have all red, green, blue, yellow, cyan, purpal, colors on both text color and background color.
7
7
 
@@ -19,9 +19,13 @@ const cstyle = require("cstyle");
19
19
  USE:
20
20
  console.log(cstyle.bold.underline.italic.dark.yellow("Here goes your text"));
21
21
 
22
+ You can add these colors by name: red, green, blue, yellow, purpal, grey. You can darken them with a .dark property accessor. You can add rbg, hex, bgrgb and bghex color using .hex('#123456'), and rgb(100,100,100) and same for bg hex and bg rgb.
23
+
22
24
  Feel free to use.
23
25
  <<<<<<< HEAD
24
26
  Regards from kormoi.com
25
27
  =======
26
- Regards from kormoi.com
28
+ Regards from
29
+ kormoi.com
30
+ MD NASIRUDDIN AHMED
27
31
  >>>>>>> 7cb483c (Second commit)
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- class cstyle {
1
+ class cstyler {
2
2
  constructor() {
3
3
  return this.createStyler([]);
4
4
  }
@@ -32,14 +32,78 @@ class cstyle {
32
32
  bgGray: ['\x1b[40m', '\x1b[49m']
33
33
  };
34
34
 
35
+ // Dynamically define valid style accessors
35
36
  for (const [name, [open, close]] of Object.entries(styleMap)) {
36
37
  Object.defineProperty(styler, name, {
37
38
  get: () => addStyle(open, close)
38
39
  });
39
40
  }
40
41
 
41
- return styler;
42
+ // RGB support
43
+ styler.rgb = (r, g, b) => {
44
+ if (![r, g, b].every(n => Number.isInteger(n) && n >= 0 && n <= 255)) {
45
+ console.error('Invalid RGB value. Falling back to white.');
46
+ return addStyle('\x1b[37m', '\x1b[39m'); // white
47
+ }
48
+ const open = `\x1b[38;2;${r};${g};${b}m`;
49
+ const close = '\x1b[39m';
50
+ return addStyle(open, close);
51
+ };
52
+
53
+ // Hex color support
54
+ styler.hex = (hex) => {
55
+ try {
56
+ if (typeof hex !== 'string') throw new Error();
57
+ hex = hex.replace('#', '').slice(0, 6);
58
+ const r = parseInt(hex.slice(0, 2), 16);
59
+ const g = parseInt(hex.slice(2, 4), 16);
60
+ const b = parseInt(hex.slice(4, 6), 16);
61
+ return styler.rgb(r, g, b);
62
+ } catch (e) {
63
+ console.error('Invalid hex color. Falling back to white.');
64
+ return addStyle('\x1b[37m', '\x1b[39m'); // white
65
+ }
66
+ };
67
+
68
+ // Background RGB
69
+ styler.bgrgb = (r, g, b) => {
70
+ if (![r, g, b].every(n => Number.isInteger(n) && n >= 0 && n <= 255)) {
71
+ console.error('Invalid background RGB value. Falling back to white.');
72
+ return addStyle('\x1b[47m', '\x1b[49m');
73
+ }
74
+ const open = `\x1b[48;2;${r};${g};${b}m`;
75
+ const close = '\x1b[49m';
76
+ return addStyle(open, close);
77
+ };
78
+
79
+ // Background Hex
80
+ styler.bghex = (hex) => {
81
+ try {
82
+ if (typeof hex !== 'string') throw new Error();
83
+ hex = hex.replace('#', '').slice(0, 6);
84
+ const r = parseInt(hex.slice(0, 2), 16);
85
+ const g = parseInt(hex.slice(2, 4), 16);
86
+ const b = parseInt(hex.slice(4, 6), 16);
87
+ return styler.bgrgb(r, g, b);
88
+ } catch (e) {
89
+ console.error('Invalid background hex. Falling back to white.');
90
+ return addStyle('\x1b[47m', '\x1b[49m');
91
+ }
92
+ };
93
+
94
+ // Use Proxy to catch invalid property access
95
+ return new Proxy(styler, {
96
+ get(target, prop) {
97
+ if (prop in target) {
98
+ return target[prop];
99
+ } else {
100
+ console.log(`Wrong style: ${String(prop)}`);
101
+ console.error(`Invalid property accessor used: ${String(prop)}`);
102
+ return target; // Return unstyled version to continue chain safely
103
+ }
104
+ }
105
+ });
42
106
  }
43
107
  }
44
108
 
45
- module.exports = new cstyle();
109
+ module.exports = new cstyler();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cstyler",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Chainable terminal text styling tool (bold, colors, etc.)",
5
5
  "main": "index.js",
6
6
  "keywords": [