import { ParsedXml } from '@interfaces/utils/Xml';
import xmlConverter from 'xml-js';

export default class XmlParser {
  static async parse(file: File, options?: object) {
    const xml = await file.text();
    const json: ParsedXml = JSON.parse(xmlConverter.xml2json(xml, options) ?? '{}');
    return json;
  }

  static parseString(text: string, options?: object): ParsedXml {
    return JSON.parse(xmlConverter.xml2json(text, options) ?? '{}');
  }
}
