32 lines
749 B
JavaScript
32 lines
749 B
JavaScript
import { Field_Configuration } from '@efforting.tech/data/field-configuration';
|
|
|
|
|
|
function mandatory_anything(value) {
|
|
return value !== undefined;
|
|
}
|
|
|
|
|
|
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);
|
|
console.log(fc.load(undefined, 'New thingamabob object'));
|