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 🙏

© 2024 – Pkg Stats / Ryan Hefner

dnsz

v4.2.0

Published

Generic DNS zone file parser and stringifier

Downloads

394

Readme

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 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"

API

parseZone(str, [opts])

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.dots boolean: 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.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 object

  • records: 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:

  • A $ORIGIN variable is added.
  • All occurences of data.origin within content are replaced with @.
  • If data.origin matches the name of a record, name is 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::1

Example 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