@microphi/debug 1.1.4 → 1.1.5

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.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/debug';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Public API Surface of store
3
+ */
4
+ export * from './lib/debug';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,3 @@
1
+ export type Log = (...args: unknown[]) => void;
2
+ export declare function getDebugger(namespace: string): Log;
3
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/lib/debug.ts"],"names":[],"mappings":"AA+CA,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE/C,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CA2DlD"}
@@ -0,0 +1,59 @@
1
+ import { getEnvironmentVariables } from "./get-environment-varialbles";
2
+ const colors = new Map();
3
+ const colorPalette = [];
4
+ if (process) {
5
+ 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");
6
+ }
7
+ else {
8
+ colorPalette.push("#0000FF", "#6699FF", // Blue
9
+ "#FF0000", "#FF6666", // Red
10
+ "#00FF00", "#66FF66", // Green
11
+ "#FFFF00", "#FFFF66", // Yellow
12
+ "#800080", "#CC66CC", // Purple
13
+ "#FFA500", "#FFCC99", // Orange
14
+ "#FFC0CB", "#FFCCCC", // Pink
15
+ "#40E0D0", "#66CCCC" // Turquoise
16
+ );
17
+ }
18
+ export function getDebugger(namespace) {
19
+ let lastTimeStamp = 0;
20
+ const { DEBUG } = getEnvironmentVariables(process);
21
+ const random = Math.floor(Math.random() * (colorPalette.length - 1));
22
+ // Generate a random color
23
+ const randomColor = colors.get(namespace) ||
24
+ colors.set(namespace, colorPalette[random]).get(namespace);
25
+ // CSS style for the namespace with random color and bold
26
+ const namespaceStyle = `color: ${randomColor}; font-weight: bold;`;
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ return (...args) => {
29
+ let formattedTime = '';
30
+ const now = Date.now();
31
+ if ((now - lastTimeStamp) > 1000) {
32
+ const currentTime = new Date();
33
+ const hours = currentTime.getHours().toString().padStart(2, '0');
34
+ const minutes = currentTime.getMinutes().toString().padStart(2, '0');
35
+ const seconds = currentTime.getSeconds().toString().padStart(2, '0');
36
+ formattedTime = `${hours}:${minutes}:${seconds}`;
37
+ lastTimeStamp = now;
38
+ }
39
+ else {
40
+ formattedTime = `+${now - lastTimeStamp}`.padStart(8, ' ');
41
+ }
42
+ if (DEBUG) {
43
+ const regexs = DEBUG.split(',');
44
+ for (const regex of regexs) {
45
+ const match = namespace.match(regex);
46
+ if (match) {
47
+ // Print formatted time with namespace
48
+ if (process) {
49
+ console.log(`\x1b[7m${formattedTime}\x1b[0m`, `\x1b[1m${randomColor}${namespace}\x1b[0m`, ...args);
50
+ }
51
+ else {
52
+ console.log(`%c${formattedTime} %c${namespace}`, 'color: lightblue', namespaceStyle, ...args);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ };
58
+ }
59
+ //# sourceMappingURL=debug.js.map
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a,SAAS,EAAE,UAAU,WAAW,GAAG,SAAS,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;qBAEpG;yBAAM;wBAEL,OAAO,CAAC,GAAG,CAAC,KAAK,aAAa,MAAM,SAAS,EAAE,EAAE,kBAAkB,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC;qBAC/F;iBACF;aAEF;SAEF;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { getEnvironmentVariables } from \"./get-environment-varialbles\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ndeclare const process: any;\n\nconst colors = new Map<string, string>();\n\nconst colorPalette: string[] = [];\n\nif (process) {\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\n\n\n\nexport type Log = (...args: unknown[]) => void;\n\nexport function getDebugger(namespace: string): Log {\n\n\n let lastTimeStamp = 0;\n const {DEBUG} = getEnvironmentVariables(process);\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 (process) {\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\n }\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare function getEnvironmentVariables(process: {
2
+ env: {
3
+ [k: string]: string;
4
+ };
5
+ }): {
6
+ DEBUG: string;
7
+ };
8
+ //# sourceMappingURL=get-environment-varialbles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-environment-varialbles.d.ts","sourceRoot":"","sources":["../../src/lib/get-environment-varialbles.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAAC,GAAG,EAAE;QAAC,CAAC,CAAC,EAAC,MAAM,GAAG,MAAM,CAAA;KAAC,CAAA;CAAC;;EAc3E"}
@@ -0,0 +1,11 @@
1
+ export function getEnvironmentVariables(process) {
2
+ let DEBUG;
3
+ if (typeof window === 'object') {
4
+ DEBUG = localStorage.getItem('debug') || '';
5
+ }
6
+ else {
7
+ DEBUG = process.env['DEBUG'];
8
+ }
9
+ return { DEBUG };
10
+ }
11
+ //# sourceMappingURL=get-environment-varialbles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-environment-varialbles.js","sourceRoot":"","sources":["../../src/lib/get-environment-varialbles.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,uBAAuB,CAAC,OAAoC;IACxE,IAAI,KAAa,CAAC;IAElB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAE5B,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;KAE/C;SAAM;QAEH,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KAEhC;IAED,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC","sourcesContent":["export function getEnvironmentVariables(process: {env: {[k:string]: string}}) {\n let DEBUG: string;\n\n if (typeof window === 'object') {\n\n DEBUG = localStorage.getItem('debug') || '';\n\n } else {\n\n DEBUG = process.env['DEBUG'];\n\n }\n\n return { DEBUG };\n}\n"]}
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "files": [
16
16
  "lib"
17
17
  ],
18
- "version": "1.1.4",
18
+ "version": "1.1.5",
19
19
  "dependencies": {
20
20
  "tslib": "^2.5.0"
21
21
  },
@@ -23,7 +23,8 @@
23
23
  "build": "tsc -b tsconfig.build.json",
24
24
  "build:ci": "yarn build",
25
25
  "test:ci": "jest --coverage --ci",
26
+ "prepack": "yarn build",
26
27
  "lint": "eslint ./src"
27
28
  },
28
- "gitHead": "40ae123e364284d3308bab5ab9532376ebcd404f"
29
+ "gitHead": "82e5091939c81ad825089316a5ddf66638e8c32f"
29
30
  }