logger-chroma 1.0.2 → 1.0.4

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
@@ -10,7 +10,7 @@
10
10
  </p>
11
11
 
12
12
  * 🎨 A lightweight, high-performance Node.js logging utility designed for developers who need to visualize complex, nested operations. `logger-chroma` transforms flat, messy console outputs into a beautiful, structured tree that makes debugging logical flows intuitive.
13
- * 👨‍💻 Optimized for modern terminals like `Windows Terminal`, `VS Code Integrated Terminal`, and `iTerm2`, `Windows Git Bash Terminal` where box-drawing characters are rendered natively.
13
+ * 👨‍💻 Optimized for modern terminals like `Windows Terminal`, `VS Code Integrated Terminal`, `iTerm2`, and `Windows Git Bash Terminal` where box-drawing characters are rendered natively.
14
14
  * ♻️ Works seamlessly with `CommonJS`, `ESM` and `TypeScript`
15
15
 
16
16
  # 📦 Install via [NPM](https://www.npmjs.com/package/logger-chroma)
package/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * logger-chroma - 🦄 A colorful, developer-friendly Node.js logger with timestamps, emojis, pretty-printed objects, and grouped logs for clear, readable output.
3
- * @version: v1.0.2
3
+ * @version: v1.0.4
4
4
  * @link: https://github.com/tutyamxx/logger-chroma
5
5
  * @license: MIT
6
6
  **/
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * logger-chroma - 🦄 A colorful, developer-friendly Node.js logger with timestamps, emojis, pretty-printed objects, and grouped logs for clear, readable output.
3
- * @version: v1.0.2
3
+ * @version: v1.0.4
4
4
  * @link: https://github.com/tutyamxx/logger-chroma
5
5
  * @license: MIT
6
6
  **/
@@ -39,19 +39,35 @@ const generateLogPrefix = (level, customEmoji, config, depth) => {
39
39
  return `${timestampPart}${indent}${emojiPart}${levelConfig.color(`[${levelConfig.label}]`)}`;
40
40
  };
41
41
 
42
- const createLoggerFunction = (level) => (message, customEmoji, ...additionalArgs) => {
43
- const config = createLoggerFunction.config ?? defaultLoggerConfig;
44
- const depth = createLoggerFunction.currentDepth ?? 0;
42
+ const createLoggerFunction = (level) => (...args) => {
43
+ const config = createLoggerFunction?.config ?? defaultLoggerConfig;
44
+ const depth = createLoggerFunction?.currentDepth ?? 0;
45
+
46
+ let customEmoji = null;
47
+ let messageArgs = args;
48
+
49
+ if (typeof args?.[1] === 'string' && args?.[1]?.length <= 2) {
50
+ customEmoji = args?.[1];
51
+ messageArgs = [args?.[0], ...args?.slice(2)];
52
+ }
53
+
54
+ else if (typeof args?.[0] === 'string' && args?.[0]?.length <= 2) {
55
+ customEmoji = args?.[0];
56
+ messageArgs = args?.slice(1);
57
+ }
58
+
45
59
  const prefix = generateLogPrefix(level, customEmoji, config, depth);
46
60
 
47
- const formattedMessage = [message, ...additionalArgs]
61
+ const formattedMessage = messageArgs
48
62
  ?.map(arg => typeof arg === 'object' ? prettyPrintObject(arg) : arg)
49
63
  ?.join(' ')
50
64
  ?.split('\n')
51
65
  ?.map(line => `${prefix} ${line}`)
52
66
  ?.join('\n');
53
67
 
54
- console.log(formattedMessage);
68
+ if (formattedMessage) {
69
+ console.log(formattedMessage);
70
+ }
55
71
  };
56
72
 
57
73
  const createLogGroup = (groupTitle, groupCallback) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logger-chroma",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "🦄 A colorful, developer-friendly Node.js logger with timestamps, emojis, pretty-printed objects, and grouped logs for clear, readable output.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -112,4 +112,35 @@ describe('Logger Chroma Unit Tests', () => {
112
112
  loggerChroma.config.timestampEnabled = original;
113
113
  });
114
114
  });
115
+
116
+ describe('Emoji & Argument Detection', () => {
117
+ test('Should detect emoji as the first argument', () => {
118
+ loggerChroma.info('🚀', 'Server started');
119
+ const output = stripAnsi(logSpy.mock.calls[0][0]);
120
+
121
+ expect(output).toContain('🚀 [INFO ] Server started');
122
+ });
123
+
124
+ test('Should detect emoji as the second argument', () => {
125
+ loggerChroma.info('Connected to DB', '✅');
126
+ const output = stripAnsi(logSpy.mock.calls[0][0]);
127
+
128
+ expect(output).toContain('✅ [INFO ] Connected to DB');
129
+ });
130
+
131
+ test('Should NOT treat a number as an emoji when passed as second argument', () => {
132
+ loggerChroma.info('Port number:', 3000);
133
+ const output = stripAnsi(logSpy.mock.calls[0][0]);
134
+
135
+ expect(output).toContain('[INFO ] Port number: 3000');
136
+ expect(output).toMatch(/\]\s{4}\[INFO \]/);
137
+ });
138
+
139
+ test('Should handle multiple arguments correctly with an emoji', () => {
140
+ loggerChroma.info('User', '👤', { id: 1 }, 'logged in');
141
+ const output = stripAnsi(logSpy.mock.calls[0][0]);
142
+
143
+ expect(output).toContain('👤 [INFO ] User { id: 1 } logged in');
144
+ });
145
+ });
115
146
  });