in packages/ua/src/util/get-os.ts [23:64]
export default function getOs(ua: string): [EOsType, string] {
/**
* Windows
* 标识 `Windows NT x.y`,其他的 Windows ME、Windows 98 就不管了
*
* Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
*/
if (/Windows/i.test(ua)) {
if (/Windows NT ([^ /;()]+)/i.test(ua)) {
const ntVersion = `NT ${RegExp.$1}`;
return [EOsType.WINDOWS, WINDOWS_NT_TO_VERSION[ntVersion] || ntVersion];
}
// Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 1520)
if (/Windows Phone[/ ]([^ /;()]+)/i.test(ua)) {
return [EOsType.WINDOWS_PHONE, RegExp.$1];
}
// Opera/9.80 (Windows Mobile; Opera Mini/5.1.21594/37.6270; U; en) Presto/2.12.423 Version/12.16
if (/Windows Mobile/i.test(ua)) {
return [EOsType.WINDOWS_MOBILE, ''];
}
return [EOsType.WINDOWS, ''];
}
// MacOS
// e.g. Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15
if (/Mac OS X ([^ /;()]+)/i.test(ua)) {
return [EOsType.MAC_OS, RegExp.$1.replace(/_/g, '.')];
}
// iOs - iPhone + iPad
// Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
// Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; nl-nl) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
if (/iPhone|iPad/i.test(ua)) {
if (/CPU (?:iPhone )?OS ([^ /;()]+)/i.test(ua)) { // iPad 是 CPU OS,iPhone 是 CPU iPhone OS
return [EOsType.IOS, RegExp.$1.replace(/_/g, '.')];
}
}