From 1022c7ee7dadce002b00144eaacb5742ea0a7058 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Tue, 27 Nov 2018 10:57:31 +0100 Subject: [PATCH] Add function that validates whether a given value is a correct vcabulary Feature #14393 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/models/vocabulary.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/models/vocabulary.ts b/src/models/vocabulary.ts index 3dbd4756..c1c3c1e9 100644 --- a/src/models/vocabulary.ts +++ b/src/models/vocabulary.ts @@ -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 -- 2.30.2