{"id":14399,"library":"zonefile-parser","title":"DNS Zonefile Parser","description":"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.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/tableflip/zonefile-parser","tags":["javascript","dns","zonefile","parser","peg","soa","srv","txt"],"install":[{"cmd":"npm install zonefile-parser","lang":"bash","label":"npm"},{"cmd":"yarn add zonefile-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add zonefile-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While the README uses `require()`, modern Node.js and bundlers can use default ESM import. The primary export is the parser object directly.","wrong":"const { parser } = require('zonefile-parser')","symbol":"parser","correct":"import parser from 'zonefile-parser'"},{"note":"For browser environments or to reduce bundle size, the 'small' bundle can be imported. It's also a default export.","wrong":"import { parser } from 'zonefile-parser/small'","symbol":"parser (small bundle)","correct":"import parser from 'zonefile-parser/small'"},{"note":"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).","wrong":"import parser from 'zonefile-parser'","symbol":"require (CJS default)","correct":"const parser = require('zonefile-parser')"}],"quickstart":{"code":"const fastParser = require('zonefile-parser');\nconst smallParser = require('zonefile-parser/small');\n\nconst zonefileContent = `\n$ORIGIN example.com.\n$TTL 1h\n@               IN SOA  ns1.example.com. hostmaster.example.com. (\n                        2023010101 ; serial\n                        1h         ; refresh\n                        15m        ; retry\n                        1w         ; expire\n                        1h )       ; minimum\n@               IN NS   ns1.example.com.\n@               IN A    192.0.2.1\nwww             IN A    192.0.2.2\nmail            IN MX   10 mail.example.com.\n_sip._tcp       IN SRV  0 5 5060 sip.example.com.\nexample.com.    IN TXT  \"v=spf1 include:_spf.example.com ~all\"\n`;\n\nconsole.log('--- Using fast.js parser ---');\ntry {\n  const resultFast = fastParser.parse(zonefileContent);\n  console.log(JSON.stringify(resultFast, null, 2));\n} catch (e) {\n  console.error('Fast parser error:', e.message);\n}\n\nconsole.log('\\n--- Using small.js parser (for smaller bundles) ---');\ntry {\n  const resultSmall = smallParser.parse('tableflip.io. 21599 IN A 178.62.82.182');\n  console.log(JSON.stringify(resultSmall, null, 2));\n} catch (e) {\n  console.error('Small parser error:', e.message);\n}","lang":"javascript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"As 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.1':36 'aaaa':57 'accur':26 'appear':89 'browser':76,84 'cadenc':97 'case':86 'cname':53 'common':38 'configur':16 'core':102 'current':33 'depend':66 'design':11 'differenti':60 'dns':1,14,39,110,120 'environ':77 'establish':116 'file':17 'focus':99 'format':118 'frequent':106 'function':104 'generat':22 'grammar':21 'handl':37 'includ':46 'interpret':27 'javascript':9,119 'leverag':19 'lightweight':70 'line':49 'low':95 'make':67,112 'modul':10 'multi':48 'multi-lin':47 'mx':52 'new':109 'node.js':74 'ns':54 'packag':32 'pars':13,103 'parser':3,6,122 'peg':123 'peg.js':24 'primarili':98 'project':88 'record':40,50,58 'releas':96 'runtim':65 'small.js':81 'smaller':80 'soa':44,124 'solut':71 'srv':51,125 'stabl':92 'standard':28,111 'suitabl':114 'syntax':30 'txt':45,126 'type':41 'updat':107 'use':85 'variant':82 'version':35 'without':105 'zone':15 'zonefil':2,5,29,117,121 'zonefile-pars':4","created_at":"2026-04-20T01:59:30.755884+00:00","updated_at":"2026-04-20T01:59:30.755884+00:00","problems":[{"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.","cause":"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.","error":"SyntaxError: Expected <some DNS token> but got <unexpected token>"},{"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.","cause":"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).","error":"require is not defined"},{"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`.","cause":"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.","error":"TypeError: parser.parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.1.20","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/tableflip/zonefile-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/zonefile-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}