Cleanup Date.fromNow() and friendlySize()

This commit is contained in:
djmaze 2020-10-03 14:02:33 +02:00
parent 2bd9528098
commit a0f8ac0dad
7 changed files with 28 additions and 50 deletions

View file

@ -7,6 +7,7 @@ const
msOffice = app+'vnd.openxmlformats-officedocument.',
openDoc = app+'vnd.oasis.opendocument.',
font = app+'x-font-',
sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB'],
exts = {
'eml': 'message/rfc822',
@ -309,5 +310,12 @@ export const File = {
}
return '';
},
friendlySize: bytes => {
bytes = parseInt(bytes, 10) || 0;
let i = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, i)).toFixed(2>i ? 0 : 1) + sizes[i];
}
};

View file

@ -99,16 +99,6 @@ export function inFocus() {
return false;
}
/**
* @param {(number|string)} sizeInBytes
* @returns {string}
*/
export function friendlySize(sizeInBytes) {
sizeInBytes = pInt(sizeInBytes);
const sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB'], i = pInt(Math.floor(Math.log(sizeInBytes) / Math.log(1024)));
return (sizeInBytes / Math.pow(1024, i)).toFixed(2>i ? 0 : 1) + sizes[i];
}
/**
* @param {string} theme
* @returns {string}