@nu-art/ts-common 0.202.113 → 0.202.115

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.
@@ -0,0 +1,23 @@
1
+ import { LogClient } from './LogClient';
2
+ import { LogLevel, LogParam } from './types';
3
+ export type LoggerStyleObject = {
4
+ color?: string;
5
+ 'background-color'?: string;
6
+ 'font-weight'?: 'bold' | 'normal';
7
+ padding?: string;
8
+ 'border-radius'?: string;
9
+ };
10
+ declare class LogClient_BrowserGroups_Class extends LogClient {
11
+ constructor();
12
+ private newComposer;
13
+ protected logMessage(level: LogLevel, bold: boolean, prefix: string, toLog: LogParam[]): void;
14
+ private logSingle;
15
+ private logGroup;
16
+ private getLogLevelColor;
17
+ private composeStyleString;
18
+ private getLogLevelStyling;
19
+ private getTimestampStyling;
20
+ private getTagStyling;
21
+ }
22
+ export declare const LogClient_BrowserGroups: LogClient_BrowserGroups_Class;
23
+ export {};
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogClient_BrowserGroups = void 0;
4
+ const object_tools_1 = require("../../utils/object-tools");
5
+ const LogClient_1 = require("./LogClient");
6
+ const types_1 = require("./types");
7
+ const PrimitiveLogParams = ['string', 'number', 'boolean'];
8
+ class LogClient_BrowserGroups_Class extends LogClient_1.LogClient {
9
+ constructor() {
10
+ super();
11
+ this.logSingle = (logLevel, bold, toLog) => {
12
+ console.log(toLog, this.getLogLevelStyling(logLevel, bold), this.getTimestampStyling(bold, logLevel), this.getTagStyling(logLevel, bold));
13
+ };
14
+ this.logGroup = (logLevel, bold, prefix, toLog) => {
15
+ console.group(prefix, this.getLogLevelStyling(logLevel, bold), this.getTimestampStyling(bold, logLevel), this.getTagStyling(logLevel, bold));
16
+ toLog.forEach(logParam => console.log(logParam));
17
+ console.groupEnd();
18
+ };
19
+ // ################## Class Methods - Styling ##################
20
+ this.getLogLevelColor = (logLevel) => {
21
+ switch (logLevel) {
22
+ case types_1.LogLevel.Verbose:
23
+ return '#444444';
24
+ case types_1.LogLevel.Debug:
25
+ return '#3066be';
26
+ case types_1.LogLevel.Info:
27
+ return '#52a447';
28
+ case types_1.LogLevel.Warning:
29
+ return '#ed820e';
30
+ case types_1.LogLevel.Error:
31
+ return '#d14348';
32
+ default:
33
+ return 'transparent';
34
+ }
35
+ };
36
+ this.composeStyleString = (styleObject) => {
37
+ const styleArr = (0, object_tools_1._keys)(styleObject).map(key => `${key}: ${styleObject[key]}`);
38
+ return styleArr.join(';') + ';';
39
+ };
40
+ this.getLogLevelStyling = (logLevel, bold) => {
41
+ return this.composeStyleString({
42
+ color: '#ffffff',
43
+ 'background-color': this.getLogLevelColor(logLevel),
44
+ 'font-weight': bold ? 'bold' : 'normal',
45
+ padding: '2px 5px',
46
+ 'border-radius': '4px 0 0 4px',
47
+ });
48
+ };
49
+ this.getTimestampStyling = (bold, logLevel) => {
50
+ return this.composeStyleString({
51
+ color: '#ffffff',
52
+ 'background-color': this.getLogLevelColor(logLevel),
53
+ 'font-weight': bold ? 'bold' : 'normal',
54
+ padding: '2px 5px',
55
+ 'border-radius': '0 4px 4px 0',
56
+ });
57
+ };
58
+ this.getTagStyling = (logLevel, bold) => {
59
+ return this.composeStyleString({
60
+ color: this.getLogLevelColor(logLevel),
61
+ 'font-weight': bold ? 'bold' : 'normal',
62
+ padding: '2px 5px',
63
+ });
64
+ };
65
+ this.setComposer(this.newComposer);
66
+ }
67
+ // ################## Class Methods - Logging ##################
68
+ newComposer(tag, level) {
69
+ LogClient_1._logger_finalDate.setTime(Date.now() - LogClient_1._logger_timezoneOffset);
70
+ const date = LogClient_1._logger_finalDate.toISOString().replace(/T/, '_').replace(/Z/, '').substring(0, 23);
71
+ return `%c${(0, LogClient_1._logger_getPrefix)(level)}%c${date}%c${tag}`;
72
+ }
73
+ logMessage(level, bold, prefix, toLog) {
74
+ if (!prefix.startsWith('%c'))
75
+ prefix = `%c ${prefix}`;
76
+ //If the first log param is a primitive combine it with the prefix
77
+ if (PrimitiveLogParams.includes(typeof toLog[0])) {
78
+ prefix += ` ${toLog[0]}`;
79
+ toLog.shift();
80
+ }
81
+ //If no more items to log
82
+ if (!toLog.length)
83
+ return this.logSingle(level, bold, prefix);
84
+ this.logGroup(level, bold, prefix, toLog);
85
+ }
86
+ }
87
+ exports.LogClient_BrowserGroups = new LogClient_BrowserGroups_Class();
package/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './core/logger/BeLogged';
15
15
  export * from './core/logger/Logger';
16
16
  export * from './core/logger/types';
17
17
  export * from './core/logger/LogClient';
18
+ export * from './core/logger/LogClient_BrowserGroups';
18
19
  export * from './db/consts';
19
20
  export * from './db/types';
20
21
  export * from './tools/Replacer';
package/index.js CHANGED
@@ -48,6 +48,7 @@ __exportStar(require("./core/logger/BeLogged"), exports);
48
48
  __exportStar(require("./core/logger/Logger"), exports);
49
49
  __exportStar(require("./core/logger/types"), exports);
50
50
  __exportStar(require("./core/logger/LogClient"), exports);
51
+ __exportStar(require("./core/logger/LogClient_BrowserGroups"), exports);
51
52
  __exportStar(require("./db/consts"), exports);
52
53
  __exportStar(require("./db/types"), exports);
53
54
  __exportStar(require("./tools/Replacer"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.202.113",
3
+ "version": "0.202.115",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",