Murk is an Elixir data type validation library.


License
GPL-3.0

Documentation

Murk

Murk is an Elixir data type validation library.

Installation

Add murk to your list of dependencies in mix.exs:

  def deps do
    [{:murk, "~> 0.4.0"}]
  end

Usage

Murk provides a few functions for type validation.

Murk.type(:test)          #=> :atom
Murk.type("test")         #=> :string
Murk.type(1)              #=> :integer
Murk.type(%{name: "foo"}) #=> %{name: :string}

Murk.is_type?(:test, :atom)   #=> true
Murk.is_type?(:test, :string) #=> false

Murk also allows you to define your structs as valid Murk types.

defmodule Human do
  import Murk

  defmurk do
    field :name, :string
    field :age,  :integer, required: false
  end
end

Now %Human{} also has access to Murk function, but also the valid? function.

Murk.valid?(%Human{})                       #=> false
Murk.valid?(%Human{age: 20})                #=> false
Murk.valid?(%Human{name: "human"})          #=> true
Murk.valid?(%Human{name: "human", age: 20}) #=> true

You an also add custom nested types, which need to be valid as well

field :friends, [Human]