{"id":20481904,"url":"https://github.com/typeable/validationt","last_synced_at":"2025-04-13T14:11:22.918Z","repository":{"id":56504192,"uuid":"91562442","full_name":"typeable/validationt","owner":"typeable","description":"Straightforward validation monad. Convenient for validating web forms and APIs.","archived":false,"fork":false,"pushed_at":"2024-01-08T09:32:46.000Z","size":34,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-04-25T01:08:22.143Z","etag":null,"topics":["web"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/typeable.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}},"created_at":"2017-05-17T10:06:19.000Z","updated_at":"2024-01-03T15:56:20.000Z","dependencies_parsed_at":"2024-01-08T11:06:46.747Z","dependency_job_id":"71ba63b8-1f8c-4f54-a5b2-92bb3569f3c1","html_url":"https://github.com/typeable/validationt","commit_stats":{"total_commits":39,"total_committers":3,"mean_commits":13.0,"dds":0.5641025641025641,"last_synced_commit":"83e415e43fb821930d9a387ed1f4e5b12495df65"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeable%2Fvalidationt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeable%2Fvalidationt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeable%2Fvalidationt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeable%2Fvalidationt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typeable","download_url":"https://codeload.github.com/typeable/validationt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724629,"owners_count":21151561,"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":["web"],"created_at":"2024-11-15T16:10:14.420Z","updated_at":"2025-04-13T14:11:22.898Z","avatar_url":"https://github.com/typeable.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Travis CI Badge](https://img.shields.io/travis/typeable/validationt)\n\n# ValidationT\n\nA simple data validation library. The main idea is to provide an easy way to\nvalidate web form data by aggregating errors for each field.\n\n## Usage\n\nSuppose you want to validate some data from the user. Say, that the password adheres to some rules.\n\nYou might do something like this:\n\n```haskell\nvalidatePassword :: Monad m =\u003e String -\u003e ValidationT [String] m ()\nvalidatePassword password = do\n  vLength password\n  vAlpha password\n  vNum password\n  where\n    vLength p = when (length p \u003c 8)\n      $ vWarning [\"The password should be at least 8 characters long.\"]\n    vAlpha p = unless (any isAlpha p)\n      $ vWarning [\"The password should contain at least one alphabetic character.\"]\n    vNum p = unless (any isDigit p)\n      $ vWarning [\"The password should contain at least one numeric character.\"]\n```\n\n`ValidationT e m a` essentially just gathers the errors thrown by `vWarning`.\n\n```haskell\nvWarning :: (Monad m, Monoid e) =\u003e e -\u003e ValidationT e m ()\n```\n\n`vWarning` `mappend`s the given `e` to the already collected errors. This is why the warnings are contained inside a list.\n\nThere is also `vError`. The only difference between `vWarning` and `vError` is that `vError` stops further execution (and further collection of errors and warnings).\n\nYou would use the validation like this:\n\n```haskell\nmain :: IO ()\nmain = do\n  password \u003c- getLine\n  result \u003c- runValidationTEither . validatePassword $ password\n  putStrLn $ case result of\n    Left errs -\u003e unlines err\n    Right () -\u003e \"You are fine.\"\n```\n\nYou could, of course, do more complicated things like use `vWarningL` and `vErrorL` to add an error to a `mempty` structure, which gets `mappend`ed with other errors.\n\nThe library comes with a `MonoidMap` `newtype` wrapper around `Map`, which `mappend`s the values themselves on conflict. This can be useful if you have a multiple points of failure and you want to distinguich between them -- validating a username and a password for example:\n\n```haskell\ndata Piece\n  = Password\n  | UserName\n  deriving (Eq, Show, Ord)\n\nvalidatePassword :: Monad m =\u003e String -\u003e ValidationT (MonoidMap Piece [String]) m ()\nvalidatePassword password = do\n  vLength password\n  vAlpha password\n  vNum password\n  where\n    warning = mmSingleton UserName\n    vLength p = when (length p \u003c 8)\n      $ warning [\"The password should be at least 8 characters long.\"]\n    vAlpha p = unless (any isAlpha p)\n      $ warning [\"The password should contain at least one alphabetic character.\"]\n    vNum p = unless (any isDigit p)\n      $ warning [\"The password should contain at least one numeric character.\"]\n```\n\n(`mmSingleton` is a covenience initializer for `MonoidMap`.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeable%2Fvalidationt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypeable%2Fvalidationt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeable%2Fvalidationt/lists"}