{"id":13722262,"url":"https://github.com/erlangbureau/liver","last_synced_at":"2025-04-19T15:16:40.007Z","repository":{"id":72282773,"uuid":"111549044","full_name":"erlangbureau/liver","owner":"erlangbureau","description":"Lightweight Erlang validator based on LIVR specification","archived":false,"fork":false,"pushed_at":"2024-04-04T15:14:56.000Z","size":142,"stargazers_count":37,"open_issues_count":3,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-14T11:39:58.807Z","etag":null,"topics":["erlang","json","livr","validator"],"latest_commit_sha":null,"homepage":"","language":"Erlang","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/erlangbureau.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-21T12:56:40.000Z","updated_at":"2024-09-19T02:26:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"93bef9db-9fc6-4f67-be4a-59a7a8faefc6","html_url":"https://github.com/erlangbureau/liver","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangbureau%2Fliver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangbureau%2Fliver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangbureau%2Fliver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangbureau%2Fliver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erlangbureau","download_url":"https://codeload.github.com/erlangbureau/liver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224958561,"owners_count":17398500,"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":["erlang","json","livr","validator"],"created_at":"2024-08-03T01:01:26.594Z","updated_at":"2025-04-19T15:16:40.000Z","avatar_url":"https://github.com/erlangbureau.png","language":"Erlang","funding_links":[],"categories":["General Libraries"],"sub_categories":[],"readme":"# Liver\n[![Build Status](https://github.com/erlangbureau/liver/actions/workflows/ci.yml/badge.svg)](https://github.com/erlangbureau/liver/actions)\n[![Coverage Status](https://coveralls.io/repos/github/erlangbureau/liver/badge.svg?branch=master)](https://coveralls.io/github/erlangbureau/liver?branch=master)\n\n## Summary\n[![Logo](https://upload.wikimedia.org/wikipedia/commons/d/d4/Liver.svg)]()\n\nLiver is a lightweight Erlang validator based on LIVR Specification (See http://livr-spec.org for details)\n\n## Table of Contents\n* [Description](#description)\n* [Geting Started](#geting-started)\n* [Usage Examples](#usage-examples)\n* [Exports](#exports)\n* [License](#license)\n\n## \u003ca name='description'\u003e\u003c/a\u003eDescription\n**LIVR specification features:**\n\n1. Rules are declarative and language independent\n2. Any number of rules for each field\n3. Validator should return together errors for all fields\n4. Exclude all fields that do not have validation rules described\n5. Possibility to validate complex hierarchical structures\n6. Easy to describe and understand validation\n7. Returns understandable error codes (neither error messages nor numeric codes)\n8. Easy to implement own rules (usually you will have several in every project)\n9. Rules should be able to change results output (\"trim\", \"nested_object\", for example)\n10. Multipurpose (user input validation, configs validation, contracts programming etc)\n11. Unicode support\n\n**This implementation specific features:**\n1. Strict Mode (returns errors on all fields that do not have validation rules)\n2. Support on-the-fly conversion from proplist to map and vice versa\n3. Support list as root element, what is missing in the original specification\n4. Support on-the-fly conversion keys from string to atom\n5. Ability to return custom error codes\n6. Additional set of strict rules (without implicit conversion of types)\n\n\n\n## \u003ca name='geting-started'\u003e\u003c/a\u003eGeting Started\n1. Add as a dependency in your project:\n  * For **rebar** add to rebar.config\n  ```erl\n{deps, [\n    {liver, \".*\",\n        {git, \"https://github.com/erlangbureau/liver.git\", {branch, \"0.9.0\"}}\n    }\n]}.\n```\n\n  * For **erlang.mk** add to make file:\n```erl\nDEPS = liver\ndep_liver = git https://github.com/erlangbureau/liver.git 0.9.0\n```\n\n2. Add liver in **your_project.app.src** file in tuple **applications**:\n```erl\n    {applications, [\n        kernel,\n        stdlib,\n        liver\n    ]},\n```\n3. Thats all, now you can validate data, register your own rules or add aliases for built-in rules.\n\n## \u003ca name='usage-examples'\u003e\u003c/a\u003eUsage Examples\n\nExample of simple validation for object (map or proplist):\n```erl\n1\u003e Schema1 = [{\u003c\u003c\"first_name\"\u003e\u003e,[{length_between,[4,6]}]}].\n\n2\u003e Input1 =  [{\u003c\u003c\"first_name\"\u003e\u003e,\u003c\u003c\"Vasya\"\u003e\u003e}].\n\n3\u003e liver:validate(Schema1, Input1).\n{ok, [{\u003c\u003c\"first_name\"\u003e\u003e,\u003c\u003c\"Vasya\"\u003e\u003e}]}\n\n4\u003e Schema2 = [{\u003c\u003c\"number1\"\u003e\u003e,integer}].\n\n5\u003e Input2 =  [{\u003c\u003c\"number1\"\u003e\u003e,-1.12}].\n\n6\u003e liver:validate(Schema2, Input2).\n{error,[{\u003c\u003c\"number1\"\u003e\u003e,\u003c\u003c\"NOT_INTEGER\"\u003e\u003e}]}\n```\n\nExample of simple validation for list:\n```erl\n1\u003e Schema = [{nested_object, #{pool_name =\u003e [required, is_atom]}}].\n\n2\u003e liver:validate(Schema, [[{pool_name, test1}], [{pool_name, test2}]], #{return =\u003e map}).\n{ok,[#{pool_name =\u003e test1},#{pool_name =\u003e test2}]}\n\n3\u003e liver:validate(Schema, [[{pool_name, test1}], [{pool_nam, test2}]], #{return =\u003e map}).\n{error,[null,#{pool_name =\u003e \u003c\u003c\"REQUIRED\"\u003e\u003e}]}\n```\n\nExample of more complex validation for object (map or proplist):\n```erl\n7\u003e Schema = #{\n    \u003c\u003c\"address\"\u003e\u003e =\u003e [required, {nested_object, #{\n        \u003c\u003c\"country\"\u003e\u003e =\u003e [required,{one_of,[[\u003c\u003c\"Ukraine\"\u003e\u003e,\u003c\u003c\"USA\"\u003e\u003e]]}],\n        \u003c\u003c\"zip\"\u003e\u003e =\u003e positive_integer,\n        \u003c\u003c\"street\"\u003e\u003e =\u003e required,\n        \u003c\u003c\"building\"\u003e\u003e =\u003e [required,positive_integer]\n    }}]\n}.\n\n8\u003e Input = #{\n    \u003c\u003c\"address\"\u003e\u003e =\u003e #{\n        \u003c\u003c\"country\"\u003e\u003e =\u003e \u003c\u003c\"Ukraine\"\u003e\u003e,\n        \u003c\u003c\"zip\"\u003e\u003e =\u003e \u003c\u003c\"12345\"\u003e\u003e,\n        \u003c\u003c\"street\"\u003e\u003e =\u003e \u003c\u003c\"10\"\u003e\u003e,\n        \u003c\u003c\"building\"\u003e\u003e =\u003e \u003c\u003c\"10\"\u003e\u003e,\n        \u003c\u003c\"extra_field\"\u003e\u003e =\u003e \u003c\u003c\"will be removed\"\u003e\u003e\n    },\n    \u003c\u003c\"extra_field\"\u003e\u003e =\u003e \u003c\u003c\"will be removed\"\u003e\u003e\n}.\n\n9\u003e liver:validate(Schema, Input).\n{ok,#{\u003c\u003c\"address\"\u003e\u003e =\u003e #{\u003c\u003c\"building\"\u003e\u003e =\u003e 10,\n        \u003c\u003c\"country\"\u003e\u003e =\u003e \u003c\u003c\"Ukraine\"\u003e\u003e,\n        \u003c\u003c\"street\"\u003e\u003e =\u003e \u003c\u003c\"10\"\u003e\u003e,\n        \u003c\u003c\"zip\"\u003e\u003e =\u003e 12345}}}\n```\n\nExample of strict validation (fields that are not specified in the scheme are forbidden):\n```erl\n10\u003e liver:validate(Schema, Input, [{strict, true}]).\n{error,#{\u003c\u003c\"address\"\u003e\u003e =\u003e #{\u003c\u003c\"extra_field\"\u003e\u003e =\u003e \u003c\u003c\"UNKNOWN_FIELD\"\u003e\u003e},\n         \u003c\u003c\"extra_field\"\u003e\u003e =\u003e \u003c\u003c\"UNKNOWN_FIELD\"\u003e\u003e}}\n```\n## \u003ca name='exports'\u003e\u003c/a\u003eExports\n\n### `validate/2`\n\n```erlang\nvalidate(Schema, Input) -\u003e {ok, Output} | {error, ErrorList}\n\n  Schema, Input, Output, ErrorList = proplist() | map()\n```\n  Equivalent to `validate(Schema, Input, []).`\n\n### `validate/3`\n\n```erlang\nvalidate(Schema, Input, Opts) -\u003e {ok, Output} | {error, ErrorList}\n\n  Schema, Input, Output, ErrorList, Opts = proplist() | map()\n```\nParameter Opts is a proplist or map that specifies return type and validation strictness. Default values are used for omitted options. This means that not specifying any options `([])` is the same as specifying `[{return, as_is}, {strict, false}]`.\n\n`{return, ReturnType}`\n\nIf set to `as_is` the type of `Output` wiil be the same as type of `Input`. If set to `map` the `Output` will be map. If set to `proplist` the `Output` will be proplist. Defaults to `as_is`\n\n`{strict, boolean()}`\n\nIf set to `false` deletes from `Input` all fields that not defined in `Schema`. Or if set to `true` and `Input` has fields that not defined in `Schema` returns error. Defaults to `false`\n\n## \u003ca name='license'\u003e\u003c/a\u003eLicense\n\nLiver is released under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferlangbureau%2Fliver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferlangbureau%2Fliver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferlangbureau%2Fliver/lists"}