@volverjs/ui-vue 0.0.10-beta.46 → 0.0.10-beta.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -224,11 +224,17 @@ onBeforeUnmount(() => {
224
224
  }
225
225
  })
226
226
 
227
- function sizeInKiB(size?: number) {
228
- if (!size) {
227
+ function formatBytes(bytes?: number, decimals?: number) {
228
+ if (!bytes) {
229
229
  return
230
230
  }
231
- return Math.floor(size / 1024)
231
+ if (bytes === 0)
232
+ return '0 Bytes'
233
+ const k = 1024
234
+ const dm = !decimals ? 2 : decimals <= 0 ? 0 : decimals
235
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
236
+ const i = Math.floor(Math.log(bytes) / Math.log(k))
237
+ return `${Number.parseFloat((bytes / (k ** i)).toFixed(dm))} ${sizes[i]}`
232
238
  }
233
239
 
234
240
  function onClickDownloadFile(file: File | UploadedFile) {
@@ -376,7 +382,7 @@ export default {
376
382
  {{ file.name }}
377
383
  </div>
378
384
  <small class="vv-input-file__item-info">
379
- {{ sizeInKiB(file.size) }} KB
385
+ {{ formatBytes(file.size) }}
380
386
  </small>
381
387
  <button
382
388
  v-if="!readonly"