-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetAppVersion.ts
39 lines (38 loc) · 989 Bytes
/
getAppVersion.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
/**
* Get the APP version number
*
* @deprecated please use 'appVersion' instead
* @since 1.0.1
* @param appName - app name
* @param withApp - whether to bring the name
* @param userAgent - ua, may not be passed, default is navigator.appVersion
* @return null/true/false
*/
function getAppVersion(
appName: string,
withApp?: boolean,
userAgent?: string
): string | boolean | null {
userAgent = userAgent || navigator.appVersion
const reg = new RegExp(appName + '\\/([\\d\\.]+)', 'i')
const isApp = userAgent.includes(appName)
const ver = userAgent.match(reg)
// withApp = typeof(withApp) != "undefined" ? withApp : false;
if (ver) {
if (withApp) {
// Need to bring the app name, complete output
return ver ? ver[0] : ''
} else {
return ver ? ver[1] : ''
}
} else {
if (isApp) {
// is the specified client but the version number is unknown
return false
} else {
// Not a designated client
return null
}
}
}
export default getAppVersion