~ubuntu-branches/ubuntu/jaunty/couchdb/jaunty

« back to all changes in this revision

Viewing changes to share/www/script/pprint.js

  • Committer: Bazaar Package Importer
  • Author(s): Noah Slater
  • Date: 2008-05-24 16:30:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080524163021-bpkh6s1090i37xy1
Tags: 0.7.3~svn650270-2
* Added release partitioning to database and log directories.
* Corrected postrm maintainer script to not remove logs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2007, 2008 Damien Katz <damien_katz@yahoo.com>
2
 
 
3
1
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
2
// use this file except in compliance with the License.  You may obtain a copy
5
3
// of the License at
12
10
// License for the specific language governing permissions and limitations under
13
11
// the License.
14
12
 
15
 
/* JSON pretty printing */
 
13
// JSON pretty printing
16
14
 
17
15
function prettyPrintJSON(val, indent, linesep, depth) {
18
16
  indent = indent != null ? indent : 4;
26
24
    case "boolean":
27
25
    case "number":
28
26
    case "string":
29
 
      return val.toJSONString();
 
27
      return JSON.stringify(val);
30
28
    case "object": {
31
29
      if (val === null) return "null";
32
 
      if (val.constructor == Date) return val.toJSONString();
 
30
      if (val.constructor == Date) return JSON.stringify(val);
33
31
      var buf = [];
34
32
      if (val.constructor == Array) {
35
33
        buf.push("[");
48
46
          if (!val.hasOwnProperty(key)) continue;
49
47
          buf.push(index > 0 ? propsep : linesep);
50
48
          buf.push(
51
 
            tab, key.toJSONString(), ": ",
 
49
            tab, JSON.stringify(key), ": ",
52
50
            prettyPrintJSON(val[key], indent, linesep, depth + 1)
53
51
          );
54
52
          index++;
60
58
    }
61
59
  }
62
60
}
 
61
 
 
62
// File size pretty printing
 
63
 
 
64
function prettyPrintSize(size) {
 
65
  var jump = 512;
 
66
  if (size < jump) return size + " bytes";
 
67
  var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
 
68
  var i = 0;
 
69
  while (size >= jump && i < units.length) {
 
70
    i += 1;
 
71
    size /= 1024
 
72
  }
 
73
  return size.toFixed(1) + ' ' + units[i - 1];
 
74
}