-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
28 lines (27 loc) · 760 Bytes
/
Copy pathutils.ts
File metadata and controls
28 lines (27 loc) · 760 Bytes
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
export function getComponent(data:any, component:string|string[]) {
if (Array.isArray(component)) {
return Object.keys(component)
.reduce((obj, key)=> ({
...obj,
[key]: data[key]
}), {});
} else if (typeof component === 'string') {
return data[component];
} else if (data.default) {
return data.default;
} else {
throw new Error('Bundle does not export a component');
}
}
export function getScope() {
if (typeof globalThis === 'object' && globalThis)
return globalThis;
if (typeof window === 'object' && window)
return window;
if (typeof self === 'object' && self)
return self;
if (typeof global === 'object' && global)
return global;
else
return Function('return this')();
}