1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getColumn = exports.pad = exports.removeStyles = exports.maxTableColumnLength = exports.getBrowserStyle = exports.ANSICodes = exports.stringColorToAnsiColor = exports.SetLoggerEnvironment = exports.defaultLogTableOptions = exports.isBrowser = void 0;
|
4 | var s_color_1 = require("s.color");
|
5 | exports.isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
6 | exports.defaultLogTableOptions = { padding: 0, spacing: 1 };
|
7 |
|
8 |
|
9 |
|
10 | function SetLoggerEnvironment(env) {
|
11 | exports.isBrowser = env === 'browser';
|
12 | }
|
13 | exports.SetLoggerEnvironment = SetLoggerEnvironment;
|
14 | function stringColorToAnsiColor(type, color) {
|
15 | if (!color) {
|
16 | return undefined;
|
17 | }
|
18 | var _a = s_color_1.StringToRGB(color, true), r = _a.r, g = _a.g, b = _a.b;
|
19 | return ANSICodes(type) + "2;" + r + ";" + g + ";" + b + ";";
|
20 | }
|
21 | exports.stringColorToAnsiColor = stringColorToAnsiColor;
|
22 | function ANSICodes(type) {
|
23 | switch (type) {
|
24 | case 'reset':
|
25 | return '0';
|
26 | case 'bold':
|
27 | return '1;';
|
28 | case 'color':
|
29 | return '38;';
|
30 | case 'background':
|
31 | return '48;';
|
32 | }
|
33 | }
|
34 | exports.ANSICodes = ANSICodes;
|
35 | function getBrowserStyle(style) {
|
36 | if (style == undefined)
|
37 | return '';
|
38 | if (typeof style === 'string') {
|
39 | return "color: " + style + ";";
|
40 | }
|
41 | var out = '';
|
42 | for (var key in style) {
|
43 | if (Object.prototype.hasOwnProperty.call(style, key)) {
|
44 | out += key + ": " + style[key] + "; ";
|
45 | }
|
46 | }
|
47 | return out;
|
48 | }
|
49 | exports.getBrowserStyle = getBrowserStyle;
|
50 | function maxTableColumnLength(column) {
|
51 | var max = 0;
|
52 | for (var i = 0; i < column.length; i++) {
|
53 | var field = column[i];
|
54 | if (field) {
|
55 | var length_1 = removeStyles(typeof field === 'object' ? field.message : field).length;
|
56 | max = length_1 > max ? length_1 : max;
|
57 | }
|
58 | }
|
59 | return max;
|
60 | }
|
61 | exports.maxTableColumnLength = maxTableColumnLength;
|
62 | function removeStyles(item) {
|
63 | return item.toString().replace(/[\033\x1b\u001b]\[.*?m/g, '');
|
64 | }
|
65 | exports.removeStyles = removeStyles;
|
66 | function pad(text, start, end) {
|
67 | var space = function (amount) { return ' '.repeat(amount); };
|
68 | return "" + space(start) + text + space(end);
|
69 | }
|
70 | exports.pad = pad;
|
71 | function getColumn(matrix, col) {
|
72 | return matrix.map(function (row) { return row[col]; });
|
73 | }
|
74 | exports.getColumn = getColumn;
|