{"id":20720212,"url":"https://github.com/zaaack/fable-validation","last_synced_at":"2025-09-06T19:39:02.846Z","repository":{"id":74324708,"uuid":"105499368","full_name":"zaaack/fable-validation","owner":"zaaack","description":"An isomorphic validation library for Fable/F#, inspired by elm-validate","archived":false,"fork":false,"pushed_at":"2017-11-25T04:17:37.000Z","size":289,"stargazers_count":49,"open_issues_count":2,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-01T08:20:54.180Z","etag":null,"topics":["elmish","fable","validation"],"latest_commit_sha":null,"homepage":"","language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zaaack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-10-02T04:54:19.000Z","updated_at":"2023-12-24T15:09:45.000Z","dependencies_parsed_at":"2023-06-03T02:00:29.250Z","dependency_job_id":null,"html_url":"https://github.com/zaaack/fable-validation","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zaaack/fable-validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaack%2Ffable-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaack%2Ffable-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaack%2Ffable-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaack%2Ffable-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zaaack","download_url":"https://codeload.github.com/zaaack/fable-validation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaaack%2Ffable-validation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273954922,"owners_count":25197575,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["elmish","fable","validation"],"created_at":"2024-11-17T03:19:39.500Z","updated_at":"2025-09-06T19:39:02.841Z","avatar_url":"https://github.com/zaaack.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fable.Validation\n\n[![Build Status](https://travis-ci.org/zaaack/fable-validation.svg \"Build Status\")](https://travis-ci.org/zaaack/fable-validation)\n[![NuGet version](https://badge.fury.io/nu/Fable.Validation.svg)](https://badge.fury.io/nu/Fable.Validation)\n\n## Install\n```sh\npaket add Fable.Validation\n```\nOR\n\n```sh\ndotnet add package Fable.Validation\n```\n\n## Usage\n\n### Example\n\n`all` is a validate function, it has a parameter to pass a callback with the only argument of a validator instance, you can write your validate rules and return the Ok value. `all` means validate all fields, if you want to return early after first error, you can use `fast`, there are also `allAsync`, `fastAsync` for async validate support.\n\n```F#\nopen System\nopen Fable.Core\nopen Fable.Core.JsInterop\nopen Fable.Core.Testing\nopen Fable.Validation.Core\n\ntype People = {\n    name: string\n    age: int\n}  with\n    static member Name = \"name\"\n    static member Age = \"age\"\n\nlet valid = { name=\"abcd\"; age=10 }\nlet result = all \u003c| fun t -\u003e\n\n    { name = t.Test People.Name valid.name // call `t.Test fieldName value` to initialize field state\n                |\u003e t.Trim // pipe the field state to rules\n                |\u003e t.NotBlank \"name cannot be blank\" // rules can contain params and a generic error message\n                |\u003e t.MaxLen 20 \"maxlen is {len}\"\n                |\u003e t.MinLen 4 \"minlen is {len}\"\n                |\u003e t.End // call `t.End` to unwrap the validated\n                         // and transformed value,\n                         // you can use the transformed values to create a new model\n\n      age = t.Test People.Age valid.age\n                |\u003e t.Gt 0 \"should greater then {min}\"\n                |\u003e t.Lt 200 \"shoudld less then {max}\"\n                |\u003e t.End }\n\nAssert.AreEqual (result, Ok(valid))\n\n// the result type is Result\u003c'T, 'E list\u003e\nlet result: Result\u003cPeople, string list\u003e = all \u003c| fun t -\u003e\n\n    { name = t.Test People.Name \"abc\"\n                |\u003e t.MaxLen 20 \"maxlen is 20\"\n                |\u003e t.MinLen 4 \"minlen is 4\"\n                |\u003e t.End\n      age = t.Test People.Age 201\n                |\u003e t.Gt 0 \"should greater then 0\"\n                |\u003e t.Lt 200 \"should less then 200\"\n                |\u003e t.End }\n\nAssert.AreEqual (result, Error(Map [ People.Name, [\"minlen is 4\"]\n                                     People.Age, [\"should less then 200\"] ]))\n\n// async validate example\n\nasync {\n    let valid = { name=\" abcd \"; age=10 }\n\n    let testNameAsync =\n        IsValidOptAsync\u003cstring, string, string\u003e \u003c| fun name -\u003e\n            async { return Valid (name.Trim()) }\n\n    // fast validation\n    let! result = fastAsync \u003c| fun t -\u003e\n        async {\n            let! name = t.Test People.Name valid.name\n                        |\u003e t.ToAsync\n                        |\u003e testNameAsync \"should be right\"\n                        |\u003e t.EndAsync\n\n            return { name = name\n                     age = t.Test People.Age valid.age\n                            |\u003e t.Gt 0 \"shoud greater then 0\"\n                            |\u003e t.Lt 200 \"should less then 200\"\n                            |\u003e t.End }\n        }\n\n    Assert.AreEqual (result, Ok({name=\"abcd\"; age=10}))\n} |\u003e Async.StartImmediately\n\n// validate single value\n\n// result is Ok(transformed input value) or Error(error list)\n// test single value don't need call `t.End`, because it will return as result.\nlet result: Result\u003cstring, string list\u003e = single \u003c| fun t -\u003e\n    t.TestOne \"Some Input\" |\u003e t.MinLen 10 \"minlen is 10\" |\u003e t.End\n\n```\n\n### Option/Result support\n\nThis library comes with Option/Result support in mind, you can unwrap it by validate rules like IsSome/IsOK, or skip following validation it if it's None/Error.\n\n```F#\nlet result: Result\u003cstring, string list\u003e = single \u003c| fun t -\u003e\n    t.TestOne (Some 1) |\u003e t.IsSome  \"should be some\" |\u003e t.Gt 0 \"should greater then 0\" |\u003e t.End\n\n// In this case you don't need to call t.End and rules are a list of rule,\n// it will return None if it's None and don't cause any error.\n// there are TestOneOnlySome/TestOneOnlyOk/TestOneOnlySomeAsync/TestOneOnlyOkAsync for single field test\n// and TestOnlySome/TestOnlyOk/TestOnlySomeAsync/TestOnlyOkAsync for multi fields test\nlet result: Result\u003cstring, string list\u003e = single \u003c| fun t -\u003e\n    t.TestOneOnlySome None [ t.Gt 0 \"should greater then 0\" ]\n```\n\n### Map/To\n\nIt's very easy to transform the input value to another type:\n\n* `t.Map` Lift the input value's type, it shouldn't throw error\n* `t.To` Parse the input value to another type, it could throw error.\n\n```F#\nlet result: Result\u003cint option, string list\u003e =\n    single (fun t -\u003e t.TestOne 1 |\u003e t.Map Some |\u003e t.End)\n\nlet result: Result\u003cint, string list\u003e =\n    single (fun t -\u003e t.TestOne \"123\" |\u003e t.To int \"cann't parse to int\" |\u003e t.End)\n```\n\nFor more you can see [API Reference](https://zaaack.github.io/fable-validation).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaaack%2Ffable-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaaack%2Ffable-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaaack%2Ffable-validation/lists"}