Repository navigation
Expand file tree
/
Copy pathnormalizeStringifyValue.ts
More file actions
47 lines (42 loc) · 1.52 KB
/
Copy pathnormalizeStringifyValue.ts
File metadata and controls
47 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { normalizeStringifyValue as browserNormalizeStringifyValue } from '@sentry/browser';
interface VueViewModel {
// Vue3
__isVue?: boolean;
// Vue2
_isVue?: boolean;
}
interface VNode {
// Vue3 — https://github.com/vuejs/core/blob/main/packages/runtime-core/src/vnode.ts
__v_isVNode?: boolean;
}
/**
* Checks whether the given value is a Vue ViewModel (Vue 2 / Vue 3 component
* instance) or a Vue 3 `VNode`.
*
* The check is structural (not `instanceof`) because in Vue 3 the toString tag
* would read a custom `Symbol.toStringTag`, and we want a cheap, runtime-safe
* probe that works on either Vue version.
*/
function isVueViewModel(wat: unknown): wat is VueViewModel {
return !!(typeof wat === 'object' && wat && ((wat as VueViewModel).__isVue || (wat as VueViewModel)._isVue));
}
/**
* Checks whether the given value is a Vue ViewModel (Vue 2 / Vue 3 component
* instance) or a Vue 3 `VNode`.
*
* The check is structural (not `instanceof`) because in Vue 3 the toString tag
* would read a custom `Symbol.toStringTag`, and we want a cheap, runtime-safe
* probe that works on either Vue version.
*/
function isVNode(wat: unknown): wat is VNode {
return !!(typeof wat === 'object' && (wat as VNode | null)?.__v_isVNode);
}
export function normalizeStringifyValue(value: Exclude<unknown, string | number | boolean | null>): string | undefined {
if (isVueViewModel(value)) {
return '[VueViewModel]';
}
if (isVNode(value)) {
return '[VueVNode]';
}
return browserNormalizeStringifyValue(value);
}