2 * (C) Copyright 2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
10 function pretty_print_value (value) {
11 if (value === undefined)
15 if (typeof(value) == "object")
16 return value.toSource();
17 if (typeof(value) == "function")
18 return value.toString();
19 if (typeof(value) == "string") {
20 let s = value.toSource();
21 // toSource returns: (new String("<blah>"))
22 // we want just: "<blah>"
23 return s.substring(12, s.length - 2);
25 return new String(value);
28 function pretty_print_file_size (val) {
29 const GIBI = 1073741824; /* 2^30 */
30 const MEBI = 1048576; /* 2^20 */
31 const KIBI = 1024; /* 2^10 */
36 } else if (val < MEBI) {
39 } else if (val < GIBI) {
52 return [val.toFixed(precision), suffix];
55 function pretty_print_time (val) {
56 val = Math.round(val);
57 var seconds = val % 60;
58 val = Math.floor(val / 60);
59 var minutes = val % 60;
60 var hours = Math.floor(val / 60);
64 parts.push(hours + " hours");
69 parts.push(minutes + " minutes");
70 else if (minutes == 1)
71 parts.push("1 minute");
73 if (minutes <= 1 && hours == 0) {
75 parts.push(seconds + " seconds");
77 parts.push("1 second");
80 return parts.join(", ");
83 provide("pretty-print");