wechaty-puppet-wechat4u
Version:
Wechat4u Puppet for Wechaty
20 lines (17 loc) • 573 B
text/typescript
import { parseString } from 'xml2js'
import { log } from 'wechaty-puppet'
export async function xmlToJson (xml: string): Promise<any> {
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)
})
})
}