UNPKG

@dzfu/parser

Version:
88 lines (71 loc) 1.62 kB
## @dzfu/parser dns zonefile parser [![Build Status](https://travis-ci.org/KoyamaSohei/dzfu.svg?branch=master)](https://travis-ci.org/KoyamaSohei/dzfu) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) ## Install ```bash yarn add @dzfu/parser ``` ## Usage ```ts import { RR } from "@dzfu/core"; import { parseZone } from "@dzfu/parser"; const text = ` $TTL 3600 @ IN SOA ns.example1.com. root.example1.com. ( 20190101 ; serial 3600 ; refresh 3600 ; retry 1209600 ; expire 3600 ; negative cache ttl ) ; NS records @ IN NS ns.example1.com. @ IN NS ns2.example1.com. ; A records localhost.example1.com. IN A 127.0.0.1 ns.example1.com. IN A 192.1.2.2 ns2.example1.com. IN A 192.1.2.3 bug.example1.com. IN A 192.249.249.1 dog IN A 192.249.249.2 cat IN A 192.249.249.3 shark IN A 192.249.249.4 ; CNAME records foo.example1.com. IN CNAME example2.com. bar.example1.com. IN CNAME foo.example2.com. `; const rrs: RR[] = parseZone(text, "example1.com."); console.log(rrs); /** Array [ Object { "class": 0, "expire": 1209600, "mbox": "root.example1.com.", "minttl": 3600, "name": "example1.com.", "ns": "ns.example1.com.", "refresh": 3600, "retry": 3600, "rrtype": 5, "serial": 20190101, "ttl": 3600, }, Object { "class": 0, "name": "example1.com.", "ns": "ns.example1.com.", "rrtype": 3, "ttl": 3600, }, ..., Object { "class": 0, "name": "bar.example1.com.", "rrtype": 0, "target": "foo.example2.com.", "ttl": 3600, }, ] */ ```