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/LICENSE +21 -0
- package/README.md +400 -0
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +171 -0
- package/dist/browser.js.map +1 -0
- package/dist/common.d.ts +14 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +258 -0
- package/dist/common.js.map +1 -0
- package/dist/filter.d.ts +64 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +182 -0
- package/dist/filter.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +177 -0
- package/dist/node.js.map +1 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
- package/src/browser.ts +199 -0
- package/src/common.ts +306 -0
- package/src/filter.ts +204 -0
- package/src/index.ts +23 -0
- package/src/node.ts +161 -0
- package/src/types.ts +194 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# debug-better
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/debug-better)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
|
|
7
|
+
A modern, TypeScript-based debugging utility with advanced filtering capabilities for Node.js and browser environments. Built as an enhanced version of the popular `debug` package with additional features.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- ✨ **TypeScript Support** - Full TypeScript types and definitions
|
|
12
|
+
- 🎯 **Advanced Filtering** - Regex patterns, predicates, and custom filters
|
|
13
|
+
- 🎨 **Colorized Output** - Beautiful colored output in terminal and browser console
|
|
14
|
+
- 🌐 **Universal** - Works in Node.js and browser environments
|
|
15
|
+
- ⚡ **Performance** - Lightweight with minimal overhead
|
|
16
|
+
- 📊 **Metadata Support** - Attach contextual data to log instances
|
|
17
|
+
- 🔧 **Extensible** - Easy to extend and customize
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install debug-better
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### Basic Usage
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import debug from 'debug-better';
|
|
31
|
+
|
|
32
|
+
const log = debug('app:server');
|
|
33
|
+
|
|
34
|
+
log('Server starting on port %d', 3000);
|
|
35
|
+
log('Connected to database');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Enable Debug Output
|
|
39
|
+
|
|
40
|
+
**Node.js:**
|
|
41
|
+
```bash
|
|
42
|
+
DEBUG=* node app.js # Enable all
|
|
43
|
+
DEBUG=app:* node app.js # Enable app namespace
|
|
44
|
+
DEBUG=app:*,-app:verbose node app.js # Enable app except verbose
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Browser:**
|
|
48
|
+
```javascript
|
|
49
|
+
localStorage.setItem('debug', 'app:*');
|
|
50
|
+
// Or via URL: ?debug=app:*
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Advanced Features
|
|
54
|
+
|
|
55
|
+
### 1. TypeScript Support
|
|
56
|
+
|
|
57
|
+
Full type safety and IntelliSense:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import debug, { Debugger, FilterOptions } from 'debug-better';
|
|
61
|
+
|
|
62
|
+
const log: Debugger = debug('my-app');
|
|
63
|
+
|
|
64
|
+
const filterOpts: FilterOptions = {
|
|
65
|
+
enabled: true,
|
|
66
|
+
patterns: [/^api:.*/],
|
|
67
|
+
exclude: ['api:debug'],
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. Advanced Filtering
|
|
72
|
+
|
|
73
|
+
#### Pattern-Based Filtering
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import debug from 'debug-better';
|
|
77
|
+
|
|
78
|
+
// Set global filter
|
|
79
|
+
debug.setGlobalFilter({
|
|
80
|
+
include: ['app:*', 'api:*'],
|
|
81
|
+
exclude: ['*:verbose', '*:debug'],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const log = debug('app:main');
|
|
85
|
+
log('This will be shown');
|
|
86
|
+
|
|
87
|
+
const verboseLog = debug('app:verbose');
|
|
88
|
+
verboseLog('This will be hidden');
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Regex Filtering
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import debug from 'debug-better';
|
|
95
|
+
|
|
96
|
+
debug.setGlobalFilter({
|
|
97
|
+
patterns: [
|
|
98
|
+
/^api:.*$/, // Match all api namespaces
|
|
99
|
+
/^app:(server|db)$/, // Match specific namespaces
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Custom Predicate Filters
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import debug from 'debug-better';
|
|
108
|
+
|
|
109
|
+
debug.setGlobalFilter({
|
|
110
|
+
predicates: [
|
|
111
|
+
// Only log during business hours
|
|
112
|
+
(namespace: string) => {
|
|
113
|
+
const hour = new Date().getHours();
|
|
114
|
+
return hour >= 9 && hour <= 17;
|
|
115
|
+
},
|
|
116
|
+
// Only log errors and warnings
|
|
117
|
+
(namespace: string, ...args: any[]) => {
|
|
118
|
+
const msg = args[0]?.toString() || '';
|
|
119
|
+
return msg.includes('error') || msg.includes('warning');
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Instance-Specific Filtering
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import debug from 'debug-better';
|
|
129
|
+
|
|
130
|
+
const log = debug('app:main', {
|
|
131
|
+
filter: {
|
|
132
|
+
enabled: true,
|
|
133
|
+
predicates: [
|
|
134
|
+
(namespace, ...args) => {
|
|
135
|
+
// Custom logic for this instance
|
|
136
|
+
return args[0]?.priority === 'high';
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
log({ priority: 'high' }, 'Important message'); // Shown
|
|
143
|
+
log({ priority: 'low' }, 'Regular message'); // Hidden
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 3. Metadata Support
|
|
147
|
+
|
|
148
|
+
Attach contextual data to debugger instances:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import debug from 'debug-better';
|
|
152
|
+
|
|
153
|
+
const log = debug('api:user', {
|
|
154
|
+
metadata: {
|
|
155
|
+
service: 'user-service',
|
|
156
|
+
version: '1.0.0',
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
log.setMetadata('requestId', '12345');
|
|
161
|
+
log('Processing request');
|
|
162
|
+
|
|
163
|
+
console.log(log.getMetadata('service')); // 'user-service'
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 4. Custom Formatters
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import debug from 'debug-better';
|
|
170
|
+
|
|
171
|
+
// Add custom formatter
|
|
172
|
+
debug.formatters.j = (v: any) => {
|
|
173
|
+
return JSON.stringify(v, null, 2);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const log = debug('app');
|
|
177
|
+
log('Config: %j', { port: 3000, host: 'localhost' });
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 5. Extending Debuggers
|
|
181
|
+
|
|
182
|
+
Create sub-namespaces:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import debug from 'debug-better';
|
|
186
|
+
|
|
187
|
+
const app = debug('app');
|
|
188
|
+
const server = app.extend('server');
|
|
189
|
+
const db = app.extend('db');
|
|
190
|
+
|
|
191
|
+
app('Application started'); // app
|
|
192
|
+
server('Server listening'); // app:server
|
|
193
|
+
db('Connected to database'); // app:db
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 6. Custom Options
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import debug from 'debug-better';
|
|
200
|
+
|
|
201
|
+
const log = debug('app', {
|
|
202
|
+
useColors: true,
|
|
203
|
+
hideDate: false,
|
|
204
|
+
metadata: { environment: 'production' },
|
|
205
|
+
log: (...args) => {
|
|
206
|
+
// Custom log function
|
|
207
|
+
console.log('[CUSTOM]', ...args);
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## API Reference
|
|
213
|
+
|
|
214
|
+
### Factory Function
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
debug(namespace: string, options?: DebugOptions): Debugger
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Options
|
|
221
|
+
|
|
222
|
+
- `namespace`: String identifier for the debugger instance
|
|
223
|
+
- `useColors`: Enable/disable colors (default: auto-detected)
|
|
224
|
+
- `hideDate`: Hide timestamp in output
|
|
225
|
+
- `log`: Custom log function
|
|
226
|
+
- `filter`: Instance-specific filter options
|
|
227
|
+
- `metadata`: Additional contextual data
|
|
228
|
+
|
|
229
|
+
### Debugger Instance
|
|
230
|
+
|
|
231
|
+
#### Methods
|
|
232
|
+
|
|
233
|
+
- `log(...args)`: Log a message
|
|
234
|
+
- `extend(namespace, delimiter?)`: Create a sub-debugger
|
|
235
|
+
- `setFilter(filter)`: Update filter options
|
|
236
|
+
- `setMetadata(key, value)`: Set metadata
|
|
237
|
+
- `getMetadata(key)`: Get metadata
|
|
238
|
+
|
|
239
|
+
#### Properties
|
|
240
|
+
|
|
241
|
+
- `namespace`: The namespace string
|
|
242
|
+
- `enabled`: Whether this debugger is enabled
|
|
243
|
+
- `useColors`: Whether colors are used
|
|
244
|
+
- `color`: Assigned color
|
|
245
|
+
- `diff`: Time difference from previous log
|
|
246
|
+
|
|
247
|
+
### Global Methods
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
debug.enable(namespaces: string): void
|
|
251
|
+
debug.disable(): string
|
|
252
|
+
debug.enabled(name: string): boolean
|
|
253
|
+
debug.setGlobalFilter(filter: FilterOptions): void
|
|
254
|
+
debug.getGlobalFilter(): FilterOptions
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Filter Options
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
interface FilterOptions {
|
|
261
|
+
enabled?: boolean;
|
|
262
|
+
patterns?: RegExp[];
|
|
263
|
+
predicates?: FilterPredicate[];
|
|
264
|
+
include?: string[];
|
|
265
|
+
exclude?: string[];
|
|
266
|
+
tags?: string[];
|
|
267
|
+
minLevel?: number;
|
|
268
|
+
maxLevel?: number;
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Environment Variables (Node.js)
|
|
273
|
+
|
|
274
|
+
- `DEBUG`: Enable namespaces (e.g., `DEBUG=app:*`)
|
|
275
|
+
- `DEBUG_COLORS`: Force colors on/off
|
|
276
|
+
- `DEBUG_HIDE_DATE`: Hide timestamps
|
|
277
|
+
- `DEBUG_SHOW_HIDDEN`: Show hidden properties in objects
|
|
278
|
+
|
|
279
|
+
## Browser Console
|
|
280
|
+
|
|
281
|
+
In browser environments, you can:
|
|
282
|
+
|
|
283
|
+
1. Set via localStorage: `localStorage.setItem('debug', 'app:*')`
|
|
284
|
+
2. Set via URL parameter: `?debug=app:*`
|
|
285
|
+
3. Use browser console: `debug.enable('app:*')`
|
|
286
|
+
|
|
287
|
+
## Examples
|
|
288
|
+
|
|
289
|
+
### Express Server
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import debug from 'debug-better';
|
|
293
|
+
import express from 'express';
|
|
294
|
+
|
|
295
|
+
const app = express();
|
|
296
|
+
const log = debug('server');
|
|
297
|
+
const reqLog = debug('server:request');
|
|
298
|
+
const errLog = debug('server:error');
|
|
299
|
+
|
|
300
|
+
app.use((req, res, next) => {
|
|
301
|
+
reqLog('%s %s', req.method, req.url);
|
|
302
|
+
next();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
app.get('/', (req, res) => {
|
|
306
|
+
log('Handling root request');
|
|
307
|
+
res.send('Hello World');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
app.use((err, req, res, next) => {
|
|
311
|
+
errLog('Error: %O', err);
|
|
312
|
+
res.status(500).send('Internal Server Error');
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const PORT = 3000;
|
|
316
|
+
app.listen(PORT, () => {
|
|
317
|
+
log('Server started on port %d', PORT);
|
|
318
|
+
});
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Microservice with Filtering
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import debug from 'debug-better';
|
|
325
|
+
|
|
326
|
+
// Only log errors and warnings in production
|
|
327
|
+
if (process.env.NODE_ENV === 'production') {
|
|
328
|
+
debug.setGlobalFilter({
|
|
329
|
+
predicates: [
|
|
330
|
+
(namespace, ...args) => {
|
|
331
|
+
const msg = JSON.stringify(args);
|
|
332
|
+
return msg.includes('error') || msg.includes('warn');
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const log = debug('service:main');
|
|
339
|
+
const errorLog = debug('service:error');
|
|
340
|
+
|
|
341
|
+
log('Service starting...'); // Hidden in production
|
|
342
|
+
errorLog('Critical error occurred!'); // Always shown
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Migration from `debug`
|
|
346
|
+
|
|
347
|
+
`debug-better` is designed to be a drop-in replacement for the `debug` package:
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
// Before
|
|
351
|
+
const debug = require('debug');
|
|
352
|
+
const log = debug('app');
|
|
353
|
+
|
|
354
|
+
// After
|
|
355
|
+
import debug from 'debug-better';
|
|
356
|
+
const log = debug('app');
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
All existing functionality is preserved, with additional features available when needed.
|
|
360
|
+
|
|
361
|
+
## Performance
|
|
362
|
+
|
|
363
|
+
`debug-better` is designed with performance in mind:
|
|
364
|
+
|
|
365
|
+
- Disabled debuggers have near-zero overhead
|
|
366
|
+
- Filtering is evaluated lazily
|
|
367
|
+
- No dependencies beyond `ms` for time formatting
|
|
368
|
+
|
|
369
|
+
## Browser Support
|
|
370
|
+
|
|
371
|
+
- Chrome (latest)
|
|
372
|
+
- Firefox (latest)
|
|
373
|
+
- Safari (latest)
|
|
374
|
+
- Edge (latest)
|
|
375
|
+
- IE11+ (with polyfills)
|
|
376
|
+
|
|
377
|
+
## Node.js Support
|
|
378
|
+
|
|
379
|
+
- Node.js >= 18.0.0 (LTS)
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
MIT © Your Name
|
|
384
|
+
|
|
385
|
+
## Contributing
|
|
386
|
+
|
|
387
|
+
Contributions are welcome! Please read our contributing guidelines and code of conduct.
|
|
388
|
+
|
|
389
|
+
## Credits
|
|
390
|
+
|
|
391
|
+
Inspired by the excellent [debug](https://github.com/debug-js/debug) package by TJ Holowaychuk and contributors.
|
|
392
|
+
|
|
393
|
+
## Changelog
|
|
394
|
+
|
|
395
|
+
### 1.0.0
|
|
396
|
+
- Initial release
|
|
397
|
+
- TypeScript support
|
|
398
|
+
- Advanced filtering capabilities
|
|
399
|
+
- Metadata support
|
|
400
|
+
- Full backward compatibility with `debug`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiMH;;GAEG;;AACH,kBAA2B"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser implementation of debug-utility
|
|
4
|
+
*/
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
/**
|
|
7
|
+
* Colors for browser (hex codes)
|
|
8
|
+
*/
|
|
9
|
+
const colors = [
|
|
10
|
+
'#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF',
|
|
11
|
+
'#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF',
|
|
12
|
+
'#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33',
|
|
13
|
+
'#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF',
|
|
14
|
+
'#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33',
|
|
15
|
+
'#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333',
|
|
16
|
+
'#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
|
|
17
|
+
'#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF',
|
|
18
|
+
'#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633',
|
|
19
|
+
'#FF9900', '#FF9933', '#FFCC00', '#FFCC33',
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Get localStorage safely
|
|
23
|
+
*/
|
|
24
|
+
function localstorage() {
|
|
25
|
+
try {
|
|
26
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
27
|
+
return window.localStorage;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const storage = localstorage();
|
|
36
|
+
/**
|
|
37
|
+
* Check if colors should be used in browser
|
|
38
|
+
*/
|
|
39
|
+
function useColors() {
|
|
40
|
+
// Electron renderer
|
|
41
|
+
if (typeof window !== 'undefined' &&
|
|
42
|
+
window.process &&
|
|
43
|
+
(window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// Internet Explorer and Edge do not support colors
|
|
47
|
+
if (typeof navigator !== 'undefined' &&
|
|
48
|
+
navigator.userAgent &&
|
|
49
|
+
navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// Check for various browser capabilities
|
|
53
|
+
return ((typeof document !== 'undefined' &&
|
|
54
|
+
document.documentElement &&
|
|
55
|
+
document.documentElement.style &&
|
|
56
|
+
document.documentElement.style.WebkitAppearance) ||
|
|
57
|
+
(typeof window !== 'undefined' &&
|
|
58
|
+
window.console &&
|
|
59
|
+
(window.console.firebug ||
|
|
60
|
+
(window.console.exception && window.console.table))) ||
|
|
61
|
+
(typeof navigator !== 'undefined' &&
|
|
62
|
+
navigator.userAgent &&
|
|
63
|
+
navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) &&
|
|
64
|
+
parseInt(RegExp.$1, 10) >= 31) ||
|
|
65
|
+
(typeof navigator !== 'undefined' &&
|
|
66
|
+
navigator.userAgent &&
|
|
67
|
+
navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Format arguments with browser colors
|
|
71
|
+
*/
|
|
72
|
+
function formatArgs(args) {
|
|
73
|
+
args[0] =
|
|
74
|
+
(this.useColors ? '%c' : '') +
|
|
75
|
+
this.namespace +
|
|
76
|
+
(this.useColors ? ' %c' : ' ') +
|
|
77
|
+
args[0] +
|
|
78
|
+
(this.useColors ? '%c ' : ' ') +
|
|
79
|
+
'+' +
|
|
80
|
+
ms(this.diff);
|
|
81
|
+
if (!this.useColors) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const c = 'color: ' + this.color;
|
|
85
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
86
|
+
// Handle %c positioning
|
|
87
|
+
let index = 0;
|
|
88
|
+
let lastC = 0;
|
|
89
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
90
|
+
if (match === '%%') {
|
|
91
|
+
return match;
|
|
92
|
+
}
|
|
93
|
+
index++;
|
|
94
|
+
if (match === '%c') {
|
|
95
|
+
lastC = index;
|
|
96
|
+
}
|
|
97
|
+
return match;
|
|
98
|
+
});
|
|
99
|
+
args.splice(lastC, 0, c);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Log function for browser
|
|
103
|
+
*/
|
|
104
|
+
const log = typeof console !== 'undefined' && typeof console.debug === 'function'
|
|
105
|
+
? console.debug.bind(console)
|
|
106
|
+
: typeof console !== 'undefined' && typeof console.log === 'function'
|
|
107
|
+
? console.log.bind(console)
|
|
108
|
+
: () => { };
|
|
109
|
+
/**
|
|
110
|
+
* Save namespaces to localStorage
|
|
111
|
+
*/
|
|
112
|
+
function save(namespaces) {
|
|
113
|
+
try {
|
|
114
|
+
if (namespaces) {
|
|
115
|
+
storage?.setItem('debug', namespaces);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
storage?.removeItem('debug');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// Ignore errors (e.g., localStorage quota exceeded)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Load namespaces from localStorage
|
|
127
|
+
*/
|
|
128
|
+
function load() {
|
|
129
|
+
let r = '';
|
|
130
|
+
try {
|
|
131
|
+
r = storage?.getItem('debug') || '';
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
// Ignore errors
|
|
135
|
+
}
|
|
136
|
+
// Also check URL query parameter
|
|
137
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
138
|
+
const match = window.location.search.match(/[?&]debug=([^&]*)/);
|
|
139
|
+
if (match) {
|
|
140
|
+
r = decodeURIComponent(match[1]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return r;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Destroy function (deprecated)
|
|
147
|
+
*/
|
|
148
|
+
let warnedDestroy = false;
|
|
149
|
+
function destroy() {
|
|
150
|
+
if (!warnedDestroy) {
|
|
151
|
+
warnedDestroy = true;
|
|
152
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything.');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Import ms for humanizing time
|
|
156
|
+
const ms = require("ms");
|
|
157
|
+
/**
|
|
158
|
+
* Create environment config for browser
|
|
159
|
+
*/
|
|
160
|
+
const browserEnv = {
|
|
161
|
+
formatArgs,
|
|
162
|
+
save,
|
|
163
|
+
load,
|
|
164
|
+
useColors,
|
|
165
|
+
colors,
|
|
166
|
+
log,
|
|
167
|
+
storage,
|
|
168
|
+
destroy,
|
|
169
|
+
};
|
|
170
|
+
module.exports = (0, common_1.setup)(browserEnv);
|
|
171
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH,qCAAiC;AAGjC;;GAEG;AACH,MAAM,MAAM,GAAG;IACb,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;IACtF,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;IACtF,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;IACtF,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;IACtF,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;IACtF,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,S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C;AAED;;GAEG;AACH,SAAS,IAAI;IACX,IAAI,CAAC,GAAW,EAAE,CAAC;IACnB,IAAI,CAAC;QACH,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAgB;IAClB,CAAC;IAED,iCAAiC;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChE,IAAI,KAAK,EAAE,CAAC;YACV,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;GAEG;AACH,IAAI,aAAa,GAAG,KAAK,CAAC;AAC1B,SAAS,OAAO;IACd,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,CAAC;QACrB,OAAO,CAAC,IAAI,CACV,8EAA8E,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gCAAgC;AAChC,yBAA0B;AAE1B;;GAEG;AACH,MAAM,UAAU,GAAsB;IACpC,UAAU;IACV,IAAI;IACJ,IAAI;IACJ,SAAS;IACT,MAAM;IACN,GAAG;IACH,OAAO;IACP,OAAO;CACR,CAAC;AAKF,iBAAS,IAAA,cAAK,EAAC,UAAU,CAAC,CAAC"}
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common logic for both Node.js and browser implementations
|
|
3
|
+
*/
|
|
4
|
+
import { DebugFactory, EnvironmentConfig } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Setup function that creates the debug factory with environment-specific config
|
|
7
|
+
*/
|
|
8
|
+
export declare function setup(env: EnvironmentConfig): DebugFactory;
|
|
9
|
+
/**
|
|
10
|
+
* Match a namespace against a template with wildcards
|
|
11
|
+
*/
|
|
12
|
+
declare function matchesTemplate(search: string, template: string): boolean;
|
|
13
|
+
export { matchesTemplate };
|
|
14
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAEL,YAAY,EAEZ,iBAAiB,EAElB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,iBAAiB,GAAG,YAAY,CAuP1D;AAED;;GAEG;AACH,iBAAS,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAkClE;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|