@loggerjs/processors 0.5.5 → 0.6.0

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
@@ -61,6 +61,17 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
61
61
  return out;
62
62
  }
63
63
  if (value instanceof Date) return value;
64
+ const toJSON = value.toJSON;
65
+ if (typeof toJSON === "function") {
66
+ let serialized;
67
+ try {
68
+ serialized = toJSON.call(value, "");
69
+ } catch {
70
+ return options.replacement;
71
+ }
72
+ if (serialized === value) return value;
73
+ return redactValue(serialized, options, path, depth, seen);
74
+ }
64
75
  if (value instanceof Error) {
65
76
  const entries = ownEnumerableEntries$1(value);
66
77
  const hiddenFields = hiddenErrorFields(value);
@@ -1258,6 +1269,27 @@ function guardValue(value, path, key, depth, options, seen) {
1258
1269
  value,
1259
1270
  changed: false
1260
1271
  };
1272
+ const toJSON = value.toJSON;
1273
+ if (typeof toJSON === "function") {
1274
+ let serialized;
1275
+ try {
1276
+ serialized = toJSON.call(value, "");
1277
+ } catch {
1278
+ return {
1279
+ value: redact(path, "serialize-error", options),
1280
+ changed: true
1281
+ };
1282
+ }
1283
+ if (serialized === value) return {
1284
+ value,
1285
+ changed: false
1286
+ };
1287
+ const guarded = guardValue(serialized, path, key, depth, options, seen);
1288
+ return guarded.changed ? guarded : {
1289
+ value,
1290
+ changed: false
1291
+ };
1292
+ }
1261
1293
  if (value instanceof Error) {
1262
1294
  const message = guardErrorString(value.message, dotPath(path, "message"), options);
1263
1295
  const stack = guardErrorString(value.stack, dotPath(path, "stack"), options);