diff --git a/src/parser-os.js b/src/parser-os.js index 939aa34a..a66a118c 100644 --- a/src/parser-os.js +++ b/src/parser-os.js @@ -46,10 +46,16 @@ export default [ test: [/macintosh/i], describe(ua) { const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.'); - return { + const versionName = Utils.getMacOSVersionName(version); + + const os = { name: OS_MAP.MacOS, version, }; + if (versionName) { + os.versionName = versionName; + } + return os; }, }, diff --git a/src/utils.js b/src/utils.js index 171dfae6..7e36f8fa 100644 --- a/src/utils.js +++ b/src/utils.js @@ -53,6 +53,46 @@ export default class Utils { } } + /** + * Get macOS version name + * 10.5 - Leopard + * 10.6 - Snow Leopard + * 10.7 - Lion + * 10.8 - Mountain Lion + * 10.9 - Mavericks + * 10.10 - Yosemite + * 10.11 - El Capitan + * 10.12 - Sierra + * 10.13 - High Sierra + * 10.14 - Mojave + * 10.15 - Catalina + * + * @example + * getMacOSVersionName("10.14") // 'Mojave' + * + * @param {string} version + * @return {string} versionName + */ + static getMacOSVersionName(version) { + const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0); + v.push(0); + if (v[0] !== 10) return undefined; + switch (v[1]) { + case 5: return 'Leopard'; + case 6: return 'Snow Leopard'; + case 7: return 'Lion'; + case 8: return 'Mountain Lion'; + case 9: return 'Mavericks'; + case 10: return 'Yosemite'; + case 11: return 'El Capitan'; + case 12: return 'Sierra'; + case 13: return 'High Sierra'; + case 14: return 'Mojave'; + case 15: return 'Catalina'; + default: return undefined; + } + } + /** * Get Android version name * 1.5 - Cupcake @@ -69,7 +109,7 @@ export default class Utils { * 6.x - Marshmallow * 7.x - Nougat * 8.x - Oreo - * 9.x - ? + * 9.x - Pie * * @example * getAndroidVersionName("7.0") // 'Nougat' @@ -94,6 +134,7 @@ export default class Utils { if (v[0] === 6) return 'Marshmallow'; if (v[0] === 7) return 'Nougat'; if (v[0] === 8) return 'Oreo'; + if (v[0] === 9) return 'Pie'; return undefined; } diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 713d5771..403275a2 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -207,6 +207,21 @@ type: "desktop" engine: name: "Blink" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" + spec: + browser: + name: "Chrome" + version: "49.0.2623.112" + os: + name: "macOS" + version: "10.7.5" + versionName: "Lion" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "Blink" - ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24" spec: @@ -216,6 +231,7 @@ os: name: "macOS" version: "10.6.7" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -378,6 +394,7 @@ os: name: "macOS" version: "10.6.3" + versionName: "Snow Leopard" platform: type: "tablet" vendor: "Amazon" @@ -539,6 +556,7 @@ os: name: "macOS" version: "10.6.7" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -665,6 +683,7 @@ os: name: "macOS" version: "10.10.3" + versionName: "Yosemite" platform: type: "desktop" vendor: "Apple" @@ -711,6 +730,7 @@ os: name: "macOS" version: "10.6.8" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -726,6 +746,7 @@ os: name: "macOS" version: "10.6.7" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -784,12 +805,29 @@ os: name: "macOS" version: "10.6.1" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" engine: name: "WebKit" version: "531.21.10" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A" + spec: + browser: + name: "Safari" + version: "7.0.3" + os: + name: "macOS" + version: "10.9.3" + versionName: "Mavericks" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "WebKit" + version: "537.75.14" - ua: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; de-de) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.28.3" spec: @@ -799,6 +837,7 @@ os: name: "macOS" version: "10.5.7" + versionName: "Leopard" platform: type: "desktop" vendor: "Apple" @@ -868,6 +907,22 @@ engine: name: "WebKit" version: "532.9" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13) AppleWebKit/604.1.31 (KHTML, like Gecko) Version/11.0 Safari/604.1.31" + spec: + browser: + name: "Safari" + version: "11.0" + os: + name: "macOS" + version: "10.13" + versionName: "High Sierra" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "WebKit" + version: "604.1.31" - ua: "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone" spec: @@ -877,6 +932,7 @@ os: name: "macOS" version: "10.5.2" + versionName: "Leopard" platform: type: "mobile" vendor: "Apple" @@ -1540,6 +1596,7 @@ os: name: "macOS" version: "10.8" + versionName: "Mountain Lion" platform: type: "desktop" vendor: "Apple" @@ -1652,6 +1709,7 @@ os: name: "macOS" version: "10.6" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -1717,6 +1775,22 @@ engine: name: "WebKit" version: "601.1.46" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0" + spec: + browser: + name: "Firefox" + version: "68.0" + os: + name: "macOS" + version: "10.14" + versionName: "Mojave" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "Gecko" + version: "20100101" SeaMonkey: - ua: "Mozilla/5.0 (Windows NT 5.2; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 SeaMonkey/2.7.1" @@ -1742,6 +1816,7 @@ os: name: "macOS" version: "10.5" + versionName: "Leopard" platform: type: "desktop" vendor: "Apple" @@ -2070,6 +2145,21 @@ engine: name: "WebKit" version: "533.1" + - + ua: "Mozilla/5.0 (Linux; U; Android 2.2; en-us; GT-I5800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" + spec: + browser: + name: "Android Browser" + version: "4.0" + os: + name: "Android" + version: "2.2" + versionName: "Froyo" + platform: + type: "mobile" + engine: + name: "WebKit" + version: "533.1" - ua: "Mozilla/5.0 (Linux; U; Android 1.6; ar-us; SonyEricssonX10i Build/R2BA026) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1" spec: @@ -2252,6 +2342,7 @@ os: name: "macOS" version: "10.11.1" + versionName: "El Capitan" platform: type: "desktop" vendor: "Apple" @@ -2290,6 +2381,7 @@ os: name: "macOS" version: "10.6.8" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -2614,6 +2706,7 @@ os: name: "macOS" version: "10.12.6" + versionName: "Sierra" platform: type: "desktop" vendor: "Apple" diff --git a/test/unit/utils.js b/test/unit/utils.js index ecbf85f3..b41843e9 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -3,6 +3,8 @@ import { getBrowserAlias, getFirstMatch, getWindowsVersionName, + getMacOSVersionName, + getAndroidVersionName, compareVersions, } from '../../src/utils'; @@ -16,6 +18,20 @@ test('getWindowsVersionName', (t) => { t.is(getWindowsVersionName('XXX'), void 0); }); +test('getMacOSVersionName', (t) => { + t.is(getMacOSVersionName('10.14.5'), 'Mojave'); + t.is(getMacOSVersionName('10.15'), 'Catalina'); + t.is(getMacOSVersionName('10.999999'), void 0); + t.is(getMacOSVersionName('XXX'), void 0); +}); + +test('getAndroidVersionName', (t) => { + t.is(getAndroidVersionName('1.0'), void 0); + t.is(getAndroidVersionName('8.0'), 'Oreo'); + t.is(getAndroidVersionName('9'), 'Pie'); + t.is(getAndroidVersionName('XXX'), void 0); +}); + test('compareVersions', (t) => { const comparisionsTasks = [ ['9.0', '10', -1],