lifecycleion 0.0.3 → 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.
@@ -934,7 +934,17 @@ function ms() {
934
934
  return Date.now();
935
935
  }
936
936
 
937
+ // src/lib/internal/path-utils.ts
938
+ var PATH_SEGMENT_PATTERN = /\w+|\[(\d+)\]/g;
939
+ function getPathParts(path) {
940
+ return Array.from(
941
+ path.matchAll(PATH_SEGMENT_PATTERN),
942
+ (match) => match[1] ?? match[0]
943
+ );
944
+ }
945
+
937
946
  // src/lib/curly-brackets.ts
947
+ var PLACEHOLDER_PATTERN = /(?:\\)?{{(\s*\w+(?:\[\d+\])*(?:\.\w+(?:\[\d+\])*)*\s*)(?:\\)?\s*}}/g;
938
948
  var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
939
949
  if (!str.includes("{{")) {
940
950
  return str;
@@ -943,9 +953,8 @@ var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
943
953
  return compiled(locals);
944
954
  };
945
955
  CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
946
- const pattern = /(?:\\)?{{(\s*[\w.]+?)(?:\\)?\s*}}/g;
947
956
  return (locals) => {
948
- return str.replace(pattern, (match, p1) => {
957
+ return str.replace(PLACEHOLDER_PATTERN, (match, p1) => {
949
958
  if (typeof p1 !== "string") {
950
959
  return match;
951
960
  }
@@ -962,7 +971,7 @@ CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
962
971
  return "{{" + p1.trim() + "}}";
963
972
  }
964
973
  const key = p1.trim();
965
- const parts = key.split(".");
974
+ const parts = getPathParts(key);
966
975
  let replacement = locals;
967
976
  for (const part of parts) {
968
977
  if (replacement !== void 0 && replacement !== null && typeof replacement === "object" && part in replacement) {
@@ -1308,10 +1317,13 @@ var defaultRedactFunction = (_keyName, value) => {
1308
1317
  return "***REDACTED***";
1309
1318
  };
1310
1319
  function setNestedValue(obj, path, value) {
1311
- const parts = path.split(".");
1320
+ const parts = getPathParts(path);
1312
1321
  let current = obj;
1313
1322
  for (let i = 0; i < parts.length - 1; i++) {
1314
1323
  const part = parts[i];
1324
+ if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
1325
+ return;
1326
+ }
1315
1327
  const next = current[part];
1316
1328
  if (next === void 0 || next === null || typeof next !== "object") {
1317
1329
  return;
@@ -1319,12 +1331,12 @@ function setNestedValue(obj, path, value) {
1319
1331
  current = next;
1320
1332
  }
1321
1333
  const lastPart = parts[parts.length - 1];
1322
- if (lastPart !== void 0 && lastPart in current) {
1334
+ if (lastPart !== void 0 && current !== void 0 && current !== null && typeof current === "object" && lastPart in current) {
1323
1335
  current[lastPart] = value;
1324
1336
  }
1325
1337
  }
1326
1338
  function getNestedValue(obj, path) {
1327
- const parts = path.split(".");
1339
+ const parts = getPathParts(path);
1328
1340
  let current = obj;
1329
1341
  for (const part of parts) {
1330
1342
  if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
@@ -1341,7 +1353,7 @@ function applyRedaction(params, redactedKeys, redactFunction) {
1341
1353
  const redactFn = redactFunction || defaultRedactFunction;
1342
1354
  const redactedParams = deepClone(params);
1343
1355
  for (const key of redactedKeys) {
1344
- if (key.includes(".")) {
1356
+ if (key.includes(".") || key.includes("[")) {
1345
1357
  const value = getNestedValue(redactedParams, key);
1346
1358
  if (value !== void 0) {
1347
1359
  const redactedValue = redactFn(key, value);