fortify-schema
Version:
A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities.
41 lines (38 loc) • 1.25 kB
JavaScript
'use strict';
/**
* Builder for the "else" part of conditional validation with TypeScript inference
* This class is returned after calling .then() and provides the .else() method
*/
class ConditionalElse {
constructor(builder, condition, thenSchema) {
this.builder = builder;
this.condition = condition;
this.thenSchema = thenSchema;
}
/**
* Specify the schema to use when the condition is false
*/
else(elseSchema) {
// Add the condition with the "then" schema
this.builder.addCondition(this.condition, this.thenSchema);
// Set the default schema (used when condition is false)
const result = this.builder.default(elseSchema);
// Return with type information for TypeScript inference
return result;
}
/**
* Alias for else() - for backward compatibility
*/
default(defaultSchema) {
return this.else(defaultSchema);
}
/**
* Build without else clause (same as calling .else(undefined))
*/
build() {
this.builder.addCondition(this.condition, this.thenSchema);
return this.builder.build();
}
}
exports.ConditionalElse = ConditionalElse;
//# sourceMappingURL=ConditionalElse.js.map