Skip to content

Instantly share code, notes, and snippets.

@talesmgodois
Last active October 6, 2020 14:36
Show Gist options
  • Save talesmgodois/6774b357b5d19aab9709d09c80ccb1ee to your computer and use it in GitHub Desktop.
Save talesmgodois/6774b357b5d19aab9709d09c80ccb1ee to your computer and use it in GitHub Desktop.
import { Parser } from "xml2js";
const parseName = (name: string) => (name.indexOf(':') !== -1 ? name.split(':')[1] : name);
const camelize = (name: string) => name[0].toLowerCase() + name.substring(1, name.length);
const envelope = import { Parser } from "xml2js";
await new Parser({
explicitArray: false,
explicitRoot : false,
trim: true,
emptyTag: true,
ignoreAttrs: true,
tagNameProcessors: [parseName, camelize],
}).parseStringPromise(xml);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment