« get me outta code hell

data: use optional in definitions for more utility validators - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-20 19:28:06 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-21 07:50:14 -0400
commit453b0e9845d41c7a1049d4f0982b66121626766a (patch)
treeec07b0a2e8567d06865c92ad336dc1001430ab79 /src
parent7f56163ad123b3ba8da431630d3da67f5444adb6 (diff)
data: use optional in definitions for more utility validators
Diffstat (limited to 'src')
-rw-r--r--src/data/things/validators.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/data/things/validators.js b/src/data/things/validators.js
index f60c363c..19ad1c0a 100644
--- a/src/data/things/validators.js
+++ b/src/data/things/validators.js
@@ -96,7 +96,10 @@ export function isStringNonEmpty(value) {
 }
 
 export function optional(validator) {
-  return value => value === null || value === undefined || validator(value);
+  return value =>
+    value === null ||
+    value === undefined ||
+    validator(value);
 }
 
 // Complex types (non-primitives)
@@ -285,20 +288,14 @@ export function validateProperties(spec) {
 
 export const isContribution = validateProperties({
   who: isArtistRef,
-  what: (value) =>
-    value === undefined ||
-    value === null ||
-    isStringNonEmpty(value),
+  what: optional(isStringNonEmpty),
 });
 
 export const isContributionList = validateArrayItems(isContribution);
 
 export const isAdditionalFile = validateProperties({
   title: isString,
-  description: (value) =>
-    value === undefined ||
-    value === null ||
-    isString(value),
+  description: optional(isStringNonEmpty),
   files: validateArrayItems(isString),
 });