mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 08:52:34 +00:00
FileUpload: Added fileSizeTypes (#4377)
* added fileSizeTypes * Added filesizeTypes fileupload, refactor and docs * Added format
This commit is contained in:
parent
b867022473
commit
430958237d
7 changed files with 57 additions and 29 deletions
|
@ -326,16 +326,18 @@ export default {
|
|||
}
|
||||
},
|
||||
formatSize(bytes) {
|
||||
const k = 1024;
|
||||
const dm = 3;
|
||||
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
||||
|
||||
if (bytes === 0) {
|
||||
return '0 B';
|
||||
return `0 ${sizes[0]}`;
|
||||
}
|
||||
|
||||
let k = 1000,
|
||||
dm = 3,
|
||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
return `${formattedSize} ${sizes[i]}`;
|
||||
},
|
||||
isFileLimitExceeded() {
|
||||
if (this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount && this.focused) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue