{"id":15681699,"url":"https://github.com/nsweeting/keyword_validator","last_synced_at":"2025-05-07T09:47:42.171Z","repository":{"id":48309305,"uuid":"183300044","full_name":"nsweeting/keyword_validator","owner":"nsweeting","description":"Simple keyword validation for Elixir","archived":false,"fork":false,"pushed_at":"2025-04-25T15:39:52.000Z","size":50,"stargazers_count":10,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T16:33:53.201Z","etag":null,"topics":["elixir","elixir-lang","keyword-lists","validation"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/nsweeting.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}},"created_at":"2019-04-24T20:12:57.000Z","updated_at":"2025-04-25T15:39:36.000Z","dependencies_parsed_at":"2022-08-31T23:00:34.702Z","dependency_job_id":null,"html_url":"https://github.com/nsweeting/keyword_validator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fkeyword_validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fkeyword_validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fkeyword_validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fkeyword_validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsweeting","download_url":"https://codeload.github.com/nsweeting/keyword_validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252854538,"owners_count":21814701,"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":["elixir","elixir-lang","keyword-lists","validation"],"created_at":"2024-10-03T16:58:44.006Z","updated_at":"2025-05-07T09:47:42.151Z","avatar_url":"https://github.com/nsweeting.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KeywordValidator\n\n[![Build Status](https://travis-ci.org/nsweeting/keyword_validator.svg?branch=master)](https://travis-ci.org/nsweeting/keyword_validator)\n[![StatBuffer Version](https://img.shields.io/hexpm/v/keyword_validator.svg)](https://hex.pm/packages/keyword_validator)\n\nKeywordValidator provides a simple interface to validate keyword lists in Elixir.\n\n## Installation\n\nThe package can be installed by adding `keyword_validator` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:keyword_validator, \"~\u003e 2.0\"}\n  ]\nend\n```\n\n## Documentation\n\nPlease see [HexDocs](https://hexdocs.pm/keyword_validator) for additional documentation.\n\n## Getting Started\n\nTo begin validating, we must first create a schema that defines the rules for our\nkeyword list.\n\nA schema is a simple keyword list with each value representing the options available for validation.\n\nIf the validation passes, we are returned a valid keyword list.\n\n```elixir\niex\u003e keyword = [foo: :foo, bar: \"one\"]\niex\u003e schema = [\n  foo: [is: :atom, required: true],\n  bar: [is: {:in, [\"one\", \"two\", \"three\"]}]\n]\niex\u003e KeywordValidator.validate(keyword, schema)\n{:ok, [foo: :foo, bar: \"one\"]}\n```\n\nTo avoid additional schema validation - define your schemas as module attributes.\n\n```\n@opts_schema KeywordValidator.schema!([foo: [is: :integer]])\n```\n\nIf validation fails on any of the keys, a keyword list of the invalid entries and the\nassociated errors is returned.\n\n```elixir\niex\u003e keyword = [foo: \"foo\", bar: \"bar\"]\niex\u003e schema = [\n  foo: [is: :atom, required: true],\n  bar: [is: {:in, [\"one\", \"two\", \"three\"]}]\n]\niex\u003e KeywordValidator.validate(keyword, schema)\n{:error, [bar: [\"must be one of: [\\\"one\\\", \\\"two\\\", \\\"three\\\"]\"], foo: [\"must be a binary\"]]}\n```\n\nWe can optionally use the `KeywordValidator.validate!/2` function as well - which will raise\nan error that describes the invalid key entries.\n\n```elixir\n** (ArgumentError) Invalid keyword given.\n\nKeyword:\n\n[foo: :foo, bar: :bar]\n\nInvalid:\n\nbar: [\"must be one of: [:one, :two, :three]\"]\nfoo: [\"must be a binary\"]\n```\n\nTo view all the available validation options, please check out the [relevant documentation](https://hexdocs.pm/keyword_validator/KeywordValidator.html#validate/2).\n\nYou can optionally generate documentation from your schemas.\n\n```\n@doc \"\"\"\nThis is a function.\n\n## Options\n#{KeywordValidator.docs(@opts_schema)}\n\"\"\"\ndef my_function(opts) do\n  ...\nend\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fkeyword_validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsweeting%2Fkeyword_validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fkeyword_validator/lists"}