mirror of
https://github.com/lancedikson/bowser
synced 2025-06-13 13:03:52 +00:00
Add detection of macOS version names
This commit is contained in:
parent
72b59a9208
commit
afc19c86c9
@ -46,9 +46,12 @@ export default [
|
||||
test: [/macintosh/i],
|
||||
describe(ua) {
|
||||
const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.');
|
||||
const versionName = Utils.getMacOSVersionName(version);
|
||||
|
||||
return {
|
||||
name: OS_MAP.MacOS,
|
||||
version,
|
||||
versionName
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
32
src/utils.js
32
src/utils.js
@ -53,6 +53,38 @@ export default class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get macOS version name
|
||||
* 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;
|
||||
if (v[1] === 8) return 'Mountain Lion';
|
||||
if (v[1] === 9) return 'Mavericks';
|
||||
if (v[1] === 10) return 'Yosemite';
|
||||
if (v[1] === 11) return 'El Capitan';
|
||||
if (v[1] === 12) return 'Sierra';
|
||||
if (v[1] === 13) return 'High Sierra';
|
||||
if (v[1] === 14) return 'Mojave';
|
||||
if (v[1] === 15) return 'Catalina';
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Android version name
|
||||
* 1.5 - Cupcake
|
||||
|
||||
Loading…
Reference in New Issue
Block a user