@loggerjs/processors 0.5.2 → 0.5.4

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/dist/index.js CHANGED
@@ -22,16 +22,25 @@ function dotPath(path, field) {
22
22
  }
23
23
  //#endregion
24
24
  //#region src/redact.ts
25
+ function keyName$1(key) {
26
+ if (typeof key === "symbol") return key.description ?? key.toString();
27
+ return String(key);
28
+ }
29
+ function ownEnumerableEntries$1(value) {
30
+ return Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key)).map((key) => [key, value[key]]);
31
+ }
25
32
  function matchesKey(key, path, value, matchers) {
33
+ const name = keyName$1(key);
26
34
  return matchers.some((matcher) => {
27
- if (typeof matcher === "string") return matcher.toLowerCase() === key.toLowerCase();
35
+ if (typeof matcher === "symbol") return matcher === key;
36
+ if (typeof matcher === "string") return matcher.toLowerCase() === name.toLowerCase();
28
37
  if (matcher instanceof RegExp) {
29
38
  matcher.lastIndex = 0;
30
- const keyMatches = matcher.test(key);
39
+ const keyMatches = matcher.test(name);
31
40
  matcher.lastIndex = 0;
32
41
  return keyMatches || matcher.test(path);
33
42
  }
34
- return matcher(key, path, value);
43
+ return matcher(name, path, value);
35
44
  });
36
45
  }
37
46
  function pathMatches(path, paths) {
@@ -53,7 +62,7 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
53
62
  }
54
63
  if (value instanceof Date) return value;
55
64
  if (value instanceof Error) {
56
- const entries = Object.entries(value);
65
+ const entries = ownEnumerableEntries$1(value);
57
66
  const hiddenFields = hiddenErrorFields(value);
58
67
  if (entries.length === 0 && hiddenFields.length === 0) return value;
59
68
  const errorOut = Object.create(Object.getPrototypeOf(value));
@@ -71,7 +80,7 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
71
80
  defineHidden(errorOut, field, redactValue(child, options, childPath, depth + 1, seen));
72
81
  }
73
82
  for (const [key, child] of entries) {
74
- const childPath = dotPath(path, key);
83
+ const childPath = dotPath(path, keyName$1(key));
75
84
  if (shouldRedact(key, childPath, child, options)) {
76
85
  if (options.remove) continue;
77
86
  errorOut[key] = options.replacement;
@@ -83,8 +92,8 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
83
92
  const mapOut = /* @__PURE__ */ new Map();
84
93
  seen.set(value, mapOut);
85
94
  for (const [key, child] of value) {
86
- if (typeof key === "string") {
87
- const childPath = dotPath(path, key);
95
+ if (typeof key === "string" || typeof key === "symbol") {
96
+ const childPath = dotPath(path, keyName$1(key));
88
97
  if (shouldRedact(key, childPath, child, options)) {
89
98
  if (options.remove) continue;
90
99
  mapOut.set(key, options.replacement);
@@ -107,11 +116,10 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
107
116
  }
108
117
  return setOut;
109
118
  }
110
- const input = value;
111
119
  const out = {};
112
120
  seen.set(value, out);
113
- for (const [key, child] of Object.entries(input)) {
114
- const childPath = dotPath(path, key);
121
+ for (const [key, child] of ownEnumerableEntries$1(value)) {
122
+ const childPath = dotPath(path, keyName$1(key));
115
123
  if (shouldRedact(key, childPath, child, options)) {
116
124
  if (options.remove) continue;
117
125
  out[key] = options.replacement;
@@ -1102,6 +1110,13 @@ function isAsciiAlphaNumeric(code) {
1102
1110
  function hasChar(code, chars) {
1103
1111
  return chars.includes(String.fromCharCode(code));
1104
1112
  }
1113
+ function keyName(key) {
1114
+ if (typeof key === "symbol") return key.description ?? key.toString();
1115
+ return String(key);
1116
+ }
1117
+ function ownEnumerableEntries(value) {
1118
+ return Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key)).map((key) => [key, value[key]]);
1119
+ }
1105
1120
  function isEmailLocalChar(code) {
1106
1121
  return isAsciiAlphaNumeric(code) || hasChar(code, "._%+-");
1107
1122
  }
@@ -1167,12 +1182,14 @@ function redactEmailAddresses(input, path, options) {
1167
1182
  };
1168
1183
  }
1169
1184
  function matcherMatches(matcher, key, path, value) {
1170
- if (typeof matcher === "string") return matcher.toLowerCase() === key.toLowerCase();
1185
+ const name = keyName(key);
1186
+ if (typeof matcher === "symbol") return matcher === key;
1187
+ if (typeof matcher === "string") return matcher.toLowerCase() === name.toLowerCase();
1171
1188
  if (matcher instanceof RegExp) {
1172
1189
  matcher.lastIndex = 0;
1173
- return matcher.test(key) || matcher.test(path);
1190
+ return matcher.test(name) || matcher.test(path);
1174
1191
  }
1175
- return matcher(key, path, value);
1192
+ return matcher(name, path, value);
1176
1193
  }
1177
1194
  function matchesAny(matchers, key, path, value) {
1178
1195
  return matchers.some((matcher) => matcherMatches(matcher, key, path, value));
@@ -1245,7 +1262,7 @@ function guardValue(value, path, key, depth, options, seen) {
1245
1262
  const message = guardErrorString(value.message, dotPath(path, "message"), options);
1246
1263
  const stack = guardErrorString(value.stack, dotPath(path, "stack"), options);
1247
1264
  const fieldChanged = message.changed || stack.changed;
1248
- const entries = Object.entries(value);
1265
+ const entries = ownEnumerableEntries(value);
1249
1266
  const hiddenFields = hiddenErrorFields(value);
1250
1267
  if (entries.length === 0 && hiddenFields.length === 0 && !fieldChanged) return {
1251
1268
  value,
@@ -1263,7 +1280,7 @@ function guardValue(value, path, key, depth, options, seen) {
1263
1280
  changed ||= child.changed;
1264
1281
  }
1265
1282
  for (const [childKey, childValue] of entries) {
1266
- const child = guardValue(childValue, dotPath(path, childKey), childKey, depth + 1, options, seen);
1283
+ const child = guardValue(childValue, dotPath(path, keyName(childKey)), childKey, depth + 1, options, seen);
1267
1284
  errorOut[childKey] = child.value;
1268
1285
  changed ||= child.changed;
1269
1286
  }
@@ -1277,8 +1294,8 @@ function guardValue(value, path, key, depth, options, seen) {
1277
1294
  seen.set(value, mapOut);
1278
1295
  let changed = false;
1279
1296
  for (const [mapKey, mapValue] of value) {
1280
- const isStringKey = typeof mapKey === "string";
1281
- const child = guardValue(mapValue, isStringKey ? dotPath(path, mapKey) : path, isStringKey ? mapKey : key, depth + 1, options, seen);
1297
+ const isNamedKey = typeof mapKey === "string" || typeof mapKey === "symbol";
1298
+ const child = guardValue(mapValue, isNamedKey ? dotPath(path, keyName(mapKey)) : path, isNamedKey ? mapKey : key, depth + 1, options, seen);
1282
1299
  mapOut.set(mapKey, child.value);
1283
1300
  changed ||= child.changed;
1284
1301
  }
@@ -1317,12 +1334,11 @@ function guardValue(value, path, key, depth, options, seen) {
1317
1334
  changed
1318
1335
  };
1319
1336
  }
1320
- const input = value;
1321
1337
  const out = {};
1322
1338
  seen.set(value, out);
1323
1339
  let changed = false;
1324
- for (const [childKey, childValue] of Object.entries(input)) {
1325
- const child = guardValue(childValue, dotPath(path, childKey), childKey, depth + 1, options, seen);
1340
+ for (const [childKey, childValue] of ownEnumerableEntries(value)) {
1341
+ const child = guardValue(childValue, dotPath(path, keyName(childKey)), childKey, depth + 1, options, seen);
1326
1342
  out[childKey] = child.value;
1327
1343
  changed ||= child.changed;
1328
1344
  }