1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Support Android version names, Recognise Huawei devices

This commit is contained in:
Robert Sandell 2018-12-30 09:03:08 +02:00
parent 70a4604873
commit f338045df7
5 changed files with 106 additions and 4 deletions

View File

@ -130,8 +130,8 @@ More of API and possibilities you will find in the `docs` folder.
If you'd like to contribute a change to bowser, modify the files in `src/`, then run the following (you'll need node + npm installed): If you'd like to contribute a change to bowser, modify the files in `src/`, then run the following (you'll need node + npm installed):
``` sh ``` sh
$ npm install $ npm install #build
$ npm test $ npm test #run tests
``` ```
### Adding tests ### Adding tests

View File

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

View File

@ -12,6 +12,22 @@ const TYPES_LABELS = {
*/ */
export default [ 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 */ /* Nexus Tablet */
{ {
test: [/nexus\s*(?:7|8|9|10).*/i], test: [/nexus\s*(?:7|8|9|10).*/i],

View File

@ -51,6 +51,51 @@ 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(function(s) {
return parseInt(s) || 0;
}).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 * Get version precisions count
* *

View File

@ -1,5 +1,21 @@
--- ---
Chrome: Chrome:
-
ua: "Mozilla/5.0 (Linux; Android 7.0; HUAWEI CAN-L01) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 Mobile Safari/537.36"
spec:
browser:
name: "Chrome"
version: "71.0.3578.99"
os:
name: "Android"
version: "7.0"
versionName: "Nougat"
platform:
type: "mobile"
vendor: "Huawei"
model: "Nova"
engine:
name: "Blink"
- -
ua: "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 9 Build/LMY48T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Safari/537.36" ua: "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 9 Build/LMY48T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Safari/537.36"
spec: spec:
@ -9,6 +25,7 @@
os: os:
name: "Android" name: "Android"
version: "5.1.1" version: "5.1.1"
versionName: "Lollipop"
platform: platform:
type: "tablet" type: "tablet"
vendor: "Nexus" vendor: "Nexus"
@ -23,6 +40,7 @@
os: os:
name: "Android" name: "Android"
version: "4.4.2" version: "4.4.2"
versionName: "KitKat"
platform: platform:
type: "tablet" type: "tablet"
vendor: "Nexus" vendor: "Nexus"
@ -37,6 +55,7 @@
os: os:
name: "Android" name: "Android"
version: "4.3" version: "4.3"
versionName: "Jelly Bean"
platform: platform:
type: "mobile" type: "mobile"
vendor: "Nexus" vendor: "Nexus"
@ -51,6 +70,7 @@
os: os:
name: "Android" name: "Android"
version: "4.1" version: "4.1"
versionName: "Jelly Bean"
platform: platform:
type: "mobile" type: "mobile"
vendor: "Nexus" vendor: "Nexus"
@ -66,6 +86,7 @@
os: os:
name: "Android" name: "Android"
version: "4.0.3" version: "4.0.3"
versionName: "Ice Cream Sandwich"
platform: platform:
type: "tablet" type: "tablet"
engine: engine:
@ -80,6 +101,7 @@
os: os:
name: "Android" name: "Android"
version: "4.0.3" version: "4.0.3"
versionName: "Ice Cream Sandwich"
platform: platform:
type: "mobile" type: "mobile"
vendor: "Nexus" vendor: "Nexus"
@ -237,6 +259,7 @@
os: os:
name: "Android" name: "Android"
version: "5.0.2" version: "5.0.2"
versionName: "Lollipop"
platform: platform:
type: "tablet" type: "tablet"
engine: engine:
@ -250,6 +273,7 @@
os: os:
name: "Android" name: "Android"
version: "6.0.99" version: "6.0.99"
versionName: "Marshmallow"
platform: platform:
type: "tablet" type: "tablet"
engine: engine:
@ -263,6 +287,7 @@
os: os:
name: "Android" name: "Android"
version: "7.0" version: "7.0"
versionName: "Nougat"
platform: platform:
type: "mobile" type: "mobile"
vendor: "Nexus" vendor: "Nexus"
@ -277,6 +302,7 @@
os: os:
name: "Android" name: "Android"
version: "8.0.0" version: "8.0.0"
versionName: "Oreo"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -291,6 +317,7 @@
os: os:
name: "Android" name: "Android"
version: "4.0.3" version: "4.0.3"
versionName: "Ice Cream Sandwich"
platform: platform:
type: "tablet" type: "tablet"
vendor: "Amazon" vendor: "Amazon"
@ -322,6 +349,7 @@
os: os:
name: "Android" name: "Android"
version: "2.3.4" version: "2.3.4"
versionName: "Gingerbread"
platform: platform:
type: "tablet" type: "tablet"
vendor: "Amazon" vendor: "Amazon"
@ -353,6 +381,7 @@
os: os:
name: "Android" name: "Android"
version: "4.4.2" version: "4.4.2"
versionName: "KitKat"
platform: platform:
type: "tablet" type: "tablet"
vendor: "Nexus" vendor: "Nexus"
@ -367,6 +396,7 @@
os: os:
name: "Android" name: "Android"
version: "4.3" version: "4.3"
versionName: "Jelly Bean"
platform: platform:
type: "mobile" type: "mobile"
vendor: "Nexus" vendor: "Nexus"
@ -395,6 +425,7 @@
os: os:
name: "Android" name: "Android"
version: "4.3" version: "4.3"
versionName: "Jelly Bean"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -409,6 +440,7 @@
os: os:
name: "Android" name: "Android"
version: "4.4.2" version: "4.4.2"
versionName: "KitKat"
platform: platform:
type: "tablet" type: "tablet"
engine: engine:
@ -588,6 +620,7 @@
os: os:
name: "Android" name: "Android"
version: "6.0" version: "6.0"
versionName: "Marshmallow"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -633,6 +666,7 @@
os: os:
name: "Android" name: "Android"
version: "5.1.1" version: "5.1.1"
versionName: "Lollipop"
platform: platform:
type: "mobile" type: "mobile"
vendor: "Nexus" vendor: "Nexus"
@ -1309,6 +1343,7 @@
os: os:
name: "Android" name: "Android"
version: "8.0" version: "8.0"
versionName: "Oreo"
platform: platform:
type: "mobile" type: "mobile"
engine: engine: