@sprucelabs/schema
Version:
Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓
36 lines (35 loc) • 1.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractField_1 = __importDefault(require("./AbstractField"));
class BooleanField extends AbstractField_1.default {
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.';
exports.default = BooleanField;