Skip to content

Commit

Permalink
adding utility file for common functionality in system/templates/base…
Browse files Browse the repository at this point in the history
…/src/js
  • Loading branch information
dragonflyfree committed Sep 27, 2024
1 parent 0e10e12 commit 66efe49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 1 addition & 11 deletions system/templates/base/src/js/components/MultiFileUpload.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
// src/js/components/MultiFileUpload.ts

function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';

const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

const i = Math.floor(Math.log(bytes) / Math.log(k));

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
import { formatBytes } from "../utility";

export class MultiFileUpload {
private static containerTarget = 'multi-upload-file-container';
Expand Down
13 changes: 13 additions & 0 deletions system/templates/base/src/js/utility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// src/js/utility.ts

export function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';

const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

const i = Math.floor(Math.log(bytes) / Math.log(k));

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

0 comments on commit 66efe49

Please sign in to comment.