aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/html/util/friendly.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/frontend/html/util/friendly.js')
-rw-r--r--src/zenserver/frontend/html/util/friendly.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/zenserver/frontend/html/util/friendly.js b/src/zenserver/frontend/html/util/friendly.js
new file mode 100644
index 000000000..6eee3a5b8
--- /dev/null
+++ b/src/zenserver/frontend/html/util/friendly.js
@@ -0,0 +1,23 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+"use strict";
+
+////////////////////////////////////////////////////////////////////////////////
+export class Friendly
+{
+ static sep(value, prec=0)
+ {
+ return (+value).toLocaleString("en", {
+ style: "decimal",
+ minimumFractionDigits : prec,
+ maximumFractionDigits : prec,
+ });
+ }
+
+ static k(x) { return Friendly.sep((x + 999) / Math.pow(10, 3), 0) + "K"; }
+ static m(x) { return Friendly.sep( x / Math.pow(10, 6), 1) + "M"; }
+ static g(x) { return Friendly.sep( x / Math.pow(10, 6), 2) + "G"; }
+ static kib(x) { return Friendly.sep((x + 1023) / (1 << 10), 0) + " KiB"; }
+ static mib(x) { return Friendly.sep( x / (1 << 20), 1) + " MiB"; }
+ static gib(x) { return Friendly.sep( x / (1 << 30), 2) + " GiB"; }
+}