@microphi/debug 1.1.7 → 1.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.
@@ -1,3 +1,9 @@
1
1
  export type Log = (...args: unknown[]) => void;
2
+ export type onMessageCallback = ({ formattedTime, namespace, args }: {
3
+ formattedTime: string;
4
+ namespace: string;
5
+ args: unknown[];
6
+ }) => void;
7
+ export declare function onMessage(cb: onMessageCallback): void;
2
8
  export declare function getDebugger(namespace: string): Log;
3
9
  //# sourceMappingURL=debug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/lib/debug.ts"],"names":[],"mappings":"AA2CA,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE/C,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CA8DlD"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/lib/debug.ts"],"names":[],"mappings":"AA2CA,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GAAG,CAAC,EAC/B,aAAa,EAAE,SAAS,EAAE,IAAI,EAC/B,EAAE;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAC,KAAK,IAAI,CAAC;AAIxE,wBAAgB,SAAS,CAAC,EAAE,EAAE,iBAAiB,QAE9C;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAkElD"}
package/lib/lib/debug.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDebugger = void 0;
3
+ exports.getDebugger = exports.onMessage = void 0;
4
4
  const get_environment_varialbles_1 = require("./get-environment-varialbles");
5
5
  const is_nodejs_1 = require("./is_nodejs");
6
6
  const colors = new Map();
@@ -19,6 +19,11 @@ else {
19
19
  "#40E0D0", "#66CCCC" // Turquoise
20
20
  );
21
21
  }
22
+ const callBacks = [];
23
+ function onMessage(cb) {
24
+ callBacks.push(cb);
25
+ }
26
+ exports.onMessage = onMessage;
22
27
  function getDebugger(namespace) {
23
28
  let lastTimeStamp = 0;
24
29
  const { DEBUG } = (0, get_environment_varialbles_1.getEnvironmentVariables)();
@@ -56,6 +61,10 @@ function getDebugger(namespace) {
56
61
  console.log(`%c${formattedTime} %c${namespace}`, 'color: lightblue', namespaceStyle, ...args);
57
62
  }
58
63
  }
64
+ // in anycase call callbacks
65
+ callBacks.forEach((cb) => {
66
+ cb.apply(null, [{ formattedTime, namespace, args }]);
67
+ });
59
68
  }
60
69
  }
61
70
  };
@@ -1 +1 @@
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,CACX,CAAC;CAEH;KAAM;IAEL,YAAY,CAAC,IAAI,CACf,SAAS,EAAE,SAAS,EAAE,OAAO;IAC7B,SAAS,EAAE,SAAS,EAAE,MAAM;IAC5B,SAAS,EAAE,SAAS,EAAE,QAAQ;IAC9B,SAAS,EAAE,SAAS,EAAE,SAAS;IAC/B,SAAS,EAAE,SAAS,EAAE,SAAS;IAC/B,SAAS,EAAE,SA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C;YAErE,aAAa,GAAG,GAAG,KAAK,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;YACjD,aAAa,GAAG,GAAG,CAAC;SAErB;aAAM;YACL,aAAa,GAAG,IAAI,GAAG,GAAG,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC5D;QAGD,IAAI,KAAK,EAAE;YAET,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;gBAE1B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAErC,IAAI,KAAK,EAAE;oBACT,sCAAsC;oBAEtC,IAAI,IAAA,oBAAQ,GAAE,EAAE;wBAEd,OAAO,CAAC,GAAG,CAAC,UAAU,aAAa,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;qBAE/F;iBACF;aAEF;SAEF;IACH,CAAC,CAAA;AACH,CAAC;AA9DD,kCA8DC","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 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\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 }\n\n }\n }\n}\n"]}
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/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;oBACtC,IAAI,IAAA,oBAAQ,GAAE,EAAE;wBAEd,OAAO,CAAC,GAAG,CAAC,UAAU,aAAa,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;qBAE/F;iBACF;gBAED,4BAA4B;gBAC5B,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;oBACvB,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"]}
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "files": [
17
17
  "lib"
18
18
  ],
19
- "version": "1.1.7",
19
+ "version": "1.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": "9ace3d12ef3cb095f590455029a58eed8546d2a5"
30
+ "gitHead": "eeba2aded4e0bc2d1006ab164b583c232d542085"
31
31
  }