All Projects → balance-platform → talos

balance-platform / talos

Licence: other
Elixir parameter validation library. Simple and extensible

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to talos

react-formulation
Simple React form validation
Stars: ✭ 14 (-39.13%)
Mutual labels:  forms, validate
tarams
Casting and validating external data and request parameters in Elixir and Phoenix
Stars: ✭ 40 (+73.91%)
Mutual labels:  params-validate, params-validator
Build-Former
This is a library for building forms dynamically in Android.
Stars: ✭ 20 (-13.04%)
Mutual labels:  forms
streaming-form-data
Streaming parser for multipart/form-data written in Cython
Stars: ✭ 112 (+386.96%)
Mutual labels:  forms
ember-validated-form-buffer
A validated form buffer that wraps Ember Data models for use in forms.
Stars: ✭ 46 (+100%)
Mutual labels:  forms
cleye
👁‍🗨 cleye — The intuitive & typed CLI development tool for Node.js
Stars: ✭ 235 (+921.74%)
Mutual labels:  parameters
react-conversational-ui
🤖 React conversational UI
Stars: ✭ 51 (+121.74%)
Mutual labels:  forms
flask-wtf
Simple integration of Flask and WTForms, including CSRF, file upload and Recaptcha integration.
Stars: ✭ 1,357 (+5800%)
Mutual labels:  forms
ember-validity-modifier
Ember Octane addon to add custom validity (form validation) to form fields
Stars: ✭ 28 (+21.74%)
Mutual labels:  forms
form-saver
A simple script that lets users save and reuse form data.
Stars: ✭ 67 (+191.3%)
Mutual labels:  forms
react-forms-processor
A forms processor for React
Stars: ✭ 63 (+173.91%)
Mutual labels:  forms
opzioni
The wanna-be-simplest command line arguments library for C++
Stars: ✭ 29 (+26.09%)
Mutual labels:  parameters
LC-switch
Superlight vanilla javascript plugin improving forms look and functionality
Stars: ✭ 31 (+34.78%)
Mutual labels:  forms
platform
A collection of minimalistic, easy-to-use and fully customizable Angular components, directives and services
Stars: ✭ 17 (-26.09%)
Mutual labels:  forms
FrontendForms
A module for ProcessWire CMS to create and validate forms on the frontend easily using the Valitron library.
Stars: ✭ 0 (-100%)
Mutual labels:  forms
Formidable
The PHP pragmatic forms library
Stars: ✭ 116 (+404.35%)
Mutual labels:  forms
reach-schema
Functional schema-driven JavaScript object validation library.
Stars: ✭ 34 (+47.83%)
Mutual labels:  validate
insect
🛠 Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (+43.48%)
Mutual labels:  forms
RapidFormBundle
Create Symfony forms at record speed using PHP 8 attributes!
Stars: ✭ 33 (+43.48%)
Mutual labels:  forms
mui-form-fields
Material UI + Final Form Forms and Components
Stars: ✭ 15 (-34.78%)
Mutual labels:  forms

Talos

hex.pm hex.pm hex.pm hex.pm github.com Elixir CI

Talos is simple parameters validation library

Documentation can be found at ExDoc

Why another one validation library?

I needed more checks than just whether the value belonged to a particular data type.

This library allows you to define your own checks and use typical checks with a simple setup.

Usage

  defmodule CheckUserSignUp do
    import Talos

    @schema map(fields: [
      field(key: "action", type: const(value: "sign-up")),
      field(key: "email", type: string(min_length: 5, max_length: 255, regexp: ~r/.*@.*/)),
      field(key: "age", type: integer(gteq: 18, allow_nil: true))
    ])

    def validate(%{} = map_data) do
      params = Talos.permit(map_data)
      errors = Talos.errors(@schema, params)

      case errors == %{} do
        true -> {:ok, params}
        false -> {:error, errors}
      end
    end
  end

Somewhere in UserController

  ...

  def sign_up(conn, params)
    case CheckUserSignUp.valid?(params) do
       :ok -> 
          result = MyApp.register_user!(params)
          render_json(%{"ok" => true | result})
       {:error, errors} -> 
          render_errors(errors)
    end
  end
  
  ...

Flow

Own Type definition

If you want define own Type, just create module with Talos.Types behavior

defmodule ZipCodeType do
  @behaviour Talos.Types
  defstruct [length: 6]

  def valid?(%__MODULE__{length: len}, value) do
    String.valid?(value) && String.match?(value, ~r/\d{len}/)
  end

  def errors(__MODULE__, value) do
    case valid?(__MODULE__,value) do
      true -> []
      false -> ["#{value} is not zipcode"]
    end
  end
end

# And use it

Talos.valid?(%ZipCodeType{}, "123456") # => true
Talos.valid?(%ZipCodeType{}, "1234") # => false
Talos.valid?(%ZipCodeType{}, 123456) # => false

Installation

def deps do
  [
    {:talos, "~> 1.12"}
  ]
end

Contribution

Feel free to make a pull request. All contributions are appreciated!

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].