-
Notifications
You must be signed in to change notification settings - Fork 88
/
utils.js
45 lines (36 loc) · 932 Bytes
/
utils.js
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
export function camelToDash(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
export function pascalToDash(str) {
str = str[0].toLowerCase() + str.slice(1);
return camelToDash(str);
}
export function dispatch(host, eventType, options = {}) {
host.dispatchEvent(new CustomEvent(eventType, { bubbles: false, ...options }));
}
export function createMap() {
const map = new WeakMap();
return {
get(key, defaultValue) {
if (map.has(key)) {
return map.get(key);
}
if (defaultValue !== undefined) {
map.set(key, defaultValue);
}
return defaultValue;
},
set(key, value) {
map.set(key, value);
return value;
},
};
}
export function shadyCSS(fn, fallback) {
const shady = window.ShadyCSS;
if (shady && !shady.nativeShadow) {
return fn(shady);
}
return fallback;
}
export const IS_IE = 'ActiveXObject' in global;