1
0
mirror of https://github.com/lancedikson/bowser synced 2026-03-02 03:40:27 +00:00

Merge pull request #276 from rcsandell/master

Support Android version names, Recognise Huawei devices
This commit is contained in:
Denis Demchenko
2019-01-06 22:40:40 +02:00
committed by GitHub
5 changed files with 115 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import {
getFirstMatch,
getWindowsVersionName,
getAndroidVersionName,
} from './utils';
export default [
@@ -65,10 +66,15 @@ export default [
},
describe(ua) {
const version = getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
return {
const versionName = getAndroidVersionName(version);
const os = {
name: 'Android',
version,
};
if (versionName) {
os.versionName = versionName;
}
return os;
},
},

View File

@@ -12,6 +12,22 @@ const TYPES_LABELS = {
*/
export default [
/* Huawei */
{
test: [/huawei/i],
describe(ua) {
const model = getFirstMatch(/(can-l01)/i, ua) && 'Nova';
const platform = {
type: TYPES_LABELS.mobile,
vendor: 'Huawei',
};
if (model) {
platform.model = model;
}
return platform;
},
},
/* Nexus Tablet */
{
test: [/nexus\s*(?:7|8|9|10).*/i],

View File

@@ -51,6 +51,50 @@ class Utils {
}
}
/**
* Get Android version name
* 1.5 - Cupcake
* 1.6 - Donut
* 2.0 - Eclair
* 2.1 - Eclair
* 2.2 - Froyo
* 2.x - Gingerbread
* 3.x - Honeycomb
* 4.0 - Ice Cream Sandwich
* 4.1 - Jelly Bean
* 4.4 - KitKat
* 5.x - Lollipop
* 6.x - Marshmallow
* 7.x - Nougat
* 8.x - Oreo
* 9.x - ?
*
* @example
* getAndroidVersionName("7.0") // 'Nougat'
*
* @param {string} version
* @return {string} versionName
*/
static getAndroidVersionName(version) {
const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0);
v.push(0);
if (v[0] === 1 && v[1] < 5) return undefined;
if (v[0] === 1 && v[1] < 6) return 'Cupcake';
if (v[0] === 1 && v[1] >= 6) return 'Donut';
if (v[0] === 2 && v[1] < 2) return 'Eclair';
if (v[0] === 2 && v[1] === 2) return 'Froyo';
if (v[0] === 2 && v[1] > 2) return 'Gingerbread';
if (v[0] === 3) return 'Honeycomb';
if (v[0] === 4 && v[1] < 1) return 'Ice Cream Sandwich';
if (v[0] === 4 && v[1] < 4) return 'Jelly Bean';
if (v[0] === 4 && v[1] >= 4) return 'KitKat';
if (v[0] === 5) return 'Lollipop';
if (v[0] === 6) return 'Marshmallow';
if (v[0] === 7) return 'Nougat';
if (v[0] === 8) return 'Oreo';
return undefined;
}
/**
* Get version precisions count
*