summaryrefslogtreecommitdiff
path: root/cli/js/util.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2019-11-21 03:02:08 +1100
committerRy Dahl <ry@tinyclouds.org>2019-11-20 11:02:08 -0500
commit8d977d0117c2b61e6714cec9e4238f4ba0a56195 (patch)
tree5992f83fa50067f59aec1f1c9008d6c3fe6e921d /cli/js/util.ts
parent1912ed674097588adb7b83e7b78043b2168821f3 (diff)
feat: Support named exports on bundles. (#3352)
Diffstat (limited to 'cli/js/util.ts')
-rw-r--r--cli/js/util.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/cli/js/util.ts b/cli/js/util.ts
index 54230af1f..b046a34f4 100644
--- a/cli/js/util.ts
+++ b/cli/js/util.ts
@@ -248,3 +248,19 @@ export function commonPath(paths: string[], sep = "/"): string {
const prefix = parts.slice(0, endOfPrefix).join(sep);
return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`;
}
+
+/** Utility function to turn the number of bytes into a human readable
+ * unit */
+export function humanFileSize(bytes: number): string {
+ const thresh = 1000;
+ if (Math.abs(bytes) < thresh) {
+ return bytes + " B";
+ }
+ const units = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
+ let u = -1;
+ do {
+ bytes /= thresh;
+ ++u;
+ } while (Math.abs(bytes) >= thresh && u < units.length - 1);
+ return `${bytes.toFixed(1)} ${units[u]}`;
+}