mirror of
https://github.com/koloml/philomena-tagging-assistant.git
synced 2026-05-09 07:12:19 +00:00
Validate exclusive and conditional as optional booleans
This commit is contained in:
@@ -32,6 +32,14 @@ function validateOptionalArray(value: unknown): boolean {
|
||||
return typeof value === 'undefined' || value === null || Array.isArray(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the following value is not set or is a valid boolean.
|
||||
* @param value Value to be checked.
|
||||
*/
|
||||
function validateOptionalBoolean(value: unknown): boolean {
|
||||
return typeof value === 'undefined' || typeof value === 'boolean';
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of validators for each entity. Function should throw the error if validation failed.
|
||||
*/
|
||||
@@ -73,7 +81,8 @@ const entitiesValidators: EntitiesValidationMap = {
|
||||
!validateRequiredString(importedObject?.id)
|
||||
|| !validateRequiredString(importedObject?.name)
|
||||
|| !validateOptionalArray(importedObject?.tags)
|
||||
|| typeof importedObject.conditional !== 'boolean'
|
||||
|| !validateOptionalBoolean(importedObject?.exclusive)
|
||||
|| !validateOptionalBoolean(importedObject?.conditional)
|
||||
|| !validateOptionalArray(importedObject?.requiredTags)
|
||||
) {
|
||||
throw new Error('Invalid preset format detected!');
|
||||
|
||||
Reference in New Issue
Block a user