UNPKG

fortify-schema

Version:

TypeScript interface-like schema validation system that's easier to use than Zod

59 lines (56 loc) 1.3 kB
'use strict'; /** * 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 * @example * ```typescript * const schema = Interface({ * status: Make.unionOptional("pending", "accepted", "rejected") * }); * ``` */ static unionOptional(...values) { return values.join("|") + "?"; } } /** * future improvements: * * fromType and fromInterface (see @see {@link "./TODO.md"}) */ exports.Make = Make; //# sourceMappingURL=Make.js.map