Skip to content

Commit

Permalink
fix byte conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
rikschennink committed Oct 9, 2020
1 parent 95cc575 commit b9da589
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.21.1

- Fix calculation of file size when `fileSizeBase` is set to 1024.


## 4.21.0

- Add `fileSizeBase` use to adjust the way files sizes are displayed. Default is `1000`.
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.21.0
* FilePond 4.21.1
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
8 changes: 4 additions & 4 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.21.0
* FilePond 4.21.1
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -1349,7 +1349,7 @@ const toBytes = (value, base = 1000) => {
// if is value in megabytes
if (/MB$/i.test(naturalFileSize)) {
naturalFileSize = naturalFileSize.replace(/MB$i/, '').trim();
return toInt(naturalFileSize) * base * 1000;
return toInt(naturalFileSize) * base * base;
}

// if is value in kilobytes
Expand Down Expand Up @@ -5285,8 +5285,8 @@ const toNaturalFileSize = (bytes, decimalSeparator = '.', base = 1000) => {
bytes = Math.round(Math.abs(bytes));

const KB = base;
const MB = base * 1000;
const GB = base * 1000000;
const MB = base * base;
const GB = base * base * base;

// just bytes
if (bytes < KB) {
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.21.0
* FilePond 4.21.1
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -1595,7 +1595,7 @@
// if is value in megabytes
if (/MB$/i.test(naturalFileSize)) {
naturalFileSize = naturalFileSize.replace(/MB$i/, '').trim();
return toInt(naturalFileSize) * base * 1000;
return toInt(naturalFileSize) * base * base;
}

// if is value in kilobytes
Expand Down Expand Up @@ -7836,8 +7836,8 @@
bytes = Math.round(Math.abs(bytes));

var KB = base;
var MB = base * 1000;
var GB = base * 1000000;
var MB = base * base;
var GB = base * base * base;

// just bytes
if (bytes < KB) {
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.css

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

4 changes: 2 additions & 2 deletions dist/filepond.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filepond",
"version": "4.21.0",
"version": "4.21.1",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/toBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const toBytes = (value, base = 1000) => {
// if is value in megabytes
if (/MB$/i.test(naturalFileSize)) {
naturalFileSize = naturalFileSize.replace(/MB$i/, '').trim();
return toInt(naturalFileSize) * base * 1000;
return toInt(naturalFileSize) * base * base;
}

// if is value in kilobytes
Expand Down
4 changes: 2 additions & 2 deletions src/js/utils/toNaturalFileSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export const toNaturalFileSize = (bytes, decimalSeparator = '.', base = 1000) =>
bytes = Math.round(Math.abs(bytes));

const KB = base;
const MB = base * 1000;
const GB = base * 1000000;
const MB = base * base;
const GB = base * base * base;

// just bytes
if (bytes < KB) {
Expand Down

0 comments on commit b9da589

Please sign in to comment.