1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +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
commit cd72625e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 3 deletions

View File

@ -130,8 +130,9 @@ 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
$ npm run lint #check lint rules
``` ```
### 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,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 * 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:
@ -1909,6 +1944,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"
@ -1924,6 +1960,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"
@ -1939,6 +1976,7 @@
os: os:
name: "Android" name: "Android"
version: "4.2" version: "4.2"
versionName: "Jelly Bean"
platform: platform:
type: "tablet" type: "tablet"
vendor: "Nexus" vendor: "Nexus"
@ -1954,6 +1992,7 @@
os: os:
name: "Android" name: "Android"
version: "3.2" version: "3.2"
versionName: "Honeycomb"
platform: platform:
type: "tablet" type: "tablet"
engine: engine:
@ -1968,6 +2007,7 @@
os: os:
name: "Android" name: "Android"
version: "2.3.4" version: "2.3.4"
versionName: "Gingerbread"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -1982,6 +2022,7 @@
os: os:
name: "Android" name: "Android"
version: "1.6" version: "1.6"
versionName: "Donut"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -2266,6 +2307,7 @@
os: os:
name: "Android" name: "Android"
version: "4.1.2" version: "4.1.2"
versionName: "Jelly Bean"
platform: platform:
type: "tablet" type: "tablet"
engine: engine:
@ -2457,6 +2499,7 @@
os: os:
name: "Android" name: "Android"
version: "5.0.2" version: "5.0.2"
versionName: "Lollipop"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -2486,6 +2529,7 @@
os: os:
name: "Android" name: "Android"
version: "6.0" version: "6.0"
versionName: "Marshmallow"
platform: platform:
type: "mobile" type: "mobile"
engine: engine:
@ -2500,6 +2544,7 @@
os: os:
name: "Android" name: "Android"
version: "7.1.1" version: "7.1.1"
versionName: "Nougat"
platform: platform:
type: "tablet" type: "tablet"
engine: engine: