Started textnodes, renamed tool with wrong name, started field configuration system
This commit is contained in:
24
source/data/field-configuration.mjs
Normal file
24
source/data/field-configuration.mjs
Normal file
@@ -0,0 +1,24 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user