UNPKG

succulent

Version:

Powerful and easy runtime type checking

28 lines 889 B
import { Schema } from "../schema"; import { is } from "./is"; export function union(...schemas) { return new Schema((t) => schemas.some((schema) => is(t, schema)), { displayName: `(${schemas .map((schema) => Schema.from(schema).displayName) .join(" | ")})`, *iter() { for (const schema of schemas) yield* Schema.from(schema); }, }); } export function or(x, y) { return new Schema((t) => is(t, x) || is(t, y), { displayName: `(${Schema.displayName(x)} | ${Schema.displayName(y)})`, *iter() { yield* Schema.from(x); yield* Schema.from(y); }, }); } export function and(x, y) { return new Schema((t) => is(t, x) && is(t, y), { displayName: `(${Schema.displayName(x)} & ${Schema.displayName(y)})`, }); } //# sourceMappingURL=logic.js.map