dnsz v4.2.1
dnsz
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.
Usage
npm i dnszimport {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"API
parseZone(str, opts)
Parse a string of a DNS zone file and returns a data object.
- opts.replaceOriginstring: When specified, replaces any- @in- nameor- contentwith it. Default:- null.
- opts.crlfboolean: When true, emit- \r\ninstead of- \nin- header. Default:- false.
- opts.defaultTTLnumber: Default TTL when absent and- $TTLis not present. Default:- 60.
- opts.dotsboolean: Ensure trailing dots on FQDNs in content. Supports a limited amount of record types. Default:- false.
stringifyZone(data, opts)
Parse a data object and return a string with the zone file contents.
- opts.sectionsboolean: Whether to group records into sections. Default:- true.
- opts.crlfboolean: When- true, emit- \r\ninstead of- \nfor the resulting zone file. Default:- false.
- opts.dotsboolean: Ensure trailing dots on FQDNs in content. Supports a limited amount of record types. Default:- false.
data object
- records: Array of- recordwith 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",- nullif absent.
 
- origin: The value of- $ORIGINin the zone file.
- ttl: The value of- $TTLin 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:
- A $ORIGINvariable is added.
- All occurences of data.originwithincontentare replaced with@.
- If data.originmatches thenameof arecord,nameis replaced with@.
Example zone file
$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::1Example data object
{
  "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
    }
  ]
}License
© silverwind, distributed under BSD licence
9 months ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago