UNPKG

684 BPlain TextView Raw
1const parseIsSsrByDefault = (): boolean =>
2 !(typeof window !== 'undefined' && window.document && window.document.createElement && window.setTimeout);
3
4export interface GlobalConfig {
5 isSsr?: boolean;
6}
7
8export type GlobalConfigKeys = 'isSsr';
9
10export const Global = {
11 isSsr: parseIsSsrByDefault(),
12
13 get: (key: 'isSsr') => {
14 return Global[key];
15 },
16
17 set: (key: GlobalConfigKeys | GlobalConfig, value?: any) => {
18 if (typeof key === 'string') {
19 Global[key] = value;
20 } else {
21 const keys = Object.keys(key);
22
23 if (keys && keys.length) {
24 keys.forEach((k: GlobalConfigKeys) => {
25 Global[k] = key[k];
26 });
27 }
28 }
29 },
30};