@vielzeug/logit 1.0.5 → 1.1.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/logit.js CHANGED
@@ -1,17 +1,7 @@
1
- const $ = {};
2
- const v = {
1
+ const E = {};
2
+ const $ = {
3
3
  debug: "log",
4
4
  success: "log"
5
- }, w = () => typeof window < "u" && $?.NODE_ENV ? !1 : typeof process < "u" && process.env?.NODE_ENV ? process.env.NODE_ENV === "production" : !1, _ = w(), L = typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches, b = {
6
- debug: { bg: "#616161", border: "#424242", color: "#fff", icon: "☕", symbol: "🅳" },
7
- error: { bg: "#d32f2f", border: "#c62828", color: "#fff", icon: "✘", symbol: "🅴" },
8
- group: { bg: "#546e7a", border: "#455a64", color: "#fff", icon: "⚭", symbol: "🅶" },
9
- info: { bg: "#1976d2", border: "#1565c0", color: "#fff", icon: "ℹ", symbol: "🅸" },
10
- ns: L ? { bg: "#fafafa", border: "#c7c7c7", color: "#000" } : { bg: "#424242", border: "#212121", color: "#fff" },
11
- success: { bg: "#689f38", border: "#558b2f", color: "#fff", icon: "✔", symbol: "🆂" },
12
- time: { bg: "#0097a7", border: "#00838f", color: "#fff", icon: "⏲", symbol: "🆃" },
13
- trace: { bg: "#d81b60", border: "#c2185b", color: "#fff", icon: "⛢", symbol: "🆃" },
14
- warn: { bg: "#ffb300", border: "#ffa000", color: "#fff", icon: "⚠", symbol: "🆆" }
15
5
  }, l = {
16
6
  debug: 0,
17
7
  trace: 1,
@@ -22,76 +12,142 @@ const v = {
22
12
  warn: 6,
23
13
  error: 7,
24
14
  off: 8
25
- }, r = {
15
+ }, w = typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches, p = {
16
+ debug: { bg: "#616161", border: "#424242", color: "#fff", icon: "☕", symbol: "🅳" },
17
+ error: { bg: "#d32f2f", border: "#c62828", color: "#fff", icon: "✘", symbol: "🅴" },
18
+ group: { bg: "#546e7a", border: "#455a64", color: "#fff", icon: "⚭", symbol: "🅶" },
19
+ info: { bg: "#1976d2", border: "#1565c0", color: "#fff", icon: "ℹ", symbol: "🅸" },
20
+ ns: w ? { bg: "#fafafa", border: "#c7c7c7", color: "#000" } : { bg: "#424242", border: "#212121", color: "#fff" },
21
+ success: { bg: "#689f38", border: "#558b2f", color: "#fff", icon: "✔", symbol: "🆂" },
22
+ time: { bg: "#0097a7", border: "#00838f", color: "#fff", icon: "⏲", symbol: "🆃" },
23
+ trace: { bg: "#d81b60", border: "#c2185b", color: "#fff", icon: "⛢", symbol: "🆃" },
24
+ warn: { bg: "#ffb300", border: "#ffa000", color: "#fff", icon: "⚠", symbol: "🆆" }
25
+ }, b = "border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter; padding: 0 4px;";
26
+ function L() {
27
+ return typeof window < "u" && E?.NODE_ENV === "production" ? !0 : typeof process < "u" && process.env?.NODE_ENV === "production";
28
+ }
29
+ const v = L(), o = {
26
30
  environment: !0,
27
31
  logLevel: "debug",
28
32
  namespace: "",
29
33
  remote: { handler: void 0, logLevel: "off" },
30
34
  timestamp: !0,
31
35
  variant: "symbol"
32
- }, a = (e) => l[r.logLevel] <= l[e], u = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), d = () => _ ? "🄿" : "🄳", x = (e, o) => {
33
- r.remote.handler && l[r.remote.logLevel] <= l[e] && r.remote.handler(e, ...o);
34
- }, g = (e) => v[e] || e, m = "border: 1px solid", p = "border-radius: 4px", h = "border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter", f = (e, o = "") => {
35
- const { bg: t, color: c, border: n } = b[e], s = `color: ${t}; ${m} ${n}; ${p}`;
36
- switch (r.variant) {
36
+ };
37
+ function a(e) {
38
+ return l[o.logLevel] <= l[e];
39
+ }
40
+ function g() {
41
+ return (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
42
+ }
43
+ function d() {
44
+ return v ? "🅿" : "🅳";
45
+ }
46
+ function _(e, t) {
47
+ const { handler: r, logLevel: n } = o.remote;
48
+ r && l[n] <= l[e] && Promise.resolve().then(() => {
49
+ r(e, {
50
+ args: t,
51
+ environment: v ? "production" : "development",
52
+ namespace: o.namespace || void 0,
53
+ timestamp: o.timestamp ? g() : void 0
54
+ });
55
+ });
56
+ }
57
+ function u(e) {
58
+ return $[e] || e;
59
+ }
60
+ function f(e, t = "") {
61
+ const { bg: r, color: n, border: s } = p[e], c = `border: 1px solid ${s}; border-radius: 4px`;
62
+ switch (o.variant) {
37
63
  case "symbol":
38
- return `${s}; padding: 1px 1px 0${o}`;
39
64
  case "icon":
40
- return `${s}; padding: 0 3px${o}`;
65
+ return `color: ${r}; ${c}; padding: 0 3px${t}`;
41
66
  default:
42
- return `background: ${t}; color: ${c}; ${m} ${n}; ${p}; font-weight: bold; padding: 0 3px${o}`;
67
+ return `background: ${r}; color: ${n}; ${c}; font-weight: bold; padding: 0 3px${t}`;
43
68
  }
44
- }, E = (e) => {
45
- const o = b[e], { variant: t } = r;
46
- return t === "text" || !o[t] ? e.toUpperCase() : o[t];
47
- };
48
- function D(e) {
49
- const { namespace: o, timestamp: t, environment: c } = r;
50
- let n = `%c${E(e)}%c`;
51
- const s = [f(e), ""];
52
- return o && (n += ` %c${o}%c`, s.push(f("ns", `; ${h}`), "")), c && (n += ` %c${d()}%c`, s.push("color: darkgray", "")), t && (n += ` %c${u()}%c`, s.push("color: gray", "")), { format: n, parts: s };
53
69
  }
54
- const i = (e, ...o) => {
70
+ function h(e) {
71
+ if (e === "table")
72
+ return e.toUpperCase();
73
+ const t = p[e], { variant: r } = o;
74
+ return r === "text" || !t[r] ? e.toUpperCase() : t[r];
75
+ }
76
+ function x(e) {
77
+ const { namespace: t, timestamp: r, environment: n } = o;
78
+ let s = `%c${h(e)}%c`;
79
+ const c = [f(e), ""];
80
+ return t && (s += ` %c${t}%c`, c.push(f("ns", `; ${b}`), "")), n && (s += ` %c${d()}%c`, c.push("color: darkgray", "")), r && (s += ` %c${g()}%c`, c.push("color: gray", "")), { format: s, parts: c };
81
+ }
82
+ function i(e, ...t) {
55
83
  if (typeof window > "u") {
56
- const s = console[g(e)];
57
- s(`${E(e)} | ${d()} |`, ...o);
84
+ const c = console[u(e)];
85
+ c(`${h(e)} | ${d()} |`, ...t);
58
86
  return;
59
87
  }
60
88
  if (!a(e)) return;
61
- const { format: t, parts: c } = D(e), n = console[g(e)];
62
- n(t, ...c, ...o), x(e, o);
63
- }, O = (e) => {
64
- const o = Math.floor(Date.now() - e);
65
- return o ? `${o}ms` : "";
66
- }, y = {
89
+ const { format: r, parts: n } = x(e), s = console[u(e)];
90
+ s(r, ...n, ...t), _(e, t);
91
+ }
92
+ function O(e) {
93
+ const t = o.namespace, r = t ? `${t}.${e}` : e, n = (s) => (...c) => {
94
+ const m = o.namespace;
95
+ o.namespace = r, i(s, ...c), o.namespace = m;
96
+ };
97
+ return {
98
+ debug: n("debug"),
99
+ error: n("error"),
100
+ info: n("info"),
101
+ success: n("success"),
102
+ trace: n("trace"),
103
+ warn: n("warn")
104
+ };
105
+ }
106
+ const D = {
107
+ /**
108
+ * Asserts a condition and logs if false.
109
+ */
110
+ assert: (e, t, r) => {
111
+ console.assert(e, t, r);
112
+ },
67
113
  /**
68
- * Asserts a condition and logs an error if it's false.
114
+ * Logs a debug message.
69
115
  */
70
- assert: (e, o, t) => console.assert(e, o, t),
71
116
  debug: (...e) => i("debug", ...e),
117
+ /**
118
+ * Logs an error message.
119
+ */
72
120
  error: (...e) => i("error", ...e),
121
+ /**
122
+ * Gets environment indicator visibility.
123
+ */
124
+ getEnvironment: () => o.environment,
73
125
  /**
74
126
  * Gets the current log level.
75
127
  */
76
- getLevel: () => r.logLevel,
128
+ getLevel: () => o.logLevel,
129
+ /**
130
+ * Gets the current namespace.
131
+ */
132
+ getPrefix: () => o.namespace,
77
133
  /**
78
- * Gets the current namespace prefix.
134
+ * Gets timestamp visibility.
79
135
  */
80
- getPrefix: () => r.namespace,
136
+ getTimestamp: () => o.timestamp,
81
137
  /**
82
- * Gets whether timestamps are shown.
138
+ * Gets the current variant.
83
139
  */
84
- getTimestamp: () => r.timestamp,
140
+ getVariant: () => o.variant,
85
141
  /**
86
- * Creates a collapsed group in the console.
142
+ * Creates a collapsed console group.
87
143
  */
88
- groupCollapsed: (e, o = "GROUP", t = Date.now()) => {
144
+ groupCollapsed: (e, t = "GROUP", r = Date.now()) => {
89
145
  if (!a("success")) return;
90
- const c = O(t), n = d(), s = r.timestamp ? u() : "";
146
+ const n = Date.now() - r, s = n ? `${n}ms` : "", c = d(), m = o.timestamp ? g() : "";
91
147
  console.groupCollapsed(
92
- `%c${o}%c${r.namespace}%c${n}%c${s}%c${c}%c${e}`,
148
+ `%c${t}%c${o.namespace}%c${c}%c${m}%c${s}%c${e}`,
93
149
  f("group", "; margin-right: 6px; padding: 1px 3px 0"),
94
- f("ns", `; ${h}; margin-right: 6px`),
150
+ f("ns", `; ${b}; margin-right: 6px`),
95
151
  "color: darkgray; margin-right: 6px",
96
152
  "color: gray; font-weight: lighter; margin-right: 6px",
97
153
  "color: gray; font-weight: lighter; margin-right: 6px",
@@ -104,55 +160,73 @@ const i = (e, ...o) => {
104
160
  groupEnd: () => {
105
161
  a("success") && console.groupEnd();
106
162
  },
163
+ /**
164
+ * Logs an info message.
165
+ */
107
166
  info: (...e) => i("info", ...e),
108
167
  /**
109
- * Initializes Logit with custom options.
168
+ * Creates a scoped logger with a namespace.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * const apiLogger = Logit.scope('api');
173
+ * apiLogger.info('Request received'); // [api] Request received
174
+ * ```
110
175
  */
111
- initialise: (e) => {
112
- Object.assign(r, e);
113
- },
176
+ scope: (e) => O(e),
114
177
  /**
115
- * Sets the minimum log level to display.
178
+ * Sets the minimum log level.
116
179
  */
117
180
  setLogLevel: (e) => {
118
- r.logLevel = e;
181
+ o.logLevel = e;
119
182
  },
120
183
  /**
121
- * Sets the namespace prefix for all logs.
184
+ * Sets the global namespace prefix.
122
185
  */
123
186
  setPrefix: (e) => {
124
- r.namespace = e;
187
+ o.namespace = e;
125
188
  },
126
189
  /**
127
- * Configures remote logging options.
190
+ * Sets the remote logging options.
128
191
  */
129
192
  setRemote: (e) => {
130
- r.remote = e;
193
+ o.remote = { ...o.remote, ...e };
131
194
  },
132
195
  /**
133
- * Sets the log level for remote logging.
196
+ * Sets the remote log level.
134
197
  */
135
198
  setRemoteLogLevel: (e) => {
136
- r.remote.logLevel = e;
199
+ o.remote.logLevel = e;
137
200
  },
138
201
  /**
139
- * Sets the display variant (text, icon, or symbol).
202
+ * Configures Logit with options.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * Logit.setup({
207
+ * logLevel: 'info',
208
+ * variant: 'text',
209
+ * timestamp: false
210
+ * });
211
+ * ```
140
212
  */
141
- setVariant: (e) => {
142
- r.variant = e;
213
+ setup: (e) => {
214
+ if (e.remote) {
215
+ o.remote = { ...o.remote, ...e.remote };
216
+ const { remote: t, ...r } = e;
217
+ Object.assign(o, r);
218
+ } else
219
+ Object.assign(o, e);
143
220
  },
144
221
  /**
145
- * Shows or hides the environment indicator.
222
+ * Sets the display variant.
146
223
  */
147
- showEnvironment: (e) => {
148
- r.environment = e;
224
+ setVariant: (e) => {
225
+ o.variant = e;
149
226
  },
150
227
  /**
151
- * Shows or hides timestamps in logs.
228
+ * Logs a success message.
152
229
  */
153
- showTimestamp: (e) => {
154
- r.timestamp = e;
155
- },
156
230
  success: (...e) => i("success", ...e),
157
231
  /**
158
232
  * Displays data in a table format.
@@ -161,21 +235,39 @@ const i = (e, ...o) => {
161
235
  a("table") && console.table(...e);
162
236
  },
163
237
  /**
164
- * Starts a timer with the given label.
238
+ * Starts a timer.
165
239
  */
166
240
  time: (e) => {
167
241
  a("time") && console.time(e);
168
242
  },
169
243
  /**
170
- * Ends a timer with the given label.
244
+ * Ends a timer.
171
245
  */
172
246
  timeEnd: (e) => {
173
247
  a("time") && console.timeEnd(e);
174
248
  },
249
+ /**
250
+ * Toggles or sets environment indicator visibility.
251
+ */
252
+ toggleEnvironment: (e) => {
253
+ o.environment = e ?? !o.environment;
254
+ },
255
+ /**
256
+ * Toggles or sets timestamp visibility.
257
+ */
258
+ toggleTimestamp: (e) => {
259
+ o.timestamp = e ?? !o.timestamp;
260
+ },
261
+ /**
262
+ * Logs a trace message.
263
+ */
175
264
  trace: (...e) => i("trace", ...e),
265
+ /**
266
+ * Logs a warning message.
267
+ */
176
268
  warn: (...e) => i("warn", ...e)
177
269
  };
178
270
  export {
179
- y as Logit
271
+ D as Logit
180
272
  };
181
273
  //# sourceMappingURL=logit.js.map
package/dist/logit.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logit.js","sources":["../src/logit.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noAssignInExpressions: - */\n/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\n/**\n * Environment indicator symbols.\n */\nconst ENV_PROD = '\\uD83C\\uDD3F'; // 🅿\nconst ENV_DEV = '\\uD83C\\uDD33'; // 🅳\n\n/**\n * Console method mappings for log types.\n */\nconst CONSOLE_METHOD_MAP: Record<string, keyof Console> = {\n debug: 'log',\n success: 'log',\n} as const;\n\n/**\n * Checks if the current environment is production.\n * Cached for performance - evaluated once at a module load.\n */\nconst isProduction = (): boolean => {\n // Browser environment (Vite, Webpack, etc.)\n if (typeof window !== 'undefined' && (import.meta as any)?.env?.NODE_ENV) {\n return (import.meta as any).env.NODE_ENV === 'production';\n }\n\n // Node.js environment\n // @ts-expect-error\n if (typeof process !== 'undefined' && (process as any).env?.NODE_ENV) {\n // @ts-expect-error\n return (process as any).env.NODE_ENV === 'production';\n }\n\n return false;\n};\n\n// Cache the result to avoid repeated checks\nconst IS_PROD = isProduction();\n\nexport type LogitInstance = typeof Logit;\nexport type LogitType = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error';\nexport type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';\nexport type LogitLevel = LogitType | 'off';\nexport type LogitRemoteOptions = {\n handler?: (...args: any[]) => void;\n logLevel: LogitLevel;\n};\nexport type LogitOptions = {\n environment?: boolean;\n variant?: 'text' | 'symbol' | 'icon';\n logLevel?: LogitLevel;\n namespace?: string;\n remote?: LogitRemoteOptions;\n timestamp?: boolean;\n};\nexport type LogitTheme = { color: string; bg: string; border: string; icon?: string; symbol?: string };\n\n/**\n * Detects dark mode preference at module load time.\n * Note: This is intentionally static and won't update if the user changes their theme.\n */\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\n\nconst Theme: Readonly<Record<LogitColors, LogitTheme>> = {\n debug: { bg: '#616161', border: '#424242', color: '#fff', icon: '\\u2615', symbol: '\\uD83C\\uDD73' },\n error: { bg: '#d32f2f', border: '#c62828', color: '#fff', icon: '\\u2718', symbol: '\\uD83C\\uDD74' },\n group: { bg: '#546e7a', border: '#455a64', color: '#fff', icon: '\\u26AD', symbol: '\\uD83C\\uDD76' },\n info: { bg: '#1976d2', border: '#1565c0', color: '#fff', icon: '\\u2139', symbol: '\\uD83C\\uDD78' },\n ns: isDark\n ? { bg: '#fafafa', border: '#c7c7c7', color: '#000' }\n : { bg: '#424242', border: '#212121', color: '#fff' },\n success: { bg: '#689f38', border: '#558b2f', color: '#fff', icon: '\\u2714', symbol: '\\uD83C\\uDD82' },\n time: { bg: '#0097a7', border: '#00838f', color: '#fff', icon: '\\u23F2', symbol: '\\uD83C\\uDD83' },\n trace: { bg: '#d81b60', border: '#c2185b', color: '#fff', icon: '\\u26e2', symbol: '\\uD83C\\uDD83' },\n warn: { bg: '#ffb300', border: '#ffa000', color: '#fff', icon: '\\u26a0', symbol: '\\uD83C\\uDD86' },\n};\n\n// biome-ignore assist/source/useSortedKeys: -\nconst logLevel: Readonly<Record<LogitLevel, number>> = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8,\n};\n\nconst state: Required<LogitOptions> = {\n environment: true,\n logLevel: 'debug',\n namespace: '',\n remote: { handler: undefined, logLevel: 'off' },\n timestamp: true,\n variant: 'symbol',\n};\n\n/**\n * Determines if a log message should be shown based on the current log level.\n */\nconst shouldLog = (type: LogitType): boolean => logLevel[state.logLevel] <= logLevel[type];\n\n/**\n * Gets the current timestamp in ISO format (HH:MM:SS.mmm).\n */\nconst getCurrentTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (IS_PROD ? ENV_PROD : ENV_DEV);\n\n/**\n * Sends log data to remote handler if configured.\n */\nconst sendRemoteLog = (type: LogitType, args: any[]): void => {\n if (state.remote.handler && logLevel[state.remote.logLevel] <= logLevel[type]) {\n state.remote.handler(type, ...args);\n }\n};\n\n/**\n * Gets the console method for a given log type.\n */\nconst getConsoleMethod = (type: LogitType): keyof Console => {\n return (CONSOLE_METHOD_MAP[type] || type) as keyof Console;\n};\n\n/**\n * CSS style constants for consistent formatting.\n */\nconst BASE_BORDER_STYLE = 'border: 1px solid';\nconst BASE_BORDER_RADIUS = 'border-radius: 4px';\nconst NAMESPACE_STYLE = 'border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter';\n\n/**\n * Generates CSS styles for log messages based on theme and variant.\n */\nconst style = (type: LogitColors, extra = ''): string => {\n const { bg, color, border } = Theme[type];\n const baseStyle = `color: ${bg}; ${BASE_BORDER_STYLE} ${border}; ${BASE_BORDER_RADIUS}`;\n\n switch (state.variant) {\n case 'symbol':\n return `${baseStyle}; padding: 1px 1px 0${extra}`;\n case 'icon':\n return `${baseStyle}; padding: 0 3px${extra}`;\n default:\n return `background: ${bg}; color: ${color}; ${BASE_BORDER_STYLE} ${border}; ${BASE_BORDER_RADIUS}; font-weight: bold; padding: 0 3px${extra}`;\n }\n};\n\n/**\n * Gets the display value for a log type based on current variant.\n */\nconst getDisplayValue = (type: LogitType): string => {\n const theme = Theme[type as LogitColors];\n const { variant } = state;\n\n // For 'text' variant or if the variant key doesn't exist, use uppercase type\n if (variant === 'text' || !theme[variant]) {\n return type.toUpperCase();\n }\n\n return theme[variant] as string;\n};\n\n/**\n * Builds the format string and style parts for browser console logging.\n */\nfunction buildBrowserLogParts(type: LogitType): { format: string; parts: string[] } {\n const { namespace, timestamp, environment } = state;\n\n let format = `%c${getDisplayValue(type)}%c`;\n const parts: string[] = [style(type as LogitColors), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', `; ${NAMESPACE_STYLE}`), '');\n }\n\n if (environment) {\n format += ` %c${getEnvIndicator()}%c`;\n parts.push('color: darkgray', '');\n }\n\n if (timestamp) {\n format += ` %c${getCurrentTimestamp()}%c`;\n parts.push('color: gray', '');\n }\n\n return { format, parts };\n}\n\n/**\n * Logs messages to the console with styling and metadata.\n */\nconst log = (type: LogitType, ...args: any[]): void => {\n // Server-side logging (Node.js)\n if (typeof window === 'undefined') {\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any[]) => void;\n consoleMethod(`${getDisplayValue(type)} | ${getEnvIndicator()} |`, ...args);\n return;\n }\n\n // Check log level\n if (!shouldLog(type)) return;\n\n // Browser-side logging with styling\n const { format, parts } = buildBrowserLogParts(type);\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any[]) => void;\n\n consoleMethod(format, ...parts, ...args);\n sendRemoteLog(type, args);\n};\n\n/**\n * Formats the elapsed time for display.\n */\nconst formatElapsedTime = (startTime: number): string => {\n const elapsed = Math.floor(Date.now() - startTime);\n return elapsed ? `${elapsed}ms` : '';\n};\n\nexport const Logit = {\n /**\n * Asserts a condition and logs an error if it's false.\n */\n assert: (valid: boolean, message: string, context: Record<string, any>): void =>\n console.assert(valid, message, context),\n\n debug: (...args: any[]): void => log('debug', ...args),\n error: (...args: any[]): void => log('error', ...args),\n\n /**\n * Gets the current log level.\n */\n getLevel: (): LogitLevel => state.logLevel,\n\n /**\n * Gets the current namespace prefix.\n */\n getPrefix: (): string => state.namespace,\n\n /**\n * Gets whether timestamps are shown.\n */\n getTimestamp: (): boolean => state.timestamp,\n\n /**\n * Creates a collapsed group in the console.\n */\n groupCollapsed: (text: string, label = 'GROUP', time = Date.now()): void => {\n if (!shouldLog('success')) return;\n\n const elapsed = formatElapsedTime(time);\n const env = getEnvIndicator();\n const timestamp = state.timestamp ? getCurrentTimestamp() : '';\n\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${timestamp}%c${elapsed}%c${text}`,\n style('group', '; margin-right: 6px; padding: 1px 3px 0'),\n style('ns', `; ${NAMESPACE_STYLE}; margin-right: 6px`),\n 'color: darkgray; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: inherit; font-weight: lighter',\n );\n },\n\n /**\n * Ends the current console group.\n */\n groupEnd: (): void => {\n if (shouldLog('success')) console.groupEnd();\n },\n\n info: (...args: any[]): void => log('info', ...args),\n\n /**\n * Initializes Logit with custom options.\n */\n initialise: (options: LogitOptions): void => {\n Object.assign(state, options);\n },\n\n /**\n * Sets the minimum log level to display.\n */\n setLogLevel: (level: LogitLevel): void => {\n state.logLevel = level;\n },\n\n /**\n * Sets the namespace prefix for all logs.\n */\n setPrefix: (namespace: string): void => {\n state.namespace = namespace;\n },\n\n /**\n * Configures remote logging options.\n */\n setRemote: (remote: LogitRemoteOptions): void => {\n state.remote = remote;\n },\n\n /**\n * Sets the log level for remote logging.\n */\n setRemoteLogLevel: (level: LogitLevel): void => {\n state.remote.logLevel = level;\n },\n\n /**\n * Sets the display variant (text, icon, or symbol).\n */\n setVariant: (variant: 'text' | 'icon' | 'symbol'): void => {\n state.variant = variant;\n },\n\n /**\n * Shows or hides the environment indicator.\n */\n showEnvironment: (value: boolean): void => {\n state.environment = value;\n },\n\n /**\n * Shows or hides timestamps in logs.\n */\n showTimestamp: (value: boolean): void => {\n state.timestamp = value;\n },\n\n success: (...args: any[]): void => log('success', ...args),\n\n /**\n * Displays data in a table format.\n */\n table: (...args: any[]): void => {\n if (shouldLog('table')) console.table(...args);\n },\n\n /**\n * Starts a timer with the given label.\n */\n time: (label: string): void => {\n if (shouldLog('time')) console.time(label);\n },\n\n /**\n * Ends a timer with the given label.\n */\n timeEnd: (label: string): void => {\n if (shouldLog('time')) console.timeEnd(label);\n },\n\n trace: (...args: any[]): void => log('trace', ...args),\n warn: (...args: any[]): void => log('warn', ...args),\n};\n"],"names":["CONSOLE_METHOD_MAP","isProduction","__vite_import_meta_env__","IS_PROD","isDark","Theme","logLevel","state","shouldLog","type","getCurrentTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","BASE_BORDER_STYLE","BASE_BORDER_RADIUS","NAMESPACE_STYLE","style","extra","bg","color","border","baseStyle","getDisplayValue","theme","variant","buildBrowserLogParts","namespace","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text","label","time","env","options","level","remote","value"],"mappings":";AAYA,MAAMA,IAAoD;AAAA,EACxD,OAAO;AAAA,EACP,SAAS;AACX,GAMMC,IAAe,MAEf,OAAO,SAAW,OAAgBC,GAA0B,WACtD,KAKN,OAAO,UAAY,OAAgB,QAAgB,KAAK,WAElD,QAAgB,IAAI,aAAa,eAGpC,IAIHC,IAAUF,EAAA,GAwBVG,IAAS,OAAO,SAAW,OAAe,OAAO,aAAa,8BAA8B,EAAE,SAE9FC,IAAmD;AAAA,EACvD,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAU,QAAQ,KAAA;AAAA,EAClF,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAU,QAAQ,KAAA;AAAA,EAClF,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAU,QAAQ,KAAA;AAAA,EAClF,MAAM,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAU,QAAQ,KAAA;AAAA,EACjF,IAAID,IACA,EAAE,IA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AAA;AAAA;AAAA;AAAA,EAKA,MAAM,CAAC8B,MAAwB;AAC7B,IAAInC,EAAU,MAAM,KAAG,QAAQ,KAAKmC,CAAK;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,CAACA,MAAwB;AAChC,IAAInC,EAAU,MAAM,KAAG,QAAQ,QAAQmC,CAAK;AAAA,EAC9C;AAAA,EAEA,OAAO,IAAI9B,MAAsBoB,EAAI,SAAS,GAAGpB,CAAI;AAAA,EACrD,MAAM,IAAIA,MAAsBoB,EAAI,QAAQ,GAAGpB,CAAI;AACrD;"}
1
+ {"version":3,"file":"logit.js","sources":["../src/logit.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\n/* -------------------- Core Types -------------------- */\n\nexport type LogLevel = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error' | 'off';\nexport type LogType = Exclude<LogLevel, 'off'>;\nexport type ColorType = Exclude<LogType, 'table'> | 'group' | 'ns';\nexport type Variant = 'text' | 'symbol' | 'icon';\n\nexport type RemoteOptions = {\n handler?: (type: LogType, data: RemoteLogData) => void;\n logLevel?: LogLevel;\n};\n\nexport type RemoteLogData = {\n args: unknown[];\n environment: 'production' | 'development';\n namespace?: string;\n timestamp?: string;\n};\n\nexport type LogitOptions = {\n environment?: boolean;\n variant?: Variant;\n logLevel?: LogLevel;\n namespace?: string;\n remote?: RemoteOptions;\n timestamp?: boolean;\n};\n\nexport type ScopedLogger = {\n debug: (...args: unknown[]) => void;\n error: (...args: unknown[]) => void;\n info: (...args: unknown[]) => void;\n success: (...args: unknown[]) => void;\n trace: (...args: unknown[]) => void;\n warn: (...args: unknown[]) => void;\n};\n\n/* -------------------- Constants -------------------- */\n\nconst ENV_PROD = '🅿';\nconst ENV_DEV = '🅳';\n\nconst CONSOLE_METHOD_MAP: Partial<Record<LogType, keyof Console>> = {\n debug: 'log',\n success: 'log',\n};\n\n// biome-ignore assist/source/useSortedKeys: -\nconst LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {\n debug: 0,\n trace: 1,\n time: 2,\n table: 3,\n info: 4,\n success: 5,\n warn: 6,\n error: 7,\n off: 8,\n};\n\n/* -------------------- Theme & Styles -------------------- */\n\ntype Theme = {\n color: string;\n bg: string;\n border: string;\n icon?: string;\n symbol?: string;\n};\n\nconst isDarkMode = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\n\nconst THEME: Record<ColorType, Theme> = {\n debug: { bg: '#616161', border: '#424242', color: '#fff', icon: '☕', symbol: '🅳' },\n error: { bg: '#d32f2f', border: '#c62828', color: '#fff', icon: '✘', symbol: '🅴' },\n group: { bg: '#546e7a', border: '#455a64', color: '#fff', icon: '⚭', symbol: '🅶' },\n info: { bg: '#1976d2', border: '#1565c0', color: '#fff', icon: 'ℹ', symbol: '🅸' },\n ns: isDarkMode\n ? { bg: '#fafafa', border: '#c7c7c7', color: '#000' }\n : { bg: '#424242', border: '#212121', color: '#fff' },\n success: { bg: '#689f38', border: '#558b2f', color: '#fff', icon: '✔', symbol: '🆂' },\n time: { bg: '#0097a7', border: '#00838f', color: '#fff', icon: '⏲', symbol: '🆃' },\n trace: { bg: '#d81b60', border: '#c2185b', color: '#fff', icon: '⛢', symbol: '🆃' },\n warn: { bg: '#ffb300', border: '#ffa000', color: '#fff', icon: '⚠', symbol: '🆆' },\n};\n\nconst NAMESPACE_STYLE = 'border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter; padding: 0 4px;';\n\n/* -------------------- Environment Detection -------------------- */\n\n/**\n * Detects if running in a production environment.\n * Checks both browser (import.meta.env) and Node.js (process.env).\n */\nfunction isProduction(): boolean {\n // Browser environment (Vite, Webpack, etc.)\n if (typeof window !== 'undefined' && (import.meta as any)?.env?.NODE_ENV === 'production') {\n return true;\n }\n\n // @ts-expect-error - process.env exists in Node.js but not in a browser\n return typeof process !== 'undefined' && (process as any).env?.NODE_ENV === 'production';\n}\n\nconst IS_PROD = isProduction();\n\n/* -------------------- State -------------------- */\n\nconst state: Required<LogitOptions> & { remote: Required<RemoteOptions> } = {\n environment: true,\n logLevel: 'debug',\n namespace: '',\n remote: { handler: undefined as any, logLevel: 'off' },\n timestamp: true,\n variant: 'symbol',\n};\n\n/* -------------------- Helper Functions -------------------- */\n\n/**\n * Checks if a log should be displayed based on the current log level.\n */\nfunction shouldLog(type: LogType): boolean {\n return LOG_LEVEL_PRIORITY[state.logLevel] <= LOG_LEVEL_PRIORITY[type];\n}\n\n/**\n * Gets the current timestamp in HH:MM:SS.mmm format.\n */\nfunction getTimestamp(): string {\n return new Date().toISOString().slice(11, 23);\n}\n\n/**\n * Gets environment indicator emoji.\n */\nfunction getEnvIndicator(): string {\n return IS_PROD ? ENV_PROD : ENV_DEV;\n}\n\n/**\n * Sends log to remote handler if configured.\n */\nfunction sendRemote(type: LogType, args: unknown[]): void {\n const { handler, logLevel } = state.remote;\n\n if (handler && LOG_LEVEL_PRIORITY[logLevel] <= LOG_LEVEL_PRIORITY[type]) {\n // Use microtask to make async without setTimeout overhead\n Promise.resolve().then(() => {\n handler(type, {\n args,\n environment: IS_PROD ? 'production' : 'development',\n namespace: state.namespace || undefined,\n timestamp: state.timestamp ? getTimestamp() : undefined,\n });\n });\n }\n}\n\n/**\n * Gets the console method for a log type.\n */\nfunction getConsoleMethod(type: LogType): keyof Console {\n return (CONSOLE_METHOD_MAP[type] || type) as keyof Console;\n}\n\n/**\n * Generates CSS style for a log type.\n */\nfunction getStyle(type: ColorType, extra = ''): string {\n const { bg, color, border } = THEME[type];\n const baseStyle = `border: 1px solid ${border}; border-radius: 4px`;\n\n switch (state.variant) {\n case 'symbol':\n case 'icon':\n return `color: ${bg}; ${baseStyle}; padding: 0 3px${extra}`;\n default:\n return `background: ${bg}; color: ${color}; ${baseStyle}; font-weight: bold; padding: 0 3px${extra}`;\n }\n}\n\n/**\n * Gets display value for a log type based on variant.\n */\nfunction getDisplayValue(type: LogType): string {\n // Table doesn't have a theme, return uppercase\n if (type === 'table') {\n return type.toUpperCase();\n }\n\n const theme = THEME[type as ColorType];\n const { variant } = state;\n\n if (variant === 'text' || !theme[variant]) {\n return type.toUpperCase();\n }\n\n return theme[variant]!;\n}\n\n/**\n * Builds browser console format string and style parts.\n */\nfunction buildLogParts(type: LogType): { format: string; parts: string[] } {\n const { namespace, timestamp, environment } = state;\n\n let format = `%c${getDisplayValue(type)}%c`;\n // Table doesn't have styling, but this is only called for types that do\n const parts: string[] = [getStyle(type as ColorType), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(getStyle('ns', `; ${NAMESPACE_STYLE}`), '');\n }\n\n if (environment) {\n format += ` %c${getEnvIndicator()}%c`;\n parts.push('color: darkgray', '');\n }\n\n if (timestamp) {\n format += ` %c${getTimestamp()}%c`;\n parts.push('color: gray', '');\n }\n\n return { format, parts };\n}\n\n/**\n * Core logging function.\n */\nfunction log(type: LogType, ...args: unknown[]): void {\n // Node.js logging (simplified)\n if (typeof window === 'undefined') {\n const method = console[getConsoleMethod(type)] as (...a: unknown[]) => void;\n method(`${getDisplayValue(type)} | ${getEnvIndicator()} |`, ...args);\n return;\n }\n\n // Check the log level\n if (!shouldLog(type)) return;\n\n // Browser logging with styles\n const { format, parts } = buildLogParts(type);\n const method = console[getConsoleMethod(type)] as (...a: unknown[]) => void;\n\n method(format, ...parts, ...args);\n sendRemote(type, args);\n}\n\n/**\n * Creates a scoped logger without mutating global state.\n */\nfunction createScopedLogger(scopeName: string): ScopedLogger {\n const originalNamespace = state.namespace;\n const fullNamespace = originalNamespace ? `${originalNamespace}.${scopeName}` : scopeName;\n\n const createMethod = (type: LogType) => {\n return (...args: unknown[]) => {\n const prev = state.namespace;\n state.namespace = fullNamespace;\n log(type, ...args);\n state.namespace = prev;\n };\n };\n\n return {\n debug: createMethod('debug'),\n error: createMethod('error'),\n info: createMethod('info'),\n success: createMethod('success'),\n trace: createMethod('trace'),\n warn: createMethod('warn'),\n };\n}\n\n/* -------------------- Public API -------------------- */\n\nexport const Logit = {\n /**\n * Asserts a condition and logs if false.\n */\n assert: (condition: boolean, message: string, context?: Record<string, unknown>): void => {\n console.assert(condition, message, context);\n },\n /**\n * Logs a debug message.\n */\n debug: (...args: unknown[]): void => log('debug', ...args),\n\n /**\n * Logs an error message.\n */\n error: (...args: unknown[]): void => log('error', ...args),\n\n /**\n * Gets environment indicator visibility.\n */\n getEnvironment: (): boolean => state.environment,\n\n /**\n * Gets the current log level.\n */\n getLevel: (): LogLevel => state.logLevel,\n\n /**\n * Gets the current namespace.\n */\n getPrefix: (): string => state.namespace,\n\n /**\n * Gets timestamp visibility.\n */\n getTimestamp: (): boolean => state.timestamp,\n\n /**\n * Gets the current variant.\n */\n getVariant: (): Variant => state.variant,\n\n /**\n * Creates a collapsed console group.\n */\n groupCollapsed: (text: string, label = 'GROUP', startTime = Date.now()): void => {\n if (!shouldLog('success')) return;\n\n const elapsed = Date.now() - startTime;\n const elapsedStr = elapsed ? `${elapsed}ms` : '';\n const env = getEnvIndicator();\n const timestamp = state.timestamp ? getTimestamp() : '';\n\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${timestamp}%c${elapsedStr}%c${text}`,\n getStyle('group', '; margin-right: 6px; padding: 1px 3px 0'),\n getStyle('ns', `; ${NAMESPACE_STYLE}; margin-right: 6px`),\n 'color: darkgray; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: gray; font-weight: lighter; margin-right: 6px',\n 'color: inherit; font-weight: lighter',\n );\n },\n\n /**\n * Ends the current console group.\n */\n groupEnd: (): void => {\n if (shouldLog('success')) console.groupEnd();\n },\n\n /**\n * Logs an info message.\n */\n info: (...args: unknown[]): void => log('info', ...args),\n\n /**\n * Creates a scoped logger with a namespace.\n *\n * @example\n * ```ts\n * const apiLogger = Logit.scope('api');\n * apiLogger.info('Request received'); // [api] Request received\n * ```\n */\n scope: (namespace: string): ScopedLogger => createScopedLogger(namespace),\n\n /**\n * Sets the minimum log level.\n */\n setLogLevel: (level: LogLevel): void => {\n state.logLevel = level;\n },\n\n /**\n * Sets the global namespace prefix.\n */\n setPrefix: (namespace: string): void => {\n state.namespace = namespace;\n },\n\n /**\n * Sets the remote logging options.\n */\n setRemote: (remote: RemoteOptions): void => {\n state.remote = { ...state.remote, ...remote };\n },\n\n /**\n * Sets the remote log level.\n */\n setRemoteLogLevel: (level: LogLevel): void => {\n state.remote.logLevel = level;\n },\n\n /**\n * Configures Logit with options.\n *\n * @example\n * ```ts\n * Logit.setup({\n * logLevel: 'info',\n * variant: 'text',\n * timestamp: false\n * });\n * ```\n */\n setup: (options: LogitOptions): void => {\n if (options.remote) {\n state.remote = { ...state.remote, ...options.remote };\n const { remote, ...rest } = options;\n Object.assign(state, rest);\n } else {\n Object.assign(state, options);\n }\n },\n\n /**\n * Sets the display variant.\n */\n setVariant: (variant: Variant): void => {\n state.variant = variant;\n },\n\n /**\n * Logs a success message.\n */\n success: (...args: unknown[]): void => log('success', ...args),\n\n /**\n * Displays data in a table format.\n */\n table: (...args: unknown[]): void => {\n if (shouldLog('table')) console.table(...args);\n },\n\n /**\n * Starts a timer.\n */\n time: (label: string): void => {\n if (shouldLog('time')) console.time(label);\n },\n\n /**\n * Ends a timer.\n */\n timeEnd: (label: string): void => {\n if (shouldLog('time')) console.timeEnd(label);\n },\n\n /**\n * Toggles or sets environment indicator visibility.\n */\n toggleEnvironment: (value?: boolean): void => {\n state.environment = value ?? !state.environment;\n },\n\n /**\n * Toggles or sets timestamp visibility.\n */\n toggleTimestamp: (value?: boolean): void => {\n state.timestamp = value ?? !state.timestamp;\n },\n\n /**\n * Logs a trace message.\n */\n trace: (...args: unknown[]): void => log('trace', ...args),\n\n /**\n * Logs a warning message.\n */\n warn: (...args: unknown[]): void => log('warn', ...args),\n};\n"],"names":["CONSOLE_METHOD_MAP","LOG_LEVEL_PRIORITY","isDarkMode","THEME","NAMESPACE_STYLE","isProduction","__vite_import_meta_env__","IS_PROD","state","shouldLog","type","getTimestamp","getEnvIndicator","sendRemote","args","handler","logLevel","getConsoleMethod","getStyle","extra","bg","color","border","baseStyle","getDisplayValue","theme","variant","buildLogParts","namespace","timestamp","environment","format","parts","log","method","createScopedLogger","scopeName","originalNamespace","fullNamespace","createMethod","prev","Logit","condition","message","context","text","label","startTime","elapsed","elapsedStr","env","level","remote","options","rest","value"],"mappings":";AA4CA,MAAMA,IAA8D;AAAA,EAClE,OAAO;AAAA,EACP,SAAS;AACX,GAGMC,IAA+C;AAAA,EACnD,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AACP,GAYMC,IAAa,OAAO,SAAW,OAAe,OAAO,aAAa,8BAA8B,EAAE,SAElGC,IAAkC;AAAA,EACtC,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAA;AAAA,EAC7E,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAA;AAAA,EAC7E,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAA;AAAA,EAC7E,MAAM,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAA;AAAA,EAC5E,IAAID,IACA,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,OAAA,IAC3C,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,OAAA;AAAA,EAC/C,SAAS,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAA;AAAA,EAC/E,MAAM,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAAM,KAAK,QAAQ,KAAA;AAAA,EAC5E,OAAO,EAAE,IAAI,WAAW,QAAQ,WAAW,OAAO,QAAQ,MAA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