
Company News
Socket Joins the OpenJS Foundation
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.
Generic DNS zone file parser and stringifier
All current and future record types are supported as the module makes no effort to parse a record's content. It is highly configurable and has no dependencies.
npm i dnsz
import {parseZone, stringifyZone} from "dnsz";
const data = parseZone("example.com 60 IN A 1.2.3.4");
// => {records: [{name: "example.com", ttl: 60, class: "IN", type: "A", content: "1.2.3.4"}]}
stringifyZone(data);
// => ";; A Records\nexample.com.\t60\tIN\tA\t1.2.3.4\n"
Parse a string of a DNS zone file and returns a data object.
opts.replaceOrigin string: When specified, replaces any @ in name or content with it. Default: null.opts.crlf boolean: When true, emit \r\n instead of \n in header. Default: false.opts.defaultTTL number: Default TTL when absent and $TTL is not present. Default: 60.opts.defaultClass string: Default class when absent. Default: "IN".opts.dots boolean: Ensure trailing dots on FQDNs in content. Supports a limited amount of record types. Default: false.Parse a data object and return a string with the zone file contents.
opts.sections boolean: Whether to group records into sections. Default: true.opts.crlf boolean: When true, emit \r\n instead of \n for the resulting zone file. Default: false.opts.dots boolean: Ensure trailing dots on FQDNs in content. Supports a limited amount of record types. Default: false.data objectrecords: Array of record with these props:
name: The lowercase DNS name without a trailing dot, e.g. "example.com".ttl: The TTL in seconds, e.g. 60.class: The DNS class, e.g. "IN".type: The record type, e.g. "A".content: The record content, e.g. "2001:db8::1" or "example.com.".comment: A comment, e.g. "a comment", null if absent.origin: The value of $ORIGIN in the zone file.ttl: The value of $TTL in the zone file.header: An optional header at the start of the file. Can be multiline. Does not include comment markers.If data.origin is specified, the following things happen in the zone file output:
$ORIGIN variable is added.data.origin within content are replaced with @.data.origin matches the name of a record, name is replaced with @.$ORIGIN originzone.com.
;; SOA Records
@ 3600 IN SOA originzone.com. root.originzone.com. 2031242781 7200 3600 86400 3600
;; A Records
@ 60 IN A 1.2.3.4 ; a comment
mx 60 IN A 1.2.3.4 ; another comment
;; AAAA Records
@ 120 IN AAAA 2001:db8::1
mx 120 IN AAAA 2001:db8::1
{
"origin": "originzone.com",
"records": [
{
"name": "originzone.com",
"ttl": 3600,
"class": "IN",
"type": "SOA",
"content": "originzone.com. root.originzone.com. 2031242781 7200 3600 86400 3600",
"comment": null
},
{
"name": "originzone.com",
"ttl": 60,
"class": "IN",
"type": "A",
"content": "1.2.3.4",
"comment": "a comment"
},
{
"name": "mx",
"ttl": 60,
"class": "IN",
"type": "A",
"content": "1.2.3.4",
"comment": "another comment"
},
{
"name": "originzone.com",
"ttl": 120,
"class": "IN",
"type": "AAAA",
"content": "2001:db8::1",
"comment": null
},
{
"name": "mx",
"ttl": 120,
"class": "IN",
"type": "AAAA",
"content": "2001:db8::1",
"comment": null
}
]
}
© silverwind, distributed under BSD licence
FAQs
Generic DNS zone file parser and stringifier
The npm package dnsz receives a total of 180 weekly downloads. As such, dnsz popularity was classified as not popular.
We found that dnsz demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.