colorino 0.6.1 → 0.7.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/dist/browser.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const determineBaseTheme = require('./shared/colorino.B9WUj1qg.cjs');
3
+ const determineBaseTheme = require('./shared/colorino.DZFkhcaF.cjs');
4
4
 
5
5
  class BrowserColorSupportDetector {
6
6
  constructor(_window, _navigator, _overrideTheme) {
@@ -1,5 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DBw7jOfy.cjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DBw7jOfy.cjs';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.D5epIHWO.cjs';
2
+ export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.D5epIHWO.cjs';
3
3
 
4
4
  declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
5
 
@@ -1,5 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DBw7jOfy.mjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DBw7jOfy.mjs';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.D5epIHWO.mjs';
2
+ export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.D5epIHWO.mjs';
3
3
 
4
4
  declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
5
 
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DBw7jOfy.js';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DBw7jOfy.js';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.D5epIHWO.js';
2
+ export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.D5epIHWO.js';
3
3
 
4
4
  declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
5
 
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ColorLevel, t as themePalettes, a as Colorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.CsFoITs1.mjs';
1
+ import { C as ColorLevel, t as themePalettes, a as Colorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.Irp6M1AW.mjs';
2
2
 
3
3
  class BrowserColorSupportDetector {
4
4
  constructor(_window, _navigator, _overrideTheme) {
package/dist/node.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const determineBaseTheme = require('./shared/colorino.B9WUj1qg.cjs');
3
+ const determineBaseTheme = require('./shared/colorino.DZFkhcaF.cjs');
4
4
 
5
5
  class OscThemeQuerier {
6
6
  constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
package/dist/node.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DBw7jOfy.cjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DBw7jOfy.cjs';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.D5epIHWO.cjs';
2
+ export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.D5epIHWO.cjs';
3
3
 
4
4
  declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
5
 
package/dist/node.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DBw7jOfy.mjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DBw7jOfy.mjs';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.D5epIHWO.mjs';
2
+ export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.D5epIHWO.mjs';
3
3
 
4
4
  declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
5
 
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DBw7jOfy.js';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DBw7jOfy.js';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.D5epIHWO.js';
2
+ export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.D5epIHWO.js';
3
3
 
4
4
  declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
5
 
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { e as err, O as OscQueryError, o as ok, C as ColorLevel, d as determineBaseTheme, t as themePalettes, a as Colorino, I as InputValidator } from './shared/colorino.CsFoITs1.mjs';
1
+ import { e as err, O as OscQueryError, o as ok, C as ColorLevel, d as determineBaseTheme, t as themePalettes, a as Colorino, I as InputValidator } from './shared/colorino.Irp6M1AW.mjs';
2
2
 
3
3
  class OscThemeQuerier {
4
4
  constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
@@ -448,6 +448,7 @@ declare class Colorino {
448
448
  debug(...args: unknown[]): void;
449
449
  private _detectColorSupport;
450
450
  private _maybeWarnUser;
451
+ private _formatValue;
451
452
  private _out;
452
453
  }
453
454
 
@@ -448,6 +448,7 @@ declare class Colorino {
448
448
  debug(...args: unknown[]): void;
449
449
  private _detectColorSupport;
450
450
  private _maybeWarnUser;
451
+ private _formatValue;
451
452
  private _out;
452
453
  }
453
454
 
@@ -448,6 +448,7 @@ declare class Colorino {
448
448
  debug(...args: unknown[]): void;
449
449
  private _detectColorSupport;
450
450
  private _maybeWarnUser;
451
+ private _formatValue;
451
452
  private _out;
452
453
  }
453
454
 
@@ -115,19 +115,47 @@ class Colorino {
115
115
  "[Colorino] No ANSI color support detected in this terminal. See [https://github.com/chalk/supports-color#support-matrix](https://github.com/chalk/supports-color#support-matrix) to learn how to enable terminal color."
116
116
  );
117
117
  }
118
+ _formatValue(value, maxDepth = 3) {
119
+ const seen = /* @__PURE__ */ new WeakSet();
120
+ const sanitize = (val, currentDepth) => {
121
+ if (val === null || typeof val !== "object") return val;
122
+ if (seen.has(val)) return "[Circular]";
123
+ seen.add(val);
124
+ if (currentDepth >= maxDepth) return "[Object]";
125
+ if (Array.isArray(val)) {
126
+ return val.map((item) => sanitize(item, currentDepth + 1));
127
+ }
128
+ const result = {};
129
+ for (const key in val) {
130
+ result[key] = sanitize(val[key], currentDepth + 1);
131
+ }
132
+ return result;
133
+ };
134
+ return JSON.stringify(sanitize(value, 0), null, 2);
135
+ }
118
136
  _out(level, args) {
119
137
  const consoleMethod = isConsoleMethod(level) ? level : "log";
138
+ const processedArgs = args.map((arg) => {
139
+ if (arg !== null && typeof arg === "object" && typeof arg !== "string" && !(arg instanceof Error)) {
140
+ return this._formatValue(arg);
141
+ }
142
+ return arg;
143
+ });
120
144
  if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
121
- if (level === "trace") console.trace(...args);
122
- else console[consoleMethod](...args);
145
+ if (level === "trace") console.trace(...processedArgs);
146
+ else console[consoleMethod](...processedArgs);
123
147
  return;
124
148
  }
125
149
  if (this.isBrowser) {
126
150
  const hex2 = this._palette[level];
127
- if (typeof args[0] === "string") {
128
- console[consoleMethod](`%c${args[0]}`, `color:${hex2}`, ...args.slice(1));
151
+ if (typeof processedArgs[0] === "string") {
152
+ console[consoleMethod](
153
+ `%c${processedArgs[0]}`,
154
+ `color:${hex2}`,
155
+ ...processedArgs.slice(1)
156
+ );
129
157
  } else {
130
- console[consoleMethod](...args);
158
+ console[consoleMethod](...processedArgs);
131
159
  }
132
160
  return;
133
161
  }
@@ -151,17 +179,17 @@ class Colorino {
151
179
  break;
152
180
  }
153
181
  }
154
- const processedArgs = [...args];
155
- const firstStringIndex = processedArgs.findIndex(
182
+ const coloredArgs = [...processedArgs];
183
+ const firstStringIndex = coloredArgs.findIndex(
156
184
  (arg) => typeof arg === "string"
157
185
  );
158
186
  if (firstStringIndex !== -1) {
159
- processedArgs[firstStringIndex] = `${ansiCode}${processedArgs[firstStringIndex]}\x1B[0m`;
187
+ coloredArgs[firstStringIndex] = `${ansiCode}${coloredArgs[firstStringIndex]}\x1B[0m`;
160
188
  }
161
189
  if (level === "trace") {
162
- console.trace(...processedArgs);
190
+ console.trace(...coloredArgs);
163
191
  } else {
164
- console[consoleMethod](...processedArgs);
192
+ console[consoleMethod](...coloredArgs);
165
193
  }
166
194
  }
167
195
  }
@@ -113,19 +113,47 @@ class Colorino {
113
113
  "[Colorino] No ANSI color support detected in this terminal. See [https://github.com/chalk/supports-color#support-matrix](https://github.com/chalk/supports-color#support-matrix) to learn how to enable terminal color."
114
114
  );
115
115
  }
116
+ _formatValue(value, maxDepth = 3) {
117
+ const seen = /* @__PURE__ */ new WeakSet();
118
+ const sanitize = (val, currentDepth) => {
119
+ if (val === null || typeof val !== "object") return val;
120
+ if (seen.has(val)) return "[Circular]";
121
+ seen.add(val);
122
+ if (currentDepth >= maxDepth) return "[Object]";
123
+ if (Array.isArray(val)) {
124
+ return val.map((item) => sanitize(item, currentDepth + 1));
125
+ }
126
+ const result = {};
127
+ for (const key in val) {
128
+ result[key] = sanitize(val[key], currentDepth + 1);
129
+ }
130
+ return result;
131
+ };
132
+ return JSON.stringify(sanitize(value, 0), null, 2);
133
+ }
116
134
  _out(level, args) {
117
135
  const consoleMethod = isConsoleMethod(level) ? level : "log";
136
+ const processedArgs = args.map((arg) => {
137
+ if (arg !== null && typeof arg === "object" && typeof arg !== "string" && !(arg instanceof Error)) {
138
+ return this._formatValue(arg);
139
+ }
140
+ return arg;
141
+ });
118
142
  if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
119
- if (level === "trace") console.trace(...args);
120
- else console[consoleMethod](...args);
143
+ if (level === "trace") console.trace(...processedArgs);
144
+ else console[consoleMethod](...processedArgs);
121
145
  return;
122
146
  }
123
147
  if (this.isBrowser) {
124
148
  const hex2 = this._palette[level];
125
- if (typeof args[0] === "string") {
126
- console[consoleMethod](`%c${args[0]}`, `color:${hex2}`, ...args.slice(1));
149
+ if (typeof processedArgs[0] === "string") {
150
+ console[consoleMethod](
151
+ `%c${processedArgs[0]}`,
152
+ `color:${hex2}`,
153
+ ...processedArgs.slice(1)
154
+ );
127
155
  } else {
128
- console[consoleMethod](...args);
156
+ console[consoleMethod](...processedArgs);
129
157
  }
130
158
  return;
131
159
  }
@@ -149,17 +177,17 @@ class Colorino {
149
177
  break;
150
178
  }
151
179
  }
152
- const processedArgs = [...args];
153
- const firstStringIndex = processedArgs.findIndex(
180
+ const coloredArgs = [...processedArgs];
181
+ const firstStringIndex = coloredArgs.findIndex(
154
182
  (arg) => typeof arg === "string"
155
183
  );
156
184
  if (firstStringIndex !== -1) {
157
- processedArgs[firstStringIndex] = `${ansiCode}${processedArgs[firstStringIndex]}\x1B[0m`;
185
+ coloredArgs[firstStringIndex] = `${ansiCode}${coloredArgs[firstStringIndex]}\x1B[0m`;
158
186
  }
159
187
  if (level === "trace") {
160
- console.trace(...processedArgs);
188
+ console.trace(...coloredArgs);
161
189
  } else {
162
- console[consoleMethod](...processedArgs);
190
+ console[consoleMethod](...coloredArgs);
163
191
  }
164
192
  }
165
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "colorino",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "A super simple colorized logger that gets the most out of your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",