Skip to content

Commit

Permalink
Merge pull request #10 from pato-p/main
Browse files Browse the repository at this point in the history
Display human readable file size
  • Loading branch information
xcmd-io committed Apr 1, 2024
2 parents 40691d7 + 9883638 commit 99ba44f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xcmd-tauri/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<tr class="tbody-row" tabindex="0">
<td style="width: 20em"><img class="icon" data-src-fn="icon" src="file.svg"/> <span data-text="name">name</span></td>
<td style="width: 3em" data-text="extension" style="width: 3em">ext</td>
<td style="width: 5em" data-text="size" class="vtable--align-right">0</td>
<td style="width: 5em" data-text-fn="size" class="vtable--align-right">0</td>
<td style="width: 10em" data-text-fn="date">1970-01-01 00:00</td>
<td style="width: 5em">-a--</td>
<td></td>
Expand Down
22 changes: 22 additions & 0 deletions xcmd-tauri/dist/vtable/vtable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,28 @@ export class VTable {
}
return iconUrl;
},
size: (item) => {
if (item.isDirectory) {
return '';
}
if (typeof item.size !== 'bigint' && isNaN(item.size)) {
return '???';
}
let number = Number(item.size);
if (number < 0) {
return '???';
}
const units = 'KMGTPEZY';
const unitSize = 1024;
let unitIndex = -1;
while (number >= unitSize && unitIndex < units.length) {
number /= unitSize;
unitIndex++;
}
return unitIndex >= 0
? `${number.toFixed(2)} ${units[unitIndex]}iB`
: `${number.toString()} B`;
},
date: (item) => {
const date = new Date(item.date);
if (isNaN(date.getTime())) {
Expand Down

0 comments on commit 99ba44f

Please sign in to comment.