Skip to content

Commit 1311ea4

Browse files
committed
feat(response): add optional toXML when installing fast-xml-parser
1 parent a2de7af commit 1311ea4

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
},
8181
"optionalDependencies": {
8282
"@tauri-apps/plugin-http": "^2.4.4",
83+
"fast-xml-parser": "^5.2.3",
8384
"undici": "^7.10.0",
8485
"cheerio": "^1.0.0"
8586
},

src/response.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,17 @@ export class HttpResponse {
2727
const string = await this.toString();
2828
return JSON.parse(string) as T;
2929
}
30+
31+
public async toXML <T = unknown>(): Promise<{ root: T }> {
32+
const { XMLParser } = await import("fast-xml-parser");
33+
34+
const parser = new XMLParser({
35+
attributeNamePrefix: "",
36+
ignoreAttributes: false,
37+
textNodeName: "content"
38+
});
39+
40+
const string = await this.toString();
41+
return parser.parse(string);
42+
}
3043
}

0 commit comments

Comments
 (0)