UNPKG

@remote.it/core

Version:

Core remote.it JavasScript/TypeScript library

37 lines (31 loc) 720 B
import convert from 'xml-js' import debug from 'debug' import { File } from './File' const d = debug('remoteit:XMLFile') export class XMLFile<T> extends File { private baseOptions = { attributesKey: 'attributes', compact: true, nativeType: true, spaces: 2, textKey: 'text', } constructor(public location: string) { super(location) } /** * Return the JavaScript object representation of the * XML file. */ read(): T { return convert.xml2js(this.content, this.baseOptions) as T } /** * Write the contents as XML to the file. */ write(content: T) { const xml = convert.js2xml(content, this.baseOptions) this.content = xml d('wrote:', xml) } }