Expresso.Presenter.Schema.Check (expresso v0.1.0)

Copy Markdown View Source

Makes sure that a JSON value agrees with a form of Expresso.Presenter.Schema

check/2 examines a decoded JSON value with the same forms as the decoders of assets/src/schema.ts. Expresso.Presenter.Verifier uses it for the values of a definition, and the tests use it for each value that the renderer writes. An error holds the path of the value, such as $.modes[2].keys, and the form that the value does not agree with.

A pattern has the meaning of a JavaScript regular expression: $ matches only at the end of the string, and not in front of a last newline.

Summary

Functions

Make sure that a decoded JSON value agrees with a form, or with the form of a name

Functions

check(value, name)

@spec check(term(), atom() | Expresso.Presenter.Schema.type()) ::
  :ok | {:error, String.t()}

Make sure that a decoded JSON value agrees with a form, or with the form of a name

iex> Expresso.Presenter.Schema.Check.check("12", {:string, "^[0-9]*$"})
:ok

iex> Expresso.Presenter.Schema.Check.check("12\n", {:string, "^[0-9]*$"})
{:error, ~s($: expected {:string, "^[0-9]*$"})}