import { Invalid_Data } from '@efforting.tech/errors'; export class Field_Configuration { constructor(name, validator=null, expected=undefined) { Object.assign(this, { name, validator, expected }); } check_validation(value) { const { validator } = this; return !validator || validator(value); } validate(value, target=undefined) { const { validator, name, expected } = this; if (!this.check_validation(value)) { throw new Invalid_Data({ name, validator, value, target, expected, }); } } }