{"id":20396870,"url":"https://github.com/thelocalcoder/deno-hosts","last_synced_at":"2026-04-20T06:32:24.116Z","repository":{"id":54265224,"uuid":"343083909","full_name":"thelocalcoder/deno-hosts","owner":"thelocalcoder","description":"The hosts file parsing and resolver module for Deno","archived":false,"fork":false,"pushed_at":"2021-03-19T13:00:23.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T02:25:47.735Z","etag":null,"topics":["deno","hostname","hostsfile"],"latest_commit_sha":null,"homepage":"https://thelocalcoder.github.io/deno-hosts","language":"TypeScript","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/thelocalcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-28T11:06:19.000Z","updated_at":"2021-03-21T12:18:46.000Z","dependencies_parsed_at":"2022-08-13T10:21:05.562Z","dependency_job_id":null,"html_url":"https://github.com/thelocalcoder/deno-hosts","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/thelocalcoder/deno-hosts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thelocalcoder%2Fdeno-hosts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thelocalcoder%2Fdeno-hosts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thelocalcoder%2Fdeno-hosts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thelocalcoder%2Fdeno-hosts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thelocalcoder","download_url":"https://codeload.github.com/thelocalcoder/deno-hosts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thelocalcoder%2Fdeno-hosts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32036373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","hostname","hostsfile"],"created_at":"2024-11-15T04:10:07.695Z","updated_at":"2026-04-20T06:32:24.095Z","avatar_url":"https://github.com/thelocalcoder.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🦖 Deno-Hosts\n\n\n[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/deno_hosts)\n\n\n**The hosts file parsing and resolver module for Deno**\n\n\nDeno-Hosts is a Deno (Typescript) module for parsing hosts files and performing reverse IP -\u003e hostname or vice versa lookups which are file or text data based (e.g. via `/etc/hosts`).\n\nThis can be helpful to determine if there is a prettier (or known) hostname available for an IP address.\n\nThese lookups are \"extremely inexpensive\" compared to normal IP reverse DNS lookups because no network communication is required, as these lookups are all file-based (offline)! Naturally, the (obvious) tradeoff/downside is that this only works in cases where the IP mapping exists in the hostsfile.\n\n\n## Usages\n\n```javascript\nimport Hosts from 'https://deno.land/x/deno_hosts@v1.0.1/mod.ts';\n\nconst hostsPath = \"/etc/hosts\";  // Hosts file path\n\nconst hosts = new Hosts(Deno.readTextFileSync(hostsPath));\n\nconsole.log(hosts.toObject());\n```\n\n\n### Output\n\n```json\n[\n    {\n        \"ip\": \"127.0.0.1\",      \n        \"hostname\": \"localhost\",\n        \"alias\": null\n    },\n    {\n        \"ip\": \"127.0.1.1\",\n        \"hostname\": \"local.test\",\n        \"alias\": \"local\"\n    }\n]\n```\n\n\n## Deno Registry Links\n\n- [Nest.land -\u003e deno_hosts](https://nest.land/package/deno_hosts)\n- [Deno.land -\u003e deno_hosts](https://deno.land/x/deno_hosts)\n\n**Usages from Nest.land**\n\n```javascript\nimport Hosts from 'https://x.nest.land/deno_hosts@2.0.0/mod.ts';\n```\n\n**Usages from Deno.land**\n\n```javascript\nimport Hosts from 'https://deno.land/x/deno_hosts/mod.ts'; // Latest version\n```\n\n```javascript\nimport Hosts from 'https://deno.land/x/deno_hosts@v1.0.1/mod.ts' // Specific Version\n```\n\n\n## API\n\n- **hosts.toObject()** - For geeting JSON from hosts file.\n- **hosts.toText()** - Re-convert text from parsed hosts file.\n- **hosts.resolve(hostname : string)** - Lookup hostname -\u003e IP (Return `undefined` in case of not found).\n- **hosts.reverse(ip : string)** - Lookup IP -\u003e hostname (Return `undefined` in case of not found).\n- **hosts.match(str: string)** - Lookup and match ip/hostname/alias and return a Host object.\n\n\n```javascript\ntype Host = {\n    ip: string,\n    hostname: string,\n    alias: string | null\n}\n```\n\n```javascript\nclass Hosts {\n    constructor(hosts : string) : Object\u003cHosts\u003e\n    toObject() : Hosts[]\n    toText() : string\n    resolve(hostname : string) : string | undefined\n    reverse(ip: string) : string | undefined\n    match(str : string) : Host | undefined\n}\n```\n\n\n**Note:** Hosts file location depends on OS. So use according your OS and for checking run time env OS use `Deno.build` stable API.\n\n- Windows - `C:/Windows/System32/drivers/etc/hosts`\n- Linux - `/etc/hosts`\n- Mac OS X - `/private/etc/hosts`\n\n\n## ToDo\n\n- [x] Write Test cases.\n- [ ] Write JSDoc for class methods.\n- [x] Write Inital Readme content.\n- [ ] Write HowTo Guide.\n- [x] Publish at Deno.land\n- [x] Publish at Nest.land\n- [ ] Setup auto Testing using Travis CI\n\n\n## References\n\n1. [What is hosts file (wiki)](https://en.wikipedia.org/wiki/Hosts_%28file%29)\n2. [hosts-parser](https://github.com/imyelo/hosts-parser)\n3. [go-hostsfile](https://github.com/jaytaylor/go-hostsfile)\n\n\n## License\n\nPermissive MIT license.\n\n\n## Contact\n\nYou are more than welcome to open issues and send pull requests if you find a bug or want a new feature.\n\nIf you appreciate this module please feel free to drop me a line and tell me! It's always nice to hear from people who have benefitted from my work.\n\nEmail: [hello (at) ganeshagrawal.com](mailto:hello@ganeshagrawal.com)\n\nTwitter: [@imganeshagrawal](https://twitter.com/imganeshagrawal)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthelocalcoder%2Fdeno-hosts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthelocalcoder%2Fdeno-hosts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthelocalcoder%2Fdeno-hosts/lists"}