@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
31 lines (23 loc) • 949 B
JavaScript
import { assert } from "../assert.js";
import { noop } from "../function/noop.js";
/**
* @template T
* @param {Object<BinaryDataType>} schema
* @param {Object<T>} enumerable
* @param {function(message:string)} [error_consumer]
* @param {*} [error_consumer_context]
*/
export function validate_enum_schema(schema, enumerable, error_consumer = noop, error_consumer_context) {
assert.notNull(schema, 'schema');
assert.isObject(schema, 'schema');
let valid = true;
const valid_types = Object.values(enumerable);
for (const schemaKey in schema) {
const type = schema[schemaKey];
if (!valid_types.includes(type)) {
error_consumer.call(error_consumer_context, `Field '${schemaKey}' is expected to have have BinaryDataType value, instead found '${type}'. Valid values are: ${valid_types.join(', ')}.`);
valid = false;
}
}
return valid;
}