AsyncDataReader.js 528 B

123456789101112131415161718192021
  1. export class AsyncDataReader {
  2. async readText(filePath) {
  3. let response = await fetch(filePath);
  4. return response.text();
  5. }
  6. async readJson(filePath) {
  7. let response = await fetch(filePath);
  8. return response.json();
  9. }
  10. async readDOM(filePath) {
  11. let text = await this.readText(filePath);
  12. return new DOMParser().parseFromString(text, "text/html").body.firstChild;
  13. }
  14. async readXML(filePath) {
  15. let xml = await this.readText(filePath);
  16. return new DOMParser().parseFromString(xml, "application/xml");
  17. }
  18. }