# hosts-parser

> hosts file parser

Latest version **0.3.2** (published 2015-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install hosts-parser
pnpm add hosts-parser
yarn add hosts-parser
bun add hosts-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2015-11-24 |
| First published | 2015-01-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | yelo |
| Maintainers | yelo |
| Keywords | hosts, parser |

## Links

- npm: https://www.npmjs.com/package/hosts-parser
- Repository: https://github.com/imyelo/hosts-parser
- Issues: https://github.com/imyelo/hosts-parser/issues
- npm.io page: https://npm.io/package/hosts-parser

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^3.0.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2015-11-24
- 0.3.1 — 2015-05-13
- 0.3.0 — 2015-02-01
- 0.2.0 — 2015-02-01
- 0.1.0 — 2015-01-31

## README

# hosts-parser
hosts file parser

[![Build Status](https://travis-ci.org/imyelo/hosts-parser.svg?branch=master)](https://travis-ci.org/imyelo/hosts-parser)

## Usage
```javascript
var fs = require('fs');
var Hosts = require('hosts-parser').Hosts;
var hosts = new Hosts(fs.readFileSync('/etc/hosts', 'utf8'));
console.log(hosts.toJSON());
/**
[
    {
        "ip": "127.0.0.1",
        "hostname": "localhost"
    }
]
**/
console.log(hosts.resolve('localhost'));
// 127.0.0.1
```

## API
### Hosts(hosts) and Hosts.prototype.parse(hosts)
```javascript
var file = fs.readFileSync('/etc/hosts', 'utf-8');
var hosts = new Hosts(file);
// or (new Hosts()).parse(file);
// return a parsed Hosts object
```

### Hosts.prototype.resolve(hostname)
```javascript
hosts.resolve(hostname);
// return the ip or undefined
```

### Hosts.prototype.reverse(ip)
```javascript
hosts.reverse(ip);
// return the hostname or undefined
```

### Hosts.prototype.reverse(ip, callback)
```javascript
hosts.reverse(ip, function (err, hostname) {
  // pass the hostname or a NotFound Error
});
```

### Hosts.prototype.toJSON()
```javascript
hosts.toJSON();
// return a json formatted object
```

## What is the Hosts file
[hosts (file)](http://en.wikipedia.org/wiki/Hosts_%28file%29)

## License
the MIT License.

---
_Source: https://npm.io/package/hosts-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
