@substrate-system/debug 0.9.20 → 0.9.22
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 +2 -2
- package/dist/browser/index.cjs +16 -256
- package/dist/browser/index.cjs.map +4 -4
- package/dist/browser/index.d.ts +2 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +13 -269
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/index.min.cjs +1 -1
- package/dist/browser/index.min.cjs.map +4 -4
- package/dist/browser/index.min.js +1 -1
- package/dist/browser/index.min.js.map +4 -4
- package/dist/browser/util.cjs +102 -0
- package/dist/browser/util.cjs.map +7 -0
- package/dist/browser/util.js +82 -0
- package/dist/browser/util.js.map +7 -0
- package/dist/browser/util.min.cjs +2 -0
- package/dist/browser/util.min.cjs.map +7 -0
- package/dist/browser/util.min.js +2 -0
- package/dist/browser/util.min.js.map +7 -0
- package/dist/cloudflare/index.cjs +28 -169
- package/dist/cloudflare/index.cjs.map +4 -4
- package/dist/cloudflare/index.d.ts +2 -1
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +14 -159
- package/dist/cloudflare/index.js.map +4 -4
- package/dist/cloudflare/index.min.cjs +1 -1
- package/dist/cloudflare/index.min.cjs.map +4 -4
- package/dist/cloudflare/index.min.js +1 -1
- package/dist/cloudflare/index.min.js.map +4 -4
- package/dist/index.cjs +54 -0
- package/dist/index.cjs.map +7 -0
- package/dist/{common.d.ts → index.d.ts} +1 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.cjs +2 -0
- package/dist/index.min.cjs.map +7 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +7 -0
- package/dist/ms.cjs +140 -0
- package/dist/ms.cjs.map +7 -0
- package/dist/ms.js +121 -0
- package/dist/ms.js.map +7 -0
- package/dist/ms.min.cjs +2 -0
- package/dist/ms.min.cjs.map +7 -0
- package/dist/ms.min.js +2 -0
- package/dist/ms.min.js.map +7 -0
- package/dist/node/index.cjs +22 -155
- package/dist/node/index.cjs.map +4 -4
- package/dist/{node.d.ts → node/index.d.ts} +2 -2
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +17 -148
- package/dist/node/index.js.map +3 -3
- package/dist/node/index.min.cjs +4 -4
- package/dist/node/index.min.cjs.map +4 -4
- package/dist/node/index.min.js +4 -4
- package/dist/node/index.min.js.map +4 -4
- package/dist/noop.cjs +30 -0
- package/dist/noop.cjs.map +7 -0
- package/dist/noop.d.ts +1 -1
- package/dist/noop.d.ts.map +1 -1
- package/dist/noop.js +11 -0
- package/dist/noop.js.map +7 -0
- package/dist/noop.min.cjs +2 -0
- package/dist/noop.min.cjs.map +7 -0
- package/dist/noop.min.js +2 -0
- package/dist/noop.min.js.map +7 -0
- package/package.json +11 -8
- package/dist/common.d.ts.map +0 -1
- package/dist/meta.json +0 -116
- package/dist/node.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# debug
|
|
2
2
|
[](https://github.com/substrate-system/debug/actions/workflows/nodejs.yml)
|
|
3
|
-
[](README.md)
|
|
3
|
+
[](README.md)
|
|
4
4
|
[](README.md)
|
|
5
5
|
[](https://semver.org/)
|
|
6
6
|
[](https://packagephobia.com/result?p=@substrate-system/debug)
|
|
@@ -24,7 +24,7 @@ In Node.js, it uses the environment variable `DEBUG`.
|
|
|
24
24
|
**Featuring:**
|
|
25
25
|
* Use [exports](https://github.com/substrate-system/debug/blob/main/package.json#L31)
|
|
26
26
|
field in `package.json` to choose node JS, browser, or cloudflare version
|
|
27
|
-
* ESM
|
|
27
|
+
* ESM or common JS
|
|
28
28
|
|
|
29
29
|
Plus, [see the docs](https://substrate-system.github.io/debug/)
|
|
30
30
|
generated by typescript.
|
package/dist/browser/index.cjs
CHANGED
|
@@ -6,9 +6,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
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
9
|
var __export = (target, all) => {
|
|
13
10
|
for (var name in all)
|
|
14
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,256 +27,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
27
|
mod
|
|
31
28
|
));
|
|
32
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
-
|
|
34
|
-
|
|
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, {
|
|
30
|
+
var browser_exports = {};
|
|
31
|
+
__export(browser_exports, {
|
|
158
32
|
createDebug: () => createDebug,
|
|
159
|
-
default: () =>
|
|
33
|
+
default: () => browser_default
|
|
160
34
|
});
|
|
161
|
-
module.exports = __toCommonJS(
|
|
162
|
-
var import_ms = __toESM(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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 || (() => {
|
|
35
|
+
module.exports = __toCommonJS(browser_exports);
|
|
36
|
+
var import_ms = __toESM(require("ms"), 1);
|
|
37
|
+
var import__ = require("../index.js");
|
|
38
|
+
var import_noop = require("../noop.js");
|
|
39
|
+
var import_util = require("./util.js");
|
|
40
|
+
const log = console.log || (() => {
|
|
281
41
|
});
|
|
282
|
-
var
|
|
42
|
+
var browser_default = createDebug;
|
|
283
43
|
function isEnabled(namespace, forcedEnabled) {
|
|
284
44
|
if (forcedEnabled === true) return true;
|
|
285
45
|
const DEBUG = localStorage?.getItem("DEBUG");
|
|
@@ -291,7 +51,7 @@ function isEnabled(namespace, forcedEnabled) {
|
|
|
291
51
|
return false;
|
|
292
52
|
}
|
|
293
53
|
if (!DEBUG) return false;
|
|
294
|
-
const envVars = createRegexFromEnvVar(DEBUG);
|
|
54
|
+
const envVars = (0, import__.createRegexFromEnvVar)(DEBUG);
|
|
295
55
|
return envVars.some((regex) => regex.test(namespace));
|
|
296
56
|
}
|
|
297
57
|
__name(isEnabled, "isEnabled");
|
|
@@ -313,7 +73,7 @@ function logger(namespace, args, { prevTime, color }, forcedEnabled) {
|
|
|
313
73
|
const curr = Number(/* @__PURE__ */ new Date());
|
|
314
74
|
const diff = curr - (prevTime || curr);
|
|
315
75
|
prevTime = curr;
|
|
316
|
-
args[0] = coerce(args[0]);
|
|
76
|
+
args[0] = (0, import__.coerce)(args[0]);
|
|
317
77
|
const formatters = createFormatters();
|
|
318
78
|
if (typeof args[0] !== "string") {
|
|
319
79
|
args.unshift("%O");
|
|
@@ -371,11 +131,11 @@ function formatArgs({ diff, color, namespace, useColors }, args) {
|
|
|
371
131
|
}
|
|
372
132
|
__name(formatArgs, "formatArgs");
|
|
373
133
|
function createDebug(namespace) {
|
|
374
|
-
if (namespace === false) return noop;
|
|
134
|
+
if (namespace === false) return import_noop.noop;
|
|
375
135
|
const prevTime = Number(/* @__PURE__ */ new Date());
|
|
376
|
-
const color = selectColor(
|
|
377
|
-
typeof namespace === "string" ? namespace : generateRandomString(10),
|
|
378
|
-
colors
|
|
136
|
+
const color = (0, import__.selectColor)(
|
|
137
|
+
typeof namespace === "string" ? namespace : (0, import__.generateRandomString)(10),
|
|
138
|
+
import_util.colors
|
|
379
139
|
);
|
|
380
140
|
const forcedEnabled = namespace === true;
|
|
381
141
|
const actualNamespace = typeof namespace === "string" ? namespace : "DEV";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../
|
|
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 type Debugger\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\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\nexport type Debugger = {\n (...args: any[]): void;\n extend: (namespace: string) => Debugger;\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 './common.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 '#FF33CC',\n '#FF33FF',\n '#FF6600',\n '#FF6633',\n '#FF9900',\n '#FF9933',\n '#FFCC00',\n '#FFCC33'\n]\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../src/browser/index.ts"],
|
|
4
|
+
"sourcesContent": ["import humanize from 'ms'\nimport {\n generateRandomString,\n coerce,\n selectColor,\n createRegexFromEnvVar,\n type Debugger\n} from '../index.js'\nimport { noop } from '../noop.js'\nimport { colors } from './util.js'\n\nconst log = console.log || (() => {})\n\nexport { Debugger }\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\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"],
|
|
5
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C,QAAI,UAAU,MAAM;AAChB;AAAA,IACJ;AACA;AACA,QAAI,UAAU,MAAM;AAGhB,cAAQ;AAAA,IACZ;AAAA,EACJ,CAAC;AAED,OAAK,OAAO,OAAO,GAAG,CAAC;AAEvB,SAAO;AACX;AAtCS;AAwCT,SAAS,YAAa,WAAoC;AACtD,MAAI,cAAc,MAAO,QAAO;AAChC,QAAM,WAAW,OAAO,oBAAI,KAAK,CAAC;AAClC,QAAM,YAAQ;AAAA,IACV,OAAO,cAAc,WAAW,gBAAY,+BAAqB,EAAE;AAAA,IACnE;AAAA,EACJ;AAGA,QAAM,gBAAgB,cAAc;AACpC,QAAM,kBAAkB,OAAO,cAAc,WAAW,YAAY;AAEpE,QAAM,QAAQ,mCAAa,MAAY;AACnC,WAAO;AAAA,MACH;AAAA,MACA;AAAA,MACA,EAAE,UAAU,MAAM;AAAA,MAClB;AAAA,IACJ;AAAA,EACJ,GAPc;AASd,QAAM,SAAS,SAAU,WAA6B;AAClD,UAAM,oBAAoB,kBAAkB,MAAM;AAClD,WAAO,YAAY,iBAAiB;AAAA,EACxC;AAEA,SAAO;AACX;AA3BS;",
|
|
6
|
+
"names": ["humanize"]
|
|
7
7
|
}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AACA,OAAO,EAKH,KAAK,QAAQ,EAChB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AACA,OAAO,EAKH,KAAK,QAAQ,EAChB,MAAM,aAAa,CAAA;AAMpB,OAAO,EAAE,QAAQ,EAAE,CAAA;AACnB,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,eAAe,WAAW,CAAA;AA2K1B,iBAAS,WAAW,CAAE,SAAS,CAAC,EAAC,MAAM,GAAC,OAAO,GAAE,QAAQ,CA2BxD"}
|