Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Usage

import * as mod from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/schemable.ts";

Schemable presents a unified algebra for parsing, decoding guarding, or otherwise building typed js structures in TypeScript.

§Functions

schema

A helper function to build a generic Schema that can be used with any Schemable.

§Interfaces

ArraySchemable

Takes a Schemable and returns a Schemable<ReadonlyArray>

BooleanSchemable

Wraps a boolean type in Schemable.

IntersectSchemable

Takes two schemables, left and right, and returns the intersection of them. This means that any value for must match both schemables.

LazySchemable

Takes an id and a thunk returning a schemable and returns a schemable that matches the return value of the thunk. This schemable is necessary for handling recursive or corecursive schemables.

LiteralSchemable

Wraps a union of literals in Schemable.

NullableSchemable

Takes a Schemable and returns a Schemable<A | null>;

NumberSchemable

Wraps a number type in Schemable.

PartialSchemable

Takes a struct of Schemables and returns a Schemable for a struct that matches, key for key, the input schemables but the values can also be partial.

RecordSchemable

Takes a Schemable and returns a Schemable<ReadonlyRecord>

Schemable

A Schemable is the union of all schemable methods. This allows one to build an arbitrary Schema using the Schemable interface, then pass a concrete Schemable implementation to the Schema. Thus, one can build a single model and produce decoders, guards, or jsonschema from that model.

StringSchemable

Wraps a string type in Schemable.

StructSchemable

Takes a struct of Schemables and returns a Schemable for a struct that matches, key for key, the input schemables.

TupleSchemable

Takes a tuple of Schemables and returns a Schemable for a tuple that matches, index for index, the input schemables.

UndefinableSchemable

Takes a Schemable and returns a Schemable<A | undefined>;

UnionSchemable

Takes two schemables, left and right, and returns the union of them. This means that any value for must match either schemable.

UnknownSchemable

Wraps an unknown type in Schemable. This is the best escape hatch when a Schema isn't known ahead of time.

§Type Aliases

Literal

These are the super-types that a Literal schema must extent. They are used to constrain the inputs for LiteralSchemable.

Schema

A Schema is the a function that takes a generic schemable and builds a specific model from it.

TypeOf

Extracts the inner type of a Schema