chromalogger 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ChromaLogger
2
2
 
3
- > A powerful and colorful logger for Node.js with CLI support
3
+ > A powerful and colorful logger for Node.js with advanced formatting
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,23 +8,92 @@
8
8
  npm install chromalogger
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Basic Usage
12
12
 
13
13
  ```javascript
14
14
  import { logger } from 'chromalogger';
15
15
 
16
+ // Basic logging
16
17
  logger.info('This is an info message');
17
18
  logger.success('Operation completed successfully!');
18
19
  logger.warn('This is a warning');
19
20
  logger.error('An error occurred');
20
21
  ```
21
22
 
23
+ ## Advanced Formatting
24
+
25
+ ChromaLogger provides a flexible `format()` method for custom styling:
26
+
27
+ ```javascript
28
+ // Single style
29
+ logger.format(colors.red, 'This text will be red');
30
+
31
+ // Multiple styles combined
32
+ logger.format(
33
+ [colors.bold, colors.bgBlue, colors.white],
34
+ 'Bold white text on blue background'
35
+ );
36
+
37
+ // With timestamps
38
+ logger.setTimestamp(true);
39
+ logger.format(colors.green, 'This will include a timestamp');
40
+
41
+ // Create reusable themes
42
+ const errorTheme = [colors.bright, colors.red];
43
+ const successTheme = [colors.bright, colors.green];
44
+
45
+ logger.format(errorTheme, 'Error: Something went wrong!');
46
+ logger.format(successTheme, 'Success: Operation completed!');
47
+ ```
48
+
49
+ ### Available Styles
50
+
51
+ ChromaLogger includes several built-in styles:
52
+
53
+ - **Text Colors**: black, red, green, yellow, blue, magenta, cyan, white
54
+ - **Background Colors**: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite
55
+ - **Text Styles**: bright, dim, italic, underline, blink, reverse, hidden
56
+
22
57
  ## Features
23
58
 
24
59
  - Colorful console output
25
- - Multiple log levels
26
- - Easy to use API
27
- - CLI support
60
+ - Advanced formatting options
61
+ - Optional timestamps
62
+ - Reusable style themes
63
+ - Browser support with styled console groups
64
+
65
+ ## Browser Support
66
+
67
+ ChromaLogger works in modern browsers with full styling support:
68
+
69
+ ```javascript
70
+ // In your browser code
71
+ import { browser } from 'chromalogger';
72
+
73
+ // All logging methods work in the browser
74
+ browser.info('Browser info message');
75
+ browser.success('Operation completed in browser!');
76
+ browser.warn('Browser warning');
77
+ browser.error('Browser error occurred');
78
+
79
+ // With timestamps
80
+ browser.setTimestamp(true);
81
+ browser.info('This message has a timestamp');
82
+ ```
83
+
84
+ ### Browser-Specific Features
85
+
86
+ - **Collapsible Groups**: Info and success logs are displayed in collapsible groups
87
+ - **Native Console Methods**: Uses `console.warn` and `console.error` for warnings and errors
88
+ - **Responsive Design**: Logs adapt to the browser's console width
89
+
90
+ ### Supported Browsers
91
+
92
+ - Chrome 30+
93
+ - Firefox 25+
94
+ - Edge 12+
95
+ - Safari 7+
96
+ - Opera 15+
28
97
 
29
98
  ## License
30
99
 
package/index.js CHANGED
@@ -1,6 +1,10 @@
1
- // Import and re-export the logger from chromalog.js
2
- export * from './chromalog.js';
1
+ export * from './modules/chromalog.js';
2
+ export * from './modules/chromalog.browser.js';
3
+
4
+ import { logger } from './modules/chromalog.js';
5
+ import { browser } from './modules/chromalog.browser.js';
6
+
7
+ export { logger, browser };
3
8
 
4
- // Set default export to be the default logger instance
5
- import { logger } from './chromalog.js';
6
9
  export default logger;
10
+
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "chromalogger",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A colorful and flexible console logger for Node.js with CLI support",
5
5
  "main": "index.js",
6
+ "browser": "chromalog.browser.js",
6
7
  "type": "module",
7
8
  "files": [
8
9
  "index.js",
9
- "chromalog.js"
10
+ "chromalog.js",
11
+ "chromalog.browser.js"
10
12
  ],
13
+ "browserslist": "> 0.5%, last 2 versions, not dead",
11
14
  "scripts": {
12
- "test": "node demo.js"
15
+ "test": "node ./ideas/demo.js"
13
16
  },
14
17
  "keywords": [
15
18
  "log",
package/chromalog.js DELETED
@@ -1,208 +0,0 @@
1
- // ChromaLogger - A colorful console logger for Node.js
2
-
3
- // Import styles
4
- import {
5
- textColors,
6
- bgColors,
7
- textStyles
8
- } from './styles/index.js';
9
-
10
- // Combine all styles for backward compatibility
11
- const colors = {
12
- ...textColors,
13
- ...bgColors,
14
- ...textStyles
15
- };
16
-
17
- // Main logger class
18
- class Logger {
19
- constructor() {
20
- this.timestamp = false;
21
- }
22
-
23
- // Format the log message with color and style
24
- format(style, ...args) {
25
- const timestamp = this.timestamp ? `[${new Date().toISOString()}] ` : '';
26
- // Si style est un tableau, on combine les styles
27
- const styleStr = Array.isArray(style)
28
- ? style.join('')
29
- : style;
30
- return `${timestamp}${styleStr}${args.join(' ')}${colors.reset}`;
31
- }
32
-
33
- // Log methods with different colors
34
- log(...args) {
35
- console.log(this.format(colors.reset, ...args));
36
- }
37
-
38
- info(...args) {
39
- console.log(this.format(colors.cyan, ...args));
40
- }
41
-
42
- success(...args) {
43
- console.log(this.format(colors.green, '✓', ...args));
44
- }
45
-
46
- warn(...args) {
47
- console.warn(this.format(colors.yellow, '⚠', ...args));
48
- }
49
-
50
- error(...args) {
51
- console.error(this.format(colors.red, '✗', ...args));
52
- }
53
-
54
- // Background color methods
55
- bgBlack(...args) {
56
- this._currentBg = colors.bgBlack;
57
- if (args.length > 0) {
58
- console.log(this.format(this._currentBg, ...args));
59
- this._currentBg = undefined;
60
- }
61
- return this;
62
- }
63
-
64
- bgRed(...args) {
65
- this._currentBg = colors.bgRed;
66
- if (args.length > 0) {
67
- console.log(this.format(this._currentBg, ...args));
68
- this._currentBg = undefined;
69
- }
70
- return this;
71
- }
72
-
73
- bgGreen(...args) {
74
- this._currentBg = colors.bgGreen;
75
- if (args.length > 0) {
76
- console.log(this.format(this._currentBg, ...args));
77
- this._currentBg = undefined;
78
- }
79
- return this;
80
- }
81
-
82
- bgYellow(...args) {
83
- this._currentBg = colors.bgYellow;
84
- if (args.length > 0) {
85
- console.log(this.format(this._currentBg, ...args));
86
- this._currentBg = undefined;
87
- }
88
- return this;
89
- }
90
-
91
- bgBlue(...args) {
92
- this._currentBg = colors.bgBlue;
93
- if (args.length > 0) {
94
- console.log(this.format(this._currentBg, ...args));
95
- this._currentBg = undefined;
96
- }
97
- return this;
98
- }
99
-
100
- bgMagenta(...args) {
101
- this._currentBg = colors.bgMagenta;
102
- if (args.length > 0) {
103
- console.log(this.format(this._currentBg, ...args));
104
- this._currentBg = undefined;
105
- }
106
- return this;
107
- }
108
-
109
- bgCyan(...args) {
110
- this._currentBg = colors.bgCyan;
111
- if (args.length > 0) {
112
- console.log(this.format(this._currentBg, ...args));
113
- this._currentBg = undefined;
114
- }
115
- return this;
116
- }
117
-
118
- bgWhite(...args) {
119
- this._currentBg = colors.bgWhite;
120
- if (args.length > 0) {
121
- console.log(this.format(this._currentBg, ...args));
122
- this._currentBg = undefined;
123
- }
124
- return this;
125
- }
126
-
127
- // Text color methods
128
- black(...args) { return this._applyTextColor(colors.black, ...args); }
129
- red(...args) { return this._applyTextColor(colors.red, ...args); }
130
- green(...args) { return this._applyTextColor(colors.green, ...args); }
131
- yellow(...args) { return this._applyTextColor(colors.yellow, ...args); }
132
- blue(...args) { return this._applyTextColor(colors.blue, ...args); }
133
- magenta(...args) { return this._applyTextColor(colors.magenta, ...args); }
134
- cyan(...args) { return this._applyTextColor(colors.cyan, ...args); }
135
- white(...args) { return this._applyTextColor(colors.white, ...args); }
136
-
137
- // Text style methods
138
- bright(...args) { return this._applyTextStyle(colors.bright, ...args); }
139
- dim(...args) { return this._applyTextStyle(colors.dim, ...args); }
140
- italic(...args) { return this._applyTextStyle(colors.italic, ...args); }
141
- underline(...args) { return this._applyTextStyle(colors.underline, ...args); }
142
- blink(...args) { return this._applyTextStyle(colors.blink, ...args); }
143
- reverse(...args) { return this._applyTextStyle(colors.reverse, ...args); }
144
- hidden(...args) { return this._applyTextStyle(colors.hidden, ...args); }
145
-
146
- // Helper methods for chaining
147
- _applyTextColor(color, ...args) {
148
- this._currentFg = color;
149
- if (args.length > 0) {
150
- this._logWithCurrentStyles(...args);
151
- }
152
- return this;
153
- }
154
-
155
- _applyTextStyle(style, ...args) {
156
- if (!this._currentStyles) this._currentStyles = [];
157
- this._currentStyles.push(style);
158
- if (args.length > 0) {
159
- this._logWithCurrentStyles(...args);
160
- }
161
- return this;
162
- }
163
-
164
- _logWithCurrentStyles(...args) {
165
- const styles = [];
166
- if (this._currentBg) styles.push(this._currentBg);
167
- if (this._currentFg) styles.push(this._currentFg);
168
- if (this._currentStyles) styles.push(...this._currentStyles);
169
-
170
- console.log(this.format(styles, ...args));
171
-
172
- // Reset styles after logging
173
- this._currentBg = undefined;
174
- this._currentFg = undefined;
175
- this._currentStyles = [];
176
- }
177
-
178
- // Combined styles
179
- errorHighlight(...args) {
180
- console.error(this.format([colors.bright, colors.bgRed, colors.white], '✗', ...args));
181
- }
182
-
183
- successHighlight(...args) {
184
- console.log(this.format([colors.bright, colors.bgGreen, colors.black], '✓', ...args));
185
- }
186
-
187
- warningHighlight(...args) {
188
- console.warn(this.format([colors.bright, colors.bgYellow, colors.black], '⚠', ...args));
189
- }
190
-
191
- infoHighlight(...args) {
192
- console.log(this.format([colors.bright, colors.bgBlue, colors.white], 'ℹ', ...args));
193
- }
194
-
195
- // Enable/disable timestamps
196
- setTimestamp(enabled = true) {
197
- this.timestamp = enabled;
198
- return this;
199
- }
200
- }
201
-
202
- // Create a default logger instance
203
- const logger = new Logger();
204
-
205
- // Export the logger class and default instance
206
- export { Logger, logger };
207
-
208
- export default logger;