{"id":18338727,"url":"https://github.com/tableflip/zonefile-pegjs","last_synced_at":"2025-09-23T10:12:50.710Z","repository":{"id":57406475,"uuid":"48607914","full_name":"tableflip/zonefile-pegjs","owner":"tableflip","description":"A PEG.js grammar for parsing zonefile DNS configuration","archived":false,"fork":false,"pushed_at":"2015-12-29T02:08:18.000Z","size":42,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T20:16:40.129Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tableflip.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":"2015-12-26T11:04:14.000Z","updated_at":"2023-09-14T23:21:24.000Z","dependencies_parsed_at":"2022-09-26T17:01:51.730Z","dependency_job_id":null,"html_url":"https://github.com/tableflip/zonefile-pegjs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fzonefile-pegjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fzonefile-pegjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fzonefile-pegjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fzonefile-pegjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tableflip","download_url":"https://codeload.github.com/tableflip/zonefile-pegjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247440346,"owners_count":20939221,"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":"2024-11-05T20:15:00.937Z","updated_at":"2025-09-23T10:12:45.659Z","avatar_url":"https://github.com/tableflip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zonefile-pegjs\n\nA 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.\n\nSee **[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\n\nDerived from, and with thanks to, **Pro DNS and BIND by Ron Aitchison**.\nSee: http://www.zytrax.com/books/dns/ch8/\n\n## Install\n\n```sh\nnpm install zonefile-pegjs\n```\n\n## Usage\n\nUse [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:\n\n```js\nrequire('pegjs-require')\nvar parser = require('zonefile-pegjs')\nparser.parse('tableflip.io. 21599 IN A 178.62.82.182')\n// { origin: null, ttl: null, records:[ { name:'tableflip.io.', ttl: '21599', type:'A', data: '178.62.82.182' } ] }\n```\n\n## Example\n\n[**example.js**](https://github.com/tableflip/zonefile-pegjs/blob/master/test/example.js)\n\n```js\nvar fs = require('fs')\nvar test = require('tape')\nvar pegjs = require('pegjs-require')\n\ntest('Parse zonefile for example.org.', function (t) {\n  var zone = fs.readFileSync(__dirname  + '/example.zone', 'utf8')\n  var parser = require('../zonefile.pegjs')\n  var actual = parser.parse(zone)\n  var expected = require('./example.json')\n  t.deepEquals(actual, expected, 'Most excellent: Parser generates expected output for example.org.')\n  t.end()\n})\n```\n\nSo given a zonefile like: [**example.zone**](https://github.com/tableflip/zonefile-pegjs/blob/master/test/example.zone)\n\n```zonefile\n; zone file for example.org\n$TTL 2d    ; 172800 secs default TTL for zone\n$ORIGIN example.org.\n@             IN      SOA   ns1.example.org. hostmaster.example.org. (\n                        2003080800 ; se = serial number\n                        12h        ; ref = refresh\n                        15m        ; ret = update retry\n                        3w         ; ex = expiry\n                        3h         ; min = minimum\n                        )\n              IN      NS      ns1.example.org.\n              IN      MX  10  mail.example.org.\njoe           IN      A       192.168.254.3\nwww           IN      CNAME   joe\n```\n\nThe parser will produce: [**example.json**](https://github.com/tableflip/zonefile-pegjs/blob/master/test/example.json)\n\n```json\n{\n  \"origin\": \"example.org.\",\n  \"ttl\": \"2d\",\n  \"records\": [\n    {\n      \"name\": \"@\",\n      \"ttl\": null,\n      \"type\": \"SOA\",\n      \"data\": {\n        \"nameServer\": \"ns1.example.org.\",\n        \"email\": \"hostmaster.example.org.\",\n        \"serial\": \"2003080800\",\n        \"refresh\": \"12h\",\n        \"retry\": \"15m\",\n        \"expiry\": \"3w\",\n        \"minimum\": \"3h\"\n      }\n    },\n    {\n      \"name\": \" \",\n      \"ttl\": null,\n      \"type\": \"NS\",\n      \"data\": \"ns1.example.org.\"\n    },\n    {\n      \"name\": \" \",\n      \"ttl\": null,\n      \"type\": \"MX\",\n      \"data\": {\n        \"preference\": \"10\",\n        \"domain\": \"mail.example.org.\"\n      }\n    },\n    {\n      \"name\": \"joe\",\n      \"ttl\": null,\n      \"type\": \"A\",\n      \"data\": \"192.168.254.3\"\n    },\n    {\n      \"name\": \"www\",\n      \"ttl\": null,\n      \"type\": \"CNAME\",\n      \"data\": \"joe\"\n    }\n  ]\n}\n```\n\n---\n\nA [(╯°□°）╯︵TABLEFLIP](https://tableflip.io) side project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Fzonefile-pegjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftableflip%2Fzonefile-pegjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Fzonefile-pegjs/lists"}