Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
shim: Factor xml2Json
Browse files Browse the repository at this point in the history
Making this optional to prevent loading XML library when unused.
  • Loading branch information
bookmoons committed Mar 14, 2019
1 parent f9c5273 commit 6866ceb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .ava.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"verbose": true
"verbose": true,
"require": [
"@babel/register"
]
}
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
12 changes: 0 additions & 12 deletions lib/shim/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,6 @@ function exposePm () {
}

/* Conversion */
function xml2Json (xml) {
const xml2js = require('./xml2js.js')
let json
xml2js.parseString(xml, { async: false }, (err, result) => {
if (err) {
throw err
}
json = result
})
return json
}
function xmlToJson (xml) {
throw new Error('Deprecated function xmlToJson not supported')
}
Expand Down Expand Up @@ -443,7 +432,6 @@ Object.defineProperties(global, {
Object.assign(global, {
postman,
require,
xml2Json,
xmlToJson
})
exposePm()
14 changes: 14 additions & 0 deletions lib/shim/xml2Json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import xml2js from '../xml2js.js'

function xml2Json (xml) {
let json
xml2js.parseString(xml, { async: false }, (err, result) => {
if (err) {
throw err
}
json = result
})
return json
}

global.xml2Json = xml2Json
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"verror": "^1.10.0"
},
"devDependencies": {
"@babel/preset-env": "^7.3.4",
"@babel/register": "^7.0.0",
"ava": "^1.2.1",
"cross-env": "^5.2.0",
"mock-require": "^3.0.3",
Expand Down
3 changes: 2 additions & 1 deletion test/com/shim/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import test from 'ava'
import mockRequire from 'mock-require'
import 'shim/core'

const Reset = Symbol.for('reset')

test.before(t => {
mockRequire('../../../lib/xml2js.js', 'xml2js')
require('shim/core')
require('shim/xml2Json')
})

test.beforeEach(t => {
Expand Down

0 comments on commit 6866ceb

Please sign in to comment.