123456789101112131415161718192021 |
- export class AsyncDataReader {
- async readText(filePath) {
- let response = await fetch(filePath);
- return response.text();
- }
- async readJson(filePath) {
- let response = await fetch(filePath);
- return response.json();
- }
- async readDOM(filePath) {
- let text = await this.readText(filePath);
- return new DOMParser().parseFromString(text, "text/html").body.firstChild;
- }
- async readXML(filePath) {
- let xml = await this.readText(filePath);
- return new DOMParser().parseFromString(xml, "application/xml");
- }
- }
|