export function toRecord(value: unknown): Record { if (!value || typeof value !== "object" || Array.isArray(value)) { return {}; } return value as Record; } /** * Whether a value is a record a structural walk should descend into. * * A class instance (a `Date`, an `Error`) is not: rebuilding one as a plain * object would change what a serializer downstream writes. Distinct from * {@link toRecord}, which reads a value as a record without asking how it was * built. */ export function isPlainRecord( value: unknown, ): value is Record { if (typeof value !== "object" || value === null) return false; const prototype: unknown = Object.getPrototypeOf(value); return prototype === Object.prototype || prototype === null; } export function getNonEmptyString(value: unknown): string | null { if (typeof value !== "string") { return null; } const trimmed = value.trim(); return trimmed.length > 0 ? trimmed : null; }