Skip to content

Commit

Permalink
feat: update amazon regexp for better matching
Browse files Browse the repository at this point in the history
supersedes #88
  • Loading branch information
kaimallea committed Aug 11, 2019
1 parent 8183a1a commit 04135b1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/__tests__/amazon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,40 @@ describe('Amazon', () => {
expect(mobile.android.device).toBe(true);
});
});

describe('Amazon Fire Generic Phone User Agent', () => {
beforeEach(() => {
userAgent =
'Mozilla/5.0 (Linux; Android android-version; product-model Build/product-build) AppleWebKit/webkit-version (KHTML, like Gecko) Silk/browser-version like Chrome/chrome-version Mobile Safari/webkit-version';
mobile = isMobile(userAgent);
});

test('should be an Amazon Phone', () => {
expect(mobile.amazon.phone).toBe(true);
});

test('should not be an Amazon Tablet', () => {
expect(mobile.amazon.tablet).not.toBe(true);
});

test('should be an Amazon device', () => {
expect(mobile.amazon.device).toBe(true);
});

test('should be an Android Phone', () => {
expect(mobile.android.phone).toBe(true);
});

test('should not be an Android Tablet', () => {
expect(mobile.android.tablet).not.toBe(true);
});

test('should be matched as Any Phone', () => {
expect(mobile.phone).toBe(true);
});

test('should be an Android device', () => {
expect(mobile.android.device).toBe(true);
});
});
});
4 changes: 2 additions & 2 deletions src/isMobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const appleIpod = /iPod/i;
const appleTablet = /iPad/i;
const androidPhone = /\bAndroid(?:.+)Mobile\b/i; // Match 'Android' AND 'Mobile'
const androidTablet = /Android/i;
const amazonPhone = /\bAndroid(?:.+)SD4930UR\b/i;
const amazonTablet = /\bAndroid(?:.+)(?:KF[A-Z]{2,4})\b/i;
const amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i; // Match 'Silk' AND 'Mobile'
const amazonTablet = /Silk/i;
const windowsPhone = /Windows Phone/i;
const windowsTablet = /\bWindows(?:.+)ARM\b/i; // Match 'Windows' AND 'ARM'
const otherBlackBerry = /BlackBerry/i;
Expand Down

0 comments on commit 04135b1

Please sign in to comment.