lifecycleion 0.0.4 → 0.0.5
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 +1 -1
- package/dist/lib/curly-brackets.cjs +14 -3
- package/dist/lib/curly-brackets.cjs.map +1 -1
- package/dist/lib/curly-brackets.js +12 -3
- package/dist/lib/curly-brackets.js.map +1 -1
- package/dist/lib/logger/index.cjs +19 -7
- package/dist/lib/logger/index.cjs.map +1 -1
- package/dist/lib/logger/index.js +19 -7
- package/dist/lib/logger/index.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/logger/index.js
CHANGED
|
@@ -891,7 +891,17 @@ function ms() {
|
|
|
891
891
|
return Date.now();
|
|
892
892
|
}
|
|
893
893
|
|
|
894
|
+
// src/lib/internal/path-utils.ts
|
|
895
|
+
var PATH_SEGMENT_PATTERN = /\w+|\[(\d+)\]/g;
|
|
896
|
+
function getPathParts(path) {
|
|
897
|
+
return Array.from(
|
|
898
|
+
path.matchAll(PATH_SEGMENT_PATTERN),
|
|
899
|
+
(match) => match[1] ?? match[0]
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
|
|
894
903
|
// src/lib/curly-brackets.ts
|
|
904
|
+
var PLACEHOLDER_PATTERN = /(?:\\)?{{(\s*\w+(?:\[\d+\])*(?:\.\w+(?:\[\d+\])*)*\s*)(?:\\)?\s*}}/g;
|
|
895
905
|
var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
|
|
896
906
|
if (!str.includes("{{")) {
|
|
897
907
|
return str;
|
|
@@ -900,9 +910,8 @@ var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
|
|
|
900
910
|
return compiled(locals);
|
|
901
911
|
};
|
|
902
912
|
CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
|
|
903
|
-
const pattern = /(?:\\)?{{(\s*[\w.]+?)(?:\\)?\s*}}/g;
|
|
904
913
|
return (locals) => {
|
|
905
|
-
return str.replace(
|
|
914
|
+
return str.replace(PLACEHOLDER_PATTERN, (match, p1) => {
|
|
906
915
|
if (typeof p1 !== "string") {
|
|
907
916
|
return match;
|
|
908
917
|
}
|
|
@@ -919,7 +928,7 @@ CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
|
|
|
919
928
|
return "{{" + p1.trim() + "}}";
|
|
920
929
|
}
|
|
921
930
|
const key = p1.trim();
|
|
922
|
-
const parts = key
|
|
931
|
+
const parts = getPathParts(key);
|
|
923
932
|
let replacement = locals;
|
|
924
933
|
for (const part of parts) {
|
|
925
934
|
if (replacement !== void 0 && replacement !== null && typeof replacement === "object" && part in replacement) {
|
|
@@ -1265,10 +1274,13 @@ var defaultRedactFunction = (_keyName, value) => {
|
|
|
1265
1274
|
return "***REDACTED***";
|
|
1266
1275
|
};
|
|
1267
1276
|
function setNestedValue(obj, path, value) {
|
|
1268
|
-
const parts = path
|
|
1277
|
+
const parts = getPathParts(path);
|
|
1269
1278
|
let current = obj;
|
|
1270
1279
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
1271
1280
|
const part = parts[i];
|
|
1281
|
+
if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1272
1284
|
const next = current[part];
|
|
1273
1285
|
if (next === void 0 || next === null || typeof next !== "object") {
|
|
1274
1286
|
return;
|
|
@@ -1276,12 +1288,12 @@ function setNestedValue(obj, path, value) {
|
|
|
1276
1288
|
current = next;
|
|
1277
1289
|
}
|
|
1278
1290
|
const lastPart = parts[parts.length - 1];
|
|
1279
|
-
if (lastPart !== void 0 && lastPart in current) {
|
|
1291
|
+
if (lastPart !== void 0 && current !== void 0 && current !== null && typeof current === "object" && lastPart in current) {
|
|
1280
1292
|
current[lastPart] = value;
|
|
1281
1293
|
}
|
|
1282
1294
|
}
|
|
1283
1295
|
function getNestedValue(obj, path) {
|
|
1284
|
-
const parts = path
|
|
1296
|
+
const parts = getPathParts(path);
|
|
1285
1297
|
let current = obj;
|
|
1286
1298
|
for (const part of parts) {
|
|
1287
1299
|
if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
|
|
@@ -1298,7 +1310,7 @@ function applyRedaction(params, redactedKeys, redactFunction) {
|
|
|
1298
1310
|
const redactFn = redactFunction || defaultRedactFunction;
|
|
1299
1311
|
const redactedParams = deepClone(params);
|
|
1300
1312
|
for (const key of redactedKeys) {
|
|
1301
|
-
if (key.includes(".")) {
|
|
1313
|
+
if (key.includes(".") || key.includes("[")) {
|
|
1302
1314
|
const value = getNestedValue(redactedParams, key);
|
|
1303
1315
|
if (value !== void 0) {
|
|
1304
1316
|
const redactedValue = redactFn(key, value);
|