@microphi/debug 1.1.3 → 1.1.4
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 +21 -0
- package/package.json +3 -2
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -5
- package/lib/index.js.map +0 -1
- package/lib/lib/debug.d.ts +0 -2
- package/lib/lib/debug.d.ts.map +0 -1
- package/lib/lib/debug.js +0 -50
- package/lib/lib/debug.js.map +0 -1
- package/lib/lib/get-environment-varialbles.d.ts +0 -9
- package/lib/lib/get-environment-varialbles.d.ts.map +0 -1
- package/lib/lib/get-environment-varialbles.js +0 -14
- package/lib/lib/get-environment-varialbles.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Davide Cavaliere
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, 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,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"lib"
|
|
17
17
|
],
|
|
18
|
-
"version": "1.1.
|
|
18
|
+
"version": "1.1.4",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"tslib": "^2.5.0"
|
|
21
21
|
},
|
|
@@ -24,5 +24,6 @@
|
|
|
24
24
|
"build:ci": "yarn build",
|
|
25
25
|
"test:ci": "jest --coverage --ci",
|
|
26
26
|
"lint": "eslint ./src"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "40ae123e364284d3308bab5ab9532376ebcd404f"
|
|
28
29
|
}
|
package/lib/index.d.ts
DELETED
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC"}
|
package/lib/index.js
DELETED
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,cAAc,aAAa,CAAC","sourcesContent":["/*\n * Public API Surface of store\n */\nexport * from './lib/debug';\n"]}
|
package/lib/lib/debug.d.ts
DELETED
package/lib/lib/debug.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/lib/debug.ts"],"names":[],"mappings":"AAoBA,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,aAc1B,OAAO,EAAE,UAsC3B"}
|
package/lib/lib/debug.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { getEnvironmentVarialbles } from "./get-environment-varialbles";
|
|
2
|
-
const colors = new Map();
|
|
3
|
-
const colorPalettes = new Map();
|
|
4
|
-
colorPalettes.set('funky_dealer', [
|
|
5
|
-
'#7dd823',
|
|
6
|
-
'#d9d126',
|
|
7
|
-
'#ffb611',
|
|
8
|
-
'#ff6000',
|
|
9
|
-
'#0f5940',
|
|
10
|
-
]);
|
|
11
|
-
const DEFAULT_PALETTE = 'funky_dealer';
|
|
12
|
-
export function getDebugger(namespace) {
|
|
13
|
-
let lastTimeStamp = 0;
|
|
14
|
-
const { DEBUG, PALETTE } = getEnvironmentVarialbles(process);
|
|
15
|
-
const colorPalette = colorPalettes.get(PALETTE || DEFAULT_PALETTE);
|
|
16
|
-
const random = Math.floor(Math.random() * (colorPalette.length + 1));
|
|
17
|
-
// Generate a random color
|
|
18
|
-
const randomColor = colors.get(namespace) ||
|
|
19
|
-
colors.set(namespace, colorPalette[random]).get(namespace);
|
|
20
|
-
// CSS style for the namespace with random color and bold
|
|
21
|
-
const namespaceStyle = `color: ${randomColor}; font-weight: bold;`;
|
|
22
|
-
return (...args) => {
|
|
23
|
-
let formattedTime = undefined;
|
|
24
|
-
const now = Date.now();
|
|
25
|
-
if ((now - lastTimeStamp) > 1000) {
|
|
26
|
-
const currentTime = new Date();
|
|
27
|
-
const hours = currentTime.getHours().toString().padStart(2, '0');
|
|
28
|
-
const minutes = currentTime.getMinutes().toString().padStart(2, '0');
|
|
29
|
-
const seconds = currentTime.getSeconds().toString().padStart(2, '0');
|
|
30
|
-
formattedTime = `${hours}:${minutes}:${seconds}`;
|
|
31
|
-
lastTimeStamp = now;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
formattedTime = `+${now - lastTimeStamp}`.padStart(8, ' ');
|
|
35
|
-
}
|
|
36
|
-
if (DEBUG) {
|
|
37
|
-
const regexs = DEBUG.split(',');
|
|
38
|
-
for (const regex of regexs) {
|
|
39
|
-
// console.info({debug});
|
|
40
|
-
const match = namespace.match(regex);
|
|
41
|
-
// console.log({match});
|
|
42
|
-
if (match) {
|
|
43
|
-
// Print formatted time with namespace
|
|
44
|
-
console.log(`%c${formattedTime} %c${namespace}`, 'color: lightblue', namespaceStyle, ...args);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=debug.js.map
|
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,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAIxE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;AAIzC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAqB,CAAC;AAEnD,aAAa,CAAC,GAAG,CAAC,cAAc,EAAE;IAChC,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,eAAe,GAAY,cAAc,CAAC;AAEhD,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,MAAM,EAAC,KAAK,EAAE,OAAO,EAAC,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,IAAI,eAAe,CAAa,CAAC;IAE/E,MAAM,MAAM,GAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtE,0BAA0B;IAC1B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACvC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAW,CAAC;IAE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EAAE,GAAG,IAAI,CAAC,CAAC;iBAC/F;aAEF;SAEF;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { getEnvironmentVarialbles } from \"./get-environment-varialbles\";\n\ndeclare const process: any;\n\nconst colors = new Map<string, string>();\n\ntype Palette = 'funky_dealer' | string;\n\nconst colorPalettes = new Map<Palette, string[]>();\n\ncolorPalettes.set('funky_dealer', [\n '#7dd823',\n '#d9d126',\n '#ffb611',\n '#ff6000',\n '#0f5940',\n]);\n\nconst DEFAULT_PALETTE: Palette = 'funky_dealer';\n\nexport function getDebugger(namespace: string) {\n let lastTimeStamp = 0;\n const {DEBUG, PALETTE} = getEnvironmentVarialbles(process);\n\n const colorPalette = colorPalettes.get(PALETTE || DEFAULT_PALETTE) as string[];\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 // CSS style for the namespace with random color and bold\n const namespaceStyle = `color: ${randomColor}; font-weight: bold;`;\n\n return (...args: unknown[]) => {\n\n let formattedTime = undefined;\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 // console.info({debug});\n const match = namespace.match(regex);\n // console.log({match});\n\n if (match) {\n // Print formatted time with namespace\n console.log(`%c${formattedTime} %c${namespace}`, 'color: lightblue', namespaceStyle, ...args);\n }\n\n }\n\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-environment-varialbles.d.ts","sourceRoot":"","sources":["../../src/lib/get-environment-varialbles.ts"],"names":[],"mappings":"AAAA,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAC,GAAG,EAAE;QAAC,CAAC,CAAC,EAAC,MAAM,GAAG,MAAM,CAAA;KAAC,CAAA;CAAC;;;EAiB5E"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function getEnvironmentVarialbles(process) {
|
|
2
|
-
let DEBUG;
|
|
3
|
-
let PALETTE;
|
|
4
|
-
if (typeof window === 'object') {
|
|
5
|
-
DEBUG = localStorage.getItem('debug') || '';
|
|
6
|
-
PALETTE = localStorage.getItem('palette') || '';
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
DEBUG = process.env['DEBUG'];
|
|
10
|
-
PALETTE = process.env['PALETTE'];
|
|
11
|
-
}
|
|
12
|
-
return { DEBUG, PALETTE };
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=get-environment-varialbles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-environment-varialbles.js","sourceRoot":"","sources":["../../src/lib/get-environment-varialbles.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,wBAAwB,CAAC,OAAoC;IACzE,IAAI,KAAa,CAAC;IAClB,IAAI,OAAe,CAAC;IAEpB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAE5B,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5C,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;KAEnD;SAAM;QAEH,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KAEpC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["export function getEnvironmentVarialbles(process: {env: {[k:string]: string}}) {\n let DEBUG: string;\n let PALETTE: string;\n\n if (typeof window === 'object') {\n\n DEBUG = localStorage.getItem('debug') || '';\n PALETTE = localStorage.getItem('palette') || '';\n\n } else {\n\n DEBUG = process.env['DEBUG'];\n PALETTE = process.env['PALETTE'];\n\n }\n\n return { DEBUG, PALETTE };\n}\n"]}
|