about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/numbers.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/flavours/glitch/util/numbers.js')
-rw-r--r--app/javascript/flavours/glitch/util/numbers.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/util/numbers.js b/app/javascript/flavours/glitch/util/numbers.js
new file mode 100644
index 000000000..f7e4ceb93
--- /dev/null
+++ b/app/javascript/flavours/glitch/util/numbers.js
@@ -0,0 +1,12 @@
+import React, { Fragment } from 'react';
+import { FormattedNumber } from 'react-intl';
+
+export const shortNumberFormat = number => {
+  if (number < 1000) {
+    return <FormattedNumber value={number} />;
+  } else if (number < 1000000) {
+    return <Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</Fragment>;
+  } else {
+    return <Fragment><FormattedNumber value={number / 1000000} maximumFractionDigits={1} />M</Fragment>;
+  }
+};