fix and rename padLeft

This commit is contained in:
tophf 2020-11-16 23:41:30 +03:00
parent 35cf41ca00
commit aa6b0b03a1

View File

@ -336,7 +336,7 @@ function createSizeText(el, style) {
style.sections.reduce((sum, sec) => sum + (sec.code || '').length, 0); style.sections.reduce((sum, sec) => sum + (sec.code || '').length, 0);
if (size) { if (size) {
el.textContent = size < 1000 ? '<1k' : `${size / 1000 | 0}k`; el.textContent = size < 1000 ? '<1k' : `${size / 1000 | 0}k`;
el.title = addBigness(size); el.title = padLeft(size, 8);
} }
} }
@ -348,7 +348,7 @@ function createAgeText(el, style) {
const rounded = Math.round(val); const rounded = Math.round(val);
if (rounded < max) { if (rounded < max) {
el.textContent = text.replace('\x01', rounded); el.textContent = text.replace('\x01', rounded);
el.dataset.value = addBigness(Math.round(rounded), 2) + unit; el.dataset.value = padLeft(Math.round(rounded), 2) + unit;
break; break;
} }
val /= max; val /= max;
@ -359,8 +359,10 @@ function createAgeText(el, style) {
} }
} }
function addBigness(val, max = 8) { /** Adding spaces so CSS can detect "bigness" of a value via amount of spaces at the beginning */
return ' '.repeat(max - Math.ceil(Math.log10(val))) + val; function padLeft(val, width) {
val = `${val}`;
return ' '.repeat(Math.max(0, width - val.length)) + val;
} }
function getFaviconImgSrc(container = installed) { function getFaviconImgSrc(container = installed) {