Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
feat: no version or safari 0.8.2 use latest
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLeedham committed Nov 20, 2019
1 parent 6803e81 commit 7292379
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
8 changes: 4 additions & 4 deletions source/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`hello world 1`] = `
Object {
"and_chr": Object {
"78": 0.00832703943204618,
"78": 0.08700757666608093,
},
"and_ff": Object {
"68": 0,
Expand Down Expand Up @@ -110,7 +110,7 @@ Object {
"79": 0,
"8": 0,
"80": 0,
"81": 0,
"81": 0.007112638724844994,
"9": 0,
},
"edge": Object {
Expand Down Expand Up @@ -220,7 +220,7 @@ Object {
"12.2-12.4": 0,
"13.0-13.1": 0,
"13.2": 0,
"13.3": 0,
"13.3": 0.0028321332091358568,
"3.2": 0,
"4.0-4.1": 0,
"4.2-4.3": 0,
Expand Down Expand Up @@ -315,7 +315,7 @@ Object {
"11.1": 0,
"12": 0,
"12.1": 0.017297256022198913,
"13": 0.0214979762435615,
"13": 0.06995457133025582,
"3.1": 0,
"3.2": 0,
"4": 0,
Expand Down
42 changes: 19 additions & 23 deletions source/library/getBaseStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,23 @@ import { Stats } from 'browserslist';
*/
export default function getBaseStats(): Stats {
const baseStats: Stats = {};
const out = Object.entries(agents).reduce(
(stats, [browser, agent]): Stats => {
if (agent) {
stats[browser] = Object.entries(agent.release_date)
.sort((a, b) => {
if (a[1] === undefined) {
return -1;
} else if (b[1] === undefined) {
return 1;
} else {
return b[1] - a[1];
}
})
.reduce((versions, [version]) => {
versions[version] = 0;
return versions;
}, {} as { [version: string]: number });
}
return stats;
},
baseStats
);
return out;
return Object.entries(agents).reduce((stats, [browser, agent]): Stats => {
if (agent) {
stats[browser] = Object.entries(agent.release_date)
.sort((a, b) => {
if (a[1] === undefined) {
return -1;
} else if (b[1] === undefined) {
return 1;
} else {
return b[1] - a[1];
}
})
.reduce((versions, [version]) => {
versions[version] = 0;
return versions;
}, {} as { [version: string]: number });
}
return stats;
}, baseStats);
}
20 changes: 15 additions & 5 deletions source/library/transformAnalyticsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { RankedReportData } from 'source/types';
import { Stats } from 'browserslist';
import { agents } from 'caniuse-lite';
import getBaseStats from './getBaseStats';

console.log(agents);

const browserVersionRegex = /(?:(^\D+?)$|(^\D+?)((?:\d\.?){1,3}$))/;

const adobeBrowserslistBrowserMap: { [name: string]: string } = {
Expand Down Expand Up @@ -83,11 +80,24 @@ export function getBrowserVersion(
browser = adobeBrowserslistBrowserMap[browser];
if (browser && allStats.hasOwnProperty(browser)) {
if (version) {
// Map to browserslist equivalent.
version = cascadeSemver(version, Object.keys(allStats[browser]));
}
// TODO: Map Safari 0.8.2 and no version to latest.
// No version or Safari 0.8.2 use latest.
// https://helpx.adobe.com/uk/analytics/kb/Why-is-latest-version-of-Safari-reported-as-0-8-2-Adobe-Analytics.html
// Map to browserslist equivalent.
if (!version || (browser === 'safari' && version === '0.8.2')) {
version = Object.keys(allStats[browser]).sort((a, b) => {
const aNum = parseFloat(a);
const bNum = parseFloat(b);
if (aNum === NaN) {
return -1;
} else if (bNum === NaN) {
return 1;
}
return bNum - aNum;
})[0];
}

if (version !== null) {
return {
browser,
Expand Down

0 comments on commit 7292379

Please sign in to comment.