{"id":28278923,"url":"https://github.com/aaronius/get-apex-domain","last_synced_at":"2025-10-26T18:15:41.313Z","repository":{"id":37952372,"uuid":"222178848","full_name":"Aaronius/get-apex-domain","owner":"Aaronius","description":"Returns the apex domain (aka base, bare, naked, root apex, or zone apex domain) of the current web page without the use of a public suffix list. The apex domain is also the top-most domain that allows for setting cookies.","archived":false,"fork":false,"pushed_at":"2023-03-02T05:36:37.000Z","size":539,"stargazers_count":9,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-21T08:19:25.848Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/Aaronius.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-11-17T00:54:44.000Z","updated_at":"2024-03-31T21:46:24.000Z","dependencies_parsed_at":"2023-02-03T03:02:04.661Z","dependency_job_id":null,"html_url":"https://github.com/Aaronius/get-apex-domain","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Aaronius/get-apex-domain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aaronius%2Fget-apex-domain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aaronius%2Fget-apex-domain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aaronius%2Fget-apex-domain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aaronius%2Fget-apex-domain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aaronius","download_url":"https://codeload.github.com/Aaronius/get-apex-domain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aaronius%2Fget-apex-domain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259763102,"owners_count":22907413,"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":"2025-05-21T08:17:46.027Z","updated_at":"2025-10-04T04:52:46.889Z","avatar_url":"https://github.com/Aaronius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# get-apex-domain\n\nReturns the apex domain (aka base, bare, naked, root apex, or zone apex domain) of the current web page without the use of a public suffix list. The apex domain is also the top-most domain that allows for setting cookies.\n\nBecause of the methodology used, this library is very small.\n\n## What's an apex domain?\n\nAn apex domain is the longest portion of a domain that does not contain a subdomain. In the case of `store.example.co.uk`, `example.co.uk` would be the apex domain.\n\nWhen a website owner attempts to register a domain name, they cannot register a domain matching an effective top-level domain (e.g., `com`, `co.uk`) due to restrictions controlled by registrars. However, domains ending in an effective top-level domain are allowed (e.g., `example.com`, `example.co.uk`). **This is the apex domain.** The domain name owner can then create subdomains ending in the domain they registered (e.g., `store.example.com`, `store.example.co.uk`), but subdomains are not apex domains.\n\n## Requirements\n\nThis will only work in a browser and cookies must be enabled.\n\n## How detection is accomplished\n\nAs it turns out, browsers allow websites to set cookies for apex domains (e.g., `example.co.uk`) but not top-level domains (e.g., `uk`) or effective top-level domains (e.g., `co.uk`).\n\nConsidering a hostname of `store.example.co.uk`, we can determine the apex domain by attempting to write a cookie on `uk`, then `co.uk`, then `example.co.uk`, then `store.example.co.uk`, until we succeed in writing a cookie. In this case, the first attempt that will succeed is `example.co.uk`. This is the apex domain.\n\n## Installation\n\nIf you use npm for package management, you can install `get-apex-domain` by running the following command from within your project's directory:\n\n```\nnpm install get-apex-domain\n```\n\n## Usage\n\n```javascript\nimport getApexDomain from \"get-apex-domain\";\n\nconsole.log(getApexDomain());\n```\n\nIf cookies are not enabled, an error will be thrown.\n\nThe `localhost` hostname presents a unique case. If the hostname is `localhost`, the returned apex domain will be `undefined`.\n\n## Related Packages\n\nSee [get-etld](https://www.npmjs.com/package/get-etld) if you'd like to retrieve the effective top-level domain (eTLD).\n\n## Special Recognition\n\nFull credit goes to [Joe Khoury](https://github.com/jfkhoury) for devising the strategy used to determine the apex domain.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronius%2Fget-apex-domain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronius%2Fget-apex-domain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronius%2Fget-apex-domain/lists"}