fix .bin typo
[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 (/^ms$|Microsoft|Windows|win32|win|PowerShell/i.test(ua)) {
14     // 'win' must be tested after 'darwin'
15     return 'windows';
16   } else if (/Linux|curl|wget/i.test(ua)) {
17     return 'linux';
18   } else {
19     return 'error';
20   }
21 }
22
23 function getArch(ua) {
24   if ('-' === ua) {
25     return '-';
26   }
27
28   if (/arm64|arm8|armv8/i.test(ua)) {
29     return 'arm64';
30   } else if (/arm7|armv7/i.test(ua)) {
31     return 'armv7l';
32   } else if (/arm6|armv6/i.test(ua)) {
33     return 'armv6l';
34   } else if (/ppc64/i.test(ua)) {
35     return 'ppc64';
36   } else if (/mips64/i.test(ua)) {
37     return 'mips64';
38   } else if (/mips/i.test(ua)) {
39     return 'mips';
40   } else if (/(amd64|x64|_64)\b/i.test(ua)) {
41     // must come after ppc64/mips64
42     return 'amd64';
43   } else if (/(3|6|x|_)86\b/i.test(ua)) {
44     // must come after x86_64
45     return 'x86';
46   } else {
47     // TODO handle explicit invalid different
48     return 'error';
49   }
50 }
51
52 module.exports.os = getOs;
53 module.exports.arch = getArch;