@decaf-ts/logging 0.10.0 → 0.10.2
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/README.md +298 -171
- package/dist/logging.cjs +1 -1
- package/dist/logging.cjs.map +1 -1
- package/dist/logging.js +1 -1
- package/dist/logging.js.map +1 -1
- package/lib/LoggedClass.cjs +4 -4
- package/lib/LoggedClass.d.ts +4 -4
- package/lib/constants.cjs +32 -63
- package/lib/constants.d.ts +32 -63
- package/lib/constants.js.map +1 -1
- package/lib/decorators.cjs +28 -28
- package/lib/decorators.d.ts +29 -36
- package/lib/decorators.js.map +1 -1
- package/lib/environment.cjs +34 -41
- package/lib/environment.d.ts +31 -32
- package/lib/environment.js.map +1 -1
- package/lib/esm/LoggedClass.d.ts +4 -4
- package/lib/esm/LoggedClass.js +4 -4
- package/lib/esm/constants.d.ts +32 -63
- package/lib/esm/constants.js +32 -63
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/decorators.d.ts +29 -36
- package/lib/esm/decorators.js +28 -28
- package/lib/esm/decorators.js.map +1 -1
- package/lib/esm/environment.d.ts +31 -32
- package/lib/esm/environment.js +34 -41
- package/lib/esm/environment.js.map +1 -1
- package/lib/esm/filters/LogFilter.d.ts +11 -11
- package/lib/esm/filters/LogFilter.js +5 -5
- package/lib/esm/filters/PatternFilter.d.ts +15 -15
- package/lib/esm/filters/PatternFilter.js +12 -12
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +3 -3
- package/lib/esm/logging.d.ts +119 -113
- package/lib/esm/logging.js +223 -138
- package/lib/esm/logging.js.map +1 -1
- package/lib/esm/pino/index.d.ts +6 -0
- package/lib/esm/pino/index.js +6 -0
- package/lib/esm/pino/index.js.map +1 -1
- package/lib/esm/pino/pino.d.ts +13 -5
- package/lib/esm/pino/pino.js +70 -124
- package/lib/esm/pino/pino.js.map +1 -1
- package/lib/esm/text.d.ts +29 -67
- package/lib/esm/text.js +29 -67
- package/lib/esm/text.js.map +1 -1
- package/lib/esm/time.d.ts +45 -43
- package/lib/esm/time.js +38 -36
- package/lib/esm/time.js.map +1 -1
- package/lib/esm/types.d.ts +59 -50
- package/lib/esm/utils.d.ts +43 -0
- package/lib/esm/utils.js +55 -3
- package/lib/esm/utils.js.map +1 -1
- package/lib/esm/web.d.ts +2 -2
- package/lib/esm/web.js +2 -2
- package/lib/esm/winston/index.d.ts +7 -0
- package/lib/esm/winston/index.js +7 -1
- package/lib/esm/winston/index.js.map +1 -1
- package/lib/esm/winston/winston.d.ts +17 -21
- package/lib/esm/winston/winston.js +29 -36
- package/lib/esm/winston/winston.js.map +1 -1
- package/lib/filters/LogFilter.cjs +5 -5
- package/lib/filters/LogFilter.d.ts +11 -11
- package/lib/filters/PatternFilter.cjs +12 -12
- package/lib/filters/PatternFilter.d.ts +15 -15
- package/lib/index.cjs +3 -3
- package/lib/index.d.ts +2 -2
- package/lib/logging.cjs +224 -139
- package/lib/logging.d.ts +119 -113
- package/lib/logging.js.map +1 -1
- package/lib/pino/index.cjs +6 -0
- package/lib/pino/index.d.ts +6 -0
- package/lib/pino/index.js.map +1 -1
- package/lib/pino/pino.cjs +102 -126
- package/lib/pino/pino.d.ts +13 -5
- package/lib/pino/pino.js.map +1 -1
- package/lib/text.cjs +29 -67
- package/lib/text.d.ts +29 -67
- package/lib/text.js.map +1 -1
- package/lib/time.cjs +38 -36
- package/lib/time.d.ts +45 -43
- package/lib/time.js.map +1 -1
- package/lib/types.d.ts +59 -50
- package/lib/utils.cjs +55 -3
- package/lib/utils.d.ts +43 -0
- package/lib/utils.js.map +1 -1
- package/lib/web.cjs +2 -2
- package/lib/web.d.ts +2 -2
- package/lib/winston/index.cjs +22 -0
- package/lib/winston/index.d.ts +7 -0
- package/lib/winston/index.js.map +1 -1
- package/lib/winston/winston.cjs +29 -36
- package/lib/winston/winston.d.ts +17 -21
- package/lib/winston/winston.js.map +1 -1
- package/package.json +9 -10
- package/lib/accumulate.types.cjs +0 -27
- package/lib/accumulate.types.d.ts +0 -1
- package/lib/accumulate.types.js.map +0 -1
- package/lib/esm/accumulate.types.d.ts +0 -1
- package/lib/esm/accumulate.types.js +0 -25
- package/lib/esm/accumulate.types.js.map +0 -1
package/lib/esm/pino/index.d.ts
CHANGED
package/lib/esm/pino/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pino/index.ts"],"names":[],"mappings":"AAAA,0BAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pino/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,0BAAuB"}
|
package/lib/esm/pino/pino.d.ts
CHANGED
|
@@ -2,11 +2,17 @@ import { Logger as PinoBaseLogger } from "pino";
|
|
|
2
2
|
import { MiniLogger } from "../logging";
|
|
3
3
|
import { Logger, LoggerFactory, LoggingConfig, StringLike } from "../types";
|
|
4
4
|
import { LogLevel } from "../constants";
|
|
5
|
+
/**
|
|
6
|
+
* @description A logger that is powered by the Pino logging library.
|
|
7
|
+
* @summary This class extends {@link MiniLogger} and uses Pino as its underlying logging engine.
|
|
8
|
+
* @param {string} [context] - The context (typically the class name) that this logger is associated with.
|
|
9
|
+
* @param {Partial<LoggingConfig>} [conf] - Optional configuration to override global settings.
|
|
10
|
+
* @param {PinoBaseLogger} [driver] - An optional, pre-existing Pino logger instance to use.
|
|
11
|
+
* @class PinoLogger
|
|
12
|
+
*/
|
|
5
13
|
export declare class PinoLogger extends MiniLogger implements Logger {
|
|
6
14
|
protected pino: PinoBaseLogger;
|
|
7
|
-
|
|
8
|
-
constructor(context: string, conf?: Partial<LoggingConfig>);
|
|
9
|
-
private activePino;
|
|
15
|
+
constructor(context?: string, conf?: Partial<LoggingConfig>, driver?: PinoBaseLogger);
|
|
10
16
|
protected log(level: LogLevel, msg: StringLike | Error, error?: Error): void;
|
|
11
17
|
fatal(msg: StringLike | Error, error?: Error): void;
|
|
12
18
|
child(bindings?: Record<string, unknown>, options?: Record<string, unknown>): PinoLogger;
|
|
@@ -15,7 +21,9 @@ export declare class PinoLogger extends MiniLogger implements Logger {
|
|
|
15
21
|
set level(value: string | undefined);
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
|
-
* @description
|
|
19
|
-
* @summary
|
|
24
|
+
* @description A factory for creating {@link PinoLogger} instances.
|
|
25
|
+
* @summary This factory function creates a new {@link PinoLogger} instance, and can optionally accept a pre-existing Pino logger instance.
|
|
26
|
+
* @const {LoggerFactory} PinoFactory
|
|
27
|
+
* @memberOf module:Logging
|
|
20
28
|
*/
|
|
21
29
|
export declare const PinoFactory: LoggerFactory;
|
package/lib/esm/pino/pino.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import pino from "pino";
|
|
1
|
+
import pino, { multistream, } from "pino";
|
|
2
2
|
import { Logging, MiniLogger } from "./../logging.js";
|
|
3
|
-
import { LogLevel
|
|
3
|
+
import { LogLevel } from "./../constants.js";
|
|
4
4
|
const LogLevelToPino = {
|
|
5
5
|
[LogLevel.benchmark]: "info",
|
|
6
6
|
[LogLevel.error]: "error",
|
|
@@ -19,106 +19,92 @@ const PinoToLogLevel = {
|
|
|
19
19
|
debug: LogLevel.debug,
|
|
20
20
|
trace: LogLevel.trace,
|
|
21
21
|
};
|
|
22
|
-
const isPinoLogger = (candidate) => {
|
|
23
|
-
if (!candidate || typeof candidate !== "object")
|
|
24
|
-
return false;
|
|
25
|
-
const required = ["info", "error", "warn", "debug", "trace"];
|
|
26
|
-
return required.every((method) => typeof candidate[method] === "function");
|
|
27
|
-
};
|
|
28
22
|
const toPinoLevel = (level) => LogLevelToPino[level] ?? "info";
|
|
29
23
|
const fromPinoLevel = (level) => {
|
|
30
24
|
if (!level)
|
|
31
25
|
return undefined;
|
|
32
26
|
return PinoToLogLevel[level];
|
|
33
27
|
};
|
|
34
|
-
const
|
|
28
|
+
const joinContext = (segments, separator) => {
|
|
29
|
+
if (!segments.length)
|
|
30
|
+
return "Logger";
|
|
31
|
+
return segments.join(separator);
|
|
32
|
+
};
|
|
33
|
+
const buildPinoOptions = (context, config, overrides) => {
|
|
35
34
|
const options = {
|
|
36
35
|
level: toPinoLevel(config.level),
|
|
37
36
|
name: context,
|
|
38
|
-
...
|
|
37
|
+
...overrides,
|
|
39
38
|
};
|
|
40
39
|
if (!options.level)
|
|
41
40
|
options.level = toPinoLevel(config.level);
|
|
42
41
|
if (!options.name)
|
|
43
42
|
options.name = context;
|
|
43
|
+
options.timestamp = config.timestamp
|
|
44
|
+
? () => new Date().toISOString()
|
|
45
|
+
: false;
|
|
44
46
|
return options;
|
|
45
47
|
};
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
return
|
|
49
|
-
return
|
|
50
|
-
...(base || {}),
|
|
51
|
-
...(overrides || {}),
|
|
52
|
-
options: {
|
|
53
|
-
...(base?.options || {}),
|
|
54
|
-
...(overrides?.options || {}),
|
|
55
|
-
},
|
|
56
|
-
};
|
|
48
|
+
const isDestinationStream = (candidate) => {
|
|
49
|
+
if (!candidate || typeof candidate !== "object")
|
|
50
|
+
return false;
|
|
51
|
+
return typeof candidate.write === "function";
|
|
57
52
|
};
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
60
|
-
return
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
64
|
-
return {
|
|
65
|
-
instance: raw.instance,
|
|
66
|
-
options: raw.options,
|
|
67
|
-
destination: raw.destination,
|
|
68
|
-
};
|
|
53
|
+
const buildDestination = (transports) => {
|
|
54
|
+
if (!transports || transports.length === 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
const streams = transports.filter(isDestinationStream);
|
|
57
|
+
if (streams.length <= 1)
|
|
58
|
+
return streams[0];
|
|
59
|
+
return multistream(streams.map((stream) => ({ stream })));
|
|
69
60
|
};
|
|
70
|
-
|
|
61
|
+
/**
|
|
62
|
+
* @description A logger that is powered by the Pino logging library.
|
|
63
|
+
* @summary This class extends {@link MiniLogger} and uses Pino as its underlying logging engine.
|
|
64
|
+
* @param {string} [context] - The context (typically the class name) that this logger is associated with.
|
|
65
|
+
* @param {Partial<LoggingConfig>} [conf] - Optional configuration to override global settings.
|
|
66
|
+
* @param {PinoBaseLogger} [driver] - An optional, pre-existing Pino logger instance to use.
|
|
67
|
+
* @class PinoLogger
|
|
68
|
+
*/
|
|
71
69
|
export class PinoLogger extends MiniLogger {
|
|
72
|
-
constructor(context, conf) {
|
|
70
|
+
constructor(context, conf, driver) {
|
|
73
71
|
super(context, conf);
|
|
74
|
-
|
|
72
|
+
if (driver) {
|
|
73
|
+
this.pino = driver;
|
|
74
|
+
const derivedLevel = fromPinoLevel(driver.level);
|
|
75
|
+
if (derivedLevel)
|
|
76
|
+
this.setConfig({ level: derivedLevel });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
75
79
|
const globalConfig = Logging.getConfig();
|
|
76
80
|
const config = Object.assign({}, globalConfig, this.conf || {});
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
const options = buildPinoOptions(context, config, pinoConfig.options);
|
|
86
|
-
this.pino = pino(options, pinoConfig.destination);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
activePino() {
|
|
90
|
-
const override = this.config("pino");
|
|
91
|
-
if (override && override.instance && isPinoLogger(override.instance)) {
|
|
92
|
-
return override.instance;
|
|
93
|
-
}
|
|
94
|
-
return this.pino;
|
|
81
|
+
const separator = config.contextSeparator ||
|
|
82
|
+
Logging.getConfig().contextSeparator;
|
|
83
|
+
const contextName = joinContext(Array.isArray(this.context) ? this.context : [], separator);
|
|
84
|
+
const options = buildPinoOptions(contextName, config);
|
|
85
|
+
const destination = buildDestination(config.transports || undefined);
|
|
86
|
+
this.pino = pino(options, destination);
|
|
95
87
|
}
|
|
96
88
|
log(level, msg, error) {
|
|
97
|
-
const configuredLevel = this.config("level") || LogLevel.info;
|
|
98
|
-
if (NumericLogLevels[configuredLevel] < NumericLogLevels[level])
|
|
99
|
-
return;
|
|
100
89
|
const formatted = this.createLog(level, msg, error);
|
|
101
90
|
const methodName = toPinoLevel(level);
|
|
102
|
-
const
|
|
103
|
-
const emitter = target[methodName];
|
|
91
|
+
const emitter = this.pino[methodName];
|
|
104
92
|
if (typeof emitter === "function") {
|
|
105
|
-
emitter.call(
|
|
93
|
+
emitter.call(this.pino, formatted);
|
|
106
94
|
return;
|
|
107
95
|
}
|
|
108
|
-
if (typeof
|
|
109
|
-
|
|
96
|
+
if (typeof this.pino.log === "function") {
|
|
97
|
+
this.pino.log({
|
|
110
98
|
level: methodName,
|
|
111
99
|
msg: formatted,
|
|
112
100
|
});
|
|
113
|
-
return;
|
|
114
101
|
}
|
|
115
102
|
}
|
|
116
103
|
fatal(msg, error) {
|
|
117
104
|
const formatted = this.createLog(LogLevel.error, msg, error);
|
|
118
|
-
const
|
|
119
|
-
const fatal = target.fatal;
|
|
105
|
+
const fatal = this.pino.fatal;
|
|
120
106
|
if (typeof fatal === "function") {
|
|
121
|
-
fatal.call(
|
|
107
|
+
fatal.call(this.pino, formatted);
|
|
122
108
|
}
|
|
123
109
|
else {
|
|
124
110
|
this.error(msg, error);
|
|
@@ -130,81 +116,41 @@ export class PinoLogger extends MiniLogger {
|
|
|
130
116
|
: typeof bindings.name === "string"
|
|
131
117
|
? bindings.name
|
|
132
118
|
: undefined;
|
|
133
|
-
const
|
|
134
|
-
?
|
|
135
|
-
: this.
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
: this.pino;
|
|
143
|
-
this.childLoggers.set(key, childPino);
|
|
144
|
-
}
|
|
145
|
-
const baseConfig = getPinoConfig(Logging.getConfig(), this.conf);
|
|
146
|
-
const overrides = {
|
|
147
|
-
pino: mergePinoConfig(baseConfig, { instance: childPino }),
|
|
148
|
-
};
|
|
149
|
-
if (nextContext) {
|
|
150
|
-
return super.for(nextContext, overrides);
|
|
151
|
-
}
|
|
152
|
-
return super.for(overrides);
|
|
119
|
+
const childInstance = typeof this.pino.child === "function"
|
|
120
|
+
? this.pino.child(bindings, options)
|
|
121
|
+
: this.pino;
|
|
122
|
+
const childLogger = new PinoLogger(nextContext ??
|
|
123
|
+
joinContext(this.context, this.config("contextSeparator") || "."), this.conf, childInstance);
|
|
124
|
+
childLogger.context = nextContext
|
|
125
|
+
? [...this.context, nextContext]
|
|
126
|
+
: [...this.context];
|
|
127
|
+
return childLogger;
|
|
153
128
|
}
|
|
154
129
|
flush() {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return target.flush();
|
|
130
|
+
if (typeof this.pino.flush === "function") {
|
|
131
|
+
return this.pino.flush();
|
|
158
132
|
}
|
|
159
133
|
}
|
|
160
134
|
get level() {
|
|
161
|
-
|
|
162
|
-
return target.level;
|
|
135
|
+
return this.pino.level;
|
|
163
136
|
}
|
|
164
137
|
set level(value) {
|
|
165
138
|
if (!value)
|
|
166
139
|
return;
|
|
167
|
-
|
|
168
|
-
target.level = value;
|
|
140
|
+
this.pino.level = value;
|
|
169
141
|
const mapped = fromPinoLevel(value);
|
|
170
142
|
if (mapped)
|
|
171
143
|
this.setConfig({ level: mapped });
|
|
172
144
|
}
|
|
173
145
|
}
|
|
174
146
|
/**
|
|
175
|
-
* @description
|
|
176
|
-
* @summary
|
|
147
|
+
* @description A factory for creating {@link PinoLogger} instances.
|
|
148
|
+
* @summary This factory function creates a new {@link PinoLogger} instance, and can optionally accept a pre-existing Pino logger instance.
|
|
149
|
+
* @const {LoggerFactory} PinoFactory
|
|
150
|
+
* @memberOf module:Logging
|
|
177
151
|
*/
|
|
178
152
|
export const PinoFactory = (context, conf, ...args) => {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
...conf,
|
|
182
|
-
pino: conf.pino ? { ...conf.pino } : undefined,
|
|
183
|
-
}
|
|
184
|
-
: {};
|
|
185
|
-
const normalized = shallowClone;
|
|
186
|
-
const ensurePinoConfig = () => {
|
|
187
|
-
const current = normalized.pino;
|
|
188
|
-
if (current)
|
|
189
|
-
return current;
|
|
190
|
-
const fresh = {};
|
|
191
|
-
normalized.pino = fresh;
|
|
192
|
-
return fresh;
|
|
193
|
-
};
|
|
194
|
-
const [firstArg, secondArg] = args;
|
|
195
|
-
if (isPinoLogger(firstArg)) {
|
|
196
|
-
const pinoConfig = ensurePinoConfig();
|
|
197
|
-
pinoConfig.instance = firstArg;
|
|
198
|
-
}
|
|
199
|
-
else if (firstArg) {
|
|
200
|
-
const pinoConfig = ensurePinoConfig();
|
|
201
|
-
pinoConfig.options = {
|
|
202
|
-
...(pinoConfig.options || {}),
|
|
203
|
-
...firstArg,
|
|
204
|
-
};
|
|
205
|
-
if (secondArg !== undefined)
|
|
206
|
-
pinoConfig.destination = secondArg;
|
|
207
|
-
}
|
|
208
|
-
return new PinoLogger(context, normalized);
|
|
153
|
+
const [driver] = args;
|
|
154
|
+
return new PinoLogger(context, conf, driver);
|
|
209
155
|
};
|
|
210
156
|
//# sourceMappingURL=pino.js.map
|
package/lib/esm/pino/pino.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.js","sourceRoot":"","sources":["../../../src/pino/pino.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"pino.js","sourceRoot":"","sources":["../../../src/pino/pino.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAIX,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAmB;AAEjD,OAAO,EAAE,QAAQ,EAAE,0BAAqB;AAIxC,MAAM,cAAc,GAAoC;IACtD,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM;IAC5B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,C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AC,IAAI,EACT,aAAa,CACd,CAAC;QACF,WAAW,CAAC,OAAO,GAAG,WAAW;YAC/B,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;YAChC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK;QACH,IAAI,OAAQ,IAAI,CAAC,IAAY,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YACnD,OAAQ,IAAI,CAAC,IAAY,CAAC,KAAK,EAAE,CAAC;QACpC,CAAC;IACH,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,IAAI,KAAK,CAAC,KAAyB;QACjC,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACxB,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,MAAM;YAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAkB,CACxC,OAAgB,EAChB,IAA6B,EAC7B,GAAG,IAAW,EACd,EAAE;IACF,MAAM,CAAC,MAAM,CAAC,GAAG,IAAoC,CAAC;IACtD,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC,CAAC"}
|
package/lib/esm/text.d.ts
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description Pads the end of a string with a specified character.
|
|
3
|
-
* @summary
|
|
4
|
-
* If the input string is already longer than the specified length, it is returned unchanged.
|
|
5
|
-
*
|
|
3
|
+
* @summary This function extends the input string to a specified length by adding a padding character to the end. If the input string is already longer than the specified length, it is returned unchanged.
|
|
6
4
|
* @param {string} str - The input string to be padded.
|
|
7
5
|
* @param {number} length - The desired total length of the resulting string.
|
|
8
|
-
* @param {string} [char=" "] - The character to use for padding.
|
|
6
|
+
* @param {string} [char=" "] - The character to use for padding.
|
|
9
7
|
* @return {string} The padded string.
|
|
10
8
|
* @throws {Error} If the padding character is not exactly one character long.
|
|
11
|
-
*
|
|
12
9
|
* @function padEnd
|
|
13
|
-
*
|
|
14
10
|
* @memberOf module:Logging
|
|
15
11
|
*/
|
|
16
12
|
export declare function padEnd(str: string, length: number, char?: string): string;
|
|
17
13
|
/**
|
|
18
|
-
* @description Replaces placeholders in a string with provided values.
|
|
19
|
-
* @summary
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @param {string}
|
|
24
|
-
* @param {
|
|
25
|
-
* @
|
|
26
|
-
* @param suffix
|
|
27
|
-
* @param flags
|
|
28
|
-
* @return {string} The interpolated string with placeholders replaced by their corresponding values.
|
|
29
|
-
*
|
|
14
|
+
* @description Replaces placeholders in a string with the provided values.
|
|
15
|
+
* @summary This function interpolates a string by replacing placeholders of the form `${variableName}` with the corresponding values from the provided object. If a placeholder does not have a corresponding value, it is left unchanged in the string.
|
|
16
|
+
* @param {string} input - The input string containing the placeholders to be replaced.
|
|
17
|
+
* @param {Record<string, (number|string)>} values - An object containing key-value pairs for the replacement.
|
|
18
|
+
* @param {string} [prefix="${"] - The prefix for the placeholders.
|
|
19
|
+
* @param {string} [suffix="}"] - The suffix for the placeholders.
|
|
20
|
+
* @param {string} [flags="g"] - The regular expression flags to use.
|
|
21
|
+
* @return {string} The interpolated string with the placeholders replaced by their corresponding values.
|
|
30
22
|
* @function patchPlaceholders
|
|
31
|
-
*
|
|
32
23
|
* @mermaid
|
|
33
24
|
* sequenceDiagram
|
|
34
25
|
* participant Caller
|
|
@@ -38,117 +29,88 @@ export declare function padEnd(str: string, length: number, char?: string): stri
|
|
|
38
29
|
* patchString->>String.replace: Call with regex and replacement function
|
|
39
30
|
* String.replace->>patchString: Return replaced string
|
|
40
31
|
* patchString-->>Caller: Return patched string
|
|
41
|
-
*
|
|
42
32
|
* @memberOf module:Logging
|
|
43
33
|
*/
|
|
44
34
|
export declare function patchPlaceholders(input: string, values: Record<string, number | string>, prefix?: string, suffix?: string, flags?: string): string;
|
|
45
35
|
/**
|
|
46
36
|
* @description Replaces occurrences of keys with their corresponding values in a string.
|
|
47
|
-
* @summary
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @param {string}
|
|
51
|
-
* @
|
|
52
|
-
* @param {string} [flags="g"] - Regular expression flags to control the replacement behavior.
|
|
53
|
-
* @return {string} The string with all specified replacements applied.
|
|
54
|
-
*
|
|
37
|
+
* @summary This function iterates through a set of key-value pairs and replaces all occurrences of each key in the input string with its corresponding value. It supports regular expression flags for customized replacement.
|
|
38
|
+
* @param {string} input - The input string in which the replacements will be made.
|
|
39
|
+
* @param {Record<string, (number|string)>} values - An object containing key-value pairs for the replacement.
|
|
40
|
+
* @param {string} [flags="g"] - The regular expression flags to control the replacement behavior.
|
|
41
|
+
* @return {string} The string with all the specified replacements applied.
|
|
55
42
|
* @function patchString
|
|
56
|
-
*
|
|
57
43
|
* @memberOf module:Logging
|
|
58
44
|
*/
|
|
59
45
|
export declare function patchString(input: string, values: Record<string, number | string>, flags?: string): string;
|
|
60
46
|
/**
|
|
61
47
|
* @description Converts a string to camelCase.
|
|
62
|
-
* @summary
|
|
63
|
-
* and each word after the first starts with a capital letter.
|
|
64
|
-
*
|
|
48
|
+
* @summary This function transforms the input string into camelCase format, where words are joined without spaces and each word after the first starts with a capital letter.
|
|
65
49
|
* @param {string} text - The input string to be converted.
|
|
66
50
|
* @return {string} The input string converted to camelCase.
|
|
67
|
-
*
|
|
68
51
|
* @function toCamelCase
|
|
69
|
-
*
|
|
70
52
|
* @memberOf module:Logging
|
|
71
53
|
*/
|
|
72
54
|
export declare function toCamelCase(text: string): string;
|
|
73
55
|
/**
|
|
74
56
|
* @description Converts a string to ENVIRONMENT_VARIABLE format.
|
|
75
|
-
* @summary
|
|
76
|
-
* typically used for environment variable names.
|
|
77
|
-
*
|
|
57
|
+
* @summary This function transforms the input string into uppercase with words separated by underscores, which is a format that is typically used for environment variable names.
|
|
78
58
|
* @param {string} text - The input string to be converted.
|
|
79
59
|
* @return {string} The input string converted to ENVIRONMENT_VARIABLE format.
|
|
80
|
-
*
|
|
81
60
|
* @function toENVFormat
|
|
82
|
-
*
|
|
83
61
|
* @memberOf module:Logging
|
|
84
62
|
*/
|
|
85
63
|
export declare function toENVFormat(text: string): string;
|
|
86
64
|
/**
|
|
87
65
|
* @description Converts a string to snake_case.
|
|
88
|
-
* @summary
|
|
89
|
-
*
|
|
66
|
+
* @summary This function transforms the input string into lowercase with words separated by underscores.
|
|
90
67
|
* @param {string} text - The input string to be converted.
|
|
91
68
|
* @return {string} The input string converted to snake_case.
|
|
92
|
-
*
|
|
93
69
|
* @function toSnakeCase
|
|
94
|
-
*
|
|
95
70
|
* @memberOf module:Logging
|
|
96
71
|
*/
|
|
97
72
|
export declare function toSnakeCase(text: string): string;
|
|
98
73
|
/**
|
|
99
74
|
* @description Converts a string to kebab-case.
|
|
100
|
-
* @summary
|
|
101
|
-
*
|
|
75
|
+
* @summary This function transforms the input string into lowercase with words separated by hyphens.
|
|
102
76
|
* @param {string} text - The input string to be converted.
|
|
103
77
|
* @return {string} The input string converted to kebab-case.
|
|
104
|
-
*
|
|
105
78
|
* @function toKebabCase
|
|
106
|
-
*
|
|
107
79
|
* @memberOf module:Logging
|
|
108
80
|
*/
|
|
109
81
|
export declare function toKebabCase(text: string): string;
|
|
110
82
|
/**
|
|
111
83
|
* @description Converts a string to PascalCase.
|
|
112
|
-
* @summary
|
|
113
|
-
* and each word starts with a capital letter.
|
|
114
|
-
*
|
|
84
|
+
* @summary This function transforms the input string into PascalCase format, where words are joined without spaces and each word starts with a capital letter.
|
|
115
85
|
* @param {string} text - The input string to be converted.
|
|
116
86
|
* @return {string} The input string converted to PascalCase.
|
|
117
|
-
*
|
|
118
87
|
* @function toPascalCase
|
|
119
|
-
*
|
|
120
88
|
* @memberOf module:Logging
|
|
121
89
|
*/
|
|
122
90
|
export declare function toPascalCase(text: string): string;
|
|
123
91
|
/**
|
|
124
92
|
* @description Escapes special characters in a string for use in a regular expression.
|
|
125
|
-
* @summary
|
|
126
|
-
* allowing the string to be used as a literal match in a RegExp.
|
|
127
|
-
*
|
|
93
|
+
* @summary This function adds backslashes before characters that have a special meaning in regular expressions, which allows the string to be used as a literal match in a RegExp.
|
|
128
94
|
* @param {string} string - The string to escape for regular expression use.
|
|
129
|
-
* @return {string} The escaped string safe for use in regular expressions.
|
|
130
|
-
*
|
|
95
|
+
* @return {string} The escaped string that is safe for use in regular expressions.
|
|
131
96
|
* @function escapeRegExp
|
|
132
|
-
*
|
|
133
97
|
* @memberOf module:Logging
|
|
134
98
|
*/
|
|
135
99
|
export declare function escapeRegExp(string: string): string;
|
|
136
100
|
/**
|
|
137
|
-
* @
|
|
138
|
-
*
|
|
139
|
-
* @param {string} string
|
|
140
|
-
* @param {
|
|
141
|
-
* @return {string} formatted string
|
|
142
|
-
*
|
|
101
|
+
* @description A utility function that provides string formatting functionality that is similar to C#'s string.format.
|
|
102
|
+
* @summary This function replaces placeholders in a string with the provided arguments.
|
|
103
|
+
* @param {string} string - The string to format.
|
|
104
|
+
* @param {...(string|number|Record<string, any>)} args - The arguments to use for formatting.
|
|
105
|
+
* @return {string} The formatted string.
|
|
143
106
|
* @function sf
|
|
144
107
|
* @memberOf module:Logging
|
|
145
108
|
*/
|
|
146
109
|
export declare function sf(string: string, ...args: (string | number | Record<string, any>)[]): string;
|
|
147
110
|
/**
|
|
148
|
-
* @
|
|
149
|
-
*
|
|
111
|
+
* @description A utility function that provides string formatting functionality that is similar to C#'s string.format.
|
|
112
|
+
* @summary This function is deprecated. Use {@link sf} instead.
|
|
150
113
|
* @see sf
|
|
151
|
-
*
|
|
152
114
|
* @deprecated
|
|
153
115
|
* @function stringFormat
|
|
154
116
|
* @memberOf module:Logging
|