Migrated VisitsParser to TS

This commit is contained in:
Alejandro Celaya
2020-09-02 19:32:07 +02:00
parent 16d96efa4a
commit d0d664ef79
6 changed files with 117 additions and 85 deletions

View File

@@ -1,6 +1,7 @@
import bowser from 'bowser';
import { zipObj } from 'ramda';
import { Empty, hasValue } from '../utils';
import { Stats, UserAgent } from '../../visits/types';
const DEFAULT = 'Others';
const BROWSERS_WHITELIST = [
@@ -17,11 +18,6 @@ const BROWSERS_WHITELIST = [
'WeChat',
];
interface UserAgent {
browser: string;
os: string;
}
export const parseUserAgent = (userAgent: string | Empty): UserAgent => {
if (!hasValue(userAgent)) {
return { browser: DEFAULT, os: DEFAULT };
@@ -42,5 +38,5 @@ export const extractDomain = (url: string | Empty): string => {
return domain.split(':')[0];
};
export const fillTheGaps = (stats: Record<string, number>, labels: string[]): number[] =>
export const fillTheGaps = (stats: Stats, labels: string[]): number[] =>
Object.values({ ...zipObj(labels, labels.map(() => 0)), ...stats });