Create optional validator
[arvados-workbench2.git] / src / validators / optional.tsx
diff --git a/src/validators/optional.tsx b/src/validators/optional.tsx
new file mode 100644 (file)
index 0000000..da3a825
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export const optional = (validator: (value: any) => string | undefined) =>
+    (value: any) =>
+        value === undefined || value === null || value === ''  ? undefined : validator(value);
\ No newline at end of file