From 4708e70c612a797b5d15774149ed589996d0c2e3 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Sat, 5 Apr 2008 20:17:27 +0000 Subject: Improve database listing page. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@645171 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/pprint.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'share/www/script/pprint.js') diff --git a/share/www/script/pprint.js b/share/www/script/pprint.js index 981db0f2..1499a128 100644 --- a/share/www/script/pprint.js +++ b/share/www/script/pprint.js @@ -10,7 +10,7 @@ // License for the specific language governing permissions and limitations under // the License. -/* JSON pretty printing */ +// JSON pretty printing function prettyPrintJSON(val, indent, linesep, depth) { indent = indent != null ? indent : 4; @@ -58,3 +58,17 @@ function prettyPrintJSON(val, indent, linesep, depth) { } } } + +// File size pretty printing + +function prettyPrintSize(size) { + var jump = 512; + if (size < jump) return size + " bytes"; + var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + var i = 0; + while (size >= jump && i < units.length) { + i += 1; + size /= 1024 + } + return size.toFixed(1) + ' ' + units[i - 1]; +} -- cgit v1.2.3