Registry / serialization / zonefile-parser

zonefile-parser

JSON →
library0.1.20jsnpmunverified

zonefile-parser is a JavaScript module designed for parsing DNS zone configuration files. It leverages a grammar generated by PEG.js to accurately interpret standard zonefile syntax. The package, currently at version 1.0.1, handles common DNS record types such as SOA, TXT (including multi-line records), SRV, MX, CNAME, NS, A, and AAAA records. It differentiates itself by having no runtime dependencies, making it a lightweight solution for both Node.js and browser environments (with a smaller 'small.js' variant for browser use cases). The project appears to be stable with a low release cadence, primarily focusing on its core parsing functionality without frequent updates to new DNS standards, making it suitable for established zonefile formats.

npm install zonefile-parser
INSTALL
IMPORT
SIG · ZONEFILE-PARSER
Z
zonefile-parser
serializationjavascriptv0.1.20
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
import parser from 'zonefile-parser'
const { parser } = require('zonefile-parser')
While the README uses `require()`, modern Node.js and bundlers can use default ESM import. The primary export is the parser object directly.
parser (small bundle)
import parser from 'zonefile-parser/small'
import { parser } from 'zonefile-parser/small'
For browser environments or to reduce bundle size, the 'small' bundle can be imported. It's also a default export.
require (CJS default)
const parser = require('zonefile-parser')
import parser from 'zonefile-parser'
This is the documented and most reliable way to use the package in CommonJS environments (Node.js prior to native ESM or without type:module).

This quickstart demonstrates parsing a multi-record DNS zonefile using both the default 'fast' and the smaller 'small' parsers provided by the library, outputting the structured JSON representation of the records.

const fastParser = require('zonefile-parser'); const smallParser = require('zonefile-parser/small'); const zonefileContent = ` $ORIGIN example.com. $TTL 1h @ IN SOA ns1.example.com. hostmaster.example.com. ( 2023010101 ; serial 1h ; refresh 15m ; retry 1w ; expire 1h ) ; minimum @ IN NS ns1.example.com. @ IN A 192.0.2.1 www IN A 192.0.2.2 mail IN MX 10 mail.example.com. _sip._tcp IN SRV 0 5 5060 sip.example.com. example.com. IN TXT "v=spf1 include:_spf.example.com ~all" `; console.log('--- Using fast.js parser ---'); try { const resultFast = fastParser.parse(zonefileContent); console.log(JSON.stringify(resultFast, null, 2)); } catch (e) { console.error('Fast parser error:', e.message); } console.log('\n--- Using small.js parser (for smaller bundles) ---'); try { const resultSmall = smallParser.parse('tableflip.io. 21599 IN A 178.62.82.182'); console.log(JSON.stringify(resultSmall, null, 2)); } catch (e) { console.error('Small parser error:', e.message); }
Debug
Known issues
gotchaThe package offers two main entry points: `zonefile-parser` (fast.js) and `zonefile-parser/small` (small.js). While 'small.js' is optimized for size, both provide the same parsing API. Ensure you consistently use the desired entry point for predictable bundle sizes, especially in browser environments.
fix
Explicitly import `require('zonefile-parser/small')` when targeting smaller bundles for browser or client-side use cases. Otherwise, `require('zonefile-parser')` is the default and recommended for Node.js.
affects: >=1.0.0
gotchaAs a module generated by PEG.js, `zonefile-parser` is highly dependent on its grammar definition. If a zonefile contains syntax not covered by the grammar, or if new DNS record types/formats emerge that are not reflected in the package's 1.x version, parsing may fail or produce incorrect results. The package does not appear to be actively updated for new DNS specifications.
fix
For highly dynamic or cutting-edge DNS configurations, validate the parser's output against known good data or consider alternative, more actively maintained DNS parsing libraries. Review the upstream PEG.js grammar (`https://github.com/tableflip/zonefile-pegjs`) for supported features.
affects: >=1.0.0
gotchaThis package primarily supports CommonJS module loading (`require`). While modern bundlers or Node.js with `"type": "module"` can often transpile/interpret `require` or provide ESM compatibility, direct ESM `import` statements might not work out-of-the-box in all environments without specific configuration or transpilation due to the package's age and module format.
fix
For ESM projects, use `import parser from 'zonefile-parser';` and rely on your bundler (e.g., Webpack, Rollup, esbuild) or Node.js's native ESM loader to handle the CJS compatibility. If issues arise, consider a CJS wrapper or ensure your build tools are correctly configured for CJS interop.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Expected <some DNS token> but got <unexpected token>
The input zonefile string contains syntax that does not conform to the parser's grammar, often due to typos, malformed records, or unsupported DNS features.
fix
Carefully review the offending line in the zonefile content. Ensure all records adhere to standard DNS zonefile format, including proper spacing, quotes for TXT records, and correct record type syntax. Check for unclosed parentheses in SOA records or missing mandatory fields.
require is not defined
Attempting to use `require()` directly in an environment that only supports ES Modules (e.g., modern browser, Node.js with `"type": "module"` and no bundler).
fix
If in an ESM context, change `const parser = require('zonefile-parser')` to `import parser from 'zonefile-parser'`. If running in a browser, ensure you are using a bundler (like Webpack, Rollup) that handles CommonJS modules.
TypeError: parser.parse is not a function
The module might not have been imported correctly, or the imported object does not have a `parse` method, possibly due to a default vs. named import mismatch or an incorrect import path.
fix
Ensure you are importing the default export correctly: `const parser = require('zonefile-parser')` for CJS or `import parser from 'zonefile-parser'` for ESM. Double-check the path, especially if using `zonefile-parser/small`.
Upgrade
Version history
0.1.20latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
28 hits · last 30 days
node
22
OpenAI (training)
1
Resources
zonefile-parser — npm install zonefile-parser · libregistry