@substrate-system/debug 0.7.2

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 ADDED
@@ -0,0 +1,20 @@
1
+ THE MIT LICENSE (MIT)
2
+
3
+ Copyright © 2023 Nick Thomas <nichoth@nichoth.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the “Software”), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # debug
2
+ ![tests](https://github.com/substrate-system/debug/actions/workflows/nodejs.yml/badge.svg)
3
+ [![module](https://img.shields.io/badge/module-ESM-blue?style=flat-square)](README.md)
4
+ [![types](https://img.shields.io/npm/types/@substrate-system/debug?style=flat-square)](README.md)
5
+ [![semantic versioning](https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&style=flat-square)](https://semver.org/)
6
+ [![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/debug)](https://packagephobia.com/result?p=@substrate-system/debug)
7
+ [![license](https://img.shields.io/badge/license-MIT-brightgreen?style=flat-square)](LICENSE)
8
+
9
+ A tiny JavaScript debugging utility that works in Node.js and browsers. Use environment variables to control logging, so there are no ridiculous console log statements in production.
10
+
11
+ This is based on [debug](https://github.com/debug-js/debug). It's been rewritten to use contemporary JS.
12
+
13
+ **Featuring:**
14
+ * Use [exports](https://github.com/substrate-system/debug/blob/main/package.json#L31) field in `package.json` to choose node JS or browser version
15
+ * ESM only
16
+
17
+ Plus, [see the docs](https://substrate-system.github.io/debug/) generated by typescript.
18
+
19
+ ## Contents
20
+
21
+ <!-- toc -->
22
+
23
+ - [install](#install)
24
+ - [example](#example)
25
+ * [browser](#browser)
26
+ * [node JS](#node-js)
27
+ - [develop](#develop)
28
+ * [browser](#browser-1)
29
+ * [node](#node)
30
+
31
+ <!-- tocstop -->
32
+
33
+ ## install
34
+
35
+ ```sh
36
+ npm i -D @substrate-system/debug
37
+ ```
38
+
39
+ Use this with [vite](https://vitejs.dev/) in the [browser](#browser) or
40
+ in [node](#node-JS).
41
+
42
+ ------------------------------------------------------------------
43
+
44
+ ## example
45
+
46
+ ### browser
47
+ This is ergonomic with the [vite](https://vitejs.dev/) bundler. This module will look for an env variable prefixed with `VITE_`:
48
+ ```sh
49
+ VITE_DEBUG=fooo
50
+ ```
51
+
52
+ If you initialize this without a namespace, then it checks `import.meta.env.DEV`:
53
+ ```js
54
+ import Debug from '@substrate-system/debug'
55
+ const debug = Debug()
56
+ debug('debug works') // check if `import.meta.env.DEV`
57
+ ```
58
+
59
+ #### a third config option
60
+ You can pass in an env variable of `VITE_DEBUG_MODE`, and then `debug` will
61
+ check for that mode in vite.
62
+
63
+ ##### For example, in the staging environment:
64
+
65
+ ```sh
66
+ VITE_DEBUG_MODE=staging vite build --mode staging
67
+ ```
68
+
69
+ ##### use multiple modes
70
+ Can parse a comma separated list of modes.
71
+
72
+ A `.env` file like this:
73
+ ```sh
74
+ VITE_DEBUG_MODE="test, staging"
75
+ ```
76
+
77
+ Will log in either "test" or "staging" modes, or if `import.meta.env.DEV` is true.
78
+
79
+ ```sh
80
+ vite --mode staging build
81
+ ```
82
+
83
+ **If you are in production** (`import.meta.env.PROD`) and there is no `VITE_DEBUG` env var, then this exports a noop, so debug will do nothing, and your bundle will be smaller.
84
+
85
+ #### Use a namespace
86
+ In your JS code:
87
+ ```js
88
+ import { createDebug } from '@substrate-system/debug'
89
+ const debug = createDebug('fooo')
90
+ debug('debug works')
91
+ ```
92
+
93
+ You would start that script with a `VITE_DEBUG=fooo` env var to see the log statements.
94
+
95
+ #### Don't use a namespace
96
+ If you call this without a `namespace` argument, it will look at the value of `import.meta.env.DEV`. If you are in DEV mode, then it will log things in a random color:
97
+
98
+ ```js
99
+ import { createDebug } from '@substrate-system/debug'
100
+ const debug = createDebug('fooo')
101
+ const debug2 = createDebug()
102
+
103
+ debug('debug works')
104
+ debug2('testing debug 2')
105
+ setTimeout(() => {
106
+ debug2('log again')
107
+ }, 1000)
108
+ ```
109
+
110
+ ![Screenshot of `debug` in a browser](screenshot2.png)
111
+
112
+
113
+ ### node JS
114
+ Run your script with an env variable, `DEBUG`.
115
+
116
+ ```js
117
+ // in node JS
118
+ import createDebug from '@substrate-system/debug/node'
119
+ const debug = createDebug('fooo')
120
+ debug('testing')
121
+ ```
122
+
123
+ Call this with an env var of `DEBUG=fooo`
124
+ ```sh
125
+ DEBUG=fooo node ./test/fixture/node.js
126
+ ```
127
+
128
+ #### NODE_ENV
129
+ If you are in dev mode (`process.env.NODE_ENV === 'development'`), then this will log things in a random color if you don't initialize it with a namespace --
130
+
131
+ ```js
132
+ import createDebug from '@substrate-system/debug'
133
+ const debug = createDebug()
134
+ debug('hello')
135
+ ```
136
+
137
+ Run the script like this:
138
+ ```sh
139
+ NODE_ENV=development node ./my-script.js
140
+ ```
141
+
142
+ ##### Configure the environment value
143
+ Configure what `NODE_ENV` value will trigger logging by overriding the `shoudlLog` function:
144
+ ```js
145
+ // in node only
146
+ import Debug from '@substrate-system/debug'
147
+
148
+ Debug.shouldLog = function (NODE_ENV) {
149
+ return NODE_ENV === 'example'
150
+ }
151
+ const debug = Debug()
152
+ // this will log iff we start this like
153
+ // NODE_ENV="example" node my-program.js
154
+ debug('testing')
155
+ ```
156
+
157
+ -------------------------------------------------------------------
158
+
159
+ ## develop
160
+
161
+ ### browser
162
+ Start a `vite` server and log some things. This uses [the example directory](./example/).
163
+
164
+ ```sh
165
+ npm start
166
+ ```
167
+
168
+ ### node
169
+ Run tests:
170
+
171
+ ```sh
172
+ npm test
173
+ ```
@@ -0,0 +1,4 @@
1
+ declare let createDebug: (_?: string) => (..._args: any[]) => void;
2
+ export { createDebug };
3
+ export default createDebug;
4
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AA0FA,QAAA,IAAI,WAAW,OAAO,MAAM,gBAAe,GAAG,EAAE,SAAO,CAAA;AAqCvD,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,eAAe,WAAW,CAAA"}
@@ -0,0 +1,249 @@
1
+ import { generateRandomString, coerce, selectColor, createRegexFromEnvVar } from './common.js';
2
+ import humanize from 'ms';
3
+ const colors = [
4
+ '#0000CC',
5
+ '#0000FF',
6
+ '#0033CC',
7
+ '#0033FF',
8
+ '#0066CC',
9
+ '#0066FF',
10
+ '#0099CC',
11
+ '#0099FF',
12
+ '#00CC00',
13
+ '#00CC33',
14
+ '#00CC66',
15
+ '#00CC99',
16
+ '#00CCCC',
17
+ '#00CCFF',
18
+ '#3300CC',
19
+ '#3300FF',
20
+ '#3333CC',
21
+ '#3333FF',
22
+ '#3366CC',
23
+ '#3366FF',
24
+ '#3399CC',
25
+ '#3399FF',
26
+ '#33CC00',
27
+ '#33CC33',
28
+ '#33CC66',
29
+ '#33CC99',
30
+ '#33CCCC',
31
+ '#33CCFF',
32
+ '#6600CC',
33
+ '#6600FF',
34
+ '#6633CC',
35
+ '#6633FF',
36
+ '#66CC00',
37
+ '#66CC33',
38
+ '#9900CC',
39
+ '#9900FF',
40
+ '#9933CC',
41
+ '#9933FF',
42
+ '#99CC00',
43
+ '#99CC33',
44
+ '#CC0000',
45
+ '#CC0033',
46
+ '#CC0066',
47
+ '#CC0099',
48
+ '#CC00CC',
49
+ '#CC00FF',
50
+ '#CC3300',
51
+ '#CC3333',
52
+ '#CC3366',
53
+ '#CC3399',
54
+ '#CC33CC',
55
+ '#CC33FF',
56
+ '#CC6600',
57
+ '#CC6633',
58
+ '#CC9900',
59
+ '#CC9933',
60
+ '#CCCC00',
61
+ '#CCCC33',
62
+ '#FF0000',
63
+ '#FF0033',
64
+ '#FF0066',
65
+ '#FF0099',
66
+ '#FF00CC',
67
+ '#FF00FF',
68
+ '#FF3300',
69
+ '#FF3333',
70
+ '#FF3366',
71
+ '#FF3399',
72
+ '#FF33CC',
73
+ '#FF33FF',
74
+ '#FF6600',
75
+ '#FF6633',
76
+ '#FF9900',
77
+ '#FF9933',
78
+ '#FFCC00',
79
+ '#FFCC33'
80
+ ];
81
+ const log = console.log || (() => { });
82
+ let randomNamespace = '';
83
+ let createDebug = (_) => (..._args) => { };
84
+ const modeVar = import.meta?.env?.VITE_DEBUG_MODE || '';
85
+ let modes = [];
86
+ if (modeVar) {
87
+ modes = (modeVar.split(',')).map(mode => mode.trim());
88
+ }
89
+ if (import.meta?.env?.DEV ||
90
+ import.meta?.env?.VITE_DEBUG ||
91
+ (modes.length && modes.includes(import.meta.env.MODE))) {
92
+ /**
93
+ * Create a debugger with the given `namespace`, only
94
+ * if we are in DEV mode.
95
+ *
96
+ * @param {string?} namespace
97
+ * @return {Function}
98
+ */
99
+ createDebug = function createDebug(namespace) {
100
+ const prevTime = Number(new Date());
101
+ if (!randomNamespace) {
102
+ randomNamespace = generateRandomString(10);
103
+ }
104
+ const color = selectColor(namespace || randomNamespace, colors);
105
+ const debug = function (...args) {
106
+ if (isEnabled(namespace)) {
107
+ return logger(namespace || 'DEV', args, { prevTime, color });
108
+ }
109
+ };
110
+ return debug;
111
+ };
112
+ }
113
+ export { createDebug };
114
+ export default createDebug;
115
+ /**
116
+ * Check if the given namespace is enabled.
117
+ */
118
+ function isEnabled(namespace) {
119
+ // if no namespace,
120
+ // and we are in vite DEV mode
121
+ if (namespace === undefined) {
122
+ if (import.meta && import.meta.env?.DEV) {
123
+ return true;
124
+ }
125
+ if (import.meta.env?.VITE_DEBUG_MODE) {
126
+ if (import.meta && import.meta.env &&
127
+ import.meta.env.MODE === import.meta.env.VITE_DEBUG_MODE) {
128
+ return true;
129
+ }
130
+ }
131
+ }
132
+ if (!namespace)
133
+ return false;
134
+ if (!import.meta.env || !import.meta.env.VITE_DEBUG)
135
+ return false;
136
+ const envVars = createRegexFromEnvVar(import.meta.env?.VITE_DEBUG);
137
+ return envVars.some(regex => regex.test(namespace));
138
+ }
139
+ /**
140
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
141
+ */
142
+ function createFormatters() {
143
+ return {
144
+ j: function (v) {
145
+ try {
146
+ return JSON.stringify(v);
147
+ }
148
+ catch (error) {
149
+ return '[UnexpectedJSONParseError]: ' + String(error);
150
+ }
151
+ }
152
+ };
153
+ }
154
+ function logger(namespace, args, { prevTime, color }) {
155
+ // Set `diff` timestamp
156
+ const curr = Number(new Date());
157
+ const diff = curr - (prevTime || curr);
158
+ prevTime = curr;
159
+ args[0] = coerce(args[0]);
160
+ const formatters = createFormatters();
161
+ if (typeof args[0] !== 'string') {
162
+ // Anything else let's inspect with %O
163
+ args.unshift('%O');
164
+ }
165
+ // Apply any `formatters` transformations
166
+ let index = 0;
167
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
168
+ // If we encounter an escaped %, then don't increase the
169
+ // array index
170
+ if (match === '%%')
171
+ return '%';
172
+ index++;
173
+ const formatter = formatters[format];
174
+ if (typeof formatter === 'function') {
175
+ const val = args[index];
176
+ match = formatter.call(self, val);
177
+ // Now we need to remove `args[index]` since it's inlined
178
+ // in the `format`
179
+ args.splice(index, 1);
180
+ index--;
181
+ }
182
+ return match;
183
+ });
184
+ // Apply env-specific formatting (colors, etc.)
185
+ const _args = formatArgs({
186
+ diff,
187
+ color,
188
+ useColors: shouldUseColors(),
189
+ namespace
190
+ }, args);
191
+ log(..._args);
192
+ }
193
+ function shouldUseColors() {
194
+ // Internet Explorer and Edge do not support colors.
195
+ if (typeof navigator !== 'undefined' && navigator.userAgent &&
196
+ navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
197
+ return false;
198
+ }
199
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
200
+ // document is undefined in react-native:
201
+ // https://github.com/facebook/react-native/pull/1632
202
+ return !!((typeof document !== 'undefined' && document.documentElement &&
203
+ document.documentElement.style &&
204
+ document.documentElement.style.webkitAppearance) ||
205
+ // Is firefox >= v31?
206
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
207
+ (typeof navigator !== 'undefined' &&
208
+ navigator.userAgent &&
209
+ navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) &&
210
+ parseInt(RegExp.$1, 10) >= 31) ||
211
+ // Double check webkit in userAgent just in case we are in a worker
212
+ (typeof navigator !== 'undefined' &&
213
+ navigator.userAgent &&
214
+ navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)));
215
+ }
216
+ /**
217
+ * Colorize log arguments if enabled.
218
+ */
219
+ function formatArgs({ diff, color, namespace, useColors }, args) {
220
+ args[0] = (useColors ? '%c' : '') +
221
+ namespace +
222
+ (useColors ? ' %c' : ' ') +
223
+ args[0] +
224
+ (useColors ? '%c ' : ' ') +
225
+ '+' + humanize(diff);
226
+ if (!useColors)
227
+ return;
228
+ const c = 'color: ' + color;
229
+ args.splice(1, 0, c, 'color: inherit');
230
+ // The final "%c" is somewhat tricky, because there could be other
231
+ // arguments passed either before or after the %c, so we need to
232
+ // figure out the correct index to insert the CSS into
233
+ let index = 0;
234
+ let lastC = 0;
235
+ args[0].replace(/%[a-zA-Z%]/g, match => {
236
+ if (match === '%%') {
237
+ return;
238
+ }
239
+ index++;
240
+ if (match === '%c') {
241
+ // We only are interested in the *last* %c
242
+ // (the user may have provided their own)
243
+ lastC = index;
244
+ }
245
+ });
246
+ args.splice(lastC, 0, c);
247
+ return args;
248
+ }
249
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,oBAAoB,EACpB,MAAM,EACN,WAAW,EACX,qBAAqB,EACxB,MAAM,aAAa,CAAA;AACpB,OAAO,QAAQ,MAAM,IAAI,CAAA;AAEzB,MAAM,MAAM,GAAG;IACX,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IAC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7
+ export declare function coerce(val: unknown): string;
8
+ /**
9
+ * Selects a color for a debug namespace
10
+ * @param {string} namespace The namespace string for the debug instance to be colored
11
+ * @return {number|string} An ANSI color code for the given namespace
12
+ */
13
+ export declare function selectColor(namespace: string, colors: string[] | number[]): number | string;
14
+ export declare function createRegexFromEnvVar(names: string): RegExp[];
15
+ /**
16
+ * Use this to create a random namespace in the case that `debug`
17
+ * is called without any arguments.
18
+ * @param {number} length Lenght of the random string
19
+ * @returns {string}
20
+ */
21
+ export declare function generateRandomString(length?: number): string;
22
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AACF,wBAAgB,MAAM,CAAE,GAAG,EAAC,OAAO,GAAE,MAAM,CAM1C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACvB,SAAS,EAAC,MAAM,EAChB,MAAM,EAAC,MAAM,EAAE,GAAC,MAAM,EAAE,GAC1B,MAAM,GAAC,MAAM,CASd;AAED,wBAAgB,qBAAqB,CAAE,KAAK,EAAC,MAAM,GAAE,MAAM,EAAE,CAO5D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAE,MAAM,SAAI,GAAE,MAAM,CAEvD"}
package/dist/common.js ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Coerce `val`.
3
+ *
4
+ * @param {unknown} val
5
+ * @return {string}
6
+ */
7
+ export function coerce(val) {
8
+ if (val instanceof Error) {
9
+ return val.stack || val.message;
10
+ }
11
+ return String(val);
12
+ }
13
+ /**
14
+ * Selects a color for a debug namespace
15
+ * @param {string} namespace The namespace string for the debug instance to be colored
16
+ * @return {number|string} An ANSI color code for the given namespace
17
+ */
18
+ export function selectColor(namespace, colors) {
19
+ let hash = 0;
20
+ for (let i = 0; i < namespace.length; i++) {
21
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
22
+ hash |= 0; // Convert to 32bit integer
23
+ }
24
+ return colors[Math.abs(hash) % colors.length];
25
+ }
26
+ export function createRegexFromEnvVar(names) {
27
+ const split = names.split(/[\s,]+/).filter(Boolean);
28
+ const regexs = split
29
+ .map(word => word.replace(/\*/g, '.*?'))
30
+ .map(r => new RegExp('^' + r + '$'));
31
+ return regexs;
32
+ }
33
+ /**
34
+ * Use this to create a random namespace in the case that `debug`
35
+ * is called without any arguments.
36
+ * @param {number} length Lenght of the random string
37
+ * @returns {string}
38
+ */
39
+ export function generateRandomString(length = 6) {
40
+ return Math.random().toString(20).substring(2, length);
41
+ }
42
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AACF,MAAM,UAAU,MAAM,CAAE,GAAW;IAC/B,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAA;IACnC,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACvB,SAAgB,EAChB,MAAwB;IAExB,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACrD,IAAI,IAAI,CAAC,CAAA,CAAE,2BAA2B;IAC1C,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAE,KAAY;IAC/C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACnD,MAAM,MAAM,GAAG,KAAK;SACf,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;SACvC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IAExC,OAAO,MAAM,CAAA;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAE,MAAM,GAAG,CAAC;IAC5C,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC1D,CAAC"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Create a debugger with the given `namespace`.
3
+ *
4
+ * @param {string} namespace
5
+ * @return {Function}
6
+ */
7
+ export declare function createDebug(namespace?: string | null, env?: Record<string, any>): (...args: any[]) => void;
8
+ export declare namespace createDebug {
9
+ var shouldLog: (envString: string) => boolean | "";
10
+ }
11
+ export default createDebug;
12
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAkIA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAE,SAAS,CAAC,EAAC,MAAM,GAAC,IAAI,EAAE,GAAG,CAAC,EAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,aAOjD,GAAG,EAAE,UAOhC;yBAde,WAAW;+BAgBiB,MAAM;;AAIlD,eAAe,WAAW,CAAA"}
package/dist/node.js ADDED
@@ -0,0 +1,233 @@
1
+ import supportsColor from 'supports-color';
2
+ import ms from 'ms';
3
+ import tty from 'tty';
4
+ import util from 'util';
5
+ import { generateRandomString, coerce, createRegexFromEnvVar } from './common.js';
6
+ const colors = (supportsColor &&
7
+ // @ts-expect-error ???
8
+ (supportsColor.stderr || supportsColor).level >= 2) ? ([
9
+ 20,
10
+ 21,
11
+ 26,
12
+ 27,
13
+ 32,
14
+ 33,
15
+ 38,
16
+ 39,
17
+ 40,
18
+ 41,
19
+ 42,
20
+ 43,
21
+ 44,
22
+ 45,
23
+ 56,
24
+ 57,
25
+ 62,
26
+ 63,
27
+ 68,
28
+ 69,
29
+ 74,
30
+ 75,
31
+ 76,
32
+ 77,
33
+ 78,
34
+ 79,
35
+ 80,
36
+ 81,
37
+ 92,
38
+ 93,
39
+ 98,
40
+ 99,
41
+ 112,
42
+ 113,
43
+ 128,
44
+ 129,
45
+ 134,
46
+ 135,
47
+ 148,
48
+ 149,
49
+ 160,
50
+ 161,
51
+ 162,
52
+ 163,
53
+ 164,
54
+ 165,
55
+ 166,
56
+ 167,
57
+ 168,
58
+ 169,
59
+ 170,
60
+ 171,
61
+ 172,
62
+ 173,
63
+ 178,
64
+ 179,
65
+ 184,
66
+ 185,
67
+ 196,
68
+ 197,
69
+ 198,
70
+ 199,
71
+ 200,
72
+ 201,
73
+ 202,
74
+ 203,
75
+ 204,
76
+ 205,
77
+ 206,
78
+ 207,
79
+ 208,
80
+ 209,
81
+ 214,
82
+ 215,
83
+ 220,
84
+ 221
85
+ ]) :
86
+ ([6, 2, 3, 4, 5, 1]);
87
+ /**
88
+ * Is stdout a TTY? Colored output is enabled when `true`.
89
+ */
90
+ function shouldUseColors() {
91
+ return tty.isatty(process.stderr.fd);
92
+ }
93
+ function getDate() {
94
+ return new Date().toISOString();
95
+ }
96
+ /**
97
+ * Invokes `util.format()` with the specified arguments and writes to stderr.
98
+ */
99
+ function log(...args) {
100
+ return process.stderr.write(util.format(...args) + '\n');
101
+ }
102
+ /**
103
+ * Mutate formatters
104
+ * Map %o to `util.inspect()`, all on a single line.
105
+ */
106
+ function createFormatters(useColors, inspectOpts = {}) {
107
+ return {
108
+ o: function (v) {
109
+ return util.inspect(v, Object.assign({}, inspectOpts, {
110
+ colors: useColors
111
+ }))
112
+ .split('\n')
113
+ .map(str => str.trim())
114
+ .join(' ');
115
+ },
116
+ O: function (v) {
117
+ return util.inspect(v, Object.assign({}, inspectOpts, {
118
+ colors: shouldUseColors()
119
+ }));
120
+ }
121
+ };
122
+ }
123
+ let randomNamespace = '';
124
+ /**
125
+ * Create a debugger with the given `namespace`.
126
+ *
127
+ * @param {string} namespace
128
+ * @return {Function}
129
+ */
130
+ export function createDebug(namespace, env) {
131
+ // eslint-disable-next-line
132
+ let prevTime = Number(new Date());
133
+ if (!randomNamespace)
134
+ randomNamespace = generateRandomString(10);
135
+ const _namespace = namespace || randomNamespace;
136
+ const color = selectColor(_namespace, colors);
137
+ function debug(...args) {
138
+ if (isEnabled(namespace, env)) {
139
+ return logger(namespace || 'DEV', args, { prevTime, color });
140
+ }
141
+ }
142
+ return debug;
143
+ }
144
+ createDebug.shouldLog = function (envString) {
145
+ return (envString && (envString === 'development' || envString === 'test'));
146
+ };
147
+ export default createDebug;
148
+ function logger(namespace, args, { prevTime, color }) {
149
+ // Set `diff` timestamp
150
+ const curr = Number(new Date());
151
+ const diff = curr - (prevTime || curr);
152
+ prevTime = curr;
153
+ args[0] = coerce(args[0]);
154
+ const formatters = createFormatters(shouldUseColors());
155
+ if (typeof args[0] !== 'string') {
156
+ // Anything else let's inspect with %O
157
+ args.unshift('%O');
158
+ }
159
+ // Apply any `formatters` transformations
160
+ let index = 0;
161
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
162
+ // If we encounter an escaped % then don't increase the
163
+ // array index
164
+ if (match === '%%')
165
+ return '%';
166
+ index++;
167
+ const formatter = formatters[format];
168
+ if (typeof formatter === 'function') {
169
+ const val = args[index];
170
+ match = formatter.call(self, val);
171
+ // Now we need to remove `args[index]` since it's inlined
172
+ // in the `format`
173
+ args.splice(index, 1);
174
+ index--;
175
+ }
176
+ return match;
177
+ });
178
+ // Apply env-specific formatting (colors, etc.)
179
+ const _args = formatArgs({
180
+ diff,
181
+ color,
182
+ useColors: shouldUseColors(),
183
+ namespace
184
+ }, args);
185
+ log(..._args);
186
+ }
187
+ /**
188
+ * Check if the given namespace is enabled.
189
+ */
190
+ function isEnabled(namespace, _env) {
191
+ const env = _env || process.env;
192
+ // if no namespace, and we are in dev mode
193
+ if (!namespace) {
194
+ return !!createDebug.shouldLog(env.NODE_ENV);
195
+ }
196
+ if (!namespace)
197
+ return false;
198
+ if (!env.DEBUG)
199
+ return false;
200
+ const envVars = createRegexFromEnvVar(env.DEBUG);
201
+ return envVars.some(regex => regex.test(namespace));
202
+ }
203
+ /**
204
+ * Adds ANSI color escape codes if enabled.
205
+ */
206
+ function formatArgs({ diff, color, namespace, useColors }, args) {
207
+ if (useColors) {
208
+ const c = color;
209
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
210
+ const prefix = ` ${colorCode};1m${namespace} \u001B[0m`;
211
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
212
+ args.push(colorCode + 'm+' + ms(diff) + '\u001B[0m');
213
+ }
214
+ else {
215
+ args[0] = getDate() + ' ' + namespace + ' ' + args[0];
216
+ }
217
+ return args;
218
+ }
219
+ /**
220
+ * Selects a color for a debug namespace
221
+ * @param {string} namespace The namespace string for the debug instance to be colored
222
+ * @param {number[]} colors The namespace string for the debug instance to be colored
223
+ * @return {number} An ANSI color code for the given namespace
224
+ */
225
+ function selectColor(namespace, colors) {
226
+ let hash = 0;
227
+ for (let i = 0; i < namespace.length; i++) {
228
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
229
+ hash |= 0; // Convert to 32bit integer
230
+ }
231
+ return colors[Math.abs(hash) % colors.length];
232
+ }
233
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,gBAAgB,CAAA;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AAI,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACrD,IAAI,IAAI,CAAC,CAAA,CAAE,2BAA2B;IAC1C,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AACjD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@substrate-system/debug",
3
+ "description": "Debug utility",
4
+ "type": "module",
5
+ "version": "0.7.2",
6
+ "main": "./dist/node.js",
7
+ "files": [
8
+ "./dist/*"
9
+ ],
10
+ "scripts": {
11
+ "lint": "eslint \"./**/*.{ts,js}\"",
12
+ "build-tests": "esbuild test/index.ts --platform=node --bundle --format=esm --keep-names > test/index.js",
13
+ "test-node": "esbuild ./example/node.js --platform=node --bundle --format=esm --keep-names | node --input-type=module",
14
+ "test": "npm run lint && npm run build && esbuild test/index.ts --target=es2020 --bundle --platform=node --format=esm | DEBUG=test NODE_ENV=development node --input-type=module",
15
+ "build-browser-tests": "esbuild test/index.ts --platform=node --target=es2020 --bundle --keep-names > test/test-bundle.js",
16
+ "test-tape-run": "npm run build-browser-tests && cat test/index.html | tape-run --input=html --static=test | tap-spec",
17
+ "build": "mkdir -p dist && rm -rf dist/* && tsc --project tsconfig.build.json",
18
+ "build-docs": "typedoc ./src/browser.ts ./src/node.ts",
19
+ "toc": "markdown-toc --maxdepth 3 -i README.md",
20
+ "start": "VITE_DEBUG_MODE=staging vite --mode=staging",
21
+ "preversion": "npm run lint",
22
+ "version": "npm run toc && git add README.md",
23
+ "postversion": "git push --follow-tags && npm publish",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "dependencies": {
27
+ "ms": "2.1.3",
28
+ "supports-color": "^9.4.0"
29
+ },
30
+ "devDependencies": {
31
+ "@bicycle-codes/tapzero": "^0.10.0",
32
+ "@types/node": "^22.0.0",
33
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
34
+ "@typescript-eslint/parser": "^8.0.0",
35
+ "auto-changelog": "^2.4.0",
36
+ "esbuild": "^0.24.0",
37
+ "eslint-config-standard": "^17.1.0",
38
+ "markdown-toc": "^1.2.0",
39
+ "tap-spec": "^5.0.0",
40
+ "tape-run": "^11.0.0",
41
+ "typedoc": "^0.26.7",
42
+ "typescript": "^5.4.5",
43
+ "vite": "^5.2.11"
44
+ },
45
+ "exports": {
46
+ ".": {
47
+ "node": "./dist/node.js",
48
+ "browser": "./dist/browser.js",
49
+ "default": "./dist/browser.js"
50
+ },
51
+ "./node": "./dist/node.js",
52
+ "./browser": "./dist/browser.js"
53
+ },
54
+ "author": "nichoth <nichoth@gmail.com> (https://nichoth.com)",
55
+ "license": "MIT",
56
+ "directories": {
57
+ "example": "example",
58
+ "test": "test"
59
+ },
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/substrate-system/debug.git"
63
+ },
64
+ "keywords": [
65
+ "debug",
66
+ "console",
67
+ "log"
68
+ ],
69
+ "bugs": {
70
+ "url": "https://github.com/substrate-system/debug/issues"
71
+ },
72
+ "homepage": "https://github.com/substrate-system/debug"
73
+ }