{"id":20307602,"url":"https://github.com/balance-platform/talos","last_synced_at":"2025-04-06T10:11:38.117Z","repository":{"id":45342767,"uuid":"222021515","full_name":"balance-platform/talos","owner":"balance-platform","description":"Elixir parameter validation library. Simple and extensible","archived":false,"fork":false,"pushed_at":"2025-01-20T16:12:15.000Z","size":305,"stargazers_count":25,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T08:12:44.784Z","etag":null,"topics":["elixir","forms","json","parameters","params-validate","params-validator","validate","validation"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/talos/Talos.html","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/balance-platform.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-15T23:51:25.000Z","updated_at":"2025-01-20T16:12:16.000Z","dependencies_parsed_at":"2024-12-16T13:29:49.067Z","dependency_job_id":"6b822ca7-3756-4902-873c-95bdf5780ffb","html_url":"https://github.com/balance-platform/talos","commit_stats":{"total_commits":97,"total_committers":10,"mean_commits":9.7,"dds":0.4639175257731959,"last_synced_commit":"69ea692c8d5894c5adf788ab0f9a08b6f8bd1623"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balance-platform%2Ftalos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balance-platform%2Ftalos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balance-platform%2Ftalos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balance-platform%2Ftalos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/balance-platform","download_url":"https://codeload.github.com/balance-platform/talos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247464222,"owners_count":20942970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","forms","json","parameters","params-validate","params-validator","validate","validation"],"created_at":"2024-11-14T17:18:25.315Z","updated_at":"2025-04-06T10:11:38.091Z","avatar_url":"https://github.com/balance-platform.png","language":"Elixir","readme":"# Talos\n\n[![hex.pm](https://img.shields.io/badge/docs-hexpm-blue.svg)](https://hexdocs.pm/talos)\n[![hex.pm](https://img.shields.io/hexpm/v/talos.svg)](https://hex.pm/packages/talos)\n[![hex.pm](https://img.shields.io/hexpm/dt/talos.svg)](https://hex.pm/packages/talos)\n[![hex.pm](https://img.shields.io/hexpm/l/talos.svg)](https://hex.pm/packages/talos)\n[![github.com](https://img.shields.io/github/last-commit/balance-platform/talos.svg)](https://github.com/balance-platform/talos/commits/master)\n![Elixir CI](https://github.com/balance-platform/talos/workflows/Elixir%20CI/badge.svg)\n\nTalos is simple parameters validation library\n\nDocumentation can be found at [ExDoc](https://hexdocs.pm/talos/)\n\n## Why another one validation library?\n\nI needed more checks than just whether the value belonged to a particular data type. \n\nThis library allows you to define your own checks and use typical checks with a simple setup.\n\n## Usage\n\n```elixir\n  defmodule CheckUserSignUp do\n    import Talos\n\n    @schema map(fields: [\n      field(key: \"action\", type: const(value: \"sign-up\")),\n      field(key: \"email\", type: string(min_length: 5, max_length: 255, regexp: ~r/.*@.*/)),\n      field(key: \"age\", type: integer(gteq: 18, allow_nil: true))\n    ])\n\n    def validate(%{} = map_data) do\n      params = Talos.permit(map_data)\n      errors = Talos.errors(@schema, params)\n\n      case errors == %{} do\n        true -\u003e {:ok, params}\n        false -\u003e {:error, errors}\n      end\n    end\n  end\n```\n\nSomewhere in UserController\n```elixir\n\n  ...\n\n  def sign_up(conn, params)\n    case CheckUserSignUp.valid?(params) do\n       :ok -\u003e \n          result = MyApp.register_user!(params)\n          render_json(%{\"ok\" =\u003e true | result})\n       {:error, errors} -\u003e \n          render_errors(errors)\n    end\n  end\n  \n  ...\n```\n\n## Flow\n\n![](/.github/images/main_steps.png)\n\n## Own Type definition\n\nIf you want define own Type, just create module with `Talos.Types` behavior\n\n```elixir\ndefmodule ZipCodeType do\n  @behaviour Talos.Types\n  defstruct [length: 6]\n\n  def valid?(%__MODULE__{length: len}, value) do\n    String.valid?(value) \u0026\u0026 String.match?(value, ~r/\\d{len}/)\n  end\n\n  def errors(__MODULE__, value) do\n    case valid?(__MODULE__,value) do\n      true -\u003e []\n      false -\u003e [\"#{value} is not zipcode\"]\n    end\n  end\nend\n\n# And use it\n\nTalos.valid?(%ZipCodeType{}, \"123456\") # =\u003e true\nTalos.valid?(%ZipCodeType{}, \"1234\") # =\u003e false\nTalos.valid?(%ZipCodeType{}, 123456) # =\u003e false\n```\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:talos, \"~\u003e 1.12\"}\n  ]\nend\n```\n\n# Contribution\n\nFeel free to make a pull request. All contributions are appreciated!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalance-platform%2Ftalos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbalance-platform%2Ftalos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalance-platform%2Ftalos/lists"}