refactor: prettier format fixes

This commit is contained in:
Bart van der Braak 2023-08-02 02:16:50 +02:00
parent 95d99e0970
commit 5b6289b665
3 changed files with 79 additions and 73 deletions

View file

@ -58,6 +58,7 @@ I'm open to contributions! If you find any bugs, have suggestions, or want to ad
This project is licensed under the GPLv3 License. Feel free to explore, learn, and have fun! This project is licensed under the GPLv3 License. Feel free to explore, learn, and have fun!
Some dependencies may hold different licenses but are in compliance with GPLv3: Some dependencies may hold different licenses but are in compliance with GPLv3:
- `MIT`: Compatible with GPLv3. - `MIT`: Compatible with GPLv3.
- `Apache 2.0`: Compatible with GPLv3. - `Apache 2.0`: Compatible with GPLv3.
- `BSD-3-Clause`: Compatible with GPLv3. - `BSD-3-Clause`: Compatible with GPLv3.

View file

@ -14,17 +14,22 @@ interface NavigatorWithConnection extends Navigator {
type Params = Record<string, any>; // Define a type for 'params' type Params = Record<string, any>; // Define a type for 'params'
function getConnectionSpeed() { function getConnectionSpeed() {
return 'connection' in navigator && 'connection' && 'effectiveType' in (navigator as NavigatorWithConnection).connection return 'connection' in navigator &&
'connection' &&
'effectiveType' in (navigator as NavigatorWithConnection).connection
? (navigator as NavigatorWithConnection).connection.effectiveType ? (navigator as NavigatorWithConnection).connection.effectiveType
: ''; : '';
} }
function sendToAnalytics(metric: Metric, options: { function sendToAnalytics(
metric: Metric,
options: {
params: Params; params: Params;
path: string; path: string;
analyticsId: string; analyticsId: string;
debug: boolean; debug: boolean;
}) { }
) {
const page = Object.entries(options.params).reduce( const page = Object.entries(options.params).reduce(
(acc, [key, value]) => acc.replace(value, `[${key}]`), (acc, [key, value]) => acc.replace(value, `[${key}]`),
options.path options.path
@ -37,7 +42,7 @@ function sendToAnalytics(metric: Metric, options: {
href: location.href, href: location.href,
event_name: metric.name, event_name: metric.name,
value: metric.value.toString(), value: metric.value.toString(),
speed: getConnectionSpeed(), speed: getConnectionSpeed()
}; };
if (options.debug) { if (options.debug) {
@ -49,7 +54,7 @@ function sendToAnalytics(metric: Metric, options: {
// The type 'Record<string, string>' is compatible with 'URLSearchParams' // The type 'Record<string, string>' is compatible with 'URLSearchParams'
const blob = new Blob([searchParams.toString()], { const blob = new Blob([searchParams.toString()], {
type: 'application/x-www-form-urlencoded', type: 'application/x-www-form-urlencoded'
}); });
if (navigator.sendBeacon) { if (navigator.sendBeacon) {
navigator.sendBeacon(vitalsUrl, blob); navigator.sendBeacon(vitalsUrl, blob);
@ -58,7 +63,7 @@ function sendToAnalytics(metric: Metric, options: {
body: blob, body: blob,
method: 'POST', method: 'POST',
credentials: 'omit', credentials: 'omit',
keepalive: true, keepalive: true
}); });
} }
} }