1
mirror of https://github.com/pure-css/pure synced 2024-11-26 08:27:21 +01:00
pure/site/lib/utils.js
2020-04-27 10:42:40 -07:00

27 lines
677 B
JavaScript

/**
* Calculates filesize for a given module
*/
export function fileSize({ module, decimals = 1, filesizes }) {
const filesize = (filesizes[module] / 1024);
return filesize.toFixed(decimals) + 'KB';
}
/**
* Calculates the module percentage size against all modules
*/
export function filePercent({ modules, module, filesizes }) {
const total = modules.reduce((size, m) => {
return size + filesizes[m];
}, 0);
return (filesizes[module] / total * 100).toFixed(4) + '%';
}
/**
* Generic click handler for pages
*/
export function handleClick(e) {
e.preventDefault();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
}