@microphi/debug 1.2.0 → 2.2.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/lib/index.js +1 -18
- package/lib/lib/debug.js +16 -22
- package/lib/lib/get-environment-varialbles.js +3 -8
- package/lib/lib/is_nodejs.js +1 -6
- package/package.json +2 -2
- package/lib/index.js.map +0 -1
- package/lib/lib/debug.js.map +0 -1
- package/lib/lib/get-environment-varialbles.js.map +0 -1
- package/lib/lib/is_nodejs.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
1
|
/*
|
|
18
2
|
* Public API Surface of store
|
|
19
3
|
*/
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
4
|
+
export * from './lib/debug';
|
package/lib/lib/debug.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getDebugger = exports.onMessage = void 0;
|
|
4
|
-
const get_environment_varialbles_1 = require("./get-environment-varialbles");
|
|
5
|
-
const is_nodejs_1 = require("./is_nodejs");
|
|
1
|
+
import { getEnvironmentVariables } from './get-environment-varialbles';
|
|
2
|
+
import { isNodejs } from './is_nodejs';
|
|
6
3
|
const colors = new Map();
|
|
7
4
|
const colorPalette = [];
|
|
8
|
-
if (
|
|
9
|
-
colorPalette.push(
|
|
5
|
+
if (isNodejs()) {
|
|
6
|
+
colorPalette.push('\x1b[30m', '\x1b[31m', '\x1b[32m', '\x1b[33m', '\x1b[34m', '\x1b[35m', '\x1b[36m', '\x1b[37m', '\x1b[90m', '\x1b[91m', '\x1b[92m', '\x1b[93m', '\x1b[94m', '\x1b[95m', '\x1b[96m', '\x1b[97m');
|
|
10
7
|
}
|
|
11
8
|
else {
|
|
12
|
-
colorPalette.push(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
colorPalette.push('#0000FF', '#6699FF', // Blue
|
|
10
|
+
'#FF0000', '#FF6666', // Red
|
|
11
|
+
'#00FF00', '#66FF66', // Green
|
|
12
|
+
'#FFFF00', '#FFFF66', // Yellow
|
|
13
|
+
'#800080', '#CC66CC', // Purple
|
|
14
|
+
'#FFA500', '#FFCC99', // Orange
|
|
15
|
+
'#FFC0CB', '#FFCCCC', // Pink
|
|
16
|
+
'#40E0D0', '#66CCCC' // Turquoise
|
|
20
17
|
);
|
|
21
18
|
}
|
|
22
19
|
const callBacks = [];
|
|
23
|
-
function onMessage(cb) {
|
|
20
|
+
export function onMessage(cb) {
|
|
24
21
|
callBacks.push(cb);
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
function getDebugger(namespace) {
|
|
23
|
+
export function getDebugger(namespace) {
|
|
28
24
|
let lastTimeStamp = 0;
|
|
29
|
-
const { DEBUG } =
|
|
25
|
+
const { DEBUG } = getEnvironmentVariables();
|
|
30
26
|
const random = Math.floor(Math.random() * (colorPalette.length - 1));
|
|
31
27
|
// Generate a random color
|
|
32
28
|
const randomColor = colors.get(namespace) ||
|
|
@@ -54,7 +50,7 @@ function getDebugger(namespace) {
|
|
|
54
50
|
const match = namespace.match(regex);
|
|
55
51
|
if (match) {
|
|
56
52
|
// Print formatted time with namespace
|
|
57
|
-
if (
|
|
53
|
+
if (isNodejs()) {
|
|
58
54
|
console.log(`\x1b[7m${formattedTime}\x1b[0m`, `\x1b[1m${randomColor}${namespace}\x1b[0m`, ...args);
|
|
59
55
|
}
|
|
60
56
|
else {
|
|
@@ -69,5 +65,3 @@ function getDebugger(namespace) {
|
|
|
69
65
|
}
|
|
70
66
|
};
|
|
71
67
|
}
|
|
72
|
-
exports.getDebugger = getDebugger;
|
|
73
|
-
//# sourceMappingURL=debug.js.map
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getEnvironmentVariables = void 0;
|
|
4
|
-
const is_nodejs_1 = require("./is_nodejs");
|
|
5
|
-
function getEnvironmentVariables() {
|
|
1
|
+
import { isNodejs } from './is_nodejs';
|
|
2
|
+
export function getEnvironmentVariables() {
|
|
6
3
|
let DEBUG;
|
|
7
|
-
if (
|
|
4
|
+
if (isNodejs()) {
|
|
8
5
|
DEBUG = process.env['DEBUG'] || '';
|
|
9
6
|
}
|
|
10
7
|
else {
|
|
@@ -12,5 +9,3 @@ function getEnvironmentVariables() {
|
|
|
12
9
|
}
|
|
13
10
|
return { DEBUG };
|
|
14
11
|
}
|
|
15
|
-
exports.getEnvironmentVariables = getEnvironmentVariables;
|
|
16
|
-
//# sourceMappingURL=get-environment-varialbles.js.map
|
package/lib/lib/is_nodejs.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNodejs = void 0;
|
|
4
|
-
function isNodejs() {
|
|
1
|
+
export function isNodejs() {
|
|
5
2
|
let isNode = false;
|
|
6
3
|
try {
|
|
7
4
|
if (typeof process === 'object') {
|
|
@@ -13,5 +10,3 @@ function isNodejs() {
|
|
|
13
10
|
}
|
|
14
11
|
return isNode;
|
|
15
12
|
}
|
|
16
|
-
exports.isNodejs = isNodejs;
|
|
17
|
-
//# sourceMappingURL=is_nodejs.js.map
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"lib"
|
|
18
18
|
],
|
|
19
|
-
"version": "
|
|
19
|
+
"version": "2.2.0",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"tslib": "^2.5.0"
|
|
22
22
|
},
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"prepack": "yarn build",
|
|
28
28
|
"lint": "eslint ./src"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "f1120b91036014e2881c049713ebc00f7c965f4f"
|
|
31
31
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,8CAA4B","sourcesContent":["/*\n * Public API Surface of store\n */\nexport * from './lib/debug';\n"]}
|
package/lib/lib/debug.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/lib/debug.ts"],"names":[],"mappings":";;;AAAA,6EAAuE;AACvE,2CAAuC;AAGvC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEzC,MAAM,YAAY,GAAa,EAAE,CAAC;AAElC,IAAI,IAAA,oBAAQ,GAAE,EAAE;IAEd,YAAY,CAAC,IAAI,CACf,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU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vB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBACvD,CAAC,CAAC,CAAC;aAEJ;SAEF;IACH,CAAC,CAAA;AACH,CAAC;AAlED,kCAkEC","sourcesContent":["import { getEnvironmentVariables } from \"./get-environment-varialbles\";\nimport { isNodejs } from \"./is_nodejs\";\n\n\nconst colors = new Map<string, string>();\n\nconst colorPalette: string[] = [];\n\nif (isNodejs()) {\n\n colorPalette.push(\n \"\\x1b[30m\",\n \"\\x1b[31m\",\n \"\\x1b[32m\",\n \"\\x1b[33m\",\n \"\\x1b[34m\",\n \"\\x1b[35m\",\n \"\\x1b[36m\",\n \"\\x1b[37m\",\n \"\\x1b[90m\",\n \"\\x1b[91m\",\n \"\\x1b[92m\",\n \"\\x1b[93m\",\n \"\\x1b[94m\",\n \"\\x1b[95m\",\n \"\\x1b[96m\",\n \"\\x1b[97m\",\n );\n\n} else {\n\n colorPalette.push(\n \"#0000FF\", \"#6699FF\", // Blue\n \"#FF0000\", \"#FF6666\", // Red\n \"#00FF00\", \"#66FF66\", // Green\n \"#FFFF00\", \"#FFFF66\", // Yellow\n \"#800080\", \"#CC66CC\", // Purple\n \"#FFA500\", \"#FFCC99\", // Orange\n \"#FFC0CB\", \"#FFCCCC\", // Pink\n \"#40E0D0\", \"#66CCCC\" // Turquoise\n )\n}\n\nexport type Log = (...args: unknown[]) => void;\n\nexport type onMessageCallback = ({\n formattedTime, namespace, args\n}: {formattedTime: string; namespace: string; args: unknown[]}) => void;\n\nconst callBacks: onMessageCallback[] = [];\n\nexport function onMessage(cb: onMessageCallback) {\n callBacks.push(cb);\n}\n\nexport function getDebugger(namespace: string): Log {\n\n\n let lastTimeStamp = 0;\n const {DEBUG} = getEnvironmentVariables();\n\n\n const random = Math.floor(Math.random() * (colorPalette.length - 1));\n // Generate a random color\n const randomColor = colors.get(namespace) ||\n colors.set(namespace, colorPalette[random]).get(namespace) as string;\n\n\n // CSS style for the namespace with random color and bold\n const namespaceStyle = `color: ${randomColor}; font-weight: bold;`;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (...args: any[]) => {\n\n let formattedTime = '';\n const now = Date.now();\n\n if ((now - lastTimeStamp) > 1000) {\n\n const currentTime = new Date();\n const hours = currentTime.getHours().toString().padStart(2, '0');\n const minutes = currentTime.getMinutes().toString().padStart(2, '0');\n const seconds = currentTime.getSeconds().toString().padStart(2, '0');\n\n formattedTime = `${hours}:${minutes}:${seconds}`;\n lastTimeStamp = now;\n\n } else {\n formattedTime = `+${now - lastTimeStamp}`.padStart(8, ' ');\n }\n\n\n if (DEBUG) {\n\n const regexs = DEBUG.split(',');\n for (const regex of regexs) {\n\n const match = namespace.match(regex);\n\n if (match) {\n // Print formatted time with namespace\n if (isNodejs()) {\n\n console.log(`\\x1b[7m${formattedTime}\\x1b[0m`, `\\x1b[1m${randomColor}${namespace}\\x1b[0m`, ...args);\n\n } else {\n\n console.log(`%c${formattedTime} %c${namespace}`, 'color: lightblue', namespaceStyle, ...args);\n\n }\n }\n\n // in anycase call callbacks\n callBacks.forEach((cb) => {\n cb.apply(null, [{ formattedTime, namespace, args }]);\n });\n\n }\n\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-environment-varialbles.js","sourceRoot":"","sources":["../../src/lib/get-environment-varialbles.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAEvC,SAAgB,uBAAuB;IAErC,IAAI,KAAa,CAAC;IAElB,IAAI,IAAA,oBAAQ,GAAE,EAAE;QAEd,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;KACpC;SAAM;QAEL,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;KAC7C;IAED,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC;AAbD,0DAaC","sourcesContent":["import { isNodejs } from \"./is_nodejs\";\n\nexport function getEnvironmentVariables() {\n\n let DEBUG: string;\n\n if (isNodejs()) {\n\n DEBUG = process.env['DEBUG'] || '';\n } else {\n\n DEBUG = localStorage.getItem('debug') || '';\n }\n\n return { DEBUG };\n}\n"]}
|
package/lib/lib/is_nodejs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is_nodejs.js","sourceRoot":"","sources":["../../src/lib/is_nodejs.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ;IACtB,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI;QAEF,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,MAAM,GAAG,IAAI,CAAC;SACf;KACF;IAAC,OAAO,KAAK,EAAE;QAEd,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;KACrE;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAdD,4BAcC","sourcesContent":["declare const process: object;\n\nexport function isNodejs() {\n let isNode = false;\n\n try {\n\n if (typeof process === 'object') {\n isNode = true;\n }\n } catch (error) {\n\n console.log('process is not an object. this is likely the browser');\n }\n\n return isNode;\n}\n"]}
|