@sasjs/utils 3.6.6 → 3.7.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/logger/logger.d.ts +9 -2
- package/logger/logger.js +25 -39
- package/logger/logger.js.map +1 -1
- package/package.json +1 -3
package/logger/logger.d.ts
CHANGED
|
@@ -11,9 +11,16 @@ export declare class Logger {
|
|
|
11
11
|
warn: (message: string, ...args: any) => void;
|
|
12
12
|
error: (message: string, ...args: any) => void;
|
|
13
13
|
log: (message: string, ...args: any) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Prints rows as aligned columns, separated by two spaces. When `head` is
|
|
16
|
+
* given it is printed first, underlined with dashes.
|
|
17
|
+
*
|
|
18
|
+
* Cells may carry colour codes, which occupy no screen columns, so column
|
|
19
|
+
* widths are measured on the text with the codes removed.
|
|
20
|
+
*/
|
|
14
21
|
table: (data: string[][], options?: {
|
|
15
|
-
chars?: {} | undefined;
|
|
16
22
|
head?: string[] | undefined;
|
|
17
|
-
} | undefined
|
|
23
|
+
} | undefined) => void;
|
|
24
|
+
private visibleLength;
|
|
18
25
|
private filterArgs;
|
|
19
26
|
}
|
package/logger/logger.js
CHANGED
|
@@ -8,8 +8,6 @@ const consola_1 = require("consola");
|
|
|
8
8
|
const isLowerThanOrEqualTo_1 = require("./isLowerThanOrEqualTo");
|
|
9
9
|
const isNullOrUndefined_1 = require("./isNullOrUndefined");
|
|
10
10
|
const logLevel_1 = require("./logLevel");
|
|
11
|
-
const formatter_1 = require("../formatter");
|
|
12
|
-
const cli_table_1 = __importDefault(require("cli-table"));
|
|
13
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
12
|
class Logger {
|
|
15
13
|
constructor(logLevel) {
|
|
@@ -47,45 +45,30 @@ class Logger {
|
|
|
47
45
|
this.log = (message, ...args) => {
|
|
48
46
|
consola_1.consola.log(message, ...this.filterArgs(args));
|
|
49
47
|
};
|
|
50
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Prints rows as aligned columns, separated by two spaces. When `head` is
|
|
50
|
+
* given it is printed first, underlined with dashes.
|
|
51
|
+
*
|
|
52
|
+
* Cells may carry colour codes, which occupy no screen columns, so column
|
|
53
|
+
* widths are measured on the text with the codes removed.
|
|
54
|
+
*/
|
|
55
|
+
this.table = (data, options) => {
|
|
51
56
|
var _a;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'mid-mid': '┼',
|
|
66
|
-
right: '║',
|
|
67
|
-
'right-mid': '╢',
|
|
68
|
-
middle: '│'
|
|
69
|
-
},
|
|
70
|
-
head: []
|
|
71
|
-
};
|
|
72
|
-
let table;
|
|
73
|
-
if (options && Object.keys(options).length) {
|
|
74
|
-
table = new cli_table_1.default({
|
|
75
|
-
chars: options.chars || defaultOptions.chars,
|
|
76
|
-
head: ((_a = options.head) === null || _a === void 0 ? void 0 : _a.map((header) => chalk_1.default.white.bold(header))) ||
|
|
77
|
-
defaultOptions.head
|
|
78
|
-
});
|
|
57
|
+
const head = (_a = options === null || options === void 0 ? void 0 : options.head) === null || _a === void 0 ? void 0 : _a.map((header) => chalk_1.default.white.bold(header));
|
|
58
|
+
const rows = (head === null || head === void 0 ? void 0 : head.length) ? [head, ...data] : data;
|
|
59
|
+
const widths = [];
|
|
60
|
+
rows.forEach((row) => row.forEach((cell, column) => {
|
|
61
|
+
widths[column] = Math.max(widths[column] || 0, this.visibleLength(cell));
|
|
62
|
+
}));
|
|
63
|
+
const lines = rows.map((row) => row
|
|
64
|
+
.map((cell, column) => cell +
|
|
65
|
+
' '.repeat(Math.max(0, widths[column] - this.visibleLength(cell))))
|
|
66
|
+
.join(' ')
|
|
67
|
+
.trimEnd());
|
|
68
|
+
if (head === null || head === void 0 ? void 0 : head.length) {
|
|
69
|
+
lines.splice(1, 0, widths.map((width) => '-'.repeat(width)).join(' '));
|
|
79
70
|
}
|
|
80
|
-
|
|
81
|
-
table = new cli_table_1.default({
|
|
82
|
-
chars: defaultOptions.chars
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
data.forEach((item) => table.push(item));
|
|
86
|
-
this.log((disableStyling
|
|
87
|
-
? (0, formatter_1.sanitizeSpecialChars)(table.toString())
|
|
88
|
-
: table.toString()) + '\n');
|
|
71
|
+
this.log(lines.join('\n') + '\n');
|
|
89
72
|
};
|
|
90
73
|
if (!(0, isNullOrUndefined_1.isNullOrUndefined)(logLevel) && logLevel in logLevel_1.LogLevel) {
|
|
91
74
|
this._logLevel = logLevel;
|
|
@@ -97,6 +80,9 @@ class Logger {
|
|
|
97
80
|
set logLevel(value) {
|
|
98
81
|
this._logLevel = value;
|
|
99
82
|
}
|
|
83
|
+
visibleLength(value) {
|
|
84
|
+
return String(value).replace(/\u001b\[[0-9;]*m/g, '').length;
|
|
85
|
+
}
|
|
100
86
|
filterArgs(args) {
|
|
101
87
|
return args.filter((arg) => (arg ? arg : false));
|
|
102
88
|
}
|
package/logger/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAiC;AACjC,iEAA6D;AAC7D,2DAAuD;AACvD,yCAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAiC;AACjC,iEAA6D;AAC7D,2DAAuD;AACvD,yCAAqC;AACrC,kDAAyB;AAEzB,MAAa,MAAM;IACjB,YAAY,QAAmB;QAcvB,cAAS,GAAa,mBAAQ,CAAC,KAAK,CAAA;QAE5C,UAAK,GAAG,CAAC,OAAe,EAAE,GAAG,IAAS,EAAQ,EAAE;YAC9C,IAAI,IAAA,2CAAoB,EAAC,IAAI,CAAC,S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E,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IACvD,CAAC;CACF;AAtGD,wBAsGC"}
|
package/package.json
CHANGED
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"@sasjs/core": "5.3.0",
|
|
57
57
|
"@semantic-release/exec": "6.0.3",
|
|
58
58
|
"@semantic-release/git": "10.0.1",
|
|
59
|
-
"@types/cli-table": "0.3.4",
|
|
60
59
|
"@types/jest": "29.4.0",
|
|
61
60
|
"babel-jest": "29.4.3",
|
|
62
61
|
"jest": "29.4.3",
|
|
@@ -72,11 +71,10 @@
|
|
|
72
71
|
"@types/fs-extra": "11.0.4",
|
|
73
72
|
"@types/prompts": "2.4.9",
|
|
74
73
|
"chalk": "4.1.1",
|
|
75
|
-
"cli-table": "0.3.11",
|
|
76
74
|
"consola": "3.4.2",
|
|
77
75
|
"fs-extra": "11.4.1",
|
|
78
76
|
"jwt-decode": "4.0.0",
|
|
79
77
|
"prompts": "2.4.2"
|
|
80
78
|
},
|
|
81
|
-
"version": "3.
|
|
79
|
+
"version": "3.7.0"
|
|
82
80
|
}
|