debug-better 1.0.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/src/types.ts ADDED
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Core type definitions for debug-utility
3
+ */
4
+
5
+ /**
6
+ * Filter predicate function type
7
+ */
8
+ export type FilterPredicate = (namespace: string, ...args: any[]) => boolean;
9
+
10
+ /**
11
+ * Formatter function type
12
+ */
13
+ export type FormatterFunction = (value: any) => string;
14
+
15
+ /**
16
+ * Log function type
17
+ */
18
+ export type LogFunction = (...args: any[]) => void;
19
+
20
+ /**
21
+ * Filter options for advanced filtering
22
+ */
23
+ export interface FilterOptions {
24
+ /** Enable/disable filtering */
25
+ enabled?: boolean;
26
+ /** Regular expression patterns to match */
27
+ patterns?: RegExp[];
28
+ /** Custom predicate functions */
29
+ predicates?: FilterPredicate[];
30
+ /** Minimum log level (if using levels) */
31
+ minLevel?: number;
32
+ /** Maximum log level (if using levels) */
33
+ maxLevel?: number;
34
+ /** Custom tags to filter by */
35
+ tags?: string[];
36
+ /** Include these namespaces */
37
+ include?: string[];
38
+ /** Exclude these namespaces */
39
+ exclude?: string[];
40
+ }
41
+
42
+ /**
43
+ * Debug instance options
44
+ */
45
+ export interface DebugOptions {
46
+ /** Custom namespace */
47
+ namespace?: string;
48
+ /** Enable/disable colors */
49
+ useColors?: boolean;
50
+ /** Custom color */
51
+ color?: string | number;
52
+ /** Hide timestamp */
53
+ hideDate?: boolean;
54
+ /** Custom log function */
55
+ log?: LogFunction;
56
+ /** Filter options */
57
+ filter?: FilterOptions;
58
+ /** Additional metadata */
59
+ metadata?: Record<string, any>;
60
+ }
61
+
62
+ /**
63
+ * Debug instance interface
64
+ */
65
+ export interface Debugger {
66
+ /** The namespace of this debugger instance */
67
+ namespace: string;
68
+ /** Whether colors are enabled */
69
+ useColors: boolean;
70
+ /** The color assigned to this instance */
71
+ color: string | number;
72
+ /** Time difference from previous log */
73
+ diff: number;
74
+ /** Previous log timestamp */
75
+ prev: number;
76
+ /** Current log timestamp */
77
+ curr: number;
78
+ /** Whether this debugger is enabled */
79
+ enabled: boolean;
80
+ /** The log function */
81
+ log: LogFunction;
82
+ /** Metadata attached to this instance */
83
+ metadata: Record<string, any>;
84
+
85
+ /** Log a message */
86
+ (...args: any[]): void;
87
+
88
+ /** Extend this debugger with a sub-namespace */
89
+ extend(namespace: string, delimiter?: string): Debugger;
90
+
91
+ /** Destroy this debugger instance (deprecated) */
92
+ destroy(): void;
93
+
94
+ /** Set filter options for this instance */
95
+ setFilter(filter: FilterOptions): void;
96
+
97
+ /** Add metadata to this instance */
98
+ setMetadata(key: string, value: any): void;
99
+
100
+ /** Get metadata from this instance */
101
+ getMetadata(key: string): any;
102
+ }
103
+
104
+ /**
105
+ * Debug factory interface
106
+ */
107
+ export interface DebugFactory {
108
+ /** Create a new debugger instance */
109
+ (namespace: string, options?: DebugOptions): Debugger;
110
+
111
+ /** Available colors */
112
+ colors: (string | number)[];
113
+ /** Named namespaces that are enabled */
114
+ names: string[];
115
+ /** Named namespaces that are skipped */
116
+ skips: string[];
117
+ /** Current namespace configuration */
118
+ namespaces: string;
119
+ /** Custom formatters */
120
+ formatters: Record<string, FormatterFunction>;
121
+ /** Inspect options (Node.js specific) */
122
+ inspectOpts?: Record<string, any>;
123
+
124
+ /** Enable debug output */
125
+ enable(namespaces: string): void;
126
+
127
+ /** Disable debug output */
128
+ disable(): string;
129
+
130
+ /** Check if a namespace is enabled */
131
+ enabled(name: string): boolean;
132
+
133
+ /** Humanize time differences */
134
+ humanize: (ms: number) => string;
135
+
136
+ /** Select a color for a namespace */
137
+ selectColor(namespace: string): string | number;
138
+
139
+ /** Coerce a value */
140
+ coerce(val: any): any;
141
+
142
+ /** Format arguments (environment-specific) */
143
+ formatArgs(args: any[]): void;
144
+
145
+ /** Log function (environment-specific) */
146
+ log: LogFunction;
147
+
148
+ /** Save namespaces (environment-specific) */
149
+ save(namespaces: string): void;
150
+
151
+ /** Load namespaces (environment-specific) */
152
+ load(): string;
153
+
154
+ /** Use colors check (environment-specific) */
155
+ useColors(): boolean;
156
+
157
+ /** Initialize a debug instance (environment-specific) */
158
+ init?(debug: Debugger): void;
159
+
160
+ /** Destroy function (deprecated) */
161
+ destroy(): void;
162
+
163
+ /** Set global filter options */
164
+ setGlobalFilter(filter: FilterOptions): void;
165
+
166
+ /** Get global filter options */
167
+ getGlobalFilter(): FilterOptions;
168
+ }
169
+
170
+ /**
171
+ * Environment-specific configuration
172
+ */
173
+ export interface EnvironmentConfig {
174
+ /** Format arguments for output */
175
+ formatArgs: (args: any[]) => void;
176
+ /** Save namespace configuration */
177
+ save: (namespaces: string) => void;
178
+ /** Load namespace configuration */
179
+ load: () => string;
180
+ /** Check if colors should be used */
181
+ useColors: () => boolean;
182
+ /** Available colors */
183
+ colors: (string | number)[];
184
+ /** Log function */
185
+ log: LogFunction;
186
+ /** Inspect options */
187
+ inspectOpts?: Record<string, any>;
188
+ /** Storage mechanism (browser) */
189
+ storage?: Storage | null;
190
+ /** Initialize function */
191
+ init?: (debug: Debugger) => void;
192
+ /** Destroy function */
193
+ destroy: () => void;
194
+ }