{"id":16326627,"url":"https://github.com/izolate/agegate","last_synced_at":"2025-03-20T22:31:48.717Z","repository":{"id":30389471,"uuid":"33942158","full_name":"izolate/agegate","owner":"izolate","description":"A simple function that verifies a date of birth against a country's legal drinking age.","archived":false,"fork":false,"pushed_at":"2022-03-27T19:28:26.000Z","size":430,"stargazers_count":16,"open_issues_count":5,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T18:21:47.830Z","etag":null,"topics":["age-gate","countries","country-data"],"latest_commit_sha":null,"homepage":"https://izolate.github.io/agegate/","language":"JavaScript","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/izolate.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}},"created_at":"2015-04-14T16:03:00.000Z","updated_at":"2021-08-07T14:10:41.000Z","dependencies_parsed_at":"2022-09-07T21:12:39.337Z","dependency_job_id":null,"html_url":"https://github.com/izolate/agegate","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izolate%2Fagegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izolate%2Fagegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izolate%2Fagegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izolate%2Fagegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izolate","download_url":"https://codeload.github.com/izolate/agegate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244703940,"owners_count":20496209,"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":["age-gate","countries","country-data"],"created_at":"2024-10-10T23:09:04.805Z","updated_at":"2025-03-20T22:31:48.441Z","avatar_url":"https://github.com/izolate.png","language":"JavaScript","readme":"# Agegate\n\nA simple function that verifies a date of birth against a country's legal drinking age.\n\n```\nnpm i agegate\n```\n\n## Usage\n\n```js\nimport agegate from \"agegate\";\n\nvar user = {\n  dateOfBirth: new Date(\"2015-02-14\"), // strings are also accepted\n  country: \"US\",\n};\n\nvar isLegal = agegate(user.dateOfBirth, user.country); // false\n```\n\n:warning: If an invalid date is supplied, the result will be falsy. If an invalid country code is supplied, it will validate against a default legal drinking age of 18.\n\n### Use with frameworks (e.g. React)\n\nIn order to use this library with frontend UI frameworks, the underlying dataset used to validate is also exported.\n\n```js\nimport React, { useState } from \"react\";\nimport agegate, { getData } from \"agegate\";\n\nconst countries = getData();\n\nfunction Modal() {\n  const [date, setDate] = useState(\"\");\n  const [country, setCountry] = useState(countries[0].code);\n  const [legal, setLegal] = useState(false);\n\n  const submitHandler = e =\u003e {\n    e.preventDefault();\n\n    if (date \u0026\u0026 country) {\n      const result = agegate(new Date(date), country);\n      setLegal(result);\n    }\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cform onSubmit={submitHandler}\u003e\n        \u003ch3\u003eEnter your date of birth\u003c/h3\u003e\n        \u003cinput\n          type=\"date\"\n          value={date}\n          onChange={e =\u003e setDate(e.target.value)}\n        /\u003e\n\n        \u003ch3\u003eEnter your country\u003c/h3\u003e\n        \u003cselect value={country} onChange={e =\u003e setCountry(e.target.value)}\u003e\n          {countries.map(({ code, name }) =\u003e (\n            \u003coption key={name} value={code}\u003e\n              {name}\n            \u003c/option\u003e\n          ))}\n        \u003c/select\u003e\n\n        \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n      \u003c/form\u003e\n\n      \u003cp style={{ color: legal ? \"green\" : \"red\" }}\u003e\n        RESULT: You are {legal ? \"\" : \"NOT\"} old enough!\n      \u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n* * *\n\nPlease file a [new issue](https://github.com/izolate/agegate/issues/new) if you find any inconsistencies in the countries dataset.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizolate%2Fagegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizolate%2Fagegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizolate%2Fagegate/lists"}