All Projects → am-kantox → exvalibur

am-kantox / exvalibur

Licence: other
Elixir Validator Generator

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to exvalibur

unity-asset-validator
The Asset Validator is an editor tool for validating assets in the project and in scenes.
Stars: ✭ 30 (+114.29%)
Mutual labels:  validation
cnpj
🇧🇷 Format, validate and generate CNPJ numbers in Node & Deno
Stars: ✭ 26 (+85.71%)
Mutual labels:  validation
fastify-response-validation
A simple plugin that enables response validation for Fastify.
Stars: ✭ 20 (+42.86%)
Mutual labels:  validation
validatedb
Validate on a table in a DB, using dbplyr
Stars: ✭ 15 (+7.14%)
Mutual labels:  validation
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (+21.43%)
Mutual labels:  validation
ng2-multi-step-wizard-ui-router1
Series 3: Tutorials on creating an Angular 2 Multi-Step Wizard using UI-Router 1.0 and TypeScript 2.0.10
Stars: ✭ 33 (+135.71%)
Mutual labels:  validation
datalize
Parameter, query, form data validation and filtering for NodeJS.
Stars: ✭ 55 (+292.86%)
Mutual labels:  validation
react-form-validation-demo
React Form Validation Demo
Stars: ✭ 88 (+528.57%)
Mutual labels:  validation
Fore
Fore - declarative programming with web components
Stars: ✭ 34 (+142.86%)
Mutual labels:  validation
verum-php
Server-Side Validation Library for PHP
Stars: ✭ 17 (+21.43%)
Mutual labels:  validation
ember-changeset-conditional-validations
Conditional validations for ember-changeset-validations
Stars: ✭ 26 (+85.71%)
Mutual labels:  validation
openapi-lint-vscode
OpenAPI 2.0/3.0.x intellisense, validator, linter, converter and resolver extension for Visual Studio Code
Stars: ✭ 47 (+235.71%)
Mutual labels:  validation
fqdn
RFC-compliant FQDN validation and manipulation for Python.
Stars: ✭ 23 (+64.29%)
Mutual labels:  validation
rdf-validate-shacl
Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
Stars: ✭ 61 (+335.71%)
Mutual labels:  validation
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (+71.43%)
Mutual labels:  validation
frames-android
Checkout API Client, Payment Form UI and Utilities
Stars: ✭ 26 (+85.71%)
Mutual labels:  validation
vue-tiny-validate
💯 Tiny Vue Validate Composition
Stars: ✭ 80 (+471.43%)
Mutual labels:  validation
NZ-Bank-Account-Validator
A small, zero dependency NZ bank account validation library that runs everywhere.
Stars: ✭ 15 (+7.14%)
Mutual labels:  validation
peppermint
Declarative data validation framework, written in Swift
Stars: ✭ 37 (+164.29%)
Mutual labels:  validation
liquibase-linter
Quality control for your Liquibase scripts
Stars: ✭ 15 (+7.14%)
Mutual labels:  validation

Logo Exvalibur

CircleCI     generator for blazingly fast validators of maps based on sets of predefined rules

Installation

Simply add exvalibur to your list of dependencies in mix.exs:

def deps do
  [
    {:exvalibur, "~> 0.1"}
  ]
end

Usage

rules = [
  %{matches: %{currency_pair: "EURUSD"},
    conditions: %{rate: %{min: 1.0, max: 2.0}}}]
Exvalibur.validator!(rules, module_name: Exvalibur.Validator)
Exvalibur.Validator.valid?(%{currency_pair: "EURUSD", rate: 1.5})
#⇒ {:ok, %{currency_pair: "EURUSD", rate: 1.5}}
Exvalibur.Validator.valid?(%{currency_pair: "EURGBP", rate: 1.5})
#⇒ :error
Exvalibur.Validator.valid?(%{currency_pair: "EURUSD", rate: 0.5})
#⇒ :error

rules = [
  %{matches: %{currency_pair: "EURGBP"},
    conditions: %{rate: %{min: 1.0, max: 2.0}}}]
Exvalibur.validator!(rules, module_name: Exvalibur.Validator)
Exvalibur.Validator.valid?(%{currency_pair: "EURGBP", rate: 1.5})
#⇒ {:ok, %{currency_pair: "EURGBP", rate: 1.5}}
Exvalibur.Validator.valid?(%{currency_pair: "EURUSD", rate: 1.5})
#⇒ {:ok, %{currency_pair: "EURUSD", rate: 1.5}}

Sigils To Pattern Match Data

Starting with v0.4.0 we support ~q and ~Q sigils to use validator with pattern matching.

  import Exvalibur.Sigils

  starting_with = "bar"
  rules = [%{matches: %{foo: ~q[<<"#{starting_with}", _::binary>>]}}]

  Exvalibur.validator!(rules, module_name: TestValidator)

  assert TestValidator.valid?(%{foo: "bar"}) == {:ok, %{foo: "bar"}}
  assert TestValidator.valid?(%{foo: "zzz"}) == :error
  assert TestValidator.valid?(%{foo: 42}) == :error

Binary Conditions

Starting with v0.5.0 we support binary conditions for the declared guards.

  import Exvalibur.Sigils

  rules = [%{conditions: "num >= 0 and num <= 100"}]

  Exvalibur.validator!(rules, module_name: TestValidator)

  assert TestValidator.valid?(%{num: "bar"}) == :error
  assert TestValidator.valid?(%{num: 200}) == :error
  assert TestValidator.valid?(%{num: 42}) == {:ok, %{num: 42}}

Any match expression allowed in function head matching clause is allowed here.

  import Exvalibur.Sigils

  rules = [%{matches: %{foo: ~Q[%{} = _]}}]

  Exvalibur.validator!(rules, module_name: TestValidator)

  assert TestValidator.valid?(%{foo: %{bar: "baz"}}) == {:ok, %{foo: %{bar: "baz"}}}
  assert TestValidator.valid?(%{foo: 42}) == :error

Custom Guards

Starting with v0.6.0 we support arbitrary custom guards in rules. The variables used in these guards should be explicitly declared under the matches key in rules, in the form foo: ~Q[foo].

  import Exvalibur.Sigils

  rules = [%{
    matches: %{num: ~Q[num]},
    guards: ["num >= 0 and num <= 100"]
  }]

  Exvalibur.validator!(rules, module_name: TestValidator)

  assert TestValidator.valid?(%{num: "bar"}) == :error
  assert TestValidator.valid?(%{num: 200}) == :error
  assert TestValidator.valid?(%{num: 42}) == {:ok, %{num: 42}}

Module-based validators

defmodule Validator do
  use Exvalibur, rules: [
    %{
      matches: %{currency_pair: <<"EUR", _ :: binary>>},
      conditions: %{foo: %{min: 0, max: 100}},
      guards: %{num: num > 0 and num < 100}}]
end
Validator.valid?(%{currency_pair: "EURUSD", foo: 50, num: 50})
#⇒ {:ok, %{currency_pair: "EURUSD", foo: 50, num: 50}}

Validator.valid?(%{currency_pair: "USDEUR", foo: 50, num: 50})
#⇒ :error
Validator.valid?(%{currency_pair: "EURUSD", foo: -50, num: 50})
#⇒ :error
Validator.valid?(%{currency_pair: "EURUSD", foo: 50, num: -50})
#⇒ :error

Changelog

0.11.0

  • Descriptive errors

0.10.0

  • @behaviour Exvalibur.Validatable with overridable custom_validate/1

0.9.0

  • valid?/1 is deprecated in favor of validate/1; starting with v1.0 valid?/1 will return boolean value

0.8.0

  • module-based validators

Documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].