chore(xo-server/utils/parseXml): use fast-xml-parser instead of xml2js

It's faster, the API is simpler and it appears to be better maintained.
This commit is contained in:
Julien Fontanet
2020-12-31 10:50:22 +01:00
parent ba413f3e8f
commit 525369e0ce
3 changed files with 10 additions and 16 deletions

View File

@@ -69,6 +69,7 @@
"execa": "^5.0.0",
"express": "^4.16.2",
"express-session": "^1.15.6",
"fast-xml-parser": "^3.17.4",
"fatfs": "^0.10.4",
"from2": "^2.3.0",
"fs-extra": "^9.0.0",

View File

@@ -1,4 +1,5 @@
import base64url from 'base64url'
import fastXmlParser from 'fast-xml-parser'
import forEach from 'lodash/forEach'
import has from 'lodash/has'
import highland from 'highland'
@@ -105,24 +106,11 @@ export const formatXml = (function () {
export const parseXml = (function () {
const opts = {
mergeAttrs: true,
explicitArray: false,
attributeNamePrefix: '',
ignoreAttributes: false,
}
return xml => {
let result
// xml2js.parseString() use a callback for synchronous code.
xml2js.parseString(xml, opts, (error, result_) => {
if (error) {
throw error
}
result = result_
})
return result
}
return xml => fastXmlParser.parse(xml, opts)
})()
// -------------------------------------------------------------------

View File

@@ -7747,6 +7747,11 @@ fast-safe-stringify@^2.0.7:
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743"
integrity sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==
fast-xml-parser@^3.17.4:
version "3.17.6"
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-3.17.6.tgz#4f5df8cf927c3e59a10362abcfb7335c34bc5c5f"
integrity sha512-40WHI/5d2MOzf1sD2bSaTXlPn1lueJLAX6j1xH5dSAr6tNeut8B9ktEL6sjAK9yVON4uNj9//axOdBJUuruCzw==
fastq@^1.6.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.9.0.tgz#e16a72f338eaca48e91b5c23593bcc2ef66b7947"