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

Function objectify

packages/core/src/utils/object.ts:258–285  ·  view source on GitHub ↗
(wat: unknown)

Source from the content-addressed store, hash-verified

256 * @returns A version of `wat` which can safely be used with `Object` class methods
257 */
258export function objectify(wat: unknown): typeof Object {
259 let objectified;
260 switch (true) {
261 // this will catch both undefined and null
262 case wat == undefined:
263 objectified = new String(wat);
264 break;
265
266 // Though symbols and bigints do have wrapper classes (`Symbol` and `BigInt`, respectively), for whatever reason
267 // those classes don't have constructors which can be used with the `new` keyword. We therefore need to cast each as
268 // an object in order to wrap it.
269 case typeof wat === 'symbol' || typeof wat === 'bigint':
270 objectified = Object(wat);
271 break;
272
273 // this will catch the remaining primitives: `String`, `Number`, and `Boolean`
274 case isPrimitive(wat):
275 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
276 objectified = new (wat as any).constructor(wat);
277 break;
278
279 // by process of elimination, at this point we know that `wat` must already be an object
280 default:
281 objectified = wat;
282 break;
283 }
284 return objectified;
285}

Callers 6

sendErrorToSentryFunction · 0.90
object.test.tsFile · 0.90
wrapApiHandlerWithSentryFunction · 0.90
sendErrorToSentryFunction · 0.90
sendErrorToSentryFunction · 0.90

Calls 1

isPrimitiveFunction · 0.90

Tested by

no test coverage detected