summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/number_utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/lib/utils/number_utils.js')
-rw-r--r--app/assets/javascripts/lib/utils/number_utils.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/number_utils.js b/app/assets/javascripts/lib/utils/number_utils.js
index 0f29f538b07..63feb6f9b1d 100644
--- a/app/assets/javascripts/lib/utils/number_utils.js
+++ b/app/assets/javascripts/lib/utils/number_utils.js
@@ -150,3 +150,24 @@ export const formattedChangeInPercent = (firstY, lastY, { nonFiniteResult = '-'
return `${change >= 0 ? '+' : ''}${change}%`;
};
+
+/**
+ * Checks whether a value is numerical in nature by converting it using parseInt
+ *
+ * Example outcomes:
+ * - isNumeric(100) = true
+ * - isNumeric('100') = true
+ * - isNumeric(1.0) = true
+ * - isNumeric('1.0') = true
+ * - isNumeric('abc100') = false
+ * - isNumeric('abc') = false
+ * - isNumeric(true) = false
+ * - isNumeric(undefined) = false
+ * - isNumeric(null) = false
+ *
+ * @param value
+ * @returns {boolean}
+ */
+export const isNumeric = (value) => {
+ return !Number.isNaN(parseInt(value, 10));
+};