npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zonex-dns

v1.3.0

Published

Zonex - Library for parsing and generating DNS zone files in compliance with RFC standards.

Downloads

202

Readme

ZoneX

ZoneX is a lightweight TypeScript library for parsing and generating DNS zone files compliant with RFC standards (e.g., RFC 1035). It allows you to convert BIND-style zone files into structured JSON and generate zone files from JSON, supporting a wide variety of DNS record types including SOA, MX, TXT, HINFO, RP, OPENPGPKEY, and more.


Features

  • Structured Metadata Parsing: Automatically extracts provider-specific tags (like Cloudflare cf_tags) into a meta object and keeps comments clean.
  • Parse BIND zone files into structured JSON objects.
  • Generate BIND zone files from JSON records.
  • Supports all common and advanced DNS record types: A, AAAA, MX, CNAME, NS, TXT, HINFO, SOA, RP, OPENPGPKEY, TLSA, SSHFP, SVCB, URI, and more.
  • Customizable field mapping — adapt the generator to work with your own JSON property names.
  • TypeScript ready with full typings.
  • RFC-compliant output for production use (after editing SOA/NS records as needed).

Installation

npm install zonex-dns
# or
yarn add zonex-dns
# or
pnpm add zonex-dns

Usage

Importing

import zonex from "zonex-dns";

const { parse, generate, toZoneFile } = zonex;

Parsing a Zone File

import fs from "fs";

const zoneData = fs.readFileSync("example.txt", "utf8");
const records = parse(zoneData, { flatten: false });

console.log(records);

Output Example:

{
  "A": [
    {
      "name": "example.com.",
      "ttl": 600,
      "class": "IN",
      "type": "A",
      "rdata": "192.0.2.1",
      "address": "192.0.2.1"
    }
  ],
  "MX": [
    {
      "name": "example.com.",
      "ttl": 3600,
      "class": "IN",
      "type": "MX",
      "rdata": "10 mail.example.com.",
      "priority": 10,
      "exchange": "mail.example.com."
    }
  ]
}

Parsing with Provider Metadata

ZoneX automatically detects structured metadata within comments (e.g., cf_tags). It extracts the tags into the meta property and leaves the human-readable text in the comment property.

import { parse } from "zonex-dns";

const zoneData = `
example.com. 3600 IN A 192.0.2.1 ; cf_tags=proxied:true,env:prod Main Server
`;

const records = parse(zoneData);

console.log(records[0].comment); 
// Output: "Main Server"

console.log(records[0].meta); 
// Output: { "proxied": "true", "env": "prod" }

Generating a Zone File

import { generate } from "zonex-dns";

const inputRecords = [
  { name: "example.com.", type: "A", ttl: 3600, class: "IN", address: "192.0.2.1" },
  { name: "mail.example.com.", type: "MX", ttl: 3600, class: "IN", preference: 10, exchange: "mail.example.com." }
];

// Example: map your own property names to the standard ones
const jsonByType = generate(inputRecords, {
  fieldMap: {
    MX: {
      priority: "preference" // user property "preference" will be mapped to DNS field "priority"
    }
  }
});

Output Example:

$ORIGIN example.com.
$TTL 3500

;; A records
example.com.        3600    IN    A    192.0.2.1

;; MX records
mail.example.com.   3600    IN    MX   10 mail.example.com.

Customizing Field Mapping

By default, ZoneX expects input objects to follow the standard DNS record property names. With the fieldMap option, you can map your own property names to those expected by ZoneX.

Example: MX record

If your JSON uses preference instead of the standard priority:

generate(records, {
  fieldMap: {
    MX: { priority: "preference" }
  }
});

Parsing with Provider Metadata

ZoneX detects structured metadata (like cf_tags) and separates it from the human-readable comment.

import { parse } from "zonex-dns";

const zoneData = `
example.com. 3600 IN A 192.0.2.1 ; cf_tags=proxied:true,env:prod Main Server
`;

const records = parse(zoneData);

console.log(records[0].comment); 
// Output: "Main Server" (The tag is stripped out)

console.log(records[0].meta); 
// Output: { "proxied": "true", "env": "prod" }

API Reference

DNSRecord Interface

export interface DNSRecord {
    name: string;
    type: RecordType;
    ttl: number;
    class: string;
    rdata: string;
    comment?: string;             // Cleaned human-readable comment
    meta?: Record<string, any>;   // Structured metadata (e.g. cf_tags)
}

parse(input: string, options?: ParseOptions): ParsedRecord[]

Parses a zone file string into structured JSON.

Options:

  • preserveSpacing?: boolean – keep whitespace formatting in TXT records.
  • keepTrailingDot?: boolean – retain trailing dot on record names.
  • flatten?: boolean – flatten records into a single array.

generate(records: InputRecord[], options?: GenerateOptions): DNSRecordsByType

Generates structured JSON from input records.


Supported Record Types

A, AAAA, CAA, CNAME, MX, NS, TXT, SRV, PTR, SOA, DS, DNSKEY, TLSA, SSHFP, HTTPS, IPSECKEY, ALIAS, SPF, NAPTR, CERT, LOC, SMIMEA, SVCB, URI, DNAME, HINFO, OPENPGPKEY, RP


Disclaimer

  • This library is intended for development and educational purposes.
  • You must update SOA, NS, and other records before deploying to a production DNS server.
  • Use at your own risk.

Authors & Contributors


License

ZoneX is licensed under the MIT License.


NPM

📦 https://www.npmjs.com/package/zonex-dns