(value: V)
| 132 | * an Error. |
| 133 | */ |
| 134 | export function convertToPlainObject<V>(value: V): Record<string, unknown> | V { |
| 135 | if (isError(value)) { |
| 136 | return { |
| 137 | message: value.message, |
| 138 | name: value.name, |
| 139 | stack: value.stack, |
| 140 | ...getOwnProperties(value), |
| 141 | }; |
| 142 | } |
| 143 | |
| 144 | // This handles browser events specifically, where certain properties are non-enumerable and need to be unpacked. |
| 145 | if (isEvent(value)) { |
| 146 | const { type, target, currentTarget, detail } = value; |
| 147 | return { |
| 148 | type, |
| 149 | target, |
| 150 | currentTarget, |
| 151 | ...(detail ? { detail } : {}), |
| 152 | ...getOwnProperties(value), |
| 153 | }; |
| 154 | } |
| 155 | |
| 156 | return value; |
| 157 | } |
| 158 | |
| 159 | /** Filters out all but an object's own properties */ |
| 160 | function getOwnProperties(obj: unknown): { [key: string]: unknown } { |
no test coverage detected