Skip to content

Commit

Permalink
Merge cce6430 into 70a4604
Browse files Browse the repository at this point in the history
  • Loading branch information
rcsandell committed Dec 30, 2018
2 parents 70a4604 + cce6430 commit 0cc3ddc
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

``` sh
$ npm install
$ npm test
$ npm install #build
$ npm test #run tests
$ npm run lint #check lint rules
```

### Adding tests
Expand Down
8 changes: 7 additions & 1 deletion src/parser-os.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
getFirstMatch,
getWindowsVersionName,
getAndroidVersionName,
} from './utils';

export default [
Expand Down Expand Up @@ -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;
},
},

Expand Down
16 changes: 16 additions & 0 deletions src/parser-platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
44 changes: 44 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
45 changes: 45 additions & 0 deletions test/acceptance/useragentstrings.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
---
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"
spec:
Expand All @@ -9,6 +25,7 @@
os:
name: "Android"
version: "5.1.1"
versionName: "Lollipop"
platform:
type: "tablet"
vendor: "Nexus"
Expand All @@ -23,6 +40,7 @@
os:
name: "Android"
version: "4.4.2"
versionName: "KitKat"
platform:
type: "tablet"
vendor: "Nexus"
Expand All @@ -37,6 +55,7 @@
os:
name: "Android"
version: "4.3"
versionName: "Jelly Bean"
platform:
type: "mobile"
vendor: "Nexus"
Expand All @@ -51,6 +70,7 @@
os:
name: "Android"
version: "4.1"
versionName: "Jelly Bean"
platform:
type: "mobile"
vendor: "Nexus"
Expand All @@ -66,6 +86,7 @@
os:
name: "Android"
version: "4.0.3"
versionName: "Ice Cream Sandwich"
platform:
type: "tablet"
engine:
Expand All @@ -80,6 +101,7 @@
os:
name: "Android"
version: "4.0.3"
versionName: "Ice Cream Sandwich"
platform:
type: "mobile"
vendor: "Nexus"
Expand Down Expand Up @@ -237,6 +259,7 @@
os:
name: "Android"
version: "5.0.2"
versionName: "Lollipop"
platform:
type: "tablet"
engine:
Expand All @@ -250,6 +273,7 @@
os:
name: "Android"
version: "6.0.99"
versionName: "Marshmallow"
platform:
type: "tablet"
engine:
Expand All @@ -263,6 +287,7 @@
os:
name: "Android"
version: "7.0"
versionName: "Nougat"
platform:
type: "mobile"
vendor: "Nexus"
Expand All @@ -277,6 +302,7 @@
os:
name: "Android"
version: "8.0.0"
versionName: "Oreo"
platform:
type: "mobile"
engine:
Expand All @@ -291,6 +317,7 @@
os:
name: "Android"
version: "4.0.3"
versionName: "Ice Cream Sandwich"
platform:
type: "tablet"
vendor: "Amazon"
Expand Down Expand Up @@ -322,6 +349,7 @@
os:
name: "Android"
version: "2.3.4"
versionName: "Gingerbread"
platform:
type: "tablet"
vendor: "Amazon"
Expand Down Expand Up @@ -353,6 +381,7 @@
os:
name: "Android"
version: "4.4.2"
versionName: "KitKat"
platform:
type: "tablet"
vendor: "Nexus"
Expand All @@ -367,6 +396,7 @@
os:
name: "Android"
version: "4.3"
versionName: "Jelly Bean"
platform:
type: "mobile"
vendor: "Nexus"
Expand Down Expand Up @@ -395,6 +425,7 @@
os:
name: "Android"
version: "4.3"
versionName: "Jelly Bean"
platform:
type: "mobile"
engine:
Expand All @@ -409,6 +440,7 @@
os:
name: "Android"
version: "4.4.2"
versionName: "KitKat"
platform:
type: "tablet"
engine:
Expand Down Expand Up @@ -588,6 +620,7 @@
os:
name: "Android"
version: "6.0"
versionName: "Marshmallow"
platform:
type: "mobile"
engine:
Expand Down Expand Up @@ -633,6 +666,7 @@
os:
name: "Android"
version: "5.1.1"
versionName: "Lollipop"
platform:
type: "mobile"
vendor: "Nexus"
Expand Down Expand Up @@ -1309,6 +1343,7 @@
os:
name: "Android"
version: "8.0"
versionName: "Oreo"
platform:
type: "mobile"
engine:
Expand Down Expand Up @@ -1909,6 +1944,7 @@
os:
name: "Android"
version: "4.4.2"
versionName: "KitKat"
platform:
type: "tablet"
vendor: "Nexus"
Expand All @@ -1924,6 +1960,7 @@
os:
name: "Android"
version: "4.3"
versionName: "Jelly Bean"
platform:
type: "mobile"
vendor: "Nexus"
Expand All @@ -1939,6 +1976,7 @@
os:
name: "Android"
version: "4.2"
versionName: "Jelly Bean"
platform:
type: "tablet"
vendor: "Nexus"
Expand All @@ -1954,6 +1992,7 @@
os:
name: "Android"
version: "3.2"
versionName: "Honeycomb"
platform:
type: "tablet"
engine:
Expand All @@ -1968,6 +2007,7 @@
os:
name: "Android"
version: "2.3.4"
versionName: "Gingerbread"
platform:
type: "mobile"
engine:
Expand All @@ -1982,6 +2022,7 @@
os:
name: "Android"
version: "1.6"
versionName: "Donut"
platform:
type: "mobile"
engine:
Expand Down Expand Up @@ -2219,6 +2260,7 @@
os:
name: "Android"
version: "4.1.2"
versionName: "Jelly Bean"
platform:
type: "tablet"
engine:
Expand Down Expand Up @@ -2410,6 +2452,7 @@
os:
name: "Android"
version: "5.0.2"
versionName: "Lollipop"
platform:
type: "mobile"
engine:
Expand Down Expand Up @@ -2439,6 +2482,7 @@
os:
name: "Android"
version: "6.0"
versionName: "Marshmallow"
platform:
type: "mobile"
engine:
Expand All @@ -2453,6 +2497,7 @@
os:
name: "Android"
version: "7.1.1"
versionName: "Nougat"
platform:
type: "tablet"
engine:
Expand Down

0 comments on commit 0cc3ddc

Please sign in to comment.