@microphi/debug 2.3.0 → 2.5.1
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 +4 -1
- package/lib/lib/debug.js +12 -7
- package/lib/lib/get-environment-varialbles.js +7 -3
- package/lib/lib/is_nodejs.js +5 -1
- package/package.json +15 -9
package/lib/index.js
CHANGED
package/lib/lib/debug.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
3
6
|
const colors = new Map();
|
|
4
7
|
const colorPalette = [];
|
|
5
|
-
if (isNodejs()) {
|
|
8
|
+
if ((0, is_nodejs_1.isNodejs)()) {
|
|
6
9
|
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');
|
|
7
10
|
}
|
|
8
11
|
else {
|
|
@@ -17,12 +20,13 @@ else {
|
|
|
17
20
|
);
|
|
18
21
|
}
|
|
19
22
|
const callBacks = [];
|
|
20
|
-
|
|
23
|
+
function onMessage(cb) {
|
|
21
24
|
callBacks.push(cb);
|
|
22
25
|
}
|
|
23
|
-
|
|
26
|
+
exports.onMessage = onMessage;
|
|
27
|
+
function getDebugger(namespace) {
|
|
24
28
|
let lastTimeStamp = 0;
|
|
25
|
-
const { DEBUG } = getEnvironmentVariables();
|
|
29
|
+
const { DEBUG } = (0, get_environment_varialbles_1.getEnvironmentVariables)();
|
|
26
30
|
const random = Math.floor(Math.random() * (colorPalette.length - 1));
|
|
27
31
|
// Generate a random color
|
|
28
32
|
const randomColor = colors.get(namespace) ||
|
|
@@ -50,7 +54,7 @@ export function getDebugger(namespace) {
|
|
|
50
54
|
const match = namespace.match(regex);
|
|
51
55
|
if (match) {
|
|
52
56
|
// Print formatted time with namespace
|
|
53
|
-
if (isNodejs()) {
|
|
57
|
+
if ((0, is_nodejs_1.isNodejs)()) {
|
|
54
58
|
console.log(`\x1b[7m${formattedTime}\x1b[0m`, `\x1b[1m${randomColor}${namespace}\x1b[0m`, ...args);
|
|
55
59
|
}
|
|
56
60
|
else {
|
|
@@ -65,3 +69,4 @@ export function getDebugger(namespace) {
|
|
|
65
69
|
}
|
|
66
70
|
};
|
|
67
71
|
}
|
|
72
|
+
exports.getDebugger = getDebugger;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvironmentVariables = void 0;
|
|
4
|
+
const is_nodejs_1 = require("./is_nodejs");
|
|
5
|
+
function getEnvironmentVariables() {
|
|
3
6
|
let DEBUG;
|
|
4
|
-
if (isNodejs()) {
|
|
7
|
+
if ((0, is_nodejs_1.isNodejs)()) {
|
|
5
8
|
DEBUG = process.env['DEBUG'] || '';
|
|
6
9
|
}
|
|
7
10
|
else {
|
|
@@ -9,3 +12,4 @@ export function getEnvironmentVariables() {
|
|
|
9
12
|
}
|
|
10
13
|
return { DEBUG };
|
|
11
14
|
}
|
|
15
|
+
exports.getEnvironmentVariables = getEnvironmentVariables;
|
package/lib/lib/is_nodejs.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNodejs = void 0;
|
|
4
|
+
function isNodejs() {
|
|
2
5
|
let isNode = false;
|
|
3
6
|
try {
|
|
4
7
|
if (typeof process === 'object') {
|
|
@@ -10,3 +13,4 @@ export function isNodejs() {
|
|
|
10
13
|
}
|
|
11
14
|
return isNode;
|
|
12
15
|
}
|
|
16
|
+
exports.isNodejs = isNodejs;
|
package/package.json
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microphi/debug",
|
|
3
|
+
"version": "2.5.1",
|
|
3
4
|
"description": "A very simple wrapper to console.log",
|
|
4
|
-
"licence": "MIT",
|
|
5
|
-
"private": false,
|
|
6
|
-
"keywords": [
|
|
7
|
-
"log",
|
|
8
|
-
"debug",
|
|
9
|
-
"console"
|
|
10
|
-
],
|
|
11
5
|
"main": "lib/index.js",
|
|
12
6
|
"typings": "lib/index.d.ts",
|
|
13
7
|
"module": "lib/index.js",
|
|
@@ -17,7 +11,19 @@
|
|
|
17
11
|
"files": [
|
|
18
12
|
"lib"
|
|
19
13
|
],
|
|
20
|
-
"
|
|
14
|
+
"licence": "MIT",
|
|
15
|
+
"private": false,
|
|
16
|
+
"keywords": [
|
|
17
|
+
"log",
|
|
18
|
+
"debug",
|
|
19
|
+
"console"
|
|
20
|
+
],
|
|
21
|
+
"author": {
|
|
22
|
+
"email": "cavaliere.davide@gmail.com",
|
|
23
|
+
"name": "Davide Cavaliere",
|
|
24
|
+
"url": "www.dcsoftware.io"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/microph1/microphi",
|
|
21
27
|
"dependencies": {
|
|
22
28
|
"tslib": "^2.5.0"
|
|
23
29
|
},
|
|
@@ -28,5 +34,5 @@
|
|
|
28
34
|
"prepack": "yarn build",
|
|
29
35
|
"lint": "eslint ./src"
|
|
30
36
|
},
|
|
31
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "85be3ad7bf34a32e5b386d817b71ef3f6703b397"
|
|
32
38
|
}
|