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AAC,GAAE,YAA6B,GAAG,OAAO,CA0F7N;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,EAAC,IAA8B,EAAE,QAAsC,EAAE,IAA8B,EAAC,GAAE,gBAAqC,GAAG,MAAM,CA+CpM"} |
+72
-6
@@ -1,2 +0,1 @@ | ||
| import splitString from "split-string"; | ||
| const defaults = { | ||
@@ -42,2 +41,72 @@ parse: { | ||
| } | ||
| function splitString(input, { separator = " ", quotes = [] } = {}) { | ||
| const ast = { type: "root", nodes: [], stash: [""] }; | ||
| const stack = [ast]; | ||
| const string = input; | ||
| let value; | ||
| let node; | ||
| let i = -1; | ||
| const state = { | ||
| input, | ||
| separator, | ||
| stack, | ||
| prev: () => string[i - 1], | ||
| next: () => string[i + 1] | ||
| }; | ||
| const block = () => state.block = stack[stack.length - 1]; | ||
| const peek = () => string[i + 1]; | ||
| const next = () => string[++i]; | ||
| const append = (value2) => { | ||
| state.value = value2; | ||
| if (value2) { | ||
| state.block.stash[state.block.stash.length - 1] += value2; | ||
| } | ||
| }; | ||
| const closeIndex = (value2, startIdx) => { | ||
| let idx = string.indexOf(value2, startIdx); | ||
| if (idx > -1 && string[idx - 1] === "\\") { | ||
| idx = closeIndex(value2, idx + 1); | ||
| } | ||
| return idx; | ||
| }; | ||
| while (i < string.length - 1) { | ||
| state.value = value = next(); | ||
| state.index = i; | ||
| block(); | ||
| if (value === "\\") { | ||
| if (peek() === "\\") { | ||
| append(value + next()); | ||
| } else { | ||
| append(value); | ||
| append(next()); | ||
| } | ||
| continue; | ||
| } | ||
| if (quotes.includes(value)) { | ||
| const pos = i + 1; | ||
| const idx = closeIndex(value, pos); | ||
| if (idx > -1) { | ||
| append(value); | ||
| append(string.slice(pos, idx)); | ||
| append(string[idx]); | ||
| i = idx; | ||
| continue; | ||
| } | ||
| append(value); | ||
| continue; | ||
| } | ||
| if (value === separator && state.block.type === "root") { | ||
| state.block.stash.push(""); | ||
| continue; | ||
| } | ||
| append(value); | ||
| } | ||
| node = stack.pop(); | ||
| while (node !== ast) { | ||
| value = node.parent.stash.pop() + node.stash.join("."); | ||
| node.parent.stash = node.parent.stash.concat(value.split(".")); | ||
| node = stack.pop(); | ||
| } | ||
| return node.stash; | ||
| } | ||
| function denormalize(name) { | ||
@@ -55,5 +124,3 @@ if (!name.endsWith(".") && name.length > 1) { | ||
| quotes: [`"`], | ||
| separator: " ", | ||
| keep: () => true | ||
| // keep backslashes | ||
| separator: " " | ||
| }).map((s) => s.trim()).filter(Boolean); | ||
@@ -135,4 +202,3 @@ for (const index of indexes) { | ||
| quotes: [`"`], | ||
| separator: ";", | ||
| keep: () => true | ||
| separator: ";" | ||
| }); | ||
@@ -139,0 +205,0 @@ let parts; |
+1
-4
| { | ||
| "name": "dnsz", | ||
| "version": "4.1.2", | ||
| "version": "4.2.0", | ||
| "description": "Generic DNS zone file parser and stringifier", | ||
@@ -16,5 +16,2 @@ "author": "silverwind <me@silverwind.io>", | ||
| ], | ||
| "dependencies": { | ||
| "split-string": "6.1.0" | ||
| }, | ||
| "devDependencies": { | ||
@@ -21,0 +18,0 @@ "@types/node": "20.14.9", |
+1
-1
@@ -6,3 +6,3 @@ # dnsz | ||
| 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 minimal dependencies. | ||
| 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. | ||
@@ -9,0 +9,0 @@ ## Usage |
17836
9.9%0
-100%418
18.75%- Removed
- Removed