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.
62 lines (59 loc) • 1.39 kB
JavaScript
;
/**
* Helper class for creating schema values
*/
class Make {
/**
* Create a constant value (safer than using raw values)
* @example
* ```typescript
* const schema = Interface({
* status: Make.const("pending"),
* version: Make.const(1.0),
* enabled: Make.const(true)
* });
* ```
*/
static const(value) {
return {
const: value,
};
}
/**
* Create a union type (multiple allowed values) with proper type inference
* @example
* ```typescript
* const schema = Interface({
* status: Make.union("pending", "accepted", "rejected"),
* priority: Make.union("low", "medium", "high")
* });
* ```
*/
static union(...values) {
return {
union: values,
};
}
/**
* Create an optional union type with proper type inference
* @example
* ```typescript
* const schema = Interface({
* status: Make.unionOptional("pending", "accepted", "rejected")
* });
* ```
*/
static unionOptional(...values) {
return {
union: values,
optional: true,
};
}
}
/**
* future improvements:
*
* fromType and fromInterface (see @see {@link "/TODOS/TS_COMPILER.todo.md"})
*/
exports.Make = Make;
//# sourceMappingURL=Make.js.map