Add function that validates whether a given value is a correct vcabulary
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 27 Nov 2018 09:57:31 +0000 (10:57 +0100)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 27 Nov 2018 09:57:31 +0000 (10:57 +0100)
Feature #14393

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/models/vocabulary.ts

index 3dbd4756b22d7f801130e7b80af87ca615019d7f..c1c3c1e9acc8cd34ab2d4aeccc36e2fd82a6fda1 100644 (file)
@@ -2,6 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { isObject, has, every } from 'lodash/fp';
+
 export interface Vocabulary {
     strict: boolean;
     tags: Tag[];
@@ -11,3 +13,12 @@ export interface Tag {
     strict: boolean;
     values: string[];
 }
+
+const VOCABULARY_VALIDATORS = [
+    isObject,
+    has('strict'),
+    has('tags'),
+];
+
+export const isVocabulary = (value: any) =>
+    every(validator => validator(value), VOCABULARY_VALIDATORS);
\ No newline at end of file