2 * (C) Copyright 2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
8 function pretty_print_value (value
) {
9 if (value
=== undefined)
13 if (typeof(value
) == "object")
14 return value
.toSource();
15 if (typeof(value
) == "function")
16 return value
.toString();
17 if (typeof(value
) == "string") {
18 let s
= value
.toSource();
19 // toSource returns: (new String("<blah>"))
20 // we want just: "<blah>"
21 return s
.substring(12, s
.length
- 2);
23 return new String(value
);
26 function pretty_print_file_size (val
) {
27 const GIBI
= 1073741824; /* 2^30 */
28 const MEBI
= 1048576; /* 2^20 */
29 const KIBI
= 1024; /* 2^10 */
34 } else if (val
< MEBI
) {
37 } else if (val
< GIBI
) {
50 return [val
.toFixed(precision
), suffix
];
53 function pretty_print_time (val
) {
54 val
= Math
.round(val
);
55 var seconds
= val
% 60;
56 val
= Math
.floor(val
/ 60);
57 var minutes
= val
% 60;
58 var hours
= Math
.floor(val
/ 60);
62 parts
.push(hours
+ " hours");
67 parts
.push(minutes
+ " minutes");
68 else if (minutes
== 1)
69 parts
.push("1 minute");
71 if (minutes
<= 1 && hours
== 0) {
73 parts
.push(seconds
+ " seconds");
75 parts
.push("1 second");
78 return parts
.join(", ");
81 provide("pretty-print");