# zonefile-pegjs

> A PEG.js grammar for parsing zonefile DNS configuration

Latest version **1.0.1** (published 2015-12-29) · AGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install zonefile-pegjs
pnpm add zonefile-pegjs
yarn add zonefile-pegjs
bun add zonefile-pegjs
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-12-29 |
| First published | 2015-12-26 |
| Weekly downloads | 0 |
| License | AGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | olizilla |
| Maintainers | olizilla |
| Keywords | dns, zonefile, resource, records, peg, grammar |

## Links

- npm: https://www.npmjs.com/package/zonefile-pegjs
- Repository: https://github.com/tableflip/zonefile-pegjs
- Homepage: https://github.com/tableflip/zonefile-pegjs#readme
- Issues: https://github.com/tableflip/zonefile-pegjs/issues
- npm.io page: https://npm.io/package/zonefile-pegjs

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-12-29
- 1.0.0 — 2015-12-28
- 0.2.0 — 2015-12-28
- 0.1.0 — 2015-12-26

## README

# zonefile-pegjs

A PEG.js grammar for parsing zonefile DNS configuration to JSON. Handles **multi-line SOA and TXT records**, as well as **SRV, MX, CNAME, NS, AAAA, A** and friends.

See **[zonefile.pegjs](https://github.com/tableflip/zonefile-pegjs/blob/master/zonefile.pegjs)** for the magic. You can try it out by pasting it into the PEG.js web dingus: http://pegjs.org/online

Derived from, and with thanks to, **Pro DNS and BIND by Ron Aitchison**.
See: http://www.zytrax.com/books/dns/ch8/

## Install

```sh
npm install zonefile-pegjs
```

## Usage

Use [pegjs](https://www.npmjs.com/package/pegjs) to build the parser, or use [pegjs-require](https://www.npmjs.com/package/pegjs-require) to `require` the grammar file directly:

```js
require('pegjs-require')
var parser = require('zonefile-pegjs')
parser.parse('tableflip.io. 21599 IN A 178.62.82.182')
// { origin: null, ttl: null, records:[ { name:'tableflip.io.', ttl: '21599', type:'A', data: '178.62.82.182' } ] }
```

## Example

[**example.js**](https://github.com/tableflip/zonefile-pegjs/blob/master/test/example.js)

```js
var fs = require('fs')
var test = require('tape')
var pegjs = require('pegjs-require')

test('Parse zonefile for example.org.', function (t) {
  var zone = fs.readFileSync(__dirname  + '/example.zone', 'utf8')
  var parser = require('../zonefile.pegjs')
  var actual = parser.parse(zone)
  var expected = require('./example.json')
  t.deepEquals(actual, expected, 'Most excellent: Parser generates expected output for example.org.')
  t.end()
})
```

So given a zonefile like: [**example.zone**](https://github.com/tableflip/zonefile-pegjs/blob/master/test/example.zone)

```zonefile
; zone file for example.org
$TTL 2d    ; 172800 secs default TTL for zone
$ORIGIN example.org.
@             IN      SOA   ns1.example.org. hostmaster.example.org. (
                        2003080800 ; se = serial number
                        12h        ; ref = refresh
                        15m        ; ret = update retry
                        3w         ; ex = expiry
                        3h         ; min = minimum
                        )
              IN      NS      ns1.example.org.
              IN      MX  10  mail.example.org.
joe           IN      A       192.168.254.3
www           IN      CNAME   joe
```

The parser will produce: [**example.json**](https://github.com/tableflip/zonefile-pegjs/blob/master/test/example.json)

```json
{
  "origin": "example.org.",
  "ttl": "2d",
  "records": [
    {
      "name": "@",
      "ttl": null,
      "type": "SOA",
      "data": {
        "nameServer": "ns1.example.org.",
        "email": "hostmaster.example.org.",
        "serial": "2003080800",
        "refresh": "12h",
        "retry": "15m",
        "expiry": "3w",
        "minimum": "3h"
      }
    },
    {
      "name": " ",
      "ttl": null,
      "type": "NS",
      "data": "ns1.example.org."
    },
    {
      "name": " ",
      "ttl": null,
      "type": "MX",
      "data": {
        "preference": "10",
        "domain": "mail.example.org."
      }
    },
    {
      "name": "joe",
      "ttl": null,
      "type": "A",
      "data": "192.168.254.3"
    },
    {
      "name": "www",
      "ttl": null,
      "type": "CNAME",
      "data": "joe"
    }
  ]
}
```

---

A [(╯°□°）╯︵TABLEFLIP](https://tableflip.io) side project.

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