-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new submodule:
ua-parser-helpers
with a method: `isFrozenUA()…
…` to match a string with a frozen user-agent pattern
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/////////////////////////////////////////////// | ||
/* Helpers for UAParser.js v2.0.0-alpha.2 | ||
https://github.com/faisalman/ua-parser-js | ||
Author: Faisal Salman <f@faisalman.com> | ||
MIT License */ | ||
////////////////////////////////////////////// | ||
|
||
/*jshint esversion: 6 */ | ||
|
||
/* | ||
# Reference: | ||
https://www.chromium.org/updates/ua-reduction/ | ||
# Desktop | ||
--- | ||
Format: | ||
Mozilla/5.0 (<unifiedPlatform>) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/<majorVersion>.0.0.0 Safari/537.36 | ||
Possible <unifiedPlatform> values: | ||
- Windows NT 10.0; Win64; x64 | ||
- Macintosh; Intel Mac OS X 10_15_7 | ||
- X11; Linux x86_64 | ||
- X11; CrOS x86_64 14541.0.0 | ||
- Fuchsia | ||
# Mobile & Tablet: (except iOS/Android WebView) | ||
--- | ||
Format: | ||
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/<majorVersion>.0.0.0 <deviceCompat> Safari/537.36 | ||
Possible <deviceCompat> values: | ||
- "Mobile" | ||
- "" (empty string for Tablets & Desktop) | ||
*/ | ||
|
||
const frozenUA = /Mozilla\/5\.0 \((Windows NT 10\.0; Win64; x64|Macintosh; Intel Mac OS X 10_15_7|X11; Linux x86_64|X11; CrOS x86_64 14541\.0\.0|Fuchsia|Linux; Android 10; K)\) AppleWebKit\/537\.36 \(KHTML, like Gecko\) Chrome\/\d+\.0\.0\.0 (Mobile )?Safari\/537\.36/; | ||
|
||
const isFrozenUA = str => frozenUA.test(str); | ||
|
||
module.exports = { | ||
isFrozenUA | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { isFrozenUA } = require('ua-parser-js/helpers'); | ||
const assert = require('assert'); | ||
|
||
describe('isFrozenUA', () => { | ||
it('Returns whether a user agent is frozen', () => { | ||
|
||
const regularWindowsUA = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.1234.56 Safari/537.36"; | ||
const freezedWindowsUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.0.0 Safari/537.36"; | ||
|
||
const regularMacUA = ""; | ||
const freezedMacUA = ""; | ||
|
||
const regularLinuxUA = ""; | ||
const freezedLinuxUA = ""; | ||
|
||
const regularCrOSUA = ""; | ||
const freezedCrOSUA = ""; | ||
|
||
const regularFuchsiaUA = ""; | ||
const freezedFuchsiaUA = ""; | ||
|
||
const regularMobileUA = "Mozilla/5.0 (Linux; Android 9; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.1234.56 Mobile Safari/537.36"; | ||
const freezedMobileUA = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.0.0 Mobile Safari/537.36"; | ||
|
||
const regularTabletUA = "Mozilla/5.0 (Linux; Android 9; SM-T810) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.1234.56 Safari/537.36"; | ||
const freezedTabletUA = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.0.0 Safari/537.36"; | ||
|
||
assert.strictEqual(isFrozenUA(regularWindowsUA), false); | ||
assert.strictEqual(isFrozenUA(freezedWindowsUA), true); | ||
assert.strictEqual(isFrozenUA(regularMobileUA), false); | ||
assert.strictEqual(isFrozenUA(freezedMobileUA), true); | ||
assert.strictEqual(isFrozenUA(regularTabletUA), false); | ||
assert.strictEqual(isFrozenUA(freezedTabletUA), true); | ||
}); | ||
}); |