UNPKG

5.13 kBJavaScriptView Raw
1"use strict";
2exports.__esModule = true;
3exports.PushDebugInfo = exports.SetConvertData = exports.SetDebugLOCAL_CONTEXT = exports.ResetDebugLog = exports.LogDebugResult = void 0;
4var suf_log_1 = require("suf-log");
5suf_log_1.SetEnvironment('node');
6var colon = suf_log_1.styler(':', '#777');
7// const quote = styler('"', '#f64');
8var pipe = suf_log_1.styler('|', '#f64');
9var TEXT = function (text) { return suf_log_1.styler(text, '#eee'); };
10var NUMBER = function (number) { return suf_log_1.styler(number.toString(), '#f03'); };
11var BOOL = function (bool) { return suf_log_1.styler(bool.toString(), bool ? '#4f6' : '#f03'); };
12function LogDebugResult(result) {
13 var data = StoreLog.logs;
14 var out = suf_log_1.styler('FORMAT', { "font-weight": 'bold', color: '#0af' });
15 for (var i = 0; i < data.length; i++) {
16 out += '\n';
17 out += InfoLogHelper(data[i]);
18 }
19 out += "\n" + pipe + suf_log_1.styler(replaceWhitespace(result.replace(/\n/g, '|\n|')), '#c76') + pipe;
20 console.log(out);
21}
22exports.LogDebugResult = LogDebugResult;
23function ResetDebugLog() {
24 StoreLog.reset();
25}
26exports.ResetDebugLog = ResetDebugLog;
27var StoreLog = /** @class */ (function () {
28 function StoreLog() {
29 }
30 StoreLog.resetTemp = function () {
31 this.tempConvertData = undefined;
32 this.tempLOCAL_CONTEXT = undefined;
33 };
34 StoreLog.reset = function () {
35 this.resetTemp();
36 this.logs = [];
37 };
38 StoreLog.logs = [];
39 return StoreLog;
40}());
41function SetDebugLOCAL_CONTEXT(data) {
42 StoreLog.tempLOCAL_CONTEXT = data;
43}
44exports.SetDebugLOCAL_CONTEXT = SetDebugLOCAL_CONTEXT;
45function SetConvertData(data) {
46 StoreLog.tempConvertData = data;
47}
48exports.SetConvertData = SetConvertData;
49function PushDebugInfo(info) {
50 if (info.debug) {
51 StoreLog.logs.push({
52 info: info,
53 convertData: StoreLog.tempConvertData,
54 LOCAL_CONTEXT: StoreLog.tempLOCAL_CONTEXT
55 });
56 }
57 StoreLog.resetTemp();
58}
59exports.PushDebugInfo = PushDebugInfo;
60function InfoLogHelper(data) {
61 var convertData = data.convertData, info = data.info, LOCAL_CONTEXT = data.LOCAL_CONTEXT;
62 var notProvided = null;
63 var title = suf_log_1.styler(info.title, '#cc0');
64 var lineNumber = "" + TEXT('Line Number') + colon + " " + NUMBER(info.lineNumber);
65 var offset = info.offset !== undefined ? "" + TEXT('Offset') + colon + " " + NUMBER(info.offset) : '';
66 var originalOffset = info.originalOffset !== undefined ? "" + TEXT('Original Offset') + colon + " " + NUMBER(info.originalOffset) : '';
67 var nextLine = info.nextLine !== undefined
68 ? JSON.stringify(info.nextLine)
69 .replace(/[{}]/g, '')
70 .replace(/:/g, ': ')
71 .replace(/,/g, ', ')
72 .replace(/".*?"/g, function (s) {
73 return suf_log_1.styler(s, '#c76');
74 })
75 : notProvided;
76 var replace = info.replaceSpaceOrTabs !== undefined ? BOOL(info.replaceSpaceOrTabs) : notProvided;
77 var CONVERT = convertData
78 ? "\n " + TEXT('Convert') + " " + colon + " " + suf_log_1.styler(convertData.type, '#f64')
79 : '';
80 var newText = info.newLineText ? "\n " + TEXT('New') + " " + colon + " " + suf_log_1.styler(replaceWhitespace(info.newLineText.replace(/\n/g, '\\n')), '#0af') : '';
81 switch (info.newLineText) {
82 case 'DELETED':
83 return " " + title + " " + lineNumber + " " + TEXT('Next Line') + colon + " " + nextLine;
84 case 'NEWLINE':
85 case 'NULL':
86 return " " + title + " " + lineNumber;
87 default:
88 var data_1 = '';
89 data_1 +=
90 nextLine !== null ? "\n " + TEXT('Next Line') + " " + colon + " " + nextLine : '';
91 data_1 +=
92 replace !== null ? "\n " + TEXT('Replace') + " " + colon + " " + replace : '';
93 if (LOCAL_CONTEXT) {
94 data_1 += "\n " + suf_log_1.styler('LOCAL_CONTEXT', '#f64') + " " + suf_log_1.styler('{', '#777');
95 for (var key in LOCAL_CONTEXT) {
96 if (Object.prototype.hasOwnProperty.call(LOCAL_CONTEXT, key)) {
97 var val = LOCAL_CONTEXT[key];
98 data_1 += "\n " + suf_log_1.styler(key, '#777') + colon + " " + parseValue(val);
99 }
100 }
101 data_1 += suf_log_1.styler('\n }', '#777');
102 }
103 return " " + title + " " + lineNumber + " " + offset + " " + originalOffset + "\n " + TEXT('Old') + " " + colon + " " + suf_log_1.styler(replaceWhitespace(info.oldLineText), '#d75') + newText + CONVERT + data_1;
104 }
105}
106function replaceWhitespace(text) {
107 return text.replace(/ /g, '·').replace(/\t/g, '⟶');
108}
109function parseValue(val) {
110 var type = typeof val;
111 if (type === 'boolean') {
112 return BOOL(val);
113 }
114 else if (type === 'string') {
115 return suf_log_1.styler(val, '#f64');
116 }
117 else if (type === 'object') {
118 return suf_log_1.styler(JSON.stringify(val), '#0af');
119 }
120 return val;
121}