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/dist/node.js ADDED
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ /**
3
+ * Node.js implementation of debug-utility
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ const tty = __importStar(require("tty"));
39
+ const util = __importStar(require("util"));
40
+ const common_1 = require("./common");
41
+ /**
42
+ * Colors for Node.js (ANSI color codes)
43
+ */
44
+ const colors = [
45
+ 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77,
46
+ 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, 135, 148, 149, 160, 161, 162, 163, 164,
47
+ 165, 166, 167, 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201,
48
+ 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221,
49
+ ];
50
+ /**
51
+ * Check if supports-color is available (optional dependency)
52
+ */
53
+ try {
54
+ const supportsColor = require('supports-color');
55
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
56
+ // Use extended color palette if available
57
+ }
58
+ }
59
+ catch (e) {
60
+ // supports-color is optional
61
+ }
62
+ /**
63
+ * Build inspect options from environment variables
64
+ */
65
+ const inspectOpts = Object.keys(process.env)
66
+ .filter((key) => /^debug_/i.test(key))
67
+ .reduce((obj, key) => {
68
+ // Convert DEBUG_COLORS to colors
69
+ const prop = key
70
+ .substring(6)
71
+ .toLowerCase()
72
+ .replace(/_([a-z])/g, (_, k) => k.toUpperCase());
73
+ // Coerce string value
74
+ let val = process.env[key];
75
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
76
+ val = true;
77
+ }
78
+ else if (/^(no|off|false|disabled)$/i.test(val)) {
79
+ val = false;
80
+ }
81
+ else if (val === 'null') {
82
+ val = null;
83
+ }
84
+ else {
85
+ val = Number(val);
86
+ }
87
+ obj[prop] = val;
88
+ return obj;
89
+ }, {});
90
+ /**
91
+ * Check if colors should be used
92
+ */
93
+ function useColors() {
94
+ if ('colors' in inspectOpts) {
95
+ return Boolean(inspectOpts.colors);
96
+ }
97
+ return tty.isatty(process.stderr.fd);
98
+ }
99
+ /**
100
+ * Format arguments with ANSI colors
101
+ */
102
+ function formatArgs(args) {
103
+ const { namespace, useColors: shouldUseColors } = this;
104
+ if (shouldUseColors) {
105
+ const c = this.color;
106
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
107
+ const prefix = ` ${colorCode};1m${namespace} \u001B[0m`;
108
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
109
+ args.push(colorCode + 'm+' + ms(this.diff) + '\u001B[0m');
110
+ }
111
+ else {
112
+ args[0] = getDate() + namespace + ' ' + args[0];
113
+ }
114
+ }
115
+ /**
116
+ * Get formatted date
117
+ */
118
+ function getDate() {
119
+ if (inspectOpts.hideDate) {
120
+ return '';
121
+ }
122
+ return new Date().toISOString() + ' ';
123
+ }
124
+ /**
125
+ * Log to stderr
126
+ */
127
+ function log(...args) {
128
+ process.stderr.write(util.formatWithOptions(inspectOpts, ...args) + '\n');
129
+ }
130
+ /**
131
+ * Save namespaces to environment
132
+ */
133
+ function save(namespaces) {
134
+ if (namespaces) {
135
+ process.env.DEBUG = namespaces;
136
+ }
137
+ else {
138
+ delete process.env.DEBUG;
139
+ }
140
+ }
141
+ /**
142
+ * Load namespaces from environment
143
+ */
144
+ function load() {
145
+ return process.env.DEBUG || '';
146
+ }
147
+ /**
148
+ * Destroy function (deprecated)
149
+ */
150
+ function destroy() {
151
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything.');
152
+ }
153
+ /**
154
+ * Initialize a debug instance (optional)
155
+ */
156
+ function init(debug) {
157
+ // Initialization logic can be added here if needed
158
+ debug.inspectOpts = inspectOpts;
159
+ }
160
+ // Import ms for humanizing time
161
+ const ms = require("ms");
162
+ /**
163
+ * Create environment config for Node.js
164
+ */
165
+ const nodeEnv = {
166
+ formatArgs,
167
+ save,
168
+ load,
169
+ useColors,
170
+ colors,
171
+ log,
172
+ inspectOpts,
173
+ init,
174
+ destroy,
175
+ };
176
+ module.exports = (0, common_1.setup)(nodeEnv);
177
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAA2B;AAC3B,2CAA6B;AAC7B,qCAAiC;AAGjC;;GAEG;AACH,MAAM,MAAM,GAAG;IACb,EAAE,E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AG,UAAU,CAAC;IACjC,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;IAC3B,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,IAAI;IACX,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAS,OAAO;IACd,OAAO,CAAC,IAAI,CACV,8EAA8E,CAC/E,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,IAAI,CAAC,KAAe;IAC3B,mDAAmD;IAClD,KAAa,CAAC,WAAW,GAAG,WAAW,CAAC;AAC3C,CAAC;AAED,gCAAgC;AAChC,yBAA0B;AAE1B;;GAEG;AACH,MAAM,OAAO,GAAsB;IACjC,UAAU;IACV,IAAI;IACJ,IAAI;IACJ,SAAS;IACT,MAAM;IACN,GAAG;IACH,WAAW;IACX,IAAI;IACJ,OAAO;CACR,CAAC;AAKF,iBAAS,IAAA,cAAK,EAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Core type definitions for debug-utility
3
+ */
4
+ /**
5
+ * Filter predicate function type
6
+ */
7
+ export type FilterPredicate = (namespace: string, ...args: any[]) => boolean;
8
+ /**
9
+ * Formatter function type
10
+ */
11
+ export type FormatterFunction = (value: any) => string;
12
+ /**
13
+ * Log function type
14
+ */
15
+ export type LogFunction = (...args: any[]) => void;
16
+ /**
17
+ * Filter options for advanced filtering
18
+ */
19
+ export interface FilterOptions {
20
+ /** Enable/disable filtering */
21
+ enabled?: boolean;
22
+ /** Regular expression patterns to match */
23
+ patterns?: RegExp[];
24
+ /** Custom predicate functions */
25
+ predicates?: FilterPredicate[];
26
+ /** Minimum log level (if using levels) */
27
+ minLevel?: number;
28
+ /** Maximum log level (if using levels) */
29
+ maxLevel?: number;
30
+ /** Custom tags to filter by */
31
+ tags?: string[];
32
+ /** Include these namespaces */
33
+ include?: string[];
34
+ /** Exclude these namespaces */
35
+ exclude?: string[];
36
+ }
37
+ /**
38
+ * Debug instance options
39
+ */
40
+ export interface DebugOptions {
41
+ /** Custom namespace */
42
+ namespace?: string;
43
+ /** Enable/disable colors */
44
+ useColors?: boolean;
45
+ /** Custom color */
46
+ color?: string | number;
47
+ /** Hide timestamp */
48
+ hideDate?: boolean;
49
+ /** Custom log function */
50
+ log?: LogFunction;
51
+ /** Filter options */
52
+ filter?: FilterOptions;
53
+ /** Additional metadata */
54
+ metadata?: Record<string, any>;
55
+ }
56
+ /**
57
+ * Debug instance interface
58
+ */
59
+ export interface Debugger {
60
+ /** The namespace of this debugger instance */
61
+ namespace: string;
62
+ /** Whether colors are enabled */
63
+ useColors: boolean;
64
+ /** The color assigned to this instance */
65
+ color: string | number;
66
+ /** Time difference from previous log */
67
+ diff: number;
68
+ /** Previous log timestamp */
69
+ prev: number;
70
+ /** Current log timestamp */
71
+ curr: number;
72
+ /** Whether this debugger is enabled */
73
+ enabled: boolean;
74
+ /** The log function */
75
+ log: LogFunction;
76
+ /** Metadata attached to this instance */
77
+ metadata: Record<string, any>;
78
+ /** Log a message */
79
+ (...args: any[]): void;
80
+ /** Extend this debugger with a sub-namespace */
81
+ extend(namespace: string, delimiter?: string): Debugger;
82
+ /** Destroy this debugger instance (deprecated) */
83
+ destroy(): void;
84
+ /** Set filter options for this instance */
85
+ setFilter(filter: FilterOptions): void;
86
+ /** Add metadata to this instance */
87
+ setMetadata(key: string, value: any): void;
88
+ /** Get metadata from this instance */
89
+ getMetadata(key: string): any;
90
+ }
91
+ /**
92
+ * Debug factory interface
93
+ */
94
+ export interface DebugFactory {
95
+ /** Create a new debugger instance */
96
+ (namespace: string, options?: DebugOptions): Debugger;
97
+ /** Available colors */
98
+ colors: (string | number)[];
99
+ /** Named namespaces that are enabled */
100
+ names: string[];
101
+ /** Named namespaces that are skipped */
102
+ skips: string[];
103
+ /** Current namespace configuration */
104
+ namespaces: string;
105
+ /** Custom formatters */
106
+ formatters: Record<string, FormatterFunction>;
107
+ /** Inspect options (Node.js specific) */
108
+ inspectOpts?: Record<string, any>;
109
+ /** Enable debug output */
110
+ enable(namespaces: string): void;
111
+ /** Disable debug output */
112
+ disable(): string;
113
+ /** Check if a namespace is enabled */
114
+ enabled(name: string): boolean;
115
+ /** Humanize time differences */
116
+ humanize: (ms: number) => string;
117
+ /** Select a color for a namespace */
118
+ selectColor(namespace: string): string | number;
119
+ /** Coerce a value */
120
+ coerce(val: any): any;
121
+ /** Format arguments (environment-specific) */
122
+ formatArgs(args: any[]): void;
123
+ /** Log function (environment-specific) */
124
+ log: LogFunction;
125
+ /** Save namespaces (environment-specific) */
126
+ save(namespaces: string): void;
127
+ /** Load namespaces (environment-specific) */
128
+ load(): string;
129
+ /** Use colors check (environment-specific) */
130
+ useColors(): boolean;
131
+ /** Initialize a debug instance (environment-specific) */
132
+ init?(debug: Debugger): void;
133
+ /** Destroy function (deprecated) */
134
+ destroy(): void;
135
+ /** Set global filter options */
136
+ setGlobalFilter(filter: FilterOptions): void;
137
+ /** Get global filter options */
138
+ getGlobalFilter(): FilterOptions;
139
+ }
140
+ /**
141
+ * Environment-specific configuration
142
+ */
143
+ export interface EnvironmentConfig {
144
+ /** Format arguments for output */
145
+ formatArgs: (args: any[]) => void;
146
+ /** Save namespace configuration */
147
+ save: (namespaces: string) => void;
148
+ /** Load namespace configuration */
149
+ load: () => string;
150
+ /** Check if colors should be used */
151
+ useColors: () => boolean;
152
+ /** Available colors */
153
+ colors: (string | number)[];
154
+ /** Log function */
155
+ log: LogFunction;
156
+ /** Inspect options */
157
+ inspectOpts?: Record<string, any>;
158
+ /** Storage mechanism (browser) */
159
+ storage?: Storage | null;
160
+ /** Initialize function */
161
+ init?: (debug: Debugger) => void;
162
+ /** Destroy function */
163
+ destroy: () => void;
164
+ }
165
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;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AU,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAClC,mCAAmC;IACnC,IAAI,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,mCAAmC;IACnC,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,qCAAqC;IACrC,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,uBAAuB;IACvB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC5B,mBAAmB;IACnB,GAAG,EAAE,WAAW,CAAC;IACjB,sBAAsB;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,kCAAkC;IAClC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,0BAA0B;IAC1B,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;IACjC,uBAAuB;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Core type definitions for debug-utility
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "debug-better",
3
+ "version": "1.0.0",
4
+ "description": "Advanced TypeScript debugging utility with filtering capabilities for Node.js and browser",
5
+ "keywords": [
6
+ "debug",
7
+ "log",
8
+ "debugger",
9
+ "typescript",
10
+ "filtering",
11
+ "logger",
12
+ "utility"
13
+ ],
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "browser": "./dist/browser.js",
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "LICENSE",
21
+ "README.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "watch": "tsc --watch",
26
+ "clean": "rm -rf dist",
27
+ "prepublishOnly": "npm run clean && npm run build",
28
+ "test": "node dist/examples/test.js",
29
+ "lint": "eslint src/**/*.ts",
30
+ "format": "prettier --write \"src/**/*.ts\""
31
+ },
32
+ "engines": {
33
+ "node": ">=18.0.0"
34
+ },
35
+ "dependencies": {
36
+ "ms": "^2.1.3"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^20.10.0",
40
+ "@types/ms": "^0.7.34",
41
+ "typescript": "^5.3.3",
42
+ "eslint": "^8.55.0",
43
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
44
+ "@typescript-eslint/parser": "^6.14.0",
45
+ "prettier": "^3.1.1"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git://github.com/yourusername/debug-utility.git"
50
+ },
51
+ "author": "Your Name",
52
+ "license": "MIT"
53
+ }
package/src/browser.ts ADDED
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Browser implementation of debug-utility
3
+ */
4
+
5
+ import { setup } from './common';
6
+ import { EnvironmentConfig, Debugger } from './types';
7
+
8
+ /**
9
+ * Colors for browser (hex codes)
10
+ */
11
+ const colors = [
12
+ '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF',
13
+ '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF',
14
+ '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33',
15
+ '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF',
16
+ '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33',
17
+ '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333',
18
+ '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
19
+ '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF',
20
+ '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633',
21
+ '#FF9900', '#FF9933', '#FFCC00', '#FFCC33',
22
+ ];
23
+
24
+ /**
25
+ * Get localStorage safely
26
+ */
27
+ function localstorage(): Storage | null {
28
+ try {
29
+ if (typeof window !== 'undefined' && window.localStorage) {
30
+ return window.localStorage;
31
+ }
32
+ return null;
33
+ } catch (e) {
34
+ return null;
35
+ }
36
+ }
37
+
38
+ const storage = localstorage();
39
+
40
+ /**
41
+ * Check if colors should be used in browser
42
+ */
43
+ function useColors(): boolean {
44
+ // Electron renderer
45
+ if (
46
+ typeof window !== 'undefined' &&
47
+ (window as any).process &&
48
+ ((window as any).process.type === 'renderer' || (window as any).process.__nwjs)
49
+ ) {
50
+ return true;
51
+ }
52
+
53
+ // Internet Explorer and Edge do not support colors
54
+ if (
55
+ typeof navigator !== 'undefined' &&
56
+ navigator.userAgent &&
57
+ navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)
58
+ ) {
59
+ return false;
60
+ }
61
+
62
+ // Check for various browser capabilities
63
+ return (
64
+ (typeof document !== 'undefined' &&
65
+ document.documentElement &&
66
+ document.documentElement.style &&
67
+ (document.documentElement.style as any).WebkitAppearance) ||
68
+ (typeof window !== 'undefined' &&
69
+ (window as any).console &&
70
+ ((window as any).console.firebug ||
71
+ ((window as any).console.exception && (window as any).console.table))) ||
72
+ (typeof navigator !== 'undefined' &&
73
+ navigator.userAgent &&
74
+ navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) &&
75
+ parseInt(RegExp.$1, 10) >= 31) ||
76
+ (typeof navigator !== 'undefined' &&
77
+ navigator.userAgent &&
78
+ navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Format arguments with browser colors
84
+ */
85
+ function formatArgs(this: Debugger, args: any[]): void {
86
+ args[0] =
87
+ (this.useColors ? '%c' : '') +
88
+ this.namespace +
89
+ (this.useColors ? ' %c' : ' ') +
90
+ args[0] +
91
+ (this.useColors ? '%c ' : ' ') +
92
+ '+' +
93
+ ms(this.diff);
94
+
95
+ if (!this.useColors) {
96
+ return;
97
+ }
98
+
99
+ const c = 'color: ' + this.color;
100
+ args.splice(1, 0, c, 'color: inherit');
101
+
102
+ // Handle %c positioning
103
+ let index = 0;
104
+ let lastC = 0;
105
+ args[0].replace(/%[a-zA-Z%]/g, (match: string) => {
106
+ if (match === '%%') {
107
+ return match;
108
+ }
109
+ index++;
110
+ if (match === '%c') {
111
+ lastC = index;
112
+ }
113
+ return match;
114
+ });
115
+
116
+ args.splice(lastC, 0, c);
117
+ }
118
+
119
+ /**
120
+ * Log function for browser
121
+ */
122
+ const log =
123
+ typeof console !== 'undefined' && typeof console.debug === 'function'
124
+ ? console.debug.bind(console)
125
+ : typeof console !== 'undefined' && typeof console.log === 'function'
126
+ ? console.log.bind(console)
127
+ : (): void => {};
128
+
129
+ /**
130
+ * Save namespaces to localStorage
131
+ */
132
+ function save(namespaces: string): void {
133
+ try {
134
+ if (namespaces) {
135
+ storage?.setItem('debug', namespaces);
136
+ } else {
137
+ storage?.removeItem('debug');
138
+ }
139
+ } catch (error) {
140
+ // Ignore errors (e.g., localStorage quota exceeded)
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Load namespaces from localStorage
146
+ */
147
+ function load(): string {
148
+ let r: string = '';
149
+ try {
150
+ r = storage?.getItem('debug') || '';
151
+ } catch (error) {
152
+ // Ignore errors
153
+ }
154
+
155
+ // Also check URL query parameter
156
+ if (typeof window !== 'undefined' && window.location) {
157
+ const match = window.location.search.match(/[?&]debug=([^&]*)/);
158
+ if (match) {
159
+ r = decodeURIComponent(match[1]);
160
+ }
161
+ }
162
+
163
+ return r;
164
+ }
165
+
166
+ /**
167
+ * Destroy function (deprecated)
168
+ */
169
+ let warnedDestroy = false;
170
+ function destroy(): void {
171
+ if (!warnedDestroy) {
172
+ warnedDestroy = true;
173
+ console.warn(
174
+ 'Instance method `debug.destroy()` is deprecated and no longer does anything.'
175
+ );
176
+ }
177
+ }
178
+
179
+ // Import ms for humanizing time
180
+ import ms = require('ms');
181
+
182
+ /**
183
+ * Create environment config for browser
184
+ */
185
+ const browserEnv: EnvironmentConfig = {
186
+ formatArgs,
187
+ save,
188
+ load,
189
+ useColors,
190
+ colors,
191
+ log,
192
+ storage,
193
+ destroy,
194
+ };
195
+
196
+ /**
197
+ * Export the debug factory
198
+ */
199
+ export = setup(browserEnv);