@backland/schema
Version:
TypeScript schema declaration and validation library with static type inference
33 lines (31 loc) • 706 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EnumField = void 0;
var _FieldType = require("./FieldType");
class EnumField extends _FieldType.FieldType {
//
get value() {
return this.def;
}
constructor(def) {
super({
def: def,
name: 'enum'
});
this.parse = this.applyParser({
parse: input => {
if (!this.def.includes(input)) {
throw new Error(`accepted: ${this.def.map(e => `'${e}'`).join(' or ')}, found ${input}.`);
}
return input;
}
});
}
static create = def => {
return new EnumField(def);
};
}
exports.EnumField = EnumField;
//# sourceMappingURL=EnumField.js.map