Skip to content

Commit

Permalink
Added file size formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Oct 13, 2024
1 parent 1298606 commit a28af7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@zenfs/zip": "^0.5.1",
"chalk": "^5.3.0",
"jquery": "^3.7.1",
"utilium": "^0.8.3"
"utilium": "^0.8.4"
},
"devDependencies": {
"@eslint/js": "^9.12.0",
Expand Down
7 changes: 5 additions & 2 deletions src/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { fs } from '@zenfs/core';
import { cwd, join } from '@zenfs/core/emulation/path.js';
import $ from 'jquery';
import { formatCompact } from 'utilium';
import { cloneTemplate } from 'utilium/dom.js';

const endsWithLetter = /[^\d]$/;

function createEntry(name: string) {
const stats = fs.statSync(join(cwd, name));

const li = $(cloneTemplate('#entry')).find('li');

const size = formatCompact(stats.size);
li.find('.name').text(name);
li.find('.size').text(stats.size);
li.find('.size').text(size + (endsWithLetter.test(size) ? 'B' : ' bytes'));
li.find('.mtime').text(stats.mtime.toLocaleString());

li.appendTo('#explorer');
}

Expand Down
1 change: 1 addition & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ select {
display: flex;
align-items: center;
gap: 1em;
margin-bottom: 0.25em;

p {
white-space: nowrap;
Expand Down

0 comments on commit a28af7f

Please sign in to comment.