Skip to content

Commit

Permalink
Bump ua-parser-js from 1.0.39 to 2.0.0 (#1963)
Browse files Browse the repository at this point in the history
* Bump ua-parser-js from 1.0.39 to 2.0.0

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 1.0.39 to 2.0.0.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/CHANGELOG.md)
- [Commits](faisalman/ua-parser-js@1.0.39...2.0.0)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Some values may now be undefined

* Word "Mobile" is prepended to Android browsers as well now

* Mac OS -> macOS

* Use new export

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Queen Vinyl Da.i'gyu-Kazotetsu <[email protected]>
  • Loading branch information
dependabot[bot] and queengooborg authored Nov 26, 2024
1 parent 7d0700a commit b19d441
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/exporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const REPORTS: {
},
expected: {
slug: "1.2.3-safari-12.0-mac-os-10.14-cadc34e83f",
title: "Results from Safari 12 / Mac OS 10.14 / Collector v1.2.3",
title: "Results from Safari 12 / macOS 10.14 / Collector v1.2.3",
body: "User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15\nBrowser: Safari 12 (on Mac OS 10.14)\nHash Digest: cadc34e83f\nTest URLs: ",
},
},
Expand All @@ -43,7 +43,7 @@ const REPORTS: {
},
expected: {
slug: "1.2.3-dev-chrome-86.0.4240.198-mac-os-11.0.0-32f70f2e14",
title: "Results from Chrome 86 / Mac OS 11.0.0 / Collector v1.2.3-dev",
title: "Results from Chrome 86 / macOS 11.0.0 / Collector v1.2.3-dev",
body: "User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36\nBrowser: Chrome 86 (on Mac OS 11.0.0)\nHash Digest: 32f70f2e14\nTest URLs: \n\n**WARNING:** this PR was created from a development/staging version!",
},
},
Expand Down Expand Up @@ -75,7 +75,7 @@ const REPORTS: {
},
expected: {
slug: "1.2.3-chrome-800.0.1.2-mac-os-11.0.0-ee13f09a68",
title: "Results from Chrome 800.0 / Mac OS 11.0.0 / Collector v1.2.3",
title: "Results from Chrome 800.0 / macOS 11.0.0 / Collector v1.2.3",
body: "User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/800.0.1.2 Safari/537.36\nBrowser: Chrome 800.0 (on Mac OS 11.0.0) - **Not in BCD**\nHash Digest: ee13f09a68\nTest URLs: https://mdn-bcd-collector.gooborg.com/tests/?exposure=Window, https://mdn-bcd-collector.gooborg.com/tests/?exposure=Worker",
},
},
Expand Down
18 changes: 9 additions & 9 deletions lib/ua-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("parseUA", () => {
browser: {id: "chrome", name: "Chrome"},
version: "85",
fullVersion: "85.0.4183.121",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: true,
},
);
Expand All @@ -96,7 +96,7 @@ describe("parseUA", () => {
browser: {id: "chrome", name: "Chrome"},
version: "1000.1",
fullVersion: "1000.1.4183.121",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: false,
},
);
Expand Down Expand Up @@ -224,7 +224,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "14",
fullVersion: "14.0",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: true,
},
);
Expand All @@ -240,7 +240,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "14",
fullVersion: "14.1",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: true,
},
);
Expand All @@ -256,7 +256,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "15",
fullVersion: "15.0",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: true,
},
);
Expand All @@ -272,7 +272,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "15.2",
fullVersion: "15.2",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: true,
},
);
Expand All @@ -288,7 +288,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "15.3",
fullVersion: "15.3",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: false,
},
);
Expand All @@ -304,7 +304,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "16.0",
fullVersion: "16.0",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: false,
},
);
Expand All @@ -320,7 +320,7 @@ describe("parseUA", () => {
browser: {id: "safari", name: "Safari"},
version: "7.1",
fullVersion: "7.1",
os: {name: "Mac OS", version: "10.15.6"},
os: {name: "macOS", version: "10.15.6"},
inBcd: false,
},
);
Expand Down
21 changes: 11 additions & 10 deletions lib/ua-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
compare as compareVersions,
compareVersions as compareVersionsSort,
} from "compare-versions";
import uaParser from "ua-parser-js";
import {UAParser} from "ua-parser-js";
import {ParsedUserAgent} from "../types/types";

/**
Expand Down Expand Up @@ -41,7 +41,7 @@ const getMajorMinorVersion = (version: string): string => {
* @returns An object containing the parsed browser and operating system information.
*/
const parseUA = (userAgent: string, browsers: Browsers): ParsedUserAgent => {
const ua = uaParser(userAgent);
const ua = UAParser(userAgent);
const data: ParsedUserAgent = {
browser: {id: "", name: ""},
version: "",
Expand All @@ -66,10 +66,10 @@ const parseUA = (userAgent: string, browsers: Browsers): ParsedUserAgent => {
data.os.version = ua.os.version || "";
}

data.browser.id = data.browser.id.replace("mobile_", "");
data.browser.name = data.browser.name.replace("Mobile ", "");

switch (data.browser.id) {
case "mobile_safari":
data.browser.id = "safari";
break;
case "oculus_browser":
data.browser.id = "oculus";
break;
Expand All @@ -92,9 +92,10 @@ const parseUA = (userAgent: string, browsers: Browsers): ParsedUserAgent => {

if (ua.browser.name === "Android Browser") {
// For early WebView Android, use the OS version
data.fullVersion = compareVersions(ua.os.version, "5.0", "<")
? ua.os.version
: ua.engine.version;
data.fullVersion =
(compareVersions(ua.os.version || "0", "5.0", "<")
? ua.os.version
: ua.engine.version) || "0";
}
} else if (os === "ios") {
if (data.browser.id === "webkit") {
Expand All @@ -105,10 +106,10 @@ const parseUA = (userAgent: string, browsers: Browsers): ParsedUserAgent => {
data.browser.name += " iOS";

// https://github.com/mdn/browser-compat-data/blob/main/docs/data-guidelines.md#safari-for-ios-versioning
data.fullVersion = ua.os.version;
data.fullVersion = ua.os.version || "0";
}

data.fullVersion = data.fullVersion || ua.browser.version;
data.fullVersion = data.fullVersion || ua.browser.version || "0";
data.version = getMajorMinorVersion(data.fullVersion);

if (!(data.browser.id in browsers)) {
Expand Down
70 changes: 66 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"mermaid": "^11.4.0",
"slugify": "1.6.6",
"ts-node": "10.9.2",
"ua-parser-js": "1.0.39",
"ua-parser-js": "2.0.0",
"wasm-feature-detect": "^1.8.0",
"winston": "3.17.0",
"yargs": "17.7.2"
Expand Down

0 comments on commit b19d441

Please sign in to comment.