Function definitions

  • creates a builder for a definitions structure

    This is the only moderately complicated function for building a schema. After creating a schema, you can add a new definition by calling def with the name of the new definition, and a function that creates it from the current references.

    Returns Definitions<{}>

    Remarks

    Unlike full JTD, references declared in this way can't be cyclic. You can only reference previously defined references.

    Example

    const schema = definitions()
    .def("a", () => boolean())
    .def("b": ({ a }) => elements(a))
    .def("c": ({ a, b }) => properties({ a }, { b }))
    .build(({ c }) => c);
    schema.guard({ a: true, b: [false] });
    schema.guard({ a: false });