ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - bydooweedoo/is: Fast, extensible and easy to use data structure validation for elixir with nested structures support.
Fast, extensible and easy to use data structure validation for elixir with nested structures support. - bydooweedoo/is
Visit Site

GitHub - bydooweedoo/is: Fast, extensible and easy to use data structure validation for elixir with nested structures support.

GitHub - bydooweedoo/is: Fast, extensible and easy to use data structure validation for elixir with nested structures support.

Is

Fast, extensible and easy to use data structure validation for elixir with nested structures support.

Installation

If available in Hex, the package can be installed by adding is to your list of dependencies in mix.exs:

def deps do
  [
    {:is, "~> 1.0.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/is.

Example

iex> data = Enum.map(1..2, &(%{
...>   a: 1,
...>   b: "b",
...>   c: {"a", "b", false},
...>   d: [[1, 2, "3"], [4, false, 6]],
...>   e: -1,
...>   f: "1234567891011",
...>   index: &1 - 10,
...> }))
iex> schema = [list: [map: %{
...>   a: :binary,
...>   b: :boolean,
...>   c: [list: [or: [:binary, :boolean]]],
...>   d: [list: [list: :integer]],
...>   e: [and: [:optional, :binary]],
...>   index: [and: [:integer, in_range: [min: 0]]],
...> }]]
iex> Is.validate(data, schema)
[
  {:error, [0, :a], "must be a binary"},
  {:error, [0, :b], "must be a boolean"},
  {:error, [0, :c], "must be a list"},
  {:error, [0, :d, 0, 2], "must be an integer"},
  {:error, [0, :d, 1, 1], "must be an integer"},
  {:error, [0, :e], "must be a binary"},
  {:error, [0, :index], "must at least be 0"},
  {:error, [1, :a], "must be a binary"},
  {:error, [1, :b], "must be a boolean"},
  {:error, [1, :c], "must be a list"},
  {:error, [1, :d, 0, 2], "must be an integer"},
  {:error, [1, :d, 1, 1], "must be an integer"},
  {:error, [1, :e], "must be a binary"},
  {:error, [1, :index], "must at least be 0"},
]

Validations

Basic types

:atom

Test if data is an atom or not

iex> Is.validate(:value, :atom)
[]

iex> Is.validate(:value, atom: true)
[]

iex> Is.validate(1, :atom)
[{:error, [], "must be a atom"}]

iex> Is.validate(:value, atom: false)
[{:error, [], "must not be a atom"}]

:binary

Test if data is a binary or not

iex> Is.validate("value", :binary)
[]

iex> Is.validate("value", binary: true)
[]

iex> Is.validate(1, :binary)
[{:error, [], "must be a binary"}]

iex> Is.validate("value", binary: false)
[{:error, [], "must not be a binary"}]

:boolean

Test if data is a boolean or not

iex> Is.validate(true, :boolean)
[]

iex> Is.validate(true, boolean: true)
[]

iex> Is.validate(1, :boolean)
[{:error, [], "must be a boolean"}]

iex> Is.validate(true, boolean: false)
[{:error, [], "must not be a boolean"}]

:equals

Test if data equals given value

iex> Is.validate(true, equals: true)
[]

iex> Is.validate("str", equals: "str")
[]

iex> Is.validate(1, equals: true)
[{:error, [], "must equals true"}]

:fn

Test if data equals given value

iex> Is.validate(1, fn: &is_number/1)
[]

iex> Is.validate(true, fn: &is_number/1)
[{:error, [], "must satisfies &:erlang.is_number/1"}]

iex> starts_with? = fn(value, prefix) ->
...>   if String.starts_with?(value, prefix) do
...>     :ok
...>   else
...>     {:error, "must start with #{inspect prefix}"}
...>   end
...> end
iex> Is.validate("https://elixir-lang.org", fn: [starts_with?, "http"])
[]
iex> Is.validate("elixir-lang.org", fn: [starts_with?, "http"])
[{:error, [], "must start with \"http\""}]

iex> Is.validate(12, fn: {1, 2})
[{:error, [], "fn: options are invalid"}]

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory