Added coercing system to field configuration, revised some of the data validation errors
This commit is contained in:
@@ -6,11 +6,26 @@ function mandatory_anything(value) {
|
||||
}
|
||||
|
||||
|
||||
const fc = new Field_Configuration('Some_Field', mandatory_anything, 'Anything defined');
|
||||
function string_coercion_function(value) {
|
||||
if (value === undefined) {
|
||||
throw new Error('Undefined not allowed');
|
||||
}
|
||||
return String(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const fc = new Field_Configuration('Some_Field', null, string_coercion_function, 'Anything that could be a string');
|
||||
|
||||
console.log(fc.check_validation(undefined));
|
||||
console.log(fc.check_validation(true));
|
||||
|
||||
console.log([ fc.coerce(123) ]);
|
||||
console.log([ fc.coerce(true) ]);
|
||||
|
||||
console.log([ fc.load(undefined, 'Some configuration') ]);
|
||||
console.log([ fc.load(true) ]);
|
||||
|
||||
|
||||
//fc.validate(undefined);
|
||||
fc.validate(undefined, 'New thingamabob object');
|
||||
console.log(fc.load(undefined, 'New thingamabob object'));
|
||||
|
||||
Reference in New Issue
Block a user