still fixing WSL
[webi-installers/.git] / _webi / ua-detect.js
1 'use strict';
2
3 function getOs(ua) {
4   if ('-' === ua) {
5     return '-';
6   }
7
8   if (/Android/i.test(ua)) {
9     // android must be tested before linux
10     return 'android';
11   } else if (/iOS|iPhone|Macintosh|Darwin|OS\s*X|macOS|mac/i.test(ua)) {
12     return 'macos';
13   } else if (/Linux/i.test(ua) && !/cygwin|msysgit/i.test(ua)) {
14     // It's the year of the Linux Desktop!
15     // See also http://www.mslinux.org/
16     // 'linux' must be tested before 'Microsoft' because WSL
17     // (TODO: does this affect cygwin / msysgit?)
18     return 'linux';
19   } else if (/^ms$|Microsoft|Windows|win32|win|PowerShell/i.test(ua)) {
20     // 'win' must be tested after 'darwin'
21     return 'windows';
22   } else if (/Linux|curl|wget/i.test(ua)) {
23     // test 'linux' again, after 'win'
24     return 'linux';
25   } else {
26     return 'error';
27   }
28 }
29
30 function getArch(ua) {
31   if ('-' === ua) {
32     return '-';
33   }
34
35   if (/arm64|arm8|armv8/i.test(ua)) {
36     return 'arm64';
37   } else if (/arm7|armv7/i.test(ua)) {
38     return 'armv7l';
39   } else if (/arm6|armv6/i.test(ua)) {
40     return 'armv6l';
41   } else if (/ppc64/i.test(ua)) {
42     return 'ppc64';
43   } else if (/mips64/i.test(ua)) {
44     return 'mips64';
45   } else if (/mips/i.test(ua)) {
46     return 'mips';
47   } else if (/(amd64|x64|_64)\b/i.test(ua)) {
48     // must come after ppc64/mips64
49     return 'amd64';
50   } else if (/(3|6|x|_)86\b/i.test(ua)) {
51     // must come after x86_64
52     return 'x86';
53   } else {
54     // TODO handle explicit invalid different
55     return 'error';
56   }
57 }
58
59 module.exports.os = getOs;
60 module.exports.arch = getArch;