@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/pino/pino.cjs
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
36
|
exports.PinoFactory = exports.PinoLogger = void 0;
|
|
7
|
-
const pino_1 =
|
|
37
|
+
const pino_1 = __importStar(require("pino"));
|
|
8
38
|
const logging_1 = require("./../logging.cjs");
|
|
9
39
|
const constants_1 = require("./../constants.cjs");
|
|
10
40
|
const LogLevelToPino = {
|
|
@@ -25,106 +55,92 @@ const PinoToLogLevel = {
|
|
|
25
55
|
debug: constants_1.LogLevel.debug,
|
|
26
56
|
trace: constants_1.LogLevel.trace,
|
|
27
57
|
};
|
|
28
|
-
const isPinoLogger = (candidate) => {
|
|
29
|
-
if (!candidate || typeof candidate !== "object")
|
|
30
|
-
return false;
|
|
31
|
-
const required = ["info", "error", "warn", "debug", "trace"];
|
|
32
|
-
return required.every((method) => typeof candidate[method] === "function");
|
|
33
|
-
};
|
|
34
58
|
const toPinoLevel = (level) => LogLevelToPino[level] ?? "info";
|
|
35
59
|
const fromPinoLevel = (level) => {
|
|
36
60
|
if (!level)
|
|
37
61
|
return undefined;
|
|
38
62
|
return PinoToLogLevel[level];
|
|
39
63
|
};
|
|
40
|
-
const
|
|
64
|
+
const joinContext = (segments, separator) => {
|
|
65
|
+
if (!segments.length)
|
|
66
|
+
return "Logger";
|
|
67
|
+
return segments.join(separator);
|
|
68
|
+
};
|
|
69
|
+
const buildPinoOptions = (context, config, overrides) => {
|
|
41
70
|
const options = {
|
|
42
71
|
level: toPinoLevel(config.level),
|
|
43
72
|
name: context,
|
|
44
|
-
...
|
|
73
|
+
...overrides,
|
|
45
74
|
};
|
|
46
75
|
if (!options.level)
|
|
47
76
|
options.level = toPinoLevel(config.level);
|
|
48
77
|
if (!options.name)
|
|
49
78
|
options.name = context;
|
|
79
|
+
options.timestamp = config.timestamp
|
|
80
|
+
? () => new Date().toISOString()
|
|
81
|
+
: false;
|
|
50
82
|
return options;
|
|
51
83
|
};
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
54
|
-
return
|
|
55
|
-
return
|
|
56
|
-
...(base || {}),
|
|
57
|
-
...(overrides || {}),
|
|
58
|
-
options: {
|
|
59
|
-
...(base?.options || {}),
|
|
60
|
-
...(overrides?.options || {}),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
84
|
+
const isDestinationStream = (candidate) => {
|
|
85
|
+
if (!candidate || typeof candidate !== "object")
|
|
86
|
+
return false;
|
|
87
|
+
return typeof candidate.write === "function";
|
|
63
88
|
};
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
return
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
70
|
-
return {
|
|
71
|
-
instance: raw.instance,
|
|
72
|
-
options: raw.options,
|
|
73
|
-
destination: raw.destination,
|
|
74
|
-
};
|
|
89
|
+
const buildDestination = (transports) => {
|
|
90
|
+
if (!transports || transports.length === 0)
|
|
91
|
+
return undefined;
|
|
92
|
+
const streams = transports.filter(isDestinationStream);
|
|
93
|
+
if (streams.length <= 1)
|
|
94
|
+
return streams[0];
|
|
95
|
+
return (0, pino_1.multistream)(streams.map((stream) => ({ stream })));
|
|
75
96
|
};
|
|
76
|
-
|
|
97
|
+
/**
|
|
98
|
+
* @description A logger that is powered by the Pino logging library.
|
|
99
|
+
* @summary This class extends {@link MiniLogger} and uses Pino as its underlying logging engine.
|
|
100
|
+
* @param {string} [context] - The context (typically the class name) that this logger is associated with.
|
|
101
|
+
* @param {Partial<LoggingConfig>} [conf] - Optional configuration to override global settings.
|
|
102
|
+
* @param {PinoBaseLogger} [driver] - An optional, pre-existing Pino logger instance to use.
|
|
103
|
+
* @class PinoLogger
|
|
104
|
+
*/
|
|
77
105
|
class PinoLogger extends logging_1.MiniLogger {
|
|
78
|
-
constructor(context, conf) {
|
|
106
|
+
constructor(context, conf, driver) {
|
|
79
107
|
super(context, conf);
|
|
80
|
-
|
|
108
|
+
if (driver) {
|
|
109
|
+
this.pino = driver;
|
|
110
|
+
const derivedLevel = fromPinoLevel(driver.level);
|
|
111
|
+
if (derivedLevel)
|
|
112
|
+
this.setConfig({ level: derivedLevel });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
81
115
|
const globalConfig = logging_1.Logging.getConfig();
|
|
82
116
|
const config = Object.assign({}, globalConfig, this.conf || {});
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const options = buildPinoOptions(context, config, pinoConfig.options);
|
|
92
|
-
this.pino = (0, pino_1.default)(options, pinoConfig.destination);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
activePino() {
|
|
96
|
-
const override = this.config("pino");
|
|
97
|
-
if (override && override.instance && isPinoLogger(override.instance)) {
|
|
98
|
-
return override.instance;
|
|
99
|
-
}
|
|
100
|
-
return this.pino;
|
|
117
|
+
const separator = config.contextSeparator ||
|
|
118
|
+
logging_1.Logging.getConfig().contextSeparator;
|
|
119
|
+
const contextName = joinContext(Array.isArray(this.context) ? this.context : [], separator);
|
|
120
|
+
const options = buildPinoOptions(contextName, config);
|
|
121
|
+
const destination = buildDestination(config.transports || undefined);
|
|
122
|
+
this.pino = (0, pino_1.default)(options, destination);
|
|
101
123
|
}
|
|
102
124
|
log(level, msg, error) {
|
|
103
|
-
const configuredLevel = this.config("level") || constants_1.LogLevel.info;
|
|
104
|
-
if (constants_1.NumericLogLevels[configuredLevel] < constants_1.NumericLogLevels[level])
|
|
105
|
-
return;
|
|
106
125
|
const formatted = this.createLog(level, msg, error);
|
|
107
126
|
const methodName = toPinoLevel(level);
|
|
108
|
-
const
|
|
109
|
-
const emitter = target[methodName];
|
|
127
|
+
const emitter = this.pino[methodName];
|
|
110
128
|
if (typeof emitter === "function") {
|
|
111
|
-
emitter.call(
|
|
129
|
+
emitter.call(this.pino, formatted);
|
|
112
130
|
return;
|
|
113
131
|
}
|
|
114
|
-
if (typeof
|
|
115
|
-
|
|
132
|
+
if (typeof this.pino.log === "function") {
|
|
133
|
+
this.pino.log({
|
|
116
134
|
level: methodName,
|
|
117
135
|
msg: formatted,
|
|
118
136
|
});
|
|
119
|
-
return;
|
|
120
137
|
}
|
|
121
138
|
}
|
|
122
139
|
fatal(msg, error) {
|
|
123
140
|
const formatted = this.createLog(constants_1.LogLevel.error, msg, error);
|
|
124
|
-
const
|
|
125
|
-
const fatal = target.fatal;
|
|
141
|
+
const fatal = this.pino.fatal;
|
|
126
142
|
if (typeof fatal === "function") {
|
|
127
|
-
fatal.call(
|
|
143
|
+
fatal.call(this.pino, formatted);
|
|
128
144
|
}
|
|
129
145
|
else {
|
|
130
146
|
this.error(msg, error);
|
|
@@ -136,42 +152,28 @@ class PinoLogger extends logging_1.MiniLogger {
|
|
|
136
152
|
: typeof bindings.name === "string"
|
|
137
153
|
? bindings.name
|
|
138
154
|
: undefined;
|
|
139
|
-
const
|
|
140
|
-
?
|
|
141
|
-
: this.
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
: this.pino;
|
|
149
|
-
this.childLoggers.set(key, childPino);
|
|
150
|
-
}
|
|
151
|
-
const baseConfig = getPinoConfig(logging_1.Logging.getConfig(), this.conf);
|
|
152
|
-
const overrides = {
|
|
153
|
-
pino: mergePinoConfig(baseConfig, { instance: childPino }),
|
|
154
|
-
};
|
|
155
|
-
if (nextContext) {
|
|
156
|
-
return super.for(nextContext, overrides);
|
|
157
|
-
}
|
|
158
|
-
return super.for(overrides);
|
|
155
|
+
const childInstance = typeof this.pino.child === "function"
|
|
156
|
+
? this.pino.child(bindings, options)
|
|
157
|
+
: this.pino;
|
|
158
|
+
const childLogger = new PinoLogger(nextContext ??
|
|
159
|
+
joinContext(this.context, this.config("contextSeparator") || "."), this.conf, childInstance);
|
|
160
|
+
childLogger.context = nextContext
|
|
161
|
+
? [...this.context, nextContext]
|
|
162
|
+
: [...this.context];
|
|
163
|
+
return childLogger;
|
|
159
164
|
}
|
|
160
165
|
flush() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return target.flush();
|
|
166
|
+
if (typeof this.pino.flush === "function") {
|
|
167
|
+
return this.pino.flush();
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
get level() {
|
|
167
|
-
|
|
168
|
-
return target.level;
|
|
171
|
+
return this.pino.level;
|
|
169
172
|
}
|
|
170
173
|
set level(value) {
|
|
171
174
|
if (!value)
|
|
172
175
|
return;
|
|
173
|
-
|
|
174
|
-
target.level = value;
|
|
176
|
+
this.pino.level = value;
|
|
175
177
|
const mapped = fromPinoLevel(value);
|
|
176
178
|
if (mapped)
|
|
177
179
|
this.setConfig({ level: mapped });
|
|
@@ -179,40 +181,14 @@ class PinoLogger extends logging_1.MiniLogger {
|
|
|
179
181
|
}
|
|
180
182
|
exports.PinoLogger = PinoLogger;
|
|
181
183
|
/**
|
|
182
|
-
* @description
|
|
183
|
-
* @summary
|
|
184
|
+
* @description A factory for creating {@link PinoLogger} instances.
|
|
185
|
+
* @summary This factory function creates a new {@link PinoLogger} instance, and can optionally accept a pre-existing Pino logger instance.
|
|
186
|
+
* @const {LoggerFactory} PinoFactory
|
|
187
|
+
* @memberOf module:Logging
|
|
184
188
|
*/
|
|
185
189
|
const PinoFactory = (context, conf, ...args) => {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
...conf,
|
|
189
|
-
pino: conf.pino ? { ...conf.pino } : undefined,
|
|
190
|
-
}
|
|
191
|
-
: {};
|
|
192
|
-
const normalized = shallowClone;
|
|
193
|
-
const ensurePinoConfig = () => {
|
|
194
|
-
const current = normalized.pino;
|
|
195
|
-
if (current)
|
|
196
|
-
return current;
|
|
197
|
-
const fresh = {};
|
|
198
|
-
normalized.pino = fresh;
|
|
199
|
-
return fresh;
|
|
200
|
-
};
|
|
201
|
-
const [firstArg, secondArg] = args;
|
|
202
|
-
if (isPinoLogger(firstArg)) {
|
|
203
|
-
const pinoConfig = ensurePinoConfig();
|
|
204
|
-
pinoConfig.instance = firstArg;
|
|
205
|
-
}
|
|
206
|
-
else if (firstArg) {
|
|
207
|
-
const pinoConfig = ensurePinoConfig();
|
|
208
|
-
pinoConfig.options = {
|
|
209
|
-
...(pinoConfig.options || {}),
|
|
210
|
-
...firstArg,
|
|
211
|
-
};
|
|
212
|
-
if (secondArg !== undefined)
|
|
213
|
-
pinoConfig.destination = secondArg;
|
|
214
|
-
}
|
|
215
|
-
return new PinoLogger(context, normalized);
|
|
190
|
+
const [driver] = args;
|
|
191
|
+
return new PinoLogger(context, conf, driver);
|
|
216
192
|
};
|
|
217
193
|
exports.PinoFactory = PinoFactory;
|
|
218
194
|
//# sourceMappingURL=pino.js.map
|
package/lib/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/pino/pino.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.js","sourceRoot":"","sources":["../../src/pino/pino.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pino.js","sourceRoot":"","sources":["../../src/pino/pino.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAKc;AACd,8CAAiD;AAEjD,kDAAwC;AAIxC,MAAM,cAAc,GAAoC;IACtD,CAAC,oBAAQ,CAAC,SAAS,CAAC,EAAE,MAAM;IAC5B,CAAC,oBAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,oBAAQ,CAAC,OAAO,CAAC,EAAE,OAAO;IAC3B,CAAC,oBAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,oBAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,oBAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;CAC1B,CAAC;AAEF,MAAM,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AAI,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;AA/GD,gCA+GC;AAED;;;;;GAKG;AACI,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;AAPW,QAAA,WAAW,eAOtB"}
|
package/lib/text.cjs
CHANGED
|
@@ -14,17 +14,13 @@ exports.sf = sf;
|
|
|
14
14
|
const constants_1 = require("./constants.cjs");
|
|
15
15
|
/**
|
|
16
16
|
* @description Pads the end of a string with a specified character.
|
|
17
|
-
* @summary
|
|
18
|
-
* If the input string is already longer than the specified length, it is returned unchanged.
|
|
19
|
-
*
|
|
17
|
+
* @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.
|
|
20
18
|
* @param {string} str - The input string to be padded.
|
|
21
19
|
* @param {number} length - The desired total length of the resulting string.
|
|
22
|
-
* @param {string} [char=" "] - The character to use for padding.
|
|
20
|
+
* @param {string} [char=" "] - The character to use for padding.
|
|
23
21
|
* @return {string} The padded string.
|
|
24
22
|
* @throws {Error} If the padding character is not exactly one character long.
|
|
25
|
-
*
|
|
26
23
|
* @function padEnd
|
|
27
|
-
*
|
|
28
24
|
* @memberOf module:Logging
|
|
29
25
|
*/
|
|
30
26
|
function padEnd(str, length, char = " ") {
|
|
@@ -33,20 +29,15 @@ function padEnd(str, length, char = " ") {
|
|
|
33
29
|
return str.padEnd(length, char);
|
|
34
30
|
}
|
|
35
31
|
/**
|
|
36
|
-
* @description Replaces placeholders in a string with provided values.
|
|
37
|
-
* @summary
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param {string}
|
|
42
|
-
* @param {
|
|
43
|
-
* @
|
|
44
|
-
* @param suffix
|
|
45
|
-
* @param flags
|
|
46
|
-
* @return {string} The interpolated string with placeholders replaced by their corresponding values.
|
|
47
|
-
*
|
|
32
|
+
* @description Replaces placeholders in a string with the provided values.
|
|
33
|
+
* @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.
|
|
34
|
+
* @param {string} input - The input string containing the placeholders to be replaced.
|
|
35
|
+
* @param {Record<string, (number|string)>} values - An object containing key-value pairs for the replacement.
|
|
36
|
+
* @param {string} [prefix="${"] - The prefix for the placeholders.
|
|
37
|
+
* @param {string} [suffix="}"] - The suffix for the placeholders.
|
|
38
|
+
* @param {string} [flags="g"] - The regular expression flags to use.
|
|
39
|
+
* @return {string} The interpolated string with the placeholders replaced by their corresponding values.
|
|
48
40
|
* @function patchPlaceholders
|
|
49
|
-
*
|
|
50
41
|
* @mermaid
|
|
51
42
|
* sequenceDiagram
|
|
52
43
|
* participant Caller
|
|
@@ -56,7 +47,6 @@ function padEnd(str, length, char = " ") {
|
|
|
56
47
|
* patchString->>String.replace: Call with regex and replacement function
|
|
57
48
|
* String.replace->>patchString: Return replaced string
|
|
58
49
|
* patchString-->>Caller: Return patched string
|
|
59
|
-
*
|
|
60
50
|
* @memberOf module:Logging
|
|
61
51
|
*/
|
|
62
52
|
function patchPlaceholders(input, values, prefix = constants_1.DefaultPlaceholderWrappers[0], suffix = constants_1.DefaultPlaceholderWrappers[1], flags = "g") {
|
|
@@ -68,16 +58,12 @@ function patchPlaceholders(input, values, prefix = constants_1.DefaultPlaceholde
|
|
|
68
58
|
}
|
|
69
59
|
/**
|
|
70
60
|
* @description Replaces occurrences of keys with their corresponding values in a string.
|
|
71
|
-
* @summary
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @param {string}
|
|
75
|
-
* @
|
|
76
|
-
* @param {string} [flags="g"] - Regular expression flags to control the replacement behavior.
|
|
77
|
-
* @return {string} The string with all specified replacements applied.
|
|
78
|
-
*
|
|
61
|
+
* @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.
|
|
62
|
+
* @param {string} input - The input string in which the replacements will be made.
|
|
63
|
+
* @param {Record<string, (number|string)>} values - An object containing key-value pairs for the replacement.
|
|
64
|
+
* @param {string} [flags="g"] - The regular expression flags to control the replacement behavior.
|
|
65
|
+
* @return {string} The string with all the specified replacements applied.
|
|
79
66
|
* @function patchString
|
|
80
|
-
*
|
|
81
67
|
* @memberOf module:Logging
|
|
82
68
|
*/
|
|
83
69
|
function patchString(input, values, flags = "g") {
|
|
@@ -89,14 +75,10 @@ function patchString(input, values, flags = "g") {
|
|
|
89
75
|
}
|
|
90
76
|
/**
|
|
91
77
|
* @description Converts a string to camelCase.
|
|
92
|
-
* @summary
|
|
93
|
-
* and each word after the first starts with a capital letter.
|
|
94
|
-
*
|
|
78
|
+
* @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.
|
|
95
79
|
* @param {string} text - The input string to be converted.
|
|
96
80
|
* @return {string} The input string converted to camelCase.
|
|
97
|
-
*
|
|
98
81
|
* @function toCamelCase
|
|
99
|
-
*
|
|
100
82
|
* @memberOf module:Logging
|
|
101
83
|
*/
|
|
102
84
|
function toCamelCase(text) {
|
|
@@ -106,14 +88,10 @@ function toCamelCase(text) {
|
|
|
106
88
|
}
|
|
107
89
|
/**
|
|
108
90
|
* @description Converts a string to ENVIRONMENT_VARIABLE format.
|
|
109
|
-
* @summary
|
|
110
|
-
* typically used for environment variable names.
|
|
111
|
-
*
|
|
91
|
+
* @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.
|
|
112
92
|
* @param {string} text - The input string to be converted.
|
|
113
93
|
* @return {string} The input string converted to ENVIRONMENT_VARIABLE format.
|
|
114
|
-
*
|
|
115
94
|
* @function toENVFormat
|
|
116
|
-
*
|
|
117
95
|
* @memberOf module:Logging
|
|
118
96
|
*/
|
|
119
97
|
function toENVFormat(text) {
|
|
@@ -121,13 +99,10 @@ function toENVFormat(text) {
|
|
|
121
99
|
}
|
|
122
100
|
/**
|
|
123
101
|
* @description Converts a string to snake_case.
|
|
124
|
-
* @summary
|
|
125
|
-
*
|
|
102
|
+
* @summary This function transforms the input string into lowercase with words separated by underscores.
|
|
126
103
|
* @param {string} text - The input string to be converted.
|
|
127
104
|
* @return {string} The input string converted to snake_case.
|
|
128
|
-
*
|
|
129
105
|
* @function toSnakeCase
|
|
130
|
-
*
|
|
131
106
|
* @memberOf module:Logging
|
|
132
107
|
*/
|
|
133
108
|
function toSnakeCase(text) {
|
|
@@ -138,13 +113,10 @@ function toSnakeCase(text) {
|
|
|
138
113
|
}
|
|
139
114
|
/**
|
|
140
115
|
* @description Converts a string to kebab-case.
|
|
141
|
-
* @summary
|
|
142
|
-
*
|
|
116
|
+
* @summary This function transforms the input string into lowercase with words separated by hyphens.
|
|
143
117
|
* @param {string} text - The input string to be converted.
|
|
144
118
|
* @return {string} The input string converted to kebab-case.
|
|
145
|
-
*
|
|
146
119
|
* @function toKebabCase
|
|
147
|
-
*
|
|
148
120
|
* @memberOf module:Logging
|
|
149
121
|
*/
|
|
150
122
|
function toKebabCase(text) {
|
|
@@ -155,14 +127,10 @@ function toKebabCase(text) {
|
|
|
155
127
|
}
|
|
156
128
|
/**
|
|
157
129
|
* @description Converts a string to PascalCase.
|
|
158
|
-
* @summary
|
|
159
|
-
* and each word starts with a capital letter.
|
|
160
|
-
*
|
|
130
|
+
* @summary This function transforms the input string into PascalCase format, where words are joined without spaces and each word starts with a capital letter.
|
|
161
131
|
* @param {string} text - The input string to be converted.
|
|
162
132
|
* @return {string} The input string converted to PascalCase.
|
|
163
|
-
*
|
|
164
133
|
* @function toPascalCase
|
|
165
|
-
*
|
|
166
134
|
* @memberOf module:Logging
|
|
167
135
|
*/
|
|
168
136
|
function toPascalCase(text) {
|
|
@@ -172,26 +140,21 @@ function toPascalCase(text) {
|
|
|
172
140
|
}
|
|
173
141
|
/**
|
|
174
142
|
* @description Escapes special characters in a string for use in a regular expression.
|
|
175
|
-
* @summary
|
|
176
|
-
* allowing the string to be used as a literal match in a RegExp.
|
|
177
|
-
*
|
|
143
|
+
* @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.
|
|
178
144
|
* @param {string} string - The string to escape for regular expression use.
|
|
179
|
-
* @return {string} The escaped string safe for use in regular expressions.
|
|
180
|
-
*
|
|
145
|
+
* @return {string} The escaped string that is safe for use in regular expressions.
|
|
181
146
|
* @function escapeRegExp
|
|
182
|
-
*
|
|
183
147
|
* @memberOf module:Logging
|
|
184
148
|
*/
|
|
185
149
|
function escapeRegExp(string) {
|
|
186
150
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
|
187
151
|
}
|
|
188
152
|
/**
|
|
189
|
-
* @
|
|
190
|
-
*
|
|
191
|
-
* @param {string} string
|
|
192
|
-
* @param {
|
|
193
|
-
* @return {string} formatted string
|
|
194
|
-
*
|
|
153
|
+
* @description A utility function that provides string formatting functionality that is similar to C#'s string.format.
|
|
154
|
+
* @summary This function replaces placeholders in a string with the provided arguments.
|
|
155
|
+
* @param {string} string - The string to format.
|
|
156
|
+
* @param {...(string|number|Record<string, any>)} args - The arguments to use for formatting.
|
|
157
|
+
* @return {string} The formatted string.
|
|
195
158
|
* @function sf
|
|
196
159
|
* @memberOf module:Logging
|
|
197
160
|
*/
|
|
@@ -215,10 +178,9 @@ function sf(string, ...args) {
|
|
|
215
178
|
});
|
|
216
179
|
}
|
|
217
180
|
/**
|
|
218
|
-
* @
|
|
219
|
-
*
|
|
181
|
+
* @description A utility function that provides string formatting functionality that is similar to C#'s string.format.
|
|
182
|
+
* @summary This function is deprecated. Use {@link sf} instead.
|
|
220
183
|
* @see sf
|
|
221
|
-
*
|
|
222
184
|
* @deprecated
|
|
223
185
|
* @function stringFormat
|
|
224
186
|
* @memberOf module:Logging
|