MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / convertToPlainObject

Function convertToPlainObject

packages/core/src/utils/object.ts:134–157  ·  view source on GitHub ↗
(value: V)

Source from the content-addressed store, hash-verified

132 * an Error.
133 */
134export 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 */
160function getOwnProperties(obj: unknown): { [key: string]: unknown } {

Callers 2

visitFunction · 0.90

Calls 3

isErrorFunction · 0.90
isEventFunction · 0.90
getOwnPropertiesFunction · 0.85

Tested by

no test coverage detected