wechaty-puppet-wechat4u
Version:
Wechat4u Puppet for Wechaty
18 lines • 649 B
JavaScript
import { parseString } from 'xml2js';
import { log } from 'wechaty-puppet';
export async function xmlToJson(xml) {
const firstIndex = xml.indexOf('<');
if (firstIndex !== 0) {
xml = xml.substring(firstIndex, xml.length);
}
return new Promise((resolve) => {
parseString(xml, { explicitArray: false }, (err, result) => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (err && Object.keys(err).length !== 0) {
log.warn(JSON.stringify(err));
}
return resolve(result);
});
});
}
//# sourceMappingURL=xml-to-json.js.map