2020-08-07 11:46:21 +02:00
|
|
|
import escape from 'escape-string-regexp';
|
2020-08-07 04:37:19 +02:00
|
|
|
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';
|
2020-08-01 12:34:56 +02:00
|
|
|
|
|
|
|
export const browserFilter = data =>
|
2020-08-07 04:14:44 +02:00
|
|
|
data.map(({ x, ...props }) => ({ x: BROWSERS[x] || x, ...props }));
|
2020-08-01 12:34:56 +02:00
|
|
|
|
|
|
|
export const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWith('#'));
|
|
|
|
|
2020-08-07 11:46:21 +02:00
|
|
|
export const refFilter = domain => data => {
|
|
|
|
const regex = new RegExp(escape(domain));
|
|
|
|
return data.filter(
|
|
|
|
({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#') && !regex.test(x),
|
|
|
|
);
|
|
|
|
};
|
2020-08-01 12:34:56 +02:00
|
|
|
|
2020-08-07 04:37:19 +02:00
|
|
|
export const deviceFilter = data =>
|
|
|
|
data.map(({ x, ...props }) => ({ x: DEVICES[x] || x, ...props }));
|
2020-08-01 12:34:56 +02:00
|
|
|
|
|
|
|
export const countryFilter = data =>
|
2020-08-07 04:14:44 +02:00
|
|
|
data.map(({ x, ...props }) => ({ x: ISO_COUNTRIES[x] || x, ...props }));
|
2020-08-01 12:34:56 +02:00
|
|
|
|
|
|
|
export const percentFilter = data => {
|
|
|
|
const total = data.reduce((n, { y }) => n + y, 0);
|
|
|
|
return data.map(({ x, y }) => ({ x, y, z: total ? (y / total) * 100 : 0 }));
|
|
|
|
};
|