-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathis.ts
38 lines (38 loc) · 936 Bytes
/
is.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
/**
* 一些常用的简单环境判断
* @param env
* @returns
*/
export function is(
env:
| "ios" // ios平台
| "android" // android平台
| "wechat" // 微信环境
| "qq" // QQ环境
| "alipay" // 支付宝环境
| "weibo" // 微博环境
| "douyin" // 抖音环境
| "touchable" // 可触摸环境
) {
const ua = window.navigator.userAgent;
switch (env.toLowerCase()) {
case "ios":
return /iPhone|iPad/i.test(ua);
case "android":
return /Android/i.test(ua);
case "wechat":
return /MicroMessenger/i.test(ua);
case "qq":
return /QQ/i.test(ua);
case "alipay":
return /AlipayClient/i.test(ua);
case "weibo":
return /Weibo/i.test(ua);
case "douyin":
return /aweme/i.test(ua);
case "touchable":
return window.ontouchstart !== undefined;
default:
return false;
}
}