Simplify formatXml
This commit is contained in:
@@ -186,24 +186,17 @@ export function formatXml (xml) {
|
|||||||
"other->other": 0
|
"other->other": 0
|
||||||
}
|
}
|
||||||
fn = function(ln) {
|
fn = function(ln) {
|
||||||
var fromTo, key, padding, type, types, value
|
var fromTo, padding, type
|
||||||
types = {
|
|
||||||
single: Boolean(ln.match(/<.+\/>/)),
|
if (Boolean(ln.match(/<.+\/>/))) {
|
||||||
closing: Boolean(ln.match(/<\/.+>/)),
|
type = "single"
|
||||||
opening: Boolean(ln.match(/<[^!?].*>/))
|
} else if (Boolean(ln.match(/<\/.+>/))) {
|
||||||
|
type = "closing"
|
||||||
|
} else if (Boolean(ln.match(/<[^!?].*>/))) {
|
||||||
|
type = "opening"
|
||||||
|
} else {
|
||||||
|
type = "other"
|
||||||
}
|
}
|
||||||
type = ((function() {
|
|
||||||
var results
|
|
||||||
results = []
|
|
||||||
for (key in types) {
|
|
||||||
value = types[key]
|
|
||||||
if (value) {
|
|
||||||
results.push(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results
|
|
||||||
})())[0]
|
|
||||||
type = type === void 0 ? "other" : type
|
|
||||||
fromTo = lastType + "->" + type
|
fromTo = lastType + "->" + type
|
||||||
lastType = type
|
lastType = type
|
||||||
padding = ""
|
padding = ""
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ import {
|
|||||||
fromJSOrdered,
|
fromJSOrdered,
|
||||||
getAcceptControllingResponse,
|
getAcceptControllingResponse,
|
||||||
createDeepLinkPath,
|
createDeepLinkPath,
|
||||||
escapeDeepLinkPath
|
escapeDeepLinkPath,
|
||||||
|
formatXml
|
||||||
} from "core/utils"
|
} from "core/utils"
|
||||||
import win from "core/window"
|
import win from "core/window"
|
||||||
|
|
||||||
@@ -885,4 +886,15 @@ describe("utils", function() {
|
|||||||
expect(result).toEqual("hello\\#world")
|
expect(result).toEqual("hello\\#world")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("formatXml", function() {
|
||||||
|
it("simple xml formatting", function() {
|
||||||
|
const startTime = Date.now()
|
||||||
|
const result = formatXml("<xml><name>john doe</name></xml>")
|
||||||
|
let duration = Date.now() - startTime
|
||||||
|
expect(result).toEqual("<xml>\n <name>john doe</name>\n</xml>\n")
|
||||||
|
expect(duration).toBeLessThan(5)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user