@vielzeug/logit 1.0.1

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/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./logit.cjs");exports.Logit=t.Logit;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,108 @@
1
+ export declare const Logit: {
2
+ /**
3
+ * Asserts a condition and logs an error if it's false.
4
+ */
5
+ assert: (valid: boolean, message: string, context: Record<string, any>) => void;
6
+ debug: (...args: any[]) => void;
7
+ error: (...args: any[]) => void;
8
+ /**
9
+ * Gets the current log level.
10
+ */
11
+ getLevel: () => LogitLevel;
12
+ /**
13
+ * Gets the current namespace prefix.
14
+ */
15
+ getPrefix: () => string;
16
+ /**
17
+ * Gets whether timestamps are shown.
18
+ */
19
+ getTimestamp: () => boolean;
20
+ /**
21
+ * Creates a collapsed group in the console.
22
+ */
23
+ groupCollapsed: (text: string, label?: string, time?: number) => void;
24
+ /**
25
+ * Ends the current console group.
26
+ */
27
+ groupEnd: () => void;
28
+ info: (...args: any[]) => void;
29
+ /**
30
+ * Initializes Logit with custom options.
31
+ */
32
+ initialise: (options: LogitOptions) => void;
33
+ /**
34
+ * Sets the minimum log level to display.
35
+ */
36
+ setLogLevel: (level: LogitLevel) => void;
37
+ /**
38
+ * Sets the namespace prefix for all logs.
39
+ */
40
+ setPrefix: (namespace: string) => void;
41
+ /**
42
+ * Configures remote logging options.
43
+ */
44
+ setRemote: (remote: LogitRemoteOptions) => void;
45
+ /**
46
+ * Sets the log level for remote logging.
47
+ */
48
+ setRemoteLogLevel: (level: LogitLevel) => void;
49
+ /**
50
+ * Sets the display variant (text, icon, or symbol).
51
+ */
52
+ setVariant: (variant: "text" | "icon" | "symbol") => void;
53
+ /**
54
+ * Shows or hides the environment indicator.
55
+ */
56
+ showEnvironment: (value: boolean) => void;
57
+ /**
58
+ * Shows or hides timestamps in logs.
59
+ */
60
+ showTimestamp: (value: boolean) => void;
61
+ success: (...args: any[]) => void;
62
+ /**
63
+ * Displays data in a table format.
64
+ */
65
+ table: (...args: any[]) => void;
66
+ /**
67
+ * Starts a timer with the given label.
68
+ */
69
+ time: (label: string) => void;
70
+ /**
71
+ * Ends a timer with the given label.
72
+ */
73
+ timeEnd: (label: string) => void;
74
+ trace: (...args: any[]) => void;
75
+ warn: (...args: any[]) => void;
76
+ };
77
+
78
+ export declare type LogitColors = Exclude<LogitType, 'table'> | 'group' | 'ns';
79
+
80
+ export declare type LogitInstance = typeof Logit;
81
+
82
+ export declare type LogitLevel = LogitType | 'off';
83
+
84
+ export declare type LogitOptions = {
85
+ environment?: boolean;
86
+ variant?: 'text' | 'symbol' | 'icon';
87
+ logLevel?: LogitLevel;
88
+ namespace?: string;
89
+ remote?: LogitRemoteOptions;
90
+ timestamp?: boolean;
91
+ };
92
+
93
+ export declare type LogitRemoteOptions = {
94
+ handler?: (...args: any[]) => void;
95
+ logLevel: LogitLevel;
96
+ };
97
+
98
+ export declare type LogitTheme = {
99
+ color: string;
100
+ bg: string;
101
+ border: string;
102
+ icon?: string;
103
+ symbol?: string;
104
+ };
105
+
106
+ export declare type LogitType = 'debug' | 'trace' | 'time' | 'table' | 'info' | 'success' | 'warn' | 'error';
107
+
108
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { Logit as t } from "./logit.js";
2
+ export {
3
+ t as Logit
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/dist/logit.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w={},v="🄿",$="🄳",L={debug:"log",success:"log"},x=()=>w?.NODE_ENV==="production",E=typeof window<"u"&&window.matchMedia?.("(prefers-color-scheme: dark)").matches,m={debug:{bg:"#616161",border:"#424242",color:"#fff",icon:"☕",symbol:"🅳"},error:{bg:"#d32f2f",border:"#c62828",color:"#fff",icon:"✘",symbol:"🅴"},group:{bg:"#546e7a",border:"#455a64",color:"#fff",icon:"⚭",symbol:"🅶"},info:{bg:"#1976d2",border:"#1565c0",color:"#fff",icon:"ℹ",symbol:"🅸"},ns:E?{bg:"#fafafa",border:"#c7c7c7",color:"#000"}:{bg:"#424242",border:"#212121",color:"#fff"},success:{bg:"#689f38",border:"#558b2f",color:"#fff",icon:"✔",symbol:"🆂"},time:{bg:"#0097a7",border:"#00838f",color:"#fff",icon:"⏲",symbol:"🆃"},trace:{bg:"#d81b60",border:"#c2185b",color:"#fff",icon:"⛢",symbol:"🆃"},warn:{bg:"#ffb300",border:"#ffa000",color:"#fff",icon:"⚠",symbol:"🆆"}},f={debug:0,trace:1,time:2,table:3,info:4,success:5,warn:6,error:7,off:8},e={environment:!0,logLevel:"debug",namespace:"",remote:{handler:void 0,logLevel:"off"},timestamp:!0,variant:"symbol"},d=o=>f[e.logLevel]<=f[o],u=()=>new Date().toISOString().slice(11,23),b=()=>x()?v:$,y=(o,r)=>{e.remote.handler&&f[e.remote.logLevel]<=f[o]&&e.remote.handler(o,...r)},p=o=>L[o]||o,g=(o,r="")=>{const{bg:t,color:s,border:n}=m[o],c=`color: ${t}; border: 1px solid ${n}; border-radius: 4px;`;switch(e.variant){case"symbol":return`${c} padding: 1px 1px 0;${r};`;case"icon":return`${c} padding: 0 3px;${r};`;default:return`background: ${t}; color: ${s}; border: 1px solid ${n}; border-radius: 4px; font-weight: bold; padding: 0 3px;${r}`}};function _(o){const r=m[o],{namespace:t,variant:s,timestamp:n,environment:c}=e;let i=`%c${r[s]??o.toUpperCase()}%c`;const a=[g(o),""];return t&&(i+=` %c${t}%c`,a.push(g("ns"," border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;"),"")),c&&(i+=` %c${b()}%c`,a.push("color: darkgray;","")),n&&(i+=` %c${u()}%c`,a.push("color: gray;","")),{format:i,parts:a}}const l=(o,...r)=>{if(typeof window>"u"){const c=m[o],{variant:i}=e,a=console[p(o)];a(`${c[i]??o.toUpperCase()} | ${b()} |`,...r);return}if(!d(o))return;const{format:t,parts:s}=_(o),n=console[p(o)];n(t,...s,...r),y(o,r)},O=o=>{const r=Math.floor(Date.now()-o);return r?`${r}ms`:""},h={assert:(o,r,t)=>console.assert(o,r,t),debug:(...o)=>l("debug",...o),error:(...o)=>l("error",...o),getLevel:()=>e.logLevel,getPrefix:()=>e.namespace,getTimestamp:()=>e.timestamp,groupCollapsed:(o,r="GROUP",t=Date.now())=>{if(!d("success"))return;const s=O(t),n=b();console.groupCollapsed(`%c${r}%c${e.namespace}%c${n}%c${e.timestamp?u():""}%c${s}%c${o}`,g("group","margin-right: 6px; padding: 1px 3px 0"),g("ns"," border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;margin-right: 6px;"),"color: darkgray; margin-right: 6px;","color: gray;font-weight: lighter;margin-right: 6px;","color: gray; font-weight: lighter;margin-right: 6px;","color: inherit;font-weight: lighter;")},groupEnd:()=>{d("success")&&console.groupEnd()},info:(...o)=>l("info",...o),initialise:o=>{Object.assign(e,o)},setLogLevel:o=>{e.logLevel=o},setPrefix:o=>{e.namespace=o},setRemote:o=>{e.remote=o},setRemoteLogLevel:o=>{e.remote.logLevel=o},setVariant:o=>{e.variant=o},showEnvironment:o=>{e.environment=o},showTimestamp:o=>{e.timestamp=o},success:(...o)=>l("success",...o),table:(...o)=>{d("table")&&console.table(...o)},time:o=>{d("time")&&console.time(o)},timeEnd:o=>{d("time")&&console.timeEnd(o)},trace:(...o)=>l("trace",...o),warn:(...o)=>l("warn",...o)};typeof window<"u"&&(window.Logit=h);exports.Logit=h;
2
+ //# sourceMappingURL=logit.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logit.cjs","sources":["../src/logit.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noAssignInExpressions: - */\n/** biome-ignore-all lint/suspicious/noExplicitAny: - */\ndeclare global {\n interface Window {\n Logit: LogitInstance;\n }\n}\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 */\nconst isProd = (): boolean => (import.meta as any)?.env?.NODE_ENV === 'production';\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\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\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 getTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (isProd() ? 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 * 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}; border: 1px solid ${border}; border-radius: 4px;`;\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}; border: 1px solid ${border}; border-radius: 4px; font-weight: bold; padding: 0 3px;${extra}`;\n }\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 theme = Theme[type as LogitColors];\n const { namespace, variant, timestamp, environment } = state;\n\n let format = `%c${theme[variant as keyof LogitTheme] ?? type.toUpperCase()}%c`;\n const parts: string[] = [style(type as any), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;'), '');\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 * 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 theme = Theme[type as LogitColors];\n const { variant } = state;\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any) => void;\n consoleMethod(`${theme[variant as keyof LogitTheme] ?? type.toUpperCase()} | ${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\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${state.timestamp ? getTimestamp() : ''}%c${elapsed}%c${text}`,\n style('group', 'margin-right: 6px; padding: 1px 3px 0'),\n style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;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\nif (typeof window !== 'undefined') {\n window.Logit = Logit;\n}\n"],"names":["ENV_PROD","ENV_DEV","CONSOLE_METHOD_MAP","isProd","__vite_import_meta_env__","isDark","Theme","logLevel","state","shouldLog","type","getTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","style","extra","bg","color","border","baseStyle","buildBrowserLogParts","theme","namespace","variant","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text","label","time","env","options","level","remote","value"],"mappings":"2FAWMA,EAAW,KACXC,EAAU,KAKVC,EAAoD,CACxD,MAAO,MACP,QAAS,KACX,EAKMC,EAAS,IAAgBC,GAA0B,WAAa,aAoBhEC,EAAS,OAAO,OAAW,KAAe,OAAO,aAAa,8BAA8B,EAAE,QAC9FC,EAAmD,CACvD,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,MAAO,CAAE,GAAI,UAAW,OAAQ,UAAW,MAAO,OAAQ,KAAM,IAAU,OAAQ,IAAA,EAClF,KAAM,CAAE,GAAI,UAAW,OAAQ,UAAW,MA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AO,SAAWoC,CAC1B,EAKA,WAAanB,GAA8C,CACzDjB,EAAM,QAAUiB,CAClB,EAKA,gBAAkBqB,GAAyB,CACzCtC,EAAM,YAAcsC,CACtB,EAKA,cAAgBA,GAAyB,CACvCtC,EAAM,UAAYsC,CACpB,EAEA,QAAS,IAAIhC,IAAsBgB,EAAI,UAAW,GAAGhB,CAAI,EAKzD,MAAO,IAAIA,IAAsB,CAC3BL,EAAU,OAAO,GAAG,QAAQ,MAAM,GAAGK,CAAI,CAC/C,EAKA,KAAO0B,GAAwB,CACzB/B,EAAU,MAAM,GAAG,QAAQ,KAAK+B,CAAK,CAC3C,EAKA,QAAUA,GAAwB,CAC5B/B,EAAU,MAAM,GAAG,QAAQ,QAAQ+B,CAAK,CAC9C,EAEA,MAAO,IAAI1B,IAAsBgB,EAAI,QAAS,GAAGhB,CAAI,EACrD,KAAM,IAAIA,IAAsBgB,EAAI,OAAQ,GAAGhB,CAAI,CACrD,EAEI,OAAO,OAAW,MACpB,OAAO,MAAQqB"}
package/dist/logit.js ADDED
@@ -0,0 +1,179 @@
1
+ const h = {};
2
+ const w = {
3
+ debug: "log",
4
+ success: "log"
5
+ }, v = () => h?.NODE_ENV === "production", $ = typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches, m = {
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: $ ? { 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
+ }, f = {
16
+ debug: 0,
17
+ trace: 1,
18
+ time: 2,
19
+ table: 3,
20
+ info: 4,
21
+ success: 5,
22
+ warn: 6,
23
+ error: 7,
24
+ off: 8
25
+ }, e = {
26
+ environment: !0,
27
+ logLevel: "debug",
28
+ namespace: "",
29
+ remote: { handler: void 0, logLevel: "off" },
30
+ timestamp: !0,
31
+ variant: "symbol"
32
+ }, d = (o) => f[e.logLevel] <= f[o], u = () => (/* @__PURE__ */ new Date()).toISOString().slice(11, 23), b = () => v() ? "🄿" : "🄳", x = (o, r) => {
33
+ e.remote.handler && f[e.remote.logLevel] <= f[o] && e.remote.handler(o, ...r);
34
+ }, p = (o) => w[o] || o, g = (o, r = "") => {
35
+ const { bg: t, color: s, border: n } = m[o], c = `color: ${t}; border: 1px solid ${n}; border-radius: 4px;`;
36
+ switch (e.variant) {
37
+ case "symbol":
38
+ return `${c} padding: 1px 1px 0;${r};`;
39
+ case "icon":
40
+ return `${c} padding: 0 3px;${r};`;
41
+ default:
42
+ return `background: ${t}; color: ${s}; border: 1px solid ${n}; border-radius: 4px; font-weight: bold; padding: 0 3px;${r}`;
43
+ }
44
+ };
45
+ function L(o) {
46
+ const r = m[o], { namespace: t, variant: s, timestamp: n, environment: c } = e;
47
+ let i = `%c${r[s] ?? o.toUpperCase()}%c`;
48
+ const a = [g(o), ""];
49
+ return t && (i += ` %c${t}%c`, a.push(g("ns", " border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;"), "")), c && (i += ` %c${b()}%c`, a.push("color: darkgray;", "")), n && (i += ` %c${u()}%c`, a.push("color: gray;", "")), { format: i, parts: a };
50
+ }
51
+ const l = (o, ...r) => {
52
+ if (typeof window > "u") {
53
+ const c = m[o], { variant: i } = e, a = console[p(o)];
54
+ a(`${c[i] ?? o.toUpperCase()} | ${b()} |`, ...r);
55
+ return;
56
+ }
57
+ if (!d(o)) return;
58
+ const { format: t, parts: s } = L(o), n = console[p(o)];
59
+ n(t, ...s, ...r), x(o, r);
60
+ }, E = (o) => {
61
+ const r = Math.floor(Date.now() - o);
62
+ return r ? `${r}ms` : "";
63
+ }, _ = {
64
+ /**
65
+ * Asserts a condition and logs an error if it's false.
66
+ */
67
+ assert: (o, r, t) => console.assert(o, r, t),
68
+ debug: (...o) => l("debug", ...o),
69
+ error: (...o) => l("error", ...o),
70
+ /**
71
+ * Gets the current log level.
72
+ */
73
+ getLevel: () => e.logLevel,
74
+ /**
75
+ * Gets the current namespace prefix.
76
+ */
77
+ getPrefix: () => e.namespace,
78
+ /**
79
+ * Gets whether timestamps are shown.
80
+ */
81
+ getTimestamp: () => e.timestamp,
82
+ /**
83
+ * Creates a collapsed group in the console.
84
+ */
85
+ groupCollapsed: (o, r = "GROUP", t = Date.now()) => {
86
+ if (!d("success")) return;
87
+ const s = E(t), n = b();
88
+ console.groupCollapsed(
89
+ `%c${r}%c${e.namespace}%c${n}%c${e.timestamp ? u() : ""}%c${s}%c${o}`,
90
+ g("group", "margin-right: 6px; padding: 1px 3px 0"),
91
+ g("ns", " border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;margin-right: 6px;"),
92
+ "color: darkgray; margin-right: 6px;",
93
+ "color: gray;font-weight: lighter;margin-right: 6px;",
94
+ "color: gray; font-weight: lighter;margin-right: 6px;",
95
+ "color: inherit;font-weight: lighter;"
96
+ );
97
+ },
98
+ /**
99
+ * Ends the current console group.
100
+ */
101
+ groupEnd: () => {
102
+ d("success") && console.groupEnd();
103
+ },
104
+ info: (...o) => l("info", ...o),
105
+ /**
106
+ * Initializes Logit with custom options.
107
+ */
108
+ initialise: (o) => {
109
+ Object.assign(e, o);
110
+ },
111
+ /**
112
+ * Sets the minimum log level to display.
113
+ */
114
+ setLogLevel: (o) => {
115
+ e.logLevel = o;
116
+ },
117
+ /**
118
+ * Sets the namespace prefix for all logs.
119
+ */
120
+ setPrefix: (o) => {
121
+ e.namespace = o;
122
+ },
123
+ /**
124
+ * Configures remote logging options.
125
+ */
126
+ setRemote: (o) => {
127
+ e.remote = o;
128
+ },
129
+ /**
130
+ * Sets the log level for remote logging.
131
+ */
132
+ setRemoteLogLevel: (o) => {
133
+ e.remote.logLevel = o;
134
+ },
135
+ /**
136
+ * Sets the display variant (text, icon, or symbol).
137
+ */
138
+ setVariant: (o) => {
139
+ e.variant = o;
140
+ },
141
+ /**
142
+ * Shows or hides the environment indicator.
143
+ */
144
+ showEnvironment: (o) => {
145
+ e.environment = o;
146
+ },
147
+ /**
148
+ * Shows or hides timestamps in logs.
149
+ */
150
+ showTimestamp: (o) => {
151
+ e.timestamp = o;
152
+ },
153
+ success: (...o) => l("success", ...o),
154
+ /**
155
+ * Displays data in a table format.
156
+ */
157
+ table: (...o) => {
158
+ d("table") && console.table(...o);
159
+ },
160
+ /**
161
+ * Starts a timer with the given label.
162
+ */
163
+ time: (o) => {
164
+ d("time") && console.time(o);
165
+ },
166
+ /**
167
+ * Ends a timer with the given label.
168
+ */
169
+ timeEnd: (o) => {
170
+ d("time") && console.timeEnd(o);
171
+ },
172
+ trace: (...o) => l("trace", ...o),
173
+ warn: (...o) => l("warn", ...o)
174
+ };
175
+ typeof window < "u" && (window.Logit = _);
176
+ export {
177
+ _ as Logit
178
+ };
179
+ //# sourceMappingURL=logit.js.map
@@ -0,0 +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: - */\ndeclare global {\n interface Window {\n Logit: LogitInstance;\n }\n}\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 */\nconst isProd = (): boolean => (import.meta as any)?.env?.NODE_ENV === 'production';\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\nconst isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;\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 getTimestamp = (): string => new Date().toISOString().slice(11, 23);\n\n/**\n * Gets the environment indicator symbol.\n */\nconst getEnvIndicator = (): string => (isProd() ? 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 * 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}; border: 1px solid ${border}; border-radius: 4px;`;\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}; border: 1px solid ${border}; border-radius: 4px; font-weight: bold; padding: 0 3px;${extra}`;\n }\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 theme = Theme[type as LogitColors];\n const { namespace, variant, timestamp, environment } = state;\n\n let format = `%c${theme[variant as keyof LogitTheme] ?? type.toUpperCase()}%c`;\n const parts: string[] = [style(type as any), ''];\n\n if (namespace) {\n format += ` %c${namespace}%c`;\n parts.push(style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;'), '');\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 * 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 theme = Theme[type as LogitColors];\n const { variant } = state;\n const consoleMethod = console[getConsoleMethod(type)] as (...a: any) => void;\n consoleMethod(`${theme[variant as keyof LogitTheme] ?? type.toUpperCase()} | ${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\n console.groupCollapsed(\n `%c${label}%c${state.namespace}%c${env}%c${state.timestamp ? getTimestamp() : ''}%c${elapsed}%c${text}`,\n style('group', 'margin-right: 6px; padding: 1px 3px 0'),\n style('ns', ' border-radius: 8px; font: italic small-caps bold 12px; font-weight: lighter;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\nif (typeof window !== 'undefined') {\n window.Logit = Logit;\n}\n"],"names":["CONSOLE_METHOD_MAP","isProd","__vite_import_meta_env__","isDark","Theme","logLevel","state","shouldLog","type","getTimestamp","getEnvIndicator","sendRemoteLog","args","getConsoleMethod","style","extra","bg","color","border","baseStyle","buildBrowserLogParts","theme","namespace","variant","timestamp","environment","format","parts","log","consoleMethod","formatElapsedTime","startTime","elapsed","Logit","valid","message","context","text","label","time","env","options","level","remote","value"],"mappings":";AAiBA,MAAMA,IAAoD;AAAA,EACxD,OAAO;AAAA,EACP,SAAS;AACX,GAKMC,IAAS,MAAgBC,GAA0B,aAAa,cAoBhEC,IAAS,OAAO,SAAW,OAAe,OAAO,aAAa,8BAA8B,EAAE,SAC9FC,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,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,KAAU,QAAQ,KAAA;AAAA,EACpF,MAAM,EAAE,IAAI,WAA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DED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@vielzeug/logit",
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsc && vite build",
19
+ "fix": "biome check --write --unsafe src",
20
+ "lint": "biome check src",
21
+ "prepublishOnly": "npm run build",
22
+ "preview": "vite preview",
23
+ "test": "vitest"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "~5.9.3",
31
+ "vite": "^7.3.1",
32
+ "vite-plugin-dts": "^4.5.4",
33
+ "vitest": "^4.0.18"
34
+ }
35
+ }