-
Notifications
You must be signed in to change notification settings - Fork 1
/
bom.ts
72 lines (66 loc) · 1.53 KB
/
bom.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @description 判断是否是移动端(判断比较粗糙)
* @return {*}
*/
export const isMobile = () => {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
};
/**
* @description 判断设备类型
* @return {*}
*/
export const judgeDevice = () => {
const ua = navigator.userAgent;
const isAndroid = /(Android)/i.test(ua);
const isIphone = /(iPhone|iPad|iPod|iOS)/i.test(ua);
return { isAndroid, isIphone };
};
/**
* @description 判断是否是浏览器环境
* @param {*} boolean
* @return {*}
*/
export const isBrowser = () =>
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined';
/**
* @description 判断是否是Safari浏览器
* @return {*}
*/
export const isSafari = () => {
return (
/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)
);
};
/**
* @description 判断是否是ie浏览器
* @return {*}
*/
export const isIe = () => {
return (
navigator.userAgent.indexOf('MSIE') !== -1 ||
navigator.userAgent.indexOf('Trident') !== -1
);
};
/**
* @description 判断是否是Firefox浏览器
* @return {*}
*/
export const isFirefox = () => {
return navigator.userAgent.indexOf('Firefox') !== -1;
};
/**
* @description 判断是否是支持webp
* @return {*}
*/
export const isSupportWebp = () => {
return (
document
.createElement('canvas')
.toDataURL('image/webp')
.indexOf('data:image/webp') === 0
);
};