mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-09-27 11:42:03 -04:00
Switch from binary bytes to SI-units
This commit is contained in:
parent
67e4eb74ed
commit
863cb89ad9
43 changed files with 46 additions and 342 deletions
|
@ -602,9 +602,9 @@ jQuery.PrivateBin = (function($) {
|
|||
me.formatBytes = function (bytes)
|
||||
{
|
||||
let result = '';
|
||||
const kilobyte = 1024;
|
||||
const kilobyte = 1000;
|
||||
const decimalPoint = 2;
|
||||
const sizes = [I18n._('B'), I18n._('KiB'), I18n._('MiB'), I18n._('GiB')];
|
||||
const sizes = [I18n._('B'), I18n._('kB'), I18n._('MB'), I18n._('GB')];
|
||||
const index = Math.floor(Math.log(bytes) / Math.log(kilobyte));
|
||||
|
||||
if (bytes > 0) {
|
||||
|
|
|
@ -300,20 +300,20 @@ describe('Helper', function () {
|
|||
return $.PrivateBin.Helper.formatBytes(500) === '500 B';
|
||||
});
|
||||
|
||||
jsc.property('formats kibibytes correctly', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(1500) === '1.46 KiB';
|
||||
jsc.property('formats kilobytes correctly', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(1500) === '1.5 kB';
|
||||
});
|
||||
|
||||
jsc.property('formats mebibytes correctly', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '1.91 MiB';
|
||||
jsc.property('formats megabytes correctly', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '2 MB';
|
||||
});
|
||||
|
||||
jsc.property('formats gibibytes correctly', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.21 GiB';
|
||||
jsc.property('formats gigabytes correctly', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.45 GB';
|
||||
});
|
||||
|
||||
jsc.property('rounds to two decimal places', function () {
|
||||
return $.PrivateBin.Helper.formatBytes(1234567) === '1.18 MiB';
|
||||
return $.PrivateBin.Helper.formatBytes(1234567) === '1.23 MB';
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue