@substrate-system/debug 0.9.12 → 0.9.13

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/README.md CHANGED
@@ -9,9 +9,8 @@
9
9
 
10
10
 
11
11
  A tiny JavaScript debugging utility that works in Node.js and browsers.
12
- Use environment variables to control logging in Node.js, and localStorage
13
- to control logging in browsers, so there are no ridiculous console log
14
- statements in production.
12
+ Use environment variables to control logging in Node.js, and `localStorage`
13
+ in browsers. Keep your ridiculous console log statements out of production.
15
14
 
16
15
  This is based on [debug](https://github.com/debug-js/debug).
17
16
  It's been rewritten to use contemporary JS.
@@ -39,7 +38,7 @@ generated by typescript.
39
38
  * [Namespace](#namespace)
40
39
  * [Enable all namespaces](#enable-all-namespaces)
41
40
  * [Enable specific namespaces](#enable-specific-namespaces)
42
- * [Force logging with boolean true](#force-logging-with-boolean-true)
41
+ * [Extend](#extend)
43
42
  - [Develop](#develop)
44
43
  * [browser](#browser)
45
44
  * [Run the Node example](#run-the-node-example)
@@ -67,6 +66,7 @@ import Debug from '@substrate-system/debug'
67
66
  // Set DEBUG in localStorage
68
67
  localStorage.setItem('DEBUG', 'myapp:*')
69
68
 
69
+ // create debug instance
70
70
  const debug = Debug('myapp:component')
71
71
  debug('hello logs')
72
72
  // will log, because DEBUG in localStorage matches 'myapp:*'
@@ -74,20 +74,24 @@ debug('hello logs')
74
74
 
75
75
  ### Factor out of production
76
76
 
77
- Use dynamic imoprts to keep this out of your production code.
77
+ Use [dynamic imoprts](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)
78
+ to keep this entirely out of production code, so your bundle is smaller.
78
79
 
79
80
  ```ts
80
- import type { Debugger } from '@substrate-system/debug'
81
+ import { Debugger } from '@substrate-system/debug/browser'
82
+ import { noop } from '@substrate-system/debug/noop'
81
83
 
82
84
  let debug:Debugger
83
85
  if (import.meta.env.DEV) {
84
86
  const Debug = await import('/example/debug.js')
85
87
  debug = Debug('myApplication:abc')
86
88
  } else {
87
- debug = function noop (...args:any[]) {}
89
+ debug = noop // this is a function matching the signature for Debugger
88
90
  }
89
91
  ```
90
92
 
93
+ > [!NOTE]
94
+ > We export `noop` here; it has the same type signature as `debug`.
91
95
 
92
96
  ## Node JS
93
97
  Run your script with an env variable, `DEBUG`.
@@ -128,18 +132,30 @@ localStorage.setItem('DEBUG', '*')
128
132
 
129
133
  ### Enable specific namespaces
130
134
  ```js
131
- localStorage.setItem('DEBUG', 'myapp:auth,myapp:api')
135
+ localStorage.setItem('DEBUG', 'myapp:auth,myapp:api,myapp:api:*')
132
136
  ```
133
137
 
134
- ### Force logging with boolean true
138
+ ### Extend
135
139
 
136
- You can also pass `true` to force logging regardless of `localStorage`.
137
- For example, in Vite, this will log on your localhost server, but not
138
- in production:
140
+ You can extend the debugger to create new debug instances with new namespaces:
139
141
 
140
142
  ```js
141
- const debug = Debug(import.meta.env.DEV)
142
- debug('This logs')
143
+ const log = Debug('auth')
144
+
145
+ // Creates new debug instance with extended namespace
146
+ const logSign = log.extend('sign')
147
+ const logLogin = log.extend('login')
148
+
149
+ log('hello') // auth hello
150
+ logSign('hello') // auth:sign hello
151
+ logLogin('hello') // auth:login hello
152
+ ```
153
+
154
+ Chained extending is also supported:
155
+
156
+ ```js
157
+ const logSignVerbose = logSign.extend('verbose')
158
+ logSignVerbose('hello') // auth:sign:verbose hello
143
159
  ```
144
160
 
145
161
  ------------------------------------------------------------------
@@ -0,0 +1,397 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+
34
+ // node_modules/ms/index.js
35
+ var require_ms = __commonJS({
36
+ "node_modules/ms/index.js"(exports, module2) {
37
+ "use strict";
38
+ var s = 1e3;
39
+ var m = s * 60;
40
+ var h = m * 60;
41
+ var d = h * 24;
42
+ var w = d * 7;
43
+ var y = d * 365.25;
44
+ module2.exports = function(val, options) {
45
+ options = options || {};
46
+ var type = typeof val;
47
+ if (type === "string" && val.length > 0) {
48
+ return parse(val);
49
+ } else if (type === "number" && isFinite(val)) {
50
+ return options.long ? fmtLong(val) : fmtShort(val);
51
+ }
52
+ throw new Error(
53
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
54
+ );
55
+ };
56
+ function parse(str) {
57
+ str = String(str);
58
+ if (str.length > 100) {
59
+ return;
60
+ }
61
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
62
+ str
63
+ );
64
+ if (!match) {
65
+ return;
66
+ }
67
+ var n = parseFloat(match[1]);
68
+ var type = (match[2] || "ms").toLowerCase();
69
+ switch (type) {
70
+ case "years":
71
+ case "year":
72
+ case "yrs":
73
+ case "yr":
74
+ case "y":
75
+ return n * y;
76
+ case "weeks":
77
+ case "week":
78
+ case "w":
79
+ return n * w;
80
+ case "days":
81
+ case "day":
82
+ case "d":
83
+ return n * d;
84
+ case "hours":
85
+ case "hour":
86
+ case "hrs":
87
+ case "hr":
88
+ case "h":
89
+ return n * h;
90
+ case "minutes":
91
+ case "minute":
92
+ case "mins":
93
+ case "min":
94
+ case "m":
95
+ return n * m;
96
+ case "seconds":
97
+ case "second":
98
+ case "secs":
99
+ case "sec":
100
+ case "s":
101
+ return n * s;
102
+ case "milliseconds":
103
+ case "millisecond":
104
+ case "msecs":
105
+ case "msec":
106
+ case "ms":
107
+ return n;
108
+ default:
109
+ return void 0;
110
+ }
111
+ }
112
+ __name(parse, "parse");
113
+ function fmtShort(ms) {
114
+ var msAbs = Math.abs(ms);
115
+ if (msAbs >= d) {
116
+ return Math.round(ms / d) + "d";
117
+ }
118
+ if (msAbs >= h) {
119
+ return Math.round(ms / h) + "h";
120
+ }
121
+ if (msAbs >= m) {
122
+ return Math.round(ms / m) + "m";
123
+ }
124
+ if (msAbs >= s) {
125
+ return Math.round(ms / s) + "s";
126
+ }
127
+ return ms + "ms";
128
+ }
129
+ __name(fmtShort, "fmtShort");
130
+ function fmtLong(ms) {
131
+ var msAbs = Math.abs(ms);
132
+ if (msAbs >= d) {
133
+ return plural(ms, msAbs, d, "day");
134
+ }
135
+ if (msAbs >= h) {
136
+ return plural(ms, msAbs, h, "hour");
137
+ }
138
+ if (msAbs >= m) {
139
+ return plural(ms, msAbs, m, "minute");
140
+ }
141
+ if (msAbs >= s) {
142
+ return plural(ms, msAbs, s, "second");
143
+ }
144
+ return ms + " ms";
145
+ }
146
+ __name(fmtLong, "fmtLong");
147
+ function plural(ms, msAbs, n, name) {
148
+ var isPlural = msAbs >= n * 1.5;
149
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
150
+ }
151
+ __name(plural, "plural");
152
+ }
153
+ });
154
+
155
+ // src/browser/index.ts
156
+ var index_exports = {};
157
+ __export(index_exports, {
158
+ createDebug: () => createDebug,
159
+ default: () => index_default
160
+ });
161
+ module.exports = __toCommonJS(index_exports);
162
+ var import_ms = __toESM(require_ms(), 1);
163
+
164
+ // src/common.ts
165
+ function coerce(val) {
166
+ if (val instanceof Error) {
167
+ return val.stack || val.message;
168
+ }
169
+ return String(val);
170
+ }
171
+ __name(coerce, "coerce");
172
+ function selectColor(namespace, colors2) {
173
+ let hash = 0;
174
+ for (let i = 0; i < namespace.length; i++) {
175
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
176
+ hash |= 0;
177
+ }
178
+ return colors2[Math.abs(hash) % colors2.length];
179
+ }
180
+ __name(selectColor, "selectColor");
181
+ function createRegexFromEnvVar(names) {
182
+ const split = names.split(/[\s,]+/).filter(Boolean);
183
+ const regexs = split.map((word) => word.replace(/\*/g, ".*?")).map((r) => new RegExp("^" + r + "$"));
184
+ return regexs;
185
+ }
186
+ __name(createRegexFromEnvVar, "createRegexFromEnvVar");
187
+ function generateRandomString(length = 6) {
188
+ return Math.random().toString(20).substring(2, length);
189
+ }
190
+ __name(generateRandomString, "generateRandomString");
191
+
192
+ // src/noop.ts
193
+ var noop = /* @__PURE__ */ __name(function(_args) {
194
+ }, "noop");
195
+ noop.extend = function(_namespace) {
196
+ return noop;
197
+ };
198
+
199
+ // src/browser/util.ts
200
+ var colors = [
201
+ "#0000CC",
202
+ "#0000FF",
203
+ "#0033CC",
204
+ "#0033FF",
205
+ "#0066CC",
206
+ "#0066FF",
207
+ "#0099CC",
208
+ "#0099FF",
209
+ "#00CC00",
210
+ "#00CC33",
211
+ "#00CC66",
212
+ "#00CC99",
213
+ "#00CCCC",
214
+ "#00CCFF",
215
+ "#3300CC",
216
+ "#3300FF",
217
+ "#3333CC",
218
+ "#3333FF",
219
+ "#3366CC",
220
+ "#3366FF",
221
+ "#3399CC",
222
+ "#3399FF",
223
+ "#33CC00",
224
+ "#33CC33",
225
+ "#33CC66",
226
+ "#33CC99",
227
+ "#33CCCC",
228
+ "#33CCFF",
229
+ "#6600CC",
230
+ "#6600FF",
231
+ "#6633CC",
232
+ "#6633FF",
233
+ "#66CC00",
234
+ "#66CC33",
235
+ "#9900CC",
236
+ "#9900FF",
237
+ "#9933CC",
238
+ "#9933FF",
239
+ "#99CC00",
240
+ "#99CC33",
241
+ "#CC0000",
242
+ "#CC0033",
243
+ "#CC0066",
244
+ "#CC0099",
245
+ "#CC00CC",
246
+ "#CC00FF",
247
+ "#CC3300",
248
+ "#CC3333",
249
+ "#CC3366",
250
+ "#CC3399",
251
+ "#CC33CC",
252
+ "#CC33FF",
253
+ "#CC6600",
254
+ "#CC6633",
255
+ "#CC9900",
256
+ "#CC9933",
257
+ "#CCCC00",
258
+ "#CCCC33",
259
+ "#FF0000",
260
+ "#FF0033",
261
+ "#FF0066",
262
+ "#FF0099",
263
+ "#FF00CC",
264
+ "#FF00FF",
265
+ "#FF3300",
266
+ "#FF3333",
267
+ "#FF3366",
268
+ "#FF3399",
269
+ "#FF33CC",
270
+ "#FF33FF",
271
+ "#FF6600",
272
+ "#FF6633",
273
+ "#FF9900",
274
+ "#FF9933",
275
+ "#FFCC00",
276
+ "#FFCC33"
277
+ ];
278
+
279
+ // src/browser/index.ts
280
+ var log = console.log || (() => {
281
+ });
282
+ var index_default = createDebug;
283
+ function isEnabled(namespace, forcedEnabled) {
284
+ if (forcedEnabled === true) return true;
285
+ const DEBUG = localStorage?.getItem("DEBUG");
286
+ if (DEBUG === "*") return true;
287
+ if (namespace === "DEV") {
288
+ if (!DEBUG) {
289
+ return true;
290
+ }
291
+ return false;
292
+ }
293
+ if (!DEBUG) return false;
294
+ const envVars = createRegexFromEnvVar(DEBUG);
295
+ return envVars.some((regex) => regex.test(namespace));
296
+ }
297
+ __name(isEnabled, "isEnabled");
298
+ function createFormatters() {
299
+ return {
300
+ j: /* @__PURE__ */ __name(function(v) {
301
+ try {
302
+ return JSON.stringify(v);
303
+ } catch (error) {
304
+ return "[UnexpectedJSONParseError]: " + String(error);
305
+ }
306
+ }, "j")
307
+ };
308
+ }
309
+ __name(createFormatters, "createFormatters");
310
+ function logger(namespace, args, { prevTime, color }, forcedEnabled) {
311
+ args = args || [];
312
+ if (!isEnabled(namespace, forcedEnabled)) return;
313
+ const curr = Number(/* @__PURE__ */ new Date());
314
+ const diff = curr - (prevTime || curr);
315
+ prevTime = curr;
316
+ args[0] = coerce(args[0]);
317
+ const formatters = createFormatters();
318
+ if (typeof args[0] !== "string") {
319
+ args.unshift("%O");
320
+ }
321
+ let index = 0;
322
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
323
+ if (match === "%%") return "%";
324
+ index++;
325
+ const formatter = formatters[format];
326
+ if (typeof formatter === "function") {
327
+ const val = args[index];
328
+ match = formatter.call(self, val);
329
+ args.splice(index, 1);
330
+ index--;
331
+ }
332
+ return match;
333
+ });
334
+ const _args = formatArgs({
335
+ diff,
336
+ color,
337
+ useColors: shouldUseColors(),
338
+ namespace
339
+ }, args);
340
+ log(..._args);
341
+ }
342
+ __name(logger, "logger");
343
+ function shouldUseColors() {
344
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
345
+ return false;
346
+ }
347
+ return !!(typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.webkitAppearance || // Is firefox >= v31?
348
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
349
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
350
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
351
+ }
352
+ __name(shouldUseColors, "shouldUseColors");
353
+ function formatArgs({ diff, color, namespace, useColors }, args) {
354
+ args[0] = (useColors ? "%c" : "") + namespace + (useColors ? " %c" : " ") + args[0] + (useColors ? "%c " : " ") + "+" + (0, import_ms.default)(diff, {});
355
+ if (!useColors) return;
356
+ const c = "color: " + color;
357
+ args.splice(1, 0, c, "color: inherit");
358
+ let index = 0;
359
+ let lastC = 0;
360
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
361
+ if (match === "%%") {
362
+ return;
363
+ }
364
+ index++;
365
+ if (match === "%c") {
366
+ lastC = index;
367
+ }
368
+ });
369
+ args.splice(lastC, 0, c);
370
+ return args;
371
+ }
372
+ __name(formatArgs, "formatArgs");
373
+ function createDebug(namespace) {
374
+ if (namespace === false) return noop;
375
+ const prevTime = Number(/* @__PURE__ */ new Date());
376
+ const color = selectColor(
377
+ typeof namespace === "string" ? namespace : generateRandomString(10),
378
+ colors
379
+ );
380
+ const forcedEnabled = namespace === true;
381
+ const actualNamespace = typeof namespace === "string" ? namespace : "DEV";
382
+ const debug = /* @__PURE__ */ __name(function(...args) {
383
+ return logger(
384
+ actualNamespace,
385
+ args,
386
+ { prevTime, color },
387
+ forcedEnabled
388
+ );
389
+ }, "debug");
390
+ debug.extend = function(extension) {
391
+ const extendedNamespace = actualNamespace + ":" + extension;
392
+ return createDebug(extendedNamespace);
393
+ };
394
+ return debug;
395
+ }
396
+ __name(createDebug, "createDebug");
397
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../node_modules/ms/index.js", "../../src/browser/index.ts", "../../src/common.ts", "../../src/noop.ts", "../../src/browser/util.ts"],
4
+ "sourcesContent": ["/**\n * Helpers.\n */\n\nvar s = 1000;\nvar m = s * 60;\nvar h = m * 60;\nvar d = h * 24;\nvar w = d * 7;\nvar y = d * 365.25;\n\n/**\n * Parse or format the given `val`.\n *\n * Options:\n *\n * - `long` verbose formatting [false]\n *\n * @param {String|Number} val\n * @param {Object} [options]\n * @throws {Error} throw an error if val is not a non-empty string or a number\n * @return {String|Number}\n * @api public\n */\n\nmodule.exports = function (val, options) {\n options = options || {};\n var type = typeof val;\n if (type === 'string' && val.length > 0) {\n return parse(val);\n } else if (type === 'number' && isFinite(val)) {\n return options.long ? fmtLong(val) : fmtShort(val);\n }\n throw new Error(\n 'val is not a non-empty string or a valid number. val=' +\n JSON.stringify(val)\n );\n};\n\n/**\n * Parse the given `str` and return milliseconds.\n *\n * @param {String} str\n * @return {Number}\n * @api private\n */\n\nfunction parse(str) {\n str = String(str);\n if (str.length > 100) {\n return;\n }\n var match = /^(-?(?:\\d+)?\\.?\\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(\n str\n );\n if (!match) {\n return;\n }\n var n = parseFloat(match[1]);\n var type = (match[2] || 'ms').toLowerCase();\n switch (type) {\n case 'years':\n case 'year':\n case 'yrs':\n case 'yr':\n case 'y':\n return n * y;\n case 'weeks':\n case 'week':\n case 'w':\n return n * w;\n case 'days':\n case 'day':\n case 'd':\n return n * d;\n case 'hours':\n case 'hour':\n case 'hrs':\n case 'hr':\n case 'h':\n return n * h;\n case 'minutes':\n case 'minute':\n case 'mins':\n case 'min':\n case 'm':\n return n * m;\n case 'seconds':\n case 'second':\n case 'secs':\n case 'sec':\n case 's':\n return n * s;\n case 'milliseconds':\n case 'millisecond':\n case 'msecs':\n case 'msec':\n case 'ms':\n return n;\n default:\n return undefined;\n }\n}\n\n/**\n * Short format for `ms`.\n *\n * @param {Number} ms\n * @return {String}\n * @api private\n */\n\nfunction fmtShort(ms) {\n var msAbs = Math.abs(ms);\n if (msAbs >= d) {\n return Math.round(ms / d) + 'd';\n }\n if (msAbs >= h) {\n return Math.round(ms / h) + 'h';\n }\n if (msAbs >= m) {\n return Math.round(ms / m) + 'm';\n }\n if (msAbs >= s) {\n return Math.round(ms / s) + 's';\n }\n return ms + 'ms';\n}\n\n/**\n * Long format for `ms`.\n *\n * @param {Number} ms\n * @return {String}\n * @api private\n */\n\nfunction fmtLong(ms) {\n var msAbs = Math.abs(ms);\n if (msAbs >= d) {\n return plural(ms, msAbs, d, 'day');\n }\n if (msAbs >= h) {\n return plural(ms, msAbs, h, 'hour');\n }\n if (msAbs >= m) {\n return plural(ms, msAbs, m, 'minute');\n }\n if (msAbs >= s) {\n return plural(ms, msAbs, s, 'second');\n }\n return ms + ' ms';\n}\n\n/**\n * Pluralization helper.\n */\n\nfunction plural(ms, msAbs, n, name) {\n var isPlural = msAbs >= n * 1.5;\n return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');\n}\n", "import humanize from 'ms'\nimport {\n generateRandomString,\n coerce,\n selectColor,\n createRegexFromEnvVar\n} from '../common.js'\nimport { noop } from '../noop.js'\nimport { colors } from './util.js'\n\nconst log = console.log || (() => {})\n\nexport { createDebug }\nexport default createDebug\n\n/**\n * Check if the given namespace is enabled.\n * `namespace` is the name that is passed into debug.\n * `forcedEnabled` is a boolean that forces logging when true.\n * Only checks localStorage for the DEBUG key, unless forced.\n */\nfunction isEnabled (namespace:string, forcedEnabled?:boolean):boolean {\n // If explicitly forced to be enabled via boolean true\n if (forcedEnabled === true) return true\n\n const DEBUG = localStorage?.getItem('DEBUG')\n\n // Check for wildcard\n if (DEBUG === '*') return true\n\n // if we were not called with a namespace\n if (namespace === 'DEV') {\n // We want to log iff there is no DEBUG variable.\n if (!DEBUG) {\n return true\n }\n return false\n }\n\n // No DEBUG variable set\n if (!DEBUG) return false\n\n const envVars = createRegexFromEnvVar(DEBUG)\n return envVars.some(regex => regex.test(namespace))\n}\n\n/**\n * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.\n */\nfunction createFormatters () {\n return {\n j: function (v:any) {\n try {\n return JSON.stringify(v)\n } catch (error) {\n return '[UnexpectedJSONParseError]: ' + String(error)\n }\n }\n }\n}\n\nfunction logger (\n namespace:string,\n args:any[],\n { prevTime, color },\n forcedEnabled?:boolean\n) {\n args = args || []\n if (!isEnabled(namespace, forcedEnabled)) return\n\n // Set `diff` timestamp\n const curr = Number(new Date())\n const diff = curr - (prevTime || curr)\n prevTime = curr\n\n args[0] = coerce(args[0])\n const formatters = createFormatters()\n\n if (typeof args[0] !== 'string') {\n // Anything else let's inspect with %O\n args.unshift('%O')\n }\n\n // Apply any `formatters` transformations\n let index = 0\n args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {\n // If we encounter an escaped %, then don't increase the\n // array index\n if (match === '%%') return '%'\n\n index++\n\n const formatter = formatters[format]\n if (typeof formatter === 'function') {\n const val = args[index]\n match = formatter.call(self, val)\n\n // Now we need to remove `args[index]` since it's inlined\n // in the `format`\n args.splice(index, 1)\n index--\n }\n return match\n })\n\n // Apply env-specific formatting (colors, etc.)\n const _args = formatArgs({\n diff,\n color,\n useColors: shouldUseColors(),\n namespace\n }, args)\n\n log(..._args)\n}\n\nfunction shouldUseColors ():boolean {\n // Internet Explorer and Edge do not support colors.\n if (typeof navigator !== 'undefined' && navigator.userAgent &&\n navigator.userAgent.toLowerCase().match(/(edge|trident)\\/(\\d+)/)) {\n return false\n }\n\n // Is webkit? http://stackoverflow.com/a/16459606/376773\n // document is undefined in react-native:\n // https://github.com/facebook/react-native/pull/1632\n return !!((typeof document !== 'undefined' && document.documentElement &&\n document.documentElement.style &&\n document.documentElement.style.webkitAppearance) ||\n // Is firefox >= v31?\n // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages\n (typeof navigator !== 'undefined' &&\n navigator.userAgent &&\n navigator.userAgent.toLowerCase().match(/firefox\\/(\\d+)/) &&\n parseInt(RegExp.$1, 10) >= 31) ||\n // Double check webkit in userAgent just in case we are in a worker\n (typeof navigator !== 'undefined' &&\n navigator.userAgent &&\n navigator.userAgent.toLowerCase().match(/applewebkit\\/(\\d+)/)))\n}\n\n/**\n * Colorize log arguments if enabled.\n */\nfunction formatArgs ({ diff, color, namespace, useColors }:{\n diff:number,\n color:number,\n namespace:string,\n useColors:boolean\n}, args) {\n args[0] = (useColors ? '%c' : '') +\n namespace +\n (useColors ? ' %c' : ' ') +\n args[0] +\n (useColors ? '%c ' : ' ') +\n '+' + humanize(diff, {})\n\n if (!useColors) return\n\n const c = 'color: ' + color\n args.splice(1, 0, c, 'color: inherit')\n\n // The final \"%c\" is somewhat tricky, because there could be other\n // arguments passed either before or after the %c, so we need to\n // figure out the correct index to insert the CSS into\n let index = 0\n let lastC = 0\n args[0].replace(/%[a-zA-Z%]/g, match => {\n if (match === '%%') {\n return\n }\n index++\n if (match === '%c') {\n // We only are interested in the *last* %c\n // (the user may have provided their own)\n lastC = index\n }\n })\n\n args.splice(lastC, 0, c)\n\n return args\n}\n\nexport type Debugger = {\n (...args: any[]): void;\n extend: (namespace: string) => Debugger;\n}\n\nfunction createDebug (namespace?:string|boolean):Debugger {\n if (namespace === false) return noop\n const prevTime = Number(new Date())\n const color = selectColor(\n typeof namespace === 'string' ? namespace : generateRandomString(10),\n colors\n )\n\n // Determine if this is a boolean true passed as the namespace\n const forcedEnabled = namespace === true\n const actualNamespace = typeof namespace === 'string' ? namespace : 'DEV'\n\n const debug = function (...args:any[]) {\n return logger(\n actualNamespace,\n args,\n { prevTime, color },\n forcedEnabled\n )\n }\n\n debug.extend = function (extension: string): Debugger {\n const extendedNamespace = actualNamespace + ':' + extension\n return createDebug(extendedNamespace)\n }\n\n return debug as Debugger\n}\n", "/**\n* Coerce `val`.\n*\n* @param {unknown} val\n* @return {string}\n*/\nexport function coerce (val:unknown):string {\n if (val instanceof Error) {\n return val.stack || val.message\n }\n\n return String(val)\n}\n\n/**\n * Selects a color for a debug namespace\n * @param {string} namespace The namespace string for the debug instance to be colored\n * @return {number|string} An ANSI color code for the given namespace\n */\nexport function selectColor (\n namespace:string,\n colors:string[]|number[]\n):number|string {\n let hash = 0\n\n for (let i = 0; i < namespace.length; i++) {\n hash = ((hash << 5) - hash) + namespace.charCodeAt(i)\n hash |= 0 // Convert to 32bit integer\n }\n\n return colors[Math.abs(hash) % colors.length]\n}\n\nexport function createRegexFromEnvVar (names:string):RegExp[] {\n const split = names.split(/[\\s,]+/).filter(Boolean)\n const regexs = split\n .map(word => word.replace(/\\*/g, '.*?'))\n .map(r => new RegExp('^' + r + '$'))\n\n return regexs\n}\n\n/**\n * Use this to create a random namespace in the case that `debug`\n * is called without any arguments.\n * @param {number} length Lenght of the random string\n * @returns {string}\n */\nexport function generateRandomString (length = 6):string {\n return Math.random().toString(20).substring(2, length)\n}\n", "import { type Debugger } from './browser/index.js'\n\nexport const noop:Debugger = function (_args:any[]) {}\nnoop.extend = function (_namespace:string) { return noop }\n\n", "export const colors = [\n '#0000CC',\n '#0000FF',\n '#0033CC',\n '#0033FF',\n '#0066CC',\n '#0066FF',\n '#0099CC',\n '#0099FF',\n '#00CC00',\n '#00CC33',\n '#00CC66',\n '#00CC99',\n '#00CCCC',\n '#00CCFF',\n '#3300CC',\n '#3300FF',\n '#3333CC',\n '#3333FF',\n '#3366CC',\n '#3366FF',\n '#3399CC',\n '#3399FF',\n '#33CC00',\n '#33CC33',\n '#33CC66',\n '#33CC99',\n '#33CCCC',\n '#33CCFF',\n '#6600CC',\n '#6600FF',\n '#6633CC',\n '#6633FF',\n '#66CC00',\n '#66CC33',\n '#9900CC',\n '#9900FF',\n '#9933CC',\n '#9933FF',\n '#99CC00',\n '#99CC33',\n '#CC0000',\n '#CC0033',\n '#CC0066',\n '#CC0099',\n '#CC00CC',\n '#CC00FF',\n '#CC3300',\n '#CC3333',\n '#CC3366',\n '#CC3399',\n '#CC33CC',\n '#CC33FF',\n '#CC6600',\n '#CC6633',\n '#CC9900',\n '#CC9933',\n '#CCCC00',\n '#CCCC33',\n '#FF0000',\n '#FF0033',\n '#FF0066',\n '#FF0099',\n '#FF00CC',\n '#FF00FF',\n '#FF3300',\n '#FF3333',\n '#FF3366',\n '#FF3399',\n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X;AA3BS;",
6
+ "names": ["module", "colors", "humanize"]
7
+ }
@@ -1,5 +1,8 @@
1
1
  export { createDebug };
2
2
  export default createDebug;
3
- export type Debugger = (...args: any[]) => void;
3
+ export type Debugger = {
4
+ (...args: any[]): void;
5
+ extend: (namespace: string) => Debugger;
6
+ };
4
7
  declare function createDebug(namespace?: string | boolean): Debugger;
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,eAAe,WAAW,CAAA;AA2K1B,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAE/C,iBAAS,WAAW,CAAE,SAAS,CAAC,EAAC,MAAM,GAAC,OAAO,GAAE,QAAQ,CAsBxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,eAAe,WAAW,CAAA;AA2K1B,MAAM,MAAM,QAAQ,GAAG;IACnB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,QAAQ,CAAC;CAC3C,CAAA;AAED,iBAAS,WAAW,CAAE,SAAS,CAAC,EAAC,MAAM,GAAC,OAAO,GAAE,QAAQ,CA2BxD"}