Skip to content

Commit d22874a

Browse files
committed
s/normalizeValue/makeSerializable and update docstring
1 parent f55f069 commit d22874a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/utils/src/object.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,20 @@ function serializeValue(value: any): any {
231231
return '[Array]';
232232
}
233233

234-
const normalized = normalizeValue(value);
235-
return isPrimitive(normalized) ? normalized : type;
234+
// `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
235+
// pass-through.
236+
const serializable = makeSerializable(value);
237+
return isPrimitive(serializable) ? serializable : type;
236238
}
237239

238240
/**
239-
* normalizeValue()
241+
* makeSerializable()
240242
*
241-
* Takes unserializable input and make it serializable friendly
243+
* Takes unserializable input and make it serializer-friendly.
242244
*
243-
* - translates undefined/NaN values to "[undefined]"/"[NaN]" respectively,
244-
* - serializes Error objects
245-
* - filter global objects
245+
* Handles globals, functions, `undefined`, `NaN`, and other non-serializable values.
246246
*/
247-
function normalizeValue<T>(value: T, key?: any): T | string {
247+
function makeSerializable<T>(value: T, key?: any): T | string {
248248
if (key === 'domain' && value && typeof value === 'object' && (value as unknown as { _events: any })._events) {
249249
return '[Domain]';
250250
}
@@ -322,10 +322,12 @@ export function walk(key: string, value: any, depth: number = +Infinity, memo: M
322322
}
323323
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
324324

325-
// If normalized value is a primitive, there are no branches left to walk, so bail out
326-
const normalized = normalizeValue(value, key);
327-
if (isPrimitive(normalized)) {
328-
return normalized;
325+
// `makeSerializable` provides a string representation of certain non-serializable values. For all others, it's a
326+
// pass-through. If what comes back is a primitive (either because it's been stringified or because it was primitive
327+
// all along), we're done.
328+
const serializable = makeSerializable(value, key);
329+
if (isPrimitive(serializable)) {
330+
return serializable;
329331
}
330332

331333
// Create source that we will use for the next iteration. It will either be an objectified error object (`Error` type

0 commit comments

Comments
 (0)