From 93dfe2be64e8658839bcfe5356adf35f8cde7075 Mon Sep 17 00:00:00 2001
From: Nicolas James <Eele1Ephe7uZahRie@tutanota.com>
Date: Thu, 13 Feb 2025 18:04:18 +1100
Subject: initial commit

---
 src/web/helpers/Input.jsx | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 src/web/helpers/Input.jsx

(limited to 'src/web/helpers/Input.jsx')

diff --git a/src/web/helpers/Input.jsx b/src/web/helpers/Input.jsx
new file mode 100644
index 0000000..55f6016
--- /dev/null
+++ b/src/web/helpers/Input.jsx
@@ -0,0 +1,31 @@
+export function getFieldError(field, minmax) {
+    if (field == null || field.length == 0) {
+        return "Required"
+    }
+    const [min, max] = minmax;
+    if (field.length < min) {
+        return "Too short";
+    }
+    if (field.length > max) {
+        return "Too long";
+    }
+    return null;
+}
+
+// Removes consecutive spaces.
+export function cleanField(field) {
+    return field.replace(/\s{2,}/g, " ").replace(/\n{2,}/g, "\n");
+}
+
+export function correctFieldAnimate(field, setField, fieldErrors) {
+    if (fieldErrors == null) {
+        return;
+    }
+    setField({...field, animating: true, erroring: true});
+}
+
+// Requires lower case extension.
+export function isSupportedExtension(ext) {
+    const extensions = ["png", "jpeg", "jpg"];
+    return extensions.some((e) => e == ext);
+}
\ No newline at end of file
-- 
cgit v1.2.3

