{"id":15694143,"url":"https://github.com/silverwind/dnsz","last_synced_at":"2025-05-07T08:24:16.052Z","repository":{"id":57213721,"uuid":"192321298","full_name":"silverwind/dnsz","owner":"silverwind","description":"DNS zone file parser and stringifier","archived":false,"fork":false,"pushed_at":"2025-04-28T16:40:24.000Z","size":783,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T13:13:47.080Z","etag":null,"topics":["dns","dns-zone","dns-zone-files","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/silverwind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-06-17T09:58:32.000Z","updated_at":"2025-04-28T16:40:27.000Z","dependencies_parsed_at":"2023-01-29T16:30:19.043Z","dependency_job_id":"41590b23-8cd9-4b70-b214-69e850567cf3","html_url":"https://github.com/silverwind/dnsz","commit_stats":{"total_commits":108,"total_committers":2,"mean_commits":54.0,"dds":0.01851851851851849,"last_synced_commit":"e67e900d20398b24b7124f502a58379dbbad5148"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Fdnsz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Fdnsz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Fdnsz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Fdnsz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silverwind","download_url":"https://codeload.github.com/silverwind/dnsz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252840387,"owners_count":21812298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","dns-zone","dns-zone-files","nodejs"],"created_at":"2024-10-03T18:53:10.459Z","updated_at":"2025-05-07T08:24:16.035Z","avatar_url":"https://github.com/silverwind.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dnsz\n[![](https://img.shields.io/npm/v/dnsz.svg?style=flat)](https://www.npmjs.org/package/dnsz) [![](https://img.shields.io/npm/dm/dnsz.svg)](https://www.npmjs.org/package/dnsz) [![](https://img.shields.io/bundlephobia/minzip/dnsz.svg)](https://bundlephobia.com/package/dnsz) [![](https://packagephobia.com/badge?p=dnsz)](https://packagephobia.com/result?p=dnsz)\n\n\u003e Generic DNS zone file parser and stringifier\n\nAll 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.\n\n## Usage\n\n```bash\nnpm i dnsz\n```\n```js\nimport {parseZone, stringifyZone} from \"dnsz\";\n\nconst data = parseZone(\"example.com 60 IN A 1.2.3.4\");\n// =\u003e {records: [{name: \"example.com\", ttl: 60, class: \"IN\", type: \"A\", content: \"1.2.3.4\"}]}\n\nstringifyZone(data);\n// =\u003e \";; A Records\\nexample.com.\\t60\\tIN\\tA\\t1.2.3.4\\n\"\n```\n\n## API\n### parseZone(str, [opts])\n\nParse a string of a DNS zone file and returns a `data` object.\n\n- `opts.replaceOrigin` *string*: When specified, replaces any `@` in `name` or `content` with it. Default: `null`.\n- `opts.crlf` *boolean*: When true, emit `\\r\\n` instead of `\\n` in `header`. Default: `false`.\n- `opts.defaultTTL` *number*: Default TTL when absent and `$TTL` is not present. Default: `60`.\n- `opts.defaultClass` *string*: Default class when absent. Default: `\"IN\"`.\n- `opts.dots` *boolean*: Ensure trailing dots on FQDNs in content. Supports a limited amount of record types. Default: `false`.\n\n### stringifyZone(data, [opts])\n\nParse a `data` object and return a string with the zone file contents.\n\n- `opts.sections` *boolean*: Whether to group records into sections. Default: `true`.\n- `opts.crlf` *boolean*: When `true`, emit `\\r\\n` instead of `\\n` for the resulting zone file. Default: `false`.\n- `opts.dots` *boolean*: Ensure trailing dots on FQDNs in content. Supports a limited amount of record types. Default: `false`.\n\n### `data` object\n\n- `records`: Array of `record` with these props:\n  - `name`: The lowercase DNS name without a trailing dot, e.g. `\"example.com\"`.\n  - `ttl`: The TTL in seconds, e.g. `60`.\n  - `class`: The DNS class, e.g. `\"IN\"`.\n  - `type`: The record type, e.g. `\"A\"`.\n  - `content`: The record content, e.g. `\"2001:db8::1\"` or `\"example.com.\"`.\n  - `comment`: A comment, e.g. `\"a comment\"`, `null` if absent.\n- `origin`: The value of `$ORIGIN` in the zone file.\n- `ttl`: The value of `$TTL` in the zone file.\n- `header`: An optional header at the start of the file. Can be multiline. Does not include comment markers.\n\nIf `data.origin` is specified, the following things happen in the zone file output:\n\n- A `$ORIGIN` variable is added.\n- All occurences of `data.origin` within `content` are replaced with `@`.\n- If `data.origin` matches the `name` of a `record`, `name` is replaced with `@`.\n\n### Example zone file\n\n``` ini\n$ORIGIN originzone.com.\n\n;; SOA Records\n@   3600    IN  SOA originzone.com. root.originzone.com. 2031242781 7200 3600 86400 3600\n\n;; A Records\n@   60  IN  A   1.2.3.4 ; a comment\nmx  60  IN  A   1.2.3.4 ; another comment\n\n;; AAAA Records\n@   120 IN  AAAA    2001:db8::1\nmx  120 IN  AAAA    2001:db8::1\n```\n\n### Example data object\n\n``` json\n{\n  \"origin\": \"originzone.com\",\n  \"records\": [\n    {\n      \"name\": \"originzone.com\",\n      \"ttl\": 3600,\n      \"class\": \"IN\",\n      \"type\": \"SOA\",\n      \"content\": \"originzone.com. root.originzone.com. 2031242781 7200 3600 86400 3600\",\n      \"comment\": null\n    },\n    {\n      \"name\": \"originzone.com\",\n      \"ttl\": 60,\n      \"class\": \"IN\",\n      \"type\": \"A\",\n      \"content\": \"1.2.3.4\",\n      \"comment\": \"a comment\"\n    },\n    {\n      \"name\": \"mx\",\n      \"ttl\": 60,\n      \"class\": \"IN\",\n      \"type\": \"A\",\n      \"content\": \"1.2.3.4\",\n      \"comment\": \"another comment\"\n    },\n    {\n      \"name\": \"originzone.com\",\n      \"ttl\": 120,\n      \"class\": \"IN\",\n      \"type\": \"AAAA\",\n      \"content\": \"2001:db8::1\",\n      \"comment\": null\n    },\n    {\n      \"name\": \"mx\",\n      \"ttl\": 120,\n      \"class\": \"IN\",\n      \"type\": \"AAAA\",\n      \"content\": \"2001:db8::1\",\n      \"comment\": null\n    }\n  ]\n}\n```\n\n## License\n\n© [silverwind](https://github.com/silverwind), distributed under BSD licence\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilverwind%2Fdnsz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilverwind%2Fdnsz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilverwind%2Fdnsz/lists"}