@360works/fmpromise
Version:
A modern JS toolkit for FileMaker Web Viewers, including a dev server and type generation.
20 lines (19 loc) • 700 B
JavaScript
/**
* Validates a configuration object against a schema.
* @param config The pre-evaluated config object from window.FMPROMISE_CONFIG.
* @param schema The module's defined schema.
* @returns An object indicating if the config is valid and a list of any errors.
*/
export function validateConfig(config, schema) {
const errors = [];
for (const key in schema) {
const attribute = schema[key];
if (attribute.required && (config === undefined || config[key] === undefined || config[key] === '')) {
errors.push(`Required setting "${attribute.label || key}" is missing.`);
}
}
return {
isValid: errors.length === 0,
errors,
};
}