@yamato-daiwa/es-extensions-nodejs 0.0.2 → 0.10.0-alpha.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/Distributable/ConsoleApplicationLogger.d.ts +68 -0
- package/Distributable/ConsoleApplicationLogger.js +435 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.d.ts +289 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.js +702 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.d.ts +4 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.js +118 -0
- package/Distributable/DateTime/NodeJS_Timer.d.ts +21 -7
- package/Distributable/DateTime/NodeJS_Timer.js +61 -13
- package/Distributable/DotEnvFilesGenerator.d.ts +13 -0
- package/Distributable/DotEnvFilesGenerator.js +21 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundError.d.ts +25 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundError.js +21 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundErrorLocalization.english.js +7 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandError.d.ts +25 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandError.js +21 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.js +7 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.d.ts +25 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.js +21 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english.js +7 -0
- package/Distributable/ImprovedFileSystem.d.ts +43 -0
- package/Distributable/ImprovedFileSystem.js +142 -0
- package/Distributable/ImprovedGlob.d.ts +57 -0
- package/Distributable/ImprovedGlob.js +275 -0
- package/Distributable/ImprovedPath/ImprovedPath.d.ts +59 -0
- package/Distributable/ImprovedPath/ImprovedPath.js +224 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessor.d.ts +55 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessor.js +228 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.d.ts +4 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.js +11 -0
- package/Distributable/Temporary/appendCharacterIfItDoesNotPresentInLastPosition.d.ts +4 -0
- package/Distributable/Temporary/appendCharacterIfItDoesNotPresentInLastPosition.js +7 -0
- package/Distributable/Temporary/extractLastExtensionOfFileName.d.ts +9 -0
- package/Distributable/Temporary/extractLastExtensionOfFileName.js +21 -0
- package/Distributable/index.d.ts +22 -7
- package/Distributable/index.js +45 -7
- package/Distributable/isErrnoException.d.ts +2 -0
- package/Distributable/isErrnoException.js +12 -0
- package/LICENSE +1 -1
- package/README.md +51 -3
- package/package.json +45 -15
- package/tsconfig.test.json +0 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type ILogger, type Logger, type ErrorLog, type ThrownErrorLog, type InfoLog, type SuccessLog, type WarningLog, type Log } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
declare abstract class ConsoleApplicationLogger {
|
|
3
|
+
protected static localization: Logger.Localization;
|
|
4
|
+
static setLocalization(localization: Logger.Localization): typeof ConsoleApplicationLogger;
|
|
5
|
+
static throwErrorWithFormattedMessage<CustomError extends Error>(thrownErrorLog: ThrownErrorLog<CustomError>, options?: ILogger.ThrowingErrorWithFormattedMessage.Options): never;
|
|
6
|
+
static logError(polymorphicPayload: ErrorLog | string): void;
|
|
7
|
+
static logErrorLikeMessage(polymorphicPayload: Log | string): void;
|
|
8
|
+
static logWarning(polymorphicPayload: WarningLog | string): void;
|
|
9
|
+
static logInfo(polymorphicPayload: InfoLog | string): void;
|
|
10
|
+
static logSuccess(polymorphicPayload: SuccessLog | string): void;
|
|
11
|
+
static logDebug(polymorphicPayload: Log | string | number | bigint | boolean | null | undefined): void;
|
|
12
|
+
static logGeneric(polymorphicPayload: Log | string | number | bigint | boolean | null | undefined): void;
|
|
13
|
+
static highlightText(targetString: string): string;
|
|
14
|
+
static generateFormattedErrorFromThrownErrorLog(thrownErrorLog: ThrownErrorLog, stringifiedInnerError?: string): string;
|
|
15
|
+
static formatErrorLog(errorLog: ErrorLog): Array<string>;
|
|
16
|
+
static formatGenericLog({ genericLog, badgeContentAndFormatting, mainColor, titleColor }: Readonly<{
|
|
17
|
+
genericLog: Log;
|
|
18
|
+
badgeContentAndFormatting: Readonly<{
|
|
19
|
+
defaultText: string;
|
|
20
|
+
foregroundColor: ConsoleApplicationLogger.RedGreenBlue;
|
|
21
|
+
backgroundColor: ConsoleApplicationLogger.RedGreenBlue;
|
|
22
|
+
}>;
|
|
23
|
+
mainColor: ConsoleApplicationLogger.RedGreenBlue;
|
|
24
|
+
titleColor: ConsoleApplicationLogger.RedGreenBlue;
|
|
25
|
+
}>): Array<string>;
|
|
26
|
+
static generateBadgeIfMust(badge: Readonly<{
|
|
27
|
+
customText: string;
|
|
28
|
+
}> | false | undefined, { defaultText, foregroundColor, backgroundColor }: Readonly<{
|
|
29
|
+
defaultText: string;
|
|
30
|
+
foregroundColor: ConsoleApplicationLogger.RedGreenBlue;
|
|
31
|
+
backgroundColor: ConsoleApplicationLogger.RedGreenBlue;
|
|
32
|
+
}>): [string | null, ConsoleApplicationLogger.Formatting];
|
|
33
|
+
static generateConsoleMethodParametersForFormattedOutput(formattedOutputData: ConsoleApplicationLogger.FormattedOutputData): Array<string>;
|
|
34
|
+
static generateRedGreenBlueForegroundColorControlSequence(colorDefinition: ConsoleApplicationLogger.RedGreenBlue): string;
|
|
35
|
+
static generateRedGreenBlueBackgroundColorControlSequence(colorDefinition: ConsoleApplicationLogger.RedGreenBlue): string;
|
|
36
|
+
}
|
|
37
|
+
declare namespace ConsoleApplicationLogger {
|
|
38
|
+
type FormattedOutputData = Array<[string | null, Formatting]>;
|
|
39
|
+
type Formatting = {
|
|
40
|
+
foregroundColor?: FourBitColours | RedGreenBlue;
|
|
41
|
+
bold?: boolean;
|
|
42
|
+
bright?: boolean;
|
|
43
|
+
dim?: boolean;
|
|
44
|
+
underscore?: boolean;
|
|
45
|
+
blink?: boolean;
|
|
46
|
+
reverse?: boolean;
|
|
47
|
+
hidden?: boolean;
|
|
48
|
+
underlined?: boolean;
|
|
49
|
+
backgroundColor?: FourBitColours | RedGreenBlue;
|
|
50
|
+
};
|
|
51
|
+
enum FourBitColours {
|
|
52
|
+
black = "BLACK",
|
|
53
|
+
white = "WHITE",
|
|
54
|
+
red = "RED",
|
|
55
|
+
green = "GREEN",
|
|
56
|
+
blue = "BLUE",
|
|
57
|
+
yellow = "YELLOW",
|
|
58
|
+
magenta = "MAGENTA",
|
|
59
|
+
cyan = "CYAN"
|
|
60
|
+
}
|
|
61
|
+
type RedGreenBlue = {
|
|
62
|
+
red: number;
|
|
63
|
+
green: number;
|
|
64
|
+
blue: number;
|
|
65
|
+
};
|
|
66
|
+
function isRegGreenBlue(rawValue: unknown): rawValue is RedGreenBlue;
|
|
67
|
+
}
|
|
68
|
+
export default ConsoleApplicationLogger;
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
4
|
+
class ConsoleApplicationLogger {
|
|
5
|
+
static localization = es_extensions_1.loggerLocalization__english;
|
|
6
|
+
static setLocalization(localization) {
|
|
7
|
+
ConsoleApplicationLogger.localization = localization;
|
|
8
|
+
return ConsoleApplicationLogger;
|
|
9
|
+
}
|
|
10
|
+
static throwErrorWithFormattedMessage(thrownErrorLog, options = {}) {
|
|
11
|
+
let stringifiedInnerError;
|
|
12
|
+
if ((0, es_extensions_1.isNotUndefined)(thrownErrorLog.innerError)) {
|
|
13
|
+
stringifiedInnerError = (0, es_extensions_1.stringifyAndFormatArbitraryValue)(thrownErrorLog.innerError);
|
|
14
|
+
if (thrownErrorLog.innerError instanceof Error && (0, es_extensions_1.isNonEmptyString)(thrownErrorLog.innerError.stack)) {
|
|
15
|
+
stringifiedInnerError = thrownErrorLog.innerError.stack.includes(stringifiedInnerError) ?
|
|
16
|
+
thrownErrorLog.innerError.stack :
|
|
17
|
+
`${stringifiedInnerError}\n${thrownErrorLog.innerError.stack}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const errorMessage = ConsoleApplicationLogger.
|
|
21
|
+
generateFormattedErrorFromThrownErrorLog(thrownErrorLog, stringifiedInnerError);
|
|
22
|
+
if ("errorInstance" in thrownErrorLog) {
|
|
23
|
+
thrownErrorLog.errorInstance.message = errorMessage;
|
|
24
|
+
throw thrownErrorLog.errorInstance;
|
|
25
|
+
}
|
|
26
|
+
const errorWillBeThrown = new Error(errorMessage);
|
|
27
|
+
errorWillBeThrown.name = thrownErrorLog.errorType;
|
|
28
|
+
if (options.mustLogErrorBeforeThrowing === true) {
|
|
29
|
+
ConsoleApplicationLogger.logErrorLikeMessage({
|
|
30
|
+
title: errorWillBeThrown.name,
|
|
31
|
+
description: errorWillBeThrown.message
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
throw errorWillBeThrown;
|
|
35
|
+
}
|
|
36
|
+
static logError(polymorphicPayload) {
|
|
37
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload)) {
|
|
38
|
+
console.error(polymorphicPayload);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.error(...ConsoleApplicationLogger.formatErrorLog(polymorphicPayload));
|
|
45
|
+
}
|
|
46
|
+
static logErrorLikeMessage(polymorphicPayload) {
|
|
47
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload)) {
|
|
48
|
+
console.error(polymorphicPayload);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
console.error(...ConsoleApplicationLogger.formatGenericLog({
|
|
55
|
+
genericLog: polymorphicPayload,
|
|
56
|
+
badgeContentAndFormatting: {
|
|
57
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.error,
|
|
58
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
59
|
+
backgroundColor: { red: 192, green: 57, blue: 43 }
|
|
60
|
+
},
|
|
61
|
+
mainColor: { red: 231, green: 76, blue: 60 },
|
|
62
|
+
titleColor: { red: 192, green: 57, blue: 43 }
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
static logWarning(polymorphicPayload) {
|
|
66
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload)) {
|
|
67
|
+
console.error(polymorphicPayload);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
console.warn(...ConsoleApplicationLogger.formatGenericLog({
|
|
74
|
+
genericLog: polymorphicPayload,
|
|
75
|
+
badgeContentAndFormatting: {
|
|
76
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.warning,
|
|
77
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
78
|
+
backgroundColor: { red: 211, green: 84, blue: 0 }
|
|
79
|
+
},
|
|
80
|
+
mainColor: { red: 230, green: 126, blue: 34 },
|
|
81
|
+
titleColor: { red: 211, green: 84, blue: 0 }
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
static logInfo(polymorphicPayload) {
|
|
85
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload)) {
|
|
86
|
+
console.error(polymorphicPayload);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
console.log(...ConsoleApplicationLogger.formatGenericLog({
|
|
93
|
+
genericLog: polymorphicPayload,
|
|
94
|
+
badgeContentAndFormatting: {
|
|
95
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.info,
|
|
96
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
97
|
+
backgroundColor: { red: 41, green: 128, blue: 185 }
|
|
98
|
+
},
|
|
99
|
+
mainColor: { red: 52, green: 152, blue: 219 },
|
|
100
|
+
titleColor: { red: 41, green: 128, blue: 185 }
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
static logSuccess(polymorphicPayload) {
|
|
104
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload)) {
|
|
105
|
+
console.error(polymorphicPayload);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
console.log(...ConsoleApplicationLogger.formatGenericLog({
|
|
112
|
+
genericLog: polymorphicPayload,
|
|
113
|
+
badgeContentAndFormatting: {
|
|
114
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.success,
|
|
115
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
116
|
+
backgroundColor: { red: 39, green: 174, blue: 96 }
|
|
117
|
+
},
|
|
118
|
+
mainColor: { red: 46, green: 204, blue: 113 },
|
|
119
|
+
titleColor: { red: 39, green: 174, blue: 96 }
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
static logDebug(polymorphicPayload) {
|
|
123
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload) ||
|
|
124
|
+
(0, es_extensions_1.isNumber)(polymorphicPayload, { mustConsiderNaN_AsNumber: true }) ||
|
|
125
|
+
(0, es_extensions_1.isBigInt)(polymorphicPayload) ||
|
|
126
|
+
(0, es_extensions_1.isBoolean)(polymorphicPayload) ||
|
|
127
|
+
(0, es_extensions_1.isNull)(polymorphicPayload) ||
|
|
128
|
+
(0, es_extensions_1.isUndefined)(polymorphicPayload)) {
|
|
129
|
+
console.debug(polymorphicPayload);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
console.debug(...ConsoleApplicationLogger.formatGenericLog({
|
|
136
|
+
genericLog: polymorphicPayload,
|
|
137
|
+
badgeContentAndFormatting: {
|
|
138
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.debug,
|
|
139
|
+
foregroundColor: { red: 0, green: 0, blue: 0 },
|
|
140
|
+
backgroundColor: { red: 255, green: 255, blue: 255 }
|
|
141
|
+
},
|
|
142
|
+
mainColor: { red: 255, green: 255, blue: 255 },
|
|
143
|
+
titleColor: { red: 255, green: 255, blue: 255 }
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
static logGeneric(polymorphicPayload) {
|
|
147
|
+
if ((0, es_extensions_1.isString)(polymorphicPayload) ||
|
|
148
|
+
(0, es_extensions_1.isNumber)(polymorphicPayload, { mustConsiderNaN_AsNumber: true }) ||
|
|
149
|
+
(0, es_extensions_1.isBigInt)(polymorphicPayload) ||
|
|
150
|
+
(0, es_extensions_1.isBoolean)(polymorphicPayload) ||
|
|
151
|
+
(0, es_extensions_1.isNull)(polymorphicPayload) ||
|
|
152
|
+
(0, es_extensions_1.isUndefined)(polymorphicPayload)) {
|
|
153
|
+
console.log(polymorphicPayload);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (polymorphicPayload.mustOutputIf === false) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
console.log(...ConsoleApplicationLogger.formatGenericLog({
|
|
160
|
+
genericLog: polymorphicPayload,
|
|
161
|
+
badgeContentAndFormatting: {
|
|
162
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.generic,
|
|
163
|
+
foregroundColor: { red: 0, green: 0, blue: 0 },
|
|
164
|
+
backgroundColor: { red: 255, green: 255, blue: 255 }
|
|
165
|
+
},
|
|
166
|
+
mainColor: { red: 255, green: 255, blue: 255 },
|
|
167
|
+
titleColor: { red: 255, green: 255, blue: 255 }
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
static highlightText(targetString) {
|
|
171
|
+
return `\x1b[43m${targetString}\x1b[49m`;
|
|
172
|
+
}
|
|
173
|
+
static generateFormattedErrorFromThrownErrorLog(thrownErrorLog, stringifiedInnerError) {
|
|
174
|
+
return [
|
|
175
|
+
ConsoleApplicationLogger.generateRedGreenBlueForegroundColorControlSequence({ red: 231, green: 76, blue: 60 }),
|
|
176
|
+
"\x1b[1m",
|
|
177
|
+
thrownErrorLog.title,
|
|
178
|
+
"\x1b[22m",
|
|
179
|
+
...thrownErrorLog.compactLayout === true ? [" "] : ["\n"],
|
|
180
|
+
..."errorInstance" in thrownErrorLog ?
|
|
181
|
+
[thrownErrorLog.errorInstance.message] :
|
|
182
|
+
[thrownErrorLog.description],
|
|
183
|
+
`\n\n${ConsoleApplicationLogger.localization.occurrenceLocation}: ${thrownErrorLog.occurrenceLocation}`,
|
|
184
|
+
...(0, es_extensions_1.isNotUndefined)(stringifiedInnerError) ?
|
|
185
|
+
[`\n\n${ConsoleApplicationLogger.localization.innerError}:\n${stringifiedInnerError}`] : [],
|
|
186
|
+
...(0, es_extensions_1.isNotUndefined)(thrownErrorLog.additionalData) ?
|
|
187
|
+
[
|
|
188
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:` +
|
|
189
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(thrownErrorLog.additionalData)}`
|
|
190
|
+
] :
|
|
191
|
+
[],
|
|
192
|
+
"\x1b[0m",
|
|
193
|
+
"\n"
|
|
194
|
+
].join("");
|
|
195
|
+
}
|
|
196
|
+
static formatErrorLog(errorLog) {
|
|
197
|
+
return ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
198
|
+
ConsoleApplicationLogger.generateBadgeIfMust(errorLog.badge, {
|
|
199
|
+
defaultText: ConsoleApplicationLogger.localization.badgesDefaultTitles.error,
|
|
200
|
+
foregroundColor: { red: 255, green: 255, blue: 255 },
|
|
201
|
+
backgroundColor: { red: 192, green: 57, blue: 43 }
|
|
202
|
+
}),
|
|
203
|
+
[
|
|
204
|
+
`${(0, es_extensions_1.insertSubstringIf)(" ", errorLog.badge !== false)}${errorLog.title}`,
|
|
205
|
+
{ bold: true, foregroundColor: { red: 192, green: 57, blue: 43 } }
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
`${errorLog.compactLayout === true ? " " : "\n"}${errorLog.description}`,
|
|
209
|
+
{ foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
`\n\n${ConsoleApplicationLogger.localization.errorType}: `,
|
|
213
|
+
{ bold: true, foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
214
|
+
],
|
|
215
|
+
[
|
|
216
|
+
errorLog.errorType,
|
|
217
|
+
{ foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
218
|
+
],
|
|
219
|
+
[
|
|
220
|
+
`\n${ConsoleApplicationLogger.localization.occurrenceLocation}: `,
|
|
221
|
+
{ bold: true, foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
errorLog.occurrenceLocation,
|
|
225
|
+
{ foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
226
|
+
],
|
|
227
|
+
...("caughtError" in errorLog ? [
|
|
228
|
+
[
|
|
229
|
+
`\n\n${ConsoleApplicationLogger.localization.caughtError}:`,
|
|
230
|
+
{ bold: true, foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
(() => {
|
|
234
|
+
let stringifiedInnerError = (0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLog.caughtError);
|
|
235
|
+
if (errorLog.caughtError instanceof Error && (0, es_extensions_1.isNotUndefined)(errorLog.caughtError.stack)) {
|
|
236
|
+
stringifiedInnerError = errorLog.caughtError.stack.includes(stringifiedInnerError) ?
|
|
237
|
+
errorLog.caughtError.stack :
|
|
238
|
+
`${stringifiedInnerError}\n${errorLog.caughtError.stack}`;
|
|
239
|
+
}
|
|
240
|
+
return `\n${stringifiedInnerError}`;
|
|
241
|
+
})(),
|
|
242
|
+
{ foregroundColor: { red: 231, green: 76, blue: 60 } }
|
|
243
|
+
]
|
|
244
|
+
] : []),
|
|
245
|
+
...("additionalData" in errorLog ? [
|
|
246
|
+
[
|
|
247
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
248
|
+
{
|
|
249
|
+
bold: true,
|
|
250
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
[
|
|
254
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(errorLog.additionalData)}`,
|
|
255
|
+
{
|
|
256
|
+
foregroundColor: { red: 231, green: 76, blue: 60 }
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
] : [])
|
|
260
|
+
]);
|
|
261
|
+
}
|
|
262
|
+
static formatGenericLog({ genericLog, badgeContentAndFormatting, mainColor, titleColor }) {
|
|
263
|
+
return ConsoleApplicationLogger.generateConsoleMethodParametersForFormattedOutput([
|
|
264
|
+
ConsoleApplicationLogger.generateBadgeIfMust(genericLog.badge, badgeContentAndFormatting),
|
|
265
|
+
[
|
|
266
|
+
`${(0, es_extensions_1.insertSubstringIf)(" ", genericLog.badge !== false)}${genericLog.title}`,
|
|
267
|
+
{ foregroundColor: titleColor, bold: true }
|
|
268
|
+
],
|
|
269
|
+
[
|
|
270
|
+
`${genericLog.compactLayout === true ? " " : "\n"}${genericLog.description}`,
|
|
271
|
+
{ foregroundColor: mainColor }
|
|
272
|
+
],
|
|
273
|
+
...("additionalData" in genericLog ? [
|
|
274
|
+
[
|
|
275
|
+
`\n\n${ConsoleApplicationLogger.localization.appendedData}:`,
|
|
276
|
+
{ bold: true, foregroundColor: mainColor }
|
|
277
|
+
],
|
|
278
|
+
[
|
|
279
|
+
`\n${(0, es_extensions_1.stringifyAndFormatArbitraryValue)(genericLog.additionalData)}`,
|
|
280
|
+
{ foregroundColor: mainColor }
|
|
281
|
+
]
|
|
282
|
+
] : [])
|
|
283
|
+
]);
|
|
284
|
+
}
|
|
285
|
+
static generateBadgeIfMust(badge, { defaultText, foregroundColor, backgroundColor }) {
|
|
286
|
+
return [
|
|
287
|
+
badge === false ? null : ` ${badge?.customText ?? defaultText} `,
|
|
288
|
+
{
|
|
289
|
+
bold: true,
|
|
290
|
+
foregroundColor,
|
|
291
|
+
backgroundColor
|
|
292
|
+
}
|
|
293
|
+
];
|
|
294
|
+
}
|
|
295
|
+
static generateConsoleMethodParametersForFormattedOutput(formattedOutputData) {
|
|
296
|
+
const logsTextings = [];
|
|
297
|
+
const templatesWithFormattings = [];
|
|
298
|
+
for (const singleFormattedOutputData of formattedOutputData) {
|
|
299
|
+
if ((0, es_extensions_1.isNull)(singleFormattedOutputData[0])) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
let templateWithFormatting = "";
|
|
303
|
+
const formatting = singleFormattedOutputData[1];
|
|
304
|
+
switch (formatting.foregroundColor) {
|
|
305
|
+
case ConsoleApplicationLogger.FourBitColours.black: {
|
|
306
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[30m`;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
case ConsoleApplicationLogger.FourBitColours.red: {
|
|
310
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[31m`;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case ConsoleApplicationLogger.FourBitColours.green: {
|
|
314
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[32m`;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case ConsoleApplicationLogger.FourBitColours.yellow: {
|
|
318
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[33m`;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case ConsoleApplicationLogger.FourBitColours.blue: {
|
|
322
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[34m`;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
case ConsoleApplicationLogger.FourBitColours.magenta: {
|
|
326
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[35m`;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
case ConsoleApplicationLogger.FourBitColours.cyan: {
|
|
330
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[36m`;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
case ConsoleApplicationLogger.FourBitColours.white: {
|
|
334
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[37m`;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
default: {
|
|
338
|
+
if (ConsoleApplicationLogger.isRegGreenBlue(formatting.foregroundColor)) {
|
|
339
|
+
templateWithFormatting = `${templateWithFormatting}${ConsoleApplicationLogger.generateRedGreenBlueForegroundColorControlSequence(formatting.foregroundColor)}`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
switch (formatting.backgroundColor) {
|
|
344
|
+
case ConsoleApplicationLogger.FourBitColours.black: {
|
|
345
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[40m`;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
case ConsoleApplicationLogger.FourBitColours.red: {
|
|
349
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[41m`;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case ConsoleApplicationLogger.FourBitColours.green: {
|
|
353
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[42m`;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case ConsoleApplicationLogger.FourBitColours.yellow: {
|
|
357
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[43m`;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case ConsoleApplicationLogger.FourBitColours.blue: {
|
|
361
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[44m`;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
case ConsoleApplicationLogger.FourBitColours.magenta: {
|
|
365
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[45m`;
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case ConsoleApplicationLogger.FourBitColours.cyan: {
|
|
369
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[46m`;
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
case ConsoleApplicationLogger.FourBitColours.white: {
|
|
373
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[47m`;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
default: {
|
|
377
|
+
if (ConsoleApplicationLogger.isRegGreenBlue(formatting.backgroundColor)) {
|
|
378
|
+
templateWithFormatting = `${templateWithFormatting}${ConsoleApplicationLogger.generateRedGreenBlueBackgroundColorControlSequence(formatting.backgroundColor)}`;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (formatting.bold === true) {
|
|
383
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[1m`;
|
|
384
|
+
}
|
|
385
|
+
if (formatting.underlined === true || formatting.underscore === true) {
|
|
386
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[4m`;
|
|
387
|
+
}
|
|
388
|
+
if (formatting.bright === true) {
|
|
389
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[1m`;
|
|
390
|
+
}
|
|
391
|
+
if (formatting.dim === true) {
|
|
392
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[2m`;
|
|
393
|
+
}
|
|
394
|
+
if (formatting.blink === true) {
|
|
395
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[5m`;
|
|
396
|
+
}
|
|
397
|
+
if (formatting.reverse === true) {
|
|
398
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[7m`;
|
|
399
|
+
}
|
|
400
|
+
if (formatting.hidden === true) {
|
|
401
|
+
templateWithFormatting = `${templateWithFormatting}\x1b[8m`;
|
|
402
|
+
}
|
|
403
|
+
logsTextings.push(singleFormattedOutputData[0]);
|
|
404
|
+
templatesWithFormattings.push(templateWithFormatting);
|
|
405
|
+
}
|
|
406
|
+
return [`${templatesWithFormattings.join("%s\x1b[0m")}%s\x1b[0m`].concat(logsTextings);
|
|
407
|
+
}
|
|
408
|
+
static generateRedGreenBlueForegroundColorControlSequence(colorDefinition) {
|
|
409
|
+
return `\x1b[38;2;${colorDefinition.red};${colorDefinition.green};${colorDefinition.blue}m`;
|
|
410
|
+
}
|
|
411
|
+
static generateRedGreenBlueBackgroundColorControlSequence(colorDefinition) {
|
|
412
|
+
return `\x1b[48;2;${colorDefinition.red};${colorDefinition.green};${colorDefinition.blue}m`;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
(function (ConsoleApplicationLogger) {
|
|
416
|
+
let FourBitColours;
|
|
417
|
+
(function (FourBitColours) {
|
|
418
|
+
FourBitColours["black"] = "BLACK";
|
|
419
|
+
FourBitColours["white"] = "WHITE";
|
|
420
|
+
FourBitColours["red"] = "RED";
|
|
421
|
+
FourBitColours["green"] = "GREEN";
|
|
422
|
+
FourBitColours["blue"] = "BLUE";
|
|
423
|
+
FourBitColours["yellow"] = "YELLOW";
|
|
424
|
+
FourBitColours["magenta"] = "MAGENTA";
|
|
425
|
+
FourBitColours["cyan"] = "CYAN";
|
|
426
|
+
})(FourBitColours = ConsoleApplicationLogger.FourBitColours || (ConsoleApplicationLogger.FourBitColours = {}));
|
|
427
|
+
function isRegGreenBlue(rawValue) {
|
|
428
|
+
return (0, es_extensions_1.isArbitraryObject)(rawValue) &&
|
|
429
|
+
(0, es_extensions_1.isNaturalNumberOrZero)(rawValue.red) &&
|
|
430
|
+
(0, es_extensions_1.isNaturalNumberOrZero)(rawValue.green) &&
|
|
431
|
+
(0, es_extensions_1.isNaturalNumberOrZero)(rawValue.blue);
|
|
432
|
+
}
|
|
433
|
+
ConsoleApplicationLogger.isRegGreenBlue = isRegGreenBlue;
|
|
434
|
+
})(ConsoleApplicationLogger || (ConsoleApplicationLogger = {}));
|
|
435
|
+
exports.default = ConsoleApplicationLogger;
|