{"id":13741694,"url":"https://github.com/sporto/gleam-valid","last_synced_at":"2026-02-10T23:30:57.397Z","repository":{"id":142015741,"uuid":"304484701","full_name":"sporto/gleam-valid","owner":"sporto","description":"Validation library for Gleam","archived":false,"fork":false,"pushed_at":"2025-07-10T03:06:33.000Z","size":115,"stargazers_count":42,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-25T09:08:17.350Z","etag":null,"topics":["gleam","gleam-lang"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/valid","language":"Gleam","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sporto.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2020-10-16T01:07:45.000Z","updated_at":"2025-08-10T17:01:35.000Z","dependencies_parsed_at":"2025-05-21T21:33:30.548Z","dependency_job_id":"9558bf91-45e2-489a-be20-c5b1573d9a51","html_url":"https://github.com/sporto/gleam-valid","commit_stats":null,"previous_names":["sporto/gleam-valid","sporto/gleam-validator"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/sporto/gleam-valid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sporto%2Fgleam-valid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sporto%2Fgleam-valid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sporto%2Fgleam-valid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sporto%2Fgleam-valid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sporto","download_url":"https://codeload.github.com/sporto/gleam-valid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sporto%2Fgleam-valid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29321328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T20:44:44.282Z","status":"ssl_error","status_checked_at":"2026-02-10T20:44:43.393Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["gleam","gleam-lang"],"created_at":"2024-08-03T04:01:01.804Z","updated_at":"2026-02-10T23:30:57.390Z","avatar_url":"https://github.com/sporto.png","language":"Gleam","funding_links":[],"categories":["Packages"],"sub_categories":["Validation"],"readme":"# Valid\n\n![CI](https://github.com/sporto/gleam-valid/workflows/test/badge.svg?branch=main)\n\nA validation library for [Gleam](https://gleam.run/).\n\nAPI Docs: \u003chttps://hexdocs.pm/valid\u003e.\n\nThis library follows the principle [Parse don't validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/).\n\n## API\n\n```gleam\nimport valid\n\nfn user_validator(input: InputUser) {\n  use age \u003c- valid.check(input.age, valid.int_min(13, \"Should be at least 13\"))\n  use name \u003c- valid.check(input.name, valid.string_is_not_empty(\"Missing name\"))\n  use email \u003c- valid.check(input.email, valid.string_is_email(\"Missing email\"))\n\n  valid.ok(ValidUser(age:, name:, email:))\n}\n\nlet input = InputUser(age: 14, name: \"Sam\", email: \"sam@sample.com\")\n\nlet result = input\n |\u003e valid.validate(user_validator)\n\n result ==\n Ok(ValidUser(14, \"Sam\", \"sam@sample.com\"))\n```\n\n### Creating a custom validator\n\nA validator is a function that takes an input, and returns a tuple `#(output, errors)`.\n\nE.g.\n\n```gleam\nimport valid\n\nfn is_99(input) {\n  case input == 99 {\n    True -\u003e #(input, [])\n    False -\u003e #(0, [\"Not 99\"])\n  }\n}\n\nfn validator(input) {\n  use out \u003c- valid.check(input, is_99)\n  valid.ok(out)\n}\n```\n\nA validator must return a default value. This is so we can collect all the errors for all validators (instead of returning early).\n\n### Composing validators\n\nYou can use `then` two chain two validators:\n\n```gleam\nfn (input_name: Option(String)) {\n  use name \u003c- valid.check(\n    input_name,\n    valid.is_some(\"\", valid.ok, \"Input\")\n      |\u003e valid.then(valid.string_min_length(2, \"Size\")),\n  )\n\n  valid.ok(name)\n}\n```\n\n### Using own errors\n\nBy using your own errors you can add information to link to the source of the issue. e.g.\n\n```gleam\n\ntype Field {\n  FieldAge\n  FieldName\n  FieldEmail\n}\n\nfn user_validator(input: InputUser) {\n  use age \u003c- valid.check(input.age, valid.int_min(13, #(FieldAge,  \"Should be at least 13\")))\n  use name \u003c- valid.check(input.name, valid.string_is_not_empty(#(FieldName, \"Missing name\")))\n  use email \u003c- valid.check(input.email, valid.string_is_email(#(FieldEmail, \"Missing email\")))\n\n  valid.ok(ValidUser(age:, name:, email:))\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsporto%2Fgleam-valid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsporto%2Fgleam-valid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsporto%2Fgleam-valid/lists"}