« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/validators.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/validators.js')
-rw-r--r--src/data/things/validators.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/data/things/validators.js b/src/data/things/validators.js
index a0d473ba..24db3c79 100644
--- a/src/data/things/validators.js
+++ b/src/data/things/validators.js
@@ -96,6 +96,10 @@ export function isStringNonEmpty(value) {
   return true;
 }
 
+export function optional(validator) {
+  return value => value === null || value === undefined || validator(value);
+}
+
 // Complex types (non-primitives)
 
 export function isInstance(value, constructor) {
@@ -252,6 +256,16 @@ export const isAdditionalFile = validateProperties({
 
 export const isAdditionalFileList = validateArrayItems(isAdditionalFile);
 
+export const isTrackSection = validateProperties({
+  name: optional(isString),
+  color: optional(isColor),
+  dateOriginallyReleased: optional(isDate),
+  isDefaultTrackSection: optional(isBoolean),
+  tracksByRef: optional(validateReferenceList('track')),
+});
+
+export const isTrackSectionList = validateArrayItems(isTrackSection);
+
 export function isDimensions(dimensions) {
   isArray(dimensions);