xml.js 320 B

123456789101112131415
  1. const XML = {
  2. parse(string) {
  3. let result = null
  4. xml2js.parseString(string, (err, doc) => {
  5. if (err) throw err
  6. result = doc
  7. })
  8. if (!result) throw new Error('Async?')
  9. return result
  10. },
  11. stringify(doc) {
  12. const builder = new xml2js.Builder()
  13. return builder.buildObject(doc)
  14. }
  15. }