@microphi/debug 1.1.3

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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @microphi/store
2
+
3
+ > A typescript library to handle states in a human way
4
+
5
+ Please refer to the following post for some more info. Documentation will come at a later stage
6
+
7
+ https://dev.to/davidecavaliere/a-state-manager-for-angular-that-makes-sense-finally-at-least-for-me-2kij-temp-slug-6701935?preview=27e5680771de4a8c93dd2c825b0691b68605d25f1e4ff583e6c4116ba4d30b3b863c98dcfe41b7d059672a5bc3b6e892ceba1b8272e8123594ac0843
8
+
9
+ Be aware this is just a PoC at this moment *do not use it on your production apps*
10
+
11
+ ## Build and deploy @microphi/store
12
+
13
+ ```
14
+ yarn version
15
+ yarn build store --prod
16
+ yarn deploy store
17
+ ```
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,2 @@
1
+ export declare function getDebugger(namespace: string): (...args: unknown[]) => void;
2
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,50 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../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AAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACjE,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACrE,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;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,yBAAyB;gBACzB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACrC,wBAAwB;gBAExB,IAAI,KAAK,EAAE;oBACT,sCAAsC;oBACtC,OAAO,CAAC,GAAG,CAAC,KAAK,aAAa,MAAM,SAAS,EAAE,EAAE,kBAAkB,EAAE,cAAc,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"]}
@@ -0,0 +1,9 @@
1
+ export declare function getEnvironmentVarialbles(process: {
2
+ env: {
3
+ [k: string]: string;
4
+ };
5
+ }): {
6
+ DEBUG: string;
7
+ PALETTE: string;
8
+ };
9
+ //# 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,wBAAwB,CAAC,OAAO,EAAE;IAAC,GAAG,EAAE;QAAC,CAAC,CAAC,EAAC,MAAM,GAAG,MAAM,CAAA;KAAC,CAAA;CAAC;;;EAiB5E"}
@@ -0,0 +1,14 @@
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
@@ -0,0 +1 @@
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"]}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@microphi/debug",
3
+ "private": false,
4
+ "keywords": [
5
+ "log",
6
+ "debug",
7
+ "console"
8
+ ],
9
+ "main": "lib/index.js",
10
+ "typings": "lib/index.d.ts",
11
+ "module": "lib/index.js",
12
+ "directories": {
13
+ "lib": "lib"
14
+ },
15
+ "files": [
16
+ "lib"
17
+ ],
18
+ "version": "1.1.3",
19
+ "dependencies": {
20
+ "tslib": "^2.5.0"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc -b tsconfig.build.json",
24
+ "build:ci": "yarn build",
25
+ "test:ci": "jest --coverage --ci",
26
+ "lint": "eslint ./src"
27
+ }
28
+ }