@sprucelabs/schema
Version:
Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓
31 lines (30 loc) • 907 B
JavaScript
import AbstractField from './AbstractField.js';
class BooleanField extends AbstractField {
static generateTemplateDetails(options) {
const { definition, language } = options;
const { isArray } = definition;
const arrayNotation = isArray ? '[]' : '';
let valueType = '';
if (language === 'go') {
valueType = `${arrayNotation}bool`;
}
else {
valueType = `boolean${arrayNotation}`;
}
return {
valueType,
};
}
/** * Turn everything into a string */
toValueType(value) {
switch (value) {
case 'true':
return true;
case 'false':
return false;
}
return !!value;
}
}
BooleanField.description = 'A true/false. Converts false string to false, all other strings to true.';
export default BooleanField;