pgadmin4/web/pgadmin/static/js/size_prettify.js
Akshay Joshi 9f836f5433 Fixed following code smells reported by SonarQube:
1) Immediately return this expression instead of assigning it to the temporary variable.
 2) Extract this nested ternary operation into an independent statement.
 3) Expected a `for-of` loop instead of a `for` loop with this simple iteration.
2022-01-18 14:49:54 +05:30

32 lines
800 B
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
define([],
function () {
return function (rawSize) {
var size = Math.abs(rawSize),
limit = 10 * 1024,
limit2 = limit - 1,
cnt = 0,
sizeUnits = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
if (size < limit)
return size + ' ' + sizeUnits[cnt]; // return in bytes format
else
{
do {
size = size / 1024;
cnt += 1;
} while (size > limit2);
return Math.round(size) + ' ' + sizeUnits[cnt];
}
};
});