@microphi/debug 1.1.7 → 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 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
- __exportStar(require("./lib/debug"), exports);
21
- //# sourceMappingURL=index.js.map
4
+ export * from './lib/debug';
@@ -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,27 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDebugger = 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 ((0, is_nodejs_1.isNodejs)()) {
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");
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("#0000FF", "#6699FF", // Blue
13
- "#FF0000", "#FF6666", // Red
14
- "#00FF00", "#66FF66", // Green
15
- "#FFFF00", "#FFFF66", // Yellow
16
- "#800080", "#CC66CC", // Purple
17
- "#FFA500", "#FFCC99", // Orange
18
- "#FFC0CB", "#FFCCCC", // Pink
19
- "#40E0D0", "#66CCCC" // Turquoise
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
- function getDebugger(namespace) {
19
+ const callBacks = [];
20
+ export function onMessage(cb) {
21
+ callBacks.push(cb);
22
+ }
23
+ export function getDebugger(namespace) {
23
24
  let lastTimeStamp = 0;
24
- const { DEBUG } = (0, get_environment_varialbles_1.getEnvironmentVariables)();
25
+ const { DEBUG } = getEnvironmentVariables();
25
26
  const random = Math.floor(Math.random() * (colorPalette.length - 1));
26
27
  // Generate a random color
27
28
  const randomColor = colors.get(namespace) ||
@@ -49,16 +50,18 @@ function getDebugger(namespace) {
49
50
  const match = namespace.match(regex);
50
51
  if (match) {
51
52
  // Print formatted time with namespace
52
- if ((0, is_nodejs_1.isNodejs)()) {
53
+ if (isNodejs()) {
53
54
  console.log(`\x1b[7m${formattedTime}\x1b[0m`, `\x1b[1m${randomColor}${namespace}\x1b[0m`, ...args);
54
55
  }
55
56
  else {
56
57
  console.log(`%c${formattedTime} %c${namespace}`, 'color: lightblue', namespaceStyle, ...args);
57
58
  }
58
59
  }
60
+ // in anycase call callbacks
61
+ callBacks.forEach((cb) => {
62
+ cb.apply(null, [{ formattedTime, namespace, args }]);
63
+ });
59
64
  }
60
65
  }
61
66
  };
62
67
  }
63
- exports.getDebugger = getDebugger;
64
- //# sourceMappingURL=debug.js.map
@@ -1,10 +1,7 @@
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() {
1
+ import { isNodejs } from './is_nodejs';
2
+ export function getEnvironmentVariables() {
6
3
  let DEBUG;
7
- if ((0, is_nodejs_1.isNodejs)()) {
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
@@ -1,7 +1,4 @@
1
- "use strict";
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": "1.1.7",
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": "9ace3d12ef3cb095f590455029a58eed8546d2a5"
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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/lib/debug.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AAC;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 +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"]}
@@ -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"]}