Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OS version names #338

Merged
merged 4 commits into from Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/parser-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
},

Expand Down
43 changes: 42 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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;
}

Expand Down
93 changes: 93 additions & 0 deletions test/acceptance/useragentstrings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -216,6 +231,7 @@
os:
name: "macOS"
version: "10.6.7"
versionName: "Snow Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -378,6 +394,7 @@
os:
name: "macOS"
version: "10.6.3"
versionName: "Snow Leopard"
platform:
type: "tablet"
vendor: "Amazon"
Expand Down Expand Up @@ -539,6 +556,7 @@
os:
name: "macOS"
version: "10.6.7"
versionName: "Snow Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -665,6 +683,7 @@
os:
name: "macOS"
version: "10.10.3"
versionName: "Yosemite"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -711,6 +730,7 @@
os:
name: "macOS"
version: "10.6.8"
versionName: "Snow Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand All @@ -726,6 +746,7 @@
os:
name: "macOS"
version: "10.6.7"
versionName: "Snow Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -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:
Expand All @@ -799,6 +837,7 @@
os:
name: "macOS"
version: "10.5.7"
versionName: "Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -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:
Expand All @@ -877,6 +932,7 @@
os:
name: "macOS"
version: "10.5.2"
versionName: "Leopard"
platform:
type: "mobile"
vendor: "Apple"
Expand Down Expand Up @@ -1540,6 +1596,7 @@
os:
name: "macOS"
version: "10.8"
versionName: "Mountain Lion"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -1652,6 +1709,7 @@
os:
name: "macOS"
version: "10.6"
versionName: "Snow Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -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"
Expand All @@ -1742,6 +1816,7 @@
os:
name: "macOS"
version: "10.5"
versionName: "Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -2252,6 +2342,7 @@
os:
name: "macOS"
version: "10.11.1"
versionName: "El Capitan"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -2290,6 +2381,7 @@
os:
name: "macOS"
version: "10.6.8"
versionName: "Snow Leopard"
platform:
type: "desktop"
vendor: "Apple"
Expand Down Expand Up @@ -2614,6 +2706,7 @@
os:
name: "macOS"
version: "10.12.6"
versionName: "Sierra"
platform:
type: "desktop"
vendor: "Apple"
Expand Down
16 changes: 16 additions & 0 deletions test/unit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
getBrowserAlias,
getFirstMatch,
getWindowsVersionName,
getMacOSVersionName,
getAndroidVersionName,
compareVersions,
} from '../../src/utils';

Expand All @@ -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],
Expand Down