{"id":17159152,"url":"https://github.com/scull7/bs-validation","last_synced_at":"2025-07-26T08:31:46.660Z","repository":{"id":142121182,"uuid":"124812431","full_name":"scull7/bs-validation","owner":"scull7","description":"A BuckleScript implementation of the Folktale validation applicative","archived":false,"fork":false,"pushed_at":"2018-08-06T09:33:29.000Z","size":51,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T04:45:44.057Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","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/scull7.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2018-03-12T00:23:07.000Z","updated_at":"2020-06-20T15:43:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef622936-6305-4665-a643-a0c43951cfb9","html_url":"https://github.com/scull7/bs-validation","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"050e74381c80a520ef9b589c8e9c010b1ca9ab00"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scull7","download_url":"https://codeload.github.com/scull7/bs-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227663043,"owners_count":17800711,"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":[],"created_at":"2024-10-14T22:13:29.349Z","updated_at":"2024-12-02T03:07:17.602Z","avatar_url":"https://github.com/scull7.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://www.travis-ci.org/scull7/bs-validation.svg?branch=master)](https://www.travis-ci.org/scull7/bs-validation)\n[![Coverage Status](https://coveralls.io/repos/github/scull7/bs-validation/badge.svg?branch=master)](https://coveralls.io/github/scull7/bs-validation?branch=master)\n\n# bs-validation\nA BuckleScript implementation of the [Folktale][folktale]\n[validation][folktale-validation] applicative\n\n***NOTE:*** These are ***not*** bindings, this a ReasonML implementation of the\n`Validation` applicative.\n\n## Why?\nI wanted a way to do validations for my server side project.\n\n## Status\nNot all of the [Folktale/Validation][folktale-validation] functions will be\nimplemented. Here is a list of the currently implemented functions:\n\n* [x] map\n* [x] apply\n* [x] unsafeGet\n* [x] getOrElse\n* [x] orElse\n* [x] concat\n* [x] fold\n* [x] swap\n* [x] bimap\n* [x] mapFailure\n* [x] toOption\n* [ ] ~~merge~~ *see note in the code.*\n\nAll implemented functions are found in `src/Validation.re`, They are all\ndocumented with their [Folktale][folktale] style doc strings.\n\n## How do I install?\n1. Add the [bs-validation][npm-bs-validation] package to your project.\n  ```sh\n  yarn add bs-validation\n  ```\n2. Add `bs-validation` to your `bsconfig.json`\n  ```json\n  {\n    \"dependencies\": [ \"bs-validation\" ]\n  }\n  ```\n3. Enjoy!\n\n## Usage\n\nThe library is exposed as a functor which accepts modules that implement the\nfollowing type interface:\n```reason\nmodule type Foldable = {\n  type t('a);\n  let concat: (t('a), t('a)) =\u003e t('a);\n};\n```\n\nAll of the examples use an array based implementation of the `Foldable` type:\n```reason\nmodule FoldableArray = {\n  type t('a) = array('a);\n  let concat = (x, y) =\u003e Belt_Array.concat(x, y);\n};\n```\n\nYou import the module into your project by calling the `Validation` functor\nwith your version of the `Foldable` type.\n```reason\nmodule V = Validation.Make_validation(FoldableArray);\n```\n\nThen you can use it to validate all of your things!\n```reason\nlet lengthError = \"Password must have more than 6 characters.\";\nlet strengthError = \"Password must contain a special character.\";\n\nlet isPasswordLongEnough = (password) =\u003e\n  String.length(password) \u003e 6\n    ? V.Success(password)\n    : V.Failure([|lengthError|]);\n\nlet isPasswordStrongEnough = (password) =\u003e {\n  let regex = [%bs.re \"/[\\\\W]/\"];\n  Js.Re.test(password, regex)\n    ? V.Success(password)\n    : V.Failure([|strengthError|])\n};\n\nlet isPasswordValid = (password) =\u003e {\n  V.Success()\n  |\u003e V.concat(isPasswordLongEnough(password))\n  |\u003e V.concat(isPasswordStrongEnough(password))\n  |\u003e V.map((_) =\u003epassword)\n};\n\n\ndescribe(\"Folketale password validation example\", () =\u003e {\n  test(\"should return the password\", () =\u003e {\n    let password = \"rosesarered$andstuff\";\n    switch (isPasswordValid(password)) {\n    | Failure(f) =\u003e { Js.log(f); fail(\"unexpected_failure\") }\n    | Success(p) =\u003e Expect.expect(p) |\u003e Expect.toBe(password)\n    }\n  });\n\n  test(\"should return a single item failure\", () =\u003e {\n    let password = \"rosesarered\";\n    switch (isPasswordValid(password)) {\n    | Failure(f) =\u003e Expect.expect(f) |\u003e Expect.toBeSupersetOf([|strengthError|])\n    | Success(_) =\u003e fail(\"unexpected_success\")\n    }\n  });\n\n  test(\"should return 2 items in the failure list\", () =\u003e {\n    let password = \"foo\";\n    switch (isPasswordValid(password)) {\n    | Failure(f) =\u003e {\n        Expect.expect(f)\n        |\u003e Expect.toBeSupersetOf([|lengthError, strengthError|])\n      }\n    | Success(_) =\u003e fail(\"unexpected_success\")\n    }\n  });\n});\n```\n\n[folktale]: http://folktale.origamitower.com/\n[folktale-validation]: http://folktale.origamitower.com/api/v2.1.0/en/folktale.validation.html\n[npm-bs-validation]: https://www.npmjs.com/package/bs-validation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fbs-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscull7%2Fbs-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fbs-validation/lists"}