Skip to content

Commit

Permalink
Move round and humanSize to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Sep 18, 2021
1 parent 4195690 commit 86bc9bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/js/page/ui/results.js
@@ -1,13 +1,4 @@
import { strToEl } from '../utils.js';

const round = (num, places) => {
const mult = 10 ** places;
return Math.floor(Math.round(num * mult)) / mult;
};

const humanSize = (bytes) => {
return bytes < 1024 ? `${bytes} bytes` : `${round(bytes / 1024, 2)}k`;
};
import { strToEl, round, humanSize } from '../utils.js';

export default class Results {
constructor() {
Expand Down
9 changes: 9 additions & 0 deletions src/js/page/utils.js
Expand Up @@ -37,6 +37,15 @@ export const readFileAsText = (file) => {
return new Response(file).text();
};

export const round = (num, places) => {
const mult = 10 ** places;
return Math.floor(Math.round(num * mult)) / mult;
};

export const humanSize = (bytes) => {
return bytes < 1024 ? `${bytes} bytes` : `${round(bytes / 1024, 2)}k`;
};

const transitionClassFunc = ({ removeClass = false } = {}) => {
return (el, className = 'active', transitionClass = 'transition') => {
if (removeClass) {
Expand Down

0 comments on commit 86bc9bf

Please sign in to comment.