forked from apache/dolphinscheduler-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (34 loc) · 934 Bytes
/
index.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
/* eslint-disable import/prefer-default-export */
export const throttle = (fn, delay) => {
let timer = null;
return function (...args) {
const context = this;
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(context, args);
}, delay);
};
};
export const getScrollTop = () => {
let scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
};
export const getLink = (link) => {
if (`${link}`.length > 1 && /^\/[^/]/.test(`${link}`)) {
return `${window.rootPath}${link}`;
}
return link;
};
export const parseJSONStr = (str) => {
try {
return JSON.parse(str);
} catch (err) {
return str;
}
};
export const getKiloUnit = val => (typeof val === 'number' ? `${Math.round(val / 100) / 10}K` : val);